< prev index next >

src/java.desktop/share/classes/sun/java2d/SunCompositeContext.java

Print this page




  71         dstCM = d;
  72         this.composite = xc;
  73         this.comptype = CompositeType.Xor;
  74     }
  75 
  76     /**
  77      * Release resources allocated for context.
  78      */
  79     public void dispose() {
  80     }
  81 
  82     /**
  83      * This method composes the two source tiles
  84      * and places the result in the destination tile. Note that
  85      * the destination can be the same object as either
  86      * the first or second source.
  87      * @param src1 The first source tile for the compositing operation.
  88      * @param src2 The second source tile for the compositing operation.
  89      * @param dst The tile where the result of the operation is stored.
  90      */
  91     public void compose(Raster srcArg, Raster dstIn, WritableRaster dstOut) {
  92         WritableRaster src;
  93         int w;
  94         int h;
  95 
  96         if (dstIn != dstOut) {
  97             dstOut.setDataElements(0, 0, dstIn);
  98         }
  99 
 100         // REMIND: We should be able to create a SurfaceData from just
 101         // a non-writable Raster and a ColorModel.  Since we need to
 102         // create a SurfaceData from a BufferedImage then we need to
 103         // make a WritableRaster since it is needed to construct a
 104         // BufferedImage.
 105         if (srcArg instanceof WritableRaster) {
 106             src = (WritableRaster) srcArg;
 107         } else {
 108             src = srcArg.createCompatibleWritableRaster();
 109             src.setDataElements(0, 0, srcArg);
 110         }
 111 
 112         w = Math.min(src.getWidth(), dstIn.getWidth());
 113         h = Math.min(src.getHeight(), dstIn.getHeight());
 114 
 115         BufferedImage srcImg = new BufferedImage(srcCM, src,
 116                                                  srcCM.isAlphaPremultiplied(),
 117                                                  null);
 118         BufferedImage dstImg = new BufferedImage(dstCM, dstOut,
 119                                                  dstCM.isAlphaPremultiplied(),
 120                                                  null);
 121 
 122         SurfaceData srcData = BufImgSurfaceData.createData(srcImg);
 123         SurfaceData dstData = BufImgSurfaceData.createData(dstImg);
 124         Blit blit = Blit.getFromCache(srcData.getSurfaceType(),
 125                                       comptype,
 126                                       dstData.getSurfaceType());
 127         blit.Blit(srcData, dstData, composite, null, 0, 0, 0, 0, w, h);
 128     }
 129 }


  71         dstCM = d;
  72         this.composite = xc;
  73         this.comptype = CompositeType.Xor;
  74     }
  75 
  76     /**
  77      * Release resources allocated for context.
  78      */
  79     public void dispose() {
  80     }
  81 
  82     /**
  83      * This method composes the two source tiles
  84      * and places the result in the destination tile. Note that
  85      * the destination can be the same object as either
  86      * the first or second source.
  87      * @param src1 The first source tile for the compositing operation.
  88      * @param src2 The second source tile for the compositing operation.
  89      * @param dst The tile where the result of the operation is stored.
  90      */
  91     public void compose(Raster src1, Raster src2, WritableRaster dst) {
  92         WritableRaster src;
  93         int w;
  94         int h;
  95 
  96         if (src2 != dst) {
  97             dst.setDataElements(0, 0, src2);
  98         }
  99 
 100         // REMIND: We should be able to create a SurfaceData from just
 101         // a non-writable Raster and a ColorModel.  Since we need to
 102         // create a SurfaceData from a BufferedImage then we need to
 103         // make a WritableRaster since it is needed to construct a
 104         // BufferedImage.
 105         if (src1 instanceof WritableRaster) {
 106             src = (WritableRaster) src1;
 107         } else {
 108             src = src1.createCompatibleWritableRaster();
 109             src.setDataElements(0, 0, src1);
 110         }
 111 
 112         w = Math.min(src.getWidth(), src2.getWidth());
 113         h = Math.min(src.getHeight(), src2.getHeight());
 114 
 115         BufferedImage srcImg = new BufferedImage(srcCM, src,
 116                                                  srcCM.isAlphaPremultiplied(),
 117                                                  null);
 118         BufferedImage dstImg = new BufferedImage(dstCM, dst,
 119                                                  dstCM.isAlphaPremultiplied(),
 120                                                  null);
 121 
 122         SurfaceData srcData = BufImgSurfaceData.createData(srcImg);
 123         SurfaceData dstData = BufImgSurfaceData.createData(dstImg);
 124         Blit blit = Blit.getFromCache(srcData.getSurfaceType(),
 125                                       comptype,
 126                                       dstData.getSurfaceType());
 127         blit.Blit(srcData, dstData, composite, null, 0, 0, 0, 0, w, h);
 128     }
 129 }
< prev index next >