src/share/classes/java/awt/TexturePaintContext.java

Print this page




  56     double incYAcross;
  57     double incXDown;
  58     double incYDown;
  59 
  60     int colincx;
  61     int colincy;
  62     int colincxerr;
  63     int colincyerr;
  64     int rowincx;
  65     int rowincy;
  66     int rowincxerr;
  67     int rowincyerr;
  68 
  69     public static PaintContext getContext(BufferedImage bufImg,
  70                                           AffineTransform xform,
  71                                           RenderingHints hints,
  72                                           Rectangle devBounds) {
  73         WritableRaster raster = bufImg.getRaster();
  74         ColorModel cm = bufImg.getColorModel();
  75         int maxw = devBounds.width;
  76         Object val = hints.get(hints.KEY_INTERPOLATION);
  77         boolean filter =
  78             (val == null
  79              ? (hints.get(hints.KEY_RENDERING) == hints.VALUE_RENDER_QUALITY)
  80              : (val != hints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR));
  81         if (raster instanceof IntegerInterleavedRaster &&
  82             (!filter || isFilterableDCM(cm)))
  83         {
  84             IntegerInterleavedRaster iir = (IntegerInterleavedRaster) raster;
  85             if (iir.getNumDataElements() == 1 && iir.getPixelStride() == 1) {
  86                 return new Int(iir, cm, xform, maxw, filter);
  87             }
  88         } else if (raster instanceof ByteInterleavedRaster) {
  89             ByteInterleavedRaster bir = (ByteInterleavedRaster) raster;
  90             if (bir.getNumDataElements() == 1 && bir.getPixelStride() == 1) {
  91                 if (filter) {
  92                     if (isFilterableICM(cm)) {
  93                         return new ByteFilter(bir, cm, xform, maxw);
  94                     }
  95                 } else {
  96                     return new Byte(bir, cm, xform, maxw);
  97                 }
  98             }
  99         }
 100         return new Any(raster, cm, xform, maxw, filter);


 217             outRas.getHeight() < h)
 218         {
 219             // If h==1, we will probably get lots of "scanline" rects
 220             outRas = makeRaster((h == 1 ? Math.max(w, maxWidth) : w), h);
 221         }
 222         double X = mod(xOrg + x * incXAcross + y * incXDown, bWidth);
 223         double Y = mod(yOrg + x * incYAcross + y * incYDown, bHeight);
 224 
 225         setRaster((int) X, (int) Y, fractAsInt(X), fractAsInt(Y),
 226                   w, h, bWidth, bHeight,
 227                   colincx, colincxerr,
 228                   colincy, colincyerr,
 229                   rowincx, rowincxerr,
 230                   rowincy, rowincyerr);
 231 
 232         SunWritableRaster.markDirty(outRas);
 233 
 234         return outRas;
 235     }
 236 
 237     private static WeakReference xrgbRasRef;
 238     private static WeakReference argbRasRef;
 239 
 240     synchronized static WritableRaster makeRaster(ColorModel cm,
 241                                                   Raster srcRas,
 242                                                   int w, int h)
 243     {
 244         if (xrgbmodel == cm) {
 245             if (xrgbRasRef != null) {
 246                 WritableRaster wr = (WritableRaster) xrgbRasRef.get();
 247                 if (wr != null && wr.getWidth() >= w && wr.getHeight() >= h) {
 248                     xrgbRasRef = null;
 249                     return wr;
 250                 }
 251             }
 252             // If we are going to cache this Raster, make it non-tiny
 253             if (w <= 32 && h <= 32) {
 254                 w = h = 32;
 255             }
 256         } else if (argbmodel == cm) {
 257             if (argbRasRef != null) {
 258                 WritableRaster wr = (WritableRaster) argbRasRef.get();


 261                     return wr;
 262                 }
 263             }
 264             // If we are going to cache this Raster, make it non-tiny
 265             if (w <= 32 && h <= 32) {
 266                 w = h = 32;
 267             }
 268         }
 269         if (srcRas != null) {
 270             return srcRas.createCompatibleWritableRaster(w, h);
 271         } else {
 272             return cm.createCompatibleWritableRaster(w, h);
 273         }
 274     }
 275 
 276     synchronized static void dropRaster(ColorModel cm, Raster outRas) {
 277         if (outRas == null) {
 278             return;
 279         }
 280         if (xrgbmodel == cm) {
 281             xrgbRasRef = new WeakReference(outRas);
 282         } else if (argbmodel == cm) {
 283             argbRasRef = new WeakReference(outRas);
 284         }
 285     }
 286 
 287     private static WeakReference byteRasRef;
 288 
 289     synchronized static WritableRaster makeByteRaster(Raster srcRas,
 290                                                       int w, int h)
 291     {
 292         if (byteRasRef != null) {
 293             WritableRaster wr = (WritableRaster) byteRasRef.get();
 294             if (wr != null && wr.getWidth() >= w && wr.getHeight() >= h) {
 295                 byteRasRef = null;
 296                 return wr;
 297             }
 298         }
 299         // If we are going to cache this Raster, make it non-tiny
 300         if (w <= 32 && h <= 32) {
 301             w = h = 32;
 302         }
 303         return srcRas.createCompatibleWritableRaster(w, h);
 304     }
 305 
 306     synchronized static void dropByteRaster(Raster outRas) {
 307         if (outRas == null) {
 308             return;
 309         }
 310         byteRasRef = new WeakReference(outRas);
 311     }
 312 
 313     public abstract WritableRaster makeRaster(int w, int h);
 314     public abstract void setRaster(int x, int y, int xerr, int yerr,
 315                                    int w, int h, int bWidth, int bHeight,
 316                                    int colincx, int colincxerr,
 317                                    int colincy, int colincyerr,
 318                                    int rowincx, int rowincxerr,
 319                                    int rowincy, int rowincyerr);
 320 
 321     /*
 322      * Blends the four ARGB values in the rgbs array using the factors
 323      * described by xmul and ymul in the following ratio:
 324      *
 325      *     rgbs[0] * (1-xmul) * (1-ymul) +
 326      *     rgbs[1] * (  xmul) * (1-ymul) +
 327      *     rgbs[2] * (1-xmul) * (  ymul) +
 328      *     rgbs[3] * (  xmul) * (  ymul)
 329      *
 330      * xmul and ymul are integer values in the half-open range [0, 2^31)




  56     double incYAcross;
  57     double incXDown;
  58     double incYDown;
  59 
  60     int colincx;
  61     int colincy;
  62     int colincxerr;
  63     int colincyerr;
  64     int rowincx;
  65     int rowincy;
  66     int rowincxerr;
  67     int rowincyerr;
  68 
  69     public static PaintContext getContext(BufferedImage bufImg,
  70                                           AffineTransform xform,
  71                                           RenderingHints hints,
  72                                           Rectangle devBounds) {
  73         WritableRaster raster = bufImg.getRaster();
  74         ColorModel cm = bufImg.getColorModel();
  75         int maxw = devBounds.width;
  76         Object val = hints.get(RenderingHints.KEY_INTERPOLATION);
  77         boolean filter =
  78             (val == null
  79              ? (hints.get(RenderingHints.KEY_RENDERING) == RenderingHints.VALUE_RENDER_QUALITY)
  80              : (val != RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR));
  81         if (raster instanceof IntegerInterleavedRaster &&
  82             (!filter || isFilterableDCM(cm)))
  83         {
  84             IntegerInterleavedRaster iir = (IntegerInterleavedRaster) raster;
  85             if (iir.getNumDataElements() == 1 && iir.getPixelStride() == 1) {
  86                 return new Int(iir, cm, xform, maxw, filter);
  87             }
  88         } else if (raster instanceof ByteInterleavedRaster) {
  89             ByteInterleavedRaster bir = (ByteInterleavedRaster) raster;
  90             if (bir.getNumDataElements() == 1 && bir.getPixelStride() == 1) {
  91                 if (filter) {
  92                     if (isFilterableICM(cm)) {
  93                         return new ByteFilter(bir, cm, xform, maxw);
  94                     }
  95                 } else {
  96                     return new Byte(bir, cm, xform, maxw);
  97                 }
  98             }
  99         }
 100         return new Any(raster, cm, xform, maxw, filter);


 217             outRas.getHeight() < h)
 218         {
 219             // If h==1, we will probably get lots of "scanline" rects
 220             outRas = makeRaster((h == 1 ? Math.max(w, maxWidth) : w), h);
 221         }
 222         double X = mod(xOrg + x * incXAcross + y * incXDown, bWidth);
 223         double Y = mod(yOrg + x * incYAcross + y * incYDown, bHeight);
 224 
 225         setRaster((int) X, (int) Y, fractAsInt(X), fractAsInt(Y),
 226                   w, h, bWidth, bHeight,
 227                   colincx, colincxerr,
 228                   colincy, colincyerr,
 229                   rowincx, rowincxerr,
 230                   rowincy, rowincyerr);
 231 
 232         SunWritableRaster.markDirty(outRas);
 233 
 234         return outRas;
 235     }
 236 
 237     private static WeakReference<Raster> xrgbRasRef;
 238     private static WeakReference<Raster> argbRasRef;
 239 
 240     synchronized static WritableRaster makeRaster(ColorModel cm,
 241                                                   Raster srcRas,
 242                                                   int w, int h)
 243     {
 244         if (xrgbmodel == cm) {
 245             if (xrgbRasRef != null) {
 246                 WritableRaster wr = (WritableRaster) xrgbRasRef.get();
 247                 if (wr != null && wr.getWidth() >= w && wr.getHeight() >= h) {
 248                     xrgbRasRef = null;
 249                     return wr;
 250                 }
 251             }
 252             // If we are going to cache this Raster, make it non-tiny
 253             if (w <= 32 && h <= 32) {
 254                 w = h = 32;
 255             }
 256         } else if (argbmodel == cm) {
 257             if (argbRasRef != null) {
 258                 WritableRaster wr = (WritableRaster) argbRasRef.get();


 261                     return wr;
 262                 }
 263             }
 264             // If we are going to cache this Raster, make it non-tiny
 265             if (w <= 32 && h <= 32) {
 266                 w = h = 32;
 267             }
 268         }
 269         if (srcRas != null) {
 270             return srcRas.createCompatibleWritableRaster(w, h);
 271         } else {
 272             return cm.createCompatibleWritableRaster(w, h);
 273         }
 274     }
 275 
 276     synchronized static void dropRaster(ColorModel cm, Raster outRas) {
 277         if (outRas == null) {
 278             return;
 279         }
 280         if (xrgbmodel == cm) {
 281             xrgbRasRef = new WeakReference<>(outRas);
 282         } else if (argbmodel == cm) {
 283             argbRasRef = new WeakReference<>(outRas);
 284         }
 285     }
 286 
 287     private static WeakReference<Raster> byteRasRef;
 288 
 289     synchronized static WritableRaster makeByteRaster(Raster srcRas,
 290                                                       int w, int h)
 291     {
 292         if (byteRasRef != null) {
 293             WritableRaster wr = (WritableRaster) byteRasRef.get();
 294             if (wr != null && wr.getWidth() >= w && wr.getHeight() >= h) {
 295                 byteRasRef = null;
 296                 return wr;
 297             }
 298         }
 299         // If we are going to cache this Raster, make it non-tiny
 300         if (w <= 32 && h <= 32) {
 301             w = h = 32;
 302         }
 303         return srcRas.createCompatibleWritableRaster(w, h);
 304     }
 305 
 306     synchronized static void dropByteRaster(Raster outRas) {
 307         if (outRas == null) {
 308             return;
 309         }
 310         byteRasRef = new WeakReference<>(outRas);
 311     }
 312 
 313     public abstract WritableRaster makeRaster(int w, int h);
 314     public abstract void setRaster(int x, int y, int xerr, int yerr,
 315                                    int w, int h, int bWidth, int bHeight,
 316                                    int colincx, int colincxerr,
 317                                    int colincy, int colincyerr,
 318                                    int rowincx, int rowincxerr,
 319                                    int rowincy, int rowincyerr);
 320 
 321     /*
 322      * Blends the four ARGB values in the rgbs array using the factors
 323      * described by xmul and ymul in the following ratio:
 324      *
 325      *     rgbs[0] * (1-xmul) * (1-ymul) +
 326      *     rgbs[1] * (  xmul) * (1-ymul) +
 327      *     rgbs[2] * (1-xmul) * (  ymul) +
 328      *     rgbs[3] * (  xmul) * (  ymul)
 329      *
 330      * xmul and ymul are integer values in the half-open range [0, 2^31)