Skip to content

Commit

Permalink
Extend precompressed tile writing to OME-TIFF
Browse files Browse the repository at this point in the history
Mostly this reuses logic in the basic TIFF writer.
  • Loading branch information
melissalinkert committed May 1, 2024
1 parent 3146c90 commit 92ec581
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
18 changes: 18 additions & 0 deletions components/formats-bsd/src/loci/formats/out/OMETiffWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,24 @@ public void close() throws IOException {

// -- IFormatWriter API methods --

@Override
public void saveCompressedBytes(int no, byte[] buf, int x, int y, int w, int h)
throws FormatException, IOException
{
super.saveCompressedBytes(no, buf, x, y, w, h);

int index = no;
while (imageLocations[series][index] != null) {
if (index < imageLocations[series].length - 1) {
index++;
}
else {
break;
}
}
imageLocations[series][index] = currentId;
}

/**
* @see loci.formats.IFormatWriter#saveBytes(int, byte[], int, int, int, int)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ public boolean isThisType(String name) {

// -- IFormatWriter API methods --

protected IFD makeIFD() throws FormatException, IOException {
IFD ifd = super.makeIFD();
if (getResolution() > 0) {
ifd.put(IFD.NEW_SUBFILE_TYPE, 1);
}
else {
if (!ifd.containsKey(IFD.SUB_IFD)) {
ifd.put(IFD.SUB_IFD, (long) 0);
}
}
return ifd;
}

@Override
public void saveBytes(int no, byte[] buf, IFD ifd, int x, int y, int w, int h)
throws FormatException, IOException
Expand Down
18 changes: 11 additions & 7 deletions components/formats-bsd/src/loci/formats/out/TiffWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void saveCompressedBytes(int no, byte[] buf, int x, int y, int w, int h)
LOGGER.warn("saveCompressedBytes(series={}, resolution={}, no={}, x={}, y={})",
series, resolution, no, x, y);

IFD ifd = new IFD();
IFD ifd = makeIFD();
MetadataRetrieve retrieve = getMetadataRetrieve();
int type = FormatTools.pixelTypeFromString(
retrieve.getPixelsType(series).toString());
Expand All @@ -193,12 +193,6 @@ public void saveCompressedBytes(int no, byte[] buf, int x, int y, int w, int h)
throw new IllegalArgumentException("Compressed tile dimensions must match tile size");
}

boolean usingTiling = currentTileSizeX > 0 && currentTileSizeY > 0;
if (usingTiling) {
ifd.put(new Integer(IFD.TILE_WIDTH), new Long(currentTileSizeX));
ifd.put(new Integer(IFD.TILE_LENGTH), new Long(currentTileSizeY));
}

// This operation is synchronized
synchronized (this) {
// This operation is synchronized against the TIFF saver.
Expand All @@ -221,6 +215,16 @@ public void saveCompressedBytes(int no, byte[] buf, int x, int y, int w, int h)
nChannels, lastPlane && lastSeries && lastResolution, x, y);
}

protected IFD makeIFD() throws FormatException, IOException {
IFD ifd = new IFD();
boolean usingTiling = getTileSizeX() > 0 && getTileSizeY() > 0;
if (usingTiling) {
ifd.put(new Integer(IFD.TILE_WIDTH), new Long(getTileSizeX()));
ifd.put(new Integer(IFD.TILE_LENGTH), new Long(getTileSizeY()));
}
return ifd;
}

// -- FormatWriter API methods --

/* @see loci.formats.FormatWriter#setId(String) */
Expand Down

0 comments on commit 92ec581

Please sign in to comment.