261 return; 262 } 263 264 renderImageXform(sg, img, tx, interpType, sx1, sy1, sx2, sy2, bgColor); 265 } 266 267 /* 268 * Check the bounding coordinates of the transformed source 269 * image to see if they fall on integer coordinates such 270 * that they will cause no interpolation anomalies if we 271 * use our simplified Blit or ScaledBlit operations instead 272 * of a full transform operation. 273 */ 274 protected boolean tryCopyOrScale(SunGraphics2D sg, 275 Image img, 276 int sx1, int sy1, 277 int sx2, int sy2, 278 Color bgColor, int interpType, 279 double coords[]) 280 { 281 double dx = coords[0]; 282 double dy = coords[1]; 283 double dw = coords[2] - dx; 284 double dh = coords[3] - dy; 285 // First check if width and height are very close to img w&h. 286 if (closeToInteger(sx2-sx1, dw) && closeToInteger(sy2-sy1, dh)) { 287 // Round location to nearest pixel and then test 288 // if it will cause interpolation anomalies. 289 int idx = (int) Math.floor(dx + 0.5); 290 int idy = (int) Math.floor(dy + 0.5); 291 if (interpType == AffineTransformOp.TYPE_NEAREST_NEIGHBOR || 292 (closeToInteger(idx, dx) && closeToInteger(idy, dy))) 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 * <p> 319 * Returned BufferedImage is not accelerated for two reasons: 320 * <ul> 321 * <li> Types of the image and surface are predefined, because these types 322 * correspond to the TransformHelpers, which we know we have. And 323 * acceleration can change the type of the surface 324 * <li> Image will be used only once and acceleration caching wouldn't help 325 * </ul> | 261 return; 262 } 263 264 renderImageXform(sg, img, tx, interpType, sx1, sy1, sx2, sy2, bgColor); 265 } 266 267 /* 268 * Check the bounding coordinates of the transformed source 269 * image to see if they fall on integer coordinates such 270 * that they will cause no interpolation anomalies if we 271 * use our simplified Blit or ScaledBlit operations instead 272 * of a full transform operation. 273 */ 274 protected boolean tryCopyOrScale(SunGraphics2D sg, 275 Image img, 276 int sx1, int sy1, 277 int sx2, int sy2, 278 Color bgColor, int interpType, 279 double coords[]) 280 { 281 double dx1 = coords[0]; 282 double dy1 = coords[1]; 283 double dx2 = coords[2]; 284 double dy2 = coords[3]; 285 double dw = dx2 - dx1; 286 double dh = dy2 - dy1; 287 288 /* If any of the destination coordinates exceed the integer range, 289 * then the calculations performed in calls made here cannot be 290 * guaranteed to be correct, or to converge (terminate). 291 * So return out of here, deferring to code that can handle this. 292 */ 293 if (dx1 < Integer.MIN_VALUE || dx1 > Integer.MAX_VALUE || 294 dy1 < Integer.MIN_VALUE || dy1 > Integer.MAX_VALUE || 295 dx2 < Integer.MIN_VALUE || dx2 > Integer.MAX_VALUE || 296 dy2 < Integer.MIN_VALUE || dy2 > Integer.MAX_VALUE) 297 { 298 return false; 299 } 300 301 // First check if width and height are very close to img w&h. 302 if (closeToInteger(sx2-sx1, dw) && closeToInteger(sy2-sy1, dh)) { 303 // Round location to nearest pixel and then test 304 // if it will cause interpolation anomalies. 305 int idx = (int) Math.floor(dx1 + 0.5); 306 int idy = (int) Math.floor(dy1 + 0.5); 307 if (interpType == AffineTransformOp.TYPE_NEAREST_NEIGHBOR || 308 (closeToInteger(idx, dx1) && closeToInteger(idy, dy1))) 309 { 310 renderImageCopy(sg, img, bgColor, 311 idx, idy, 312 sx1, sy1, sx2-sx1, sy2-sy1); 313 return true; 314 } 315 } 316 // (For now) We can only use our ScaledBlits if the image 317 // is upright (i.e. dw & dh both > 0) 318 if (dw > 0 && dh > 0) { 319 if (renderImageScale(sg, img, bgColor, interpType, 320 sx1, sy1, sx2, sy2, 321 dx1, dy1, dx2, dy2)) 322 { 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> |