Added support for reading uncompressed / packbits compressed monochrome TIFF images
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3061 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -394,16 +394,35 @@ check_tiff_fields(TiffIfd &ifd, TiffDetails *pdetails)
|
|||||||
// Copy fields useful to TIFFTranslator
|
// Copy fields useful to TIFFTranslator
|
||||||
dtls.width = ifd.GetUint(TAG_IMAGE_WIDTH);
|
dtls.width = ifd.GetUint(TAG_IMAGE_WIDTH);
|
||||||
dtls.height = ifd.GetUint(TAG_IMAGE_HEIGHT);
|
dtls.height = ifd.GetUint(TAG_IMAGE_HEIGHT);
|
||||||
dtls.compression = ifd.GetUint(TAG_COMPRESSION);
|
|
||||||
dtls.interpretation = ifd.GetUint(TAG_PHOTO_INTERPRETATION);
|
dtls.interpretation = ifd.GetUint(TAG_PHOTO_INTERPRETATION);
|
||||||
|
|
||||||
|
if (!ifd.HasField(TAG_COMPRESSION))
|
||||||
|
dtls.compression = COMPRESSION_NONE;
|
||||||
|
else
|
||||||
|
dtls.compression = ifd.GetUint(TAG_COMPRESSION);
|
||||||
if (dtls.compression != COMPRESSION_NONE &&
|
if (dtls.compression != COMPRESSION_NONE &&
|
||||||
dtls.compression != COMPRESSION_PACKBITS)
|
dtls.compression != COMPRESSION_PACKBITS)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
// Currently, only uncompressed
|
// Currently, only some
|
||||||
// RGB or CMYK images are supported
|
// bilevel, RGB or CMYK images are supported
|
||||||
if (dtls.interpretation == PHOTO_RGB) {
|
switch (dtls.interpretation) {
|
||||||
|
// Bilevel images
|
||||||
|
case PHOTO_WHITEZERO:
|
||||||
|
case PHOTO_BLACKZERO:
|
||||||
|
// default value for samples per pixel is 1
|
||||||
|
if (ifd.HasField(TAG_SAMPLES_PER_PIXEL) &&
|
||||||
|
ifd.GetUint(TAG_SAMPLES_PER_PIXEL) != 1)
|
||||||
|
return B_NO_TRANSLATOR;
|
||||||
|
// default value for bits per sample is 1
|
||||||
|
if (ifd.HasField(TAG_BITS_PER_SAMPLE) &&
|
||||||
|
ifd.GetUint(TAG_BITS_PER_SAMPLE) != 1)
|
||||||
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
|
dtls.imageType = TIFF_BILEVEL;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PHOTO_RGB:
|
||||||
if (ifd.GetUint(TAG_SAMPLES_PER_PIXEL) != 3)
|
if (ifd.GetUint(TAG_SAMPLES_PER_PIXEL) != 3)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
if (ifd.GetCount(TAG_BITS_PER_SAMPLE) != 3 ||
|
if (ifd.GetCount(TAG_BITS_PER_SAMPLE) != 3 ||
|
||||||
@@ -413,8 +432,9 @@ check_tiff_fields(TiffIfd &ifd, TiffDetails *pdetails)
|
|||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
dtls.imageType = TIFF_RGB;
|
dtls.imageType = TIFF_RGB;
|
||||||
|
break;
|
||||||
|
|
||||||
} else if (dtls.interpretation == PHOTO_SEPARATED) {
|
case PHOTO_SEPARATED:
|
||||||
// CMYK (default ink set)
|
// CMYK (default ink set)
|
||||||
// is the only ink set supported
|
// is the only ink set supported
|
||||||
if (ifd.HasField(TAG_INK_SET) &&
|
if (ifd.HasField(TAG_INK_SET) &&
|
||||||
@@ -431,9 +451,11 @@ check_tiff_fields(TiffIfd &ifd, TiffDetails *pdetails)
|
|||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
dtls.imageType = TIFF_CMYK;
|
dtls.imageType = TIFF_CMYK;
|
||||||
|
break;
|
||||||
|
|
||||||
} else
|
default:
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
}
|
||||||
|
|
||||||
if (!ifd.HasField(TAG_ROWS_PER_STRIP))
|
if (!ifd.HasField(TAG_ROWS_PER_STRIP))
|
||||||
dtls.rowsPerStrip = DEFAULT_ROWS_PER_STRIP;
|
dtls.rowsPerStrip = DEFAULT_ROWS_PER_STRIP;
|
||||||
@@ -633,11 +655,35 @@ TIFFTranslator::Identify(BPositionIO *inSource,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tiff_to_bits(uint8 *ptiff, uint32 tifflen, uint8 *pbits, uint16 type)
|
tiff_to_bits(uint8 *ptiff, uint32 tifflen, uint8 *pbits, TiffDetails &details)
|
||||||
{
|
{
|
||||||
uint8 *ptiffend = ptiff + tifflen;
|
uint8 *ptiffend = ptiff + tifflen;
|
||||||
|
|
||||||
switch (type) {
|
switch (details.imageType) {
|
||||||
|
case TIFF_BILEVEL:
|
||||||
|
{
|
||||||
|
uint8 black[3] = { 0x00, 0x00, 0x00 },
|
||||||
|
white[3] = { 0xFF, 0xFF, 0xFF };
|
||||||
|
uint8 *colors[2];
|
||||||
|
if (details.interpretation == PHOTO_WHITEZERO) {
|
||||||
|
colors[0] = white;
|
||||||
|
colors[1] = black;
|
||||||
|
} else {
|
||||||
|
colors[0] = black;
|
||||||
|
colors[1] = white;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint32 i = 0; i < details.width; i++) {
|
||||||
|
uint8 eightbits = (ptiff + (i / 8))[0];
|
||||||
|
uint8 abit;
|
||||||
|
abit = (eightbits >> (7 - (i % 8))) & 1;
|
||||||
|
|
||||||
|
memcpy(pbits + (i * 4), colors[abit], 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case TIFF_RGB:
|
case TIFF_RGB:
|
||||||
while (ptiff < ptiffend) {
|
while (ptiff < ptiffend) {
|
||||||
pbits[2] = ptiff[0];
|
pbits[2] = ptiff[0];
|
||||||
@@ -754,6 +800,10 @@ translate_from_tiff(BPositionIO *inSource, ssize_t amtread, uint8 *read,
|
|||||||
uint32 inbufferlen, outbufferlen;
|
uint32 inbufferlen, outbufferlen;
|
||||||
outbufferlen = 4 * details.width;
|
outbufferlen = 4 * details.width;
|
||||||
switch (details.imageType) {
|
switch (details.imageType) {
|
||||||
|
case TIFF_BILEVEL:
|
||||||
|
inbufferlen = (details.width / 8) +
|
||||||
|
((details.width % 8) ? 1 : 0);
|
||||||
|
break;
|
||||||
case TIFF_RGB:
|
case TIFF_RGB:
|
||||||
inbufferlen = 3 * details.width;
|
inbufferlen = 3 * details.width;
|
||||||
break;
|
break;
|
||||||
@@ -811,8 +861,7 @@ translate_from_tiff(BPositionIO *inSource, ssize_t amtread, uint8 *read,
|
|||||||
}
|
}
|
||||||
|
|
||||||
read += ret;
|
read += ret;
|
||||||
tiff_to_bits(inbuffer, inbufferlen, outbuffer,
|
tiff_to_bits(inbuffer, inbufferlen, outbuffer, details);
|
||||||
details.imageType);
|
|
||||||
outDestination->Write(outbuffer, outbufferlen);
|
outDestination->Write(outbuffer, outbufferlen);
|
||||||
}
|
}
|
||||||
// If while loop was broken...
|
// If while loop was broken...
|
||||||
|
|||||||
@@ -55,7 +55,8 @@
|
|||||||
#define BBT_OUT_CAPABILITY 0.6
|
#define BBT_OUT_CAPABILITY 0.6
|
||||||
|
|
||||||
enum TIFF_IMAGE_TYPE {
|
enum TIFF_IMAGE_TYPE {
|
||||||
TIFF_RGB = 1,
|
TIFF_BILEVEL = 1,
|
||||||
|
TIFF_RGB,
|
||||||
TIFF_CMYK
|
TIFF_CMYK
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user