| 40 |
#include "Error.h" |
#include "Error.h" |
| 41 |
#include "GlobalParams.h" |
#include "GlobalParams.h" |
| 42 |
#include <cups/raster.h> |
#include <cups/raster.h> |
| 43 |
|
#include <cups/image.h> |
| 44 |
#include <splash/SplashTypes.h> |
#include <splash/SplashTypes.h> |
| 45 |
#include <splash/SplashBitmap.h> |
#include <splash/SplashBitmap.h> |
| 46 |
|
|
| 260 |
paperColor[0] = 255; |
paperColor[0] = 255; |
| 261 |
rowpad = 1; |
rowpad = 1; |
| 262 |
break; |
break; |
|
#ifdef SPLASH_CMYK |
|
| 263 |
case CUPS_CSPACE_CMYK: |
case CUPS_CSPACE_CMYK: |
| 264 |
if (header.cupsColorOrder != CUPS_ORDER_CHUNKED |
if (header.cupsColorOrder != CUPS_ORDER_CHUNKED |
| 265 |
|| header.cupsBitsPerColor != 8 |
|| header.cupsBitsPerColor != 8 |
| 267 |
error(-1,const_cast<char *>("Specified color format is not supported")); |
error(-1,const_cast<char *>("Specified color format is not supported")); |
| 268 |
exit(1); |
exit(1); |
| 269 |
} |
} |
| 270 |
cmode = splashModeCMYK8; |
/* make RGB image and convert it to CMYK */ |
| 271 |
/* set paper color white */ |
cmode = splashModeRGB8; |
|
paperColor[0] = 0; |
|
|
paperColor[1] = 0; |
|
|
paperColor[2] = 0; |
|
|
paperColor[3] = 0; |
|
| 272 |
rowpad = 4; |
rowpad = 4; |
| 273 |
|
/* set paper color white */ |
| 274 |
|
paperColor[0] = 255; |
| 275 |
|
paperColor[1] = 255; |
| 276 |
|
paperColor[2] = 255; |
| 277 |
|
break; |
| 278 |
break; |
break; |
|
#endif |
|
| 279 |
default: |
default: |
| 280 |
error(-1,const_cast<char *>("Specified ColorSpace is not supported")); |
error(-1,const_cast<char *>("Specified ColorSpace is not supported")); |
| 281 |
exit(1); |
exit(1); |
| 302 |
/* write page header */ |
/* write page header */ |
| 303 |
header.cupsWidth = bitmap->getWidth(); |
header.cupsWidth = bitmap->getWidth(); |
| 304 |
header.cupsHeight = bitmap->getHeight(); |
header.cupsHeight = bitmap->getHeight(); |
| 305 |
header.cupsBytesPerLine = bitmap->getRowSize(); |
if (header.cupsColorSpace == CUPS_CSPACE_CMYK) { |
| 306 |
|
header.cupsBytesPerLine = bitmap->getWidth()*4;; |
| 307 |
|
} else { |
| 308 |
|
header.cupsBytesPerLine = bitmap->getRowSize(); |
| 309 |
|
} |
| 310 |
if (!cupsRasterWriteHeader(raster,&header)) { |
if (!cupsRasterWriteHeader(raster,&header)) { |
| 311 |
error(-1,const_cast<char *>("Can't write page %d header"),i); |
error(-1,const_cast<char *>("Can't write page %d header"),i); |
| 312 |
exit(1); |
exit(1); |
| 323 |
*p = ~*p; |
*p = ~*p; |
| 324 |
} |
} |
| 325 |
} |
} |
| 326 |
if (cupsRasterWritePixels(raster,bp, size) != size) { |
if (header.cupsColorSpace == CUPS_CSPACE_CMYK) { |
| 327 |
error(-1,const_cast<char *>("Can't write page %d image"),i); |
/* the image is RGB, so convert it to CMYK */ |
| 328 |
exit(1); |
unsigned int rowsize = bitmap->getRowSize(); |
| 329 |
|
unsigned char *dp, *cmykImage; |
| 330 |
|
|
| 331 |
|
header.cupsBytesPerLine = header.cupsWidth*4; |
| 332 |
|
size = header.cupsBytesPerLine*header.cupsHeight; |
| 333 |
|
cmykImage = new unsigned char [size]; |
| 334 |
|
dp = cmykImage; |
| 335 |
|
for (unsigned int h = 0;h < header.cupsHeight;h++) { |
| 336 |
|
cupsImageRGBToCMYK(bp,dp,header.cupsWidth); |
| 337 |
|
bp += rowsize; |
| 338 |
|
dp += header.cupsBytesPerLine; |
| 339 |
|
} |
| 340 |
|
if (cupsRasterWritePixels(raster,cmykImage, size) != size) { |
| 341 |
|
error(-1,const_cast<char *>("Can't write page %d image"),i); |
| 342 |
|
exit(1); |
| 343 |
|
} |
| 344 |
|
delete[] cmykImage; |
| 345 |
|
} else { |
| 346 |
|
if (cupsRasterWritePixels(raster,bp, size) != size) { |
| 347 |
|
error(-1,const_cast<char *>("Can't write page %d image"),i); |
| 348 |
|
exit(1); |
| 349 |
|
} |
| 350 |
} |
} |
| 351 |
} |
} |
| 352 |
cupsRasterClose(raster); |
cupsRasterClose(raster); |