javax.imageio.ImageReadParam Java Examples

The following examples show how to use javax.imageio.ImageReadParam. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TIFFRenderedImage.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
public TIFFRenderedImage(TIFFImageReader reader,
                         int imageIndex,
                         ImageReadParam readParam,
                         int width, int height) throws IOException {
    this.reader = reader;
    this.imageIndex = imageIndex;
    this.tileParam = cloneImageReadParam(readParam, false);

    this.subsampleX = tileParam.getSourceXSubsampling();
    this.subsampleY = tileParam.getSourceYSubsampling();

    this.isSubsampling = this.subsampleX != 1 || this.subsampleY != 1;

    this.width = width/subsampleX;
    this.height = height/subsampleY;

    // If subsampling is being used, we may not match the
    // true tile grid exactly, but everything should still work
    this.tileWidth = reader.getTileWidth(imageIndex)/subsampleX;
    this.tileHeight = reader.getTileHeight(imageIndex)/subsampleY;

    Iterator<ImageTypeSpecifier> iter = reader.getImageTypes(imageIndex);
    this.its = iter.next();
    tileParam.setDestinationType(its);
}
 
Example #2
Source File: ImageUtils.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static BufferedImage readBuffereImage(ImageReader reader, int w, int h) throws IOException {
    ImageReadParam param = reader.getDefaultReadParam();
    int srcWidth = reader.getWidth(0);
    int srcHeight = reader.getHeight(0);

    Rectangle rect = null;

    if ((float) w / h > (float) srcWidth / srcHeight) {
        h = h * srcWidth / w;
        w = srcWidth;
        rect = new Rectangle(0, (srcHeight - h) / 2, w, h);
    } else {
        w = w * srcHeight / h;
        h = srcHeight;
        rect = new Rectangle((srcWidth - w) / 2, 0, w, h);
    }
    param.setSourceRegion(rect);
    BufferedImage srcBuffered = reader.read(0, param);
    return srcBuffered;
}
 
Example #3
Source File: BigBufferedImage.java    From OpenRS with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ImagePartLoader call() throws Exception {
    Thread.currentThread().setPriority((Thread.MIN_PRIORITY + Thread.NORM_PRIORITY) / 2);
    try (ImageInputStream stream = ImageIO.createImageInputStream(file);) {
        Iterator<ImageReader> readers = ImageIO.getImageReaders(stream);
        if (readers.hasNext()) {
            ImageReader reader = readers.next();
            reader.setInput(stream, true, true);
            ImageReadParam param = reader.getDefaultReadParam();
            param.setSourceRegion(region);
            BufferedImage part = reader.read(0, param);
            Raster source = part.getRaster();
            WritableRaster target = image.getRaster();
            target.setRect(0, y, source);
        }
    }
    return ImagePartLoader.this;
}
 
Example #4
Source File: PNGImageReader.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public BufferedImage read(int imageIndex, ImageReadParam param)
    throws IIOException {
    if (imageIndex != 0) {
        throw new IndexOutOfBoundsException("imageIndex != 0!");
    }

    readImage(param);
    return theImage;
}
 
Example #5
Source File: ReadAsGrayTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void testType(ImageReader reader,
                             ImageTypeSpecifier t,
                             BufferedImage src)
    throws IOException
{
    ImageReadParam p = reader.getDefaultReadParam();
    p.setDestinationType(t);
    BufferedImage dst = reader.read(0, p);

    verify(src, dst, t);
}
 
Example #6
Source File: PNGImageReader.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public BufferedImage read(int imageIndex, ImageReadParam param)
    throws IIOException {
    if (imageIndex != 0) {
        throw new IndexOutOfBoundsException("imageIndex != 0!");
    }

    readImage(param);
    return theImage;
}
 
