row = minY + h - i -1;
// Get the pixels
Rectangle srcRect =
new Rectangle(minX, row, w, 1);
Raster src = im.getData(srcRect);
SampleModel sm1 = src.getSampleModel();
int pos = 0;
int startX = srcRect.x - src.getSampleModelTranslateX();
int startY = srcRect.y - src.getSampleModelTranslateY();
if (sm1 instanceof SinglePixelPackedSampleModel) {
SinglePixelPackedSampleModel sppsm =
(SinglePixelPackedSampleModel)sm1;
pos = sppsm.getOffset(startX, startY);
}
switch(dataType) {
case DataBuffer.TYPE_SHORT:
short[] sdata =
((DataBufferShort)src.getDataBuffer()).getData();
for (int m = 0; m < sdata.length; m++)
writeWord(sdata[m]);
break;
case DataBuffer.TYPE_USHORT:
short[] usdata =
((DataBufferUShort)src.getDataBuffer()).getData();
for (int m = 0; m < usdata.length; m++)
writeWord(usdata[m]);
break;
case DataBuffer.TYPE_INT:
int[] idata =
((DataBufferInt)src.getDataBuffer()).getData();
for (int m = 0; m < idata.length; m++)
writeDWord(idata[m]);
break;
}
}
return;
}
// palette
if (isPalette == true) {
// write palette
switch(version) {
// has 3 field entries
case BMPEncodeParam.VERSION_2:
for (int i=0; i<paletteEntries; i++) {
output.write(b[i]);
output.write(g[i]);
output.write(r[i]);
}
break;
// has 4 field entries
default:
for (int i=0; i<paletteEntries; i++) {
output.write(b[i]);
output.write(g[i]);
output.write(r[i]);
output.write(a[i]);
}
break;
}
} // else no palette
// Writing of actual image data
int scanlineBytes = w * numBands;
// Buffer for up to 8 rows of pixels
int[] pixels = new int[8 * scanlineBytes];
// Also create a buffer to hold one line of the data
// to be written to the file, so we can use array writes.
byte[] bpixels = new byte[destScanlineBytes];
int l;
if (!isTopDown) {
// Process 8 rows at a time so all but the first will have a
// multiple of 8 rows.
int lastRow = minY + h;
for (int row = (lastRow-1); row >= minY; row -= 8) {
// Number of rows being read
int rows = Math.min(8, row - minY + 1);
// Get the pixels
Raster src = im.getData(new Rectangle(minX, row - rows + 1,
w, rows));
src.getPixels(minX, row - rows + 1, w, rows, pixels);
l = 0;
// Last possible position in the pixels array
int max = scanlineBytes * rows - 1;
for (int i=0; i<rows; i++) {
// Beginning of each scanline in the pixels array
l = max - (i+1) * scanlineBytes + 1;
writePixels(l, scanlineBytes, bitsPerPixel, pixels,
bpixels, padding, numBands, icm);
}
}
} else {
// Process 8 rows at a time so all but the last will have a
// multiple of 8 rows.
int lastRow = minY + h;
for (int row = minY; row < lastRow; row += 8) {
int rows = Math.min(8, lastRow - row);
// Get the pixels
Raster src = im.getData(new Rectangle(minX, row,
w, rows));
src.getPixels(minX, row, w, rows, pixels);
l=0;
for (int i=0; i<rows; i++) {
writePixels(l, scanlineBytes, bitsPerPixel, pixels,