CP1215 yellow alignment [solved]
Posted by: stefandoesinger ()
Date: September 22, 2009 05:26AM

I have the issue described in http://foo2zjs.rkkda.com/forum/read.php?57,1481 , but the topic is closed so I have to start a new topic.

Printing something like this: http://stud4.tuwien.ac.at/~e0526822/colorline.ps
Looks like this: http://stud4.tuwien.ac.at/~e0526822/colorline.jpg

This happens with both foo2hp and hplip. The Windows drivers works fine. There is however some oddity with remote printing on Windows: The same problem occurs if the driver is installed manually. Remote printing works if I let windows fetch the driver from the Windows server. I have described this behavior here: https://bugs.launchpad.net/hplip/+bug/403052 (Yes, I am aware hplip != foo2hp, but I don't want to type all this again)

I suspect that there are different kinds of CP1215 printers, and some have proper yellow alignment, while others don't, and the windows driver knows about this and corrects this in software. Is there any way to dump information about the printer? Or is the serial number all we have?

I pledge a $100 donation to the foo2hp project if this issue is resolved, even if its hacky workaround that requires me to configure some yellow offset in the ppd file manually.



Edited 1 time(s). Last edit at 10/13/2009 04:18PM by rickrich.

Re: CP1215 yellow alignment
Posted by: stefandoesinger ()
Date: September 22, 2009 09:34AM

I coded a very hacky patch to work around this issue.

It shifts the yellow channel when splitting the CYMK image into separate planes. The obvious problems are:

-> The offset is hardcoded in the code, and it will break printers that currently work
-> The yellow plane is cropped off at the edges, so the top area of a page might still show incorrect colors
-> The offset is in rows in memory, which probably doesn't have a fixed relation to the offset on the paper. It would probably be better to specify the offset in inches, and change the effective row offset based on the resolution.
-> This should be configurable via command line parameters and settings in the PPD file

And most likely many other issues.

So to reiterate and slightly change my contribution pledge to the driver maintainer:

* $50 if you can clean up this hack, and add a setting in the ppd

* $150 if you can figure out why some printers have this yellow alignment issue and find a proper fix that works out of the box without requiring that the user sets magic offsets.

* $200 if you can get the same color representation as in the windows driver without requiring the user to mess with ICC profiles. Currently the driver mixes small black dots into a 0xffff00 yellow(RGB color), and similar problems, which doesn't seem right to me.

The windows driver also seems to mix colors with better details, it is visible that a dark green is a mixture of yellow, cyan and black dots. With the windows printout this is still visible, but much less obvious(needs a magnifying glass to really see it). I am not sure yet where this comes from - probably 1bpp vs 2bpp mode?

Here's the patch:
--- foo2zjs-orig/foo2hp.c	2009-04-22 14:56:16.000000000 +0200
+++ foo2zjs/foo2hp.c	2009-09-22 15:13:54.000000000 +0200
@@ -800,6 +800,7 @@
     int			bpl = (w + 7) / 8;
     int			i;
     int			x, y;
+    int			y_y; // TODO: c_y, m_y, k_y;
     unsigned char	byte;
     unsigned char	mask[8] = { 128, 64, 32, 16, 8, 4, 2, 1 };
     int			aib = AllIsBlack;
@@ -810,6 +811,11 @@
     for (i = 0; i < 4; ++i)
 	memset(plane, 0, bpl * h);
 
+/* TODO: Make this configurable */
+#define C_YOFFSET (0)
+#define Y_YOFFSET (-18)
+#define M_YOFFSET (0)
+#define K_YOFFSET (0)
     //
     // Unpack the combined plane into individual color planes
     //
@@ -817,6 +823,10 @@
     //
     for (y = 0; y < h; ++y)
     {
+	//c_y = y + C_YOFFSET;
+	y_y = y + Y_YOFFSET;
+	//m_y = y + M_YOFFSET;
+	//k_y = y + K_YOFFSET;
 	for (x = 0; x < w; ++x)
 	{
 	    byte = raw[y*rawbpl + x/2];
@@ -832,7 +842,7 @@
 		{
 		    if (byte & 0x80) plane[0][y*bpl + x/8] |= mask[x&7];
 		    if (byte & 0x40) plane[1][y*bpl + x/8] |= mask[x&7];
-		    if (byte & 0x20) plane[2][y*bpl + x/8] |= mask[x&7];
+		    if (byte & 0x20 && y_y > 0 && y_y < h) plane[2][y_y*bpl + x/8] |= mask[x&7];
 		    if (byte & 0xE0) AnyColor |= byte;
 		}
 	    }
@@ -840,7 +850,7 @@
 	    {
 		if (byte & 0x80) plane[0][y*bpl + x/8] |= mask[x&7];
 		if (byte & 0x40) plane[1][y*bpl + x/8] |= mask[x&7];
-		if (byte & 0x20) plane[2][y*bpl + x/8] |= mask[x&7];
+		if (byte & 0x20 && y_y >= 0 && y_y < h) plane[2][y_y*bpl + x/8] |= mask[x&7];
 		if (byte & 0xE0) AnyColor |= byte;
 	    }
 
@@ -856,7 +866,7 @@
 		{
 		    if (byte & 0x8) plane[0][y*bpl + x/8] |= mask[x&7];
 		    if (byte & 0x4) plane[1][y*bpl + x/8] |= mask[x&7];
-		    if (byte & 0x2) plane[2][y*bpl + x/8] |= mask[x&7];
+		    if (byte & 0x2 && y_y > 0 && y_y < h) plane[2][y_y*bpl + x/8] |= mask[x&7];
 		    if (byte & 0xE) AnyColor |= byte;
 		}
 	    }
