(rgbCS, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000,
false, DataBuffer.TYPE_BYTE);
PaintContext pctx = paint.createContext(rgbCM, devBounds, usrBounds,
at, getRenderingHints());
PDFXObject imageInfo = pdfDoc.getXObject
("TempImage:" + pctx.toString());
if (imageInfo != null) {
resourceContext.getPDFResources().addXObject(imageInfo);
} else {
Raster r = pctx.getRaster(devX, devY, devW, devH);
WritableRaster wr = (WritableRaster)r;
wr = wr.createWritableTranslatedChild(0, 0);
ColorModel pcm = pctx.getColorModel();
BufferedImage bi = new BufferedImage
(pcm, wr, pcm.isAlphaPremultiplied(), null);
final byte[] rgb = new byte[devW * devH * 3];
final int[] line = new int[devW];
final byte[] mask;
int x, y, val, rgbIdx = 0;
if (pcm.hasAlpha()) {
mask = new byte[devW * devH];
int maskIdx = 0;
for (y = 0; y < devH; y++) {
bi.getRGB(0, y, devW, 1, line, 0, devW);
for (x = 0; x < devW; x++) {
val = line[x];
mask[maskIdx++] = (byte)(val >>> 24);
rgb[rgbIdx++] = (byte)((val >> 16) & 0x0FF);
rgb[rgbIdx++] = (byte)((val >> 8 ) & 0x0FF);
rgb[rgbIdx++] = (byte)((val ) & 0x0FF);
}
}
} else {
mask = null;
for (y = 0; y < devH; y++) {
bi.getRGB(0, y, devW, 1, line, 0, devW);
for (x = 0; x < devW; x++) {
val = line[x];
rgb[rgbIdx++] = (byte)((val >> 16) & 0x0FF);
rgb[rgbIdx++] = (byte)((val >> 8 ) & 0x0FF);
rgb[rgbIdx++] = (byte)((val ) & 0x0FF);
}
}
}
String maskRef = null;
if (mask != null) {
BitmapImage fopimg = new BitmapImage
("TempImageMask:" + pctx.toString(), devW, devH, mask, null);
fopimg.setColorSpace(new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_GRAY));
PDFImageXObject xobj = pdfDoc.addImage(resourceContext, fopimg);
maskRef = xobj.referencePDF();
if (outputStream != null) {
try {
this.pdfDoc.output(outputStream);
} catch (IOException ioe) {
// ignore exception, will be thrown again later
}
}
}
BitmapImage fopimg;
fopimg = new BitmapImage("TempImage:" + pctx.toString(),
devW, devH, rgb, maskRef);
fopimg.setTransparent(new PDFColor(255, 255, 255));
imageInfo = pdfDoc.addImage(resourceContext, fopimg);
if (outputStream != null) {
try {
this.pdfDoc.output(outputStream);
} catch (IOException ioe) {
// ignore exception, will be thrown again later
}
}
}
currentStream.write("q\n");
writeClip(shape);
currentStream.write("" + usrW + " 0 0 " + (-usrH) + " " + usrX
+ " " + (usrY + usrH) + " cm\n"
+ imageInfo.getName() + " Do\nQ\n");
return true;
}