10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.java2d.pipe;
27
28 import java.awt.AlphaComposite;
29 import java.awt.Color;
30 import java.awt.Graphics2D;
31 import java.awt.Image;
32 import java.awt.Rectangle;
33 import java.awt.Transparency;
34 import java.awt.geom.AffineTransform;
35 import java.awt.geom.NoninvertibleTransformException;
36 import java.awt.image.AffineTransformOp;
37 import java.awt.image.BufferedImage;
38 import java.awt.image.BufferedImageOp;
39 import java.awt.image.ColorModel;
40 import java.awt.image.DataBuffer;
41 import java.awt.image.DirectColorModel;
42 import java.awt.image.ImageObserver;
43 import java.awt.image.IndexColorModel;
44 import java.awt.image.Raster;
45 import java.awt.image.VolatileImage;
46 import java.awt.image.WritableRaster;
47 import java.awt.image.ImagingOpException;
48 import sun.awt.SunHints;
49 import sun.awt.image.ImageRepresentation;
50 import sun.awt.image.ToolkitImage;
51 import sun.java2d.InvalidPipeException;
52 import sun.java2d.SunGraphics2D;
53 import sun.java2d.SurfaceData;
54 import sun.java2d.loops.Blit;
55 import sun.java2d.loops.BlitBg;
56 import sun.java2d.loops.TransformHelper;
57 import sun.java2d.loops.MaskBlit;
58 import sun.java2d.loops.CompositeType;
59 import sun.java2d.loops.ScaledBlit;
60 import sun.java2d.loops.SurfaceType;
61
62 public class DrawImage implements DrawImagePipe
63 {
64 public boolean copyImage(SunGraphics2D sg, Image img,
65 int x, int y,
66 Color bgColor)
67 {
68 int imgw = img.getWidth(null);
69 int imgh = img.getHeight(null);
306 if (dw > 0 && dh > 0) {
307 if (renderImageScale(sg, img, bgColor, interpType,
308 sx1, sy1, sx2, sy2,
309 coords[0], coords[1], coords[2], coords[3]))
310 {
311 return true;
312 }
313 }
314 return false;
315 }
316
317 /*
318 * Return a BufferedImage of the requested type with the indicated
319 * subimage of the original image located at 0,0 in the new image.
320 * If a bgColor is supplied, composite the original image over that
321 * color with a SrcOver operation, otherwise make a SrcNoEa copy.
322 */
323 BufferedImage makeBufferedImage(Image img, Color bgColor, int type,
324 int sx1, int sy1, int sx2, int sy2)
325 {
326 BufferedImage bimg = new BufferedImage(sx2-sx1, sy2-sy1, type);
327 Graphics2D g2d = bimg.createGraphics();
328 g2d.setComposite(AlphaComposite.Src);
329 if (bgColor != null) {
330 g2d.setColor(bgColor);
331 g2d.fillRect(0, 0, sx2-sx1, sy2-sy1);
332 g2d.setComposite(AlphaComposite.SrcOver);
333 }
334 g2d.drawImage(img, -sx1, -sy1, null);
335 g2d.dispose();
336 return bimg;
337 }
338
339 protected void renderImageXform(SunGraphics2D sg, Image img,
340 AffineTransform tx, int interpType,
341 int sx1, int sy1, int sx2, int sy2,
342 Color bgColor)
343 {
344 Region clip = sg.getCompClip();
345 SurfaceData dstData = sg.surfaceData;
346 SurfaceData srcData = dstData.getSourceSurfaceData(img,
347 SunGraphics2D.TRANSFORM_GENERIC,
348 sg.imageComp,
349 bgColor);
350
351 if (srcData == null) {
352 img = getBufferedImage(img);
353 srcData = dstData.getSourceSurfaceData(img,
354 SunGraphics2D.TRANSFORM_GENERIC,
720 {
721 double ddx1 = dstX + sg.transX;
722 double ddy1 = dstY + sg.transY;
723 double ddx2 = ddx1 + dstW;
724 double ddy2 = ddy1 + dstH;
725 if (renderImageScale(sg, img, bgColor, sg.interpolationType,
726 srcX, srcY, srcX+srcW, srcY+srcH,
727 ddx1, ddy1, ddx2, ddy2))
728 {
729 return true;
730 }
731 }
732
733 AffineTransform atfm = new AffineTransform(sg.transform);
734 atfm.translate(dx1, dy1);
735 double m00 = (double)(dx2-dx1)/(sx2-sx1);
736 double m11 = (double)(dy2-dy1)/(sy2-sy1);
737 atfm.scale(m00, m11);
738 atfm.translate(srcX-sx1, srcY-sy1);
739
740 int imgW = img.getWidth(null);
741 int imgH = img.getHeight(null);
742 srcW += srcX;
743 srcH += srcY;
744 // Make sure we are not out of bounds
745 if (srcW > imgW) {
746 srcW = imgW;
747 }
748 if (srcH > imgH) {
749 srcH = imgH;
750 }
751 if (srcX < 0) {
752 atfm.translate(-srcX, 0);
753 srcX = 0;
754 }
755 if (srcY < 0) {
756 atfm.translate(0, -srcY);
757 srcY = 0;
758 }
759 if (srcX >= srcW || srcY >= srcH) {
760 return true;
761 }
|
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.java2d.pipe;
27
28 import java.awt.AlphaComposite;
29 import java.awt.Color;
30 import java.awt.Image;
31 import java.awt.Transparency;
32 import java.awt.geom.AffineTransform;
33 import java.awt.geom.NoninvertibleTransformException;
34 import java.awt.image.AffineTransformOp;
35 import java.awt.image.BufferedImage;
36 import java.awt.image.BufferedImageOp;
37 import java.awt.image.ColorModel;
38 import java.awt.image.DataBuffer;
39 import java.awt.image.ImageObserver;
40 import java.awt.image.IndexColorModel;
41 import java.awt.image.Raster;
42 import java.awt.image.VolatileImage;
43 import sun.awt.SunHints;
44 import sun.awt.image.ImageRepresentation;
45 import sun.awt.image.SurfaceManager;
46 import sun.awt.image.ToolkitImage;
47 import sun.java2d.InvalidPipeException;
48 import sun.java2d.SunGraphics2D;
49 import sun.java2d.SurfaceData;
50 import sun.java2d.loops.Blit;
51 import sun.java2d.loops.BlitBg;
52 import sun.java2d.loops.TransformHelper;
53 import sun.java2d.loops.MaskBlit;
54 import sun.java2d.loops.CompositeType;
55 import sun.java2d.loops.ScaledBlit;
56 import sun.java2d.loops.SurfaceType;
57
58 public class DrawImage implements DrawImagePipe
59 {
60 public boolean copyImage(SunGraphics2D sg, Image img,
61 int x, int y,
62 Color bgColor)
63 {
64 int imgw = img.getWidth(null);
65 int imgh = img.getHeight(null);
302 if (dw > 0 && dh > 0) {
303 if (renderImageScale(sg, img, bgColor, interpType,
304 sx1, sy1, sx2, sy2,
305 coords[0], coords[1], coords[2], coords[3]))
306 {
307 return true;
308 }
309 }
310 return false;
311 }
312
313 /*
314 * Return a BufferedImage of the requested type with the indicated
315 * subimage of the original image located at 0,0 in the new image.
316 * If a bgColor is supplied, composite the original image over that
317 * color with a SrcOver operation, otherwise make a SrcNoEa copy.
318 */
319 BufferedImage makeBufferedImage(Image img, Color bgColor, int type,
320 int sx1, int sy1, int sx2, int sy2)
321 {
322 final int width = sx2 - sx1;
323 final int height = sy2 - sy1;
324 final BufferedImage bimg = new BufferedImage(width, height, type);
325 final SunGraphics2D g2d = (SunGraphics2D) bimg.createGraphics();
326 g2d.setComposite(AlphaComposite.Src);
327 if (bgColor != null) {
328 g2d.setColor(bgColor);
329 g2d.fillRect(0, 0, width, height);
330 g2d.setComposite(AlphaComposite.SrcOver);
331 }
332 g2d.copyImage(img, 0, 0, sx1, sy1, width, height, null, null);
333 g2d.dispose();
334 return bimg;
335 }
336
337 protected void renderImageXform(SunGraphics2D sg, Image img,
338 AffineTransform tx, int interpType,
339 int sx1, int sy1, int sx2, int sy2,
340 Color bgColor)
341 {
342 Region clip = sg.getCompClip();
343 SurfaceData dstData = sg.surfaceData;
344 SurfaceData srcData = dstData.getSourceSurfaceData(img,
345 SunGraphics2D.TRANSFORM_GENERIC,
346 sg.imageComp,
347 bgColor);
348
349 if (srcData == null) {
350 img = getBufferedImage(img);
351 srcData = dstData.getSourceSurfaceData(img,
352 SunGraphics2D.TRANSFORM_GENERIC,
718 {
719 double ddx1 = dstX + sg.transX;
720 double ddy1 = dstY + sg.transY;
721 double ddx2 = ddx1 + dstW;
722 double ddy2 = ddy1 + dstH;
723 if (renderImageScale(sg, img, bgColor, sg.interpolationType,
724 srcX, srcY, srcX+srcW, srcY+srcH,
725 ddx1, ddy1, ddx2, ddy2))
726 {
727 return true;
728 }
729 }
730
731 AffineTransform atfm = new AffineTransform(sg.transform);
732 atfm.translate(dx1, dy1);
733 double m00 = (double)(dx2-dx1)/(sx2-sx1);
734 double m11 = (double)(dy2-dy1)/(sy2-sy1);
735 atfm.scale(m00, m11);
736 atfm.translate(srcX-sx1, srcY-sy1);
737
738 final int scale = SurfaceManager.getImageScale(img);
739 final int imgW = img.getWidth(null) * scale;
740 final int imgH = img.getHeight(null) * scale;
741 srcW += srcX;
742 srcH += srcY;
743 // Make sure we are not out of bounds
744 if (srcW > imgW) {
745 srcW = imgW;
746 }
747 if (srcH > imgH) {
748 srcH = imgH;
749 }
750 if (srcX < 0) {
751 atfm.translate(-srcX, 0);
752 srcX = 0;
753 }
754 if (srcY < 0) {
755 atfm.translate(0, -srcY);
756 srcY = 0;
757 }
758 if (srcX >= srcW || srcY >= srcH) {
759 return true;
760 }
|