/** * @see Graphics2D#drawRenderedImage(RenderedImage, AffineTransform) */ public void drawRenderedImage(RenderedImage img, AffineTransform xform) { BufferedImage image = null; if (img is BufferedImage) { image = (BufferedImage)img; } else { ColorModel cm = img.getColorModel(); int width = img.getWidth(); int height = img.getHeight(); WritableRaster raster = cm.createCompatibleWritableRaster(width, height); boolean isAlphaPremultiplied = cm.isAlphaPremultiplied(); Hashtable properties = new Hashtable(); String[] keys = img.getPropertyNames(); if (keys != null) { for (int i = 0; i < keys.length; i++) { properties.put(keys[i], img.getProperty(keys[i])); } } BufferedImage result = new BufferedImage(cm, raster, isAlphaPremultiplied, properties); img.copyData(raster); } drawImage(image, xform, null); }
/// <summary> /// Returns a <seealso cref="BufferedImage"/> with a data layout and color model /// compatible with this <code>GraphicsConfiguration</code>. This /// method has nothing to do with memory-mapping /// a device. The returned <code>BufferedImage</code> has /// a layout and color model that is closest to this native device /// configuration and can therefore be optimally blitted to this /// device. </summary> /// <param name="width"> the width of the returned <code>BufferedImage</code> </param> /// <param name="height"> the height of the returned <code>BufferedImage</code> </param> /// <returns> a <code>BufferedImage</code> whose data layout and color /// model is compatible with this <code>GraphicsConfiguration</code>. </returns> public virtual BufferedImage CreateCompatibleImage(int width, int height) { ColorModel model = ColorModel; WritableRaster raster = model.CreateCompatibleWritableRaster(width, height); return(new BufferedImage(model, raster, model.AlphaPremultiplied, null)); }
public override WritableRaster MakeRaster(int w, int h) { WritableRaster ras = MakeByteRaster(SrcRas, w, h); ByteInterleavedRaster biRas = (ByteInterleavedRaster)ras; OutData = biRas.DataStorage; OutSpan = biRas.ScanlineStride; OutOff = biRas.getDataOffset(0); return(ras); }
public override WritableRaster MakeRaster(int w, int h) { WritableRaster ras = MakeRaster(ColorModel_Renamed, SrcRas, w, h); IntegerInterleavedRaster iiRas = (IntegerInterleavedRaster)ras; OutData = iiRas.DataStorage; OutSpan = iiRas.ScanlineStride; OutOff = iiRas.getDataOffset(0); return(ras); }
public override WritableRaster MakeRaster(int w, int h) { // Note that we do not pass srcRas to makeRaster since it // is a Byte Raster and this colorModel needs an Int Raster WritableRaster ras = MakeRaster(ColorModel_Renamed, null, w, h); IntegerInterleavedRaster iiRas = (IntegerInterleavedRaster)ras; OutData = iiRas.DataStorage; OutSpan = iiRas.ScanlineStride; OutOff = iiRas.getDataOffset(0); return(ras); }
/// <summary> /// Returns a <seealso cref="WritableRaster"/> representing the alpha channel of /// an image, extracted from the input <code>WritableRaster</code>. /// This method assumes that <code>WritableRaster</code> objects /// associated with this <code>ColorModel</code> store the alpha band, /// if present, as the last band of image data. Returns <code>null</code> /// if there is no separate spatial alpha channel associated with this /// <code>ColorModel</code>. This method creates a new /// <code>WritableRaster</code>, but shares the data array. </summary> /// <param name="raster"> a <code>WritableRaster</code> containing an image </param> /// <returns> a <code>WritableRaster</code> that represents the alpha /// channel of the image contained in <code>raster</code>. </returns> public override WritableRaster GetAlphaRaster(WritableRaster raster) { if (HasAlpha() == false) { return(null); } int x = raster.MinX; int y = raster.MinY; int[] band = new int[1]; band[0] = raster.NumBands - 1; return(raster.CreateWritableChild(x, y, raster.Width, raster.Height, x, y, band)); }
internal static WritableRaster MakeRaster(ColorModel cm, Raster srcRas, int w, int h) { lock (typeof(TexturePaintContext)) { if (Xrgbmodel == cm) { if (XrgbRasRef != null) { WritableRaster wr = (WritableRaster)XrgbRasRef.get(); if (wr != null && wr.Width >= w && wr.Height >= h) { XrgbRasRef = null; return(wr); } } // If we are going to cache this Raster, make it non-tiny if (w <= 32 && h <= 32) { w = h = 32; } } else if (Argbmodel == cm) { if (ArgbRasRef != null) { WritableRaster wr = (WritableRaster)ArgbRasRef.get(); if (wr != null && wr.Width >= w && wr.Height >= h) { ArgbRasRef = null; return(wr); } } // If we are going to cache this Raster, make it non-tiny if (w <= 32 && h <= 32) { w = h = 32; } } if (srcRas != null) { return(srcRas.CreateCompatibleWritableRaster(w, h)); } else { return(cm.CreateCompatibleWritableRaster(w, h)); } } }
/// <summary> /// Return a Raster containing the colors generated for the graphics /// operation. </summary> /// <param name="x">,y,w,h The area in device space for which colors are /// generated. </param> public virtual Raster GetRaster(int x, int y, int w, int h) { if (OutRas == null || OutRas.Width < w || OutRas.Height < h) { // If h==1, we will probably get lots of "scanline" rects OutRas = MakeRaster((h == 1 ? System.Math.Max(w, MaxWidth) : w), h); } double X = Mod(XOrg + x * IncXAcross + y * IncXDown, BWidth); double Y = Mod(YOrg + x * IncYAcross + y * IncYDown, BHeight); SetRaster((int)X, (int)Y, FractAsInt(X), FractAsInt(Y), w, h, BWidth, BHeight, Colincx, Colincxerr, Colincy, Colincyerr, Rowincx, Rowincxerr, Rowincy, Rowincyerr); SunWritableRaster.markDirty(OutRas); return(OutRas); }
/// <summary> /// Returns a <code>BufferedImage</code> that supports the specified /// transparency and has a data layout and color model /// compatible with this <code>GraphicsConfiguration</code>. This /// method has nothing to do with memory-mapping /// a device. The returned <code>BufferedImage</code> has a layout and /// color model that can be optimally blitted to a device /// with this <code>GraphicsConfiguration</code>. </summary> /// <param name="width"> the width of the returned <code>BufferedImage</code> </param> /// <param name="height"> the height of the returned <code>BufferedImage</code> </param> /// <param name="transparency"> the specified transparency mode </param> /// <returns> a <code>BufferedImage</code> whose data layout and color /// model is compatible with this <code>GraphicsConfiguration</code> /// and also supports the specified transparency. </returns> /// <exception cref="IllegalArgumentException"> if the transparency is not a valid value </exception> /// <seealso cref= Transparency#OPAQUE </seealso> /// <seealso cref= Transparency#BITMASK </seealso> /// <seealso cref= Transparency#TRANSLUCENT </seealso> public virtual BufferedImage CreateCompatibleImage(int width, int height, int transparency) { if (ColorModel.Transparency == transparency) { return(CreateCompatibleImage(width, height)); } ColorModel cm = GetColorModel(transparency); if (cm == null) { throw new IllegalArgumentException("Unknown transparency: " + transparency); } WritableRaster wr = cm.CreateCompatibleWritableRaster(width, height); return(new BufferedImage(cm, wr, cm.AlphaPremultiplied, null)); }
internal static WritableRaster MakeByteRaster(Raster srcRas, int w, int h) { lock (typeof(TexturePaintContext)) { if (ByteRasRef != null) { WritableRaster wr = (WritableRaster)ByteRasRef.get(); if (wr != null && wr.Width >= w && wr.Height >= h) { ByteRasRef = null; return(wr); } } // If we are going to cache this Raster, make it non-tiny if (w <= 32 && h <= 32) { w = h = 32; } return(srcRas.CreateCompatibleWritableRaster(w, h)); } }
public virtual Raster GetRaster(int x, int y, int w, int h) { lock (this) { WritableRaster t = SavedTile; if (t == null || w > t.Width || h > t.Height) { t = ColorModel.CreateCompatibleWritableRaster(w, h); IntegerComponentRaster icr = (IntegerComponentRaster)t; Arrays.Fill(icr.DataStorage, Color); // Note - markDirty is probably unnecessary since icr is brand new icr.markDirty(); if (w <= 64 && h <= 64) { SavedTile = t; } } return(t); } }
public static PaintContext GetContext(BufferedImage bufImg, AffineTransform xform, RenderingHints hints, Rectangle devBounds) { WritableRaster raster = bufImg.Raster; ColorModel cm = bufImg.ColorModel; int maxw = devBounds.Width_Renamed; Object val = hints[RenderingHints.KEY_INTERPOLATION]; bool filter = (val == null ? (hints[RenderingHints.KEY_RENDERING] == RenderingHints.VALUE_RENDER_QUALITY) : (val != RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)); if (raster is IntegerInterleavedRaster && (!filter || IsFilterableDCM(cm))) { IntegerInterleavedRaster iir = (IntegerInterleavedRaster)raster; if (iir.NumDataElements == 1 && iir.PixelStride == 1) { return(new Int(iir, cm, xform, maxw, filter)); } } else if (raster is ByteInterleavedRaster) { ByteInterleavedRaster bir = (ByteInterleavedRaster)raster; if (bir.NumDataElements == 1 && bir.PixelStride == 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)); }
/// <summary> /// Encodes the <em>AND</em> bitmap for the given image according the its /// alpha channel (transparency) and writes it to the given output. /// </summary> /// <param name="img"> /// the image to encode as the <em>AND</em> bitmap. </param> private void WriteAndBitmap(BufferedImage img) { WritableRaster alpha = img.getAlphaRaster(); // indexed transparency (eg. GIF files) if (img.getColorModel() is IndexColorModel && img.getColorModel().hasAlpha()) { int w = img.getWidth(); int h = img.getHeight(); int bytesPerLine = GetBytesPerLine1(w); byte[] line = new byte[bytesPerLine]; IndexColorModel icm = (IndexColorModel)img.getColorModel(); Raster raster = img.getRaster(); for (int y = h - 1; y >= 0; y--) { for (int x = 0; x < w; x++) { int bi = x / 8; int i = x % 8; // int a = alpha.getSample(x, y, 0); int p = raster.getSample(x, y, 0); int a = icm.getAlpha(p); // invert bit since and mask is applied to xor mask int b = ~a & 1; line[bi] = SetBit(line[bi], i, b); } writer.Write(line); } } // no transparency else if (alpha == null) { int h = img.getHeight(); int w = img.getWidth(); // calculate number of bytes per line, including 32-bit padding int bytesPerLine = GetBytesPerLine1(w); byte[] line = new byte[bytesPerLine]; for (int i = 0; i < bytesPerLine; i++) { line[i] = (byte)0; } for (int y = h - 1; y >= 0; y--) { writer.Write(line); } } // transparency (ARGB, etc. eg. PNG) else { int w = img.getWidth(); int h = img.getHeight(); int bytesPerLine = GetBytesPerLine1(w); byte[] line = new byte[bytesPerLine]; for (int y = h - 1; y >= 0; y--) { for (int x = 0; x < w; x++) { int bi = x / 8; int i = x % 8; int a = alpha.getSample(x, y, 0); // invert bit since and mask is applied to xor mask int b = ~a & 1; line[bi] = SetBit(line[bi], i, b); } writer.Write(line); } } }
/// <summary> /// Filters the information provided in the <code>imageComplete</code> /// method of the <code>ImageConsumer</code> interface. /// <para> /// Note: This method is intended to be called by the /// <code>ImageProducer</code> of the <code>Image</code> whose pixels /// are being filtered. 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. /// </para> /// </summary> /// <param name="status"> the status of image loading </param> /// <exception cref="ImagingOpException"> if there was a problem calling the filter /// method of the <code>BufferedImageOp</code> associated with this /// instance. </exception> /// <seealso cref= ImageConsumer#imageComplete </seealso> public override void ImageComplete(int status) { WritableRaster wr; switch (status) { case ImageConsumer_Fields.IMAGEERROR: case ImageConsumer_Fields.IMAGEABORTED: // reinitialize the params Model = null; Width = -1; Height = -1; IntPixels = null; BytePixels = null; break; case ImageConsumer_Fields.SINGLEFRAMEDONE: case ImageConsumer_Fields.STATICIMAGEDONE: if (Width <= 0 || Height <= 0) { break; } if (Model is DirectColorModel) { if (IntPixels == null) { break; } wr = CreateDCMraster(); } else if (Model is IndexColorModel) { int[] bandOffsets = new int[] { 0 }; if (BytePixels == null) { break; } DataBufferByte db = new DataBufferByte(BytePixels, Width * Height); wr = Raster.CreateInterleavedRaster(db, Width, Height, Width, 1, bandOffsets, null); } else { ConvertToRGB(); if (IntPixels == null) { break; } wr = CreateDCMraster(); } BufferedImage bi = new BufferedImage(Model, wr, Model.AlphaPremultiplied, null); bi = BufferedImageOp_Renamed.Filter(bi, null); WritableRaster r = bi.Raster; ColorModel cm = bi.ColorModel; int w = r.Width; int h = r.Height; Consumer.SetDimensions(w, h); Consumer.ColorModel = cm; if (cm is DirectColorModel) { DataBufferInt db = (DataBufferInt)r.DataBuffer; Consumer.SetPixels(0, 0, w, h, cm, db.Data, 0, w); } else if (cm is IndexColorModel) { DataBufferByte db = (DataBufferByte)r.DataBuffer; Consumer.SetPixels(0, 0, w, h, cm, db.Data, 0, w); } else { throw new InternalError("Unknown color model " + cm); } break; } Consumer.ImageComplete(status); }
public Any(WritableRaster srcRas, ColorModel cm, AffineTransform xform, int maxw, bool filter) : base(cm, xform, srcRas.Width, srcRas.Height, maxw) { this.SrcRas = srcRas; this.Filter = filter; }
public override void SetRaster(int x, int y, int xerr, int yerr, int w, int h, int bWidth, int bHeight, int colincx, int colincxerr, int colincy, int colincyerr, int rowincx, int rowincxerr, int rowincy, int rowincyerr) { Object data = null; int rowx = x; int rowy = y; int rowxerr = xerr; int rowyerr = yerr; WritableRaster srcRas = this.SrcRas; WritableRaster outRas = this.OutRas; int[] rgbs = Filter ? new int[4] : null; for (int j = 0; j < h; j++) { x = rowx; y = rowy; xerr = rowxerr; yerr = rowyerr; for (int i = 0; i < w; i++) { data = srcRas.GetDataElements(x, y, data); if (Filter) { int nextx, nexty; if ((nextx = x + 1) >= bWidth) { nextx = 0; } if ((nexty = y + 1) >= bHeight) { nexty = 0; } rgbs[0] = ColorModel_Renamed.GetRGB(data); data = srcRas.GetDataElements(nextx, y, data); rgbs[1] = ColorModel_Renamed.GetRGB(data); data = srcRas.GetDataElements(x, nexty, data); rgbs[2] = ColorModel_Renamed.GetRGB(data); data = srcRas.GetDataElements(nextx, nexty, data); rgbs[3] = ColorModel_Renamed.GetRGB(data); int rgb = TexturePaintContext.Blend(rgbs, xerr, yerr); data = ColorModel_Renamed.GetDataElements(rgb, data); } outRas.SetDataElements(i, j, data); if ((xerr += colincxerr) < 0) { xerr &= Integer.MaxValue; x++; } if ((x += colincx) >= bWidth) { x -= bWidth; } if ((yerr += colincyerr) < 0) { yerr &= Integer.MaxValue; y++; } if ((y += colincy) >= bHeight) { y -= bHeight; } } if ((rowxerr += rowincxerr) < 0) { rowxerr &= Integer.MaxValue; rowx++; } if ((rowx += rowincx) >= bWidth) { rowx -= bWidth; } if ((rowyerr += rowincyerr) < 0) { rowyerr &= Integer.MaxValue; rowy++; } if ((rowy += rowincy) >= bHeight) { rowy -= bHeight; } } }
/// <summary> /// Constructs a WritableRaster with the given SampleModel, DataBuffer, /// and parent. aRegion specifies the bounding rectangle of the new /// Raster. When translated into the base Raster's coordinate /// system, aRegion must be contained by the base Raster. /// (The base Raster is the Raster's ancestor which has no parent.) /// sampleModelTranslate specifies the sampleModelTranslateX and /// sampleModelTranslateY values of the new Raster. /// /// Note that this constructor should generally be called by other /// constructors or create methods, it should not be used directly. </summary> /// <param name="sampleModel"> The SampleModel that specifies the layout. </param> /// <param name="dataBuffer"> The DataBuffer that contains the image data. </param> /// <param name="aRegion"> The Rectangle that specifies the image area. </param> /// <param name="sampleModelTranslate"> The Point that specifies the translation /// from SampleModel to Raster coordinates. </param> /// <param name="parent"> The parent (if any) of this raster. </param> /// <exception cref="RasterFormatException"> if <code>aRegion</code> has width /// or height less than or equal to zero, or computing either /// <code>aRegion.x + aRegion.width</code> or /// <code>aRegion.y + aRegion.height</code> results in integer /// overflow </exception> protected internal WritableRaster(SampleModel sampleModel, DataBuffer dataBuffer, Rectangle aRegion, Point sampleModelTranslate, WritableRaster parent) : base(sampleModel, dataBuffer, aRegion, sampleModelTranslate, parent) { }