Example #7
Source File: ImageFileReaders.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static BufferedImage readFileByWidth(String format, String filename,
            int width) {
        BufferedImage bufferedImage;
        int scale = 1;
        try {
            if ("ico".equals(format) || "icon".equals(format)) {
                bufferedImage = readIcon(new File(filename));
                return ImageManufacture.scaleImageWidthKeep(bufferedImage, width);
            }
            ImageReader reader = getReader(format);
            try ( ImageInputStream in = ImageIO.createImageInputStream(new BufferedInputStream(new FileInputStream(filename)))) {
                reader.setInput(in, false);
                if (reader.getWidth(0) <= width) {
                    scale = 1;
                } else {
                    scale = reader.getWidth(0) / width + 1;
                    if (scale < 2) {
                        scale = 2;
                    }
                }
                ImageReadParam param = reader.getDefaultReadParam();
                param.setSourceSubsampling(scale, scale, 0, 0);
                bufferedImage = reader.read(0, param);
//                logger.debug(bufferedImage.getWidth() + " " + bufferedImage.getHeight());
                reader.dispose();
            }
        } catch (Exception e) {
            bufferedImage = readBrokenImage(e, new File(filename), scale);
        }
        return bufferedImage;
    }
 
Example #8
Source File: AppletResourceTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static BufferedImage getDestination(ImageReadParam param,
                                           Iterator imageTypes,
                                           int width,
                                           int height) throws IIOException {
    return ImageReader.getDestination(param,
                                      imageTypes,
                                      width,
                                      height);
}
 
Example #9
Source File: PNGImageReader.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
public BufferedImage read(int imageIndex, ImageReadParam param)
    throws IIOException {
    if (imageIndex != 0) {
        throw new IndexOutOfBoundsException("imageIndex != 0!");
    }

    readImage(param);
    return theImage;
}
 
Example #10
Source File: PNGImageReader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public BufferedImage read(int imageIndex, ImageReadParam param)
    throws IIOException {
    if (imageIndex != 0) {
        throw new IndexOutOfBoundsException("imageIndex != 0!");
    }

    readImage(param);
    return theImage;
}
 
Example #11
Source File: UserPluginMetadataFormatTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static BufferedImage getDestination(ImageReadParam param,
                                           Iterator imageTypes,
                                           int width,
                                           int height)
  throws IIOException {
    return ImageReader.getDestination(param,
                                      imageTypes,
                                      width,
                                      height);
}
 
Example #12
Source File: AppletResourceTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void checkReadParamBandSettings(ImageReadParam param,
                                              int numSrcBands,
                                              int numDstBands) {
    ImageReader.checkReadParamBandSettings( param,
                                            numSrcBands,
                                            numDstBands);
}
 
Example #13
Source File: AppletResourceTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void checkReadParamBandSettings(ImageReadParam param,
                                              int numSrcBands,
                                              int numDstBands) {
    ImageReader.checkReadParamBandSettings( param,
                                            numSrcBands,
                                            numDstBands);
}
 
Example #14
Source File: UserPluginMetadataFormatTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public BufferedImage read(int imageIndex, ImageReadParam param)
  throws IOException {
    if (input == null)
        throw new IllegalStateException();
    if (imageIndex >= 5 || imageIndex < 0)
        throw new IndexOutOfBoundsException();
    if (seekForwardOnly) {
        if (imageIndex < minIndex)
            throw new IndexOutOfBoundsException();
        minIndex = imageIndex;
    }

    return getDestination(param, getImageTypes(imageIndex), 10, 15);
}
 
Example #15
Source File: ReadAsGrayTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void testType(ImageReader reader,
                             ImageTypeSpecifier t,
                             BufferedImage src)
    throws IOException
{
    ImageReadParam p = reader.getDefaultReadParam();
    p.setDestinationType(t);
    BufferedImage dst = reader.read(0, p);

    verify(src, dst, t);
}
 
Example #16
Source File: ImageReadParamPasses.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void test(int minPass, int numPasses) {
    ImageReadParam param = new ImageReadParam();

    param.setSourceProgressivePasses(minPass, numPasses);
    expect(param.getSourceMinProgressivePass(), minPass);
    expect(param.getSourceNumProgressivePasses(), numPasses);

    int maxPass = numPasses == maxint ? maxint : minPass + numPasses - 1;
    expect(param.getSourceMaxProgressivePass(), maxPass);
}
 
