Bug 689520 - Regression: 1bpp and grayscale output broken
Summary: Regression: 1bpp and grayscale output broken
Status: NOTIFIED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: Graphics Library (show other bugs)
Version: master
Hardware: PC All
: P1 normal
Assignee: leonardo
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-10-16 13:06 UTC by Marcos H. Woehrmann
Modified: 2008-12-19 08:31 UTC (History)
0 users

See Also:
Customer: 531
Word Size: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marcos H. Woehrmann 2007-10-16 13:06:03 UTC
Starting with r8170 1bpp and grayscale output generates a core dump with the attached file.  I've tested 
with tiffg4, pbm, and pgm and all fail; ppm, tiff24nc, and tiff32nc work.

The command line I'm using for testing:

  bin/gs -sDEVICE=tiffg4 -sOutputFile=test.tif ./1_1_2.pdf

I've assigned the bug to the engineer who made the change.
Comment 1 Marcos H. Woehrmann 2007-10-16 13:07:05 UTC
Created attachment 3481 [details]
1_1_2.pdf
Comment 2 leonardo 2007-10-16 22:45:52 UTC
Marcos, could you please identify the breaking patch ? Thanks.
Comment 3 Marcos H. Woehrmann 2007-10-17 13:47:36 UTC
I believe the change to src/gdevp14.c  was responsible.

marcos@amd64:[16]% svn diff -r8169:8170
Index: src/lib.mak
===============================================================
====
--- src/lib.mak (revision 8169)
+++ src/lib.mak (revision 8170)
@@ -2569,7 +2569,7 @@
 gsipar3x_h=$(GLSRC)gsipar3x.h $(gsiparam_h) $(gsiparm3_h)
 gximag3x_h=$(GLSRC)gximag3x.h $(gsipar3x_h) $(gxiparam_h)
 gxblend_h=$(GLSRC)gxblend.h
-gdevp14_h=$(GLSRC)gdevp14.h
+gdevp14_h=$(GLSRC)gdevp14.h $(GLSRC)gxcmap.h
 
 $(GLOBJ)gstrans.$(OBJ) : $(GLSRC)gstrans.c $(GXERR)\
  $(math__h) $(memory__h) $(gdevp14_h)\
Index: src/gdevp14.c
===============================================================
====
--- src/gdevp14.c       (revision 8169)
+++ src/gdevp14.c       (revision 8170)
@@ -1936,7 +1936,14 @@
            pis->get_cmap_procs = p14dev->save_get_cmap_procs;
            gx_set_cmap_procs(pis, p14dev->target);
            /* Send image out raster data to output device */
-            p14dev->pdf14_procs->put_image(pdev, pis, p14dev->target);
+           {   /* hack: Reset lop_pdf14, which could be set by 
+                  pdf14_fill_path, pdf14_stroke_path
+                  to prevent a failure ingx_image_enum_begin. */
+               gs_imager_state new_is = *pis;
+
+               new_is.log_op &= ~lop_pdf14;
+               p14dev->pdf14_procs->put_image(pdev, &new_is, p14dev->target);
+           }
            pdf14_disable_device(pdev);
            pdf14_close(pdev);
            break;
@@ -2661,7 +2668,6 @@
     p14dev->save_get_cmap_procs = pis->get_cmap_procs;
     pis->get_cmap_procs = pdf14_get_cmap_procs;
     gx_set_cmap_procs(pis, (gx_device *)p14dev);
-
     code = dev_proc((gx_device *) p14dev, open_device) ((gx_device *) p14dev);
     *pdev = (gx_device *) p14dev;
     pdf14_set_marking_params((gx_device *)p14dev, pis);
@@ -3327,6 +3333,10 @@
 
     code = dev_proc((gx_device *) pdev, open_device) ((gx_device *) pdev);
     pdev->pclist_device = target;
+    pdev->my_encode_color = pdev->procs.encode_color;
+    pdev->my_decode_color = pdev->procs.decode_color;
+    pdev->my_get_color_mapping_procs = pdev->procs.get_color_mapping_procs;
+    pdev->my_get_color_comp_index = pdev->procs.get_color_comp_index;
     *ppdev = (gx_device *) pdev;
     return code;
 }
@@ -3775,6 +3785,14 @@
                /* Re-activate the PDF 1.4 compositor */
                pdev->saved_target_color_info = pdev->target->color_info;
                pdev->target->color_info = pdev->color_info;
