Commit 6d3fe48c authored by Adrian Johnson's avatar Adrian Johnson
Browse files

tiff: remove splash dependency and add RGBA support

Bug 57006
parent 15f600a5
......@@ -20,13 +20,12 @@ TiffWriter::~TiffWriter()
// no cleanup needed
}
TiffWriter::TiffWriter()
TiffWriter::TiffWriter(Format formatA) : format(formatA)
{
f = NULL;
numRows = 0;
curRow = 0;
compressionString = NULL;
splashMode = splashModeRGB8;
}
// Set the compression type
......@@ -36,13 +35,6 @@ void TiffWriter::setCompressionString(const char *compressionStringArg)
compressionString = compressionStringArg;
}
// Set the bitmap mode
void TiffWriter::setSplashMode(SplashColorMode splashModeArg)
{
splashMode = splashModeArg;
}
// Write a TIFF file.
bool TiffWriter::init(FILE *openedFile, int width, int height, int hDPI, int vDPI)
......@@ -109,35 +101,31 @@ bool TiffWriter::init(FILE *openedFile, int width, int height, int hDPI, int vDP
}
}
// Set bits per sample, samples per pixel, and photometric type from the splash mode
// Set bits per sample, samples per pixel, and photometric type from format
bitspersample = (splashMode == splashModeMono1? 1: 8);
bitspersample = (format == MONOCHROME ? 1 : 8);
switch (splashMode) {
case splashModeMono1:
case splashModeMono8:
switch (format) {
case MONOCHROME:
case GRAY:
samplesperpixel = 1;
photometric = PHOTOMETRIC_MINISBLACK;
break;
case splashModeRGB8:
case splashModeBGR8:
case RGB:
samplesperpixel = 3;
photometric = PHOTOMETRIC_RGB;
break;
#if SPLASH_CMYK
case splashModeCMYK8:
case splashModeDeviceN8:
case RGBA_PREMULTIPLIED:
samplesperpixel = 4;
photometric = PHOTOMETRIC_SEPARATED;
photometric = PHOTOMETRIC_RGB;
break;
#endif
default:
fprintf(stderr, "TiffWriter: Mode %d not supported\n", splashMode);
return false;
case CMYK:
samplesperpixel = 4;
photometric = PHOTOMETRIC_SEPARATED;
break;
}
// Open the file
......@@ -168,12 +156,15 @@ bool TiffWriter::init(FILE *openedFile, int width, int height, int hDPI, int vDP
TIFFSetField(f, TIFFTAG_YRESOLUTION, (double) vDPI);
TIFFSetField(f, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
#if SPLASH_CMYK
if (splashMode == splashModeCMYK8 || splashMode == splashModeDeviceN8) {
if (format == RGBA_PREMULTIPLIED) {
uint16 extra = EXTRASAMPLE_ASSOCALPHA;
TIFFSetField(f, TIFFTAG_EXTRASAMPLES, 1, &extra);
}
if (format == CMYK) {
TIFFSetField(f, TIFFTAG_INKSET, INKSET_CMYK);
TIFFSetField(f, TIFFTAG_NUMBEROFINKS, 4);
}
#endif
return true;
}
......
......@@ -27,11 +27,18 @@ extern "C" {
class TiffWriter : public ImgWriter
{
public:
TiffWriter();
/* RGB - 3 bytes/pixel
* RGBA_PREMULTIPLIED - 4 bytes/pixel premultiplied by alpha
* GRAY - 1 byte/pixel
* MONOCHROME - 8 pixels/byte
* CMYK - 4 bytes/pixel
*/
enum Format { RGB, RGBA_PREMULTIPLIED, GRAY, MONOCHROME, CMYK };
TiffWriter(Format format = RGB);
~TiffWriter();
void setCompressionString(const char *compressionStringArg);
void setSplashMode(SplashColorMode splashModeArg);
bool init(FILE *openedFile, int width, int height, int hDPI, int vDPI);
......@@ -47,7 +54,7 @@ class TiffWriter : public ImgWriter
int numRows; // number of rows in the image
int curRow; // number of rows written
const char *compressionString; // compression type
SplashColorMode splashMode; // format of image data
Format format; // format of image data
};
......
......@@ -373,10 +373,29 @@ SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, FILE *f, in
#ifdef ENABLE_LIBTIFF
case splashFormatTiff:
writer = new TiffWriter();
switch (mode) {
case splashModeMono1:
writer = new TiffWriter(TiffWriter::MONOCHROME);
break;
case splashModeMono8:
writer = new TiffWriter(TiffWriter::GRAY);
break;
case splashModeRGB8:
case splashModeBGR8:
writer = new TiffWriter(TiffWriter::RGB);
break;
#if SPLASH_CMYK
case splashModeCMYK8:
case splashModeDeviceN8:
writer = new TiffWriter(TiffWriter::CMYK);
break;
#endif
default:
fprintf(stderr, "TiffWriter: Mode %d not supported\n", mode);
writer = new TiffWriter();
}
if (writer) {
((TiffWriter *)writer)->setCompressionString(compressionString);
((TiffWriter *)writer)->setSplashMode(mode);
}
break;
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment