| 3182 | } |
| 3183 | |
| 3184 | static int psl_bitimage_cmap (struct PSL_CTRL *PSL, double f_rgb[], double b_rgb[]) { |
| 3185 | /* Print colormap for 1-bit image or imagemask. Returns value of "polarity": |
| 3186 | * 0 = Paint 0 bits foreground color, leave 1 bits transparent |
| 3187 | * 1 = Paint 1 bits background color, leave 0 bits transparent |
| 3188 | * 2 = Paint 0 bits foreground color, paint 1 bits background color |
| 3189 | * ! Note that odd return values indicate that the bitmap has to be |
| 3190 | * ! inverted before plotting, either explicitly, or through a mapping |
| 3191 | * ! function in the PostScript image definition. |
| 3192 | */ |
| 3193 | int polarity; |
| 3194 | double f_cmyk[4], b_cmyk[4]; |
| 3195 | |
| 3196 | PSL_command (PSL, " [/Indexed /Device"); |
| 3197 | if (b_rgb[0] < 0.0) { |
| 3198 | /* Background is transparent */ |
| 3199 | polarity = 0; |
| 3200 | if (PSL_is_gray (f_rgb)) |
| 3201 | PSL_command (PSL, "Gray 0 <%02X>", PSL_u255(f_rgb[0])); |
| 3202 | else if (PSL->internal.color_mode == PSL_GRAY) |
| 3203 | PSL_command (PSL, "Gray 0 <%02X>", PSL_u255(PSL_YIQ(f_rgb))); |
| 3204 | else if (PSL->internal.color_mode == PSL_CMYK) { |
| 3205 | psl_rgb_to_cmyk (f_rgb, f_cmyk); |
| 3206 | PSL_command (PSL, "CMYK 0 <%02X%02X%02X%02X>", PSL_q255(f_cmyk)); |
| 3207 | } |
| 3208 | else |
| 3209 | PSL_command (PSL, "RGB 0 <%02X%02X%02X>", PSL_t255(f_rgb)); |
| 3210 | } |
| 3211 | else if (f_rgb[0] < 0.0) { |
| 3212 | /* Foreground is transparent */ |
| 3213 | polarity = 1; |
| 3214 | if (PSL_is_gray (b_rgb)) |
| 3215 | PSL_command (PSL, "Gray 0 <%02X>", PSL_u255(b_rgb[0])); |
| 3216 | else if (PSL->internal.color_mode == PSL_GRAY) |
| 3217 | PSL_command (PSL, "Gray 0 <%02X>", PSL_u255(PSL_YIQ(b_rgb))); |
| 3218 | else if (PSL->internal.color_mode == PSL_CMYK) { |
| 3219 | psl_rgb_to_cmyk (b_rgb, b_cmyk); |
| 3220 | PSL_command (PSL, "CMYK 0 <%02X%02X%02X%02X>", PSL_q255(b_cmyk)); |
| 3221 | } |
| 3222 | else |
| 3223 | PSL_command (PSL, "RGB 0 <%02X%02X%02X>", PSL_t255(b_rgb)); |
| 3224 | } |
| 3225 | else { |
| 3226 | /* Colored foreground and background */ |
| 3227 | polarity = 2; |
| 3228 | if (PSL_is_gray (b_rgb) && PSL_is_gray (f_rgb)) |
| 3229 | PSL_command (PSL, "Gray 1 <%02X%02X>", PSL_u255(f_rgb[0]), PSL_u255(b_rgb[0])); |
| 3230 | else if (PSL->internal.color_mode == PSL_GRAY) |
| 3231 | PSL_command (PSL, "Gray 1 <%02X%02X>", PSL_u255(PSL_YIQ(f_rgb)), PSL_u255(PSL_YIQ(b_rgb))); |
| 3232 | else if (PSL->internal.color_mode == PSL_CMYK) { |
| 3233 | psl_rgb_to_cmyk (f_rgb, f_cmyk); |
| 3234 | psl_rgb_to_cmyk (b_rgb, b_cmyk); |
| 3235 | PSL_command (PSL, "CMYK 1 <%02X%02X%02X%02X%02X%02X%02X%02X>", PSL_q255(f_cmyk), PSL_q255(b_cmyk)); |
| 3236 | } |
| 3237 | else |
| 3238 | PSL_command (PSL, "RGB 1 <%02X%02X%02X%02X%02X%02X>", PSL_t255(f_rgb), PSL_t255(b_rgb)); |
| 3239 | } |
| 3240 | PSL_command (PSL, "] setcolorspace"); |
| 3241 |
no test coverage detected