use of loci.formats.services.JPEGTurboServiceImpl in project bioformats by openmicroscopy.
the class HamamatsuVMSReader method openBytes.
/**
* @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int)
*/
@Override
public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException {
FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h);
int startCol = x / MAX_JPEG_SIZE;
int startRow = y / MAX_JPEG_SIZE;
String file = null;
switch(getCoreIndex()) {
case 0:
file = tileFiles[no][startRow][startCol];
break;
case 1:
file = macroFile;
break;
case 2:
file = mapFile;
break;
}
if (getSizeX() <= MAX_SIZE || getSizeY() <= MAX_SIZE) {
JPEGReader reader = new JPEGReader();
reader.setId(file);
reader.openBytes(0, buf, x, y, w, h);
reader.close();
return buf;
}
if (service == null) {
service = new JPEGTurboServiceImpl();
}
try {
Region image = new Region(x, y, w, h);
for (int row = startRow; row < nRows; row++) {
for (int col = startCol; col < nCols; col++) {
Region tile = new Region(col * MAX_JPEG_SIZE, row * MAX_JPEG_SIZE, col == nCols - 1 ? getSizeX() % MAX_JPEG_SIZE : MAX_JPEG_SIZE, row == nRows - 1 ? getSizeY() % MAX_JPEG_SIZE : MAX_JPEG_SIZE);
if (!tile.intersects(image)) {
continue;
}
file = tileFiles[no][row][col];
if (initializedSeries != getCoreIndex() || initializedPlane != no || !file.equals(initializedFile)) {
service.close();
if (restartMarkers.containsKey(file)) {
service.setRestartMarkers(restartMarkers.get(file));
} else {
service.setRestartMarkers(null);
}
// closing the service will close this file
RandomAccessInputStream s = new RandomAccessInputStream(file);
service.initialize(s, tile.width, tile.height);
restartMarkers.put(file, service.getRestartMarkers());
initializedSeries = getCoreIndex();
initializedPlane = no;
initializedFile = file;
}
Region intersection = tile.intersection(image);
int tileX = intersection.x % MAX_JPEG_SIZE;
int tileY = intersection.y % MAX_JPEG_SIZE;
int rowLen = intersection.width * getRGBChannelCount();
byte[] b = new byte[rowLen * intersection.height];
service.getTile(b, tileX, tileY, intersection.width, intersection.height);
for (int tileRow = 0; tileRow < intersection.height; tileRow++) {
int src = tileRow * rowLen;
int dest = (((intersection.y + tileRow - y) * w) + (intersection.x - x)) * getRGBChannelCount();
System.arraycopy(b, src, buf, dest, rowLen);
}
}
}
} catch (ServiceException e) {
throw new FormatException(e);
}
return buf;
}
use of loci.formats.services.JPEGTurboServiceImpl in project bioformats by openmicroscopy.
the class TileJPEGReader method reopenFile.
@Override
public void reopenFile() throws IOException {
if (in != null) {
in.close();
}
in = new RandomAccessInputStream(currentId);
in.seek(0);
service = new JPEGTurboServiceImpl();
try {
service.initialize(in, getSizeX(), getSizeY());
} catch (ServiceException se) {
service = null;
throw new IOException("Could not initialize JPEG service", se);
}
}
Aggregations