Display device does not display 4-bit CMYK

"Russell Lang" <[email protected]> Wed, 01 Sep 2004 19:31:07 +1000
Newsgroups gmane.comp.printing.ghostscript.patches
Message-ID <4136237B.3086.1BFEB1E3@localhost>
Dan,

Log message:
Add support for 4-bit/pixel CMYK to the display device clients for 
Windows and gtk+.


Russell Lang                   [email protected]
Ghostgum Software Pty Ltd      http://www.ghostgum.com.au/

diff -u /home/rjl/cvs/gs/src/dwimg.c src/dwimg.c
--- /home/rjl/cvs/gs/src/dwimg.c	2004-08-19 17:38:05.000000000 +1000
+++ src/dwimg.c	2004-09-01 18:07:14.238863224 +1000
@@ -87,6 +87,8 @@
     unsigned char *source);
 void image_16RGB565_to_24BGR(int width, unsigned char *dest, 
     unsigned char *source);
+void image_4CMYK_to_24BGR(int width, unsigned char *dest, 
+    unsigned char *source, IMAGE_DEVICEN *devicen, int devicen_gray);
 void image_32CMYK_to_24BGR(int width, unsigned char *dest, 
     unsigned char *source, IMAGE_DEVICEN *devicen, int devicen_gray);
 void image_devicen_to_24BGR(int width, unsigned char *dest, 
@@ -265,6 +267,14 @@
 	    }
 	    break;
 	case DISPLAY_COLORS_CMYK:
+	    switch (img->format & DISPLAY_DEPTH_MASK) {
+		case DISPLAY_DEPTH_1:
+		case DISPLAY_DEPTH_8:
+		    /* we can convert these formats */
+		    break;
+		default:
+		    return DISPLAY_ERROR;
+	    }
 	    /* we can't display this natively */
 	    /* we will convert it just before displaying */
 	    img->bmih.biBitCount = 24;
@@ -752,6 +762,46 @@
     }
 }
 
+void
+image_4CMYK_to_24BGR(int width, unsigned char *dest, unsigned char *source,
+    IMAGE_DEVICEN *devicen, int devicen_gray)
+{
+    int i;
+    int cyan, magenta, yellow, black;
+    int vc = devicen[0].visible;
+    int vm = devicen[1].visible;
+    int vy = devicen[2].visible;
+    int vk = devicen[3].visible;
+    int vall = vc && vm && vy && vk;
+    int show_gray = (vc + vm + vy + vk == 1) && devicen_gray;
+    int value;
+    for (i=0; i<width; i++) {
+        value = source[i/2];
+	if (i & 0)
+	    value >>= 4;
+	cyan = ((value >> 3) & 1) * 255;
+	magenta = ((value >> 2) & 1) * 255;
+	yellow = ((value >> 1) & 1) * 255;
+	black = (value & 1) * 255;
+	if (!vall) {
+	    if (!vc)
+		cyan = 0;
+	    if (!vm)
+		magenta = 0;
+	    if (!vy)
+		yellow = 0;
+	    if (!vk)
+		black = 0;
+	    if (show_gray) {
+		black += cyan + magenta + yellow;
+		cyan = magenta = yellow = 0;
+	    }
+	}
+	*dest++ = (255 - yellow)  * (255 - black)/255; /* blue */
+	*dest++ = (255 - magenta) * (255 - black)/255; /* green */
+	*dest++ = (255 - cyan)    * (255 - black)/255; /* red */
+    }
+}
 
 /* convert one line of 32CMYK to 24BGR */
 void
@@ -904,10 +954,15 @@
 */
 	    break;
 	case DISPLAY_COLORS_CMYK:
-	    if ((img->format & DISPLAY_DEPTH_MASK) != DISPLAY_DEPTH_8)
+	    if ((img->format & DISPLAY_DEPTH_MASK) == DISPLAY_DEPTH_8)
+		image_32CMYK_to_24BGR(width, dest, source, 
+		    img->devicen, img->devicen_gray);
+	    else if ((img->format & DISPLAY_DEPTH_MASK) == DISPLAY_DEPTH_1) {
+		image_4CMYK_to_24BGR(width, dest, source, 
+		    img->devicen, img->devicen_gray);
+	    }
+	    else
 		return;
-	    image_32CMYK_to_24BGR(width, dest, source, 
-		img->devicen, img->devicen_gray);
 	    break;
 	case DISPLAY_COLORS_SEPARATION:
 	    if ((img->format & DISPLAY_DEPTH_MASK) != DISPLAY_DEPTH_8)
diff -u /home/rjl/cvs/gs/src/dxmain.c src/dxmain.c
--- /home/rjl/cvs/gs/src/dxmain.c	2004-08-20 07:52:20.000000000 +1000
+++ src/dxmain.c	2004-09-01 19:13:24.149345096 +1000
@@ -268,6 +268,15 @@
 		    }
 		    break;
 		case DISPLAY_COLORS_CMYK:
