/** * Close the active pixel buffer, cleaning up any potential messes left by * the pixel buffer itself. */ private synchronized void closePixelBuffer() { try { if (buffer != null) { buffer.close(); } } catch (IOException e) { if (log.isDebugEnabled()) { log.debug("Buffer could not be closed successfully.", e); } throw new ResourceError(e.getMessage() + " Please check server log."); } }
@RolesAllowed("user") public synchronized Map<Integer, double[]> findMinMax(int[] channels) { Map<Integer, double[]> result = new HashMap<Integer, double[]>(); if (requiresPixelsPyramid()) return result; try { for (int ch : channels) { Channel channel = pixelsInstance.getChannel(ch); if (channel == null) continue; int z = buffer.getSizeZ() > 1 ? (buffer.getSizeZ() - 1) / 2 : 0; int t = buffer.getSizeT() > 1 ? (buffer.getSizeT() - 1) / 2 : 0; PixelData px = buffer.getPlane(z, ch, t); double[] minmax = determineHistogramMinMax(px, channel, false); result.put(ch, minmax); } } catch (IOException e) { handleException(e); } return result; }
/** * Retrieves the number of resolution levels that the backing * pixels pyramid contains. * @return The number of resolution levels. This value does not * necessarily indicate either the presence or absence of a * pixels pyramid. * @see ome.io.nio.PixelBuffer#getResolutionLevels() **/ public int getResolutionLevels() { return buffer.getResolutionLevels(); }
/** * Iterates over every tile in a given pixel buffer based on the * over arching dimensions and a requested maximum tile width and height. * @param iteration Invoker to call for each tile. * @param pixelBuffer Pixel buffer which is backing the pixel data. * @param tileWidth <b>Maximum</b> width of the tile requested. The tile * request itself will be smaller than the original tile width requested if * <code>x + tileWidth > sizeX</code>. * @param tileHeight <b>Maximum</b> height of the tile requested. The tile * request itself will be smaller if <code>y + tileHeight > sizeY</code>. * @throws FailedTileLoopException if the tile loop was aborted; exception bears completed tile count * @return The total number of tiles iterated over. */ public static int forEachTile(TileLoopIteration iteration, PixelBuffer pixelBuffer, int tileWidth, int tileHeight) throws FailedTileLoopException { int sizeX = pixelBuffer.getSizeX(); int sizeY = pixelBuffer.getSizeY(); int sizeZ = pixelBuffer.getSizeZ(); int sizeC = pixelBuffer.getSizeC(); int sizeT = pixelBuffer.getSizeT(); return forEachTile(iteration, sizeX, sizeY, sizeZ, sizeC, sizeT, tileWidth, tileHeight); }
final Dimension sourceTileSize = source.getTileSize(); final double tileWidth = sourceTileSize.getWidth(); final double tileHeight = sourceTileSize.getHeight(); if (tileWidth == source.getSizeX() || tileHeight == source.getSizeY() || tileDimensionTooSmall) source.getSizeZ() * source.getSizeC() * source.getSizeT() * (Math.ceil(source.getSizeX() / tileSize.getWidth())) * (Math.ceil(source.getSizeY() / tileSize.getHeight())); final int tenPercent = Math.max((int) totalTiles / 10, 1); Utils.forEachTile(new TileLoopIteration() { source.close();
int originalSizeX = pixels.getSizeX(); int originalSizeY = pixels.getSizeY(); int pixelBufferSizeX = pixelBuffer.getSizeX(); int pixelBufferSizeY = pixelBuffer.getSizeY(); if (pixelBuffer.getResolutionLevels() > 1) int resolutionLevel = pixelBuffer.getResolutionLevels(); while (resolutionLevel > 0) pixelBufferSizeX = pixelBuffer.getSizeX(); pixelBufferSizeY = pixelBuffer.getSizeY(); if (pixelBufferSizeX <= thumbnailMetadata.getSizeX() || pixelBufferSizeY <= thumbnailMetadata.getSizeY())
binCount = DEFAULT_HISTOGRAM_BINSIZE; int imgWidth = buffer.getSizeX(); int h = (plane != null && plane.getRegion() != null && plane .getRegion().getHeight() > 0) ? plane.getRegion().getHeight() : buffer.getSizeY(); if (channel == null) continue; PixelData px = buffer.getPlane(z, ch, t); int[] data = new int[binCount];
switch (planeDef.getSlice()) { case PlaneDef.XY: return new Plane2D(planeDef, pixels, buffer.getTile( z, c, t, region.getX(), region.getY(), region.getWidth(), region.getHeight())); case PlaneDef.XZ: //TODO return new Plane2D(planeDef, pixels, buffer.getStack(c, t)); case PlaneDef.ZY: //TODO return new Plane2D(planeDef, pixels, buffer.getStack(c, t)); if (stride == null || stride <= 0) return new Plane2D(planeDef, pixels, buffer.getPlane(z, c, t)); return new Plane2D(planeDef, pixels, buffer.getPlaneRegion(0, 0, pixels.getSizeX(), pixels.getSizeY(), z, c, t, case PlaneDef.XZ: return new Plane2D(planeDef, pixels, buffer.getStack(c, t)); case PlaneDef.ZY: return new Plane2D(planeDef, pixels, buffer.getStack(c, t));
/** * Checks the region definition to ensure that the requested tile width * and height are valid with respect to the current resolution level. * @param rd Requested region definition. */ private void checkRegionDef(RegionDef rd) { if (rd == null) { return; } // We're using the buffer X and Y size because of the // possibility that we're on a resolution level where // Pixels.Size[X,Y] != PixelBuffer.Size[X,Y]. int sizeX = buffer.getSizeX(); int sizeY = buffer.getSizeY(); int x = rd.getX(); int y = rd.getY(); if ((rd.getWidth() + x) > sizeX) { rd.setWidth(sizeX - x); } if ((rd.getHeight() + y) > sizeY) { rd.setHeight(sizeY - y); } }
/** * Retrieves the tile size for the pixel store. * @return The dimension of the tile or <code>null</code> if the pixel * buffer is not tiled. **/ public Dimension getTileSize() { return buffer.getTileSize(); } }
/** * Returns the {@link ome.util.PixelData} for plane given its z, c and t * as well as a {@link PixelBuffer} * * @param buf the {@link PixelBuffer} * @param z the Z * @param c the C * @param t the T * @return the ome.util.PixelData for the plane */ public ome.util.PixelData getPlane(PixelBuffer buf, int z, int c, int t) { try { return buf.getPlane(z, c, t); } catch (IOException e) { throw new ResourceError("IOException: " + e); } catch (DimensionsOutOfBoundsException e) { throw new ApiUsageException("DimensionsOutOfBounds: " + e); } catch (IndexOutOfBoundsException iobe) { throw new ValidationException("IndexOutOfBounds: " + iobe); } }
/** * Retrieves the active resolution level. * @return The active resolution level. * @see ome.io.nio.PixelBuffer#getResolutionLevel() **/ public int getResolutionLevel() { return buffer.getResolutionLevel(); }
/** * Returns the image's size information per resolution level. * * @return See above. */ public List<List<Integer>> getResolutionDescriptions() { return buffer.getResolutionDescriptions(); }
/** * Sets the codomain interval i.e. a sub-interval of [0, 255]. * * @param start * The lower bound of the interval. * @param end * The upper bound of the interval. */ public void setCodomainInterval(int start, int end) { CodomainChain c; for (int i = 0; i < getPixels().getSizeC(); i++) { c = getCodomainChain(i); c.setInterval(start, end); } /* * RenderingDef rd = getRenderingDef(); QuantumDef qd = * rd.getQuantization(), newQd; newQd = new QuantumDef(); * newQd.setBitResolution(qd.getBitResolution()); * newQd.setCdStart(Integer.valueOf(start)); * newQd.setCdEnd(Integer.valueOf(end)); rd.setQuantization(newQd); */ RenderingDef rd = getRenderingDef(); QuantumDef qd = rd.getQuantization(); qd.setCdStart(Integer.valueOf(start)); qd.setCdEnd(Integer.valueOf(end)); //need to rebuild the look up table updateQuantumManager(); }
@RolesAllowed("user") public synchronized int[] getTileSize() { errorIfNotLoaded(); Dimension tileSize = buffer.getTileSize(); return new int[] { (int) tileSize.getWidth(), (int) tileSize.getHeight() }; }
@RolesAllowed("user") public synchronized int getResolutionLevel() { errorIfNotLoaded(); return buffer.getResolutionLevel(); }
@RolesAllowed("user") public synchronized List<List<Integer>> getResolutionDescriptions() { errorIfNotLoaded(); return buffer.getResolutionDescriptions(); }