Example #17
Source File: BufferedImageHttpMessageConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public BufferedImage read(Class<? extends BufferedImage> clazz, HttpInputMessage inputMessage)
		throws IOException, HttpMessageNotReadableException {

	ImageInputStream imageInputStream = null;
	ImageReader imageReader = null;
	try {
		imageInputStream = createImageInputStream(inputMessage.getBody());
		MediaType contentType = inputMessage.getHeaders().getContentType();
		Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(contentType.toString());
		if (imageReaders.hasNext()) {
			imageReader = imageReaders.next();
			ImageReadParam irp = imageReader.getDefaultReadParam();
			process(irp);
			imageReader.setInput(imageInputStream, true);
			return imageReader.read(0, irp);
		}
		else {
			throw new HttpMessageNotReadableException(
					"Could not find javax.imageio.ImageReader for Content-Type [" + contentType + "]");
		}
	}
	finally {
		if (imageReader != null) {
			imageReader.dispose();
		}
		if (imageInputStream != null) {
			try {
				imageInputStream.close();
			}
			catch (IOException ex) {
				// ignore
			}
		}
	}
}
 
Example #18
Source File: ReadAsGrayTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void testType(ImageReader reader,
                             ImageTypeSpecifier t,
                             BufferedImage src)
    throws IOException
{
    ImageReadParam p = reader.getDefaultReadParam();
    p.setDestinationType(t);
    BufferedImage dst = reader.read(0, p);

    verify(src, dst, t);
}
 
Example #19
Source File: ImageReaderGetDestination.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static BufferedImage getDestination(ImageReadParam param,
                                           Iterator imageTypes,
                                           int width,
                                           int height)
  throws IIOException {
    return ImageReader.getDestination(param, imageTypes, width, height);
}
 
Example #20
Source File: HtmlTagBasedGenerator.java    From fess with Apache License 2.0 5 votes vote down vote up
protected Result saveImage(final ImageInputStream input, final File outputFile) throws IOException {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final Iterator<ImageReader> readers = ImageIO.getImageReaders(input);
    if (readers.hasNext()) {
        final ImageReader reader = readers.next();
        try {
            reader.setInput(input);
            final ImageReadParam param = reader.getDefaultReadParam();
            final int width = reader.getWidth(0);
            final int height = reader.getHeight(0);
            if (width <= 0 || height <= 0) {
                return Result.NO_IMAGE;
            }
            if (!fessConfig.validateThumbnailSize(width, height)) {
                return Result.INVALID_SIZE;
            }
            final int samplingWidth = width / fessConfig.getThumbnailHtmlImageThumbnailWidthAsInteger();
            final int samplingHeight = height / fessConfig.getThumbnailHtmlImageThumbnailHeightAsInteger();
            param.setSourceSubsampling(samplingWidth <= 0 ? 1 : samplingWidth, samplingHeight <= 0 ? 1 : samplingHeight, 0, 0);
            param.setSourceRegion(new Rectangle(width, height > width ? width : height));
            final BufferedImage image = reader.read(0, param);
            final int thumbnailWidth = fessConfig.getThumbnailHtmlImageThumbnailWidthAsInteger();
            final int thumbnailHeight =
                    (int) ((height > width ? width : height) * fessConfig.getThumbnailHtmlImageThumbnailWidthAsInteger().floatValue() / width);
            final BufferedImage thumbnail = new BufferedImage(thumbnailWidth, thumbnailHeight, image.getType());
            thumbnail.getGraphics().drawImage(image.getScaledInstance(thumbnailWidth, thumbnailHeight, Image.SCALE_AREA_AVERAGING), 0,
                    0, thumbnailWidth, thumbnailHeight, null);
            ImageIO.write(thumbnail, fessConfig.getThumbnailHtmlImageFormat(), outputFile);
            image.flush();
            return Result.OK;
        } finally {
            reader.dispose();
        }
    }
    return Result.FAILED;
}
 
Example #21
Source File: WebPReader.java    From webp-imageio with Apache License 2.0 5 votes vote down vote up
@Override
public BufferedImage read( int imageIndex, ImageReadParam param ) throws IOException {
  checkIndex( imageIndex );
  readData();
  readHeader();
  WebPReadParam options = param != null ? (WebPReadParam) param : new WebPReadParam();
  return WebP.decode( options, fData, 0, fData.length );
}
 
Example #22
Source File: AppletResourceTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public BufferedImage read(int imageIndex, ImageReadParam param)
  throws IOException {
    if (input == null)
        throw new IllegalStateException();
    if (imageIndex >= 5 || imageIndex < 0)
        throw new IndexOutOfBoundsException();
    if (seekForwardOnly) {
        if (imageIndex < minIndex)
            throw new IndexOutOfBoundsException();
        minIndex = imageIndex;
    }

    return getDestination(param, getImageTypes(imageIndex), 10, 15);
}
 
