private static void ensureLoaded(Image image) { if ( (Toolkit.getDefaultToolkit().checkImage(image, -1, -1, null) & (ImageObserver.ALLBITS | ImageObserver.FRAMEBITS)) != 0 ) { return; } synchronized (tracker) { int id = ++mediaTrackerID; tracker.addImage(image, id); try { tracker.waitForID(id, 0); } catch (InterruptedException e) { System.out.println("INTERRUPTED while loading Image"); } // #262804 assertation disabled because of error, when using ImageFilter // assert (tracker.statusID(id, false) == MediaTracker.COMPLETE) : "Image loaded"; tracker.removeImage(image, id); } }
public synchronized void reconstruct(int flags) { if (src != null) { src.checkSecurity(null, false); } int missinginfo = flags & ~availinfo; if ((availinfo & ImageObserver.ERROR) == 0 && missinginfo != 0) { numWaiters++; try { startProduction(); missinginfo = flags & ~availinfo; while ((availinfo & ImageObserver.ERROR) == 0 && missinginfo != 0) { try { wait(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return; } missinginfo = flags & ~availinfo; } } finally { decrementWaiters(); } } }
public void draw(Graphics g, int x, int y, double scale, ImageObserver obs) { if (srcOp == null || scale <= 0) return; final BufferedImage img; if (scale == 1.0) { img = srcOp.getImage(); } else { if (scaleOp == null || scaleOp.getScale() != scale) { scaleOp = Op.scale(srcOp, scale); } img = scaleOp.getImage(); } if (img == null) return; g.drawImage(img, x, y, obs); }
public boolean scaleImage(SunGraphics2D sg, Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgColor, ImageObserver observer) { if (!(img instanceof ToolkitImage)) { return scaleImage(sg, img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgColor); } else { ToolkitImage sunimg = (ToolkitImage)img; if (!imageReady(sunimg, observer)) { return false; } ImageRepresentation ir = sunimg.getImageRep(); return ir.drawToBufImage(sg, sunimg, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgColor, observer); } }
public boolean imageUpdate(Image image, int info, int x, int y, int w, int h) { if (image == this.image) { System.out.println("Image status: " + dump(info)); synchronized(this) { isReady = (info & ImageObserver.ALLBITS) != 0; if (isReady) { synchronized(lock) { lock.notifyAll(); } } } return !isReady; } else { return true; } }
public static int[] getPixels(Image img, int x, int y, int w, int h) { int[] pixels = new int[w * h]; // PixelGrabber does the work of getting // actual RGB pixel values for // us from // the image. PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w); try { pg.grabPixels(); } catch (InterruptedException e) { System.err.println("interrupted waiting for pixels!"); } if ((pg.getStatus() & ImageObserver.ABORT) != 0) { System.err.println("image fetch aborted or errored"); } return pixels; }
public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) { if (img == null) { return true; } boolean result; int srcWidth = img.getWidth(null); int srcHeight = img.getHeight(null); if (srcWidth < 0 || srcHeight < 0) { result = false; } else { result = drawImage(img, x, y, srcWidth, srcHeight, bgcolor, observer); } return result; }
synchronized void abort() { image.getSource().removeConsumer(this); consuming = false; newbits = null; bimage = null; biRaster = null; cmodel = null; srcLUT = null; isDefaultBI = false; isSameCM = false; newInfo(image, ImageObserver.ABORT, -1, -1, -1, -1); availinfo &= ~(ImageObserver.SOMEBITS | ImageObserver.FRAMEBITS | ImageObserver.ALLBITS | ImageObserver.ERROR); }
public boolean copyImage(SunGraphics2D sg, Image img, int dx, int dy, int sx, int sy, int w, int h, Color bgColor, ImageObserver observer) { if (!(img instanceof ToolkitImage)) { return copyImage(sg, img, dx, dy, sx, sy, w, h, bgColor); } else { ToolkitImage sunimg = (ToolkitImage)img; if (!imageReady(sunimg, observer)) { return false; } ImageRepresentation ir = sunimg.getImageRep(); return ir.drawToBufImage(sg, sunimg, dx, dy, (dx + w), (dy + h), sx, sy, (sx + w), (sy + h), bgColor, observer); } }
public boolean prepare(ImageObserver iw) { if (src != null) { src.checkSecurity(null, false); } if ((availinfo & ImageObserver.ERROR) != 0) { if (iw != null) { iw.imageUpdate(image, ImageObserver.ERROR|ImageObserver.ABORT, -1, -1, -1, -1); } return false; } boolean done = ((availinfo & ImageObserver.ALLBITS) != 0); if (!done) { addWatcher(iw); startProduction(); // Some producers deliver image data synchronously done = ((availinfo & ImageObserver.ALLBITS) != 0); } return done; }
private synchronized void reconstruct(int flags) { if ((flags & ~availinfo) != 0) { if ((availinfo & ImageObserver.ERROR) != 0) { return; } ImageRepresentation ir = getImageRep(); ir.startProduction(); while ((flags & ~availinfo) != 0) { try { wait(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return; } if ((availinfo & ImageObserver.ERROR) != 0) { return; } } } }
/** * Maps {@code Component.prepareImage(Image, int, int, ImageObserver)} * through queue */ public boolean prepareImage(final Image image, final int i, final int i1, final ImageObserver imageObserver) { return (runMapping(new MapBooleanAction("prepareImage") { @Override public boolean map() { return getSource().prepareImage(image, i, i1, imageObserver); } })); }
public boolean drawToBufImage(Graphics g, ToolkitImage img, AffineTransform xform, ImageObserver iw) { Graphics2D g2 = (Graphics2D) g; if (src != null) { src.checkSecurity(null, false); } if ((availinfo & ImageObserver.ERROR) != 0) { if (iw != null) { iw.imageUpdate(image, ImageObserver.ERROR|ImageObserver.ABORT, -1, -1, -1, -1); } return false; } boolean done = ((availinfo & ImageObserver.ALLBITS) != 0); boolean abort = ((availinfo & ImageObserver.ABORT) != 0); if (!done && !abort) { addWatcher(iw); startProduction(); // Some producers deliver image data synchronously done = ((availinfo & ImageObserver.ALLBITS) != 0); } if (done || (0 != (availinfo & ImageObserver.FRAMEBITS))) { g2.drawImage (bimage, xform, null); } return done; }
public void preload(ImageObserver iw) { if (src != null) { src.checkSecurity(null, false); } if ((availinfo & ImageObserver.ALLBITS) == 0) { addWatcher(iw, true); } }
/** * Draws an image at x,y in nonblocking mode with a solid background * color and a callback object. */ public boolean drawImage(Image img, int x, int y, Color bg, ImageObserver observer) { if (img == null) { return true; } if (isHiDPIImage(img)) { final int imgW = img.getWidth(null); final int imgH = img.getHeight(null); return drawHiDPIImage(img, x, y, x + imgW, y + imgH, 0, 0, imgW, imgH, bg, observer); } try { return imagepipe.copyImage(this, img, x, y, bg, observer); } catch (InvalidPipeException e) { try { revalidateAll(); return imagepipe.copyImage(this, img, x, y, bg, observer); } catch (InvalidPipeException e2) { // Still catching the exception; we are not yet ready to // validate the surfaceData correctly. Fail for now and // try again next time around. return false; } } finally { surfaceData.markDirty(); } }
public boolean scaleImage(SunGraphics2D sg, Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgColor, ImageObserver observer) { return false; }
synchronized void infoDone(int status) { if (status == ImageConsumer.IMAGEERROR || ((~availinfo) & (ImageObserver.WIDTH | ImageObserver.HEIGHT)) != 0) { addInfo(ImageObserver.ERROR); } else if ((availinfo & ImageObserver.PROPERTIES) == 0) { setProperties(null); } }
@Override public void paintOverlay(Graphics2D g2d, ImageRegion imageRegion, double downsampleFactor, ImageObserver observer, boolean paintCompletely) { if (trackerFeatures != null) { if (doPaintBoundsHeatmap.get()) { paintBoundsHeatmap(g2d); } if (doPaintCursorHeatmap.get()) { paintCursorHeatmap(g2d); } if (doPaintEyeHeatmap.get()) { paintEyeHeatmap(g2d); } } }
/** * Draws a subrectangle of an image scaled to a destination rectangle * in nonblocking mode with a callback object. */ public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) { return drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null, observer); }
private synchronized void addWatcher(ImageObserver iw, boolean load) { if ((availinfo & ImageObserver.ERROR) != 0) { if (iw != null) { iw.imageUpdate(this, ImageObserver.ERROR|ImageObserver.ABORT, -1, -1, -1, -1); } return; } ImageRepresentation ir = getImageRep(); ir.addWatcher(iw); if (load) { ir.startProduction(); } }
synchronized void dispose() { image.getSource().removeConsumer(this); consuming = false; newbits = null; availinfo &= ~(ImageObserver.SOMEBITS | ImageObserver.FRAMEBITS | ImageObserver.ALLBITS); }
public void removeWatcher(ImageObserver iw) { synchronized (this) { watcherList = watcherList.removeWatcher(iw); } if (watcherList == endlink) { notifyWatcherListEmpty(); } }
public boolean drawToBufImage(Graphics g, ToolkitImage img, int x, int y, Color bg, ImageObserver iw) { if (src != null) { src.checkSecurity(null, false); } if ((availinfo & ImageObserver.ERROR) != 0) { if (iw != null) { iw.imageUpdate(image, ImageObserver.ERROR|ImageObserver.ABORT, -1, -1, -1, -1); } return false; } boolean done = ((availinfo & ImageObserver.ALLBITS) != 0); boolean abort = ((availinfo & ImageObserver.ABORT) != 0); if (!done && !abort) { addWatcher(iw); startProduction(); // Some producers deliver image data synchronously done = ((availinfo & ImageObserver.ALLBITS) != 0); } if (done || (0 != (availinfo & ImageObserver.FRAMEBITS))) { g.drawImage (bimage, x, y, bg, null); } return done; }
private synchronized void checkConsumption() { if (isWatcherListEmpty() && numWaiters == 0 && ((availinfo & ImageObserver.ALLBITS) == 0)) { dispose(); } }
public static BufferedImage scaleBufferedImage(BufferedImage p_scaleBufferedImage_0_, int p_scaleBufferedImage_1_, int p_scaleBufferedImage_2_) { BufferedImage bufferedimage = new BufferedImage(p_scaleBufferedImage_1_, p_scaleBufferedImage_2_, 2); Graphics2D graphics2d = bufferedimage.createGraphics(); graphics2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); graphics2d.drawImage(p_scaleBufferedImage_0_, 0, 0, p_scaleBufferedImage_1_, p_scaleBufferedImage_2_, (ImageObserver)null); return bufferedimage; }
/** * Return the width of the original image source. * If the width isn't known, then the ImageObserver object will be * notified when the data is available. */ public synchronized int getWidth(ImageObserver iw) { if (src != null) { src.checkSecurity(null, false); } if ((availinfo & ImageObserver.WIDTH) == 0) { addWatcher(iw, true); if ((availinfo & ImageObserver.WIDTH) == 0) { return -1; } } return width; }
public static BufferedImage scaleToPowerOfTwo(BufferedImage p_scaleToPowerOfTwo_0_, int p_scaleToPowerOfTwo_1_) { if (p_scaleToPowerOfTwo_0_ == null) { return p_scaleToPowerOfTwo_0_; } else { int i = p_scaleToPowerOfTwo_0_.getWidth(); int j = p_scaleToPowerOfTwo_0_.getHeight(); int k = Math.max(i, p_scaleToPowerOfTwo_1_); k = MathHelper.roundUpToPowerOfTwo(k); if (k == i) { return p_scaleToPowerOfTwo_0_; } else { int l = j * k / i; BufferedImage bufferedimage = new BufferedImage(k, l, 2); Graphics2D graphics2d = bufferedimage.createGraphics(); Object object = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR; if (k % i != 0) { object = RenderingHints.VALUE_INTERPOLATION_BILINEAR; } graphics2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, object); graphics2d.drawImage(p_scaleToPowerOfTwo_0_, 0, 0, k, l, (ImageObserver)null); return bufferedimage; } } }
public int check(ImageObserver iw) { if (src != null) { src.checkSecurity(null, false); } if ((availinfo & (ImageObserver.ERROR | ImageObserver.ALLBITS)) == 0) { addWatcher(iw); } return availinfo; }
public boolean transformImage(SunGraphics2D sg, Image img, AffineTransform atfm, ImageObserver observer) { if (!(img instanceof ToolkitImage)) { transformImage(sg, img, 0, 0, atfm, sg.interpolationType); return true; } else { ToolkitImage sunimg = (ToolkitImage)img; if (!imageReady(sunimg, observer)) { return false; } ImageRepresentation ir = sunimg.getImageRep(); return ir.drawToBufImage(sg, sunimg, atfm, observer); } }
public boolean transformImage(SunGraphics2D sg, Image img, AffineTransform atfm, ImageObserver observer) { if (validate(sg)) { return sg.imagepipe.transformImage(sg, img, atfm, observer); } else { return false; } }
static void testToolkitImageObserver(final Image image) { ImageObserver observer = new ImageObserver() { @Override public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { if (img != image) { throw new RuntimeException("Wrong image in observer"); } if ((infoflags & (ImageObserver.ERROR | ImageObserver.ABORT)) != 0) { throw new RuntimeException("Error during image loading"); } return (infoflags & ImageObserver.ALLBITS) == 0; } }; final BufferedImage bufferedImage2x = new BufferedImage(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); Graphics2D g2x = (Graphics2D) bufferedImage2x.getGraphics(); setImageScalingHint(g2x, true); g2x.drawImage(image, 0, 0, 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, observer); }
synchronized void abort() { image.getSource().removeConsumer(this); consuming = false; bimage = null; bitmap = null; newInfo(image, ImageObserver.ABORT, -1, -1, -1, -1); availinfo &= ~(ImageObserver.SOMEBITS | ImageObserver.FRAMEBITS | ImageObserver.ALLBITS | ImageObserver.ERROR); }
/** * Return the height of the original image source. * If the height isn't known, then the image is reconstructed. */ public int getHeight() { if (src != null) { src.checkSecurity(null, false); } if ((availinfo & ImageObserver.HEIGHT) == 0) { reconstruct(ImageObserver.HEIGHT); } return height; }
public boolean scaleImage(SunGraphics2D sg, Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgColor, ImageObserver observer) { if (validate(sg)) { return sg.imagepipe.scaleImage(sg, img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgColor, observer); } else { return false; } }
public void setProperties(Hashtable<?,?> props) { if (src != null) { src.checkSecurity(null, false); } image.setProperties(props); newInfo(image, ImageObserver.PROPERTIES, 0, 0, 0, 0); }
protected static boolean imageReady(ToolkitImage sunimg, ImageObserver observer) { if (sunimg.hasError()) { if (observer != null) { observer.imageUpdate(sunimg, ImageObserver.ERROR|ImageObserver.ABORT, -1, -1, -1, -1); } return false; } return true; }
public boolean scaleImage(SunGraphics2D sg, Image img, int x, int y, int w, int h, Color bgColor, ImageObserver observer) { if (validate(sg)) { return sg.imagepipe.scaleImage(sg, img, x, y, w, h, bgColor, observer); } else { return false; } }