(KEY_FORCE_TRANSPARENT_WHITE)).booleanValue();
}
int w = img.getWidth();
int h = img.getHeight();
SinglePixelPackedSampleModel sppsm;
sppsm = (SinglePixelPackedSampleModel)img.getSampleModel();
if (forceTransparentWhite) {
//
// This is a trick so that viewers which do not support
// the alpha channel will see a white background (and not
// a black one).
//
DataBufferInt biDB=(DataBufferInt)img.getRaster().getDataBuffer();
int scanStride = sppsm.getScanlineStride();
int dbOffset = biDB.getOffset();
int pixels[] = biDB.getBankData()[0];
int p = dbOffset;
int adjust = scanStride - w;
int a=0, r=0, g=0, b=0, pel=0;
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
pel = pixels[p];
a = (pel >> 24) & 0xff;
r = (pel >> 16) & 0xff;
g = (pel >> 8 ) & 0xff;
b = pel & 0xff;
r = (255*(255 -a) + a*r)/255;
g = (255*(255 -a) + a*g)/255;
b = (255*(255 -a) + a*b)/255;
pixels[p++] =
(a<<24 & 0xff000000) |
(r<<16 & 0xff0000) |
(g<<8 & 0xff00) |
(b & 0xff);
}
p += adjust;
}
}
try {
TIFFImageEncoder tiffEncoder =
new TIFFImageEncoder(ostream, params);
int bands = sppsm.getNumBands();
int [] off = new int[bands];
for (int i=0; i<bands; i++)
off[i] = i;
SampleModel sm = new PixelInterleavedSampleModel
(DataBuffer.TYPE_BYTE, w, h, bands, w*bands, off);