+		    if (((depth == DISPLAY_DEPTH_1) || 
+		        (depth == DISPLAY_DEPTH_8)) && img->rgbbuf)
+			gdk_draw_rgb_image(widget->window, 
+			    widget->style->fg_gc[GTK_STATE_NORMAL],
+			    x, y, width, height,
+			    GDK_RGB_DITHER_MAX, 
+			    img->rgbbuf + x*3 + y*img->width*3, 
+			    img->width * 3);
+		    break;
 		case DISPLAY_COLORS_SEPARATION:
 		    if ((depth == DISPLAY_DEPTH_8) && img->rgbbuf)
 			gdk_draw_rgb_image(widget->window, 
@@ -591,7 +600,7 @@
 		return -1;	/* not supported */
 	    break;
 	case DISPLAY_COLORS_CMYK:
-	    if (depth == DISPLAY_DEPTH_8) {
+	    if ((depth == DISPLAY_DEPTH_1) || (depth == DISPLAY_DEPTH_8)) {
 		/* need to convert to 24RGB */
 		img->rgbbuf = (guchar *)malloc(width * height * 3);
 		if (img->rgbbuf == NULL)
@@ -913,6 +922,49 @@
 		    }
 		}
 	    }
+	    else if (depth == DISPLAY_DEPTH_1) {
+	    	/* Separations */
+		int x, y;
+		int cyan, magenta, yellow, black;
+		unsigned char *s, *d;
+		int vc = img->devicen[0].visible;
+		int vm = img->devicen[1].visible;
+		int vy = img->devicen[2].visible;
+		int vk = img->devicen[3].visible;
+		int vall = vc && vm && vy && vk;
+		int show_gray = (vc + vm + vy + vk == 1) && img->devicen_gray;
+		int value;
+		for (y = 0; y<img->height; y++) {
+		    s = img->buf + y * img->rowstride;
+		    d = img->rgbbuf + y * img->width * 3;
+		    for (x=0; x<img->width; x++) {
+			value = s[x/2];
+			if (x & 0)
+			    value >>= 4;
+			cyan = ((value >> 3) & 1) * 255;
+			magenta = ((value >> 2) & 1) * 255;
+			yellow = ((value >> 1) & 1) * 255;
+			black = (value & 1) * 255;
+			if (!vall) {
+			    if (!vc)
+				cyan = 0;
+			    if (!vm)
+				magenta = 0;
+			    if (!vy)
+				yellow = 0;
+			    if (!vk)
+				black = 0;
+			    if (show_gray) {
+				black += cyan + magenta + yellow;
+				cyan = magenta = yellow = 0;
+			    }
+			}
+			*d++ = (255-cyan)    * (255-black) / 255; /* r */
+			*d++ = (255-magenta) * (255-black) / 255; /* g */
+			*d++ = (255-yellow)  * (255-black) / 255; /* b */
+		    }
+		}
+	    }
 	    break;
 	case DISPLAY_COLORS_SEPARATION:
 	    if (depth == DISPLAY_DEPTH_8) {
diff -u /home/rjl/cvs/gs/src/gdevdsp.c src/gdevdsp.c
--- /home/rjl/cvs/gs/src/gdevdsp.c	2004-08-26 19:13:08.000000000 +1000
+++ src/gdevdsp.c	2004-09-01 19:08:47.634381760 +1000
@@ -779,7 +779,6 @@
     gs_devn_params *pdevn_params = &ddev->devn_params;
     equivalent_cmyk_color_params *pequiv_colors = &ddev->equiv_cmyk_colors;
     /* Save current data in case we have a problem */
-    gx_device_color_info save_info = dev->color_info;
     gs_devn_params saved_devn_params = *pdevn_params;
     equivalent_cmyk_color_params saved_equiv_colors = *pequiv_colors;
 
@@ -1444,7 +1443,6 @@
     int bpc;	/* bits per component */
     int bpp;	/* bits per pixel */
     int maxvalue;
-    int i;
 
     switch (nFormat & DISPLAY_DEPTH_MASK) {
 	case DISPLAY_DEPTH_1:
@@ -1675,6 +1673,9 @@
     {"64bit/pixel separations, bottom first",
      DISPLAY_COLORS_SEPARATIONS | DISPLAY_ALPHA_NONE | DISPLAY_DEPTH_8 | 
      DISPLAY_BIGENDIAN | DISPLAY_BOTTOMFIRST},
+    {"4bit/pixel CMYK, bottom first",
+     DISPLAY_COLORS_CMYK | DISPLAY_ALPHA_NONE | DISPLAY_DEPTH_1 | 
+     DISPLAY_BIGENDIAN | DISPLAY_BOTTOMFIRST},
     {"1bit/pixel native, black is 1, 8 byte alignment",
      DISPLAY_COLORS_NATIVE | DISPLAY_ALPHA_NONE | DISPLAY_DEPTH_1 | 
      DISPLAY_LITTLEENDIAN | DISPLAY_BOTTOMFIRST | DISPLAY_ROW_ALIGN_8},

_______________________________________________
gs-code-review mailing list
[email protected]
http://www.ghostscript.com/mailman/listinfo/gs-code-review