mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-04 12:05:29 -04:00
TMI-64: Removed direct creation of JPEGImageReader.
This commit is contained in:
parent
e603ae260d
commit
5c8d4fad87
@ -28,7 +28,6 @@
|
|||||||
|
|
||||||
package com.twelvemonkeys.imageio.plugins.tiff;
|
package com.twelvemonkeys.imageio.plugins.tiff;
|
||||||
|
|
||||||
import com.sun.imageio.plugins.jpeg.JPEGImageReader;
|
|
||||||
import com.twelvemonkeys.imageio.ImageReaderBase;
|
import com.twelvemonkeys.imageio.ImageReaderBase;
|
||||||
import com.twelvemonkeys.imageio.color.ColorSpaces;
|
import com.twelvemonkeys.imageio.color.ColorSpaces;
|
||||||
import com.twelvemonkeys.imageio.metadata.CompoundDirectory;
|
import com.twelvemonkeys.imageio.metadata.CompoundDirectory;
|
||||||
@ -52,6 +51,7 @@ import com.twelvemonkeys.xml.XMLSerializer;
|
|||||||
import javax.imageio.*;
|
import javax.imageio.*;
|
||||||
import javax.imageio.event.IIOReadWarningListener;
|
import javax.imageio.event.IIOReadWarningListener;
|
||||||
import javax.imageio.metadata.IIOMetadata;
|
import javax.imageio.metadata.IIOMetadata;
|
||||||
|
import javax.imageio.metadata.IIOMetadataFormatImpl;
|
||||||
import javax.imageio.plugins.jpeg.JPEGImageReadParam;
|
import javax.imageio.plugins.jpeg.JPEGImageReadParam;
|
||||||
import javax.imageio.spi.IIORegistry;
|
import javax.imageio.spi.IIORegistry;
|
||||||
import javax.imageio.spi.ImageReaderSpi;
|
import javax.imageio.spi.ImageReaderSpi;
|
||||||
@ -62,6 +62,8 @@ import java.awt.color.ColorSpace;
|
|||||||
import java.awt.color.ICC_Profile;
|
import java.awt.color.ICC_Profile;
|
||||||
import java.awt.image.*;
|
import java.awt.image.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.zip.Inflater;
|
import java.util.zip.Inflater;
|
||||||
@ -735,8 +737,7 @@ public class TIFFImageReader extends ImageReaderBase {
|
|||||||
// TODO: Refactor all JPEG reading out to separate JPEG support class?
|
// TODO: Refactor all JPEG reading out to separate JPEG support class?
|
||||||
// TODO: Cache the JPEG reader for later use? Remember to reset to avoid resource leaks
|
// TODO: Cache the JPEG reader for later use? Remember to reset to avoid resource leaks
|
||||||
|
|
||||||
// TIFF is strictly ISO JPEG, so we should probably stick to the standard reader
|
ImageReader jpegReader = createJPEGDelegate();
|
||||||
ImageReader jpegReader = new JPEGImageReader(getOriginatingProvider());
|
|
||||||
JPEGImageReadParam jpegParam = (JPEGImageReadParam) jpegReader.getDefaultReadParam();
|
JPEGImageReadParam jpegParam = (JPEGImageReadParam) jpegReader.getDefaultReadParam();
|
||||||
|
|
||||||
// JPEG_TABLES should be a full JPEG 'abbreviated table specification', containing:
|
// JPEG_TABLES should be a full JPEG 'abbreviated table specification', containing:
|
||||||
@ -825,8 +826,7 @@ public class TIFFImageReader extends ImageReaderBase {
|
|||||||
|
|
||||||
// May use normal tiling??
|
// May use normal tiling??
|
||||||
|
|
||||||
// TIFF is strictly ISO JPEG, so we should probably stick to the standard reader
|
jpegReader = createJPEGDelegate();
|
||||||
jpegReader = new JPEGImageReader(getOriginatingProvider());
|
|
||||||
jpegParam = (JPEGImageReadParam) jpegReader.getDefaultReadParam();
|
jpegParam = (JPEGImageReadParam) jpegReader.getDefaultReadParam();
|
||||||
|
|
||||||
// 513/JPEGInterchangeFormat (may be absent...)
|
// 513/JPEGInterchangeFormat (may be absent...)
|
||||||
@ -1039,11 +1039,37 @@ public class TIFFImageReader extends ImageReaderBase {
|
|||||||
throw new IIOException("Unknown TIFF Compression value: " + compression);
|
throw new IIOException("Unknown TIFF Compression value: " + compression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Convert color space from source to destination
|
||||||
|
|
||||||
processImageComplete();
|
processImageComplete();
|
||||||
|
|
||||||
return destination;
|
return destination;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ImageReader createJPEGDelegate() throws IIOException {
|
||||||
|
// TIFF is strictly ISO JPEG, so we should probably stick to the standard reader
|
||||||
|
try {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Class<ImageReader> readerClass = (Class<ImageReader>) Class.forName("com.sun.imageio.plugins.jpeg.JPEGImageReader");
|
||||||
|
Constructor<ImageReader> constructor = readerClass.getConstructor(ImageReaderSpi.class);
|
||||||
|
return constructor.newInstance(getOriginatingProvider());
|
||||||
|
}
|
||||||
|
catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException ignore) {
|
||||||
|
if (DEBUG) {
|
||||||
|
ignore.printStackTrace();
|
||||||
|
}
|
||||||
|
// Fall back to default reader below
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we can't get the standard reader, fall back to the default (first) reader
|
||||||
|
Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("JPEG");
|
||||||
|
if (!readers.hasNext()) {
|
||||||
|
throw new IIOException("Could not instantiate JPEGImageReader. ");
|
||||||
|
}
|
||||||
|
|
||||||
|
return readers.next();
|
||||||
|
}
|
||||||
|
|
||||||
private static InputStream createJFIFStream(WritableRaster raster, int stripTileWidth, int stripTileHeight, byte[][] qTables, byte[][] dcTables, byte[][] acTables) throws IOException {
|
private static InputStream createJFIFStream(WritableRaster raster, int stripTileWidth, int stripTileHeight, byte[][] qTables, byte[][] dcTables, byte[][] acTables) throws IOException {
|
||||||
FastByteArrayOutputStream stream = new FastByteArrayOutputStream(
|
FastByteArrayOutputStream stream = new FastByteArrayOutputStream(
|
||||||
2 + 2 + 2 + 6 + 3 * raster.getNumBands() +
|
2 + 2 + 2 + 6 + 3 * raster.getNumBands() +
|
||||||
@ -1378,6 +1404,8 @@ public class TIFFImageReader extends ImageReaderBase {
|
|||||||
// TODO: Thumbnail support
|
// TODO: Thumbnail support
|
||||||
|
|
||||||
public static void main(final String[] args) throws IOException {
|
public static void main(final String[] args) throws IOException {
|
||||||
|
ImageIO.setUseCache(false);
|
||||||
|
|
||||||
for (final String arg : args) {
|
for (final String arg : args) {
|
||||||
File file = new File(arg);
|
File file = new File(arg);
|
||||||
|
|
||||||
@ -1459,8 +1487,13 @@ public class TIFFImageReader extends ImageReaderBase {
|
|||||||
|
|
||||||
IIOMetadata metadata = reader.getImageMetadata(imageNo);
|
IIOMetadata metadata = reader.getImageMetadata(imageNo);
|
||||||
if (metadata != null) {
|
if (metadata != null) {
|
||||||
|
if (metadata.getNativeMetadataFormatName() != null) {
|
||||||
new XMLSerializer(System.out, "UTF-8").serialize(metadata.getAsTree(metadata.getNativeMetadataFormatName()), false);
|
new XMLSerializer(System.out, "UTF-8").serialize(metadata.getAsTree(metadata.getNativeMetadataFormatName()), false);
|
||||||
}
|
}
|
||||||
|
else if (metadata.isStandardMetadataFormatSupported()) {
|
||||||
|
new XMLSerializer(System.out, "UTF-8").serialize(metadata.getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
System.err.println("image: " + image);
|
System.err.println("image: " + image);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user