[gs-commits] rev 11761 - in branches/jpx_openjpeg/gs: base psi

larsu at ghostscript.com larsu at ghostscript.com
Wed Oct 6 12:04:13 UTC 2010


Author: larsu
Date: 2010-10-06 12:04:13 +0000 (Wed, 06 Oct 2010)
New Revision: 11761

Modified:
   branches/jpx_openjpeg/gs/base/sjpx_opj.c
   branches/jpx_openjpeg/gs/psi/zfjpx.c
Log:
Don't scale 12 bit jpx streams from openjpeg to 8 bit.



Modified: branches/jpx_openjpeg/gs/base/sjpx_opj.c
===================================================================
--- branches/jpx_openjpeg/gs/base/sjpx_opj.c	2010-10-06 11:50:11 UTC (rev 11760)
+++ branches/jpx_openjpeg/gs/base/sjpx_opj.c	2010-10-06 12:04:13 UTC (rev 11761)
@@ -112,13 +112,16 @@
     bits = comp->prec;
     p = &comp->data[j];
 
-    if ( bits >= 8 ) {
-        /* shift down to 8 bpp */
-        const int shift = comp->prec > 8 ? comp->prec - 8 : 0;
-        
+    if ( bits > 8 ) {
+        const int shift = bits - 8;
         for ( i = 1; i <= bytes;  ) {
-            dest[i++] = *p++ >> shift;
+	    int value = *p++ << shift;
+	    dest[i++] = (value >> 8) & 0xff;
+	    dest[i++] = (value & 0xff);
         }
+    } else if ( bits == 8 ) {
+	for ( i = 1; i <= bytes;  )
+	    dest[i++] = *p++;
     } else if ( bits == 4 ) {
         /* return two packed pixels per byte */
         for ( i = 1; i <= bytes;  ) {
@@ -380,20 +383,19 @@
             opj_image_t *image = state->opj_image;
             int numcmpts = image->numcomps;
             int bits = image->comps[0].prec;
-            int stride = numcmpts * image->comps[0].w * (bits / 8);
+	    int dst_bits = bits <= 8 ? bits : 16;
+            int stride = (numcmpts * image->comps[0].w * dst_bits + 7) / 8;
             long image_size = stride * image->comps[0].h;
             int clrspc = image->color_space;
             int x, y;
             long usable, done;
 
-            if (bits == 4) stride = (stride + 1) / 2;
-
             /* copy data out of the decoded image data */
             /* be lazy and only write the rest of the current row */
             y = state->offset / stride;
             x = state->offset - y*stride; /* bytes, not samples */
             usable = min(out_size, stride - x);
-            x = x / numcmpts / (bits / 8);               /* now samples */
+            x = x / ((numcmpts * dst_bits + 7) / 8);               /* now samples */
 
             /* Make sure we can return a full pixel.
                This can fail if we get the colorspace wrong. */

Modified: branches/jpx_openjpeg/gs/psi/zfjpx.c
===================================================================
--- branches/jpx_openjpeg/gs/psi/zfjpx.c	2010-10-06 11:50:11 UTC (rev 11760)
+++ branches/jpx_openjpeg/gs/psi/zfjpx.c	2010-10-06 12:04:13 UTC (rev 11761)
@@ -245,10 +245,12 @@
 	return_error(e_Fatal);
 
     bpc = img->comps[0].prec;
+    if (bpc > 8)
+	bpc = 16;
 
     if ((code = dict_alloc(iimemory, 2, &dict)) < 0 ||
 	(code = opj_colorspace(i_ctx_p, img, &rcs)) < 0 ||
-	(code = make_int(&rbpc, (bpc / 8) * 8)) < 0)
+	(code = make_int(&rbpc, bpc)) < 0)
 	return code;
 
     idict_put_string(&dict, "ColorSpace", &rcs);



More information about the gs-commits mailing list