diff options
author | Roland Mainz <roland.mainz@nrubsig.org> | 2004-10-04 05:04:14 +0000 |
---|---|---|
committer | Roland Mainz <roland.mainz@nrubsig.org> | 2004-10-04 05:04:14 +0000 |
commit | 658b4ed81f777df2d8b9f47904de90bde1897113 (patch) | |
tree | e601f4479e96568797cc2aa9f49465525027de23 /Xprint | |
parent | e622b346113f65788110777d7d1b5fc436600a4d (diff) |
Fix for http://freedesktop.org/bugzilla/show_bug.cgi?id=1299 - Add more
visuals to the Postscript DDX (8bit GrayScale/StaticGray, 1bit
StaticGray and the basic infratructure for "deep" visuals with more
than 8bits per RGB gun).
Diffstat (limited to 'Xprint')
-rw-r--r-- | Xprint/Init.c | 1 | ||||
-rw-r--r-- | Xprint/ps/Ps.h | 2 | ||||
-rw-r--r-- | Xprint/ps/PsArea.c | 81 | ||||
-rw-r--r-- | Xprint/ps/PsColor.c | 105 | ||||
-rw-r--r-- | Xprint/ps/PsInit.c | 232 | ||||
-rw-r--r-- | Xprint/ps/psout.c | 110 | ||||
-rw-r--r-- | Xprint/ps/psout.h | 46 |
7 files changed, 432 insertions, 145 deletions
diff --git a/Xprint/Init.c b/Xprint/Init.c index 4160e5c85..cb47fa144 100644 --- a/Xprint/Init.c +++ b/Xprint/Init.c @@ -163,6 +163,7 @@ static PixmapFormatRec PSPixmapFormats[] = { { 1, 1, BITMAP_SCANLINE_PAD }, { 8, 8, BITMAP_SCANLINE_PAD }, + { 12, 16, BITMAP_SCANLINE_PAD }, { 24, 32, BITMAP_SCANLINE_PAD } }; diff --git a/Xprint/ps/Ps.h b/Xprint/ps/Ps.h index 6bde70f47..1b1f02a1a 100644 --- a/Xprint/ps/Ps.h +++ b/Xprint/ps/Ps.h @@ -556,7 +556,7 @@ extern int PsListInstalledColormaps(ScreenPtr pScreen, XID *pCmapList); extern void PsStoreColors(ColormapPtr pColor, int ndef, xColorItem *pdefs); extern void PsResolveColor(unsigned short *pRed, unsigned short *pGreen, unsigned short *pBlue, VisualPtr pVisual); -extern int PsGetPixelColor(ColormapPtr cMap, int pixval); +extern PsOutColor PsGetPixelColor(ColormapPtr cMap, int pixval); extern void PsSetFillColor(DrawablePtr pDrawable, GCPtr pGC, PsOutPtr psOut, ColormapPtr cMap); diff --git a/Xprint/ps/PsArea.c b/Xprint/ps/PsArea.c index 134686a87..d01ccd2c1 100644 --- a/Xprint/ps/PsArea.c +++ b/Xprint/ps/PsArea.c @@ -131,6 +131,13 @@ PsPutScaledImage(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y, PsOut_Offset(psOut, pDrawable->x, pDrawable->y); pt = (char *)(&i); i = 1; if( pt[0]=='\001' ) swap = 1; else swap = 0; +#ifdef PSOUT_USE_DEEPCOLOR + if( depth==30 ) + { + ErrorF("PsPutScaledImage: Not implemented yet for 30bit\m"); + } + else +#endif /* PSOUT_USE_DEEPCOLOR */ if( depth==24 ) { PsOut_BeginImage(psOut, 0, 0, x, y, w, h, sw, sh, 3); @@ -174,6 +181,34 @@ PsPutScaledImage(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y, else goto error; PsOut_EndImage(psOut); } +#ifdef PSOUT_USE_DEEPCOLOR + else if( (depth > 8) && (depth < 16) ) + { + int rowsiz = PixmapBytePad(w, depth); + PsOut_BeginImage(psOut, 0, 0, x, y, w, h, sw, sh, 3); + for( r=0 ; r<h ; r++ ) + { + short *pt = (short *)&pImage[rowsiz*r]; + for( c=0 ; c<w ; c++,pt++ ) + { + PsOutColor clr = PsGetPixelColor(cMap, (int)(*pt)&0xFFFF); + /* XXX: This needs to be fixed for endian swapping and to support + * depths deeper than 8bit per R-,G-,B-gun... */ + int val = PSOUTCOLOR_TO_RGB24BIT(clr); + char *ipt = (char *)&val; + if( swap ) + { + char tmp[4]; + tmp[0] = ipt[3]; tmp[1] = ipt[2]; tmp[2] = ipt[1]; tmp[3] = ipt[0]; + PsOut_OutImageBytes(psOut, 3, &tmp[1]); + } + else + PsOut_OutImageBytes(psOut, 3, &ipt[1]); + } + } + PsOut_EndImage(psOut); + } +#endif /* PSOUT_USE_DEEPCOLOR */ else if( depth==8 ) { int rowsiz = PixmapBytePad(w, depth); @@ -183,8 +218,9 @@ PsPutScaledImage(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y, char *pt = &pImage[rowsiz*r]; for( c=0 ; c<w ; c++,pt++ ) { - int val = PsGetPixelColor(cMap, (int)(*pt)&0xFF); - char *ipt = (char *)&val; + PsOutColor clr = PsGetPixelColor(cMap, (int)(*pt)&0xFF); + int val = PSOUTCOLOR_TO_RGB24BIT(clr); + char *ipt = (char *)&val; if( swap ) { char tmp[4]; @@ -296,6 +332,14 @@ PsPutScaledImageIM(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y, PsOut_BeginImageCache(psOut, cache_id); #endif + +#ifdef PSOUT_USE_DEEPCOLOR + if( depth==30 ) + { + ErrorF("PsPutScaledImageIM: Not implemented yet for 30bit\m"); + } + else +#endif /* PSOUT_USE_DEEPCOLOR */ if( depth==24 ) { PsOut_BeginImageIM(psOut, 0, 0, x, y, w, h, sw, sh, 3); @@ -339,6 +383,32 @@ PsPutScaledImageIM(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y, else goto error; PsOut_EndImage(psOut); } +#ifdef PSOUT_USE_DEEPCOLOR + else if( (depth > 8) && (depth < 16) ) + { + int rowsiz = PixmapBytePad(w, depth); + PsOut_BeginImageIM(psOut, 0, 0, x, y, w, h, sw, sh, 3); + for( r=0 ; r<h ; r++ ) + { + short *pt = (short *)&pImage[rowsiz*r]; + for( c=0 ; c<w ; c++,pt++ ) + { + PsOutColor clr = PsGetPixelColor(cMap, (int)(*pt)&0xFFFF); + int val = PSOUTCOLOR_TO_RGB24BIT(clr); + char *ipt = (char *)&val; + if( swap ) + { + char tmp[4]; + tmp[0] = ipt[3]; tmp[1] = ipt[2]; tmp[2] = ipt[1]; tmp[3] = ipt[0]; + PsOut_OutImageBytes(psOut, 3, &tmp[1]); + } + else + PsOut_OutImageBytes(psOut, 3, &ipt[1]); + } + } + PsOut_EndImage(psOut); + } +#endif /* PSOUT_USE_DEEPCOLOR */ else if( depth==8 ) { int rowsiz = PixmapBytePad(w, depth); @@ -348,8 +418,11 @@ PsPutScaledImageIM(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y, char *pt = &pImage[rowsiz*r]; for( c=0 ; c<w ; c++,pt++ ) { - int val = PsGetPixelColor(cMap, (int)(*pt)&0xFF); - char *ipt = (char *)&val; + PsOutColor clr = PsGetPixelColor(cMap, (int)(*pt)&0xFF); + /* XXX: This needs to be fixed for endian swapping and to support + * depths deeper than 8bit per R-,G-,B-gun... */ + int val = PSOUTCOLOR_TO_RGB24BIT(clr); + char *ipt = (char *)&val; if( swap ) { char tmp[4]; diff --git a/Xprint/ps/PsColor.c b/Xprint/ps/PsColor.c index da6c82c1d..856e8aab2 100644 --- a/Xprint/ps/PsColor.c +++ b/Xprint/ps/PsColor.c @@ -75,6 +75,8 @@ in this Software without prior written authorization from The Open Group. ********************************************************************/ #include "Ps.h" +#include "mi.h" +#include "micmap.h" #include "gcstruct.h" #include "windowstr.h" #include "colormapst.h" @@ -82,49 +84,25 @@ in this Software without prior written authorization from The Open Group. Bool PsCreateColormap(ColormapPtr pColor) { - int i; - unsigned short rgb; - VisualPtr pVisual = pColor->pVisual; - Pixel pix; - - if( pVisual->class==TrueColor ) - { - for( i=0 ; i<pVisual->ColormapEntries ; i++ ) - { - rgb = (i<<8)|i; - - pColor->red[i].fShared = FALSE; - pColor->red[i].co.local.red = rgb; - pColor->red[i].co.local.green = 0; - pColor->red[i].co.local.blue = 0; - - pColor->green[i].fShared = FALSE; - pColor->green[i].co.local.red = 0; - pColor->green[i].co.local.green = rgb; - pColor->green[i].co.local.blue = 0; - - pColor->blue[i].fShared = FALSE; - pColor->blue[i].co.local.red = 0; - pColor->blue[i].co.local.green = 0; - pColor->blue[i].co.local.blue = rgb; - } - } - return TRUE; + miInitializeColormap(pColor); } void PsDestroyColormap(ColormapPtr pColor) { + /* NO-OP */ } void PsInstallColormap(ColormapPtr pColor) { + miInstallColormap(pColor); } void PsUninstallColormap(ColormapPtr pColor) { + miUninstallColormap(pColor); } int @@ -132,7 +110,7 @@ PsListInstalledColormaps( ScreenPtr pScreen, XID *pCmapList) { - return 0; + return miListInstalledColormaps(pScreen, pCmapList); } void @@ -160,18 +138,71 @@ PsResolveColor( unsigned short *pBlue, VisualPtr pVisual) { + miResolveColor(pRed, pGreen, pBlue, pVisual); } -int +PsOutColor PsGetPixelColor(ColormapPtr cMap, int pixval) { - int r, g, b; - if( cMap->pVisual->class==TrueColor ) return(pixval); - if( pixval<0 || pixval>255 ) return(0); - r = cMap->red[pixval].co.local.red>>8; - g = cMap->red[pixval].co.local.green>>8; - b = cMap->red[pixval].co.local.blue>>8; - return((r<<16)|(g<<8)|b); + VisualPtr v = cMap->pVisual; + switch( v->class ) + { + case TrueColor: + { + PsOutColor p = pixval; + PsOutColor r, g, b; +#ifdef PSOUT_USE_DEEPCOLOR + int shift = 16 - v->bitsPerRGBValue; +#else + int shift = 8 - v->bitsPerRGBValue; +#endif /* PSOUT_USE_DEEPCOLOR */ + + r = ((p & v->redMask) >> v->offsetRed) << shift; + g = ((p & v->greenMask) >> v->offsetGreen) << shift; + b = ((p & v->blueMask) >> v->offsetBlue) << shift; + +#ifdef PSOUT_USE_DEEPCOLOR + return((r<<32)|(g<<16)|b); +#else + return((r<<16)|(g<<8)|b); +#endif /* PSOUT_USE_DEEPCOLOR */ + } + case PseudoColor: + case GrayScale: + case StaticGray: + { + PsOutColor r, g, b; + + if( pixval < 0 || pixval > v->ColormapEntries) + return(0); + + r = cMap->red[pixval].co.local.red; + g = cMap->red[pixval].co.local.green; + b = cMap->red[pixval].co.local.blue; + + if ((v->class | DynamicClass) == GrayScale) + { + /* rescale to gray (see |miResolveColor()|) */ + r = g = b = (30L*r + 59L*g + 11L*b) / 100L; + } + +#ifdef PSOUT_USE_DEEPCOLOR + return((r<<32)|(g<<16)|b); +#else + r >>= 8; + g >>= 8; + b >>= 8; + + return((r<<16)|(g<<8)|b); +#endif /* PSOUT_USE_DEEPCOLOR */ + } + default: + FatalError("PsGetPixelColor: Unsupported visual %x\n", + (int)cMap->pVisual->class); + break; + } + + return 0; /* NO-OP*/ } void diff --git a/Xprint/ps/PsInit.c b/Xprint/ps/PsInit.c index ba7ca5f66..f85ad78b9 100644 --- a/Xprint/ps/PsInit.c +++ b/Xprint/ps/PsInit.c @@ -119,8 +119,18 @@ InitializePsDriver(ndx, pScreen, argc, argv) #endif char **printerNames; int numPrinters; - int nVisuals; - int nDepths; + int nv, /* total number of visuals */ + nv_1bit, /* number of 8bit visuals */ + nv_8bit, /* number of 8bit visuals */ + nv_12bit, /* number of 12bit visuals */ + nv_24bit, /* number of 24bit visuals*/ + nv_30bit; /* number of 30bit visuals*/ + int nd; /* number of depths */ + VisualID *vids_1bit, + *vids_8bit, + *vids_12bit, + *vids_24bit, + *vids_30bit; VisualPtr visuals; DepthPtr depths; VisualID defaultVisual; @@ -179,44 +189,180 @@ InitializePsDriver(ndx, pScreen, argc, argv) /* Will BitmapToRegion make any difference at all? */ pScreen->BitmapToRegion = mfbPixmapToRegion; - nVisuals = 2; - nDepths = 2; - visuals = (VisualPtr)xalloc(nVisuals*sizeof(VisualRec)); - depths = (DepthPtr) xalloc(nDepths*sizeof(DepthRec)); - - visuals[0].vid = FakeClientID(0); - visuals[0].class = TrueColor; - visuals[0].bitsPerRGBValue = 8; - visuals[0].ColormapEntries = 256; - visuals[0].nplanes = 24; - visuals[0].redMask = 0x00FF0000; - visuals[0].greenMask = 0x0000FF00; - visuals[0].blueMask = 0x000000FF; - visuals[0].offsetRed = 16; - visuals[0].offsetGreen = 8; - visuals[0].offsetBlue = 0; - - visuals[1].vid = FakeClientID(0); - visuals[1].class = PseudoColor; - visuals[1].bitsPerRGBValue = 8; - visuals[1].ColormapEntries = 256; - visuals[1].nplanes = 8; - visuals[1].redMask = 0x0; - visuals[1].greenMask = 0x0; - visuals[1].blueMask = 0x0; - visuals[1].offsetRed = 0x0; - visuals[1].offsetGreen = 0x0; - visuals[1].offsetBlue = 0x0; - - depths[0].depth = 24; - depths[0].numVids = 1; - depths[0].vids = (VisualID *)xalloc(sizeof(VisualID)); - depths[0].vids[0] = visuals[0].vid; - - depths[1].depth = 8; - depths[1].numVids = 1; - depths[1].vids = (VisualID *)xalloc(sizeof(VisualID)); - depths[1].vids[0] = visuals[1].vid; + visuals = (VisualPtr) xalloc(8*sizeof(VisualRec)); + depths = (DepthPtr) xalloc(8*sizeof(DepthRec)); + vids_1bit = (VisualID *)xalloc(8*sizeof(VisualID)); + vids_8bit = (VisualID *)xalloc(8*sizeof(VisualID)); + vids_12bit = (VisualID *)xalloc(8*sizeof(VisualID)); + vids_24bit = (VisualID *)xalloc(8*sizeof(VisualID)); + vids_30bit = (VisualID *)xalloc(8*sizeof(VisualID)); + + nv = nv_1bit = nv_8bit = nv_12bit = nv_24bit = nv_30bit = nd = 0; + + /* TrueColor, 24bit */ + visuals[nv].vid = FakeClientID(0); + visuals[nv].class = TrueColor; + visuals[nv].bitsPerRGBValue = 8; + visuals[nv].ColormapEntries = 256; + visuals[nv].nplanes = 24; + visuals[nv].redMask = 0X00FF0000; + visuals[nv].greenMask = 0X0000FF00; + visuals[nv].blueMask = 0X000000FF; + visuals[nv].offsetRed = 16; + visuals[nv].offsetGreen = 8; + visuals[nv].offsetBlue = 0; + vids_24bit[nv_24bit] = visuals[nv].vid; + nv++; nv_24bit++; + + /* PseudoColor, 8bit */ + visuals[nv].vid = FakeClientID(0); + visuals[nv].class = PseudoColor; + visuals[nv].bitsPerRGBValue = 8; + visuals[nv].ColormapEntries = 256; + visuals[nv].nplanes = 8; + visuals[nv].redMask = 0x0; + visuals[nv].greenMask = 0x0; + visuals[nv].blueMask = 0x0; + visuals[nv].offsetRed = 0x0; + visuals[nv].offsetGreen = 0x0; + visuals[nv].offsetBlue = 0x0; + vids_8bit[nv_8bit] = visuals[nv].vid; + nv++; nv_8bit++; + + /* GrayScale, 8bit */ + visuals[nv].vid = FakeClientID(0); + visuals[nv].class = GrayScale; + visuals[nv].bitsPerRGBValue = 8; + visuals[nv].ColormapEntries = 256; + visuals[nv].nplanes = 8; + visuals[nv].redMask = 0x0; + visuals[nv].greenMask = 0x0; + visuals[nv].blueMask = 0x0; + visuals[nv].offsetRed = 0x0; + visuals[nv].offsetGreen = 0x0; + visuals[nv].offsetBlue = 0x0; + vids_8bit[nv_8bit] = visuals[nv].vid; + nv++; nv_8bit++; + + /* StaticGray, 8bit */ + visuals[nv].vid = FakeClientID(0); + visuals[nv].class = StaticGray; + visuals[nv].bitsPerRGBValue = 8; + visuals[nv].ColormapEntries = 256; + visuals[nv].nplanes = 8; + visuals[nv].redMask = 0x0; + visuals[nv].greenMask = 0x0; + visuals[nv].blueMask = 0x0; + visuals[nv].offsetRed = 0x0; + visuals[nv].offsetGreen = 0x0; + visuals[nv].offsetBlue = 0x0; + vids_8bit[nv_8bit] = visuals[nv].vid; + nv++; nv_8bit++; + + /* StaticGray, 1bit */ + visuals[nv].vid = FakeClientID(0); + visuals[nv].class = StaticGray; + visuals[nv].bitsPerRGBValue = 8; + visuals[nv].ColormapEntries = 2; + visuals[nv].nplanes = 1; + visuals[nv].redMask = 0x0; + visuals[nv].greenMask = 0x0; + visuals[nv].blueMask = 0x0; + visuals[nv].offsetRed = 0x0; + visuals[nv].offsetGreen = 0x0; + visuals[nv].offsetBlue = 0x0; + vids_1bit[nv_1bit] = visuals[nv].vid; + nv++; nv_1bit++; + +#ifdef PSOUT_USE_DEEPCOLOR + /* TrueColor, 30bit, 10bit per R-,G-,B-gun */ + visuals[nv].vid = FakeClientID(0); + visuals[nv].class = TrueColor; + visuals[nv].bitsPerRGBValue = 10; + visuals[nv].ColormapEntries = 1024; + visuals[nv].nplanes = 30; + visuals[nv].redMask = 0X3FF00000; + visuals[nv].greenMask = 0X000FFC00; + visuals[nv].blueMask = 0X000003FF; + visuals[nv].offsetRed = 20; + visuals[nv].offsetGreen = 10; + visuals[nv].offsetBlue = 0; + vids_30bit[nv_30bit] = visuals[nv].vid; + nv++; nv_30bit++; + + /* PostScript Level 2 and above, colors can have 12 bits per component + * (36 bit for RGB) */ + + /* GrayScale, 12bit, 12bit per R-,G-,B-gun */ + visuals[nv].vid = FakeClientID(0); + visuals[nv].class = GrayScale; + visuals[nv].bitsPerRGBValue = 12; + visuals[nv].ColormapEntries = 4096; + visuals[nv].nplanes = 12; + visuals[nv].redMask = 0x0; + visuals[nv].greenMask = 0x0; + visuals[nv].blueMask = 0x0; + visuals[nv].offsetRed = 0x0; + visuals[nv].offsetGreen = 0x0; + visuals[nv].offsetBlue = 0x0; + vids_12bit[nv_12bit] = visuals[nv].vid; + nv++; nv_12bit++; + + /* StaticGray, 12bit, 12bit per R-,G-,B-gun */ + visuals[nv].vid = FakeClientID(0); + visuals[nv].class = StaticGray; + visuals[nv].bitsPerRGBValue = 12; + visuals[nv].ColormapEntries = 4096; + visuals[nv].nplanes = 12; + visuals[nv].redMask = 0x0; + visuals[nv].greenMask = 0x0; + visuals[nv].blueMask = 0x0; + visuals[nv].offsetRed = 0x0; + visuals[nv].offsetGreen = 0x0; + visuals[nv].offsetBlue = 0x0; + vids_12bit[nv_12bit] = visuals[nv].vid; + nv++; nv_12bit++; +#endif /* PSOUT_USE_DEEPCOLOR */ + + if( nv_30bit > 0 ) + { + depths[nd].depth = 30; + depths[nd].numVids = nv_30bit; + depths[nd].vids = vids_30bit; + nd++; + } + + if( nv_24bit > 0 ) + { + depths[nd].depth = 24; + depths[nd].numVids = nv_24bit; + depths[nd].vids = vids_24bit; + nd++; + } + + if( nv_12bit > 0 ) + { + depths[nd].depth = 12; + depths[nd].numVids = nv_12bit; + depths[nd].vids = vids_12bit; + nd++; + } + + if( nv_8bit > 0 ) + { + depths[nd].depth = 8; + depths[nd].numVids = nv_8bit; + depths[nd].vids = vids_8bit; + nd++; + } + + if( nv_1bit > 0 ) + { + depths[nd].depth = 1; + depths[nd].numVids = nv_1bit; + depths[nd].vids = vids_1bit; + nd++; + } /* Defaul visual is 8bit PseudoColor */ defaultVisual = visuals[1].vid; @@ -228,7 +374,7 @@ InitializePsDriver(ndx, pScreen, argc, argv) GlxWrapInitVisuals(&proc); /* GlxInitVisuals ignores the last three arguments. */ - proc(&visuals, &depths, &nVisuals, &nDepths, + proc(&visuals, &depths, &nv, &nd, &rootDepth, &defaultVisual, 0, 0, 0); } #endif /* GLXEXT */ @@ -237,8 +383,8 @@ InitializePsDriver(ndx, pScreen, argc, argv) pScreen->width, pScreen->height, (int) (pScreen->width / (pScreen->mmWidth / 25.40)), (int) (pScreen->height / (pScreen->mmHeight / 25.40)), - 0, rootDepth, nDepths, - depths, defaultVisual, nVisuals, visuals); + 0, rootDepth, nd, + depths, defaultVisual, nv, visuals); if( cfbCreateDefColormap(pScreen)==FALSE ) return FALSE; diff --git a/Xprint/ps/psout.c b/Xprint/ps/psout.c index d66374a4c..f156ce81f 100644 --- a/Xprint/ps/psout.c +++ b/Xprint/ps/psout.c @@ -422,17 +422,19 @@ S_OutTok(PsOutPtr self, char *tok, int cr) } static void -S_Color(PsOutPtr self, int clr) +S_Color(PsOutPtr self, PsOutColor clr) { int ir, ig, ib; - ir = clr>>16; ig = (clr>>8)&0xFF; ib = clr&0xFF; + ir = PSOUTCOLOR_TO_REDBITS(clr); + ig = PSOUTCOLOR_TO_GREENBITS(clr); + ib = PSOUTCOLOR_TO_BLUEBITS(clr); if( ir==ig && ig==ib ) - { S_OutNum(self, (float)ir/255.); S_OutTok(self, "g", 1); } + { S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ir)); S_OutTok(self, "g", 1); } else { - S_OutNum(self, (float)ir/255.); - S_OutNum(self, (float)ig/255.); - S_OutNum(self, (float)ib/255.); + S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ir)); + S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ig)); + S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ib)); S_OutTok(self, "sc", 1); } } @@ -636,7 +638,7 @@ PsOut_BeginFile(FILE *fp, char *title, int orient, int count, int plex, int res, /* * Initialize the structure */ - psout->CurColor = 0xFFFFFFFF; + psout->CurColor = PSOUTCOLOR_NOCOLOR; psout->LineWidth = 1; psout->LineCap = PsCButt; psout->LineJoin = PsJMiter; @@ -723,7 +725,7 @@ void PsOut_DirtyAttributes(PsOutPtr self) { int i; - self->CurColor = 0xFFFFFFFF; + self->CurColor = PSOUTCOLOR_NOCOLOR; self->LineWidth = -1; self->LineCap = (PsCapEnum)-1; self->LineJoin = (PsJoinEnum)-1; @@ -911,7 +913,7 @@ PsOut_Clip(PsOutPtr self, int clpTyp, PsClipPtr clpinf) } void -PsOut_Color(PsOutPtr self, int clr) +PsOut_Color(PsOutPtr self, PsOutColor clr) { if( clr==self->CurColor || self->InTile>=PsStip ) return; self->CurColor = clr; @@ -926,7 +928,7 @@ PsOut_FillRule(PsOutPtr self, PsRuleEnum rule) void PsOut_LineAttrs(PsOutPtr self, int wd, PsCapEnum cap, PsJoinEnum join, - int nDsh, int *dsh, int dshOff, int bclr) + int nDsh, int *dsh, int dshOff, PsOutColor bclr) { int i; int same = 1; @@ -973,7 +975,10 @@ PsOut_LineAttrs(PsOutPtr self, int wd, PsCapEnum cap, PsJoinEnum join, S_OutTok(self, "ds", 1); } - if( nDsh ) self->LineBClr = bclr; else bclr = -1; + if( nDsh ) + self->LineBClr = bclr; + else + bclr = PSOUTCOLOR_NOCOLOR; } void @@ -1094,7 +1099,7 @@ PsOut_Lines(PsOutPtr self, int nPts, PsPointPtr pts) if( i==0 ) S_OutTok(self, "m", 0); else S_OutTok(self, "l", 0); } - if( self->LineBClr>=0 ) + if( self->LineBClr != PSOUTCOLOR_NOCOLOR ) { S_OutTok(self, "gs", 0); S_Color(self, self->LineBClr); @@ -1133,7 +1138,7 @@ PsOut_DrawRect(PsOutPtr self, int x, int y, int w, int h) S_OutNum(self, (float)w); S_OutNum(self, (float)h); S_OutTok(self, "R", 0); - if( self->LineBClr>=0 ) + if( self->LineBClr != PSOUTCOLOR_NOCOLOR ) { S_OutTok(self, "gs", 0); S_Color(self, self->LineBClr); @@ -1159,7 +1164,7 @@ PsOut_DrawArc(PsOutPtr self, int x, int y, int w, int h, S_OutNum(self, ang1+ang2); if( ang2<0 ) S_OutTok(self, "An", 0); else S_OutTok(self, "Ac", 0); - if( self->LineBClr>=0 ) + if( self->LineBClr != PSOUTCOLOR_NOCOLOR ) { S_OutTok(self, "gs", 0); S_Color(self, self->LineBClr); @@ -1169,7 +1174,7 @@ PsOut_DrawArc(PsOutPtr self, int x, int y, int w, int h, } void -PsOut_Text(PsOutPtr self, int x, int y, char *text, int textl, int bclr) +PsOut_Text(PsOutPtr self, int x, int y, char *text, int textl, PsOutColor bclr) { int xo = self->XOff; int yo = self->YOff; @@ -1179,21 +1184,23 @@ PsOut_Text(PsOutPtr self, int x, int y, char *text, int textl, int bclr) S_OutStr(self, text, textl); S_OutNum(self, (float)x); S_OutNum(self, (float)y); - if( bclr<0 ) S_OutTok(self, "T", 1); + if( bclr == PSOUTCOLOR_NOCOLOR ) + S_OutTok(self, "T", 1); else { - int ir = bclr>>16; - int ig = (bclr>>8)&0xFF; - int ib = bclr&0xFF; - S_OutNum(self, (float)ir/255.); - S_OutNum(self, (float)ig/255.); - S_OutNum(self, (float)ib/255.); + int ir = PSOUTCOLOR_TO_REDBITS(bclr); + int ig = PSOUTCOLOR_TO_GREENBITS(bclr); + int ib = PSOUTCOLOR_TO_BLUEBITS(bclr); + + S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ir)); + S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ig)); + S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ib)); S_OutTok(self, "Tb", 1); } } void -PsOut_Text16(PsOutPtr self, int x, int y, unsigned short *text, int textl, int bclr) +PsOut_Text16(PsOutPtr self, int x, int y, unsigned short *text, int textl, PsOutColor bclr) { int xo = self->XOff; int yo = self->YOff; @@ -1203,22 +1210,23 @@ PsOut_Text16(PsOutPtr self, int x, int y, unsigned short *text, int textl, int b S_OutStr16(self, text, textl); S_OutNum(self, (float)x); S_OutNum(self, (float)y); - if( bclr<0 ) S_OutTok(self, "T", 1); + if( bclr == PSOUTCOLOR_NOCOLOR ) + S_OutTok(self, "T", 1); else { - int ir = bclr>>16; - int ig = (bclr>>8)&0xFF; - int ib = bclr&0xFF; - S_OutNum(self, (float)ir/255.); - S_OutNum(self, (float)ig/255.); - S_OutNum(self, (float)ib/255.); + int ir = PSOUTCOLOR_TO_REDBITS(bclr); + int ig = PSOUTCOLOR_TO_GREENBITS(bclr); + int ib = PSOUTCOLOR_TO_BLUEBITS(bclr); + S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ir)); + S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ig)); + S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ib)); S_OutTok(self, "Tb", 1); } } #ifdef BM_CACHE void /* new */ -PsOut_ImageCache(PsOutPtr self, int x, int y, long cache_id, int bclr, int fclr) +PsOut_ImageCache(PsOutPtr self, int x, int y, long cache_id, PsOutColor bclr, PsOutColor fclr) { char cacheID[10]; int xo = self->XOff; @@ -1231,22 +1239,26 @@ PsOut_ImageCache(PsOutPtr self, int x, int y, long cache_id, int bclr, int fclr) S_OutNum(self, (float)x); S_OutNum(self, (float)y); - if( fclr==0xFFFFFF ) + if( fclr==PSOUTCOLOR_WHITE ) { - int ir, ig, ib; - ir = bclr>>16; ig = (bclr>>8)&0xFF; ib = bclr&0xFF; + int ir = PSOUTCOLOR_TO_REDBITS(bclr); + int ig = PSOUTCOLOR_TO_GREENBITS(bclr); + int ib = PSOUTCOLOR_TO_BLUEBITS(bclr); + if( ir==ig && ig==ib ) - S_OutNum(self, (float)ir/255.); + S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ir)); else S_OutNum(self, (float)0); self->RevImage = 1; } else { - int ir, ig, ib; - ir = fclr>>16; ig = (fclr>>8)&0xFF; ib = fclr&0xFF; + int ir = PSOUTCOLOR_TO_REDBITS(fclr); + int ig = PSOUTCOLOR_TO_GREENBITS(fclr); + int ib = PSOUTCOLOR_TO_BLUEBITS(fclr); + if( ir==ig && ig==ib ) - S_OutNum(self, (float)ir/255.); + S_OutNum(self, PSOUTCOLOR_BITS_TO_PSFLOAT(ir)); else S_OutNum(self, (float)0); } @@ -1272,10 +1284,10 @@ PsOut_EndImageCache(PsOutPtr self) #endif void -PsOut_BeginImage(PsOutPtr self, int bclr, int fclr, int x, int y, +PsOut_BeginImage(PsOutPtr self, PsOutColor bclr, PsOutColor fclr, int x, int y, int w, int h, int sw, int sh, int format) { - int savClr = self->CurColor; + PsOutColor savClr = self->CurColor; int xo = self->XOff; int yo = self->YOff; @@ -1291,7 +1303,7 @@ PsOut_BeginImage(PsOutPtr self, int bclr, int fclr, int x, int y, S_OutTok(self, "<", 0); self->ImageFormat = format; self->RevImage = 0; - if( self->InTile==PsTile && format==1 && fclr==0xFFFFFF ) + if( self->InTile==PsTile && format==1 && fclr==PSOUTCOLOR_WHITE ) self->RevImage = 1; return; } @@ -1300,7 +1312,7 @@ PsOut_BeginImage(PsOutPtr self, int bclr, int fclr, int x, int y, if( format==1 ) { S_OutTok(self, "gs", 0); - if( fclr==0xFFFFFF ) + if( fclr==PSOUTCOLOR_WHITE ) { PsOut_Color(self, fclr); PsOut_FillRect(self, x, y, sw, sh); @@ -1332,10 +1344,10 @@ PsOut_BeginImage(PsOutPtr self, int bclr, int fclr, int x, int y, } void -PsOut_BeginImageIM(PsOutPtr self, int bclr, int fclr, int x, int y, +PsOut_BeginImageIM(PsOutPtr self, PsOutColor bclr, PsOutColor fclr, int x, int y, int w, int h, int sw, int sh, int format) { - int savClr = self->CurColor; + PsOutColor savClr = self->CurColor; int xo = self->XOff; int yo = self->YOff; @@ -1351,7 +1363,7 @@ PsOut_BeginImageIM(PsOutPtr self, int bclr, int fclr, int x, int y, S_OutTok(self, "<", 0); self->ImageFormat = format; self->RevImage = 0; - if( self->InTile==PsTile && format==1 && fclr==0xFFFFFF ) + if( self->InTile==PsTile && format==1 && fclr==PSOUTCOLOR_WHITE ) self->RevImage = 1; return; } @@ -1363,7 +1375,7 @@ PsOut_BeginImageIM(PsOutPtr self, int bclr, int fclr, int x, int y, #ifdef BM_CACHE S_OutTok(self, "g", 1); #else - if( fclr==0xFFFFFF ) + if( fclr==PSOUTCOLOR_WHITE ) { PsOut_Color(self, bclr); self->RevImage = 1; @@ -1411,7 +1423,7 @@ PsOut_EndImage(PsOutPtr self) S_OutTok(self, ">", 1); if( self->ImageFormat==1 && self->InTile==PsTile ) { - if( self->ImgFClr==0xFFFFFF ) + if( self->ImgFClr==PSOUTCOLOR_WHITE ) { PsOut_Color(self, self->ImgFClr); PsOut_FillRect(self, self->ImgX, self->ImgY, self->SclW, self->SclH); @@ -1509,7 +1521,7 @@ PsOut_EndFrame(PsOutPtr self) int PsOut_BeginPattern(PsOutPtr self, void *tag, int w, int h, PsFillEnum type, - int bclr, int fclr) + PsOutColor bclr, PsOutColor fclr) { int i; char key[64]; @@ -1585,7 +1597,7 @@ PsOut_SetPattern(PsOutPtr self, void *tag, PsFillEnum type) case PsOpStip: key[0] = 'o'; break; } S_OutTok(self, key, 0); S_OutTok(self, "spt", 1); - self->CurColor = 0xFFFFFFFF; + self->CurColor = PSOUTCOLOR_NOCOLOR; } void diff --git a/Xprint/ps/psout.h b/Xprint/ps/psout.h index c592d7250..a9c7d4a51 100644 --- a/Xprint/ps/psout.h +++ b/Xprint/ps/psout.h @@ -153,6 +153,30 @@ typedef enum PsFTDownloadFontType_ PsFontType3 } PsFTDownloadFontType; +#ifdef PSOUT_USE_DEEPCOLOR +typedef long long PsOutColor; +#define PSOUTCOLOR_TO_REDBITS(clr) ((clr) >> 32) +#define PSOUTCOLOR_TO_GREENBITS(clr) (((clr) >> 16) & 0xFFFF) +#define PSOUTCOLOR_TO_BLUEBITS(clr) ((clr) & 0xFFFF) +#define PSOUTCOLOR_BITS_TO_PSFLOAT(b) ((float)(b) / 65535.) +#define PSOUTCOLOR_WHITE (0xFFFFFFFFFFFFLL) +#define PSOUTCOLOR_NOCOLOR (-1LL) +#define PSOUTCOLOR_TO_RGB24BIT(clr) (((PSOUTCOLOR_TO_REDBITS(clr) >> 8) << 16) | \ + ((PSOUTCOLOR_TO_GREENBITS(clr) >> 8) << 8) | \ + ((PSOUTCOLOR_TO_BLUEBITS(clr) >> 8) << 0)) +#else +typedef long PsOutColor; +#define PSOUTCOLOR_TO_REDBITS(clr) ((clr) >> 16) +#define PSOUTCOLOR_TO_GREENBITS(clr) (((clr) >> 8) & 0xFF) +#define PSOUTCOLOR_TO_BLUEBITS(clr) ((clr) & 0xFF) +#define PSOUTCOLOR_BITS_TO_PSFLOAT(b) ((float)(b) / 255.) +#define PSOUTCOLOR_WHITE (0xFFFFFF) +#define PSOUTCOLOR_NOCOLOR (-1) +#define PSOUTCOLOR_TO_RGB24BIT(clr) ((PSOUTCOLOR_TO_REDBITS(clr) << 16) | \ + (PSOUTCOLOR_TO_GREENBITS(clr) << 8) | \ + (PSOUTCOLOR_TO_BLUEBITS(clr) << 0)) +#endif /* PSOUT_USE_DEEPCOLOR */ + #ifdef USE_PSOUT_PRIVATE typedef void *voidPtr; @@ -168,14 +192,14 @@ typedef struct PsOutRec_ { FILE *Fp; char Buf[16384]; - int CurColor; + PsOutColor CurColor; int LineWidth; PsCapEnum LineCap; PsJoinEnum LineJoin; int NDashes; int *Dashes; int DashOffset; - int LineBClr; + PsOutColor LineBClr; PsRuleEnum FillRule; char *FontName; int FontSize; @@ -193,8 +217,8 @@ typedef struct PsOutRec_ PsFillEnum InTile; int ImgSkip; - int ImgBClr; - int ImgFClr; + PsOutColor ImgBClr; + PsOutColor ImgFClr; int ImgX; int ImgY; int ImgW; @@ -230,11 +254,11 @@ extern void PsOut_Offset(PsOutPtr self, int x, int y); extern void PsOut_Clip(PsOutPtr self, int clpTyp, PsClipPtr clpinf); -extern void PsOut_Color(PsOutPtr self, int clr); +extern void PsOut_Color(PsOutPtr self, PsOutColor clr); extern void PsOut_FillRule(PsOutPtr self, PsRuleEnum rule); extern void PsOut_LineAttrs(PsOutPtr self, int wd, PsCapEnum cap, PsJoinEnum join, int nDsh, int *dsh, int dshOff, - int bclr); + PsOutColor bclr); extern void PsOut_TextAttrs(PsOutPtr self, char *fnam, int siz, int iso); extern void PsOut_TextAttrsMtx(PsOutPtr self, char *fnam, float *mtx, int iso); @@ -250,12 +274,12 @@ extern void PsOut_DrawArc(PsOutPtr self, int x, int y, int w, int h, float ang1, float ang2); extern void PsOut_Text(PsOutPtr self, int x, int y, char *text, int textl, - int bclr); -extern void PsOut_Text16(PsOutPtr self, int x, int y, unsigned short *text, int textl, int bclr); + PsOutColor bclr); +extern void PsOut_Text16(PsOutPtr self, int x, int y, unsigned short *text, int textl, PsOutColor bclr); -extern void PsOut_BeginImage(PsOutPtr self, int bclr, int fclr, int x, int y, +extern void PsOut_BeginImage(PsOutPtr self, PsOutColor bclr, PsOutColor fclr, int x, int y, int w, int h, int sw, int sh, int format); -extern void PsOut_BeginImageIM(PsOutPtr self, int bclr, int fclr, int x, int y, +extern void PsOut_BeginImageIM(PsOutPtr self, PsOutColor bclr, PsOutColor fclr, int x, int y, int w, int h, int sw, int sh, int format); extern void PsOut_EndImage(PsOutPtr self); extern void PsOut_OutImageBytes(PsOutPtr self, int nBytes, char *bytes); @@ -265,7 +289,7 @@ extern void PsOut_BeginFrame(PsOutPtr self, int xoff, int yoff, int x, int y, extern void PsOut_EndFrame(PsOutPtr self); extern int PsOut_BeginPattern(PsOutPtr self, void *tag, int w, int h, - PsFillEnum type, int bclr, int fclr); + PsFillEnum type, PsOutColor bclr, PsOutColor fclr); extern void PsOut_EndPattern(PsOutPtr self); extern void PsOut_SetPattern(PsOutPtr self, void *tag, PsFillEnum type); |