+               pdev->saved_target_encode_color = pdev->target->procs.encode_color;
+               pdev->saved_target_decode_color = pdev->target->procs.decode_color;
+               pdev->target->procs.encode_color = pdev->procs.encode_color = pdev-
>my_encode_color;
+               pdev->target->procs.decode_color = pdev->procs.decode_color = pdev-
>my_decode_color;
+               pdev->saved_target_get_color_mapping_procs = pdev->target-
>procs.get_color_mapping_procs;
+               pdev->saved_target_get_color_comp_index = pdev->target->procs.get_color_comp_index;
+               pdev->target->procs.get_color_mapping_procs = pdev->procs.get_color_mapping_procs = 
pdev->my_get_color_mapping_procs;
+               pdev->target->procs.get_color_comp_index = pdev->procs.get_color_comp_index = pdev-
>my_get_color_comp_index;
                pdev->save_get_cmap_procs = pis->get_cmap_procs;
                pis->get_cmap_procs = pdf14_get_cmap_procs;
                gx_set_cmap_procs(pis, dev);
@@ -3806,6 +3824,10 @@
                pdf14_clist_get_param_compressed_color_list(pdev);
                /* Restore the color_info for the clist device */
                pdev->target->color_info = pdev->saved_target_color_info;
+               pdev->target->procs.encode_color = pdev->saved_target_encode_color;
+               pdev->target->procs.decode_color = pdev->saved_target_decode_color;
+               pdev->target->procs.get_color_mapping_procs = pdev-
>saved_target_get_color_mapping_procs;
+               pdev->target->procs.get_color_comp_index = pdev->saved_target_get_color_comp_index;
                pis->get_cmap_procs = pdev->save_get_cmap_procs;
                gx_set_cmap_procs(pis, pdev->target);
                /* Disable the PDF 1.4 compositor */
@@ -3951,7 +3973,7 @@
      * filling and stroking operations.
      */
     new_is.log_op |= lop_pdf14;
-    return gx_default_fill_path(dev, &new_is, ppath, params, pdcolor, pcpath);
+    return gx_forward_fill_path(dev, &new_is, ppath, params, pdcolor, pcpath);
 }
 
 /*
@@ -3982,7 +4004,7 @@
      * filling and stroking operations.
      */
     new_is.log_op |= lop_pdf14;
-    return gx_default_stroke_path(dev, &new_is, ppath, params, pdcolor, pcpath);
+    return gx_forward_stroke_path(dev, &new_is, ppath, params, pdcolor, pcpath);
 }
 
 /*
@@ -4010,7 +4032,7 @@
     if (code < 0)
        return code;
     /* Pass text_begin to the target */
