Skip to content

Commit

Permalink
Reuse the byte buffer instead of reallocating
Browse files Browse the repository at this point in the history
For performance, Bio-Formats supports passing a preallocated byte
buffer. Let's definitely do this whenever possible, instead of getting
back a newly allocated buffer (of the exact same size) every time.

Might help some with scifio/scifio-imageio#17.
  • Loading branch information
ctrueden committed Apr 13, 2015
1 parent 3161913 commit 3b0966c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/main/java/io/scif/itk/SCIFIOITKBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,21 @@ public boolean read(String filePath, String series, int xBegin, int xEnd,
// System.err.println("canDoDirect = "+canDoDirect);

byte[] pixel = new byte[bpp];
byte[] image = null;
for (int c = cBegin; c <= cEnd; c++) {
for (int t = tBegin; t <= tEnd; t++) {
for (int z = zBegin; z <= zEnd; z++) {
int xLen = xEnd - xBegin + 1;
int yLen = yEnd - yBegin + 1;
byte[] image =
reader.openBytes(reader.getIndex(z, c, t), xBegin, yBegin, xLen,
yLen);
final int no = reader.getIndex(z, c, t);
if (image == null) {
// allocate a new image buffer
image = reader.openBytes(no, xBegin, yBegin, xLen, yLen);
}
else {
// reuse the existing image buffer
reader.openBytes(no, image, xBegin, yBegin, xLen, yLen);
}
if (canDoDirect) {
Object data =
DataTools.makeDataArray(image, bpp, FormatTools
Expand Down

0 comments on commit 3b0966c

Please sign in to comment.