kinow commented on a change in pull request #72: URL: https://github.com/apache/commons-imaging/pull/72#discussion_r422077764
########## File path: src/test/java/org/apache/commons/imaging/formats/tiff/photometricinterpreters/fp/PhotometricInterpreterFloatTest.java ########## @@ -0,0 +1,248 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.imaging.formats.tiff.photometricinterpreters.fp; + +import java.awt.Color; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.apache.commons.imaging.ImageReadException; +import org.apache.commons.imaging.ImageWriteException; +import org.apache.commons.imaging.common.ImageBuilder; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +/** + * Provides a unit test for the TIFF photometric interpreter used for mapping + * floating-point values to a color palette. + */ +public class PhotometricInterpreterFloatTest { + + private static PhotometricInterpreterFloat pInterp; + private static PhotometricInterpreterFloat bandedInterp; + private static ImageBuilder imageBuilder; + private static ImageBuilder bandedImageBuilder; + + private static final Color orange = new Color(255, 136, 62); + private static final Color green = new Color(22, 155, 98); + + public PhotometricInterpreterFloatTest() { + } + + @BeforeAll + public static void setUpClass() throws ImageWriteException, ImageReadException, IOException { + // the setup is to assign color (grayscale) values to the + // pixels along the main diagonal at coordinates + // (0, 0), (1, 1), ... (256, 256). + // The floating point values at each pixel are just the + // index divided by 256. + + List<IPaletteEntry> paletteList = new ArrayList<>(); + List<IPaletteEntry> reverseList = new ArrayList<>(); + for (int i = 0; i < 256; i += 32) { + int i1 = i + 31; + float f0 = (float) i / 256f; + float f1 = (float) (i + 32) / 256f; + int argb0 = 0xff000000 | (i << 8) | i; + int argb1 = 0xff000000 | (i1 << 8) | i; + Color c0 = new Color(argb0); + Color c1 = new Color(argb1); + PaletteEntryForRange entry = new PaletteEntryForRange(f0, f1, c0, c1); + paletteList.add(entry); + } + // The interpreter is supposed to sort entries. To test that, + // we copy them to a list in reverse order. + for (int i = paletteList.size() - 1; i >= 0; i--) { + IPaletteEntry entry = paletteList.get(i); + reverseList.add(entry); + } + + pInterp = new PhotometricInterpreterFloat(reverseList); + + // pre-populate the state data for the interpreter with + // some values so that we can test min/max access methods. + imageBuilder = new ImageBuilder(257, 257, false); + int[] samples = new int[1]; + for (int i = 0; i <= 256; i++) { + float f = (float) i / 256f; + samples[0] = Float.floatToRawIntBits(f); + pInterp.interpretPixel(imageBuilder, samples, i, i); + } + + // Now set up a palette than maps values in a range to a single color. + List<IPaletteEntry> bandedPaletteList = new ArrayList<>(); + bandedPaletteList.add(new PaletteEntryForRange(0f, 0.33f, green)); + bandedPaletteList.add(new PaletteEntryForRange(0.33f, 0.66f, Color.white)); + bandedPaletteList.add(new PaletteEntryForRange(0.66f, 1.0f, orange)); + bandedPaletteList.add(new PaletteEntryForValue(Float.NaN, Color.gray)); + bandedPaletteList.add(new PaletteEntryForValue(-1, Color.gray)); + bandedInterp = new PhotometricInterpreterFloat(bandedPaletteList); + bandedImageBuilder = new ImageBuilder(300, 200, false); + for (int j = 0; j < 300; j++) { + float f = (float) j / 299.0f; + samples[0] = Float.floatToRawIntBits(f); + for (int i = 0; i < 200; i++) { + bandedInterp.interpretPixel(bandedImageBuilder, samples, j, i); + } + } + samples[0] = Float.floatToRawIntBits(Float.NaN); + for (int i = 0; i < 200; i++) { + bandedInterp.interpretPixel(bandedImageBuilder, samples, 0, i); + bandedInterp.interpretPixel(bandedImageBuilder, samples, 299, i); + } + samples[0] = Float.floatToRawIntBits(-1); + for (int i = 0; i < 300; i++) { + bandedInterp.interpretPixel(bandedImageBuilder, samples, i, 0); + bandedInterp.interpretPixel(bandedImageBuilder, samples, i, 199); + } + } + + /** + * Test of interpretPixel method, of class PhotometricInterpreterFloat. + */ + @Test + public void testInterpretPixel() { + for (int i = 0; i < 256; i++) { + int lowTest = (i / 32) * 32; + int argb = imageBuilder.getRGB(i, i); + int b = argb & 0xff; + assertEquals(b, lowTest, "Invalid conversion for level " + i); + } + + // nothing should match the i=256 case. + // The last entry in the palette has values + // in the range 224.0/256.0 <= value < 256.0/256.0. So when it + // was rendered, there was not palette entry that matched it, + // and the corresponding pixel was set to zero. + int argb = imageBuilder.getRGB(256, 256); + assertEquals(argb, 0, "Invalid upper-bound test"); + + // Now inspect the banded palette case + argb = bandedImageBuilder.getRGB(0, 0); + assertEquals(Color.gray.getRGB(), argb, "Invalid mapping of NaN"); + argb = bandedImageBuilder.getRGB(50, 10); + assertEquals(green.getRGB(), argb, "Invalid mapping of green range"); + argb = bandedImageBuilder.getRGB(150, 10); + assertEquals(Color.white.getRGB(), argb, "Invalid mapping of white range"); + argb = bandedImageBuilder.getRGB(250, 10); + assertEquals(orange.getRGB(), argb, "Invalid mapping of orange range"); + // Example code to write image to PNG file for visual inspection. + //try { + // BufferedImage bImage = bandedImageBuilder.getBufferedImage(); + // ImageIO.write(bImage, "PNG", new File("C:/Users/Public/test1.png")); + //} catch (IOException ioex) { + // fail("IOException saving test image" + ioex.getMessage()); + //} Review comment: Do we need the example code in this test? Asking because we had a big review/refactoring during the 0.9 to 1.0 vote thread, and many of the reviews/changes requested were around things like commented code that wasn't working after some recent changes. But we can leave it here if that's useful for another developer maintaining this test. ########## File path: src/main/java/org/apache/commons/imaging/formats/tiff/TiffRasterData.java ########## @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.imaging.formats.tiff; + +/** + * Provides a simple container for floating-point data. Some TIFF files are used + * to store floating-point data rather than images. This class is intended to + * support access to those TIFF files. + */ +public class TiffRasterData { + + + private final int width; + private final int height; + private final float[] data; + + /** + * Construct an instance allocating memory for the specified dimensions. + * + * @param width a value of 1 or greater + * @param height a value of 1 or greater + */ + public TiffRasterData(int width, int height) { + if (width <= 0 || height <= 0) { + throw new IllegalArgumentException( + "Raster dimensions less than or equal to zero are not supported"); + } + int nCells = width * height; + data = new float[nCells]; + this.width = width; + this.height = height; + + } + + /** + * Construct an instance allocating memory for the specified dimensions. + * + * @param width a value of 1 or greater + * @param height a value of 1 or greater + * @param data the data to be stored in the raster. + */ + public TiffRasterData(int width, int height, float[] data) { + if (width <= 0 || height <= 0) { + throw new IllegalArgumentException( + "Raster dimensions less than or equal to zero are not supported"); + } + if (data == null || data.length < width * height) { + throw new IllegalArgumentException( + "Specified data does not contain sufficient elements"); + } + this.width = width; + this.height = height; + this.data = data; + + } + + /** + * Sets the value stored at the specified raster coordinates. + * + * @param x integer coordinate in the columnar direction + * @param y integer coordinate in the row direction + * @param value the value to be stored at the specified location; + * potentially a Float.NaN. + */ + public void setValue(int x, int y, float value) { + if (x < 0 || x >= width || y < 0 || y >= height) { + throw new IllegalArgumentException( + "Coordinates out of range (" + x + ", " + y + ")"); + } + data[y * width + x] = value; + } + + /** + * Gets the value stored at the specified raster coordinates. + * + * @param x integer coordinate in the columnar direction + * @param y integer coordinate in the row direction + * @return the value stored at the specified location; potentially a + * Float.NaN. + */ + public float getValue(int x, int y) { + if (x < 0 || x >= width || y < 0 || y >= height) { + throw new IllegalArgumentException( + "Coordinates out of range (" + x + ", " + y + ")"); + } + return data[y * width + x]; + } + + /** + * Tabulates simple statistics for the raster and returns an instance + * containing general metadata. + * + * @return a valid instance. + */ + public TiffRasterStatistics getSimpleStatistics() { + return new TiffRasterStatistics(this, Float.NaN); + } + + /** + * Tabulates simple statistics for the raster excluding the specified value + * and returns an instance containing general metadata, Review comment: s/,/. ########## File path: src/main/java/org/apache/commons/imaging/formats/tiff/TiffRasterData.java ########## @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.imaging.formats.tiff; + +/** + * Provides a simple container for floating-point data. Some TIFF files are used + * to store floating-point data rather than images. This class is intended to + * support access to those TIFF files. + */ +public class TiffRasterData { + + + private final int width; + private final int height; + private final float[] data; + + /** + * Construct an instance allocating memory for the specified dimensions. + * + * @param width a value of 1 or greater + * @param height a value of 1 or greater + */ + public TiffRasterData(int width, int height) { + if (width <= 0 || height <= 0) { + throw new IllegalArgumentException( + "Raster dimensions less than or equal to zero are not supported"); + } + int nCells = width * height; + data = new float[nCells]; + this.width = width; + this.height = height; + + } + + /** + * Construct an instance allocating memory for the specified dimensions. + * + * @param width a value of 1 or greater + * @param height a value of 1 or greater + * @param data the data to be stored in the raster. + */ + public TiffRasterData(int width, int height, float[] data) { + if (width <= 0 || height <= 0) { + throw new IllegalArgumentException( + "Raster dimensions less than or equal to zero are not supported"); + } + if (data == null || data.length < width * height) { + throw new IllegalArgumentException( + "Specified data does not contain sufficient elements"); + } + this.width = width; + this.height = height; + this.data = data; + + } + + /** + * Sets the value stored at the specified raster coordinates. + * + * @param x integer coordinate in the columnar direction + * @param y integer coordinate in the row direction + * @param value the value to be stored at the specified location; + * potentially a Float.NaN. + */ + public void setValue(int x, int y, float value) { + if (x < 0 || x >= width || y < 0 || y >= height) { + throw new IllegalArgumentException( + "Coordinates out of range (" + x + ", " + y + ")"); + } + data[y * width + x] = value; + } + + /** + * Gets the value stored at the specified raster coordinates. + * + * @param x integer coordinate in the columnar direction + * @param y integer coordinate in the row direction + * @return the value stored at the specified location; potentially a + * Float.NaN. + */ + public float getValue(int x, int y) { + if (x < 0 || x >= width || y < 0 || y >= height) { + throw new IllegalArgumentException( + "Coordinates out of range (" + x + ", " + y + ")"); + } + return data[y * width + x]; + } + + /** + * Tabulates simple statistics for the raster and returns an instance + * containing general metadata. + * + * @return a valid instance. + */ + public TiffRasterStatistics getSimpleStatistics() { + return new TiffRasterStatistics(this, Float.NaN); + } + + /** + * Tabulates simple statistics for the raster excluding the specified value + * and returns an instance containing general metadata, + * + * @param valueToExclude exclude samples with this specified value. + * @return a valid instance. + */ + public TiffRasterStatistics getSimpleStatistics(float valueToExclude) { + return new TiffRasterStatistics(this, valueToExclude); + } + + /** + * Gets the width (number of columns) of the raster. + * + * @return the width of the raster + */ + public int getWidth() { + return width; + } + + /** + * Gets the height (number of rows) of the raster. + * + * @return the height of the raster. + */ + public int getHeight() { + return height; + } + + /** + * Returns a reference to the data array stored in this instance. Note that + * value is <strong>not</strong> a safe copy and that modifying it would + * directly affect the content of the instance. While this design approach + * carries some risk in terms of data security, it was chosen for reasons of + * performance and memory conservation. + * + * @return a direct reference to the data array stored in this instance. + */ + public float[] getData() { + return data; Review comment: Would returning a copy of the data be a problem? Is it the array of the complete image? We could offer this method, telling users to use it at their own risk too, while avoiding possible bugs (security or simple bugs due to changes in this array?) ########## File path: src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderStrips.java ########## @@ -14,6 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + + /* + * Implementation notes: + * See ImageDataReader for notes on development + * with particular emphasis on run-time performance. + */ Review comment: I think this comment could go above the class declaration, and maybe use the @link or @see, etc Javadocs annotations? ########## File path: src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderTiled.java ########## @@ -235,4 +286,59 @@ public BufferedImage readImageData(final Rectangle subImage) subImage.height); } + @Override + public TiffRasterData readRasterData(final Rectangle subImage) + throws ImageReadException, IOException { + final int bitsPerRow = tileWidth * bitsPerPixel; + final int bytesPerRow = (bitsPerRow + 7) / 8; + final int bytesPerTile = bytesPerRow * tileLength; + int xRaster; + int yRaster; + int rasterWidth; + int rasterHeight; + if (subImage != null) { + xRaster = subImage.x; + yRaster = subImage.y; + rasterWidth = subImage.width; + rasterHeight = subImage.height; + } else { + xRaster = 0; + yRaster = 0; + rasterWidth = width; + rasterHeight = height; + } + float[] rasterData = new float[rasterWidth * rasterHeight]; + + // tileWidth is the width of the tile + // tileLength is the height of the tile + final int col0 = xRaster / tileWidth; + final int col1 = (xRaster + rasterWidth - 1) / tileWidth; Review comment: Ditto the above here about the division by zero. ########## File path: src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/DataReaderStrips.java ########## @@ -285,4 +324,57 @@ public BufferedImage readImageData(final Rectangle subImage) subImage.height); } + @Override + public TiffRasterData readRasterData(Rectangle subImage) + throws ImageReadException, IOException { + + int xRaster; + int yRaster; + int rasterWidth; + int rasterHeight; + if (subImage != null) { + xRaster = subImage.x; + yRaster = subImage.y; + rasterWidth = subImage.width; + rasterHeight = subImage.height; + } else { + xRaster = 0; + yRaster = 0; + rasterWidth = width; + rasterHeight = height; + } + float[] rasterData = new float[rasterWidth * rasterHeight]; + + // the legacy code is optimized to the reading of whole + // strips (except for the last strip in the image, which can + // be a partial). So create a working image with compatible + // dimensions and read that. Later on, the working image + // will be sub-imaged to the proper size. + // strip0 and strip1 give the indices of the strips containing + // the first and last rows of pixels in the subimage + final int strip0 = yRaster / rowsPerStrip; Review comment: Any change—even if remote—that `rowsPerStrip` could be zero? One of the reasons why 1.0-alpha1 took so long (couple years after the work started?) was largely due to CVE's created for sanselan. One of the CVE, if I am not mistaken, was about a division by zero (or another sort of arithmetic error?), that caused an exception and some infinite loop or large memory allocation (allowing users to perform DDOS). If it's never zero, then no need to worry. Otherwise, if there's any risk, better set a quick validation somewhere (here or constructor). ########## File path: src/main/java/org/apache/commons/imaging/formats/tiff/photometricinterpreters/fp/PaletteEntryForRange.java ########## @@ -0,0 +1,175 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.imaging.formats.tiff.photometricinterpreters.fp; Review comment: I am really bad with names. But I wonder if we could find an alternative for `fp`. See its parent package as example, `photometricinterpreters`. It could be `pi` too, but `tiff.pi.fp` looks even more enigmatic. @gwlucastrig could we use some different name, easier for users/devs to know what's that package for/about? ########## File path: src/main/java/org/apache/commons/imaging/formats/tiff/photometricinterpreters/fp/PaletteEntryForRange.java ########## @@ -0,0 +1,175 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.imaging.formats.tiff.photometricinterpreters.fp; + +import java.awt.Color; + +/** + * Provides a palette entry for colors associated with a range of values. The + * return value will be interpolated between the minimum and maximum value for + * this entry. + * <p> + * In keeping with the conventions of many Geographic Information Systems (GIS) + * and art applications, this instance "covered" values in the range v0 ≤ f + * < v1. Thus, a value that exactly matches the upper bound of the range is + * not considered "covered". + */ +public class PaletteEntryForRange implements IPaletteEntry { + + private final float v0; + private final float v1; + private final float deltaV; + private final float r0; + private final float r1; + private final float g0; + private final float g1; + private final float b0; + private final float b1; + private final float a0; + private final float a1; + private final float deltaA; + private final float deltaR; + private final float deltaG; + private final float deltaB; Review comment: Probably nit-picking. I think the variables above are related to variable1, variable0, red1, red2, green1, green2, etc. But could be wrong. In case these variables appear somewhere like debugger/profiler/log/stacktrace/etc, it would be better to have a better name I think. Is it something that could be changed @gwlucastrig ? (I acknowledge sometimes the best name is the simplest like these, so just asking if you have any suggestion that could make it easier for other contributors) Maybe as we are talking about range, the v0 and v1 could be left, right. Or from, to. Or fromInclusive, toInclusive, etc. Something that is easy for another developer used to other "ranges" to associate with? ########## File path: src/main/java/org/apache/commons/imaging/formats/tiff/photometricinterpreters/fp/PaletteEntryForValue.java ########## @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.imaging.formats.tiff.photometricinterpreters.fp; + +import java.awt.Color; + +/** + * Provides a palette entry for a color assignment to a single value. This class + * will assign a color to a value only if it is an exact match for the input. + * This class will also support Float.NaN + */ +public class PaletteEntryForValue implements IPaletteEntry { + + private final float value; + private final int iColor; + private final Color color; + private boolean isNull; + + /** + * Constructs a palette entry for a single value. + * <p> + * This class will support color-assignments for Float.NaN. + * + * @param value the color value associated with this palette entry; a + * Float.NaN is allowed. + * @param color the color assigned to value + */ + public PaletteEntryForValue(float value, Color color) { + if (color == null) { + throw new IllegalArgumentException("Null colors not allowed"); + } + this.value = value; + this.color = color; + this.iColor = color.getRGB(); + isNull = Float.isNaN(value); + + } + + @Override + public boolean isCovered(float f) { + if (isNull) { + return Float.isNaN(f); + } + return f == value; + } + + @Override + public int getARGB(float f) { + if (isNull) { + if (Float.isNaN(f)) { + return iColor; + } + } else { + if (f == value) { + return iColor; + } + } + return 0; + } + + @Override + public Color getColor(float f) { + if (isNull) { + if (Float.isNaN(f)) { + return color; + } + } else { + if (f == value) { + return color; + } + } Review comment: Simplify expression above? ########## File path: src/main/java/org/apache/commons/imaging/formats/tiff/photometricinterpreters/fp/PaletteEntryForValue.java ########## @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.imaging.formats.tiff.photometricinterpreters.fp; + +import java.awt.Color; + +/** + * Provides a palette entry for a color assignment to a single value. This class + * will assign a color to a value only if it is an exact match for the input. + * This class will also support Float.NaN + */ +public class PaletteEntryForValue implements IPaletteEntry { + + private final float value; + private final int iColor; + private final Color color; + private boolean isNull; + + /** + * Constructs a palette entry for a single value. + * <p> + * This class will support color-assignments for Float.NaN. + * + * @param value the color value associated with this palette entry; a + * Float.NaN is allowed. + * @param color the color assigned to value + */ + public PaletteEntryForValue(float value, Color color) { + if (color == null) { + throw new IllegalArgumentException("Null colors not allowed"); + } + this.value = value; + this.color = color; + this.iColor = color.getRGB(); + isNull = Float.isNaN(value); + + } + + @Override + public boolean isCovered(float f) { + if (isNull) { + return Float.isNaN(f); + } + return f == value; + } + + @Override + public int getARGB(float f) { + if (isNull) { + if (Float.isNaN(f)) { + return iColor; + } + } else { + if (f == value) { + return iColor; + } + } Review comment: ``` if (isNull && Float.isNaN(f)) { return iColor; } else if (f == value) { return iColor; } ``` ? ########## File path: src/main/java/org/apache/commons/imaging/formats/tiff/TiffRasterData.java ########## @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.imaging.formats.tiff; + +/** + * Provides a simple container for floating-point data. Some TIFF files are used + * to store floating-point data rather than images. This class is intended to + * support access to those TIFF files. + */ +public class TiffRasterData { + + + private final int width; + private final int height; Review comment: Would it make sense call these two `columns` and `rows` instead? Asking because I noticed the other docs appear to treat them as such. Happy with either option :+1: ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