@@ -864,7 +874,7 @@
 	    {
 		if (byte & 0x8) plane[0][y*bpl + x/8] |= mask[x&7];
 		if (byte & 0x4) plane[1][y*bpl + x/8] |= mask[x&7];
-		if (byte & 0x2) plane[2][y*bpl + x/8] |= mask[x&7];
+		if (byte & 0x2 && y_y > 0 && y_y < h) plane[2][y_y*bpl + x/8] |= mask[x&7];
 		if (byte & 0xE) AnyColor |= byte;
 	    }
 	}

If the in-comment diff doesn't work: http://stud4.tuwien.ac.at/~e0526822/cp1215-yoffset.diff
I don't think this file can remain online for an eternity, it will probably go away once I finish university in a few years.

Re: CP1215 yellow alignment
Posted by: rickrich ()
Date: September 22, 2009 09:39PM

From the Changelog:
2009-09-22      Rick Richardson <rick.richardson@comcast.net>
        * foo2hp, foo2hp2600-wrapper, foomatic, and PPD's:
            HP LJC CP1215: Add alignment for Cyan, Magenta, or Yellow.

Re: CP1215 yellow alignment
Posted by: stefandoesinger ()
Date: September 29, 2009 03:11PM

Cool stuff, I'll look at this tomorrow. I guess its time to warm up my Google Checkout account :-)

Re: CP1215 yellow alignment
Posted by: soifran ()
Date: October 05, 2009 04:53AM

things are going a lot better for me, foo2hp on ubuntu 8.04
it's not yet perfect but the ability to set the colors alignement is very useful, making this driver the best so far solution to my opinion, to work under linux without wine / virtualization solutions.

trying to decide my organisation to sponsorize (a bit) this project

thanks a lot for all that work

Re: CP1215 yellow alignment [solved]
Posted by: jkan ()
Date: October 25, 2009 12:13PM

The following patch adds color alignment and support of AllIsBlack
and BlackClears functionality in 2bit mode. Tested on my CP1215.



--- foo2hp.c.orig	2009-10-06 13:59:36.000000000 +0200
+++ foo2hp.c	2009-10-25 17:03:30.000000000 +0100
@@ -935,12 +935,66 @@
 int
 pksm_page(unsigned char *plane[4], int w, int h, FILE *ofp)
 {
-    int i;
+    int i, j;
     unsigned char *bitmaps[4];
 
-    for (i = 0; i < 4; ++i)
-	bitmaps = plane;
+    int w16;
+    int bpl;
+
+    if (Bpp == 2)
+        w16 = (w + 63) & ~63;
+    else
+        w16 = (w + 127) & ~127;
+
+    // bytes per line
+    bpl = (w16 * Bpp + 7) / 8;
+
+    if (AnyColor && (AllIsBlack || BlackClears))
+    {
+	for (i = 0; i < h * bpl; ++i) 
+	{
+	    for (j = 0; j < 8; j += Bpp) 
+	    {
+  	        unsigned char mask = (Bpp == 2 ? 0x03 : 0x01) << j;
+
+		if ((BlackClears && (plane[3] & mask) == mask) ||
+		    (AllIsBlack && (plane[0] & plane[1] & plane[2] & mask) == mask)) 
+		{
+		    plane[0] &= ~mask;
+		    plane[1] &= ~mask;
+		    plane[2] &= ~mask;
+		    plane[3] |= mask;
+		}
+	    }
+	}
+    }
 
+
+    for (i = 0; i < 4; ++i) 
+    {
+         if (CMYK_Offset) 
+	 {
+	     unsigned char *tmp = malloc(h * bpl);
+	     if (!tmp) error(3, "Cannot allocate space for bitmap\n");
+	     debug(1, "malloc bitmaps[%d] = %x\n", i, tmp);
+
+	     if (CMYK_Offset < 0) 
+	     {
+	         memcpy(tmp, plane - CMYK_Offset * bpl, (h + CMYK_Offset) * bpl);
+		 memset(tmp + (h + CMYK_Offset) * bpl, 0, -CMYK_Offset * bpl);
+	     }
+	     else 
+	     {
+	         memcpy(tmp + (CMYK_Offset * bpl), plane, (h - CMYK_Offset)  * bpl);
+		 memset(tmp, 0, CMYK_Offset * bpl);
+	     }
+
+	     free(plane);
+	     plane = tmp;
+	 }
+	 bitmaps = plane;
+    }
+  
     if (Color2Mono)
 	write_bitmap_page(w, h, 1, &bitmaps[Color2Mono-1], ofp);
     else if (AnyColor)

Sorry, only registered users may post in this forum.
This forum powered by Phorum.