numPixels -= (rightPixels + leftPixels);
switch(ifd.getImageType())
{
case(TIFFImageFileDirectory.TYPE_BILEVEL_BYTE):
{
BilevelImage image = (BilevelImage)codec.getImage();
int index = offset + leftPixels;
int x = getX1() - codec.getBoundsX1() + leftPixels;
while (numPixels-- > 0)
{
if (data[index++] == (byte)BilevelImage.BLACK)
{
image.putBlack(x++, y);
}
else
{
image.putWhite(x++, y);
}
}
break;
}
case(TIFFImageFileDirectory.TYPE_BILEVEL_PACKED):
{
BilevelImage image = (BilevelImage)codec.getImage();
int x = getX1() - codec.getBoundsX1() + leftPixels;
image.putPackedBytes(x, y, numPixels, data, offset + (leftPixels / 8), leftPixels % 8);
break;
}
case(TIFFImageFileDirectory.TYPE_GRAY4):
{
ByteChannelImage image = (ByteChannelImage)codec.getImage();
byte[] dest = new byte[data.length * 2];
ArrayConverter.decodePacked4Bit(data, 0, dest, 0, data.length);
for (int i = 0; i < dest.length; i++)
{
int value = dest[i] & 15;
value = (value << 4) | value;
dest[i] = (byte)value;
}
image.putByteSamples(0, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, dest, offset + leftPixels);
break;
}
case(TIFFImageFileDirectory.TYPE_PALETTED4):
{
ByteChannelImage image = (ByteChannelImage)codec.getImage();
byte[] dest = new byte[data.length * 2];
ArrayConverter.decodePacked4Bit(data, 0, dest, 0, data.length);
image.putByteSamples(0, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, dest, offset + leftPixels);
break;
}
case(TIFFImageFileDirectory.TYPE_GRAY8):
case(TIFFImageFileDirectory.TYPE_PALETTED8):
{
ByteChannelImage image = (ByteChannelImage)codec.getImage();
image.putByteSamples(0, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, data, offset + leftPixels);
break;
}
case(TIFFImageFileDirectory.TYPE_CMYK32_INTERLEAVED):
{
ByteChannelImage image = (ByteChannelImage)codec.getImage();
byte[] dest = new byte[data.length];
int numSamples = ifd.getTileWidth();
CMYKConversion.convertCMYK32InterleavedToRGB24Planar(
data, 0,
dest, 0,
dest, numSamples,
dest, numSamples * 2,
numSamples);
image.putByteSamples(RGBIndex.INDEX_RED, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, dest, leftPixels);
image.putByteSamples(RGBIndex.INDEX_GREEN, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, dest, numSamples + leftPixels);
image.putByteSamples(RGBIndex.INDEX_BLUE, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, dest, 2 * numSamples + leftPixels);
break;
}
/* case(TIFFImageFileDirectory.TYPE_CMYK32_PLANAR):
{
ByteChannelImage image = (ByteChannelImage)codec.getImage();
byte[] dest = new byte[data.length];
int numSamples = ifd.getTileWidth();
CMYKConversion.convertCMYK32PlanarToRGB24Planar(
data, 0,
data, numPixels,
data, numPixels * 2,
data, numPixels * 3,
dest, 0,
dest, numSamples,
dest, numSamples * 2,
numSamples);
image.putByteSamples(RGBIndex.INDEX_RED, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, dest, leftPixels);
image.putByteSamples(RGBIndex.INDEX_GREEN, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, dest, numSamples + leftPixels);
image.putByteSamples(RGBIndex.INDEX_BLUE, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, dest, 2 * numSamples + leftPixels);
break;
}*/
case(TIFFImageFileDirectory.TYPE_RGB24_INTERLEAVED):
{
ByteChannelImage image = (ByteChannelImage)codec.getImage();
offset += leftPixels * 3;
for (int i = 0, x = getX1() - codec.getBoundsX1() + leftPixels; i < numPixels; i++, x++)
{
image.putByteSample(RGBIndex.INDEX_RED, x, y, data[offset++]);
image.putByteSample(RGBIndex.INDEX_GREEN, x, y, data[offset++]);
image.putByteSample(RGBIndex.INDEX_BLUE, x, y, data[offset++]);
}
break;
}
case(TIFFImageFileDirectory.TYPE_RGB48_INTERLEAVED):
{
ShortChannelImage image = (ShortChannelImage)codec.getImage();
offset += leftPixels * 3;
short[] triplet = new short[3];
boolean littleEndian = codec.getByteOrder() == TIFFCodec.BYTE_ORDER_INTEL;
for (int i = 0, x = getX1() - codec.getBoundsX1() + leftPixels; i < numPixels; i++, x++)
{
for (int j = 0; j < 3; j++, offset += 2)
{
if (littleEndian)
{
triplet[j] = ArrayConverter.getShortLE(data, offset);
}
else
{
triplet[j] = ArrayConverter.getShortBE(data, offset);
}
}
image.putShortSample(RGBIndex.INDEX_RED, x, y, triplet[0]);
image.putShortSample(RGBIndex.INDEX_GREEN, x, y, triplet[1]);
image.putShortSample(RGBIndex.INDEX_BLUE, x, y, triplet[2]);
}
break;
}
case(TIFFImageFileDirectory.TYPE_LOGLUV32_INTERLEAVED):
{
if (getImageFileDirectory().getCompression() == TIFFConstants.COMPRESSION_SGI_LOG_RLE)
{
ByteChannelImage image = (ByteChannelImage)codec.getImage();
int numSamples = ifd.getTileWidth();
byte[] red = new byte[numSamples];
byte[] green = new byte[numSamples];
byte[] blue = new byte[numSamples];
LogLuvConversion.convertLogLuv32InterleavedtoRGB24Planar(data, red, green, blue, numSamples);
image.putByteSamples(RGBIndex.INDEX_RED, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, red, leftPixels);
image.putByteSamples(RGBIndex.INDEX_GREEN, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, green, leftPixels);
image.putByteSamples(RGBIndex.INDEX_BLUE, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, blue, leftPixels);
}
else
if (getImageFileDirectory().getCompression() == TIFFConstants.COMPRESSION_SGI_LOG_24_PACKED)
{
ByteChannelImage image = (ByteChannelImage)codec.getImage();
int numSamples = ifd.getTileWidth();
byte[] red = new byte[numSamples];
byte[] green = new byte[numSamples];
byte[] blue = new byte[numSamples];
LogLuvConversion.convertLogLuv24InterleavedtoRGB24Planar(data, red, green, blue, numSamples);
image.putByteSamples(RGBIndex.INDEX_RED, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, red, leftPixels);
image.putByteSamples(RGBIndex.INDEX_GREEN, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, green, leftPixels);
image.putByteSamples(RGBIndex.INDEX_BLUE, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, blue, leftPixels);
}
break;
}
case(TIFFImageFileDirectory.TYPE_LOGL):
{
ByteChannelImage image = (ByteChannelImage)codec.getImage();
int numSamples = ifd.getTileWidth();
byte[] gray = new byte[numSamples];
LogLuvConversion.convertLogL16toGray8(data, gray, numSamples);
image.putByteSamples(0, getX1() - codec.getBoundsX1() + leftPixels, y, numPixels, 1, gray, leftPixels);
break;
}
}
}