Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions components/formats-bsd/src/loci/formats/tiff/TiffParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1061,10 +1061,14 @@ public byte[] getSamples(IFD ifd, byte[] buf, int x, int y,
}
}
}
// buf may be larger than the actual image, so don't use buf.length
// to determine the number of bytes per channel
// since offset is updated after every tile copy, it reflects the
// actual number of bytes that were read and copied into buf
if (effectiveChannels > 1) {
byte[][] split = new byte[effectiveChannels][buf.length / effectiveChannels];
byte[][] split = new byte[effectiveChannels][offset / effectiveChannels];
for (int c=0; c<split.length; c++) {
split[c] = ImageTools.splitChannels(buf, c, effectiveChannels, bytes, false, true);
split[c] = ImageTools.splitChannels(buf, split[c], c, effectiveChannels, bytes, false, true, split[c].length);
}
for (int c=0; c<split.length; c++) {
System.arraycopy(split[c], 0, buf, c * split[c].length, split[c].length);
Expand Down
7 changes: 7 additions & 0 deletions components/formats-bsd/test/loci/formats/utests/testng.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@
<class name="loci.formats.utests.tiff.TiffParserTest"/>
</classes>
</test>
<test name="RGB48TIFFParserTest">
<parameter name="mockClassName"
value="loci.formats.utests.tiff.RGB48TiffMock"/>
<classes>
<class name="loci.formats.utests.tiff.TiffParserTest"/>
</classes>
</test>
<test name="TiffWriterTest">
<groups/>
<classes>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* #%L
* BSD implementations of Bio-Formats readers and writers
* %%
* Copyright (C) 2005 - 2017 Open Microscopy Environment:
* - Board of Regents of the University of Wisconsin-Madison
* - Glencoe Software, Inc.
* - University of Dundee
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/

package loci.formats.utests.tiff;

import java.io.IOException;

import loci.formats.FormatException;

public class RGB48TiffMock extends RGBTiffMock {

public RGB48TiffMock() throws FormatException, IOException {
super();
}

@Override
public int[] getBitsPerSample() {
return new int[] { 16, 16, 16};
}

@Override
public int[] getRowsPerStrip() {
return new int[] {1};
}

@Override
public int[] getStripOffsets() {
return new int[] {0, 36, 72, 108};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -198,5 +198,19 @@ public void testBitsPerSampleMismatch() throws IOException, FormatException {
mock.close();
}

@Test
public void testReadPixels() throws IOException, FormatException {
int size = mock.getImageLength();
int bytesPerPixel = 0;
for (int bps : mock.getBitsPerSample()) {
bytesPerPixel += (bps / 8);
}
int minBuf = size * size * bytesPerPixel;
for (int i=minBuf; i<minBuf*10; i++) {
byte[] buf = new byte[i];
tiffParser.getSamples(tiffParser.getFirstIFD(), buf, 0, 0, size, size);
}
}

// TODO: Test wrong type exceptions
}
Loading