You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ap...@apache.org on 2007/12/29 10:30:12 UTC
svn commit: r607405 - in
/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java:
javax/imageio/ImageReader.java
org/apache/harmony/x/imageio/internal/nls/messages.properties
Author: apavlenko
Date: Sat Dec 29 01:30:11 2007
New Revision: 607405
URL: http://svn.apache.org/viewvc?rev=607405&view=rev
Log:
Completed implementation of javax.imageio.ImageReader
Modified:
harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/ImageReader.java
harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/messages.properties
Modified: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/ImageReader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/ImageReader.java?rev=607405&r1=607404&r2=607405&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/ImageReader.java (original)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/ImageReader.java Sat Dec 29 01:30:11 2007
@@ -14,56 +14,57 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-/**
- * @author Rustem V. Rafikov
- * @version $Revision: 1.3 $
- */
package javax.imageio;
-import javax.imageio.spi.ImageReaderSpi;
-import javax.imageio.stream.ImageInputStream;
-import javax.imageio.metadata.IIOMetadata;
-import javax.imageio.event.IIOReadWarningListener;
-import javax.imageio.event.IIOReadProgressListener;
-import javax.imageio.event.IIOReadUpdateListener;
-
-import org.apache.harmony.luni.util.NotImplementedException;
-
-import java.util.Locale;
-import java.util.List;
-import java.util.Iterator;
-import java.util.Set;
-import java.io.IOException;
+import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.awt.image.Raster;
import java.awt.image.RenderedImage;
-import java.awt.*;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+import java.util.ResourceBundle;
+import java.util.Set;
+
+import javax.imageio.event.IIOReadProgressListener;
+import javax.imageio.event.IIOReadUpdateListener;
+import javax.imageio.event.IIOReadWarningListener;
+import javax.imageio.metadata.IIOMetadata;
+import javax.imageio.spi.ImageReaderSpi;
+import javax.imageio.stream.ImageInputStream;
+
+import org.apache.harmony.x.imageio.internal.nls.Messages;
public abstract class ImageReader {
- protected ImageReaderSpi originatingProvider;
+ protected ImageReaderSpi originatingProvider;
- protected Object input;
+ protected Object input;
- protected boolean seekForwardOnly;
+ protected boolean seekForwardOnly;
- protected boolean ignoreMetadata;
+ protected boolean ignoreMetadata;
- protected int minIndex;
+ protected int minIndex;
- protected Locale[] availableLocales;
+ protected Locale[] availableLocales;
- protected Locale locale;
+ protected Locale locale;
- protected List<IIOReadWarningListener> warningListeners;
+ protected List<IIOReadWarningListener> warningListeners;
- protected List<Locale> warningLocales;
+ protected List<Locale> warningLocales;
protected List<IIOReadProgressListener> progressListeners;
- protected List<IIOReadUpdateListener> updateListeners;
+ protected List<IIOReadUpdateListener> updateListeners;
- protected ImageReader(ImageReaderSpi originatingProvider) {
+ private boolean isAborted;
+
+ protected ImageReader(final ImageReaderSpi originatingProvider) {
this.originatingProvider = originatingProvider;
}
@@ -75,10 +76,13 @@
return originatingProvider;
}
- public void setInput(Object input, boolean seekForwardOnly, boolean ignoreMetadata) {
+ public void setInput(final Object input, final boolean seekForwardOnly,
+ final boolean ignoreMetadata) {
if (input != null) {
if (!isSupported(input) && !(input instanceof ImageInputStream)) {
- throw new IllegalArgumentException("input " + input + " is not supported");
+ throw new IllegalArgumentException(Messages.getString(
+ "imageio.2", //$NON-NLS-1$
+ input));
}
}
this.minIndex = 0;
@@ -87,10 +91,11 @@
this.input = input;
}
- private boolean isSupported(Object input) {
+ private boolean isSupported(final Object input) {
ImageReaderSpi spi = getOriginatingProvider();
if (null != spi) {
- Class[] outTypes = spi.getInputTypes();
+ Class<?>[] outTypes = spi.getInputTypes();
+
for (Class<?> element : outTypes) {
if (element.isInstance(input)) {
return true;
@@ -100,11 +105,11 @@
return false;
}
- public void setInput(Object input, boolean seekForwardOnly) {
+ public void setInput(final Object input, final boolean seekForwardOnly) {
setInput(input, seekForwardOnly, false);
}
- public void setInput(Object input) {
+ public void setInput(final Object input) {
setInput(input, false, false);
}
@@ -128,316 +133,448 @@
return availableLocales;
}
- public void setLocale(Locale locale) throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ public void setLocale(final Locale locale) {
+ if (locale != null) {
+ final Locale[] locales = getAvailableLocales();
+
+ if ((locales == null) || !arrayContains(locales, locale)) {
+ throw new IllegalArgumentException(Messages.getString(
+ "imageio.3", //$NON-NLS-1$
+ "Locale " + locale)); //$NON-NLS-1$
+ }
+ }
+
+ this.locale = locale;
}
public Locale getLocale() {
return locale;
}
- public abstract int getNumImages(boolean allowSearch) throws IOException;
+ public abstract int getNumImages(final boolean allowSearch)
+ throws IOException;
- public abstract int getWidth(int imageIndex) throws IOException;
+ public abstract int getWidth(final int imageIndex) throws IOException;
- public abstract int getHeight(int imageIndex) throws IOException;
+ public abstract int getHeight(final int imageIndex) throws IOException;
- public boolean isRandomAccessEasy(int imageIndex) throws IOException {
- return false; //def
+ public boolean isRandomAccessEasy(final int imageIndex) throws IOException {
+ return false;
}
- public float getAspectRatio(int imageIndex) throws IOException {
+ public float getAspectRatio(final int imageIndex) throws IOException {
return (float) getWidth(imageIndex) / getHeight(imageIndex);
}
- public ImageTypeSpecifier getRawImageType(int imageIndex) throws IOException, NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ public ImageTypeSpecifier getRawImageType(final int imageIndex)
+ throws IOException {
+ return getImageTypes(imageIndex).next();
}
- public abstract Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex) throws IOException;
+ public abstract Iterator<ImageTypeSpecifier> getImageTypes(
+ final int imageIndex) throws IOException;
- public ImageReadParam getDefaultReadParam() throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ public ImageReadParam getDefaultReadParam() {
+ return new ImageReadParam();
}
public abstract IIOMetadata getStreamMetadata() throws IOException;
- public IIOMetadata getStreamMetadata(String formatName, Set<String> nodeNames)
- throws IOException, NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ public IIOMetadata getStreamMetadata(final String formatName,
+ final Set<String> nodeNames) throws IOException {
+ iaeIfNull("formatName", formatName); //$NON-NLS-1$
+ iaeIfNull("nodeNames", nodeNames); //$NON-NLS-1$
+
+ final IIOMetadata data = getStreamMetadata();
+ return isSupportedFormat(formatName, data) ? data : null;
}
- public abstract IIOMetadata getImageMetadata(int imageIndex) throws IOException;
+ public abstract IIOMetadata getImageMetadata(final int imageIndex)
+ throws IOException;
- public IIOMetadata getImageMetadata(int imageIndex, String formatName,
- Set<String> nodeNames) throws IOException, NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ public IIOMetadata getImageMetadata(final int imageIndex,
+ final String formatName, final Set<String> nodeNames)
+ throws IOException {
+ iaeIfNull("formatName", formatName); //$NON-NLS-1$
+ iaeIfNull("nodeNames", nodeNames); //$NON-NLS-1$
+
+ final IIOMetadata data = getImageMetadata(imageIndex);
+ return isSupportedFormat(formatName, data) ? data : null;
}
- public BufferedImage read(int imageIndex) throws IOException {
+ public BufferedImage read(final int imageIndex) throws IOException {
return read(imageIndex, null);
}
- public abstract BufferedImage read(int imageIndex, ImageReadParam param) throws IOException;
+ public abstract BufferedImage read(final int imageIndex,
+ final ImageReadParam param) throws IOException;
+
+ public IIOImage readAll(final int imageIndex, final ImageReadParam param)
+ throws IOException {
+ List<BufferedImage> th = null;
+ final BufferedImage img = read(imageIndex, param);
+ final int num = getNumThumbnails(imageIndex);
+
+ if (num > 0) {
+ th = new ArrayList<BufferedImage>(num);
+
+ for (int i = 0; i < num; i++) {
+ th.add(readThumbnail(imageIndex, i));
+ }
+ }
- public IIOImage readAll(int imageIndex, ImageReadParam param) throws IOException, NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ return new IIOImage(img, th, getImageMetadata(imageIndex));
}
- public Iterator<IIOImage> readAll(Iterator<? extends ImageReadParam> params) throws IOException, NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ public Iterator<IIOImage> readAll(
+ final Iterator<? extends ImageReadParam> params)
+ throws IOException {
+ final int index = getMinIndex();
+ final List<IIOImage> list = new LinkedList<IIOImage>();
+
+ processSequenceStarted(index);
+
+ while (params.hasNext()) {
+ try {
+ list.add(readAll(index, params.next()));
+ } catch (final ClassCastException ex) {
+ throw new IllegalArgumentException(ex);
+ }
+ }
+
+ processSequenceComplete();
+ return list.iterator();
}
public boolean canReadRaster() {
- return false; //def
+ return false; // def
}
- public Raster readRaster(int imageIndex, ImageReadParam param) throws IOException {
- throw new UnsupportedOperationException("Unsupported");
+ public Raster readRaster(final int imageIndex, final ImageReadParam param)
+ throws IOException {
+ throw new UnsupportedOperationException(Messages.getString("imageio.7", //$NON-NLS-1$
+ "readRaster()")); //$NON-NLS-1$
}
- public boolean isImageTiled(int imageIndex) throws IOException {
- return false; //def
+ public boolean isImageTiled(final int imageIndex) throws IOException {
+ return false; // def
}
- public int getTileWidth(int imageIndex) throws IOException {
- return getWidth(imageIndex); //def
+ public int getTileWidth(final int imageIndex) throws IOException {
+ return getWidth(imageIndex); // def
}
- public int getTileHeight(int imageIndex) throws IOException {
- return getHeight(imageIndex); //def
+ public int getTileHeight(final int imageIndex) throws IOException {
+ return getHeight(imageIndex); // def
}
- public int getTileGridXOffset(int imageIndex) throws IOException {
- return 0; //def
+ public int getTileGridXOffset(final int imageIndex) throws IOException {
+ return 0; // def
}
- public int getTileGridYOffset(int imageIndex) throws IOException {
- return 0; //def
+ public int getTileGridYOffset(final int imageIndex) throws IOException {
+ return 0; // def
}
- public BufferedImage readTile(int imageIndex, int tileX, int tileY) throws IOException, NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ public BufferedImage readTile(final int imageIndex, final int tileX,
+ final int tileY) throws IOException {
+ if ((tileX != 0) || (tileY != 0)) {
+ throw new IllegalArgumentException(Messages.getString("imageio.5", //$NON-NLS-1$
+ "0", "tileX & tileY")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ return read(imageIndex);
}
- public Raster readTileRaster(int imageIndex, int tileX, int tileY) throws IOException, NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ public Raster readTileRaster(final int imageIndex, final int tileX,
+ final int tileY) throws IOException {
+ if (canReadRaster()) {
+ if ((tileX != 0) || (tileY != 0)) {
+ throw new IllegalArgumentException(Messages.getString(
+ "imageio.5", //$NON-NLS-1$
+ "0", "tileX & tileY")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return readRaster(imageIndex, null);
+ }
+
+ throw new UnsupportedOperationException(Messages.getString("imageio.7", //$NON-NLS-1$
+ "readTileRaster()")); //$NON-NLS-1$
}
- public RenderedImage readAsRenderedImage(int imageIndex, ImageReadParam param) throws IOException {
+ public RenderedImage readAsRenderedImage(final int imageIndex,
+ final ImageReadParam param) throws IOException {
return read(imageIndex, param);
}
public boolean readerSupportsThumbnails() {
- return false; //def
+ return false; // def
}
- public boolean hasThumbnails(int imageIndex) throws IOException {
- return getNumThumbnails(imageIndex) > 0; //def
+ public boolean hasThumbnails(final int imageIndex) throws IOException {
+ return getNumThumbnails(imageIndex) > 0; // def
}
- public int getNumThumbnails(int imageIndex) throws IOException {
- return 0; //def
+ public int getNumThumbnails(final int imageIndex) throws IOException {
+ return 0; // def
}
- public int getThumbnailWidth(int imageIndex, int thumbnailIndex) throws IOException {
- return readThumbnail(imageIndex, thumbnailIndex).getWidth(); //def
+ public int getThumbnailWidth(final int imageIndex, final int thumbnailIndex)
+ throws IOException {
+ return readThumbnail(imageIndex, thumbnailIndex).getWidth(); // def
}
- public int getThumbnailHeight(int imageIndex, int thumbnailIndex) throws IOException {
- return readThumbnail(imageIndex, thumbnailIndex).getHeight(); //def
+ public int getThumbnailHeight(final int imageIndex, final int thumbnailIndex)
+ throws IOException {
+ return readThumbnail(imageIndex, thumbnailIndex).getHeight(); // def
}
- public BufferedImage readThumbnail(int imageIndex, int thumbnailIndex) throws IOException {
- throw new UnsupportedOperationException("Unsupported"); //def
+ public BufferedImage readThumbnail(final int imageIndex,
+ final int thumbnailIndex) throws IOException {
+ throw new UnsupportedOperationException(Messages.getString("imageio.7", //$NON-NLS-1$
+ "readThumbnail()")); //$NON-NLS-1$
}
- public void abort() throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ public void abort() {
+ isAborted = true;
}
- protected boolean abortRequested() throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ protected boolean abortRequested() {
+ return isAborted;
}
- protected void clearAbortRequest() throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ protected void clearAbortRequest() {
+ isAborted = false;
}
- public void addIIOReadWarningListener(IIOReadWarningListener listener) throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ public void addIIOReadWarningListener(final IIOReadWarningListener listener) {
+ if (listener != null) {
+ warningListeners = addToList(warningListeners, listener);
+ warningLocales = addToList(warningLocales, getLocale());
+ }
}
- public void removeIIOReadWarningListener(IIOReadWarningListener listener) throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ public void removeIIOReadWarningListener(
+ final IIOReadWarningListener listener) {
+ final int ind;
+
+ if ((warningListeners != null) && (listener != null)
+ && ((ind = warningListeners.indexOf(listener)) != -1)) {
+ warningListeners.remove(ind);
+ warningLocales.remove(ind);
+ }
}
- public void removeAllIIOReadWarningListeners() throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ public void removeAllIIOReadWarningListeners() {
+ warningListeners = null;
+ warningLocales = null;
}
- public void addIIOReadProgressListener(IIOReadProgressListener listener) throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ public void addIIOReadProgressListener(
+ final IIOReadProgressListener listener) {
+ if (listener != null) {
+ progressListeners = addToList(progressListeners, listener);
+ }
}
- public void removeIIOReadProgressListener(IIOReadProgressListener listener) throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ public void removeIIOReadProgressListener(
+ final IIOReadProgressListener listener) {
+ if ((progressListeners != null) && (listener != null)) {
+ progressListeners.remove(listener);
+ }
}
- public void removeAllIIOReadProgressListeners() throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ public void removeAllIIOReadProgressListeners() {
+ progressListeners = null;
}
- public void addIIOReadUpdateListener(IIOReadUpdateListener listener) throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ public void addIIOReadUpdateListener(final IIOReadUpdateListener listener) {
+ if (listener != null) {
+ updateListeners = addToList(updateListeners, listener);
+ }
}
- public void removeIIOReadUpdateListener(IIOReadUpdateListener listener) throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ public void removeIIOReadUpdateListener(final IIOReadUpdateListener listener) {
+ if ((updateListeners != null) && (listener != null)) {
+ updateListeners.remove(listener);
+ }
}
- public void removeAllIIOReadUpdateListeners() throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ public void removeAllIIOReadUpdateListeners() {
+ updateListeners = null;
}
- protected void processSequenceStarted(int minIndex) throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ protected void processSequenceStarted(final int minIndex) {
+ if (progressListeners != null) {
+ for (final IIOReadProgressListener listener : progressListeners) {
+ listener.sequenceStarted(this, minIndex);
+ }
+ }
}
- protected void processSequenceComplete() throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ protected void processSequenceComplete() {
+ if (progressListeners != null) {
+ for (final IIOReadProgressListener listener : progressListeners) {
+ listener.sequenceComplete(this);
+ }
+ }
}
- protected void processImageStarted(int imageIndex) throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ protected void processImageStarted(final int imageIndex) {
+ if (progressListeners != null) {
+ for (final IIOReadProgressListener listener : progressListeners) {
+ listener.imageStarted(this, imageIndex);
+ }
+ }
}
- protected void processImageProgress(float percentageDone) throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ protected void processImageProgress(final float percentageDone) {
+ if (progressListeners != null) {
+ for (final IIOReadProgressListener listener : progressListeners) {
+ listener.imageProgress(this, percentageDone);
+ }
+ }
}
- protected void processImageComplete() throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ protected void processImageComplete() {
+ if (progressListeners != null) {
+ for (final IIOReadProgressListener listener : progressListeners) {
+ listener.imageComplete(this);
+ }
+ }
}
- protected void processThumbnailStarted(int imageIndex, int thumbnailIndex) throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ protected void processThumbnailStarted(final int imageIndex,
+ final int thumbnailIndex) {
+ if (progressListeners != null) {
+ for (final IIOReadProgressListener listener : progressListeners) {
+ listener.thumbnailStarted(this, imageIndex, thumbnailIndex);
+ }
+ }
}
- protected void processThumbnailProgress(float percentageDone) throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ protected void processThumbnailProgress(final float percentageDone) {
+ if (progressListeners != null) {
+ for (final IIOReadProgressListener listener : progressListeners) {
+ listener.thumbnailProgress(this, percentageDone);
+ }
+ }
}
- protected void processThumbnailComplete() throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ protected void processThumbnailComplete() {
+ if (progressListeners != null) {
+ for (final IIOReadProgressListener listener : progressListeners) {
+ listener.thumbnailComplete(this);
+ }
+ }
}
- protected void processReadAborted() throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ protected void processReadAborted() {
+ if (progressListeners != null) {
+ for (final IIOReadProgressListener listener : progressListeners) {
+ listener.readAborted(this);
+ }
+ }
}
- protected void processPassStarted(BufferedImage theImage,
- int pass,
- int minPass,
- int maxPass,
- int minX,
- int minY,
- int periodX,
- int periodY,
- int[] bands) throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ protected void processPassStarted(final BufferedImage theImage,
+ final int pass, final int minPass, final int maxPass,
+ final int minX, final int minY, final int periodX,
+ final int periodY, final int[] bands) {
+ if (updateListeners != null) {
+ for (final IIOReadUpdateListener listener : updateListeners) {
+ listener.passStarted(this, theImage, pass, minPass, maxPass,
+ minX, minY, periodX, periodY, bands);
+ }
+ }
}
- protected void processImageUpdate(BufferedImage theImage,
- int minX,
- int minY,
- int width,
- int height,
- int periodX,
- int periodY,
- int[] bands) throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ protected void processImageUpdate(final BufferedImage theImage,
+ final int minX, final int minY, final int width,
+ final int height, final int periodX, final int periodY,
+ final int[] bands) {
+ if (updateListeners != null) {
+ for (final IIOReadUpdateListener listener : updateListeners) {
+ listener.imageUpdate(this, theImage, minX, minY, width, height,
+ periodX, periodY, bands);
+ }
+ }
}
- protected void processPassComplete(BufferedImage theImage) throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ protected void processPassComplete(final BufferedImage theImage) {
+ if (updateListeners != null) {
+ for (IIOReadUpdateListener listener : updateListeners) {
+ listener.passComplete(this, theImage);
+ }
+ }
}
- protected void processThumbnailPassStarted(BufferedImage theThumbnail,
- int pass,
- int minPass,
- int maxPass,
- int minX,
- int minY,
- int periodX,
- int periodY,
- int[] bands) throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ protected void processThumbnailPassStarted(
+ final BufferedImage theThumbnail, final int pass,
+ final int minPass, final int maxPass, final int minX,
+ final int minY, final int periodX, final int periodY,
+ final int[] bands) {
+ if (updateListeners != null) {
+ for (final IIOReadUpdateListener listener : updateListeners) {
+ listener.thumbnailPassStarted(this, theThumbnail, pass,
+ minPass, maxPass, minX, minY, periodX, periodY, bands);
+ }
+ }
}
- protected void processThumbnailUpdate(BufferedImage theThumbnail,
- int minX,
- int minY,
- int width,
- int height,
- int periodX,
- int periodY,
- int[] bands) throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ protected void processThumbnailUpdate(final BufferedImage theThumbnail,
+ final int minX, final int minY, final int width,
+ final int height, final int periodX, final int periodY,
+ final int[] bands) {
+ if (updateListeners != null) {
+ for (final IIOReadUpdateListener listener : updateListeners) {
+ listener.thumbnailUpdate(this, theThumbnail, minX, minY, width,
+ height, periodX, periodY, bands);
+ }
+ }
}
- protected void processThumbnailPassComplete(BufferedImage theThumbnail) throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ protected void processThumbnailPassComplete(final BufferedImage theThumbnail) {
+ if (updateListeners != null) {
+ for (final IIOReadUpdateListener listener : updateListeners) {
+ listener.thumbnailPassComplete(this, theThumbnail);
+ }
+ }
}
- protected void processWarningOccurred(String warning) throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ protected void processWarningOccurred(final String warning) {
+ if (warningListeners != null) {
+ iaeIfNull("warning", warning); //$NON-NLS-1$
+ for (final IIOReadWarningListener listener : warningListeners) {
+ listener.warningOccurred(this, warning);
+ }
+ }
}
- protected void processWarningOccurred(String baseName, String keyword) throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ protected void processWarningOccurred(final String baseName,
+ final String keyword) {
+ if (warningListeners != null) {
+ int i = 0;
+
+ iaeIfNull("keyword", keyword); //$NON-NLS-1$
+ iaeIfNull("baseName", baseName); //$NON-NLS-1$
+
+ for (final IIOReadWarningListener listener : warningListeners) {
+ try {
+ final Locale locale = warningLocales.get(i);
+ final ResourceBundle bundle = (locale != null)
+ ? ResourceBundle.getBundle(baseName, locale)
+ : ResourceBundle.getBundle(baseName);
+ listener.warningOccurred(this, bundle.getString(keyword));
+ } catch (final RuntimeException ex) {
+ throw new IllegalArgumentException(ex.getMessage());
+ }
+
+ i++;
+ }
+ }
}
public void reset() {
- // def
setInput(null, false);
setLocale(null);
removeAllIIOReadUpdateListeners();
@@ -450,33 +587,185 @@
// do nothing by def
}
- protected static Rectangle getSourceRegion(ImageReadParam param, int srcWidth, int srcHeight) throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
- }
-
- protected static void computeRegions(ImageReadParam param,
- int srcWidth,
- int srcHeight,
- BufferedImage image,
- Rectangle srcRegion,
- Rectangle destRegion) throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
- }
-
- protected static void checkReadParamBandSettings(ImageReadParam param,
- int numSrcBands,
- int numDstBands) throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
- }
-
- protected static BufferedImage getDestination(ImageReadParam param, Iterator<ImageTypeSpecifier> imageTypes,
- int width,
- int height)
- throws IIOException, NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ protected static Rectangle getSourceRegion(final ImageReadParam param,
+ final int srcWidth, final int srcHeight) {
+ final Rectangle r = new Rectangle(0, 0, srcWidth, srcHeight);
+
+ if (param != null) {
+ final int x;
+ final int y;
+ final Rectangle sr = param.getSourceRegion();
+
+ if (sr != null) {
+ r.setBounds(r.intersection(sr));
+ }
+
+ x = param.getSubsamplingXOffset();
+ y = param.getSubsamplingYOffset();
+ r.x += x;
+ r.y += y;
+ r.width -= x;
+ r.height -= y;
+ }
+
+ return r;
+ }
+
+ protected static void computeRegions(final ImageReadParam param,
+ final int srcWidth, final int srcHeight,
+ final BufferedImage image, final Rectangle srcRegion,
+ final Rectangle destRegion) {
+ int xCols = 1;
+ int yCols = 1;
+
+ iaeIfNull("srcRegion", srcRegion); //$NON-NLS-1$
+ iaeIfNull("destRegion", destRegion); //$NON-NLS-1$
+ iaeIfEmpty("srcRegion", srcRegion.isEmpty()); //$NON-NLS-1$
+ iaeIfEmpty("destRegion", destRegion.isEmpty()); //$NON-NLS-1$
+
+ srcRegion.setBounds(getSourceRegion(param, srcWidth, srcHeight));
+
+ if (param != null) {
+ destRegion.setLocation(param.getDestinationOffset());
+ xCols = param.getSourceXSubsampling();
+ yCols = param.getSourceYSubsampling();
+ }
+
+ if (destRegion.x < 0) {
+ final int shift = -destRegion.x * xCols;
+ srcRegion.x += shift;
+ srcRegion.width -= shift;
+ destRegion.x = 0;
+ }
+
+ if (destRegion.y < 0) {
+ final int shift = -destRegion.y * yCols;
+ srcRegion.y += shift;
+ srcRegion.height -= shift;
+ destRegion.y = 0;
+ }
+
+ destRegion.width = srcRegion.width / xCols;
+ destRegion.height = srcRegion.height / yCols;
+
+ if (image != null) {
+ destRegion.setBounds(destRegion.intersection(new Rectangle(0, 0,
+ image.getWidth(), image.getHeight())));
+ }
+ }
+
+ protected static void checkReadParamBandSettings(
+ final ImageReadParam param, final int numSrcBands,
+ final int numDstBands) {
+ final int[] src = (param != null) ? param.getSourceBands() : null;
+ final int[] dst = (param != null) ? param.getDestinationBands() : null;
+ final int srcLen = (src != null) ? src.length : numSrcBands;
+ final int dstLen = (dst != null) ? dst.length : numDstBands;
+
+ if (srcLen != dstLen) {
+ throw new IllegalArgumentException("srcLen != dstLen"); //$NON-NLS-1$
+ }
+
+ if (src != null) {
+ for (int i = 0; i < srcLen; i++) {
+ if (src[i] >= numSrcBands) {
+ throw new IllegalArgumentException("src[" + i //$NON-NLS-1$
+ + "] >= numSrcBands"); //$NON-NLS-1$
+ }
+ }
+ }
+
+ if (dst != null) {
+ for (int i = 0; i < dstLen; i++) {
+ if (dst[i] >= numDstBands) {
+ throw new IllegalArgumentException("dst[" + i //$NON-NLS-1$
+ + "] >= numDstBands"); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+
+ protected static BufferedImage getDestination(final ImageReadParam param,
+ final Iterator<ImageTypeSpecifier> imageTypes,
+ final int width, final int height) throws IIOException {
+ iaeIfNull("imageTypes", imageTypes); //$NON-NLS-1$
+ iaeIfEmpty("imageTypes", !imageTypes.hasNext()); //$NON-NLS-1$
+
+ if ((long) (width * height) > (long) Integer.MAX_VALUE) {
+ throw new IllegalArgumentException(
+ "width * height > Integer.MAX_VALUE!"); //$NON-NLS-1$
+ }
+
+ final Rectangle dst;
+ ImageTypeSpecifier its = null;
+
+ if (param != null) {
+ final BufferedImage img = param.getDestination();
+
+ if (img != null) {
+ return img;
+ }
+
+ its = param.getDestinationType();
+ }
+
+ try {
+ isValid: if (its != null) {
+ while (imageTypes.hasNext()) {
+ if (its.equals((ImageTypeSpecifier) imageTypes.next())) {
+ break isValid;
+ }
+ }
+ throw new IIOException(Messages.getString("imageio.3", its)); //$NON-NLS-1$
+ } else {
+ its = imageTypes.next();
+ }
+ } catch (final ClassCastException ex) {
+ throw new IllegalArgumentException(ex);
+ }
+
+ dst = new Rectangle(0, 0, 0, 0);
+ computeRegions(param, width, height, null, new Rectangle(0, 0, 0, 0),
+ dst);
+ return its.createBufferedImage(dst.width, dst.height);
+ }
+
+ private static <T> List<T> addToList(List<T> list, final T value) {
+ if (list == null) {
+ list = new LinkedList<T>();
+ }
+
+ list.add(value);
+ return list;
+ }
+
+ private static void iaeIfNull(final String name, final Object value) {
+ if (value == null) {
+ throw new IllegalArgumentException(Messages.getString("imageio.2", //$NON-NLS-1$
+ name));
+ }
+ }
+
+ private static void iaeIfEmpty(final String name, final boolean isEmpty) {
+ if (isEmpty) {
+ throw new IllegalArgumentException(Messages.getString("imageio.6", //$NON-NLS-1$
+ name));
+ }
+ }
+
+ private static <T> boolean arrayContains(final T[] array, final Object value) {
+ for (T t : array) {
+ if ((t == value) || ((t != null) && t.equals(value))) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static boolean isSupportedFormat(final String formatName,
+ final IIOMetadata data) {
+ final String[] names;
+ return ((data != null) && ((names = data.getMetadataFormatNames()) != null))
+ ? arrayContains(names, formatName) : false;
}
}
Modified: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/messages.properties?rev=607405&r1=607404&r2=607405&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/messages.properties (original)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/internal/nls/messages.properties Sat Dec 29 01:30:11 2007
@@ -15,4 +15,10 @@
#
# messages for EN locale
-imageio.1=Wrong bitDepth-numBands composition
\ No newline at end of file
+imageio.1=Wrong bitDepth-numBands composition
+imageio.2="{0}" is null
+imageio.3="{0}" is not valid
+imageio.4={0} {1} {2}
+imageio.5="{0}" value expected for "{1}"
+imageio.6="{0}" is empty
+imageio.7="{0}" is not supported