Skip to content
Permalink
Browse files Browse the repository at this point in the history
fixed wrong data_maximum calcluation; prevent out-of-buffer in exp_bef
  • Loading branch information
alextutubalin committed May 24, 2013
1 parent f306538 commit 2f912f5
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/libraw_cxx.cpp
Expand Up @@ -2336,14 +2336,15 @@ int LibRaw::subtract_black()
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define LIM(x,min,max) MAX(min,MIN(x,max))
#define CLIP(x) LIM(x,0,65535)

for(i=0; i< size*4; i++)
int dmax = 0;
for(i=0; i< size*4; i++)
{
int val = imgdata.image[0][i];
val -= cblk[i & 3];
imgdata.image[0][i] = CLIP(val);
if(C.data_maximum < val) C.data_maximum = val;
if(dmax < val) dmax = val;
}
C.data_maximum = dmax & 0xffff;
#undef MIN
#undef MAX
#undef LIM
Expand All @@ -2359,9 +2360,10 @@ int LibRaw::subtract_black()
// only calculate channel maximum;
int idx;
ushort *p = (ushort*)imgdata.image;
C.data_maximum = 0;
int dmax = 0;
for(idx=0;idx<S.iheight*S.iwidth*4;idx++)
if(C.data_maximum < p[idx]) C.data_maximum = p[idx];
if(dmax < p[idx]) dmax = p[idx];
C.data_maximum = dmax;
}
return 0;
}
Expand Down Expand Up @@ -2421,8 +2423,10 @@ void LibRaw::exp_bef(float shift, float smooth)
imgdata.image[i][3] = lut[imgdata.image[i][3]];
}

C.data_maximum = lut[C.data_maximum];
C.maximum = lut[C.maximum];
if(C.data_maximum <=TBLN)
C.data_maximum = lut[C.data_maximum];
if(C.maximum <= TBLN)
C.maximum = lut[C.maximum];
// no need to adjust the minumum, black is already subtracted
free(lut);
}
Expand Down Expand Up @@ -2530,7 +2534,7 @@ int LibRaw::dcraw_process(void)

raw2image_ex(subtract_inline); // allocate imgdata.image and copy data!

int save_4color = O.four_color_rgb;
int save_4color = O.four_color_rgb;

if (IO.zero_is_bad)
{
Expand Down

0 comments on commit 2f912f5

Please sign in to comment.