new Rectangle( this.gridRange.getLow(0), this.gridRange.getLow(1), this.gridRange.getSpan(1)); final Rectangle thatRectangle = new Rectangle( gridRange.getLow(0), gridRange.getLow(1), gridRange.getSpan(0), gridRange.getSpan(1)); if (!thisRectangle.equals(thatRectangle)) { if (!canSupportHeterogeneousCoverages) { throw new IllegalArgumentException( if (layout.getSampleModel(null).getDataType() != this.layout.getSampleModel(null).getDataType()) { throw new IllegalArgumentException( "The coverage dataType should be the same for all coverages");
/** * Computes the image size based on the SampleModel and image dimension * * @param image * @return */ static long computeImageSize(RenderedImage image) { long bits = 0; final int bands = image.getSampleModel().getNumBands(); for (int i = 0; i < bands; i++) { bits += image.getSampleModel().getSampleSize(i); } return (long) Math.ceil(bits / 8) * image.getWidth() * image.getHeight(); }
final SampleModel sampleModel = sourceImage.getSampleModel(); final int sourceTileW = sampleModel.getWidth(); final int sourceTileH = sampleModel.getHeight(); final Dimension tileDimensions = new Dimension(sourceTileW, sourceTileH); LOGGER.fine("Source tiling:" + tileDimensions.width + "x" + tileDimensions.height);
/** * Computes the size of a grid coverage in bytes given its grid envelope and the target sample * model * * @param envelope * @param sm */ static long getCoverageSize(GridEnvelope2D envelope, SampleModel sm) { // === compute the coverage memory usage and compare with limit final long pixelsNumber = computePixelsNumber(envelope); long pixelSize = 0; final int numBands = sm.getNumBands(); for (int i = 0; i < numBands; i++) { pixelSize += sm.getSampleSize(i); } return pixelsNumber * pixelSize / 8; }
@Override public ColorModel createColorModel( SampleModel sampleModel, List sources, Map configuration) { final int dataType = sampleModel.getDataType(); final int numBands = sampleModel.getNumBands(); ColorSpace cs; switch (numBands) { case 1: case 2: cs = ColorSpace.getInstance(ColorSpace.CS_GRAY); break; case 3: cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); break; default: cs = new BogusColorSpace(numBands); } return RasterFactory.createComponentColorModel( dataType, cs, false, false, Transparency.OPAQUE); } });
SampleModel sampleModel = RasterFactory.createBandedSampleModel( originalSampleModel.getDataType(), originalSampleModel.getWidth(), originalSampleModel.getHeight(), coverageView.getCoverageBands().size()); layout.getMinX(null), layout.getMinY(null), originalSampleModel.getWidth(), originalSampleModel.getHeight()); imageLayout.setSampleModel(sampleModel); imageLayout.setColorModel(colorModel);
protected BufferedImage getStartImage(BufferedImage copyFrom, int width, int height) { Map<String, Object> properties = null; if (copyFrom.getPropertyNames() != null) { properties = new HashMap<String, Object>(); for (String name : copyFrom.getPropertyNames()) { properties.put(name, copyFrom.getProperty(name)); } } SampleModel sm = copyFrom.getSampleModel().createCompatibleSampleModel(width, height); WritableRaster raster = Raster.createWritableRaster(sm, null); BufferedImage image = new BufferedImage( copyFrom.getColorModel(), raster, copyFrom.isAlphaPremultiplied(), (Hashtable<?, ?>) properties); // white background Graphics2D g2D = (Graphics2D) image.getGraphics(); Color save = g2D.getColor(); g2D.setColor(Color.WHITE); g2D.fillRect(0, 0, image.getWidth(), image.getHeight()); g2D.setColor(save); return image; }
/** * Check if the image is fail safe for color based features that are actually using 8 bits per pixel RGB. * * @param bufferedImage * @return */ public static BufferedImage get8BitRGBImage(BufferedImage bufferedImage) { // check if it's (i) RGB and (ii) 8 bits per pixel. if (bufferedImage.getType() != BufferedImage.TYPE_INT_RGB || bufferedImage.getSampleModel().getSampleSize(0) != 8) { BufferedImage img = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), BufferedImage.TYPE_INT_RGB); img.getGraphics().drawImage(bufferedImage, 0, 0, null); bufferedImage = img; } return bufferedImage; }
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; }
ImageTypeSpecifier rawType = getRawImageType(imageIndex); if (rawType.getColorModel() instanceof IndexColorModel && rawType.getBufferedImageType() != image.getType()) { checkReadParamBandSettings(param, 4, image.getSampleModel().getNumBands()); checkReadParamBandSettings(param, rawType.getNumBands(), image.getSampleModel().getNumBands()); final Rectangle source = new Rectangle(); final Rectangle dest = new Rectangle(); computeRegions(param, width, height, image, source, dest); WritableRaster raster = Raster.createPackedRaster(buffer, width, height, resource.depth(), null); if (image.getType() == rawType.getBufferedImageType() && ((IndexColorModel) image.getColorModel()).getMapSize() == 2) { WritableRaster mask = Raster.createPackedRaster(maskBuffer, width, height, resource.depth(), null); Graphics2D graphics = image.createGraphics(); WritableRaster raster = Raster.createPackedRaster(buffer, width, height, resource.depth(), null); if (image.getType() == rawType.getBufferedImageType()) { image.getAlphaRaster().setRect(mask); image.getAlphaRaster().setRect(mask);
final Rectangle srcRegion = new Rectangle(); final Rectangle destRegion = new Rectangle(); computeRegions(param, width, height, null, srcRegion, destRegion); wrapper.getSampleModel().getDataType(), destWidth, destHeight, numDstBands); final ColorModel colorModel = ImageIOUtilities.createColorModel(sampleModel); final WritableRaster raster = Raster.createWritableRaster(sampleModel, new Point(0, 0)); Hashtable<String, Object> properties = getNoDataProperties(wrapper); final BufferedImage image = new BufferedImage( colorModel, raster, colorModel.isAlphaPremultiplied(), properties); final int type = raster.getSampleModel().getDataType(); final int xmin = destRegion.x; final int ymin = destRegion.y; case DataBuffer.TYPE_DOUBLE: raster.setSample(x, y, dstBand, it.getDoubleNext()); break; raster.setSample(x, y, dstBand, it.getFloatNext()); break;
new BufferedImage( src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_INDEXED, icm); final WritableRaster destWr = dest.getRaster(); if (src.getNumXTiles() == 1 && src.getNumYTiles() == 1) { final int minTileX = src.getMinTileX(); final int minTileY = src.getMinTileY(); final Raster sourceR = src.getTile(minTileX, minTileY); rasterOp.filter( sourceR.createChild( src.getMinX(), src.getMinY(), final int numBands = src.getSampleModel().getNumBands(); final int[] rgba = new int[numBands]; final boolean sourceHasAlpha = (numBands % 2 == 0); final Raster r = src.getTile(tx, ty); int minx = r.getMinX(); int miny = r.getMinY(); minx = minx < minx_ ? minx_ : minx; miny = miny < miny_ ? miny_ : miny; rgba[numBands == 1 ? 0 : 2]); if (hasAlpha && val >= transparencyIndex) val++; destWr.setSample(ii, jj, 0, (byte) (val & 0xff)); } else destWr.setSample(ii, jj, 0, transparencyIndex);
checkReadParamBandSettings(param, rawType.getNumBands(), destination.getSampleModel().getNumBands()); final Rectangle srcRegion = new Rectangle(); final Rectangle dstRegion = new Rectangle(); computeRegions(param, width, height, destination, srcRegion, dstRegion); int ySub = param != null ? param.getSourceYSubsampling() : 1; WritableRaster destRaster = clipToRect(destination.getRaster(), dstRegion, param != null ? param.getDestinationBands() : null); final int predictor = getValueAsIntWithDefault(TIFF.TAG_PREDICTOR, 1); final int planarConfiguration = getValueAsIntWithDefault(TIFF.TAG_PLANAR_CONFIGURATION, TIFFBaseline.PLANARCONFIG_CHUNKY); final int numBands = planarConfiguration == TIFFExtension.PLANARCONFIG_PLANAR ? 1 : rawType.getNumBands(); WritableRaster rowRaster = rawType.createBufferedImage(stripTileWidth, 1).getRaster(); if (rowRaster.getNumBands() != 3) { throw new IIOException("TIFF PhotometricInterpretation YCbCr requires SamplesPerPixel == 3: " + rowRaster.getNumBands()); if (rowRaster.getTransferType() != DataBuffer.TYPE_BYTE && rowRaster.getTransferType() != DataBuffer.TYPE_USHORT) { throw new IIOException("TIFF PhotometricInterpretation YCbCr requires BitsPerSample == [8,8,8] or [16,16,16]"); Point offset = new Point((intersection.x - srcRegion.x) / xSub, (intersection.y - srcRegion.y) / ySub); Point offset = new Point(col - srcRegion.x, srcRow - srcRegion.y); Point offset = new Point(col - srcRegion.x, srcRow - srcRegion.y);
icm.createCompatibleWritableRaster(src.getWidth(), src.getHeight()); final BufferedImage dst = new BufferedImage(icm, destWr, false, null); final int numBands = src.getSampleModel().getNumBands(); final int[] rgba = new int[numBands]; final boolean sourceHasAlpha = (numBands % 2 == 0); final Raster r = src.getTile(tx, ty); int minx = r.getMinX(); int miny = r.getMinY(); int maxx = minx + r.getWidth(); int maxy = miny + r.getHeight(); if (LOGGER.isLoggable(Level.FINE)) { r.getPixel(i, j, rgba); destWr.setSample(ii, jj, 0, findColorIndex(root, rgba, alphaBand));
final Point offset = pParam == null ? new Point(0, 0) : pParam.getDestinationOffset(); checkReadParamBandSettings(pParam, isConvertToRGB() ? 3 : 1, image.getSampleModel().getNumBands()); WritableRaster destination = image.getRaster(); if (destinationBands != null || offset.x != 0 || offset.y != 0) { destination = destination.createWritableChild(0, 0, destination.getWidth(), destination.getHeight(), offset.x, offset.y, destinationBands); ); raster = Raster.createInterleavedRaster( DataBuffer.TYPE_BYTE, width, 1, width * 3, 3, new int[]{2, 1, 0}, null ); if (cm.isCompatibleRaster(destination)) { for (int srcX = 0; srcX < sourceRow.getWidth(); srcX += sourceXSubsampling) { dataElements = sourceRow.getDataElements(srcX, 0, dataElements); int dstX = /*offset.x +*/ srcX / sourceXSubsampling; destination.setDataElements(dstX, dstY, dataElements); dataElements = sourceRow.getDataElements(srcX, 0, dataElements); int rgb = icm.getRGB(dataElements); outDataElements = image.getColorModel().getDataElements(rgb, outDataElements); int dstX = srcX / sourceXSubsampling; destination.setDataElements(dstX, dstY, outDataElements); converter = new ColorConvertOp(cm.getColorSpace(), image.getColorModel().getColorSpace(), null);
ColorModel cm = image.getColorModel(); final boolean hasAlpha = cm.hasAlpha(); forceComponentColorModel(); cm = image.getColorModel(); rescaleToBytes(); cm = image.getColorModel(); final int numBands = image.getSampleModel().getNumBands(); if (hasAlpha) { retainBands(numBands - 1); || (nativeAcc && (image.getNumXTiles() > 1 || image.getNumYTiles() > 1))) { final BufferedImage finalImage = new BufferedImage( image.getColorModel(), ((WritableRaster) image.getData()) .createWritableTranslatedChild(0, 0), image.getColorModel().isAlphaPremultiplied(), null);
static public final BufferedImage createImage(final int[] pixels, final int width, final int height, final DirectColorModel cm) { WritableRaster wr = cm.createCompatibleWritableRaster(1, 1); SampleModel sm = wr.getSampleModel().createCompatibleSampleModel(width, height); DataBuffer dataBuffer = new DataBufferInt(pixels, width*height, 0); WritableRaster rgbRaster = Raster.createWritableRaster(sm, dataBuffer, null); return new BufferedImage(cm, rgbRaster, cm == RGBA_PRE_COLOR_MODEL, null); }
final Point offset = pParam == null ? new Point(0, 0) : pParam.getDestinationOffset(); checkReadParamBandSettings(pParam, header.bitplanes / 8, image.getSampleModel().getNumBands()); final byte[] planeData = new byte[8 * planeWidth]; WritableRaster destination = image.getRaster(); if (destinationBands != null || offset.x != 0 || offset.y != 0) { destination = destination.createWritableChild(0, 0, destination.getWidth(), destination.getHeight(), offset.x, offset.y, destinationBands); WritableRaster raster = image.getRaster().createCompatibleWritableRaster(8 * planeWidth, 1); Raster sourceRow = raster.createChild(aoi.x, 0, aoi.width, 1, 0, 0, sourceBands); for (int srcX = 0; srcX < sourceRow.getWidth(); srcX += sourceXSubsampling) { dataElements = sourceRow.getDataElements(srcX, 0, dataElements); int dstX = srcX / sourceXSubsampling; destination.setDataElements(dstX, dstY, dataElements);
name, raster, minValues, maxValues, units, colors, hints); final ColorModel model = bands[0].getColorModel(0, bands.length, raster.getSampleModel().getDataType()); final RenderedImage image = new BufferedImage(model, raster, false, null); return create(name, image, envelope, bands, null, null);
public Raster getData(Rectangle rect) { SampleModel smRet = sm.createCompatibleSampleModel( rect.width, rect.height); Point pt = new Point(rect.x, rect.y); WritableRaster wr = Raster.createWritableRaster(smRet, pt); // System.out.println("GD DB: " + wr.getDataBuffer().getSize()); return copyData(wr); }