b8180d9f6d41dc708a2f249ba892cbca311e7a06 jcasper Mon Feb 27 11:38:55 2023 -0800 Adding transparency support for colors refs #30569 diff --git src/lib/pscmGfx.c src/lib/pscmGfx.c index ec25f4c..6b3fa00 100644 --- src/lib/pscmGfx.c +++ src/lib/pscmGfx.c @@ -87,37 +87,46 @@ void pscmUnclip(struct pscmGfx *pscm) /* Set clipping rect to cover full thing. */ { pscmSetClip(pscm, 0, 0, pscm->ps->userWidth, pscm->ps->userHeight); } int pscmFindColorIx(struct pscmGfx *pscm, int r, int g, int b) /* Returns closest color in color map to rgb values. If it doesn't * already exist in color map and there's room, it will create * exact color in map. */ { return MAKECOLOR_32(r,g,b); } +int pscmFindAlphaColorIx(struct pscmGfx *pscm, int r, int g, int b, int a) +/* Returns closest color in color map to rgba values. If it doesn't + * already exist in color map and there's room, it will create + * exact color in map. */ +{ +return MAKECOLOR_32_A(r,g,b,a); +} + struct rgbColor pscmColorIxToRgb(struct pscmGfx *pscm, int colorIx) /* Return rgb value at color index. */ { static struct rgbColor rgb; -rgb.r = (colorIx >> 0) & 0xff; -rgb.g = (colorIx >> 8) & 0xff; -rgb.b = (colorIx >> 16) & 0xff; +rgb.r = COLOR_32_RED(colorIx); +rgb.g = COLOR_32_GREEN(colorIx); +rgb.b = COLOR_32_BLUE(colorIx); +rgb.a = COLOR_32_ALPHA(colorIx); return rgb; } void pscmSetWriteMode(struct pscmGfx *pscm, unsigned int writeMode) /* Set write mode */ { pscm->writeMode = writeMode; } struct pscmGfx *pscmOpen(int width, int height, char *file) /* Return new pscmGfx. */ { struct pscmGfx *pscm; @@ -134,42 +143,35 @@ void pscmClose(struct pscmGfx **pPscm) /* Finish writing out and free structure. */ { struct pscmGfx *pscm = *pPscm; if (pscm != NULL) { psClose(&pscm->ps); colHashFree(&pscm->colorHash); freez(pPscm); } } void pscmSetColor(struct pscmGfx *pscm, Color color) /* Set current color to Color. */ { -struct rgbColor *col; - -struct rgbColor myCol; -col = &myCol; - -col->r = (color >> 0) & 0xff; -col->g = (color >> 8) & 0xff; -col->b = (color >> 16) & 0xff; - +struct rgbColor col = colorIxToRgb(color); if (color != pscm->curColor) { - psSetColor(pscm->ps, col->r, col->g, col->b); + psSetColor(pscm->ps, col.r, col.g, col.b); + psSetColorAlpha(pscm->ps, (int)col.a); pscm->curColor = color; } } void pscmBoxToPs(struct pscmGfx *pscm, int x, int y, int width, int height) /* adjust coordinates for PS */ { /* Do some clipping here to make the postScript * easier to edit in illustrator. */ double x2 = x + width; double y2 = y + height; if (x < pscm->clipMinX) x = pscm->clipMinX; if (y < pscm->clipMinY) y = pscm->clipMinY; @@ -775,30 +777,31 @@ struct vGfx *vgOpenPostScript(int width, int height, char *fileName) /* Open up something that will someday be a PostScript file. */ { struct vGfx *vg = vgHalfInit(width, height); vg->data = pscmOpen(width, height, fileName); vg->close = (vg_close)pscmClose; vg->dot = (vg_dot)pscmDot; vg->box = (vg_box)pscmBox; vg->line = (vg_line)pscmLine; vg->text = (vg_text)pscmText; vg->textRight = (vg_textRight)pscmTextRight; vg->textCentered = (vg_textCentered)pscmTextCentered; vg->textInBox = (vg_textInBox)pscmTextInBox; vg->findColorIx = (vg_findColorIx)pscmFindColorIx; +vg->findAlphaColorIx = (vg_findAlphaColorIx)pscmFindAlphaColorIx; vg->colorIxToRgb = (vg_colorIxToRgb)pscmColorIxToRgb; vg->setClip = (vg_setClip)pscmSetClip; vg->unclip = (vg_unclip)pscmUnclip; vg->verticalSmear = (vg_verticalSmear)pscmVerticalSmear; vg->fillUnder = (vg_fillUnder)pscmFillUnder; vg->drawPoly = (vg_drawPoly)pscmDrawPoly; vg->ellipse = (vg_ellipse)pscmEllipse; vg->circle = (vg_circle)pscmCircle; vg->curve = (vg_curve)pscmCurve; vg->setHint = (vg_setHint)pscmSetHint; vg->getHint = (vg_getHint)pscmGetHint; vg->getFontPixelHeight = (vg_getFontPixelHeight)pscmGetFontPixelHeight; vg->getFontStringWidth = (vg_getFontStringWidth)pscmGetFontStringWidth; vg->setWriteMode = (vg_setWriteMode)pscmSetWriteMode; vg->setFontMethod = (vg_setFontMethod)pscmSetFontMethod;