/** * Implemented as specified by {@link PixelBuffer} I/F. * @see PixelBuffer#setPlane(ByteBuffer, Integer, Integer, Integer) */ public void setPlane(ByteBuffer buffer, Integer z, Integer c, Integer t) throws IOException, DimensionsOutOfBoundsException { throwIfReadOnly(); Long offset = getPlaneOffset(z, c, t); Integer size = safeLongToInteger(getPlaneSize()); if (buffer.limit() != size) { // Handle the size mismatch. if (buffer.limit() < size) throw new BufferUnderflowException(); throw new BufferOverflowException(); } setRegion(size, offset, buffer); }
/** * Helper method to properlty create a RomioPixelBuffer. * * @param pixelsFilePath * @param pixels * @param allowModification */ protected PixelBuffer createRomioPixelBuffer(String pixelsFilePath, Pixels pixels, boolean allowModification) { return new RomioPixelBuffer(pixelsFilePath, pixels, allowModification); }
/** * Implemented as specified by {@link PixelBuffer} I/F. * @see PixelBuffer#getPlaneOffset(Integer, Integer, Integer) */ public Long getPlaneOffset(Integer z, Integer c, Integer t) throws DimensionsOutOfBoundsException { checkBounds(null, null, z, c, t); Long timepointSize = getTimepointSize(); Long stackSize = getStackSize(); Long planeSize = getPlaneSize(); return timepointSize * t + stackSize * c + planeSize * z; }
/** * Implemented as specified by {@link PixelBuffer} I/F. * @see PixelBuffer#getTimepoint(Integer) */ public PixelData getTimepoint(Integer t) throws IOException, DimensionsOutOfBoundsException { Long offset = getTimepointOffset(t); Integer size = safeLongToInteger(getTimepointSize()); return getRegion(size, offset); }
/** * Implemented as specified by {@link PixelBuffer} I/F. * @see PixelBuffer#getStackOffset(Integer, Integer) */ public Long getStackOffset(Integer c, Integer t) throws DimensionsOutOfBoundsException { checkBounds(null, null, null, c, t); Long timepointSize = getTimepointSize(); Long stackSize = getStackSize(); return timepointSize * t + stackSize * c; }
/** * Implemented as specified by {@link PixelBuffer} I/F. * @see PixelBuffer#getPlaneSize() */ public Long getPlaneSize() { if (planeSize == null) { planeSize = (long) getSizeX() * (long) getSizeY() * getByteWidth(); } return planeSize; }
public byte[] getMessageDigest() throws IOException { MessageDigest md; try { md = MessageDigest.getInstance("SHA-1"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException( "Required SHA-1 message digest algorithm unavailable."); } int sizeT = getSizeT(); for (int t = 0; t < sizeT; t++) { try { int size = RomioPixelBuffer.safeLongToInteger(getTimepointSize()); byte[] buffer = new byte[size]; getTimepoint(t,buffer); md.update(ByteBuffer.wrap(buffer)); } catch (DimensionsOutOfBoundsException e) { throw new RuntimeException(e); } } return md.digest(); }
String path = getPixelsPath(pixbuf.getId()); createSubpath(path); Integer size = RomioPixelBuffer.safeLongToInteger(pixbuf.getPlaneSize()); byte[] padding = new byte[size - NULL_PLANE_SIZE]; FileOutputStream stream = new FileOutputStream(path); try { for (int z = 0; z < pixbuf.getSizeZ(); z++) { for (int c = 0; c < pixbuf.getSizeC(); c++) { for (int t = 0; t < pixbuf.getSizeT(); t++) { stream.write(nullPlane); stream.write(padding);
/** * Implemented as specified by {@link PixelBuffer} I/F. * @see PixelBuffer#setStack(ByteBuffer, Integer, Integer, Integer) */ public void setStack(ByteBuffer buffer, Integer z, Integer c, Integer t) throws IOException, DimensionsOutOfBoundsException { throwIfReadOnly(); Long offset = getStackOffset(c, t); Integer size = safeLongToInteger(getStackSize()); if (buffer.limit() != size) { // Handle the size mismatch. if (buffer.limit() < size) throw new BufferUnderflowException(); throw new BufferOverflowException(); } setRegion(size, offset, buffer); }
/** * Implemented as specified by {@link PixelBuffer} I/F. * @see PixelBuffer#setTimepoint(ByteBuffer, Integer) */ public void setTimepoint(ByteBuffer buffer, Integer t) throws IOException, DimensionsOutOfBoundsException { throwIfReadOnly(); Long offset = getTimepointOffset(t); Integer size = safeLongToInteger(getTimepointSize()); if (buffer.limit() != size) { // Handle the size mismatch. if (buffer.limit() < size) throw new BufferUnderflowException(); throw new BufferOverflowException(); } setRegion(size, offset, buffer); }
/** * Implemented as specified by {@link PixelBuffer} I/F. * @see PixelBuffer#getStack(Integer, Integer) */ public PixelData getStack(Integer c, Integer t) throws IOException, DimensionsOutOfBoundsException { Long offset = getStackOffset(c, t); Integer size = safeLongToInteger(getStackSize()); return getRegion(size, offset); }
int cubeOffset = 0; int xStripes = (size.get(0) + step.get(0) - 1) / step.get(0); int pixelSize = getByteWidth(); int tileRowSize = pixelSize * xStripes; byte[] plane = new byte[safeLongToInteger(getPlaneSize())]; for(int t = offset.get(4); t < size.get(4)+offset.get(4); t += step.get(4)) getPlaneDirect(z,c,t,plane); int rowOffset = offset.get(1)*getRowSize(); if(step.get(0)==1) byteOffset += getRowSize()*step.get(1); byteOffset += step.get(0)*pixelSize; rowOffset += getRowSize()*step.get(1);
/** * Implemented as specified by {@link PixelBuffer} I/F. * @see PixelBuffer#getPlane(Integer, Integer, Integer) */ public PixelData getPlane(Integer z, Integer c, Integer t) throws IOException, DimensionsOutOfBoundsException { log.info("Retrieving plane: " + z + "x" + c + "x" + t); Long offset = getPlaneOffset(z, c, t); Integer size = safeLongToInteger(getPlaneSize()); PixelData region = getRegion(size, offset); byte[] nullPlane = PixelsService.nullPlane; for (int i = 0; i < PixelsService.NULL_PLANE_SIZE; i++) { if (region.getData().get(i) != nullPlane[i]) { return region; } } region.dispose(); return null; // All of the nullPlane bytes match, non-filled plane }
/** * Implemented as specified by {@link PixelBuffer} I/F. * @see PixelBuffer#getHypercube(List, List, List) */ public PixelData getHypercube(List<Integer> offset, List<Integer> size, List<Integer> step) throws IOException, DimensionsOutOfBoundsException { byte[] buffer = new byte[ safeLongToInteger(getHypercubeSize(offset,size,step))]; getHypercubeDirect(offset,size,step,buffer); return new PixelData(pixels.getPixelsType().getValue(), ByteBuffer.wrap(buffer)); }
public void setTile(byte[] buffer, Integer z, Integer c, Integer t, Integer x, Integer y, Integer w, Integer h) throws IOException, BufferOverflowException { if (x != 0) { throw new UnsupportedOperationException( "ROMIO pixel buffer only supports 0 offseted tile writes."); } if (w != getSizeX()) { throw new UnsupportedOperationException( "ROMIO pixel buffer only supports full row writes."); } try { long offset = getPlaneOffset(z, c, t); offset += getByteWidth() * getSizeX() * y; setRegion(buffer.length, offset, buffer); } catch (DimensionsOutOfBoundsException e) { throw new RuntimeException(e); } }
/** * Implemented as specified by {@link PixelBuffer} I/F. * @see PixelBuffer#getCol(Integer, Integer, Integer, Integer) */ public PixelData getCol(Integer x, Integer z, Integer c, Integer t) throws IOException, DimensionsOutOfBoundsException { //Dimension check in plane. PixelData plane = getPlane(z, c, t); Integer sizeY = getSizeY(); Integer sizeX = getSizeX(); Integer colSize = getColSize(); ByteBuffer buf = ByteBuffer.wrap(new byte[colSize]); PixelData column = new PixelData(pixels.getPixelsType().getValue(), buf); int offset; double value; for (int i = 0; i < sizeY; i++) { offset = (i * sizeX) + x; value = plane.getPixelValue(offset); column.setPixelValue(i, value); } plane.dispose(); return column; }
throws IOException, DimensionsOutOfBoundsException { if (stride == null || stride < 0) stride = 0; checkBounds(x, y, z, c, t); checkBounds(x+width-1, y+height-1, null, null, null); PixelData plane = getPlane(z, c, t); Integer size; ByteBuffer buf; size = width*height*getByteWidth(); buf = ByteBuffer.wrap(new byte[size]); region = new PixelData(pixels.getPixelsType().getValue(), buf); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { offset = (i+y)*getSizeX()+x+j; region.setPixelValue(i*width+j, plane.getPixelValue(offset)); size = width*height*getByteWidth()/(stride*stride); buf = ByteBuffer.wrap(new byte[size]); region = new PixelData(pixels.getPixelsType().getValue(), buf); l = 0; for (int j = 0; j < width; j = j+stride) { offset = (i+y)*getSizeX()+x+j; region.setPixelValue(k*w+l, plane.getPixelValue(offset)); l++;
/** * Implemented as specified by {@link PixelBuffer} I/F. * @see PixelBuffer#getRowSize() */ public Integer getRowSize() { if (rowSize == null) { rowSize = getSizeX() * getByteWidth(); } return rowSize; }
/** * Implemented as specified by {@link PixelBuffer} I/F. * @see PixelBuffer#getColSize() */ public Integer getColSize() { if (colSize == null) { colSize = getSizeY() * getByteWidth(); } return colSize; }
/** * Implemented as specified by {@link PixelBuffer} I/F. * @see PixelBuffer#getTimepointOffset(Integer) */ public Long getTimepointOffset(Integer t) throws DimensionsOutOfBoundsException { checkBounds(null, null, null, null, t); Long timepointSize = getTimepointSize(); return (long) timepointSize * t; }