ByteArrayOutputStream baos=new ByteArrayOutputStream();
BitSwapOutputStream bsos=new BitSwapOutputStream(baos);
ModHuffmanOutputStream mhos=new ModHuffmanOutputStream(bsos);
RLEOutputStream rlos=new RLEOutputStream(mhos,3); // rgb = 3 bytes per sample code word (not needed here)
for(int i=0;i<maxrps;i++){
if((y+i)==height){break;} // last strip might have less rows
rlos.setStartCodeWord(-1); // white run first
for(int x=0;x<width;x++){
rlos.write(image.getRGB(x,y+i));
}
rlos.flush(); // write padding after ever image row
}
rlos.close();
byte[] data=baos.toByteArray();
counts.setCount(index,data.length); // update ifd strip counter array
offsets.setOffset(index,out.getStreamPosition()); // update ifd image data offset array
out.write(data); // write to image stream