Example #23
Source File: ReadAsGrayTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void testType(ImageReader reader,
                             ImageTypeSpecifier t,
                             BufferedImage src)
    throws IOException
{
    ImageReadParam p = reader.getDefaultReadParam();
    p.setDestinationType(t);
    BufferedImage dst = reader.read(0, p);

    verify(src, dst, t);
}
 
Example #24
Source File: UserPluginMetadataFormatTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static BufferedImage getDestination(ImageReadParam param,
                                           Iterator imageTypes,
                                           int width,
                                           int height)
  throws IIOException {
    return ImageReader.getDestination(param,
                                      imageTypes,
                                      width,
                                      height);
}
 
Example #25
Source File: UserPluginMetadataFormatTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void computeRegions(ImageReadParam param,
                                  int srcWidth,
                                  int srcHeight,
                                  BufferedImage image,
                                  Rectangle srcRegion,
                                  Rectangle destRegion) {
    ImageReader.computeRegions(param,
                               srcWidth,
                               srcHeight,
                               image,
                               srcRegion,
                               destRegion);
}
 
Example #26
Source File: ReadAsGrayTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static void testType(ImageReader reader,
                             ImageTypeSpecifier t,
                             BufferedImage src)
    throws IOException
{
    ImageReadParam p = reader.getDefaultReadParam();
    p.setDestinationType(t);
    BufferedImage dst = reader.read(0, p);

    verify(src, dst, t);
}
 
Example #27
Source File: BufferedImageHttpMessageConverter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public BufferedImage read(@Nullable Class<? extends BufferedImage> clazz, HttpInputMessage inputMessage)
		throws IOException, HttpMessageNotReadableException {

	ImageInputStream imageInputStream = null;
	ImageReader imageReader = null;
	try {
		imageInputStream = createImageInputStream(inputMessage.getBody());
		MediaType contentType = inputMessage.getHeaders().getContentType();
		if (contentType == null) {
			throw new HttpMessageNotReadableException("No Content-Type header", inputMessage);
		}
		Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(contentType.toString());
		if (imageReaders.hasNext()) {
			imageReader = imageReaders.next();
			ImageReadParam irp = imageReader.getDefaultReadParam();
			process(irp);
			imageReader.setInput(imageInputStream, true);
			return imageReader.read(0, irp);
		}
		else {
			throw new HttpMessageNotReadableException(
					"Could not find javax.imageio.ImageReader for Content-Type [" + contentType + "]",
					inputMessage);
		}
	}
	finally {
		if (imageReader != null) {
			imageReader.dispose();
		}
		if (imageInputStream != null) {
			try {
				imageInputStream.close();
			}
			catch (IOException ex) {
				// ignore
			}
		}
	}
}
 
Example #28
Source File: MJPGImageReader.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BufferedImage read(int imageIndex, ImageReadParam param) throws IOException {
    if (imageIndex > 0) {
        throw new IndexOutOfBoundsException();
    }
    readHeader();

    return image;
}
 
Example #29
Source File: UserPluginMetadataFormatTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void checkReadParamBandSettings(ImageReadParam param,
                                              int numSrcBands,
                                              int numDstBands) {
    ImageReader.checkReadParamBandSettings( param,
                                            numSrcBands,
                                            numDstBands);
}
 
Example #30
Source File: J2KImageReadParamJava.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 5 votes vote down vote up
public J2KImageReadParamJava(ImageReadParam param) {
    super();

    // Generic settings.
    if(param.hasController()) {
        setController(param.getController());
    }
    setSourceRegion(param.getSourceRegion());
    setSourceBands(param.getSourceBands());
    setDestinationBands(param.getDestinationBands());
    setDestination(param.getDestination());

    setDestinationOffset(param.getDestinationOffset());
    setSourceSubsampling(param.getSourceXSubsampling(),
                         param.getSourceYSubsampling(),
                         param.getSubsamplingXOffset(),
                         param.getSubsamplingYOffset());
    setDestinationType(param.getDestinationType());

    // J2K settings.
    J2KImageReadParam j2kParam;
    if(param instanceof J2KImageReadParam) {
        j2kParam = (J2KImageReadParam)param;
    } else {
        j2kParam = new J2KImageReadParam();
    }
    setDecodingRate(j2kParam.getDecodingRate());
    setResolution(j2kParam.getResolution());
}