diff --git a/.travis.yml b/.travis.yml index cff3613..921a18f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,4 @@ language: java jdk: - - oraclejdk8 - - oraclejdk9 - - openjdk7 - - openjdk8 + - oraclejdk11 + - openjdk11 diff --git a/pom.xml b/pom.xml index 28c6b7a..0a0d3e9 100644 --- a/pom.xml +++ b/pom.xml @@ -38,8 +38,8 @@ maven-compiler-plugin 3.7.0 - 1.6 - 1.6 + 11 + 11 @@ -172,7 +172,7 @@ - -Xdoclint:none + none true true diff --git a/src/main/java/com/github/jaiimageio/impl/common/ImageUtil.java b/src/main/java/com/github/jaiimageio/impl/common/ImageUtil.java index effc383..ddff742 100644 --- a/src/main/java/com/github/jaiimageio/impl/common/ImageUtil.java +++ b/src/main/java/com/github/jaiimageio/impl/common/ImageUtil.java @@ -154,7 +154,7 @@ public static void main(String[] args) { * *

An instance of IndexColorModel will be created for * instances of MultiPixelPackedSampleModel. The colormap - * will be a grayscale ramp with 1 << numberOfBits + * will be a grayscale ramp with 1 << numberOfBits * entries ranging from zero to at most 255.

* * @return An instance of ColorModel that is suitable for @@ -1057,8 +1057,8 @@ public static long getBandSize(SampleModel sm) { /** * Tests whether the color indices represent a gray-scale image with * the indicated number of bits over the color component range [0,255]. - * The grayscale mapping may be inverted, i.e., 0 -> 255 and - * mapSize -> 0. + * The grayscale mapping may be inverted, i.e., 0 -> 255 and + * mapSize -> 0. * * @param icm The gray-to-color mapping. * @return Whether the IndexColorModel maps index diff --git a/src/main/java/com/github/jaiimageio/impl/plugins/tiff/TIFFImageWriter.java b/src/main/java/com/github/jaiimageio/impl/plugins/tiff/TIFFImageWriter.java index 9644889..b77c66a 100644 --- a/src/main/java/com/github/jaiimageio/impl/plugins/tiff/TIFFImageWriter.java +++ b/src/main/java/com/github/jaiimageio/impl/plugins/tiff/TIFFImageWriter.java @@ -240,7 +240,7 @@ public class TIFFImageWriter extends ImageWriter { * relative to a given tile grid layout specified by its X offset * and tile width. * - *

If tileWidth < 0, the results of this method + *

If tileWidth < 0, the results of this method * are undefined. If tileWidth == 0, an * ArithmeticException will be thrown. * @@ -259,7 +259,7 @@ public static int XToTileX(int x, int tileGridXOffset, int tileWidth) { * relative to a given tile grid layout specified by its Y offset * and tile height. * - *

If tileHeight < 0, the results of this method + *

If tileHeight < 0, the results of this method * are undefined. If tileHeight == 0, an * ArithmeticException will be thrown. * @@ -1717,7 +1717,8 @@ private int writeTile(Rectangle tileRect, TIFFCompressor compressor) SampleModel sm = image.getSampleModel(); // Read only data from the active rectangle. - Raster raster = image.getData(activeRect); + Raster raster = image instanceof BufferedImage ? ((BufferedImage) image).getRaster() + : image.getData(activeRect); // If padding is required, create a larger Raster and fill // it from the active rectangle. @@ -1780,14 +1781,11 @@ private int writeTile(Rectangle tileRect, TIFFCompressor compressor) return compressor.encode(buf, 0, width, height, sampleSize, (tileRect.width + 7)/8); - } else if(bitDepth == 8 && - sm.getDataType() == DataBuffer.TYPE_BYTE) { + } else if(bitDepth == DataBuffer.getDataTypeSize(sm.getDataType())) { + ComponentSampleModel csm = (ComponentSampleModel)raster.getSampleModel(); - byte[] buf = - ((DataBufferByte)raster.getDataBuffer()).getData(); - int off = csm.getOffset(minX - raster.getSampleModelTranslateX(), @@ -1798,7 +1796,7 @@ private int writeTile(Rectangle tileRect, TIFFCompressor compressor) System.out.println("Optimized component case"); } - return compressor.encode(buf, off, + return compressor.encode(raster.getDataBuffer(), off, width, height, sampleSize, csm.getScanlineStride()); } diff --git a/src/main/java/com/github/jaiimageio/plugins/bmp/BMPImageWriteParam.java b/src/main/java/com/github/jaiimageio/plugins/bmp/BMPImageWriteParam.java index 23953b1..beea210 100644 --- a/src/main/java/com/github/jaiimageio/plugins/bmp/BMPImageWriteParam.java +++ b/src/main/java/com/github/jaiimageio/plugins/bmp/BMPImageWriteParam.java @@ -76,9 +76,9 @@ *

* * - * - * - * + * + * + * * * *
Compression Types
Type String Description Image Types
BI_RGB Uncompressed RLE <= 8-bits/sample
BI_RLE8 8-bit Run Length Encoding <= 8-bits/sample
BI_RLE4 4-bit Run Length Encoding <= 4-bits/sample
BI_RGB Uncompressed RLE <= 8-bits/sample
BI_RLE8 8-bit Run Length Encoding <= 8-bits/sample
BI_RLE4 4-bit Run Length Encoding <= 4-bits/sample
BI_BITFIELDS Packed data 16 or 32 bits/sample
BI_JPEG JPEG encoded grayscale or RGB image
diff --git a/src/main/java/com/github/jaiimageio/plugins/tiff/GeoTIFFTagSet.java b/src/main/java/com/github/jaiimageio/plugins/tiff/GeoTIFFTagSet.java index f91cf81..3fc7b31 100644 --- a/src/main/java/com/github/jaiimageio/plugins/tiff/GeoTIFFTagSet.java +++ b/src/main/java/com/github/jaiimageio/plugins/tiff/GeoTIFFTagSet.java @@ -76,7 +76,7 @@ public class GeoTIFFTagSet extends TIFFTagSet { */ public static final int TAG_MODEL_TRANSFORMATION = 34264; - /** A tag used to store raster->model tiepoint pairs. */ + /** A tag used to store raster->model tiepoint pairs. */ public static final int TAG_MODEL_TIE_POINT = 33922; /** A tag used to store the GeoKey directory. */ diff --git a/src/main/java/com/github/jaiimageio/plugins/tiff/TIFFColorConverter.java b/src/main/java/com/github/jaiimageio/plugins/tiff/TIFFColorConverter.java index e7627d1..3d42538 100644 --- a/src/main/java/com/github/jaiimageio/plugins/tiff/TIFFColorConverter.java +++ b/src/main/java/com/github/jaiimageio/plugins/tiff/TIFFColorConverter.java @@ -67,7 +67,7 @@ public TIFFColorConverter() {} * @throws NullPointerException if result is * null. * @throws ArrayIndexOutOfBoundsException if - * result.length < 3. + * result.length < 3. */ public abstract void fromRGB(float r, float g, float b, float[] result); @@ -83,7 +83,7 @@ public TIFFColorConverter() {} * @throws NullPointerException if rgb is * null. * @throws ArrayIndexOutOfBoundsException if - * rgb.length < 3. + * rgb.length < 3. */ public abstract void toRGB(float x0, float x1, float x2, float[] rgb); } diff --git a/src/main/java/com/github/jaiimageio/plugins/tiff/TIFFCompressor.java b/src/main/java/com/github/jaiimageio/plugins/tiff/TIFFCompressor.java index 630900f..6e7e695 100644 --- a/src/main/java/com/github/jaiimageio/plugins/tiff/TIFFCompressor.java +++ b/src/main/java/com/github/jaiimageio/plugins/tiff/TIFFCompressor.java @@ -49,6 +49,11 @@ import javax.imageio.ImageWriter; import javax.imageio.metadata.IIOMetadata; import javax.imageio.stream.ImageOutputStream; +import java.awt.image.*; +import java.nio.ByteBuffer; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; +import java.nio.ShortBuffer; import com.github.jaiimageio.impl.plugins.tiff.TIFFImageWriter; @@ -278,7 +283,83 @@ public abstract int encode(byte[] b, int off, int width, int height, int[] bitsPerSample, int scanlineStride) throws IOException; - + + /** + * Encodes the supplied image data, writing to the currently set + * ImageOutputStream. + * + * @param dataBuffer an DataBuffer with pixels + * @param off the starting offset of the data to be written in the + * array b. + * @param width the width of the rectangle of pixels to be written. + * @param height the height of the rectangle of pixels to be written. + * @param bitsPerSample an array of ints indicting + * the number of bits used to represent each image sample within + * a pixel. + * @param scanlineStride the number of bytes separating each + * row of the input data. + * + * @return the number of bytes written. + * + * @throws IOException if the supplied data cannot be encoded by + * this TIFFCompressor, or if any I/O error occurs + * during writing. + */ + private byte[] currentTile = null; + public int encode(DataBuffer dataBuffer, int off, + int width, int height, + int[] bitsPerSample, + int scanlineStride) throws IOException { + final int dataType = dataBuffer.getDataType(); + if (dataType == DataBuffer.TYPE_BYTE) { + return encode(((DataBufferByte) dataBuffer).getData(), off, width, height, bitsPerSample, scanlineStride); + } + final int dataTypeSize = DataBuffer.getDataTypeSize(dataType) / Byte.SIZE; + int tileSize = width * height * dataTypeSize; + if (currentTile == null || currentTile.length < tileSize) + currentTile = new byte[tileSize]; + final ByteBuffer buffer = ByteBuffer.wrap(currentTile).order(stream.getByteOrder()); + switch (dataType) { + case DataBuffer.TYPE_USHORT: { + ShortBuffer sb = buffer.asShortBuffer(); + short[] shorts = ((DataBufferUShort) dataBuffer).getData(); + for (int i = 0; i < height; i++) { + sb.put(shorts, off, width); + off += scanlineStride; + } + break; + } + case DataBuffer.TYPE_SHORT: { + ShortBuffer sb = buffer.asShortBuffer(); + short[] shorts = ((DataBufferShort) dataBuffer).getData(); + for (int i = 0; i < height; i++) { + sb.put(shorts, off, width); + off += scanlineStride; + } + break; + } + case DataBuffer.TYPE_INT: { + IntBuffer ib = buffer.asIntBuffer(); + int[] ints = ((DataBufferInt) dataBuffer).getData(); + for (int i = 0; i < height; i++) { + ib.put(ints, off, width); + off += scanlineStride; + } + break; + } + case DataBuffer.TYPE_FLOAT: { + FloatBuffer fb = buffer.asFloatBuffer(); + float[] floats = ((DataBufferFloat) dataBuffer).getData(); + for (int i = 0; i < height; i++) { + fb.put(floats, off, width); + off += scanlineStride; + } + break; + } + } + return encode(currentTile, 0, width, height, bitsPerSample, width * dataTypeSize); + } + /** * Allows any resources held by this object to be released. The * result of calling any other method (other than diff --git a/src/main/java/com/github/jaiimageio/plugins/tiff/TIFFDecompressor.java b/src/main/java/com/github/jaiimageio/plugins/tiff/TIFFDecompressor.java index 5ec1b99..796db1b 100644 --- a/src/main/java/com/github/jaiimageio/plugins/tiff/TIFFDecompressor.java +++ b/src/main/java/com/github/jaiimageio/plugins/tiff/TIFFDecompressor.java @@ -376,7 +376,7 @@ public abstract class TIFFDecompressor { *

The pixels in the source region to be copied are * those with X coordinates of the form activeSrcMinX + * k*subsampleX, where k is an integer such - * that 0 <= k < dstWidth. + * that 0 <= k < dstWidth. */ protected int activeSrcMinX; @@ -388,7 +388,7 @@ public abstract class TIFFDecompressor { *

The pixels in the source region to be copied are * those with Y coordinates of the form activeSrcMinY + * k*subsampleY, where k is an integer such - * that 0 <= k < dstHeight. + * that 0 <= k < dstHeight. */ protected int activeSrcMinY; diff --git a/src/main/java/com/github/jaiimageio/plugins/tiff/TIFFTag.java b/src/main/java/com/github/jaiimageio/plugins/tiff/TIFFTag.java index 475a3b5..e8658bc 100644 --- a/src/main/java/com/github/jaiimageio/plugins/tiff/TIFFTag.java +++ b/src/main/java/com/github/jaiimageio/plugins/tiff/TIFFTag.java @@ -292,7 +292,7 @@ public int getNumber() { * would return a value of: * *

-     * (1 << TIFFTag.TIFF_SHORT) | (1 << TIFFTag.TIFF_LONG)
+     * (1 << TIFFTag.TIFF_SHORT) | (1 << TIFFTag.TIFF_LONG)
      * 
* * @return an int containing a bitmask encoding the diff --git a/src/main/java/com/github/jaiimageio/plugins/tiff/package.html b/src/main/java/com/github/jaiimageio/plugins/tiff/package.html index 9316653..2f3f0bb 100644 --- a/src/main/java/com/github/jaiimageio/plugins/tiff/package.html +++ b/src/main/java/com/github/jaiimageio/plugins/tiff/package.html @@ -289,9 +289,9 @@
/Chroma/ColorSpaceType@name PhotometricInterpretation: WhiteIsZero, BlackIsZero, TransparencyMask = -"GRAY"; RGB, PaletteColor => "RGB"; CMYK => "CMYK"; -YCbCr => "YCbCr"; -CIELab, ICCLab => "Lab". +"GRAY"; RGB, PaletteColor => "RGB"; CMYK => "CMYK"; +YCbCr => "YCbCr"; +CIELab, ICCLab => "Lab". /Chroma/NumChannels@value @@ -299,7 +299,7 @@
/Chroma/BlackIsZero@value -"TRUE" <=> PhotometricInterpretation => WhiteIsZero +"TRUE" <=> PhotometricInterpretation => WhiteIsZero /Chroma/Palette @@ -307,28 +307,28 @@
/Compression/CompressionTypeName@value -Compression: Uncompressed => "none"; CCITT 1D => "CCITT +Compression: Uncompressed => "none"; CCITT 1D => "CCITT RLE"; -Group 3 Fax => "CCITT T.4"; Group 4 Fax => "CCITT T.6"; -LZW => "LZW"; -JPEG => "Old JPEG"; New JPEG => "JPEG"; Zlib =>> "ZLib"; PackBits => +Group 3 Fax => "CCITT T.4"; Group 4 Fax => "CCITT T.6"; +LZW => "LZW"; +JPEG => "Old JPEG"; New JPEG => "JPEG"; Zlib =>> "ZLib"; PackBits => "PackBits"; -Deflate => "Deflate"; EXIF JPEG => "JPEG". +Deflate => "Deflate"; EXIF JPEG => "JPEG". /Compression/Lossless@value -Compression: JPEG or New JPEG => "FALSE"; otherwise "TRUE". +Compression: JPEG or New JPEG => "FALSE"; otherwise "TRUE". /Data/PlanarConfiguration@value -Chunky => "PixelInterleaved"; Planar => "PlaneInterleaved". +Chunky => "PixelInterleaved"; Planar => "PlaneInterleaved". /Data/SampleFormat@value -PhotometricInterpretation PaletteColor => "Index"; -SampleFormat unsigned integer data => "UnsignedIntegral"; -SampleFormat two's complement signed integer data => "SignedIntegral"; -SampleFormat IEEE floating point data => "Real"; +PhotometricInterpretation PaletteColor => "Index"; +SampleFormat unsigned integer data => "UnsignedIntegral"; +SampleFormat two's complement signed integer data => "SignedIntegral"; +SampleFormat IEEE floating point data => "Real"; otherwise element not emitted. @@ -338,8 +338,8 @@
/Data/SampleMSB@value -FillOrder: left-to-right => space-separated list of BitsPerSample-1; -right-to-left => space-separated list of 0s. +FillOrder: left-to-right => space-separated list of BitsPerSample-1; +right-to-left => space-separated list of 0s. /Dimension/PixelAspectRatio@value @@ -371,9 +371,9 @@
/Document/SubimageInterpretation@value -NewSubFileType: transparency => "TransparencyMask"; -reduced-resolution => "ReducedResolution"; -single page => "SinglePage". +NewSubFileType: transparency => "TransparencyMask"; +reduced-resolution => "ReducedResolution"; +single page => "SinglePage". /Document/ImageCreationTime@value @@ -385,14 +385,14 @@
Artist, HostComputer, InkNames, Copyright: /Text/TextEntry@keyword = field name, /Text/TextEntry@value = field value.
-Example: TIFF Software field => /Text/TextEntry@keyword = "Software", +Example: TIFF Software field => /Text/TextEntry@keyword = "Software", /Text/TextEntry@value = Name and version number of the software package(s) used to create the image. /Transparency/Alpha@value -ExtraSamples: associated alpha => "premultiplied"; -unassociated alpha => "nonpremultiplied". +ExtraSamples: associated alpha => "premultiplied"; +unassociated alpha => "nonpremultiplied".

@@ -426,7 +426,7 @@
Reading Uncompressed EXIF Images
// Read thumbnail and IFD if present. BufferedImage thumbnail = null; IIOMetadata thumbnailIFD = null; -if(tiffReader.getNumImages(true) > 1) { +if(tiffReader.getNumImages(true) > 1) { thumbnail = tiffReader.read(1, readParam); thumbnailIFD = tiffReader.getImageMetadata(1); } @@ -477,7 +477,7 @@
Reading Compressed EXIF Images
// Read thumbnail and IFD if present. BufferedImage thumbnail = null; IIOMetadata thumbnailIFD = null; -if(tiffReader.getNumImages(true) > 1) { +if(tiffReader.getNumImages(true) > 1) { thumbnail = tiffReader.read(1, readParam); thumbnailIFD = tiffReader.getImageMetadata(1); } @@ -676,10 +676,10 @@
PhotometricInterpretation /Chroma/ColorSpaceType@name: "GRAY" and /Chroma/BlackIsZero@value = "FALSE" -=> WhiteIsZero; "GRAY" and /Document/SubimageInterpretation@value = -"TransparencyMask" => TransparencyMask; "RGB" and /Chroma/Palette present => -PaletteColor; "GRAY" => BlackIsZero; "RGB" => RGB; "YCbCr" => YCbCr; -"CMYK" => CMYK; "Lab" => CIELab. +=> WhiteIsZero; "GRAY" and /Document/SubimageInterpretation@value = +"TransparencyMask" => TransparencyMask; "RGB" and /Chroma/Palette present => +PaletteColor; "GRAY" => BlackIsZero; "RGB" => RGB; "YCbCr" => YCbCr; +"CMYK" => CMYK; "Lab" => CIELab. SamplesPerPixel @@ -691,21 +691,21 @@
Compression -/Compression/CompressionTypeName@value: "none" => Uncompressed; -"CCITT RLE" => CCITT 1D; "CCITT T.4" => Group 3 Fax; "CCITT T.6" => Group 4 -Fax; "LZW" => LZW; "Old JPEG" => JPEG; "JPEG" => New JPEG; "ZLib" => ZLib; -"PackBits" => PackBits; "Deflate" => Deflate. +/Compression/CompressionTypeName@value: "none" => Uncompressed; +"CCITT RLE" => CCITT 1D; "CCITT T.4" => Group 3 Fax; "CCITT T.6" => Group 4 +Fax; "LZW" => LZW; "Old JPEG" => JPEG; "JPEG" => New JPEG; "ZLib" => ZLib; +"PackBits" => PackBits; "Deflate" => Deflate. PlanarConfiguration -/Data/PlanarConfiguration@value: "PixelInterleaved" => Chunky; -"PlaneInterleaved" => Planar. +/Data/PlanarConfiguration@value: "PixelInterleaved" => Chunky; +"PlaneInterleaved" => Planar. SampleFormat -/Data/SampleFormat@value: "SignedIntegral" => two's complement signed -integer data; "UnsignedIntegral" => unsigned integer data; "Real" => -IEEE floating point data; "Index" => unsigned integer data. +/Data/SampleFormat@value: "SignedIntegral" => two's complement signed +integer data; "UnsignedIntegral" => unsigned integer data; "Real" => +IEEE floating point data; "Index" => unsigned integer data. @@ -714,8 +714,8 @@
FillOrder -/Data/SampleMSB@value: if all values in space-separated list are 0s => -right-to-left; otherwise => left-to-right. +/Data/SampleMSB@value: if all values in space-separated list are 0s => +right-to-left; otherwise => left-to-right. @@ -748,9 +748,9 @@
NewSubFileType -/Document/SubimageInterpretation@value: "TransparencyMask" => -transparency mask; "ReducedResolution" => reduced-resolution; -"SinglePage" => single page. +/Document/SubimageInterpretation@value: "TransparencyMask" => +transparency mask; "ReducedResolution" => reduced-resolution; +"SinglePage" => single page. DateTime @@ -765,8 +765,8 @@
ExtraSamples -/Transparency/Alpha@value: "premultiplied" => associated alpha, count 1; -"nonpremultiplied" => unassociated alpha, count 1. +/Transparency/Alpha@value: "premultiplied" => associated alpha, count 1; +"nonpremultiplied" => unassociated alpha, count 1. @@ -948,7 +948,7 @@

Stream Metadata

 <!DOCTYPE "com_sun_media_imageio_plugins_tiff_stream_1.0" [
 
-  <!ELEMENT "com_sun_media_imageio_plugins_tiff_stream_1.0" (ByteOrder)>
+  <!ELEMENT "com_sun_media_imageio_plugins_tiff_stream_1.0" (ByteOrder)>
 
     <!ELEMENT "ByteOrder" EMPTY>
       <!-- The stream byte order --> 
diff --git a/src/main/java/com/github/jaiimageio/stream/RawImageInputStream.java b/src/main/java/com/github/jaiimageio/stream/RawImageInputStream.java
index 98e37b6..794f512 100644
--- a/src/main/java/com/github/jaiimageio/stream/RawImageInputStream.java
+++ b/src/main/java/com/github/jaiimageio/stream/RawImageInputStream.java
@@ -255,7 +255,7 @@ public RawImageInputStream(ImageInputStream source,
      *
      * 

An instance of IndexColorModel will be created for * instances of MultiPixelPackedSampleModel. The colormap - * will be a grayscale ramp with 1 << numberOfBits + * will be a grayscale ramp with 1 << numberOfBits * entries ranging from zero to at most 255.

* * @param source The ImageInputStream containing all the raw