[
https://issues.apache.org/jira/browse/IMAGING-311?focusedWorklogId=668049&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-668049
]
ASF GitHub Bot logged work on IMAGING-311:
------------------------------------------
Author: ASF GitHub Bot
Created on: 20/Oct/21 23:50
Start Date: 20/Oct/21 23:50
Worklog Time Spent: 10m
Work Description: kinow commented on a change in pull request #179:
URL: https://github.com/apache/commons-imaging/pull/179#discussion_r733222342
##########
File path:
src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/ImageDataReader.java
##########
@@ -62,15 +63,15 @@
* Unfortunately, the TIFF floating-point format allows for a lot of different
* variations. At this time, only the most widely used of these are supported.
* When this code was written, only a small set of test data products were
- * available. Thus it is likely that developers will wish to extend the
- * range of floating-point data that can be processed as
- * additional test data become available. When implementing extensions to this
- * logic, developers are reminded that image processing requires
- * the handling of literally millions of pixels, so attention to performance
- * is essential to a successful implementation (please see the notes in
- * DataReaderStrips.java for more information).
+ * available. Thus it is likely that developers will wish to extend the range
of
+ * floating-point data that can be processed as additional test data become
+ * available. When implementing extensions to this logic, developers are
+ * reminded that image processing requires the handling of literally millions
of
+ * pixels, so attention to performance is essential to a successful
+ * implementation (please see the notes in DataReaderStrips.java for more
Review comment:
Use `{@code DataReaderStrips}` or `{@link DataReaderStrips}`.
##########
File path:
src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/ImageDataReader.java
##########
@@ -382,53 +413,91 @@ protected void applyPredictorToBlock(final int width,
final int height, final in
final int height,
final int scanSize,
final byte[] bytes,
- final int predictor,
- final int bitsPerSample,
+ final int bitsPerPixel,
final ByteOrder byteOrder)
throws ImageReadException {
+ final int bitsPerSample = bitsPerPixel / samplesPerPixel;
final int bytesPerSample = bitsPerSample / 8;
- final int nBytes = bytesPerSample * scanSize * height;
- final int length = bytes.length < nBytes ? nBytes / scanSize : height;
-
- final int[] samples = new int[scanSize * height];
+ final int bytesPerScan = scanSize * samplesPerPixel * bytesPerSample;
+ final int nBytes = bytesPerScan * height;
+ final int length = bytes.length < nBytes ? nBytes / bytesPerScan :
height;
+ final int[] samples = new int[scanSize * samplesPerPixel * height];
// floating-point differencing is indicated by a predictor value of 3.
if (predictor ==
TiffTagConstants.PREDICTOR_VALUE_FLOATING_POINT_DIFFERENCING) {
// at this time, this class supports the 32-bit format. The
// main reason for this is that we have not located sample data
// that can be used for testing and analysis.
- if (bitsPerSample != 32) {
+ if (bitsPerPixel / samplesPerPixel != 32) {
throw new ImageReadException(
"Imaging does not yet support floating-point data"
+ " with predictor type 3 for "
- + bitsPerSample + " bits per sample");
+ + bitsPerPixel + " bits per sample");
}
- final int bytesInRow = scanSize * 4;
- for (int i = 0; i < length; i++) {
- final int aOffset = i * bytesInRow;
- final int bOffset = aOffset + scanSize;
- final int cOffset = bOffset + scanSize;
- final int dOffset = cOffset + scanSize;
- // in this loop, the source bytes give delta values.
- // we adjust them to give true values. This operation is
- // done on a row-by-row basis.
- for (int j = 1; j < bytesInRow; j++) {
- bytes[aOffset + j] += bytes[aOffset + j - 1];
+
+ if (planarConfiguration == TiffPlanarConfiguration.CHUNKY) {
+ final int bytesInRow = scanSize * 4 * samplesPerPixel;
+ for (int i = 0; i < length; i++) {
+ final int aOffset = i * bytesInRow;
+ final int bOffset = aOffset + scanSize * samplesPerPixel;
+ final int cOffset = bOffset + scanSize * samplesPerPixel;
+ final int dOffset = cOffset + scanSize * samplesPerPixel;
+ // in this loop, the source bytes give delta values.
+ // we adjust them to give true values. This operation is
+ // done on a row-by-row basis.
+ for (int j = 1; j < bytesInRow; j++) {
+ bytes[aOffset + j] += bytes[aOffset + j - 1];
+ }
+ // pack the bytes into the integer bit-equivalent of
+ // floating point values
+ int index = i * scanSize;
+ for (int j = 0; j < width * samplesPerPixel; j++) {
+ final int a = bytes[aOffset + j];
+ final int b = bytes[bOffset + j];
+ final int c = bytes[cOffset + j];
+ final int d = bytes[dOffset + j];
+ // Pack the 4 byte components into a single integer
+ // in the byte order used by the TIFF standard
+ samples[index++] = ((a & 0xff) << 24)
+ | ((b & 0xff) << 16)
+ | ((c & 0xff) << 8)
+ | (d & 0xff);
+ }
}
- // pack the bytes into the integer bit-equivalent of
- // floating point values
- int index = i * scanSize;
- for (int j = 0; j < width; j++) {
- final int a = bytes[aOffset + j];
- final int b = bytes[bOffset + j];
- final int c = bytes[cOffset + j];
- final int d = bytes[dOffset + j];
- // Pack the 4 byte components into a single integer
- // in the byte order used by the TIFF standard
- samples[index++] = ((a & 0xff) << 24)
- | ((b & 0xff) << 16)
- | ((c & 0xff) << 8)
- | (d & 0xff);
+ } else {
+ final int bytesInRow = scanSize * 4;
+ for (int iPlane = 0; iPlane < samplesPerPixel; iPlane++) {
+ int planarIntOffset = iPlane * length * scanSize;
+ int planarByteOffset = planarIntOffset * 4;
+
+ for (int i = 0; i < length; i++) {
+ final int aOffset = i * bytesInRow + planarByteOffset;
+ final int bOffset = aOffset + scanSize;
+ final int cOffset = bOffset + scanSize;
+ final int dOffset = cOffset + scanSize;
+ // in this loop, the source bytes give delta values.
+ // we adjust them to give true values. This operation
is
+ // done on a row-by-row basis.
+ for (int j = 1; j < bytesInRow; j++) {
+ bytes[aOffset + j] += bytes[aOffset + j - 1];
+ }
+ // pack the bytes into the integer bit-equivalent of
+ // floating point values
+ int index = planarIntOffset + i * scanSize;
+ for (int j = 0; j < width; j++) {
+ final int a = bytes[aOffset + j];
+ final int b = bytes[bOffset + j];
+ final int c = bytes[cOffset + j];
+ final int d = bytes[dOffset + j];
+ // Pack the 4 byte components into a single integer
+ // in the byte order used by the TIFF standard
+ samples[index++] = ((a & 0xff) << 24)
+ | ((b & 0xff) << 16)
+ | ((c & 0xff) << 8)
+ | (d & 0xff);
+ }
+ }
Review comment:
For a follow-up, we should probably simplify this method, splitting into
separate methods if possible.
##########
File path:
src/test/java/org/apache/commons/imaging/formats/tiff/TiffRasterDataTest.java
##########
@@ -84,6 +85,45 @@ public void testGetValue() {
}
}
+ /**
+ * Test of setValue method, of class TiffRasterData.
+ */
+ @Test
+ public void testSetValue2() {
+ final TiffRasterData instance = new TiffRasterDataFloat(width, height,
2);
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ final int index = y * width + height;
+ instance.setValue(x, y, 1, index);
+ final int test = (int) instance.getValue(x, y, 1);
+ assertEquals(index, test, "Set/get value test failed at (" + x
+ "," + y + ")");
+ instance.setIntValue(x, y, 1, index);
+ final int iTest = instance.getIntValue(x, y, 1);
+ assertEquals(index, iTest, "Get/set value test failed at (" +
x + "," + y + ")");
+ }
+ }
+ }
+
+ /**
+ * Test of getValue method, of class TiffRasterData.
+ */
+ @Test
+ public void testGetValue2() {
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ final int index = y * width + x;
+ final int test = (int) raster.getValue(x, y, 0);
+ assertEquals(index, test, "Get into source data test failed at
(" + x + "," + y + ")");
+ final int iTest = raster.getIntValue(x, y, 0);
+ assertEquals(index, iTest, "Get into source data test failed
at (" + x + "," + y + ")");
+ }
+ }
+ }
+
+
+
+
+
Review comment:
Unnecessary extra blank lines :point_up:
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 668049)
Time Spent: 0.5h (was: 20m)
> Read TIFFs with multiple floating-point samples
> -----------------------------------------------
>
> Key: IMAGING-311
> URL: https://issues.apache.org/jira/browse/IMAGING-311
> Project: Commons Imaging
> Issue Type: New Feature
> Components: Format: TIFF
> Affects Versions: 1.0-alpha2
> Environment:
> [IMAGING-251|https://issues.apache.org/jira/browse/IMAGING-251]
> Reporter: Gary Lucas
> Assignee: Bruno P. Kinoshita
> Priority: Major
> Fix For: 1.0-alpha3
>
> Attachments: NBS_Example.jpg
>
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> I propose to extend Commons Imaging to support reading TIFF files that
> contain floating-point formats that feature more than one sample. The
> ability to support floating-point samples was introduced in
> [ISSUE-251|https://issues.apache.org/jira/browse/IMAGING-251]. But that
> implementation was limited to only those files that provided a single sample
> per raster cell (e.g. "a single sample per pixel"). The ability to read files
> with multiple samples per raster cell would extend the usefulness of the
> Commons Imaging API, particularly for geophysical applications.
> If anyone knows of good sources for test TIFF files that use this format,
> please let me know.
> *Background*
> In addition to conventional image data, TIFF files can provide floating-point
> numerical information. This feature is often used for geophysical data (in
> GeoTIFF files), but can also be applied to other uses. Although the existing
> implementation can support files which give a single value per raster cell,
> there are some products that carry multiple samples per cell. Examples
> include products that give both a measured value and a corresponding accuracy
> estimate (i.e. 245.6 meters plus or minus 0.5 meters). Some geophysical
> products give vectors (gravitational potential, wind vectors, ocean currents,
> etc.).
> Changes would involve extensions to the classes in the TIFF datareader
> package as well as the TiffRasterData class.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)