private void writeEdges(int pixels[]) { // NOTE: There is currently no mechanism for obtaining the edge data // in any other format other than an INT_ARGB type BufferedImage. // This may be easily remedied by providing alternative accessors. nonMax = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); nonMax.getWritableTile(0, 0).setDataElements(0, 0, width, height, pixels); }
public BufferedImage readBufferedImage() throws IOException { colorModel = getColorModel(); sampleModel = getSampleModel(); WritableRaster raster = null; BufferedImage image = j2krparam.getDestination(); int x = destinationRegion.x; int y = destinationRegion.y; destinationRegion.setLocation(j2krparam.getDestinationOffset()); if (image == null) { // If the destination type is specified, use the color model of it. ImageTypeSpecifier type = j2krparam.getDestinationType(); if (type != null) colorModel = type.getColorModel(); raster = Raster.createWritableRaster( sampleModel.createCompatibleSampleModel( destinationRegion.x + destinationRegion.width, destinationRegion.y + destinationRegion.height), new Point(0, 0)); image = new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), new Hashtable()); } else raster = image.getWritableTile(0, 0); destImage = image; readSubsampledRaster(raster); destinationRegion.setLocation(x, y); destImage = null; return image; }
@Override public BufferedImage getImage() { int[] ss = new int[s.length]; for (int i = 0; i < ss.length; i++) { int argb = s[i] == 1 ? 0xffffffff : 0xff000000; ss[i] = argb; } BufferedImage image = new BufferedImage(cx, cy, BufferedImage.TYPE_INT_ARGB); image.getWritableTile(0, 0).setDataElements(0, 0, image.getWidth(), image.getHeight(), ss); return image; }
public Raster readAsRaster() throws IOException { BufferedImage image = j2krparam.getDestination(); WritableRaster raster = null; if (image == null) { sampleModel = getSampleModel(); raster = Raster.createWritableRaster( sampleModel.createCompatibleSampleModel( destinationRegion.x + destinationRegion.width, destinationRegion.y + destinationRegion.height), new Point(0, 0)); } else raster = image.getWritableTile(0, 0); readSubsampledRaster(raster); return raster; }
public RenderedImage decodeAsRenderedImage(int page) throws IOException { if (page != 0) { throw new IOException(JaiI18N.getString(JaiI18N.getString("WBMPImageDecoder0"))); } input.read(); // TypeField input.read(); // FixHeaderField // Image width int value = input.read(); int width = value & 0x7f; while ((value & 0x80) == 0x80) { width <<= 7; value = input.read(); width |= (value & 0x7f); } // Image height value = input.read(); int height = value & 0x7f; while ((value & 0x80) == 0x80) { height <<= 7; value = input.read(); height |= (value & 0x7f); } // Create byte-packed bilevel image width an IndexColorModel BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY); // Get the image tile. WritableRaster tile = bi.getWritableTile(0, 0); // Get the SampleModel. MultiPixelPackedSampleModel sm = (MultiPixelPackedSampleModel) bi.getSampleModel(); // Read the data. input.readFully( ((DataBufferByte) tile.getDataBuffer()).getData(), 0, height * sm.getScanlineStride()); return bi; }
public BufferedImage read(int imageIndex, ImageReadParam param) throws IOException { checkIndex(imageIndex); readHeader(); if (iis == null) throw new IllegalStateException("input is null"); BufferedImage img; clearAbortRequest(); processImageStarted(imageIndex); if (param == null) param = getDefaultReadParam(); sourceRegion = new Rectangle(0, 0, 0, 0); destinationRegion = new Rectangle(0, 0, 0, 0); computeRegions( param, this.width, this.height, param.getDestination(), sourceRegion, destinationRegion); scaleX = param.getSourceXSubsampling(); scaleY = param.getSourceYSubsampling(); // If the destination band is set used it sourceBands = param.getSourceBands(); destBands = param.getDestinationBands(); seleBand = (sourceBands != null) && (destBands != null); noTransform = destinationRegion.equals(new Rectangle(0, 0, width, height)) || seleBand; if (!seleBand) { sourceBands = new int[colorPlanes]; destBands = new int[colorPlanes]; for (int i = 0; i < colorPlanes; i++) destBands[i] = sourceBands[i] = i; } // If the destination is provided, then use it. Otherwise, create new one bi = param.getDestination(); // Get the image data. WritableRaster raster = null; if (bi == null) { if (sampleModel != null && colorModel != null) { sampleModel = sampleModel.createCompatibleSampleModel( destinationRegion.width + destinationRegion.x, destinationRegion.height + destinationRegion.y); if (seleBand) sampleModel = sampleModel.createSubsetSampleModel(sourceBands); raster = Raster.createWritableRaster(sampleModel, new Point(0, 0)); bi = new BufferedImage(colorModel, raster, false, null); } } else { raster = bi.getWritableTile(0, 0); sampleModel = bi.getSampleModel(); colorModel = bi.getColorModel(); noTransform &= destinationRegion.equals(raster.getBounds()); } byte bdata[] = null; // buffer for byte data if (sampleModel.getDataType() == DataBuffer.TYPE_BYTE) bdata = (byte[]) ((DataBufferByte) raster.getDataBuffer()).getData(); readImage(bdata); if (abortRequested()) processReadAborted(); else processImageComplete(); return bi; }