changeset 11125:0e8471a4ad56 12+4

8214035: Unable to render cmyk jpeg image Reviewed-by: kcr, jdv
author arapte
date Thu, 06 Dec 2018 14:04:41 +0530
parents 281a7c2ead0f
children fa76dfc055eb
files modules/javafx.graphics/src/main/native-iio/libjpeg/UPDATING.txt modules/javafx.graphics/src/main/native-iio/libjpeg/jchuff.c modules/javafx.graphics/src/main/native-iio/libjpeg/jcmaster.c modules/javafx.graphics/src/main/native-iio/libjpeg/jdcolor.c modules/javafx.graphics/src/main/native-iio/libjpeg/jdhuff.c modules/javafx.graphics/src/main/native-iio/libjpeg/jmorecfg.h
diffstat 6 files changed, 182 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/javafx.graphics/src/main/native-iio/libjpeg/UPDATING.txt	Thu Dec 06 14:04:41 2018 +0530
@@ -0,0 +1,45 @@
+Updating libjpeg in OpenJFX:
+
+1) Update the modules/javafx.graphics/src/main/legal/jpeg_fx.md file.
+It would need updating the version at top, getting file header from
+jcapimin.c (or consider using jversion.h), and part of the 'In legalese'
+section from README.
+
+2) Copy README file from the new version into OpenJFX's libjpeg source directory.
+
+3) OpenJFX imports only the JPEG library source with some exceptions.
+OpenJFX does not need any other applications or tools provided by IJG libjpeg.
+Copy only the same 41 .c and 9 .h files as are already there.
+
+4) The following files contain local modifications of libjpeg for JavaFX:
+* jchuff.c
+* jcinit.c
+* jcmaster.c
+* jctrans.c
+* jdcolor.c
+* jdhuff.c
+* jdmaster.c
+* jdtrans.c
+* jerror.h
+* jmorecfg.h
+
+** The modifications are,
+4.1) Remove arithmetic encoding/decoding.
+Files: jcinit.c, jctrans.c, jdmaster.c, jdtrans.c, jerror.h, jmorecfg.h
+
+4.2) Initialize arrays.
+Files: jchuff.c, jcmaster.c, jdhuff.c
+
+4.3) Add support for CMYK & YCCK jpeg color space.
+Files: jdcolor.c
+Two functions are added to jdcolor.c,
+a) ycck_rgb_convert(): converts YCCK to RGB color space.
+b) cmyk_rgb_convert(): converts CMYK to RGB color space.
+Pointer to these functions is used while initializing decompressor.
+
+4.4) Improve image filling.
+Files: jdhuff.c
+
+5) Expand tabs and remove trailing white spaces from source files.
+
+6) Verification: FX sdk build and all test run, on all supported platforms.
--- a/modules/javafx.graphics/src/main/native-iio/libjpeg/jchuff.c	Wed Dec 05 18:46:54 2018 -0800
+++ b/modules/javafx.graphics/src/main/native-iio/libjpeg/jchuff.c	Thu Dec 06 14:04:41 2018 +0530
@@ -168,6 +168,8 @@
   unsigned int huffcode[257];
   unsigned int code;
 
+  MEMZERO(huffsize, SIZEOF(huffsize));
+  MEMZERO(huffcode, SIZEOF(huffcode));
   /* Note that huffsize[] and huffcode[] are filled in code-length order,
    * paralleling the order of the symbols themselves in htbl->huffval[].
    */
@@ -793,6 +795,8 @@
   unsigned int BR;
   int absvalues[DCTSIZE2];
 
+  MEMZERO(absvalues, SIZEOF(absvalues));
+
   entropy->next_output_byte = cinfo->dest->next_output_byte;
   entropy->free_in_buffer = cinfo->dest->free_in_buffer;
 
--- a/modules/javafx.graphics/src/main/native-iio/libjpeg/jcmaster.c	Wed Dec 05 18:46:54 2018 -0800
+++ b/modules/javafx.graphics/src/main/native-iio/libjpeg/jcmaster.c	Thu Dec 06 14:04:41 2018 +0530
@@ -184,8 +184,11 @@
   int * last_bitpos_ptr;
   int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
   /* -1 until that coefficient has been seen; then last Al for it */
+  MEMZERO(last_bitpos, SIZEOF(last_bitpos));
 #endif
 
