1 /* |
1 /* |
2 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
308 } |
308 } |
309 } |
309 } |
310 return false; |
310 return false; |
311 } |
311 } |
312 |
312 |
313 /* |
313 /** |
314 * Return a BufferedImage of the requested type with the indicated |
314 * Return a non-accelerated BufferedImage of the requested type with the |
315 * subimage of the original image located at 0,0 in the new image. |
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 |
316 * If a bgColor is supplied, composite the original image over that color |
317 * color with a SrcOver operation, otherwise make a SrcNoEa copy. |
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> |
318 */ |
326 */ |
319 BufferedImage makeBufferedImage(Image img, Color bgColor, int type, |
327 BufferedImage makeBufferedImage(Image img, Color bgColor, int type, |
320 int sx1, int sy1, int sx2, int sy2) |
328 int sx1, int sy1, int sx2, int sy2) |
321 { |
329 { |
322 final int width = sx2 - sx1; |
330 final int width = sx2 - sx1; |
323 final int height = sy2 - sy1; |
331 final int height = sy2 - sy1; |
324 final BufferedImage bimg = new BufferedImage(width, height, type); |
332 final BufferedImage bimg = new BufferedImage(width, height, type); |
325 final SunGraphics2D g2d = (SunGraphics2D) bimg.createGraphics(); |
333 final SunGraphics2D g2d = (SunGraphics2D) bimg.createGraphics(); |
326 g2d.setComposite(AlphaComposite.Src); |
334 g2d.setComposite(AlphaComposite.Src); |
|
335 bimg.setAccelerationPriority(0); |
327 if (bgColor != null) { |
336 if (bgColor != null) { |
328 g2d.setColor(bgColor); |
337 g2d.setColor(bgColor); |
329 g2d.fillRect(0, 0, width, height); |
338 g2d.fillRect(0, 0, width, height); |
330 g2d.setComposite(AlphaComposite.SrcOver); |
339 g2d.setComposite(AlphaComposite.SrcOver); |
331 } |
340 } |