/** * Modifies the lookup table to display a bright image with gray values * in the range minGray ... 255. Does nothing if ip is of type * ColorProcessor. * * @param ip The target image. * @param minGray Minimum gray value. */ public static void brightLut(ImageProcessor ip, int minGray) { if (minGray < 0 || minGray >= 255) return; ColorModel cm = ip.getColorModel(); if (!(cm instanceof IndexColorModel)) return; IndexColorModel icm = (IndexColorModel) cm; int mapSize = icm.getMapSize(); byte[] reds = new byte[mapSize]; byte[] grns = new byte[mapSize]; byte[] blus = new byte[mapSize]; float scale = (255 - minGray) / 255f; for (int i = 0; i < mapSize; i++) { byte g = (byte) (Math.round(minGray + scale * i) & 0xFF); reds[i] = g; grns[i] = g; blus[i] = g; } ip.setColorModel(new IndexColorModel(8, mapSize, reds, grns, blus)); }
/** * Took this cacheRaster code from GradientPaint. It appears to recycle * rasters for use by any other instance, as long as they are sufficiently * large. */ private static synchronized Raster getCachedRaster(ColorModel cm, int w, int h) { if (cm == cachedModel) { if (cached != null) { Raster ras = cached.get(); if (ras != null && ras.getWidth() >= w && ras.getHeight() >= h) { cached = null; return ras; } } } return cm.createCompatibleWritableRaster(w, h); }
/** * The setDimensions method is part of the ImageConsumer API which * this class must implement to retrieve the pixels. * <p> * Note: This method is intended to be called by the ImageProducer * of the Image whose pixels are being grabbed. Developers using * this class to retrieve pixels from an image should avoid calling * this method directly since that operation could result in problems * with retrieving the requested pixels. * @param width the width of the dimension * @param height the height of the dimension */ public void setDimensions(int width, int height) { if (dstW < 0) { dstW = width - dstX; } if (dstH < 0) { dstH = height - dstY; } if (dstW <= 0 || dstH <= 0) { imageComplete(STATICIMAGEDONE); } else if (intPixels == null && imageModel == ColorModel.getRGBdefault()) { intPixels = new int[dstW * dstH]; dstScan = dstW; dstOff = 0; } flags |= (ImageObserver.WIDTH | ImageObserver.HEIGHT); }
/** * Given an image type, return the Adobe transform corresponding to * that type, or ADOBE_IMPOSSIBLE if the image type is incompatible * with an Adobe marker segment. If {@code input} is true, then * the image type is considered before colorspace conversion. */ static int transformForType(ImageTypeSpecifier imageType, boolean input) { int retval = ADOBE_IMPOSSIBLE; ColorModel cm = imageType.getColorModel(); switch (cm.getColorSpace().getType()) { case ColorSpace.TYPE_GRAY: retval = ADOBE_UNKNOWN; break; case ColorSpace.TYPE_RGB: retval = input ? ADOBE_YCC : ADOBE_UNKNOWN; break; case ColorSpace.TYPE_YCbCr: retval = ADOBE_YCC; break; case ColorSpace.TYPE_CMYK: retval = input ? ADOBE_YCCK : ADOBE_IMPOSSIBLE; } return retval; }
public static SurfaceData createDataBP(BufferedImage bImg, SurfaceType sType) { BytePackedRaster bpRaster = (BytePackedRaster)bImg.getRaster(); BufImgSurfaceData bisd = new BufImgSurfaceData(bpRaster.getDataBuffer(), bImg, sType); ColorModel cm = bImg.getColorModel(); IndexColorModel icm = ((cm instanceof IndexColorModel) ? (IndexColorModel) cm : null); bisd.initRaster(bpRaster.getDataStorage(), bpRaster.getDataBitOffset() / 8, bpRaster.getDataBitOffset() & 7, bpRaster.getWidth(), bpRaster.getHeight(), 0, bpRaster.getScanlineStride(), icm); return bisd; }
JFIFExtensionMarkerSegment(BufferedImage thumbnail) throws IllegalThumbException { super(JPEG.APP0); ColorModel cm = thumbnail.getColorModel(); int csType = cm.getColorSpace().getType(); if (cm.hasAlpha()) { throw new IllegalThumbException(); } if (cm instanceof IndexColorModel) { code = THUMB_PALETTE; thumb = new JFIFThumbPalette(thumbnail); } else if (csType == ColorSpace.TYPE_RGB) { code = THUMB_RGB; thumb = new JFIFThumbRGB(thumbnail); } else if (csType == ColorSpace.TYPE_GRAY) { code = THUMB_JPEG; thumb = new JFIFThumbJPEG(thumbnail); } else { throw new IllegalThumbException(); } }
static synchronized void putCachedRaster(ColorModel cm, Raster ras) { if (cached != null) { Raster cras = cached.get(); if (cras != null) { int cw = cras.getWidth(); int ch = cras.getHeight(); int iw = ras.getWidth(); int ih = ras.getHeight(); if (cw >= iw && ch >= ih) { return; } if (cw * ch >= iw * ih) { return; } } } cachedModel = cm; cached = new WeakReference<>(ras); }
/** * Create a pixmap-based SurfaceData object */ protected SurfaceData initAcceleratedSurface() { SurfaceData sData; try { X11GraphicsConfig gc = (X11GraphicsConfig)vImg.getGraphicsConfig(); ColorModel cm = gc.getColorModel(); long drawable = 0; if (context instanceof Long) { drawable = ((Long)context).longValue(); } sData = X11SurfaceData.createData(gc, vImg.getWidth(), vImg.getHeight(), cm, vImg, drawable, Transparency.OPAQUE); } catch (NullPointerException ex) { sData = null; } catch (OutOfMemoryError er) { sData = null; } return sData; }
public final void xSetBackground(Color c) { XToolkit.awtLock(); try { winBackground(c); // fix for 6558510: handle sun.awt.noerasebackground flag, // see doEraseBackground() and preInit() methods in XCanvasPeer if (!doEraseBackground()) { return; } // 6304250: XAWT: Items in choice show a blue border on OpenGL + Solaris10 when background color is set // Note: When OGL is enabled, surfaceData.pixelFor() will not // return a pixel value appropriate for passing to // XSetWindowBackground(). Therefore, we will use the ColorModel // for this component in order to calculate a pixel value from // the given RGB value. ColorModel cm = getColorModel(); int pixel = PixelConverter.instance.rgbToPixel(c.getRGB(), cm); XlibWrapper.XSetWindowBackground(XToolkit.getDisplay(), getContentWindow(), pixel); XlibWrapper.XClearWindow(XToolkit.getDisplay(), getContentWindow()); } finally { XToolkit.awtUnlock(); } }
static ColorModel createComponentCM(ColorSpace colorSpace, int numBands, int dataType, boolean hasAlpha, boolean isAlphaPremultiplied) { int transparency = hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE; int[] numBits = new int[numBands]; int bits = DataBuffer.getDataTypeSize(dataType); for (int i = 0; i < numBands; i++) { numBits[i] = bits; } return new ComponentColorModel(colorSpace, numBits, hasAlpha, isAlphaPremultiplied, transparency, dataType); }
/** * Returns the color model associated with this configuration that * supports the specified transparency. */ public ColorModel getColorModel(int transparency) { if (model.getTransparency() == transparency) { return model; } switch (transparency) { case Transparency.OPAQUE: return new DirectColorModel(24, 0xff0000, 0xff00, 0xff); case Transparency.BITMASK: return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000); case Transparency.TRANSLUCENT: return ColorModel.getRGBdefault(); default: return null; } }
public boolean canEncodeImage(ImageTypeSpecifier type) { if (type == null) { throw new IllegalArgumentException("type == null!"); } SampleModel sm = type.getSampleModel(); ColorModel cm = type.getColorModel(); boolean canEncode = sm.getNumBands() == 1 && sm.getSampleSize(0) <= 8 && sm.getWidth() <= 65535 && sm.getHeight() <= 65535 && (cm == null || cm.getComponentSize()[0] <= 8); if (canEncode) { return true; } else { return PaletteBuilder.canCreatePalette(type); } }
static synchronized Raster getCachedRaster(ColorModel cm, int w, int h) { if (cm == cachedModel) { if (cached != null) { Raster ras = cached.get(); if (ras != null && ras.getWidth() >= w && ras.getHeight() >= h) { cached = null; return ras; } } } return cm.createCompatibleWritableRaster(w, h); }
/** * Creates a new managed image of the given width and height * that is associated with the target Component. */ public Image createAcceleratedImage(Component target, int width, int height) { ColorModel model = getColorModel(Transparency.OPAQUE); WritableRaster wr = model.createCompatibleWritableRaster(width, height); return new OffScreenImage(target, model, wr, model.isAlphaPremultiplied()); }
/** * Choose which rows and columns of the delivered int pixels are * needed for the destination scaled image and pass through just * those rows and columns that are needed, replicated as necessary. * <p> * Note: This method is intended to be called by the * {@code ImageProducer} of the {@code Image} whose pixels * are being filtered. Developers using * this class to filter pixels from an image should avoid calling * this method directly since that operation could interfere * with the filtering operation. */ public void setPixels(int x, int y, int w, int h, ColorModel model, int pixels[], int off, int scansize) { if (srcrows == null || srccols == null) { calculateMaps(); } int sx, sy; int dx1 = (2 * x * destWidth + srcWidth - 1) / (2 * srcWidth); int dy1 = (2 * y * destHeight + srcHeight - 1) / (2 * srcHeight); int outpix[]; if (outpixbuf != null && outpixbuf instanceof int[]) { outpix = (int[]) outpixbuf; } else { outpix = new int[destWidth]; outpixbuf = outpix; } for (int dy = dy1; (sy = srcrows[dy]) < y + h; dy++) { int srcoff = off + scansize * (sy - y); int dx; for (dx = dx1; (sx = srccols[dx]) < x + w; dx++) { outpix[dx] = pixels[srcoff + sx - x]; } if (dx > dx1) { consumer.setPixels(dx1, dy, dx - dx1, 1, model, outpix, dx1, destWidth); } } }
@Override public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform at, RenderingHints hints) { // Fill bufferedImage using final Graphics2D g2d = (Graphics2D) getImage().getGraphics(); try { g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setBackground(Color.PINK); g2d.clearRect(0, 0, size, size); g2d.setColor(Color.BLUE); g2d.drawRect(0, 0, size, size); g2d.fillOval(size / 10, size / 10, size * 8 / 10, size * 8 / 10); } finally { g2d.dispose(); } return super.createContext(cm, deviceBounds, userBounds, at, hints); }
public Object startSequence(SunGraphics2D sg, Shape s, Rectangle devR, int[] abox) { RenderingHints hints = sg.getRenderingHints(); ColorModel model = sg.getDeviceColorModel(); PaintContext paintContext = sg.paint.createContext(model, devR, s.getBounds2D(), sg.cloneTransform(), hints); CompositeContext compositeContext = sg.composite.createContext(paintContext.getColorModel(), model, hints); return new TileContext(sg, paintContext, compositeContext, model); }
public WGLVSyncOffScreenSurfaceData(WComponentPeer peer, WGLGraphicsConfig gc, int width, int height, Image image, ColorModel cm, int type) { super(peer, gc, width, height, image, cm, type); flipSurface = WGLSurfaceData.createData(peer, image, FLIP_BACKBUFFER); }
public int rgbToPixel(int rgb, ColorModel cm) { int red = (rgb >> 16) & 0xff; int grn = (rgb >> 8) & 0xff; int blu = (rgb ) & 0xff; return (int) (red * USHORT_RED_MULT + grn * USHORT_GRN_MULT + blu * USHORT_BLU_MULT + 0.5); }
public GLXOffScreenSurfaceData(X11ComponentPeer peer, GLXGraphicsConfig gc, int width, int height, Image image, ColorModel cm, int type) { super(peer, gc, cm, type); this.width = width; this.height = height; offscreenImage = image; initSurface(width, height); }
/** * Gets the instance of <code>ColorModel</code> used to display * the component on the output device. * @return the color model used by this component * @see java.awt.image.ColorModel * @see java.awt.peer.ComponentPeer#getColorModel() * @see Toolkit#getColorModel() * @since JDK1.0 */ public ColorModel getColorModel() { ComponentPeer peer = this.peer; if ((peer != null) && ! (peer instanceof LightweightPeer)) { return peer.getColorModel(); } else if (GraphicsEnvironment.isHeadless()) { return ColorModel.getRGBdefault(); } // else return getToolkit().getColorModel(); }
/** * Returns the color model associated with this configuration that * supports the specified transparency. */ public ColorModel getColorModel(int transparency) { switch (transparency) { case Transparency.OPAQUE: return getColorModel(); case Transparency.BITMASK: return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000); case Transparency.TRANSLUCENT: return ColorModel.getRGBdefault(); default: return null; } }
/** * Returns the non-dynamic ColorModel associated with this device */ public ColorModel getColorModel() { if (colorModel == null) { colorModel = makeColorModel(screen, false); } return colorModel; }
/** * Method for instantiating a Pixmap SurfaceData (offscreen) */ public static X11PixmapSurfaceData createData(X11GraphicsConfig gc, int width, int height, ColorModel cm, Image image, long drawable, int transparency) { return new X11PixmapSurfaceData(gc, width, height, image, getSurfaceType(gc, transparency, true), cm, drawable, transparency); }
public int pixelToRgb(int pixel, ColorModel cm) { int a, r, g, b; // replicate 4 bits for each color // 0xARGB -> 0xAARRGGBB a = pixel & 0xf000; a = ((pixel << 16) | (pixel << 12)) & 0xff000000; r = pixel & 0x0f00; r = ((pixel << 12) | (pixel << 8)) & 0x00ff0000; g = pixel & 0x00f0; g = ((pixel << 8) | (pixel << 4)) & 0x0000ff00; b = pixel & 0x000f; b = ((pixel << 4) | (pixel << 0)) & 0x000000ff; return (a | r | g | b); }
protected GLXSurfaceData(X11ComponentPeer peer, GLXGraphicsConfig gc, ColorModel cm, int type) { super(gc, cm, type); this.peer = peer; this.graphicsConfig = gc; initOps(peer, graphicsConfig.getAData()); }
@Override public ColorModel getColorModel() { GraphicsConfiguration gc = getGraphicsConfiguration(); if (gc != null) { return gc.getColorModel(); } else { return null; } }
public TileContext(SunGraphics2D sg, PaintContext pCtx, CompositeContext cCtx, ColorModel cModel) { sunG2D = sg; paintCtxt = pCtx; compCtxt = cCtx; compModel = cModel; }
public int pixelToRgb(int pixel, ColorModel cm) { int r, g, b; r = (pixel >> 11) & 0x1f; r = (r << 3) | (r >> 2); g = (pixel >> 5) & 0x3f; g = (g << 2) | (g >> 4); b = (pixel ) & 0x1f; b = (b << 3) | (b >> 2); return (0xff000000 | (r << 16) | (g << 8) | (b)); }
@Override public Image createAcceleratedImage(Component target, int width, int height) { ColorModel model = getColorModel(Transparency.OPAQUE); WritableRaster wr = model.createCompatibleWritableRaster(width, height); return new OffScreenImage(target, model, wr, model.isAlphaPremultiplied()); }
/** * Constructs an OffScreenImage given a color model and tile, * for offscreen rendering to be used with a given component. * The component is used to obtain the foreground color, background * color and font. */ public OffScreenImage(Component c, ColorModel cm, WritableRaster raster, boolean isRasterPremultiplied) { super(cm, raster, isRasterPremultiplied, null); this.c = c; initSurface(raster.getWidth(), raster.getHeight()); }
public Any(WritableRaster srcRas, ColorModel cm, AffineTransform xform, int maxw, boolean filter) { super(cm, xform, srcRas.getWidth(), srcRas.getHeight(), maxw); this.srcRas = srcRas; this.filter = filter; }
void createBufferedImage() { // REMIND: Be careful! Is this called everytime there is a // startProduction? We only want to call it if it is new or // there is an error isDefaultBI = false; try { biRaster = cmodel.createCompatibleWritableRaster(width, height); bimage = createImage(cmodel, biRaster, cmodel.isAlphaPremultiplied(), null); } catch (Exception e) { // Create a default image cmodel = ColorModel.getRGBdefault(); biRaster = cmodel.createCompatibleWritableRaster(width, height); bimage = createImage(cmodel, biRaster, false, null); } int type = bimage.getType(); if ((cmodel == ColorModel.getRGBdefault()) || (type == BufferedImage.TYPE_INT_RGB) || (type == BufferedImage.TYPE_INT_ARGB_PRE)) { isDefaultBI = true; } else if (cmodel instanceof DirectColorModel) { DirectColorModel dcm = (DirectColorModel) cmodel; if (dcm.getRedMask() == 0xff0000 && dcm.getGreenMask() == 0xff00 && dcm.getBlueMask() == 0xff) { isDefaultBI = true; } } }
private static BufferedImage deepCopy(BufferedImage bi) { ColorModel cm = bi.getColorModel(); boolean isAlphaPremultiplied = cm.isAlphaPremultiplied(); WritableRaster raster = bi.copyData(null); return new BufferedImage(cm, raster, isAlphaPremultiplied, null); }
public static PaintContext getContext(BufferedImage bufImg, AffineTransform xform, RenderingHints hints, Rectangle devBounds) { WritableRaster raster = bufImg.getRaster(); ColorModel cm = bufImg.getColorModel(); int maxw = devBounds.width; Object val = hints.get(RenderingHints.KEY_INTERPOLATION); boolean filter = (val == null ? (hints.get(RenderingHints.KEY_RENDERING) == RenderingHints.VALUE_RENDER_QUALITY) : (val != RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)); if (raster instanceof IntegerInterleavedRaster && (!filter || isFilterableDCM(cm))) { IntegerInterleavedRaster iir = (IntegerInterleavedRaster) raster; if (iir.getNumDataElements() == 1 && iir.getPixelStride() == 1) { return new Int(iir, cm, xform, maxw, filter); } } else if (raster instanceof ByteInterleavedRaster) { ByteInterleavedRaster bir = (ByteInterleavedRaster) raster; if (bir.getNumDataElements() == 1 && bir.getPixelStride() == 1) { if (filter) { if (isFilterableICM(cm)) { return new ByteFilter(bir, cm, xform, maxw); } } else { return new Byte(bir, cm, xform, maxw); } } } return new Any(raster, cm, xform, maxw, filter); }
/** * Returns the BufferedImage that will be used as the representation of * the pixel data. Subclasses can override this method to return * platform specific subclasses of BufferedImage that may or may not be * accelerated. * * It is subclass' responsibility to propagate acceleration priority * to the newly created image. */ protected BufferedImage createImage(ColorModel cm, WritableRaster raster, boolean isRasterPremultiplied, Hashtable properties) { BufferedImage bi = new BufferedImage(cm, raster, isRasterPremultiplied, null); bi.setAccelerationPriority(image.getAccelerationPriority()); return bi; }
static synchronized void dropRaster(ColorModel cm, Raster outRas) { if (outRas == null) { return; } if (xrgbmodel == cm) { xrgbRasRef = new WeakReference<>(outRas); } else if (argbmodel == cm) { argbRasRef = new WeakReference<>(outRas); } }
/** * Creates a SurfaceData object representing an off-screen buffer (either * a Pbuffer or Texture). */ public static WGLOffScreenSurfaceData createData(WGLGraphicsConfig gc, int width, int height, ColorModel cm, Image image, int type) { return new WGLOffScreenSurfaceData(null, gc, width, height, image, cm, type); }