use of loci.formats.codec.CodecOptions in project bioformats by openmicroscopy.
the class CellSensReader method decodeTile.
private byte[] decodeTile(int no, int row, int col) throws FormatException, IOException {
if (tileMap.get(getCoreIndex()) == null) {
return new byte[getTileSize()];
}
int[] zct = getZCTCoords(no);
TileCoordinate t = new TileCoordinate(nDimensions.get(getCoreIndex()));
t.coordinate[0] = col;
t.coordinate[1] = row;
int resIndex = getResolution();
int pyramidIndex = getSeries();
if (hasFlattenedResolutions()) {
int index = 0;
pyramidIndex = 0;
for (int i = 0; i < core.size(); ) {
if (index + core.get(i).resolutionCount <= getSeries()) {
index += core.get(i).resolutionCount;
i += core.get(i).resolutionCount;
pyramidIndex++;
} else {
resIndex = getSeries() - index;
break;
}
}
}
Pyramid pyramid = pyramids.get(pyramidIndex);
for (String dim : pyramid.dimensionOrdering.keySet()) {
int index = pyramid.dimensionOrdering.get(dim) + 2;
if (dim.equals("Z")) {
t.coordinate[index] = zct[0];
} else if (dim.equals("C")) {
t.coordinate[index] = zct[1];
} else if (dim.equals("T")) {
t.coordinate[index] = zct[2];
}
}
if (resIndex > 0) {
t.coordinate[t.coordinate.length - 1] = resIndex;
}
ArrayList<TileCoordinate> map = tileMap.get(getCoreIndex());
Integer index = map.indexOf(t);
if (index == null || index < 0) {
// fill in the tile with the stored background color
// usually this is either black or white
byte[] tile = new byte[getTileSize()];
byte[] color = backgroundColor.get(getCoreIndex());
if (color != null) {
for (int q = 0; q < getTileSize(); q += color.length) {
for (int i = 0; i < color.length; i++) {
tile[q + i] = color[i];
}
}
}
return tile;
}
Long offset = tileOffsets.get(getCoreIndex())[index];
RandomAccessInputStream ets = new RandomAccessInputStream(fileMap.get(getCoreIndex()));
ets.seek(offset);
CodecOptions options = new CodecOptions();
options.interleaved = isInterleaved();
options.littleEndian = isLittleEndian();
int tileSize = getTileSize();
if (tileSize == 0) {
tileSize = tileX.get(getCoreIndex()) * tileY.get(getCoreIndex()) * 10;
}
options.maxBytes = (int) (offset + tileSize);
byte[] buf = null;
long end = index < tileOffsets.get(getCoreIndex()).length - 1 ? tileOffsets.get(getCoreIndex())[index + 1] : ets.length();
IFormatReader reader = null;
String file = null;
switch(compressionType.get(getCoreIndex())) {
case RAW:
buf = new byte[tileSize];
ets.read(buf);
break;
case JPEG:
Codec codec = new JPEGCodec();
buf = codec.decompress(ets, options);
break;
case JPEG_2000:
codec = new JPEG2000Codec();
buf = codec.decompress(ets, options);
break;
case JPEG_LOSSLESS:
codec = new LosslessJPEGCodec();
buf = codec.decompress(ets, options);
break;
case PNG:
file = "tile.png";
reader = new APNGReader();
case BMP:
if (reader == null) {
file = "tile.bmp";
reader = new BMPReader();
}
byte[] b = new byte[(int) (end - offset)];
ets.read(b);
Location.mapFile(file, new ByteArrayHandle(b));
reader.setId(file);
buf = reader.openBytes(0);
Location.mapFile(file, null);
break;
}
if (reader != null) {
reader.close();
}
ets.close();
return buf;
}
use of loci.formats.codec.CodecOptions in project bioformats by openmicroscopy.
the class TiffCompressionCompressTest method testTHUNDERSCAN.
@Test(expectedExceptions = { FormatException.class })
public void testTHUNDERSCAN() throws FormatException, IOException {
TiffCompression compression = TiffCompression.THUNDERSCAN;
CodecOptions options = compression.getCompressionCodecOptions(ifd);
compression.compress(data, options);
}
use of loci.formats.codec.CodecOptions in project bioformats by openmicroscopy.
the class TiffCompressionCompressTest method testJPEG_2000_ResetQuality.
@Test(enabled = true)
public void testJPEG_2000_ResetQuality() throws FormatException, IOException {
TiffCompression compression = TiffCompression.JPEG_2000;
JPEG2000CodecOptions opt = JPEG2000CodecOptions.getDefaultOptions();
opt.quality = 1.0f;
CodecOptions options = compression.getCompressionCodecOptions(ifd, opt);
assertEquals(options.quality, opt.quality);
compression = TiffCompression.JPEG_2000_LOSSY;
options = compression.getCompressionCodecOptions(ifd, opt);
assertEquals(options.quality, opt.quality);
compression = TiffCompression.ALT_JPEG2000;
options = compression.getCompressionCodecOptions(ifd, opt);
assertEquals(options.quality, opt.quality);
}
use of loci.formats.codec.CodecOptions in project bioformats by openmicroscopy.
the class TiffCompressionCompressTest method testJPEG_2000_LOSSY.
@Test
public void testJPEG_2000_LOSSY() throws FormatException, IOException {
TiffCompression compression = TiffCompression.JPEG_2000_LOSSY;
CodecOptions options = compression.getCompressionCodecOptions(ifd);
byte[] compressed = compression.compress(data, options);
assertNotNull(compressed);
}
use of loci.formats.codec.CodecOptions in project bioformats by openmicroscopy.
the class TiffCompressionCompressTest method testNIKON.
@Test(expectedExceptions = { FormatException.class })
public void testNIKON() throws FormatException, IOException {
TiffCompression compression = TiffCompression.NIKON;
CodecOptions options = compression.getCompressionCodecOptions(ifd);
compression.compress(data, options);
}
Aggregations