From 7e660b0f450a1da0f6ef76a132c00705337c0450 Mon Sep 17 00:00:00 2001 From: gwlucastrig Date: Mon, 15 Jan 2024 11:42:00 -0500 Subject: [PATCH] Issue 105: Enhance SVM to write GeoTIFF files --- .../gis/geotiff/GeoTiffTableBuilder.java | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/gis/src/main/java/org/tinfour/gis/geotiff/GeoTiffTableBuilder.java b/gis/src/main/java/org/tinfour/gis/geotiff/GeoTiffTableBuilder.java index ba0fdcd..ab21053 100644 --- a/gis/src/main/java/org/tinfour/gis/geotiff/GeoTiffTableBuilder.java +++ b/gis/src/main/java/org/tinfour/gis/geotiff/GeoTiffTableBuilder.java @@ -42,17 +42,17 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.zip.Deflater; import org.apache.commons.imaging.ImageWriteException; import org.apache.commons.imaging.PixelDensity; import org.apache.commons.imaging.common.RationalNumber; -import org.apache.commons.imaging.common.mylzw.MyLzwCompressor; import org.apache.commons.imaging.formats.tiff.TiffElement; import org.apache.commons.imaging.formats.tiff.TiffImageData; import static org.apache.commons.imaging.formats.tiff.constants.GdalLibraryTagConstants.EXIF_TAG_GDAL_NO_DATA; import org.apache.commons.imaging.formats.tiff.constants.GeoTiffTagConstants; import static org.apache.commons.imaging.formats.tiff.constants.GeoTiffTagConstants.EXIF_TAG_MODEL_PIXEL_SCALE_TAG; import static org.apache.commons.imaging.formats.tiff.constants.GeoTiffTagConstants.EXIF_TAG_MODEL_TIEPOINT_TAG; -import static org.apache.commons.imaging.formats.tiff.constants.TiffConstants.TIFF_COMPRESSION_LZW; +import static org.apache.commons.imaging.formats.tiff.constants.TiffConstants.TIFF_COMPRESSION_DEFLATE_ADOBE; import static org.apache.commons.imaging.formats.tiff.constants.TiffConstants.TIFF_COMPRESSION_UNCOMPRESSED; import org.apache.commons.imaging.formats.tiff.constants.TiffTagConstants; import static org.apache.commons.imaging.formats.tiff.constants.TiffTagConstants.PLANAR_CONFIGURATION_VALUE_CHUNKY; @@ -423,29 +423,29 @@ public byte[] encodeBlock(float[] f, int nRows, int scanSize) { b[aOffset + i] = (byte) ((b[aOffset + i] & 0xff) - (b[aOffset + i - 1] & 0xff)); } } - - try { - final int LZW_MINIMUM_CODE_SIZE = 8; - MyLzwCompressor compressor = new MyLzwCompressor( - LZW_MINIMUM_CODE_SIZE, ByteOrder.BIG_ENDIAN, true); - final byte[] compressed = compressor.compress(b); - return compressed; - } catch (IOException iex) { - return null; - } - // - // // apply the Deflate - // Deflater deflater = new Deflater(6); - // deflater.setInput(b, 0, b.length); - // deflater.finish(); - // byte[] deflaterResult = new byte[b.length + 1024]; - // int dN = deflater.deflate(deflaterResult, 0, deflaterResult.length, Deflater.FULL_FLUSH); - // if (dN <= 0) { - // // deflate failed - // return null; - // } - // return Arrays.copyOf(deflaterResult, dN); + // try { + // final int LZW_MINIMUM_CODE_SIZE = 8; + // MyLzwCompressor compressor = new MyLzwCompressor( + // LZW_MINIMUM_CODE_SIZE, ByteOrder.BIG_ENDIAN, true); + // final byte[] compressed = compressor.compress(b); + // return compressed; + // } catch (IOException iex) { + // return null; + // } + + + // apply the Deflate compression technique + Deflater deflater = new Deflater(6); + deflater.setInput(b, 0, b.length); + deflater.finish(); + byte[] deflaterResult = new byte[b.length + 1024]; + int dN = deflater.deflate(deflaterResult, 0, deflaterResult.length, Deflater.FULL_FLUSH); + if (dN <= 0) { + // deflate failed + return null; + } + return Arrays.copyOf(deflaterResult, dN); } /** @@ -468,8 +468,8 @@ public void writeTiles(File geoTiffFile, int width, int height, int tileSize, by short planarConfiguration; if (compressionEnabled) { - //compression = TIFF_COMPRESSION_DEFLATE_ADOBE; - compression = TIFF_COMPRESSION_LZW; + compression = TIFF_COMPRESSION_DEFLATE_ADOBE; + //compression = TIFF_COMPRESSION_LZW; } else { compression = TIFF_COMPRESSION_UNCOMPRESSED; }