You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/02/22 22:26:53 UTC
(commons-imaging) 09/09: Internal renames
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-imaging.git
commit a4294247b1b06194f27a5678f84f22924b1d146d
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 22 17:26:38 2025 -0500
Internal renames
Remove vertical space
---
.../{InfoHeaderReader.java => InfoHeader.java} | 14 +++----
.../commons/imaging/formats/rgbe/RgbeInfo.java | 45 +++++-----------------
2 files changed, 16 insertions(+), 43 deletions(-)
diff --git a/src/main/java/org/apache/commons/imaging/formats/rgbe/InfoHeaderReader.java b/src/main/java/org/apache/commons/imaging/formats/rgbe/InfoHeader.java
similarity index 86%
rename from src/main/java/org/apache/commons/imaging/formats/rgbe/InfoHeaderReader.java
rename to src/main/java/org/apache/commons/imaging/formats/rgbe/InfoHeader.java
index be329e72..ae729c24 100644
--- a/src/main/java/org/apache/commons/imaging/formats/rgbe/InfoHeaderReader.java
+++ b/src/main/java/org/apache/commons/imaging/formats/rgbe/InfoHeader.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.commons.imaging.formats.rgbe;
import java.io.IOException;
@@ -21,14 +22,15 @@ import java.io.InputStream;
import org.apache.commons.imaging.ImagingException;
-final class InfoHeaderReader {
+final class InfoHeader {
+
private final InputStream is;
- InfoHeaderReader(final InputStream is) {
+ InfoHeader(final InputStream is) {
this.is = is;
}
- private char read() throws IOException {
+ private char readChar() throws IOException {
final int result = is.read();
if (result < 0) {
throw new ImagingException("HDR: Unexpected EOF");
@@ -36,14 +38,12 @@ final class InfoHeaderReader {
return (char) result;
}
- public String readNextLine() throws IOException {
+ String line() throws IOException {
final StringBuilder buffer = new StringBuilder();
char c;
-
- while ((c = read()) != '\n') {
+ while ((c = readChar()) != '\n') {
buffer.append(c);
}
-
return buffer.toString();
}
}
diff --git a/src/main/java/org/apache/commons/imaging/formats/rgbe/RgbeInfo.java b/src/main/java/org/apache/commons/imaging/formats/rgbe/RgbeInfo.java
index e696c0e6..5af39727 100644
--- a/src/main/java/org/apache/commons/imaging/formats/rgbe/RgbeInfo.java
+++ b/src/main/java/org/apache/commons/imaging/formats/rgbe/RgbeInfo.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.commons.imaging.formats.rgbe;
import java.io.Closeable;
@@ -32,26 +33,22 @@ import org.apache.commons.imaging.common.GenericImageMetadata;
import org.apache.commons.imaging.common.ImageMetadata;
final class RgbeInfo implements Closeable {
+
// #?RADIANCE
private static final byte[] HEADER = { 0x23, 0x3F, 0x52, 0x41, 0x44, 0x49, 0x41, 0x4E, 0x43, 0x45 };
private static final Pattern RESOLUTION_STRING = Pattern.compile("-Y (\\d+) \\+X (\\d+)");
-
private static final byte[] TWO_TWO = { 0x2, 0x2 };
private static void decompress(final InputStream in, final byte[] out) throws IOException, ImagingException {
int position = 0;
final int total = out.length;
-
while (position < total) {
final int n = in.read();
-
if (n < 0) {
throw new ImagingException("Error decompressing RGBE file");
}
-
if (n > 128) {
final int value = in.read();
-
for (int i = 0; i < (n & 0x7f); i++) {
out[position++] = (byte) value;
}
@@ -66,7 +63,6 @@ final class RgbeInfo implements Closeable {
private final InputStream in;
private GenericImageMetadata metadata;
private int width = -1;
-
private int height = -1;
RgbeInfo(final ByteSource byteSource) throws IOException {
@@ -82,7 +78,6 @@ final class RgbeInfo implements Closeable {
if (-1 == height) {
readDimensions();
}
-
return height;
}
@@ -90,38 +85,30 @@ final class RgbeInfo implements Closeable {
if (null == metadata) {
readMetadata();
}
-
return metadata;
}
- public float[][] getPixelData() throws IOException, ImagingException {
+ float[][] getPixelData() throws IOException, ImagingException {
// Read into local variables to ensure that we have seeked into the file
// far enough
final int ht = getHeight();
final int wd = getWidth();
-
if (wd >= 32768) {
throw new ImagingException("Scan lines must be less than 32768 bytes long");
}
-
final byte[] scanLineBytes = ByteConversions.toBytes((short) wd, ByteOrder.BIG_ENDIAN);
final byte[] rgbe = Allocator.byteArray(wd * 4);
final float[][] out = new float[3][Allocator.check(wd * ht)];
-
for (int i = 0; i < ht; i++) {
BinaryFunctions.readAndVerifyBytes(in, TWO_TWO, "Scan line " + i + " expected to start with 0x2 0x2");
BinaryFunctions.readAndVerifyBytes(in, scanLineBytes, "Scan line " + i + " length expected");
-
decompress(in, rgbe);
-
for (int channel = 0; channel < 3; channel++) {
final int channelOffset = channel * wd;
final int eOffset = 3 * wd;
-
for (int p = 0; p < wd; p++) {
final int mantissa = rgbe[p + eOffset] & 0xff;
final int pos = p + i * wd;
-
if (0 == mantissa) {
out[channel][pos] = 0;
} else {
@@ -131,7 +118,6 @@ final class RgbeInfo implements Closeable {
}
}
}
-
return out;
}
@@ -139,55 +125,42 @@ final class RgbeInfo implements Closeable {
if (-1 == width) {
readDimensions();
}
-
return width;
}
private void readDimensions() throws IOException, ImagingException {
getMetadata(); // Ensure we've read past this
-
- final InfoHeaderReader reader = new InfoHeaderReader(in);
- final String resolution = reader.readNextLine();
+ final InfoHeader header = new InfoHeader(in);
+ final String resolution = header.line();
final Matcher matcher = RESOLUTION_STRING.matcher(resolution);
-
if (!matcher.matches()) {
throw new ImagingException("Invalid HDR resolution string. Only \"-Y N +X M\" is supported. Found \"" + resolution + "\"");
}
-
height = Integer.parseInt(matcher.group(1));
width = Integer.parseInt(matcher.group(2));
}
private void readMetadata() throws IOException, ImagingException {
BinaryFunctions.readAndVerifyBytes(in, HEADER, "Not a valid HDR: Incorrect Header");
-
- final InfoHeaderReader reader = new InfoHeaderReader(in);
-
- if (!reader.readNextLine().isEmpty()) {
+ final InfoHeader reader = new InfoHeader(in);
+ if (!reader.line().isEmpty()) {
throw new ImagingException("Not a valid HDR: Incorrect Header");
}
-
metadata = new GenericImageMetadata();
-
- String info = reader.readNextLine();
-
+ String info = reader.line();
while (!info.isEmpty()) {
final int equals = info.indexOf('=');
-
if (equals > 0) {
final String variable = info.substring(0, equals);
final String value = info.substring(equals + 1);
-
if ("FORMAT".equals(value) && !"32-bit_rle_rgbe".equals(value)) {
throw new ImagingException("Only 32-bit_rle_rgbe images are supported, trying to read " + value);
}
-
metadata.add(variable, value);
} else {
metadata.add("<command>", info);
}
-
- info = reader.readNextLine();
+ info = reader.line();
}
}
}