throws IOException Region image = new Region(xCoordinate, yCoordinate, width, height); Region tileBoundary = new Region(0, 0, 0, 0); byte[] tile = null; for (int row=0; row<yTiles; row++) { tileBoundary.x = col * tileDim; tileBoundary.width = col < xTiles - 1 ? tileDim : imageWidth - (tileDim*col); if (tileBoundary.intersects(image)) { intersection = image.intersection(tileBoundary); tile = getTile(col, row);
public byte[] get(int x, int y, int w, int h) throws CodecException, IOException { Region[] keys = compressedTiles.keySet().toArray(new Region[0]); Region r = new Region(x, y, w, h); for (Region key : keys) { if (key.intersects(r)) { r = key; } } if (!r.equals(lastRegion)) { lastRegion = r; byte[] compressed = null; compressed = compressedTiles.get(r); if (compressed == null) return null; lastTile = codec.decompress(compressed, options); } int pixel = options.channels * (options.bitsPerSample / 8); byte[] buf = new byte[w * h * pixel]; for (int i=0; i<h; i++) { System.arraycopy(lastTile, r.width * pixel * (i + y - r.y) + (x - r.x), buf, i * w * pixel, pixel * w); } return buf; } }
@Override public int hashCode() { return toString().hashCode(); }
/** * Returns true if the point specified by the given X and Y coordinates * is contained within this region. * * @param xc the integer X coordinate of a point * @param yc the integer Y coordinate of a point * @return true if this Region encloses the given point */ public boolean containsPoint(int xc, int yc) { return intersects(new Region(xc, yc, 1, 1)); }
/** * Returns a Region representing the intersection of this Region with the * given Region. If the two Regions do not intersect, the result is an * empty Region. */ public Region intersection(Region r) { int x = Math.max(this.x, r.x); int y = Math.max(this.y, r.y); int w = Math.min(this.x + this.width, r.x + r.width) - x; int h = Math.min(this.y + this.height, r.y + r.height) - y; if (w < 0) w = 0; if (h < 0) h = 0; return new Region(x, y, w, h); }
/** * Returns a Region representing the intersection of this Region with the * given Region. If the two Regions do not intersect, the result is an * empty Region. * * @param r the region for which to calculate an intersection (or overlap) * @return a Region representing the intersection (overlap) of the two Regions. * If the two Regions have no common area, then the width and/or height * of the returned Region will be 0. null is never returned. */ public Region intersection(Region r) { int x = Math.max(this.x, r.x); int y = Math.max(this.y, r.y); int w = Math.min(this.x + this.width, r.x + r.width) - x; int h = Math.min(this.y + this.height, r.y + r.height) - y; if (w < 0) w = 0; if (h < 0) h = 0; return new Region(x, y, w, h); }
/** * Returns true if the point specified by the given X and Y coordinates * is contained within this region. */ public boolean containsPoint(int xc, int yc) { return intersects(new Region(xc, yc, 1, 1)); }
throws IOException Region image = new Region(xCoordinate, yCoordinate, width, height); Region tileBoundary = new Region(0, 0, 0, 0); byte[] tile = null; for (int row=0; row<yTiles; row++) { tileBoundary.x = col * tileDim; tileBoundary.width = col < xTiles - 1 ? tileDim : imageWidth - (tileDim*col); if (tileBoundary.intersects(image)) { intersection = image.intersection(tileBoundary); tile = getTile(col, row);
public void add(byte[] pixels, int x, int y, int w, int h) throws CodecException, IOException { toCompress.add(pixels); row++; if ((y % ROW_COUNT) == ROW_COUNT - 1 || y == getHeight() - 1 || y == yy + hh - 1) { Region r = new Region(x, y - row + 1, w, row); options.width = w; options.height = row; options.channels = 1; options.bitsPerSample = 8; options.signed = false; byte[] compressed = codec.compress(toCompress.toByteArray(), options); compressedTiles.put(r, compressed); toCompress.clear(); } }
if (planarConfig == 2) numTileRows *= samplesPerPixel; Region imageBounds = new Region(x, y, (int) width, (int) height); Region tileBounds = new Region(0, 0, (int) tileWidth, (int) tileLength); if (!imageBounds.intersects(tileBounds)) continue;
@Override public int hashCode() { return toString().hashCode(); }
int tileCols = cols.get(getCoreIndex()); Region image = new Region(x, y, w, h); int outputRow = 0, outputCol = 0; Region intersection = null; int width = tileX.get(getCoreIndex()); int height = tileY.get(getCoreIndex()); Region tile = new Region(col * width, row * height, width, height); if (!tile.intersects(image)) { continue; intersection = tile.intersection(image); int intersectionX = 0;
public void add(int[] pixels, int x, int y, int w, int h) throws CodecException, IOException { byte[] buf = new byte[pixels.length * 3]; for (int i=0; i<pixels.length; i++) { buf[i * 3] = (byte) ((pixels[i] & 0xff0000) >> 16); buf[i * 3 + 1] = (byte) ((pixels[i] & 0xff00) >> 8); buf[i * 3 + 2] = (byte) (pixels[i] & 0xff); } toCompress.add(buf); row++; if ((y % ROW_COUNT) == ROW_COUNT - 1 || y == getHeight() - 1 || y == yy + hh - 1) { Region r = new Region(x, y - row + 1, w, row); options.width = w; options.height = row; options.channels = 3; options.bitsPerSample = 8; options.signed = false; byte[] compressed = codec.compress(toCompress.toByteArray(), options); compressedTiles.put(r, compressed); toCompress.clear(); row = 0; } }
if (planarConfig == 2) numTileRows *= samplesPerPixel; Region imageBounds = new Region(x, y, (int) width, (int) height); Region tileBounds = new Region(0, 0, (int) tileWidth, (int) tileLength); if (!imageBounds.intersects(tileBounds)) continue;
int tileCols = cols.get(getCoreIndex()); Region image = new Region(x, y, w, h); int outputRow = 0, outputCol = 0; Region intersection = null; int width = tileX.get(getCoreIndex()); int height = tileY.get(getCoreIndex()); Region tile = new Region(col * width, row * height, width, height); if (!tile.intersects(image)) { continue; intersection = tile.intersection(image); int intersectionX = 0;
/** Valid only after {@link ImportStep#STACK}. */ public Region getCropRegion(int s) { assertStep(ImportStep.STACK); Region region = options.doCrop() ? options.getCropRegion(s) : null; reader.setSeries(s); int sizeX = reader.getSizeX(), sizeY = reader.getSizeY(); if (region == null) { // entire image plane is the default region region = new Region(0, 0, sizeX, sizeY); } else { // bounds checking for cropped region if (region.x < 0) region.x = 0; if (region.y < 0) region.y = 0; if (region.width <= 0 || region.x + region.width > sizeX) { region.width = sizeX - region.x; } if (region.height <= 0 || region.y + region.height > sizeY) { region.height = sizeX - region.y; } } return region; }
int th = reader.getSizeY(); Region image = new Region(x, y, w, h); int pixelType = getPixelType(); int pixel = getRGBChannelCount() * FormatTools.getBytesPerPixel(pixelType); Region tile = new Region(tx * tw, ty * th, tw, th); if (!tile.intersects(image)) { continue; intersection = tile.intersection(image); int rowLen = pixel * (int) Math.min(intersection.width, tw);
/** Valid only after {@link ImportStep#STACK}. */ public Region getCropRegion(int s) { assertStep(ImportStep.STACK); Region region = options.doCrop() ? options.getCropRegion(s) : null; reader.setSeries(s); int sizeX = reader.getSizeX(), sizeY = reader.getSizeY(); if (region == null) { // entire image plane is the default region region = new Region(0, 0, sizeX, sizeY); } else { // bounds checking for cropped region if (region.x < 0) region.x = 0; if (region.y < 0) region.y = 0; if (region.width <= 0 || region.x + region.width > sizeX) { region.width = sizeX - region.x; } if (region.height <= 0 || region.y + region.height > sizeY) { region.height = sizeX - region.y; } } return region; }