@@ -126,13 +126,13 @@ public class BufferedImage extends Image implements RenderedImage, Transparency
126126 protected int width , height ;
127127
128128 /**
129- * the JSGrpahics2D object associated with this image
129+ * the JSGrpahics2D object associated with this image, if it has been requested
130130 */
131131 public JSGraphics2D 秘g ; // a JSGraphics2D instance
132132
133133 /**
134- * if an image is used just for graphics that the HTML5 canvas can use , we back
135- * the BufferedImage with an HTML5 canvas and just draw to it, never using the
134+ * if an image is used just for graphics that the HTML5 canvas can draw , we back
135+ * the BufferedImage with an HTML5 canvas and draw to it, never using the
136136 * raster associated with this image.
137137 */
138138 public Object 秘imgNode ; // used by JSGraphics2D directly
@@ -150,7 +150,7 @@ public class BufferedImage extends Image implements RenderedImage, Transparency
150150 * set to true if pixels have been generated from an HTML5 canvas
151151 *
152152 */
153- private boolean 秘havePixels ;
153+ private boolean 秘haveFilePixels ;
154154
155155 /**
156156 * the HTML5 canvas that originated 秘pix or that was created from them.
@@ -453,7 +453,7 @@ public BufferedImage(int width, int height, int imageType) {
453453 DataBuffer .TYPE_BYTE );
454454 raster = Raster .createInterleavedRaster (DataBuffer .TYPE_BYTE , width , height , width * 4 , 4 , bOffs , null );
455455 秘pix = ((DataBufferInt ) raster .getDataBuffer ()).data ;
456- 秘havePixels = 秘hasRasterData = true ;
456+ 秘haveFilePixels = 秘hasRasterData = true ;
457457 }
458458 break ;
459459
@@ -909,7 +909,7 @@ public int[] getRGB(int startX, int startY, int w, int h, int[] rgbArray, int of
909909 * @return true if pixels had to be set
910910 */
911911 public boolean 秘ensureHavePixels (boolean andSetImageNode ) {
912- if (!秘havePixels && (秘imgNode != null || 秘g != null )) {
912+ if (!秘haveFilePixels && (秘imgNode != null || 秘g != null )) {
913913 秘setPixelsFromHTML5Canavas (andSetImageNode );
914914 return true ;
915915 }
@@ -1019,7 +1019,7 @@ public void setRGB(int startX, int startY, int w, int h, int[] rgbArray, int off
10191019 // 秘pix is used by getGraphics()
10201020 // 秘pixSaved is kept in case we need to do this again
10211021 秘g = null ; // forces new this.秘canvas to be created in getGraphics()
1022- getImageGraphic (); // sets 秘pix = null and creates 秘canvas
1022+ 秘getImageGraphic (); // sets 秘pix = null and creates 秘canvas
10231023
10241024 }
10251025
@@ -1152,7 +1152,7 @@ public Graphics getGraphics() {
11521152 * @return a <code>Graphics2D</code>, used for drawing into this image.
11531153 */
11541154 public Graphics2D createGraphics () {
1155- return (Graphics2D ) getImageGraphic ().create ();
1155+ return (Graphics2D ) 秘getImageGraphic ().create ();
11561156// GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
11571157// return (Graphics2D) env.createGraphics(this);
11581158 }
@@ -1715,7 +1715,7 @@ public void setImageFromHTML5Canvas(JSGraphics2D g) {
17151715 if (秘pix == null )
17161716 toIntARGB (data , 秘pix = new int [data .length >> 2 ]);
17171717 秘imgNode = (andSetImgNode ? canvas : null );
1718- 秘havePixels = true ;
1718+ 秘haveFilePixels = true ;
17191719 }
17201720
17211721 /**
@@ -1794,7 +1794,7 @@ public void flush() {
17941794 // call this method after drawing to ensure that
17951795 // pixels are recreated from the HTML5 canvas
17961796 秘pix = null ;
1797- 秘havePixels = false ;
1797+ 秘haveFilePixels = false ;
17981798 }
17991799
18001800 /**
@@ -1807,7 +1807,7 @@ public void flush() {
18071807 * @return a JSGraphics2D object
18081808 */
18091809 @ SuppressWarnings ("unused" )
1810- public Graphics2D getImageGraphic () {
1810+ public Graphics2D 秘getImageGraphic () {
18111811 if (秘g == null ) {
18121812 HTML5Canvas canvas = (HTML5Canvas ) DOMNode .createElement ("canvas" , "img" + System .currentTimeMillis ());
18131813 int w = getWidth ();
@@ -1914,10 +1914,13 @@ public Graphics2D getImageGraphic() {
19141914 boolean isPacked = cm instanceof PackedColorModel ;
19151915 int [] p = 秘pix ;
19161916 if (isPacked ) {
1917+ int alpha = (cm .getNumColorComponents () == 3 ? 0xFF : -1 );
19171918 int [] a = new int [n ];
19181919 raster .getDataElements (0 , 0 , width , height , a );
19191920 for (int i = 0 , pt = 0 ; i < n ; i ++, pt += 4 ) {
19201921 cm .getComponents (a [i ], p , pt );
1922+ if (alpha != 0 )
1923+ p [pt + 3 ] = alpha ;
19211924 }
19221925 } else {
19231926 int nc = cm .getNumComponents ();
@@ -1966,20 +1969,26 @@ public Graphics2D getImageGraphic() {
19661969 * canvas associated with this image, particularly if this is from a
19671970 * user-provided raster.
19681971 *
1969- * @param imgNode
1972+ * @param force initially false just to get the pre-constructed canvas if it exists
19701973 * @return
19711974 */
19721975
19731976 public DOMNode 秘getImageNode (boolean force ) {
1974- if (!秘hasRasterData )
1975- return (DOMNode ) (秘canvas != null ? 秘canvas
1977+ // If we have raster data and are not forcing, return the canvas if it exists.
1978+ // If we we have no raster data and are not forcing, force the issue anyway
1979+ // and return the canvas or image node.
1980+ // If we are forcing, or force the creation of a canvas
1981+ if (!force )
1982+ return (DOMNode ) (秘hasRasterData || 秘canvas != null ? 秘canvas
19761983 : 秘imgNode != null ? 秘imgNode : JSGraphicsCompositor .createImageNode (this ));
1977- if (!force )// || imageType == TYPE_4BYTE_HTML5)
1978- return null ;
1984+ // we are forcing
19791985 秘getPixelsFromRaster ();
19801986 秘g = null ;
1981- getImageGraphic ();
1982- return 秘g .getCanvas ();
1987+ 秘getImageGraphic ();
1988+ DOMNode canvas = 秘g .getCanvas ();
1989+ 秘g = null ;
1990+ 秘canvas = null ;
1991+ return canvas ;
19831992 }
19841993
19851994 /**
@@ -1989,11 +1998,11 @@ public Graphics2D getImageGraphic() {
19891998 */
19901999 protected void 秘setPixels (int [] argb ) {
19912000 秘pix = argb ;
1992- 秘havePixels = true ;
2001+ 秘haveFilePixels = true ;
19932002 }
19942003
19952004 /**
1996- * This private method does not trigger actual conversion to a rastered image.
2005+ * This method, called from ImageUtil does not trigger actual conversion to a rastered image.
19972006 *
19982007 * @return
19992008 */
0 commit comments