From 479693417fe2de2ac248fb9f02375e793721d8c8 Mon Sep 17 00:00:00 2001 From: David Joy Date: Wed, 25 Jun 2014 11:42:06 -0400 Subject: [PATCH] Merge the rest of the patches Now it actually works and passes the test suite --- PIL/Jpeg2KImagePlugin.py | 8 ++++---- libImaging/Jpeg2KEncode.c | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/PIL/Jpeg2KImagePlugin.py b/PIL/Jpeg2KImagePlugin.py index c75b38576..ff6ca4b35 100644 --- a/PIL/Jpeg2KImagePlugin.py +++ b/PIL/Jpeg2KImagePlugin.py @@ -40,7 +40,7 @@ def _parse_codestream(fp): size = (xsiz - xosiz, ysiz - yosiz) if csiz == 1: - if len(yrsiz) > 0 and yrsiz[0] > 8: + if (ssiz[0] & 0x7f) > 8: mode = 'I' else: mode = 'L' @@ -99,7 +99,7 @@ def _parse_jp2_header(fp): = struct.unpack('>IIHBBBB', content) size = (width, height) if unkc: - if nc == 1 and bpc > 8: + if nc == 1 and (bpc & 0x7f) > 8: mode = 'I' elif nc == 1: mode = 'L' @@ -115,7 +115,7 @@ def _parse_jp2_header(fp): if meth == 1: cs = struct.unpack('>I', content[3:7])[0] if cs == 16: # sRGB - if nc == 1 and bpc > 8: + if nc == 1 and (bpc & 0x7f) > 8: mode = 'I' elif nc == 1: mode = 'L' @@ -125,7 +125,7 @@ def _parse_jp2_header(fp): mode = 'RGBA' break elif cs == 17: # grayscale - if nc == 1 and bpc > 8: + if nc == 1 and (bpc & 0x7f) > 8: mode = 'I' elif nc == 1: mode = 'L' diff --git a/libImaging/Jpeg2KEncode.c b/libImaging/Jpeg2KEncode.c index 8d8737474..e8eef08c1 100644 --- a/libImaging/Jpeg2KEncode.c +++ b/libImaging/Jpeg2KEncode.c @@ -290,7 +290,13 @@ j2k_encode_entry(Imaging im, ImagingCodecState state, components = 1; color_space = OPJ_CLRSPC_GRAY; pack = j2k_pack_l; - } else if (strcmp (im->mode, "I")){ + } else if (strcmp (im->mode, "I;16") == 0){ + components = 1; + color_space = OPJ_CLRSPC_GRAY; + pack = j2k_pack_i16; + prec = 16; + bpp = 12; + } else if (strcmp (im->mode, "I;16B") == 0){ components = 1; color_space = OPJ_CLRSPC_GRAY; pack = j2k_pack_i16;