// specialization for type conversion void copyBuf (byte *pTo, const RGB_TRIPLE *const pFrom, int width1, int height1) { for (int iy = 0; iy < height1; iy++) for (int ix = 0; ix < width1; ix++) { RGB_TRIPLE Pix = pFrom[ix + ((height1 - 1 - iy) * width1)]; pTo[ix + iy * width1] = RgbToGray(Pix); } }
VOID ps_setrgbcolor( PDEVDATA pdev, PSRGB *prgb ) /*++ Routine Description: Select a new color into the current graphics state Arguments: pdev - Points to our DEVDATA structure prgb - Specifies the new color to be selected Return Value: NONE --*/ { if (pdev->dm.dmPrivate.dwFlags & PSDEVMODE_BLACK) { // If monochrome flag is set, map all non-white colors to black if (*((ULONG *) prgb) == RGB_WHITE) psputs(pdev, "1 g\n"); else psputs(pdev, "0 g\n"); } else if (pdev->cgs.ulColor != *((ULONG *) prgb)) { PS_FIX psfxRed, psfxGreen, psfxBlue; // Save the new color in the current graphics state structure. pdev->cgs.ulColor = *((ULONG *) prgb); // Convert RGB values from integers in the range of 0-255 // to 24.8 fixed-point values: // fixValue = (rgbValue << 8) / 255 // // Here, we use a simpler formula here to achieve similar results. psfxRed = prgb->red; if (psfxRed > 128) psfxRed++; psfxGreen = prgb->green; if (psfxGreen > 128) psfxGreen++; psfxBlue = prgb->blue; if (psfxBlue > 128) psfxBlue++; if (pdev->dm.dmPublic.dmColor == DMCOLOR_COLOR) { // If all color components have equal value, just output a // gray scale value. Otherwise, output the RGB value. if (psfxRed == psfxGreen && psfxRed == psfxBlue) { psprintf(pdev, "%f g\n", psfxRed); } else { psprintf(pdev, "%f %f %f r\n", psfxRed, psfxGreen, psfxBlue); } } else { // Convert RGB color to grayscale using NTSC formula // and output the grayscale value to the printer. psprintf(pdev, "%f g\n", RgbToGray(psfxRed, psfxGreen, psfxBlue)); } } }