< prev index next >

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

Print this page




 323                 return true;
 324             }
 325         }
 326         return false;
 327     }
 328 
 329     /**
 330      * Return a non-accelerated BufferedImage of the requested type with the
 331      * indicated subimage of the original image located at 0,0 in the new image.
 332      * If a bgColor is supplied, composite the original image over that color
 333      * with a SrcOver operation, otherwise make a SrcNoEa copy.
 334      * <p>
 335      * Returned BufferedImage is not accelerated for two reasons:
 336      * <ul>
 337      * <li> Types of the image and surface are predefined, because these types
 338      *      correspond to the TransformHelpers, which we know we have. And
 339      *      acceleration can change the type of the surface
 340      * <li> Image will be used only once and acceleration caching wouldn't help
 341      * </ul>
 342      */
 343     BufferedImage makeBufferedImage(Image img, Color bgColor, int type,
 344                                     int sx1, int sy1, int sx2, int sy2)
 345     {
 346         final int width = sx2 - sx1;
 347         final int height = sy2 - sy1;
 348         final BufferedImage bimg = new BufferedImage(width, height, type);
 349         final SunGraphics2D g2d = (SunGraphics2D) bimg.createGraphics();
 350         g2d.setComposite(AlphaComposite.Src);
 351         bimg.setAccelerationPriority(0);
 352         if (bgColor != null) {
 353             g2d.setColor(bgColor);
 354             g2d.fillRect(0, 0, width, height);
 355             g2d.setComposite(AlphaComposite.SrcOver);
 356         }
 357         g2d.copyImage(img, 0, 0, sx1, sy1, width, height, null, null);
 358         g2d.dispose();
 359         return bimg;
 360     }
 361 
 362     protected void renderImageXform(SunGraphics2D sg, Image img,
 363                                     AffineTransform tx, int interpType,


 413         final SurfaceData dstData = sg.surfaceData;
 414         SurfaceData srcData = dstData.getSourceSurfaceData(img,
 415                                                            SunGraphics2D.TRANSFORM_GENERIC,
 416                                                            sg.imageComp,
 417                                                            bgColor);
 418 
 419         if (srcData == null) {
 420             img = getBufferedImage(img);
 421             srcData = dstData.getSourceSurfaceData(img,
 422                                                    SunGraphics2D.TRANSFORM_GENERIC,
 423                                                    sg.imageComp,
 424                                                    bgColor);
 425             if (srcData == null) {
 426                 // REMIND: Is this correct?  Can this happen?
 427                 return;
 428             }
 429         }
 430 
 431         if (isBgOperation(srcData, bgColor)) {
 432             // We cannot perform bg operations during transform so make
 433             // an opaque temp image with the appropriate background
 434             // and work from there.
 435             img = makeBufferedImage(img, bgColor, BufferedImage.TYPE_INT_RGB,
 436                                     sx1, sy1, sx2, sy2);






 437             // Temp image has appropriate subimage at 0,0 now.
 438             sx2 -= sx1;
 439             sy2 -= sy1;
 440             sx1 = sy1 = 0;
 441 
 442             srcData = dstData.getSourceSurfaceData(img,
 443                                                    SunGraphics2D.TRANSFORM_GENERIC,
 444                                                    sg.imageComp,
 445                                                    bgColor);
 446         }
 447 
 448         SurfaceType srcType = srcData.getSurfaceType();
 449         TransformHelper helper = TransformHelper.getFromCache(srcType);
 450 
 451         if (helper == null) {
 452             /* We have no helper for this source image type.
 453              * But we know that we do have helpers for both RGB and ARGB,
 454              * so convert to one of those types depending on transparency.
 455              * ARGB_PRE might be a better choice if the source image has
 456              * alpha, but it may cause some recursion here since we only




 323                 return true;
 324             }
 325         }
 326         return false;
 327     }
 328 
 329     /**
 330      * Return a non-accelerated BufferedImage of the requested type with the
 331      * indicated subimage of the original image located at 0,0 in the new image.
 332      * If a bgColor is supplied, composite the original image over that color
 333      * with a SrcOver operation, otherwise make a SrcNoEa copy.
 334      * <p>
 335      * Returned BufferedImage is not accelerated for two reasons:
 336      * <ul>
 337      * <li> Types of the image and surface are predefined, because these types
 338      *      correspond to the TransformHelpers, which we know we have. And
 339      *      acceleration can change the type of the surface
 340      * <li> Image will be used only once and acceleration caching wouldn't help
 341      * </ul>
 342      */
 343     private BufferedImage makeBufferedImage(Image img, Color bgColor, int type,
 344                                             int sx1, int sy1, int sx2, int sy2)
 345     {
 346         final int width = sx2 - sx1;
 347         final int height = sy2 - sy1;
 348         final BufferedImage bimg = new BufferedImage(width, height, type);
 349         final SunGraphics2D g2d = (SunGraphics2D) bimg.createGraphics();
 350         g2d.setComposite(AlphaComposite.Src);
 351         bimg.setAccelerationPriority(0);
 352         if (bgColor != null) {
 353             g2d.setColor(bgColor);
 354             g2d.fillRect(0, 0, width, height);
 355             g2d.setComposite(AlphaComposite.SrcOver);
 356         }
 357         g2d.copyImage(img, 0, 0, sx1, sy1, width, height, null, null);
 358         g2d.dispose();
 359         return bimg;
 360     }
 361 
 362     protected void renderImageXform(SunGraphics2D sg, Image img,
 363                                     AffineTransform tx, int interpType,


 413         final SurfaceData dstData = sg.surfaceData;
 414         SurfaceData srcData = dstData.getSourceSurfaceData(img,
 415                                                            SunGraphics2D.TRANSFORM_GENERIC,
 416                                                            sg.imageComp,
 417                                                            bgColor);
 418 
 419         if (srcData == null) {
 420             img = getBufferedImage(img);
 421             srcData = dstData.getSourceSurfaceData(img,
 422                                                    SunGraphics2D.TRANSFORM_GENERIC,
 423                                                    sg.imageComp,
 424                                                    bgColor);
 425             if (srcData == null) {
 426                 // REMIND: Is this correct?  Can this happen?
 427                 return;
 428             }
 429         }
 430 
 431         if (isBgOperation(srcData, bgColor)) {
 432             // We cannot perform bg operations during transform so make
 433             // a temp image with the appropriate background based on
 434             // background alpha value and work from there. If background
 435             // alpha is opaque use INT_RGB else use INT_ARGB so that we
 436             // will not lose translucency of background.
 437 
 438             int bgAlpha = bgColor.getAlpha();
 439             int type = ((bgAlpha == 255)
 440                         ? BufferedImage.TYPE_INT_RGB
 441                         : BufferedImage.TYPE_INT_ARGB);
 442             img = makeBufferedImage(img, bgColor, type, sx1, sy1, sx2, sy2);
 443             // Temp image has appropriate subimage at 0,0 now.
 444             sx2 -= sx1;
 445             sy2 -= sy1;
 446             sx1 = sy1 = 0;
 447 
 448             srcData = dstData.getSourceSurfaceData(img,
 449                                                    SunGraphics2D.TRANSFORM_GENERIC,
 450                                                    sg.imageComp,
 451                                                    bgColor);
 452         }
 453 
 454         SurfaceType srcType = srcData.getSurfaceType();
 455         TransformHelper helper = TransformHelper.getFromCache(srcType);
 456 
 457         if (helper == null) {
 458             /* We have no helper for this source image type.
 459              * But we know that we do have helpers for both RGB and ARGB,
 460              * so convert to one of those types depending on transparency.
 461              * ARGB_PRE might be a better choice if the source image has
 462              * alpha, but it may cause some recursion here since we only


< prev index next >