faster float to 8bit convertion

This commit is contained in:
homm 2014-10-25 06:04:04 +04:00
parent a484d28d1f
commit e9fc720709

View File

@ -78,6 +78,18 @@ static inline float bicubic_filter(float x)
static struct filter BICUBIC = { bicubic_filter, 2.0 }; static struct filter BICUBIC = { bicubic_filter, 2.0 };
static inline UINT8 clip8(float in)
{
int out = (int) in;
if (out >= 255)
return 255;
if (out <= 0)
return 0;
return (UINT8) out;
}
Imaging Imaging
ImagingStretchHorizaontal(Imaging imOut, Imaging imIn, int filter) ImagingStretchHorizaontal(Imaging imOut, Imaging imIn, int filter)
{ {
@ -183,12 +195,7 @@ ImagingStretchHorizaontal(Imaging imOut, Imaging imIn, int filter)
ss = 0.5; ss = 0.5;
for (x = xmin; x < xmax; x++) for (x = xmin; x < xmax; x++)
ss = ss + imIn->image8[yy][x] * k[x - xmin]; ss = ss + imIn->image8[yy][x] * k[x - xmin];
if (ss < 0.5) imOut->image8[yy][xx] = clip8(ss);
imOut->image8[yy][xx] = (UINT8) 0;
else if (ss >= 255.0)
imOut->image8[yy][xx] = (UINT8) 255;
else
imOut->image8[yy][xx] = (UINT8) ss;
} }
} else } else
switch(imIn->type) { switch(imIn->type) {
@ -204,12 +211,7 @@ ImagingStretchHorizaontal(Imaging imOut, Imaging imIn, int filter)
ss = 0.5; ss = 0.5;
for (x = xmin; x < xmax; x++) for (x = xmin; x < xmax; x++)
ss = ss + (UINT8) imIn->image[yy][x*4+b] * k[x - xmin]; ss = ss + (UINT8) imIn->image[yy][x*4+b] * k[x - xmin];
if (ss < 0.5) imOut->image[yy][xx*4+b] = clip8(ss);
imOut->image[yy][xx*4+b] = (UINT8) 0;
else if (ss >= 255.0)
imOut->image[yy][xx*4+b] = (UINT8) 255;
else
imOut->image[yy][xx*4+b] = (UINT8) ss;
} }
} }
break; break;