jdk/src/share/classes/sun/java2d/pipe/DrawImage.java
changeset 11080 7e18e343964e
parent 9830 692619a439fc
child 16840 64446d4710c4
equal deleted inserted replaced
11059:b5060eae3b32 11080:7e18e343964e
   144         int txtype = extraAT.getType();
   144         int txtype = extraAT.getType();
   145         int imgw = img.getWidth(null);
   145         int imgw = img.getWidth(null);
   146         int imgh = img.getHeight(null);
   146         int imgh = img.getHeight(null);
   147         boolean checkfinalxform;
   147         boolean checkfinalxform;
   148 
   148 
   149         if (sg.transformState <= sg.TRANSFORM_ANY_TRANSLATE &&
   149         if (sg.transformState <= SunGraphics2D.TRANSFORM_ANY_TRANSLATE &&
   150             (txtype == AffineTransform.TYPE_IDENTITY ||
   150             (txtype == AffineTransform.TYPE_IDENTITY ||
   151              txtype == AffineTransform.TYPE_TRANSLATION))
   151              txtype == AffineTransform.TYPE_TRANSLATION))
   152         {
   152         {
   153             // First optimization - both are some kind of translate
   153             // First optimization - both are some kind of translate
   154 
   154 
   164             {
   164             {
   165                 renderImageCopy(sg, img, null, x+itx, y+ity, 0, 0, imgw, imgh);
   165                 renderImageCopy(sg, img, null, x+itx, y+ity, 0, 0, imgw, imgh);
   166                 return;
   166                 return;
   167             }
   167             }
   168             checkfinalxform = false;
   168             checkfinalxform = false;
   169         } else if (sg.transformState <= sg.TRANSFORM_TRANSLATESCALE &&
   169         } else if (sg.transformState <= SunGraphics2D.TRANSFORM_TRANSLATESCALE &&
   170                    ((txtype & (AffineTransform.TYPE_FLIP |
   170                    ((txtype & (AffineTransform.TYPE_FLIP |
   171                                AffineTransform.TYPE_MASK_ROTATION |
   171                                AffineTransform.TYPE_MASK_ROTATION |
   172                                AffineTransform.TYPE_GENERAL_TRANSFORM)) == 0))
   172                                AffineTransform.TYPE_GENERAL_TRANSFORM)) == 0))
   173         {
   173         {
   174             // Second optimization - both are some kind of translate or scale
   174             // Second optimization - both are some kind of translate or scale
   342                                     Color bgColor)
   342                                     Color bgColor)
   343     {
   343     {
   344         Region clip = sg.getCompClip();
   344         Region clip = sg.getCompClip();
   345         SurfaceData dstData = sg.surfaceData;
   345         SurfaceData dstData = sg.surfaceData;
   346         SurfaceData srcData = dstData.getSourceSurfaceData(img,
   346         SurfaceData srcData = dstData.getSourceSurfaceData(img,
   347                                                            sg.TRANSFORM_GENERIC,
   347                                                            SunGraphics2D.TRANSFORM_GENERIC,
   348                                                            sg.imageComp,
   348                                                            sg.imageComp,
   349                                                            bgColor);
   349                                                            bgColor);
   350 
   350 
   351         if (srcData == null) {
   351         if (srcData == null) {
   352             img = getBufferedImage(img);
   352             img = getBufferedImage(img);
   353             srcData = dstData.getSourceSurfaceData(img,
   353             srcData = dstData.getSourceSurfaceData(img,
   354                                                    sg.TRANSFORM_GENERIC,
   354                                                    SunGraphics2D.TRANSFORM_GENERIC,
   355                                                    sg.imageComp,
   355                                                    sg.imageComp,
   356                                                    bgColor);
   356                                                    bgColor);
   357             if (srcData == null) {
   357             if (srcData == null) {
   358                 // REMIND: Is this correct?  Can this happen?
   358                 // REMIND: Is this correct?  Can this happen?
   359                 return;
   359                 return;
   370             sx2 -= sx1;
   370             sx2 -= sx1;
   371             sy2 -= sy1;
   371             sy2 -= sy1;
   372             sx1 = sy1 = 0;
   372             sx1 = sy1 = 0;
   373 
   373 
   374             srcData = dstData.getSourceSurfaceData(img,
   374             srcData = dstData.getSourceSurfaceData(img,
   375                                                    sg.TRANSFORM_GENERIC,
   375                                                    SunGraphics2D.TRANSFORM_GENERIC,
   376                                                    sg.imageComp,
   376                                                    sg.imageComp,
   377                                                    bgColor);
   377                                                    bgColor);
   378         }
   378         }
   379 
   379 
   380         SurfaceType srcType = srcData.getSurfaceType();
   380         SurfaceType srcType = srcData.getSurfaceType();
   396             sx2 -= sx1;
   396             sx2 -= sx1;
   397             sy2 -= sy1;
   397             sy2 -= sy1;
   398             sx1 = sy1 = 0;
   398             sx1 = sy1 = 0;
   399 
   399 
   400             srcData = dstData.getSourceSurfaceData(img,
   400             srcData = dstData.getSourceSurfaceData(img,
   401                                                    sg.TRANSFORM_GENERIC,
   401                                                    SunGraphics2D.TRANSFORM_GENERIC,
   402                                                    sg.imageComp,
   402                                                    sg.imageComp,
   403                                                    null);
   403                                                    null);
   404             srcType = srcData.getSurfaceType();
   404             srcType = srcData.getSurfaceType();
   405             helper = TransformHelper.getFromCache(srcType);
   405             helper = TransformHelper.getFromCache(srcType);
   406             // assert(helper != null);
   406             // assert(helper != null);
   447         int dy2 = (int) Math.ceil(ddy2);
   447         int dy2 = (int) Math.ceil(ddy2);
   448 
   448 
   449         SurfaceType dstType = dstData.getSurfaceType();
   449         SurfaceType dstType = dstData.getSurfaceType();
   450         MaskBlit maskblit;
   450         MaskBlit maskblit;
   451         Blit blit;
   451         Blit blit;
   452         if (sg.compositeState <= sg.COMP_ALPHA) {
   452         if (sg.compositeState <= SunGraphics2D.COMP_ALPHA) {
   453             /* NOTE: We either have, or we can make,
   453             /* NOTE: We either have, or we can make,
   454              * a MaskBlit for any alpha composite type
   454              * a MaskBlit for any alpha composite type
   455              */
   455              */
   456             maskblit = MaskBlit.getFromCache(SurfaceType.IntArgbPre,
   456             maskblit = MaskBlit.getFromCache(SurfaceType.IntArgbPre,
   457                                              sg.imageComp,
   457                                              sg.imageComp,
   563         // revalidate the surfaceData objects in case of an exception
   563         // revalidate the surfaceData objects in case of an exception
   564         // and try it once more
   564         // and try it once more
   565         while (true) {
   565         while (true) {
   566             SurfaceData srcData =
   566             SurfaceData srcData =
   567                 dstData.getSourceSurfaceData(img,
   567                 dstData.getSourceSurfaceData(img,
   568                                              sg.TRANSFORM_ISIDENT,
   568                                              SunGraphics2D.TRANSFORM_ISIDENT,
   569                                              sg.imageComp,
   569                                              sg.imageComp,
   570                                              bgColor);
   570                                              bgColor);
   571             if (srcData == null) {
   571             if (srcData == null) {
   572                 return false;
   572                 return false;
   573             }
   573             }
   626         // revalidate the surfaceData objects in case of an exception
   626         // revalidate the surfaceData objects in case of an exception
   627         // and try it once more
   627         // and try it once more
   628         while (true) {
   628         while (true) {
   629             SurfaceData srcData =
   629             SurfaceData srcData =
   630                 dstData.getSourceSurfaceData(img,
   630                 dstData.getSourceSurfaceData(img,
   631                                              sg.TRANSFORM_TRANSLATESCALE,
   631                                              SunGraphics2D.TRANSFORM_TRANSLATESCALE,
   632                                              sg.imageComp,
   632                                              sg.imageComp,
   633                                              bgColor);
   633                                              bgColor);
   634 
   634 
   635             if (srcData == null || isBgOperation(srcData, bgColor)) {
   635             if (srcData == null || isBgOperation(srcData, bgColor)) {
   636                 return false;
   636                 return false;
   798         return (Math.abs(d-i) < MAX_TX_ERROR);
   798         return (Math.abs(d-i) < MAX_TX_ERROR);
   799     }
   799     }
   800 
   800 
   801     public static boolean isSimpleTranslate(SunGraphics2D sg) {
   801     public static boolean isSimpleTranslate(SunGraphics2D sg) {
   802         int ts = sg.transformState;
   802         int ts = sg.transformState;
   803         if (ts <= sg.TRANSFORM_INT_TRANSLATE) {
   803         if (ts <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) {
   804             // Integer translates are always "simple"
   804             // Integer translates are always "simple"
   805             return true;
   805             return true;
   806         }
   806         }
   807         if (ts >= sg.TRANSFORM_TRANSLATESCALE) {
   807         if (ts >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
   808             // Scales and beyond are always "not simple"
   808             // Scales and beyond are always "not simple"
   809             return false;
   809             return false;
   810         }
   810         }
   811         // non-integer translates are only simple when not interpolating
   811         // non-integer translates are only simple when not interpolating
   812         if (sg.interpolationType == AffineTransformOp.TYPE_NEAREST_NEIGHBOR) {
   812         if (sg.interpolationType == AffineTransformOp.TYPE_NEAREST_NEIGHBOR) {
   844         if (tx.isIdentity()) {
   844         if (tx.isIdentity()) {
   845             return dstCM;
   845             return dstCM;
   846         }
   846         }
   847         int type = tx.getType();
   847         int type = tx.getType();
   848         boolean needTrans =
   848         boolean needTrans =
   849             ((type&(tx.TYPE_MASK_ROTATION|tx.TYPE_GENERAL_TRANSFORM)) != 0);
   849                 ((type & (AffineTransform.TYPE_MASK_ROTATION |
   850         if (! needTrans && type != tx.TYPE_TRANSLATION && type != tx.TYPE_IDENTITY)
   850                           AffineTransform.TYPE_GENERAL_TRANSFORM)) != 0);
       
   851         if (! needTrans &&
       
   852               type != AffineTransform.TYPE_TRANSLATION &&
       
   853               type != AffineTransform.TYPE_IDENTITY)
   851         {
   854         {
   852             double[] mtx = new double[4];
   855             double[] mtx = new double[4];
   853             tx.getMatrix(mtx);
   856             tx.getMatrix(mtx);
   854             // Check out the matrix.  A non-integral scale will force ARGB
   857             // Check out the matrix.  A non-integral scale will force ARGB
   855             // since the edge conditions cannot be guaranteed.
   858             // since the edge conditions cannot be guaranteed.
   859         if (sg.renderHint != SunHints.INTVAL_RENDER_QUALITY) {
   862         if (sg.renderHint != SunHints.INTVAL_RENDER_QUALITY) {
   860             if (cm instanceof IndexColorModel) {
   863             if (cm instanceof IndexColorModel) {
   861                 Raster raster = bImg.getRaster();
   864                 Raster raster = bImg.getRaster();
   862                 IndexColorModel icm = (IndexColorModel) cm;
   865                 IndexColorModel icm = (IndexColorModel) cm;
   863                 // Just need to make sure that we have a transparent pixel
   866                 // Just need to make sure that we have a transparent pixel
   864                 if (needTrans && cm.getTransparency() == cm.OPAQUE) {
   867                 if (needTrans && cm.getTransparency() == Transparency.OPAQUE) {
   865                     // Fix 4221407
   868                     // Fix 4221407
   866                     if (raster instanceof sun.awt.image.BytePackedRaster) {
   869                     if (raster instanceof sun.awt.image.BytePackedRaster) {
   867                         dstCM = ColorModel.getRGBdefault();
   870                         dstCM = ColorModel.getRGBdefault();
   868                     }
   871                     }
   869                     else {
   872                     else {
   890                             }
   893                             }
   891                         }  /* if (matrix[0] < 1.f ...) */
   894                         }  /* if (matrix[0] < 1.f ...) */
   892                     }   /* raster instanceof sun.awt.image.BytePackedRaster */
   895                     }   /* raster instanceof sun.awt.image.BytePackedRaster */
   893                 } /* if (cm.getTransparency() == cm.OPAQUE) */
   896                 } /* if (cm.getTransparency() == cm.OPAQUE) */
   894             } /* if (cm instanceof IndexColorModel) */
   897             } /* if (cm instanceof IndexColorModel) */
   895             else if (needTrans && cm.getTransparency() == cm.OPAQUE) {
   898             else if (needTrans && cm.getTransparency() == Transparency.OPAQUE) {
   896                 // Need a bitmask transparency
   899                 // Need a bitmask transparency
   897                 // REMIND: for now, use full transparency since no loops
   900                 // REMIND: for now, use full transparency since no loops
   898                 // for bitmask
   901                 // for bitmask
   899                 dstCM = ColorModel.getRGBdefault();
   902                 dstCM = ColorModel.getRGBdefault();
   900             }
   903             }
   901         } /* if (sg.renderHint == RENDER_QUALITY) */
   904         } /* if (sg.renderHint == RENDER_QUALITY) */
   902         else {
   905         else {
   903 
   906 
   904             if (cm instanceof IndexColorModel ||
   907             if (cm instanceof IndexColorModel ||
   905                 (needTrans && cm.getTransparency() == cm.OPAQUE))
   908                 (needTrans && cm.getTransparency() == Transparency.OPAQUE))
   906             {
   909             {
   907                 // Need a bitmask transparency
   910                 // Need a bitmask transparency
   908                 // REMIND: for now, use full transparency since no loops
   911                 // REMIND: for now, use full transparency since no loops
   909                 // for bitmask
   912                 // for bitmask
   910                 dstCM = ColorModel.getRGBdefault();
   913                 dstCM = ColorModel.getRGBdefault();