diff mbox

Added CMYK to RGB color conversion.

Message ID BANLkTi=k_1eXbiHfr=Ey6MP=K5nhbh=Ckw@mail.gmail.com
State New
Headers show

Commit Message

Mandeep Kumar June 2, 2011, 1:31 p.m. UTC
From e821a725e69102ec42bb56ad9b783b415141fda3 Mon Sep 17 00:00:00 2001
From: Mandeep Kumar <mandeep.kumar@linaro.org>
Date: Tue, 3 May 2011 17:33:49 -0500
Subject: [PATCH] Added CMYK to RGB color conversion.

---
 djpeg.c   |    4 ++++
 jdcolor.c |   38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 0 deletions(-)
 mode change 100644 => 100755 djpeg.c
 mode change 100644 => 100755 jdcolor.c
diff mbox

Patch

diff --git a/djpeg.c b/djpeg.c
old mode 100644
new mode 100755
index 466973f..4c8545e
--- a/djpeg.c
+++ b/djpeg.c
@@ -539,6 +539,10 @@  main (int argc, char **argv)
   /* Adjust default decompression parameters by re-parsing the options */
   file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);

+  if (cinfo.jpeg_color_space == JCS_CMYK) {
+    cinfo.out_color_space = JCS_RGB;
+  }
+
   /* Initialize the output module now to let it override any crucial
    * option settings (for instance, GIF wants to force color quantization).
    */
diff --git a/jdcolor.c b/jdcolor.c
old mode 100644
new mode 100755
index bc73b3f..4678467
--- a/jdcolor.c
+++ b/jdcolor.c
@@ -159,6 +159,42 @@  ycc_rgb_convert (j_decompress_ptr cinfo,
   }
 }

+/*
+ * Convert 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;
+    }
+  }
+}
+

 /**************** Cases other than YCbCr -> RGB **************/

@@ -377,6 +413,8 @@  jinit_color_deconverter (j_decompress_ptr cinfo)
         cconvert->pub.color_convert = ycc_rgb_convert;
         build_ycc_rgb_table(cinfo);
       }
+    } else if (cinfo->jpeg_color_space == JCS_CMYK) {
+      cconvert->pub.color_convert = cmyk_rgb_convert;
     } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
       cconvert->pub.color_convert = gray_rgb_convert;
     } else if (cinfo->jpeg_color_space == cinfo->out_color_space &&