{
Object value = params.get(PARAM_KEY_COMPRESSION);
if (value != null)
{
if (!(value instanceof Number))
throw new ImageWriteException(
"Invalid compression parameter: " + value);
compression = ((Number) value).intValue();
}
params.remove(PARAM_KEY_COMPRESSION);
}
final int samplesPerPixel = 3; // TODO:
final int bitsPerSample = 8; // TODO:
// int fRowsPerStrip; // TODO:
int rowsPerStrip = 8000 / (width * samplesPerPixel); // TODO:
rowsPerStrip = Math.max(1, rowsPerStrip); // must have at least one.
byte strips[][] = getStrips(src, samplesPerPixel, bitsPerSample,
rowsPerStrip);
// int stripCount = (height + fRowsPerStrip - 1) / fRowsPerStrip;
// int stripCount = strips.length;
if (params.size() > 0)
{
Object firstKey = params.keySet().iterator().next();
throw new ImageWriteException("Unknown parameter: " + firstKey);
}
// System.out.println("width: " + width);
// System.out.println("height: " + height);
// System.out.println("fRowsPerStrip: " + fRowsPerStrip);
// System.out.println("fSamplesPerPixel: " + fSamplesPerPixel);
// System.out.println("stripCount: " + stripCount);
if (compression == TIFF_COMPRESSION_PACKBITS)
{
for (int i = 0; i < strips.length; i++)
strips[i] = new PackBits().compress(strips[i]);
} else if (compression == TIFF_COMPRESSION_LZW)
{
for (int i = 0; i < strips.length; i++)
{
byte uncompressed[] = strips[i];
int LZW_MINIMUM_CODE_SIZE = 8;
MyLZWCompressor compressor = new MyLZWCompressor(
LZW_MINIMUM_CODE_SIZE, BYTE_ORDER_MSB, true);
byte compressed[] = compressor.compress(uncompressed);
strips[i] = compressed;
}
} else if (compression == TIFF_COMPRESSION_UNCOMPRESSED)
{
// do nothing.
} else
throw new ImageWriteException(
"Invalid compression parameter (Only LZW, Packbits and uncompressed supported).");
TiffElement.DataElement imageData[] = new TiffElement.DataElement[strips.length];
for (int i = 0; i < strips.length; i++)
imageData[i] = new TiffImageData.Data(0, strips[i].length,