changeset 1408:e59742ef792a

CMYK JPEGs, at least Adobe ones for now
author corvid <corvid@lavabit.com>
date Wed, 04 Nov 2009 16:59:54 +0000
parents c5cc5560d2b2
children 78b152208bc1
files ChangeLog src/image.hh src/imgbuf.cc src/jpeg.c
diffstat 4 files changed, 21 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Nov 04 09:26:28 2009 -0300
+++ b/ChangeLog	Wed Nov 04 16:59:54 2009 +0000
@@ -46,6 +46,7 @@
  - Tooltips
  - Fix segfault when radio button lacks name attribute.
  - Enable popup menu below bottom of page content (BUG#856).
+ - Handle JPEGs with CMYK color space.
    Patches: corvid
 +- Support for the letter-spacing property.
    Patch: Johannes Hofmann, corvid
--- a/src/image.hh	Wed Nov 04 09:26:28 2009 -0300
+++ b/src/image.hh	Wed Nov 04 16:59:54 2009 +0000
@@ -29,6 +29,7 @@
    DILLO_IMG_TYPE_INDEXED,
    DILLO_IMG_TYPE_RGB,
    DILLO_IMG_TYPE_GRAY,
+   DILLO_IMG_TYPE_CMYK_INV,
    DILLO_IMG_TYPE_NOTSET    /* Initial value */
 } DilloImgType;
 
--- a/src/imgbuf.cc	Wed Nov 04 09:26:28 2009 -0300
+++ b/src/imgbuf.cc	Wed Nov 04 16:59:54 2009 +0000
@@ -45,6 +45,19 @@
       for (x = 0; x < width; x++)
          memset(linebuf + x * 3, buf[x], 3);
       break;
+   case DILLO_IMG_TYPE_CMYK_INV:
+      /*
+       * We treat CMYK as if it were "RGBW", and it works. Everyone who is
+       * trying to handle CMYK jpegs is confused by this, and supposedly
+       * the issue is that Adobe CMYK is "wrong" but ubiquitous.
+       */
+      for (x = 0; x < width; x++) {
+         uint_t white = buf[x * 4 + 3];
+         linebuf[x * 3] = buf[x * 4] * white / 0x100;
+         linebuf[x * 3 + 1] = buf[x * 4 + 1] * white / 0x100;
+         linebuf[x * 3 + 2] = buf[x * 4 + 2] * white / 0x100;
+      }
+      break;
    case DILLO_IMG_TYPE_RGB:
       /* avoid a memcpy here!  --Jcid */
       return (uchar_t *)buf;
--- a/src/jpeg.c	Wed Nov 04 09:26:28 2009 -0300
+++ b/src/jpeg.c	Wed Nov 04 16:59:54 2009 +0000
@@ -273,8 +273,12 @@
          } else if (jpeg->cinfo.num_components == 3) {
             type = DILLO_IMG_TYPE_RGB;
          } else {
-            _MSG("jpeg: can't handle %d component images\n",
-                 jpeg->cinfo.num_components);
+            MSG("4-component JPEG!\n");
+            if (jpeg->cinfo.jpeg_color_space == JCS_YCCK)
+               MSG("YCCK. Are the colors wrong?\n");
+            if (!jpeg->cinfo.saw_Adobe_marker)
+               MSG("No adobe marker! Is the image shown in reverse video?\n");
+            type = DILLO_IMG_TYPE_CMYK_INV;
          }
          /*
           * If a multiple-scan image is not completely in cache,