Package: libjpeg-progs
Version: 8d-1
Severity: normal
Tags: patch upstream

This report will mostly be a duplicate of #74087, closed almost 13 years
ago, without any explanation that I can find in the bug log, and without
actually fixing it as far as I can tell from the packages from that era
on archive.debian.org.

The problem now is as it was then: djpeg can't handle all jpegs. The
ones it doesn't handle are the ones encoded as YCCK or CMYK. The bug log
for #74087 doesn't mention YCCK or CMYK, so it's possible that the
problem just wasn't understood back then. But the sample included in the
original bug report is a YCCK jpeg.

This time, there's a patch. The patch has been seen before too, in a
slightly different form, targeted at libjpeg-turbo. It adds a couple of
conversion functions to the library, allowing clients like djpeg to get
RGB output regardless of the input.

  http://sourceforge.net/p/libjpeg-turbo/patches/15/

It was rejected there, but I hope history won't repeat itself here.
It makes no sense that djpeg (the Decode JPEG program from the de facto
JPEG reference implementation!) can't decode all jpegs. The people in
the libjpeg-turbo discussion didn't even seem to realize they were
deciding to keep their version of djpeg crippled forever.

The conversion code could be moved into djpeg, leaving the library
untouched, but djpeg isn't the only place something like this is needed.
I'd also like to see xli not choke on these jpegs.

If the conversion is supported by the library, then adding YCCK-jpeg
support to djpeg and xli is a 3-line patch for each program. 

If the conversion function is banned from the library like the
libjpeg-turbo people seem to want, xli and djpeg both need the same big
mess of pixel-shuffling code inserted into them, and so will the next
program. That's just a stupid way to do it.

Index: libjpeg8-8d/jdcolor.c
===================================================================
--- libjpeg8-8d.orig/jdcolor.c  2013-08-02 18:38:50.000000000 -0500
+++ libjpeg8-8d/jdcolor.c       2013-08-02 18:42:18.578891259 -0500
@@ -125,6 +125,105 @@
   }
 }
 
+/*
+ * Convert inverted CMYK to RGB
+ */
+METHODDEF(void)
+cmyk_rgb_convert (j_decompress_ptr cinfo,
+                JSAMPIMAGE input_buf, JDIMENSION input_row,
+                JSAMPARRAY output_buf, int num_rows)
+{
+  double c, m, y, k;
+  register JSAMPROW outptr;
+  register JSAMPROW inptr0, inptr1, inptr2, inptr3;
+  register JDIMENSION col;
+
+  JDIMENSION num_cols = cinfo->output_width;
+
+  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 = (double) GETJSAMPLE(inptr0[col]);
+       m = (double) GETJSAMPLE(inptr1[col]);
+       y = (double) GETJSAMPLE(inptr2[col]);
+       k = (double) GETJSAMPLE(inptr3[col]);
+
+    outptr[RGB_RED] =   (JSAMPLE)(c*k/255);
+    outptr[RGB_GREEN] = (JSAMPLE)(m*k/255);
+    outptr[RGB_BLUE] =  (JSAMPLE)(y*k/255);
+    outptr += RGB_PIXELSIZE;
+    }
+  }
+}
+
+/*
+ * Convert YCCK to RGB
+ */
+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;
+  double cyan, magenta, yellow, black;
+  register int y, cb, cr;
+  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++) {
+
+
+      /********* Read YCCK Pixel **********/
+      y     = GETJSAMPLE(inptr0[col]);
+      cb    = GETJSAMPLE(inptr1[col]);
+      cr    = GETJSAMPLE(inptr2[col]);
+         black = (double)GETJSAMPLE(inptr3[col]);
+
+      /********* Convert  YCCK to CMYK  **********/
+        /* Range-limiting is essential due to noise introduced by DCT losses. 
*/
+      outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])];
+      outptr[1] = range_limit[MAXJSAMPLE - (y +
+                             ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], 
SCALEBITS)))];
+      outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])];
+         /* K passes through unchanged */
+      outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
+
+         cyan          = (double)GETJSAMPLE(outptr[0]);
+         magenta       = (double)GETJSAMPLE(outptr[1]);
+         yellow        = (double)GETJSAMPLE(outptr[2]);
+      //Black is same as in YCCK input
+
+      /********* Convert  CMYK to RGB  **********/
+      outptr[RGB_RED]  = (JSAMPLE)(cyan*black/255);
+      outptr[RGB_GREEN] = (JSAMPLE)(magenta*black/255);
+      outptr[RGB_BLUE]         = (JSAMPLE)(yellow*black/255);
+
+      outptr += RGB_PIXELSIZE;
+    }
+  }
+}
 
 /*
  * Convert some rows of samples to the output colorspace.
@@ -480,6 +579,11 @@
       cconvert->pub.color_convert = gray_rgb_convert;
     } else if (cinfo->jpeg_color_space == JCS_RGB) {
       cconvert->pub.color_convert = rgb_convert;
+    } else if (cinfo->jpeg_color_space == JCS_CMYK) {
+      cconvert->pub.color_convert = cmyk_rgb_convert;
+    } else if (cinfo->jpeg_color_space == JCS_YCCK) {
+      cconvert->pub.color_convert = ycck_rgb_convert;
+      build_ycc_rgb_table(cinfo);
     } else
       ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
     break;
Index: libjpeg8-8d/djpeg.c
===================================================================
--- libjpeg8-8d.orig/djpeg.c    2013-08-02 18:46:00.077338767 -0500
+++ libjpeg8-8d/djpeg.c 2013-08-02 18:40:54.158892208 -0500
@@ -532,6 +532,10 @@
   /* Read file header, set default decompression parameters */
   (void) jpeg_read_header(&cinfo, TRUE);
 
+  if(cinfo.jpeg_color_space == JCS_CMYK ||
+     cinfo.jpeg_color_space == JCS_YCCK)
+    cinfo.out_color_space = JCS_RGB;
+
   /* Adjust default decompression parameters by re-parsing the options */
   file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);
 

-- System Information:
Debian Release: 7.1
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 3.8.2+ (SMP w/2 CPU cores)
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
Shell: /bin/sh linked to /bin/dash

Versions of packages libjpeg-progs depends on:
ii  libc6     2.13-38
ii  libjpeg8  8d-1

libjpeg-progs recommends no packages.

libjpeg-progs suggests no packages.

-- no debconf information


-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to