# HG changeset patch # User prr # Date 1297203854 28800 # Node ID 956b231fed6265cde690bdc50ba538085e86584a # Parent e2932d8114cb28583bfa7c041c8391e5769c7985 7006865: Regression: Corrupted output when printing images with bit depth of 4 Reviewed-by: bae, jgodinez diff -r e2932d8114cb -r 956b231fed62 jdk/src/windows/classes/sun/awt/windows/WPathGraphics.java --- a/jdk/src/windows/classes/sun/awt/windows/WPathGraphics.java Tue Feb 08 09:22:49 2011 -0500 +++ b/jdk/src/windows/classes/sun/awt/windows/WPathGraphics.java Tue Feb 08 14:24:14 2011 -0800 @@ -51,9 +51,12 @@ import java.awt.image.DataBuffer; import java.awt.image.IndexColorModel; import java.awt.image.WritableRaster; +import java.awt.image.ComponentSampleModel; +import java.awt.image.MultiPixelPackedSampleModel; +import java.awt.image.SampleModel; + import sun.awt.image.ByteComponentRaster; import sun.awt.image.BytePackedRaster; - import java.awt.print.PageFormat; import java.awt.print.Printable; import java.awt.print.PrinterException; @@ -1272,6 +1275,25 @@ return false; } + int bitsPerPixel = 24; + SampleModel sm = deepImage.getSampleModel(); + if (sm instanceof ComponentSampleModel) { + ComponentSampleModel csm = (ComponentSampleModel)sm; + bitsPerPixel = csm.getPixelStride() * 8; + } else if (sm instanceof MultiPixelPackedSampleModel) { + MultiPixelPackedSampleModel mppsm = + (MultiPixelPackedSampleModel)sm; + bitsPerPixel = mppsm.getPixelBitStride(); + } else { + if (icm != null) { + int diw = deepImage.getWidth(); + int dih = deepImage.getHeight(); + if (diw > 0 && dih > 0) { + bitsPerPixel = data.length*8/diw/dih; + } + } + } + /* Because the caller's image has been rotated * and sheared into our BufferedImage and because * we will be handing that BufferedImage directly to @@ -1289,7 +1311,7 @@ (float)Math.rint(scaledBounds.height+0.5), 0f, 0f, deepImage.getWidth(), deepImage.getHeight(), - icm); + bitsPerPixel, icm); setClip(holdClip); } diff -r e2932d8114cb -r 956b231fed62 jdk/src/windows/classes/sun/awt/windows/WPrinterJob.java --- a/jdk/src/windows/classes/sun/awt/windows/WPrinterJob.java Tue Feb 08 09:22:49 2011 -0500 +++ b/jdk/src/windows/classes/sun/awt/windows/WPrinterJob.java Tue Feb 08 14:24:14 2011 -0800 @@ -1212,13 +1212,14 @@ float destWidth, float destHeight, float srcX, float srcY, float srcWidth, float srcHeight, + int sampleBitsPerPixel, IndexColorModel icm) { int bitCount = 24; byte[] bmiColors = null; if (icm != null) { - bitCount = icm.getPixelSize(); - bmiColors = new byte[(1< 0) { + return Printable.NO_SUCH_PAGE; + } + Graphics2D g2d = (Graphics2D)g; + g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY()); + paint(g2d); + return Printable.PAGE_EXISTS; + } + + private void drawImage(Graphics g, int biType, IndexColorModel icm) { + + BufferedImage bi; + if (icm != null) { + bi = new BufferedImage(sw, sh, biType, icm); + } else { + bi = new BufferedImage(sw, sh, biType); + } + + Graphics big = bi.getGraphics(); + if (bi.getColorModel().getPixelSize() <=2) { + big.drawImage(opaqueImg, 0, 0, null); + } else { + big.drawImage(transImg, 0, 0, null); + } + g.drawImage(bi, 0, 0, null); + } + + public void paint(Graphics g) { + + int incX = sw+10, incY = sh+10; + + g.translate(10, 10); + + drawImage(g, TYPE_INT_RGB, null); + g.translate(incX, 0); + + drawImage(g, TYPE_INT_BGR, null); + g.translate(incX, 0); + + drawImage(g, TYPE_INT_ARGB, null); + g.translate(incX, 0); + + drawImage(g, TYPE_INT_ARGB_PRE, null); + g.translate(-3*incX, incY); + + drawImage(g, TYPE_3BYTE_BGR, null); + g.translate(incX, 0); + + drawImage(g, TYPE_4BYTE_ABGR, null); + g.translate(incX, 0); + + drawImage(g, TYPE_4BYTE_ABGR_PRE, null); + g.translate(incX, 0); + + drawImage(g, TYPE_USHORT_555_RGB, null); + g.translate(-3*incX, incY); + + drawImage(g, TYPE_USHORT_555_RGB, null); + g.translate(incX, 0); + + drawImage(g, TYPE_USHORT_GRAY, null); + g.translate(incX, 0); + + drawImage(g, TYPE_BYTE_GRAY, null); + g.translate(incX, 0); + + drawImage(g, TYPE_BYTE_INDEXED, null); + g.translate(-3*incX, incY); + + drawImage(g, TYPE_BYTE_BINARY, null); + g.translate(incX, 0); + + drawImage(g, TYPE_BYTE_BINARY, icm2); + g.translate(incX, 0); + + drawImage(g, TYPE_BYTE_BINARY, icm4); + g.translate(incX, 0); + + drawImage(g, TYPE_BYTE_INDEXED, icm2); + g.translate(-3*incX, incY); + + drawImage(g, TYPE_BYTE_INDEXED, icm4); + g.translate(incX, 0); + } + + + + /* Size is chosen to match default imageable width of a NA letter + * page. This means there will be clipping, what is clipped will + * depend on PageFormat orientation. + */ + public Dimension getPreferredSize() { + return new Dimension(468, 600); + } + +}