Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * @(#)ILBMImageReader.java  
   * 
   * Copyright (c) 2009 Werner Randelshofer, Goldau, Switzerland.
   * All rights reserved.
   *
   * You may not use, copy or modify this file, except in compliance with the
   * license agreement you entered into with Werner Randelshofer.
   * For details see accompanying license terms.
  */
 package org.monte.media.ilbm;
 
Reads an image in the Amiga IFF Interleaved Bitmap image format (ILBM).

Author(s):
Werner Randelshofer
Version:
$Id: ILBMImageReader.java 299 2013-01-03 07:40:18Z werner $
 
 public class ILBMImageReader extends ImageReader {
 
     private ArrayList<ColorCyclingMemoryImageSourceimages = null;
 
     public ILBMImageReader(ILBMImageReaderSpi originatingProvider) {
         super(originatingProvider);
     }
 
     @Override
     public int getNumImages(boolean allowSearchthrows IOException {
         if (allowSearch &&  == null) {
             readImages();
         }
         return .size();
     }
 
     @Override
     public int getWidth(int imageIndexthrows IOException {
         readImages();
         return .get(imageIndex).getWidth();
     }
 
     @Override
     public int getHeight(int imageIndexthrows IOException {
         readImages();
         return .get(imageIndex).getHeight();
     }
 
     @Override
     public Iterator<ImageTypeSpecifiergetImageTypes(int imageIndexthrows IOException {
         readImages();
         ColorCyclingMemoryImageSource iip = .get(imageIndex);
 
         l.add(new ImageTypeSpecifier(iip.getColorModel(), //
                 iip.getColorModel().createCompatibleSampleModel(iip.getWidth(), iip.getHeight())));
         return l.iterator();
     }

    
Returns the aspect ratio of the given image (that is, its width divided by its height) as a float. For images that are inherently resizable, this method provides a way to determine the appropriate width given a deired height, or vice versa. For non-resizable images, the true width and height are used.

The default implementation simply returns (float)getWidth(imageIndex)/getHeight(imageIndex).

Parameters:
imageIndex the index of the image to be queried.
Returns:
a float indicating the aspect ratio of the given image.
Throws:
java.lang.IllegalStateException if the input source has not been set.
java.lang.IndexOutOfBoundsException if the supplied index is out of bounds.
java.io.IOException if an error occurs during reading.
 
     @Override
     public float getAspectRatio(int imageIndexthrows IOException {
         readImages();
         ColorCyclingMemoryImageSource mis=.get(imageIndex);
         float ratio = (floatgetWidth(imageIndex) / getHeight(imageIndex);
         if (mis.getProperties().containsKey("aspect")) {
             ratio*=(Double)mis.getProperties().get("aspect");
         }
         return ratio;
    }
    @Override
    public IIOMetadata getStreamMetadata() throws IOException {
        return null;
    }
    @Override
    public IIOMetadata getImageMetadata(int imageIndexthrows IOException {
        return null;
    }
    @Override
    public BufferedImage read(int imageIndexImageReadParam param)
            throws IOException {
        readImages();
        return .get(imageIndex).toBufferedImage();
    }
    private void readImages() throws IOException {
        ImageInputStream in = (ImageInputStreamgetInput();
        if ( == null) {
            in.seek(0);
            ILBMDecoder d = new ILBMDecoder(new ImageInputStreamAdapter(in));
             = d.produce();
        }
    }
New to GrepCode? Check out our FAQ X