mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
Add conversions from I;16 to F to retain 16 bit precision
This commit is contained in:
parent
c7264b5d4b
commit
993e075c0d
|
@ -24,3 +24,27 @@ def test_default():
|
|||
assert_image(im, "RGB", im.size)
|
||||
im = im.convert()
|
||||
assert_image(im, "RGB", im.size)
|
||||
|
||||
|
||||
|
||||
# ref https://github.com/python-imaging/Pillow/issues/274
|
||||
|
||||
def _test_float_conversion(im):
|
||||
orig = im.getpixel((5,5))
|
||||
converted = im.convert('F').getpixel((5,5))
|
||||
assert_equal(orig, converted)
|
||||
|
||||
def test_8bit():
|
||||
im = Image.open('Images/lena.jpg')
|
||||
_test_float_conversion(im.convert('L'))
|
||||
|
||||
def test_12bit():
|
||||
im = Image.open('Tests/images/12bit.tif')
|
||||
_test_float_conversion(im)
|
||||
|
||||
def test_12bit_workaround():
|
||||
im = Image.open('Tests/images/12bit.tif')
|
||||
_test_float_conversion(im.convert('I'))
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -498,6 +498,25 @@ I16B_I(UINT8* out_, const UINT8* in, int xsize)
|
|||
*out++ = in[1] + ((int) in[0] << 8);
|
||||
}
|
||||
|
||||
static void
|
||||
I16L_F(UINT8* out_, const UINT8* in, int xsize)
|
||||
{
|
||||
int x;
|
||||
FLOAT32* out = (FLOAT32*) out_;
|
||||
for (x = 0; x < xsize; x++, in += 2)
|
||||
*out++ = (FLOAT32) (in[0] + ((int) in[1] << 8));
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
I16B_F(UINT8* out_, const UINT8* in, int xsize)
|
||||
{
|
||||
int x;
|
||||
FLOAT32* out = (FLOAT32*) out_;
|
||||
for (x = 0; x < xsize; x++, in += 2)
|
||||
*out++ = (FLOAT32) (in[1] + ((int) in[0] << 8));
|
||||
}
|
||||
|
||||
static void
|
||||
L_I16L(UINT8* out, const UINT8* in, int xsize)
|
||||
{
|
||||
|
@ -630,6 +649,10 @@ static struct {
|
|||
{ "L", "I;16B", L_I16B },
|
||||
{ "I;16B", "L", I16B_L },
|
||||
|
||||
{ "I;16", "F", I16L_F },
|
||||
{ "I;16L", "F", I16L_F },
|
||||
{ "I;16B", "F", I16B_F },
|
||||
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user