+  MEMZERO(component_sent, SIZEOF(component_sent));
+
   if (cinfo->num_scans <= 0)
     ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
 
--- a/modules/javafx.graphics/src/main/native-iio/libjpeg/jdcolor.c	Wed Dec 05 18:46:54 2018 -0800
+++ b/modules/javafx.graphics/src/main/native-iio/libjpeg/jdcolor.c	Thu Dec 06 14:04:41 2018 +0530
@@ -504,6 +504,118 @@
 
 
 /*
+ * YCCK->CMYK->CMY->RGB conversion.
+ *
+ * NB: this color conversion is introduced in jfx libjpeg snapshot as
+ *     a part of the fix for JDK-8096615. In case of library upgrade, please
+ *     check whether this convertor needs to be moved into upgraded version
+ *     of the library.
+ */
+METHODDEF(void)
+ycck_rgb_convert (j_decompress_ptr cinfo,
+                   JSAMPIMAGE input_buf, JDIMENSION input_row,
+                   JSAMPARRAY output_buf, int num_rows)
+{
+  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
+  register int y, cb, cr, k;
+  register int C, M, Y;
+  register int r, g, b;
+  register JSAMPROW outptr;
+  register JSAMPROW inptr0, inptr1, inptr2, inptr3;
+  register JDIMENSION col;
+  JDIMENSION num_cols = cinfo->output_width;
+  /* copy these pointers into registers if possible */
+  register JSAMPLE * range_limit = cinfo->sample_range_limit;
+  register int * Crrtab = cconvert->Cr_r_tab;
+  register int * Cbbtab = cconvert->Cb_b_tab;
+  register INT32 * Crgtab = cconvert->Cr_g_tab;
+  register INT32 * Cbgtab = cconvert->Cb_g_tab;
+  SHIFT_TEMPS
+
+  while (--num_rows >= 0) {
+    inptr0 = input_buf[0][input_row];
+    inptr1 = input_buf[1][input_row];
+    inptr2 = input_buf[2][input_row];
+    inptr3 = input_buf[3][input_row];
+    input_row++;
+    outptr = *output_buf++;
+    for (col = 0; col < num_cols; col++) {
+      y  = GETJSAMPLE(inptr0[col]);
+      cb = GETJSAMPLE(inptr1[col]);
+      cr = GETJSAMPLE(inptr2[col]);
+      k  = GETJSAMPLE(inptr3[col]);
+
+      C = MAXJSAMPLE - (y + Crrtab[cr]);
+      M = MAXJSAMPLE - (y + ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS)));
+      Y = MAXJSAMPLE - (y + Cbbtab[cb]);
+
+      r = C * k / MAXJSAMPLE;
+      g = M * k / MAXJSAMPLE;
+      b = Y * k / MAXJSAMPLE;
+
+      /* Range-limiting is essential due to noise introduced by DCT losses. */
+      outptr[RGB_RED] = range_limit[r];
+      outptr[RGB_GREEN] = range_limit[g];
+      outptr[RGB_BLUE] = range_limit[b];
+
+      outptr += RGB_PIXELSIZE;
+    }
+  }
+}
+
+/*
+ * CMYK->CMY->RGB conversion.
+ *
+ * NB: this color conversion is introduced in jfx libjpeg snapshot as
+ *     a part of the fix for JDK-8096615. In case of library upgrade, please
+ *     check whether this convertor needs to be moved into upgraded version
+ *     of the library.
+ */
+METHODDEF(void)
+cmyk_rgb_convert (j_decompress_ptr cinfo,
+                   JSAMPIMAGE input_buf, JDIMENSION input_row,
+                   JSAMPARRAY output_buf, int num_rows)
+{
+  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
+  register int c, m, y, k;
+  register int r, g, b;
+  register JSAMPROW outptr;
+  register JSAMPROW inptr0, inptr1, inptr2, inptr3;
+  register JDIMENSION col;
+  JDIMENSION num_cols = cinfo->output_width;
+  /* copy these pointers into registers if possible */
+  register JSAMPLE * range_limit = cinfo->sample_range_limit;
+  SHIFT_TEMPS
+
+  while (--num_rows >= 0) {
+    inptr0 = input_buf[0][input_row];
+    inptr1 = input_buf[1][input_row];
+    inptr2 = input_buf[2][input_row];
+    inptr3 = input_buf[3][input_row];
+    input_row++;
+    outptr = *output_buf++;
+    for (col = 0; col < num_cols; col++) {
+      c = GETJSAMPLE(inptr0[col]);
+      m = GETJSAMPLE(inptr1[col]);
+      y = GETJSAMPLE(inptr2[col]);
+      k = GETJSAMPLE(inptr3[col]);
+
+      r = c * k / MAXJSAMPLE;
+      g = m * k / MAXJSAMPLE;
+      b = y * k / MAXJSAMPLE;
+
+      /* Range-limiting is essential due to noise introduced by DCT losses. */
+      outptr[RGB_RED] = range_limit[r];
+      outptr[RGB_GREEN] = range_limit[g];
+      outptr[RGB_BLUE] = range_limit[b];
+
+      outptr += RGB_PIXELSIZE;
+    }
+  }
+}
+
+
+/*
  * Adobe-style YCCK->CMYK conversion.
  * We convert YCbCr to R=1-C, G=1-M, and B=1-Y using the same
  * conversion as above, while passing K (black) unchanged.
@@ -668,15 +780,22 @@
     case JCS_RGB:
       switch (cinfo->color_transform) {
       case JCT_NONE:
-    cconvert->pub.color_convert = rgb_convert;
-    break;
+        cconvert->pub.color_convert = rgb_convert;
+        break;
       case JCT_SUBTRACT_GREEN:
-    cconvert->pub.color_convert = rgb1_rgb_convert;
-    break;
+        cconvert->pub.color_convert = rgb1_rgb_convert;
+        break;
       default:
-    ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
+        ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
       }
       break;
+    case JCS_YCCK:
+      cconvert->pub.color_convert = ycck_rgb_convert;
+      build_ycc_rgb_table(cinfo);
+      break;
+    case JCS_CMYK:
+      cconvert->pub.color_convert = cmyk_rgb_convert;
+      break;
     default:
       ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
     }
--- a/modules/javafx.graphics/src/main/native-iio/libjpeg/jdhuff.c	Wed Dec 05 18:46:54 2018 -0800
+++ b/modules/javafx.graphics/src/main/native-iio/libjpeg/jdhuff.c	Thu Dec 06 14:04:41 2018 +0530
@@ -331,6 +331,8 @@
   unsigned int huffcode[257];
   unsigned int code;
 
+  MEMZERO(huffsize, SIZEOF(huffsize));
+  MEMZERO(huffcode, SIZEOF(huffcode));
   /* Note that huffsize[] and huffcode[] are filled in code-length order,
    * paralleling the order of the symbols themselves in htbl->huffval[].
    */
