@Test(dependsOnMethods = {"testMetadataLevel"}) public void testEquivilentBlockRetrievalPlaneData() throws FormatException, IOException { String fileName = wrapper.getCurrentFile(); int sizeX = wrapper.getSizeX(); int sizeY = wrapper.getSizeY(); int sizeZ = wrapper.getSizeZ(); int sizeC = wrapper.getSizeC(); int sizeT = wrapper.getSizeT(); int bytesPerPixel = wrapper.getBitsPerPixel() / 8; int planeSize = sizeX * sizeY * bytesPerPixel; byte[] planar = new byte[planeSize]; byte[] block = new byte[planeSize]; int planeNumber = 0; String planarDigest; String blockDigest; for (int t = 0; t < sizeT; t++) { for (int c = 0; c < sizeC; c++) { for (int z = 0; z < sizeZ; z++) { planeNumber = wrapper.getIndex(z, c, t); wrapper.openPlane2D(fileName, planeNumber, planar); planarDigest = sha1(planar); wrapper.openPlane2D(fileName, planeNumber, block, 0, 0, sizeX, sizeY); blockDigest = sha1(block); assertEquals(planarDigest, blockDigest); } } } }
/** * Read a plane and update the pixels checksum * * @param size Sizes of the Pixels set. * @param z The Z-section offset to write to. * @param c The channel offset to write to. * @param t The timepoint offset to write to. * @param bytesPerPixel Number of bytes per pixel. * @param fileName Name of the file. * @param md Current Pixels set message digest. * @throws FormatException If there is an error reading Pixel data via Bio-Formats. * @throws IOException If there is an I/O error reading Pixel data via Bio-Formats. */ private void parseDataByPlane( ImportSize size, int z, int c, int t, int bytesPerPixel, String fileName, MessageDigest md) throws FormatException, IOException { int tileHeight = reader.getOptimalTileHeight(); int tileWidth = reader.getOptimalTileWidth(); int planeNumber, x, y, w, h; for (int tileOffsetY = 0; tileOffsetY < (size.sizeY + tileHeight - 1) / tileHeight; tileOffsetY++) { for (int tileOffsetX = 0; tileOffsetX < (size.sizeX + tileWidth - 1) / tileWidth; tileOffsetX++) { x = tileOffsetX * tileWidth; y = tileOffsetY * tileHeight; w = tileWidth; h = tileHeight; if ((x + tileWidth) > size.sizeX) { w = size.sizeX - x; } if ((y + tileHeight) > size.sizeY) { h = size.sizeY - y; } int bytesToRead = w * h * bytesPerPixel; if (arrayBuf.length != bytesToRead) { arrayBuf = new byte[bytesToRead]; } planeNumber = reader.getIndex(z, c, t); if (log.isDebugEnabled()) { log.debug( String.format( "Plane:%d X:%d Y:%d TileWidth:%d TileHeight:%d " + "arrayBuf.length:%d", planeNumber, x, y, w, h, arrayBuf.length)); } arrayBuf = reader.openBytes(planeNumber, arrayBuf, x, y, w, h); try { md.update(arrayBuf); } catch (Exception e) { // This better not happen. :) throw new RuntimeException(e); } } } }