-    code = gx_default_text_begin(dev, pis, text, font, path,
+    code = gx_forward_text_begin(dev, pis, text, font, path,
                                pdcolor, pcpath, memory, &penum);
     if (code < 0)
        return code;
@@ -4039,7 +4061,7 @@
     if (code < 0)
        return code;
     /* Pass image to the target */
-    return gx_default_begin_image(dev, pis, pim, format, prect,
+    return gx_forward_begin_image(dev, pis, pim, format, prect,
                                        pdcolor, pcpath, memory, pinfo);
 }
 
@@ -4064,7 +4086,7 @@
     if (code < 0)
        return code;
     /* Pass image to the target */
-    return gx_default_begin_typed_image(dev, pis, pmat,
+    return gx_forward_begin_typed_image(dev, pis, pmat,
                            pic, prect, pdcolor, pcpath, mem, pinfo);
 }
 
@@ -4100,6 +4122,14 @@
            p14dev = (pdf14_clist_device *)(*pcdev);
            p14dev->saved_target_color_info = dev->color_info;
            dev->color_info = (*pcdev)->color_info;
+           p14dev->saved_target_encode_color = dev->procs.encode_color;
+           p14dev->saved_target_decode_color = dev->procs.decode_color;
+           dev->procs.encode_color = p14dev->procs.encode_color = p14dev->my_encode_color;
+           dev->procs.decode_color = p14dev->procs.decode_color = p14dev->my_decode_color;
+           p14dev->saved_target_get_color_mapping_procs = dev->procs.get_color_mapping_procs;
+           p14dev->saved_target_get_color_comp_index = dev->procs.get_color_comp_index;
+           dev->procs.get_color_mapping_procs = p14dev->procs.get_color_mapping_procs = p14dev-
>my_get_color_mapping_procs;
+           dev->procs.get_color_comp_index = p14dev->procs.get_color_comp_index = p14dev-
>my_get_color_comp_index;
            p14dev->save_get_cmap_procs = pis->get_cmap_procs;
            pis->get_cmap_procs = pdf14_get_cmap_procs;
            gx_set_cmap_procs(pis, dev);
@@ -4143,8 +4173,12 @@
      */
     switch (pdf14pct->params.pdf14_op) {
        case PDF14_PUSH_DEVICE:
+#          if 0 /* Disabled because *p14dev has no forwarding methods during the clist playback. 
+                   This code is not executed while clist writing. */
            p14dev->saved_target_color_info = cdev->color_info;
            cdev->color_info = p14dev->color_info;
+            */
+#          endif
            /*
             * If we are blending using spot colors (i.e. the output device
             * supports spot colors) then we need to transfer compressed
@@ -4185,7 +4219,10 @@
            }
            break;
        case PDF14_POP_DEVICE:
+#          if 0 /* Disabled because *p14dev has no forwarding methods during the clist playback. 
+                   This code is not executed while clist writing. */
            cdev->color_info = p14dev->saved_target_color_info;
+#          endif
            break;
        default:
            break;              /* do nothing for remaining ops */
Index: src/gdevp14.h
===============================================================
====
--- src/gdevp14.h       (revision 8169)
+++ src/gdevp14.h       (revision 8170)
@@ -16,6 +16,8 @@
 #ifndef gdevp14_INCLUDED
 #  define gdevp14_INCLUDED
 
+#include "gxcmap.h"
+
 typedef enum {
     PDF14_DeviceGray = 0,
     PDF14_DeviceRGB = 1,
@@ -134,6 +136,14 @@
     const gx_color_map_procs *(*save_get_cmap_procs)(const gs_imager_state *,
                                                     const gx_device *);
     gx_device_color_info saved_target_color_info;
+    dev_proc_encode_color(*saved_target_encode_color);
+    dev_proc_decode_color(*saved_target_decode_color);
+    dev_proc_get_color_mapping_procs(*saved_target_get_color_mapping_procs);
+    dev_proc_get_color_comp_index(*saved_target_get_color_comp_index);
+    dev_proc_encode_color(*my_encode_color);
+    dev_proc_decode_color(*my_decode_color);
+    dev_proc_get_color_mapping_procs(*my_get_color_mapping_procs);
+    dev_proc_get_color_comp_index(*my_get_color_comp_index);
 } pdf14_device_t;
 
 /*
Index: src/gdevm4.c
===============================================================
====
--- src/gdevm4.c        (revision 8169)
+++ src/gdevm4.c        (revision 8170)
@@ -29,7 +29,7 @@
 
 /* The device descriptor. */
 const gx_device_memory mem_mapped4_device =
-mem_device("image4", 4, 0,
+mem_device("image4", 3, 1,
           mem_mapped_map_rgb_color, mem_mapped_map_color_rgb,
   mem_mapped4_copy_mono, mem_mapped4_copy_color, mem_mapped4_fill_rectangle,
           mem_gray_strip_copy_rop);

marcos@amd64:[17]% 

Comment 4 Marcos H. Woehrmann 2007-10-17 13:54:02 UTC
BTW, this is the error:

GPL Ghostscript SVN PRE-RELEASE 8.61: ./src/gxclrast.c(1552): Bad op ff band y0 = 405 file pos 4096 
buf pos 1388/4096
   0: 20 ff 30 00 95 03 a0 14 51 00
  10: d3 84 00 00 80 3f 00 00 d8 44
  20: df 01 03 00 00 00 00 00 d3 1c
  30: 00 00 10 c2 83 76 18 45 cc f8
.
.
.
Comment 5 leonardo 2007-10-18 12:11:26 UTC
Marcos, I didn't mean to copy the patch to here. I only wanted the revision 
number, because I didn't notice one in Dwescriotion. I'm sorry.

However I'm not clear why it is a 'regression'. The nightly regression tool 
doesn'r report a regression with pgmraw. Or maybe I missed something ?

Meanwhile I could reproduce the problem with the attached file with tiffg4 and 
pgmraw. I'll work on it.
Comment 6 Marcos H. Woehrmann 2007-10-18 12:29:25 UTC
Sorry, I misunderstood your comment #2.

The reason that the nightly regression test didn't show a problem is that the regression does not show up 
on all (most?) files.  I've added the 1_1_2.pdf file to the regression set.
Comment 7 leonardo 2007-10-18 12:42:07 UTC
I've got a 490MBytes trace with :

..\..\gs-hd\bin\gswin32c.exe -IF:/AFPL/gs-hd/lib;f:\afpl\fonts -ZL -r300 -
dNOPAUSE -dBATCH -d/DEBUG -dEPSFitPage -sDEVICE=pgmraw -sOutputFile=cur.ppm 
attachment.pdf 2>o

Here is a quote from (near) its end :


[L]rmoveto: (9945,283) 396.668 2187.86
[L]vlineto: -1591.69
[L]stroke:
[L]end_run:
[L]set_ctm: [29.1667 0 0 -29.1667 10093.8 5315.67]
[L]put_params:[L]set_ctm: [29.1667 0 0 -29.1667 10093.8 5315.67]
[L]put_params:[L]end_run:
[L]set_ctm: [29.1667 0 0 -29.1667 10025 5349]
[L]put_params:[L]set_ctm: [29.1667 0 0 -29.1667 10025 5349]
[L]put_params:[L]end_run:
[L]set_ctm: [4.16667 0 0 -4.16667 0 5699]
[L]put_params:[L]set_ctm: [4.16667 0 0 -4.16667 0 5699]
[L]put_params:[L]end_run:
[L]set_misc: lop=0x40fc
[L]put_params:[L]rmoveto: (10341,879) -25.375 1556.42
[L]vlineto: -933.336
[L]hlineto: -325
[L]vlineto: 933.336
[L]closepath:
[L]eofill:
[L]end_run:
[L]set_ctm: [1.25e-005 -932.335 -325 -0 10315.6 934.417]
[L]put_params:[L]set_ctm: [1.25e-005 -932.335 -325 -0 10315.6 934.417]
[L]put_params:[L]set_ctm: [1.25e-005 -932.335 -325 -0 10315.6 934.417]
[L]put_params:[L]set_ctm: [1.25e-005 -932.335 -325 -0 10315.6 934.417]
[L]put_params:[L]end_run:
[L]disable_lop:
[L]set_color[1] 0: 0x       0000000ff
[L]?ff?:
GPL Ghostscript SVN PRE-RELEASE 8.61: f:\afpl\gs-hd\src\gxclrast.c(1552): Bad 
op ff band y0 = 1501 file pos 4096 buf pos 1400/4096


I guess the clist reader expects a wrong number of color components.
Comment 8 leonardo 2007-10-19 00:15:28 UTC
Regarding Comment #6 : I believe that regrssions is a failure against our 
testbase (comparefiles). Any filure besides that is a new bug. If Support has 
more test files, they need to be added to Artifex test base. Please proceed 
with Henry about that.

Comment 9 Marcos H. Woehrmann 2007-10-19 06:44:15 UTC
I've tried added the 1_1_2.pdf file to our regression test files, however, with
gshead pkmraw output locks up, which isn't handled very well by the regression
system.  
Comment 10 Marcos H. Woehrmann 2007-10-24 13:02:54 UTC
I've received a file from a customer that exhibits a different failure with pbmraw output.  Instead of core 
dumping file causes Ghostscript r8170 and newer to lock up.  Let me know if this file is of interest and I'll 
add it to the bug report.
Comment 11 leonardo 2007-11-01 09:49:16 UTC
The command line for a better trace :

..\..\gs-hd\bin\gswin32c.exe -IF:/AFPL/gs-hd/lib;f:\afpl\fonts -ZLv! -r300 -
dNOPAUSE -dBATCH -d/DEBUG -dEPSFitPage -sDEVICE=pgmraw -sOutputFile=cur.ppm 
attachment.pdf 2>o
Comment 12 leonardo 2007-11-17 20:22:32 UTC
Created attachment 3567 [details]
simplified.pdf

A simplified test file.
Comment 13 leonardo 2007-11-17 20:24:41 UTC
Created attachment 3568 [details]
decompr-simplified.pdf

The simplified test with decompressed streams.
Comment 14 leonardo 2007-11-17 20:47:33 UTC
Created attachment 3569 [details]
simplified2.pdf

Finally simplified text case. Manually removed all objects except one image.
Comment 15 leonardo 2007-11-18 08:51:18 UTC
Patch to HEAD :
http://ghostscript.com/pipermail/gs-cvs/2007-November/007959.html