Skip to content

Commit

Permalink
2.0.2 release
Browse files Browse the repository at this point in the history
  • Loading branch information
bosborn committed Jul 10, 2020
1 parent e95ea0f commit 7af092b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 43 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ Adheres to [Semantic Versioning](http://semver.org/).

---

## 2.0.2 (TBD)
## [2.0.2](https://github.com/ngageoint/tiff-java/releases/tag/2.0.2) (07-10-2020)

* TBD
* Model pixel scale and model tiepoint retrieval methods
* Sample values byte buffer max capacity allocation check

## [2.0.1](https://github.com/ngageoint/tiff-java/releases/tag/2.0.1) (04-01-2019)

Expand Down
84 changes: 43 additions & 41 deletions src/main/java/mil/nga/tiff/FileDirectory.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public FileDirectory(SortedSet<FileDirectoryEntry> entries,
: TiffConstants.PLANAR_CONFIGURATION_CHUNKY;
if (planarConfiguration != TiffConstants.PLANAR_CONFIGURATION_CHUNKY
&& planarConfiguration != TiffConstants.PLANAR_CONFIGURATION_PLANAR) {
throw new TiffException("Invalid planar configuration: "
+ planarConfiguration);
throw new TiffException(
"Invalid planar configuration: " + planarConfiguration);
}

// Determine the decoder based upon the compression
Expand Down Expand Up @@ -194,7 +194,8 @@ public FileDirectory(Rasters rasters) {
* @param rasters
* image rasters to write
*/
public FileDirectory(SortedSet<FileDirectoryEntry> entries, Rasters rasters) {
public FileDirectory(SortedSet<FileDirectoryEntry> entries,
Rasters rasters) {
this.entries = entries;
for (FileDirectoryEntry entry : entries) {
fieldTagTypeMapping.put(entry.getFieldTag(), entry);
Expand Down Expand Up @@ -489,7 +490,8 @@ public void setStripOffsets(long stripOffset) {
* @since 2.0.0
*/
public int getSamplesPerPixel() {
Integer samplesPerPixel = getIntegerEntryValue(FieldTagType.SamplesPerPixel);
Integer samplesPerPixel = getIntegerEntryValue(
FieldTagType.SamplesPerPixel);
if (samplesPerPixel == null) {
// if SamplesPerPixel tag is missing, use default value defined by
// TIFF standard
Expand Down Expand Up @@ -691,6 +693,7 @@ public void setResolutionUnit(int resolutionUnit) {
* Get the model pixel scale
*
* @return model pixel scale
* @since 2.0.2
*/
public List<Double> getModelPixelScale() {
return getDoubleListEntryValue(FieldTagType.ModelPixelScale);
Expand All @@ -700,6 +703,7 @@ public List<Double> getModelPixelScale() {
* Get the model tiepoint
*
* @return model tiepoint
* @since 2.0.2
*/
public List<Double> getModelTiepoint() {
return getDoubleListEntryValue(FieldTagType.ModelTiepoint);
Expand Down Expand Up @@ -1093,9 +1097,8 @@ public Rasters readRasters(ImageWindow window, int[] samples,
// Validate the image window
if (window.getMinX() < 0 || window.getMinY() < 0
|| window.getMaxX() > width || window.getMaxY() > height) {
throw new TiffException(
"Window is out of the image bounds. Width: " + width
+ ", Height: " + height + ", Window: " + window);
throw new TiffException("Window is out of the image bounds. Width: "
+ width + ", Height: " + height + ", Window: " + window);
} else if (window.getMinX() > window.getMaxX()
|| window.getMinY() > window.getMaxY()) {
throw new TiffException("Invalid window range: " + window);
Expand All @@ -1115,8 +1118,8 @@ public Rasters readRasters(ImageWindow window, int[] samples,
} else {
for (int i = 0; i < samples.length; i++) {
if (samples[i] >= samplesPerPixel) {
throw new TiffException("Invalid sample index: "
+ samples[i]);
throw new TiffException(
"Invalid sample index: " + samples[i]);
}
}
}
Expand All @@ -1142,9 +1145,9 @@ public Rasters readRasters(ImageWindow window, int[] samples,
* Double.valueOf(bitsPerSample.get(i)) / 8;

if (numberOfBytes > Integer.MAX_VALUE) {
throw new TiffException("To allocate the sample result buffer array is "
+ "needed more than " + (Integer.MAX_VALUE / 1024 / 1024) + " "
+ "megaBytes.");
throw new TiffException(
"Number of sample value bytes is above max byte buffer capacity: "
+ numberOfBytes);
}

sample[i] = ByteBuffer.allocateDirect((int) numberOfBytes);
Expand Down Expand Up @@ -1177,7 +1180,8 @@ public Rasters readRasters(ImageWindow window, int[] samples,
* @param rasters
* rasters to populate
*/
private void readRaster(ImageWindow window, int[] samples, Rasters rasters) {
private void readRaster(ImageWindow window, int[] samples,
Rasters rasters) {

int tileWidth = getTileWidth().intValue();
int tileHeight = getTileHeight().intValue();
Expand Down Expand Up @@ -1220,14 +1224,13 @@ private void readRaster(ImageWindow window, int[] samples, Rasters rasters) {
ByteReader blockReader = new ByteReader(block,
reader.getByteOrder());

for (int y = Math.max(0, window.getMinY() - firstLine); y < Math
.min(tileHeight,
tileHeight - (lastLine - window.getMaxY())); y++) {
for (int y = Math.max(0, window.getMinY()
- firstLine); y < Math.min(tileHeight, tileHeight
- (lastLine - window.getMaxY())); y++) {

for (int x = Math.max(0, window.getMinX() - firstCol); x < Math
.min(tileWidth,
tileWidth
- (lastCol - window.getMaxX())); x++) {
for (int x = Math.max(0, window.getMinX()
- firstCol); x < Math.min(tileWidth, tileWidth
- (lastCol - window.getMaxX())); x++) {

int pixelOffset = (y * tileWidth + x)
* bytesPerPixel;
Expand All @@ -1240,19 +1243,16 @@ private void readRaster(ImageWindow window, int[] samples, Rasters rasters) {
sampleFieldTypes[sampleIndex]);

if (rasters.hasInterleaveValues()) {
int windowCoordinate = (y + firstLine - window
.getMinY())
* windowWidth
int windowCoordinate = (y + firstLine
- window.getMinY()) * windowWidth
+ (x + firstCol - window.getMinX());
rasters.addToInterleave(sampleIndex,
windowCoordinate, value);
}

if (rasters.hasSampleValues()) {
int windowCoordinate = (y + firstLine - window
.getMinY())
* windowWidth
+ x
int windowCoordinate = (y + firstLine
- window.getMinY()) * windowWidth + x
+ firstCol - window.getMinX();
rasters.addToSample(sampleIndex,
windowCoordinate, value);
Expand Down Expand Up @@ -1304,8 +1304,8 @@ private Number readValue(ByteReader reader, FieldType fieldType) {
value = reader.readDouble();
break;
default:
throw new TiffException("Unsupported raster field type: "
+ fieldType);
throw new TiffException(
"Unsupported raster field type: " + fieldType);
}

return value;
Expand All @@ -1321,7 +1321,8 @@ private Number readValue(ByteReader reader, FieldType fieldType) {
public FieldType getFieldTypeForSample(int sampleIndex) {

List<Integer> sampleFormatList = getSampleFormat();
int sampleFormat = sampleFormatList == null ? TiffConstants.SAMPLE_FORMAT_UNSIGNED_INT
int sampleFormat = sampleFormatList == null
? TiffConstants.SAMPLE_FORMAT_UNSIGNED_INT
: sampleFormatList
.get(sampleIndex < sampleFormatList.size() ? sampleIndex
: 0);
Expand Down Expand Up @@ -1359,8 +1360,8 @@ private byte[] getTileOrStrip(int x, int y, int sample) {
if (planarConfiguration == TiffConstants.PLANAR_CONFIGURATION_CHUNKY) {
index = y * numTilesPerRow + x;
} else if (planarConfiguration == TiffConstants.PLANAR_CONFIGURATION_PLANAR) {
index = sample * numTilesPerRow * numTilesPerCol + y
* numTilesPerRow + x;
index = sample * numTilesPerRow * numTilesPerCol
+ y * numTilesPerRow + x;
}

// Attempt to pull from the cache
Expand Down Expand Up @@ -1408,13 +1409,13 @@ private byte[] getTileOrStrip(int x, int y, int sample) {
private int getSampleByteSize(int sampleIndex) {
List<Integer> bitsPerSample = getBitsPerSample();
if (sampleIndex >= bitsPerSample.size()) {
throw new TiffException("Sample index " + sampleIndex
+ " is out of range");
throw new TiffException(
"Sample index " + sampleIndex + " is out of range");
}
int bits = bitsPerSample.get(sampleIndex);
if ((bits % 8) != 0) {
throw new TiffException("Sample bit-width of " + bits
+ " is not supported");
throw new TiffException(
"Sample bit-width of " + bits + " is not supported");
}
return (bits / 8);
}
Expand All @@ -1432,8 +1433,8 @@ private int getBytesPerPixel() {
for (int i = 0; i < bitsPerSamples.size(); i++) {
int bits = bitsPerSamples.get(i);
if ((bits % 8) != 0) {
throw new TiffException("Sample bit-width of " + bits
+ " is not supported");
throw new TiffException(
"Sample bit-width of " + bits + " is not supported");
} else if (bits != bitsPerSamples.get(0)) {
throw new TiffException(
"Differing size of samples in a pixel are not supported. sample 0 = "
Expand Down Expand Up @@ -1492,7 +1493,8 @@ public Number getNumberEntryValue(FieldTagType fieldTagType) {
* unsigned long value (32 bit)
* @since 2.0.0
*/
public void setUnsignedLongEntryValue(FieldTagType fieldTagType, long value) {
public void setUnsignedLongEntryValue(FieldTagType fieldTagType,
long value) {
setEntryValue(fieldTagType, FieldType.LONG, 1, value);
}

Expand Down Expand Up @@ -1525,7 +1527,8 @@ public String getStringEntryValue(FieldTagType fieldTagType) {
public void setStringEntryValue(FieldTagType fieldTagType, String value) {
List<String> values = new ArrayList<>();
values.add(value);
setEntryValue(fieldTagType, FieldType.ASCII, value.length() + 1, values);
setEntryValue(fieldTagType, FieldType.ASCII, value.length() + 1,
values);
}

/**
Expand All @@ -1552,7 +1555,6 @@ public List<Double> getDoubleListEntryValue(FieldTagType fieldTagType) {
return getEntryValue(fieldTagType);
}


/**
* Set an unsigned integer list of values for the field tag type
*
Expand Down

0 comments on commit 7af092b

Please sign in to comment.