src/share/classes/sun/java2d/pipe/DrawImage.java

Print this page


   1 /*
   2  * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  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


 293             {
 294                 renderImageCopy(sg, img, bgColor,
 295                                 idx, idy,
 296                                 sx1, sy1, sx2-sx1, sy2-sy1);
 297                 return true;
 298             }
 299         }
 300         // (For now) We can only use our ScaledBlits if the image
 301         // is upright (i.e. dw & dh both > 0)
 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,


   1 /*
   2  * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  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


 293             {
 294                 renderImageCopy(sg, img, bgColor,
 295                                 idx, idy,
 296                                 sx1, sy1, sx2-sx1, sy2-sy1);
 297                 return true;
 298             }
 299         }
 300         // (For now) We can only use our ScaledBlits if the image
 301         // is upright (i.e. dw & dh both > 0)
 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 non-accelerated BufferedImage of the requested type with the
 315      * indicated 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 color
 317      * 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         bimg.setAccelerationPriority(0);
 328         if (bgColor != null) {
 329             g2d.setColor(bgColor);
 330             g2d.fillRect(0, 0, width, height);
 331             g2d.setComposite(AlphaComposite.SrcOver);
 332         }
 333         g2d.copyImage(img, 0, 0, sx1, sy1, width, height, null, null);
 334         g2d.dispose();
 335         return bimg;
 336     }
 337 
 338     protected void renderImageXform(SunGraphics2D sg, Image img,
 339                                     AffineTransform tx, int interpType,
 340                                     int sx1, int sy1, int sx2, int sy2,
 341                                     Color bgColor)
 342     {
 343         Region clip = sg.getCompClip();
 344         SurfaceData dstData = sg.surfaceData;
 345         SurfaceData srcData = dstData.getSourceSurfaceData(img,
 346                                                            SunGraphics2D.TRANSFORM_GENERIC,
 347                                                            sg.imageComp,