@@ -619,7 +621,9 @@
   /* With garbage input we may reach the sentinel value l = 17. */
 
   if (l > 16) {
+    int br_offset = state->next_input_byte - state->cinfo->src->next_input_byte;
     WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
+    state->next_input_byte = state->cinfo->src->next_input_byte + br_offset;
     return 0;            /* fake a zero as the safest result */
   }
 
--- a/modules/javafx.graphics/src/main/native-iio/libjpeg/jmorecfg.h	Wed Dec 05 18:46:54 2018 -0800
+++ b/modules/javafx.graphics/src/main/native-iio/libjpeg/jmorecfg.h	Thu Dec 06 14:04:41 2018 +0530
@@ -349,7 +349,7 @@
 
 /* Encoder capability options: */
 
-#define C_ARITH_CODING_SUPPORTED    /* Arithmetic coding back end? */
+#undef C_ARITH_CODING_SUPPORTED    /* Arithmetic coding back end? */
 #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
 #define C_PROGRESSIVE_SUPPORTED        /* Progressive JPEG? (Requires MULTISCAN)*/
 #define DCT_SCALING_SUPPORTED        /* Input rescaling via DCT? (Requires DCT_ISLOW)*/
@@ -367,7 +367,7 @@
 
 /* Decoder capability options: */
 
-#define D_ARITH_CODING_SUPPORTED    /* Arithmetic coding back end? */
+#undef D_ARITH_CODING_SUPPORTED    /* Arithmetic coding back end? */
 #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
 #define D_PROGRESSIVE_SUPPORTED        /* Progressive JPEG? (Requires MULTISCAN)*/
 #define IDCT_SCALING_SUPPORTED        /* Output rescaling via IDCT? (Requires DCT_ISLOW)*/