mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-11 04:07:21 +03:00
faster float to 8bit convertion
This commit is contained in:
parent
a484d28d1f
commit
e9fc720709
|
@ -78,6 +78,18 @@ static inline float bicubic_filter(float x)
|
|||
|
||||
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
|
||||
ImagingStretchHorizaontal(Imaging imOut, Imaging imIn, int filter)
|
||||
{
|
||||
|
@ -183,12 +195,7 @@ ImagingStretchHorizaontal(Imaging imOut, Imaging imIn, int filter)
|
|||
ss = 0.5;
|
||||
for (x = xmin; x < xmax; x++)
|
||||
ss = ss + imIn->image8[yy][x] * k[x - xmin];
|
||||
if (ss < 0.5)
|
||||
imOut->image8[yy][xx] = (UINT8) 0;
|
||||
else if (ss >= 255.0)
|
||||
imOut->image8[yy][xx] = (UINT8) 255;
|
||||
else
|
||||
imOut->image8[yy][xx] = (UINT8) ss;
|
||||
imOut->image8[yy][xx] = clip8(ss);
|
||||
}
|
||||
} else
|
||||
switch(imIn->type) {
|
||||
|
@ -204,12 +211,7 @@ ImagingStretchHorizaontal(Imaging imOut, Imaging imIn, int filter)
|
|||
ss = 0.5;
|
||||
for (x = xmin; x < xmax; x++)
|
||||
ss = ss + (UINT8) imIn->image[yy][x*4+b] * k[x - xmin];
|
||||
if (ss < 0.5)
|
||||
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;
|
||||
imOut->image[yy][xx*4+b] = clip8(ss);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue
Block a user