Java Code Examples for java.awt.image.RenderedImage#getColorModel()

The following examples show how to use java.awt.image.RenderedImage#getColorModel() . 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: AWTImageTools.java    From scifio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Converts a java.awt.image.RenderedImage into a
 * java.awt.image.BufferedImage. This code was adapted from
 * <a href="http://www.jguru.com/faq/view.jsp?EID=114602">a jGuru post</a>.
 */
public static BufferedImage convertRenderedImage(final RenderedImage img) {
	if (img instanceof BufferedImage) return (BufferedImage) img;
	final ColorModel cm = img.getColorModel();
	final int width = img.getWidth();
	final int height = img.getHeight();
	final WritableRaster raster = cm.createCompatibleWritableRaster(width,
		height);
	final boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
	final Hashtable<String, Object> properties = new Hashtable<>();
	final String[] keys = img.getPropertyNames();
	if (keys != null) {
		for (int i = 0; i < keys.length; i++) {
			properties.put(keys[i], img.getProperty(keys[i]));
		}
	}
	final BufferedImage result = new BufferedImage(cm, raster,
		isAlphaPremultiplied, properties);
	img.copyData(raster);
	return result;
}
 
Example 2
Source File: GIFImageWriter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private boolean needToCreateIndex(RenderedImage image) {

        SampleModel sampleModel = image.getSampleModel();
        ColorModel colorModel = image.getColorModel();

        return sampleModel.getNumBands() != 1 ||
            sampleModel.getSampleSize()[0] > 8 ||
            colorModel.getComponentSize()[0] > 8;
    }
 
Example 3
Source File: PaletteBuilder.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
protected PaletteBuilder(RenderedImage src, int size) {
    this.src = src;
    this.srcColorModel = src.getColorModel();
    this.srcRaster = src.getData();

    this.transparency =
        srcColorModel.getTransparency();

    this.requiredSize = size;
}
 
Example 4
Source File: RasterUtils.java    From geowave with Apache License 2.0 5 votes vote down vote up
private static BufferedImage copyImage(
    final int targetWidth,
    final int targetHeight,
    final Color backgroundColor,
    final double[][] noDataValues,
    final RenderedImage originalImage) {
  Hashtable<String, Object> properties = null;

  if (originalImage.getPropertyNames() != null) {
    properties = new Hashtable<>();
    for (final String name : originalImage.getPropertyNames()) {
      properties.put(name, originalImage.getProperty(name));
    }
  }

  final SampleModel sm =
      originalImage.getSampleModel().createCompatibleSampleModel(targetWidth, targetHeight);
  final WritableRaster raster = Raster.createWritableRaster(sm, null);

  final ColorModel colorModel = originalImage.getColorModel();
  final boolean alphaPremultiplied = colorModel.isAlphaPremultiplied();

  RasterUtils.fillWithNoDataValues(raster, noDataValues);
  final BufferedImage image =
      new BufferedImage(colorModel, raster, alphaPremultiplied, properties);
  if (noDataValues == null) {
    final Graphics2D g2D = (Graphics2D) image.getGraphics();
    final Color save = g2D.getColor();
    g2D.setColor(backgroundColor);
    g2D.fillRect(0, 0, image.getWidth(), image.getHeight());
    g2D.setColor(save);
  }
  return image;
}
 
Example 5
Source File: GIFImageWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private boolean needToCreateIndex(RenderedImage image) {

        SampleModel sampleModel = image.getSampleModel();
        ColorModel colorModel = image.getColorModel();

        return sampleModel.getNumBands() != 1 ||
            sampleModel.getSampleSize()[0] > 8 ||
            colorModel.getComponentSize()[0] > 8;
    }
 
Example 6
Source File: PaletteBuilder.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected PaletteBuilder(RenderedImage src, int size) {
    this.src = src;
    this.srcColorModel = src.getColorModel();
    this.srcRaster = src.getData();

    this.transparency =
        srcColorModel.getTransparency();

    this.requiredSize = size;
}
 
Example 7
Source File: GIFImageWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private boolean needToCreateIndex(RenderedImage image) {

        SampleModel sampleModel = image.getSampleModel();
        ColorModel colorModel = image.getColorModel();

        return sampleModel.getNumBands() != 1 ||
            sampleModel.getSampleSize()[0] > 8 ||
            colorModel.getComponentSize()[0] > 8;
    }
 
Example 8
Source File: GIFImageWriter.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private boolean needToCreateIndex(RenderedImage image) {

        SampleModel sampleModel = image.getSampleModel();
        ColorModel colorModel = image.getColorModel();

        return sampleModel.getNumBands() != 1 ||
            sampleModel.getSampleSize()[0] > 8 ||
            colorModel.getComponentSize()[0] > 8;
    }
 
Example 9
Source File: GIFImageWriter.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Writes any extension blocks, the Image Descriptor, and the image data
 *
 * @param image The image.
 * @param imageMetadata The image metadata.
 * @param param The write parameters.
 * @param globalColorTable The Global Color Table.
 * @param sourceBounds The source region.
 * @param destSize The destination dimensions.
 */
private void writeImage(RenderedImage image,
                        GIFWritableImageMetadata imageMetadata,
                        ImageWriteParam param, byte[] globalColorTable,
                        Rectangle sourceBounds, Dimension destSize)
  throws IOException {
    ColorModel colorModel = image.getColorModel();
    SampleModel sampleModel = image.getSampleModel();

    boolean writeGraphicsControlExtension;
    if (imageMetadata == null) {
        // Create default metadata.
        imageMetadata = (GIFWritableImageMetadata)getDefaultImageMetadata(
            new ImageTypeSpecifier(image), param);

        // Set GraphicControlExtension flag only if there is
        // transparency.
        writeGraphicsControlExtension = imageMetadata.transparentColorFlag;
    } else {
        // Check for GraphicControlExtension element.
        NodeList list = null;
        try {
            IIOMetadataNode root = (IIOMetadataNode)
                imageMetadata.getAsTree(IMAGE_METADATA_NAME);
            list = root.getElementsByTagName("GraphicControlExtension");
        } catch(IllegalArgumentException iae) {
            // Should never happen.
        }

        // Set GraphicControlExtension flag if element present.
        writeGraphicsControlExtension =
            list != null && list.getLength() > 0;

        // If progressive mode is not MODE_COPY_FROM_METADATA, ensure
        // the interlacing is set per the ImageWriteParam mode setting.
        if (param != null && param.canWriteProgressive()) {
            if (param.getProgressiveMode() ==
                ImageWriteParam.MODE_DISABLED) {
                imageMetadata.interlaceFlag = false;
            } else if (param.getProgressiveMode() ==
                       ImageWriteParam.MODE_DEFAULT) {
                imageMetadata.interlaceFlag = true;
            }
        }
    }

    // Unset local color table if equal to global color table.
    if (Arrays.equals(globalColorTable, imageMetadata.localColorTable)) {
        imageMetadata.localColorTable = null;
    }

    // Override dimensions
    imageMetadata.imageWidth = destSize.width;
    imageMetadata.imageHeight = destSize.height;

    // Write Graphics Control Extension.
    if (writeGraphicsControlExtension) {
        writeGraphicControlExtension(imageMetadata);
    }

    // Write extension blocks.
    writePlainTextExtension(imageMetadata);
    writeApplicationExtension(imageMetadata);
    writeCommentExtension(imageMetadata);

    // Write Image Descriptor
    int bitsPerPixel =
        getNumBits(imageMetadata.localColorTable == null ?
                   (globalColorTable == null ?
                    sampleModel.getSampleSize(0) :
                    globalColorTable.length/3) :
                   imageMetadata.localColorTable.length/3);
    writeImageDescriptor(imageMetadata, bitsPerPixel);

    // Write image data
    writeRasterData(image, sourceBounds, destSize,
                    param, imageMetadata.interlaceFlag);
}
 
Example 10
Source File: GIFImageWriter.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Writes any extension blocks, the Image Descriptor, and the image data
 *
 * @param iioimage The image and image metadata.
 * @param param The write parameters.
 * @param globalColorTable The Global Color Table.
 * @param sourceBounds The source region.
 * @param destSize The destination dimensions.
 */
private void writeImage(RenderedImage image,
                        GIFWritableImageMetadata imageMetadata,
                        ImageWriteParam param, byte[] globalColorTable,
                        Rectangle sourceBounds, Dimension destSize)
  throws IOException {
    ColorModel colorModel = image.getColorModel();
    SampleModel sampleModel = image.getSampleModel();

    boolean writeGraphicsControlExtension;
    if (imageMetadata == null) {
        // Create default metadata.
        imageMetadata = (GIFWritableImageMetadata)getDefaultImageMetadata(
            new ImageTypeSpecifier(image), param);

        // Set GraphicControlExtension flag only if there is
        // transparency.
        writeGraphicsControlExtension = imageMetadata.transparentColorFlag;
    } else {
        // Check for GraphicControlExtension element.
        NodeList list = null;
        try {
            IIOMetadataNode root = (IIOMetadataNode)
                imageMetadata.getAsTree(IMAGE_METADATA_NAME);
            list = root.getElementsByTagName("GraphicControlExtension");
        } catch(IllegalArgumentException iae) {
            // Should never happen.
        }

        // Set GraphicControlExtension flag if element present.
        writeGraphicsControlExtension =
            list != null && list.getLength() > 0;

        // If progressive mode is not MODE_COPY_FROM_METADATA, ensure
        // the interlacing is set per the ImageWriteParam mode setting.
        if (param != null && param.canWriteProgressive()) {
            if (param.getProgressiveMode() ==
                ImageWriteParam.MODE_DISABLED) {
                imageMetadata.interlaceFlag = false;
            } else if (param.getProgressiveMode() ==
                       ImageWriteParam.MODE_DEFAULT) {
                imageMetadata.interlaceFlag = true;
            }
        }
    }

    // Unset local color table if equal to global color table.
    if (Arrays.equals(globalColorTable, imageMetadata.localColorTable)) {
        imageMetadata.localColorTable = null;
    }

    // Override dimensions
    imageMetadata.imageWidth = destSize.width;
    imageMetadata.imageHeight = destSize.height;

    // Write Graphics Control Extension.
    if (writeGraphicsControlExtension) {
        writeGraphicControlExtension(imageMetadata);
    }

    // Write extension blocks.
    writePlainTextExtension(imageMetadata);
    writeApplicationExtension(imageMetadata);
    writeCommentExtension(imageMetadata);

    // Write Image Descriptor
    int bitsPerPixel =
        getNumBits(imageMetadata.localColorTable == null ?
                   (globalColorTable == null ?
                    sampleModel.getSampleSize(0) :
                    globalColorTable.length/3) :
                   imageMetadata.localColorTable.length/3);
    writeImageDescriptor(imageMetadata, bitsPerPixel);

    // Write image data
    writeRasterData(image, sourceBounds, destSize,
                    param, imageMetadata.interlaceFlag);
}
 
Example 11
Source File: GIFImageWriter.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Writes any extension blocks, the Image Descriptor, and the image data
 *
 * @param iioimage The image and image metadata.
 * @param param The write parameters.
 * @param globalColorTable The Global Color Table.
 * @param sourceBounds The source region.
 * @param destSize The destination dimensions.
 */
private void writeImage(RenderedImage image,
                        GIFWritableImageMetadata imageMetadata,
                        ImageWriteParam param, byte[] globalColorTable,
                        Rectangle sourceBounds, Dimension destSize)
  throws IOException {
    ColorModel colorModel = image.getColorModel();
    SampleModel sampleModel = image.getSampleModel();

    boolean writeGraphicsControlExtension;
    if (imageMetadata == null) {
        // Create default metadata.
        imageMetadata = (GIFWritableImageMetadata)getDefaultImageMetadata(
            new ImageTypeSpecifier(image), param);

        // Set GraphicControlExtension flag only if there is
        // transparency.
        writeGraphicsControlExtension = imageMetadata.transparentColorFlag;
    } else {
        // Check for GraphicControlExtension element.
        NodeList list = null;
        try {
            IIOMetadataNode root = (IIOMetadataNode)
                imageMetadata.getAsTree(IMAGE_METADATA_NAME);
            list = root.getElementsByTagName("GraphicControlExtension");
        } catch(IllegalArgumentException iae) {
            // Should never happen.
        }

        // Set GraphicControlExtension flag if element present.
        writeGraphicsControlExtension =
            list != null && list.getLength() > 0;

        // If progressive mode is not MODE_COPY_FROM_METADATA, ensure
        // the interlacing is set per the ImageWriteParam mode setting.
        if (param != null && param.canWriteProgressive()) {
            if (param.getProgressiveMode() ==
                ImageWriteParam.MODE_DISABLED) {
                imageMetadata.interlaceFlag = false;
            } else if (param.getProgressiveMode() ==
                       ImageWriteParam.MODE_DEFAULT) {
                imageMetadata.interlaceFlag = true;
            }
        }
    }

    // Unset local color table if equal to global color table.
    if (Arrays.equals(globalColorTable, imageMetadata.localColorTable)) {
        imageMetadata.localColorTable = null;
    }

    // Override dimensions
    imageMetadata.imageWidth = destSize.width;
    imageMetadata.imageHeight = destSize.height;

    // Write Graphics Control Extension.
    if (writeGraphicsControlExtension) {
        writeGraphicControlExtension(imageMetadata);
    }

    // Write extension blocks.
    writePlainTextExtension(imageMetadata);
    writeApplicationExtension(imageMetadata);
    writeCommentExtension(imageMetadata);

    // Write Image Descriptor
    int bitsPerPixel =
        getNumBits(imageMetadata.localColorTable == null ?
                   (globalColorTable == null ?
                    sampleModel.getSampleSize(0) :
                    globalColorTable.length/3) :
                   imageMetadata.localColorTable.length/3);
    writeImageDescriptor(imageMetadata, bitsPerPixel);

    // Write image data
    writeRasterData(image, sourceBounds, destSize,
                    param, imageMetadata.interlaceFlag);
}
 
Example 12
Source File: mxPngEncodeParam.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * Returns an instance of <code>PNGEncodeParam.Palette</code>,
 * <code>PNGEncodeParam.Gray</code>, or
 * <code>PNGEncodeParam.RGB</code> appropriate for encoding
 * the given image.
 * <p/>
 * <p> If the image has an <code>IndexColorModel</code>, an
 * instance of <code>PNGEncodeParam.Palette</code> is returned.
 * Otherwise, if the image has 1 or 2 bands an instance of
 * <code>PNGEncodeParam.Gray</code> is returned.  In all other
 * cases an instance of <code>PNGEncodeParam.RGB</code> is
 * returned.
 * <p/>
 * <p> Note that this method does not provide any guarantee that
 * the given image will be successfully encoded by the PNG
 * encoder, as it only performs a very superficial analysis of
 * the image structure.
 */
public static mxPngEncodeParam getDefaultEncodeParam(RenderedImage im) {
  ColorModel colorModel = im.getColorModel();
  if (colorModel instanceof IndexColorModel) {
    return new mxPngEncodeParam.Palette();
  }

  SampleModel sampleModel = im.getSampleModel();
  int numBands = sampleModel.getNumBands();

  if (numBands == 1 || numBands == 2) {
    return new mxPngEncodeParam.Gray();
  }
  else {
    return new mxPngEncodeParam.RGB();
  }
}
 
Example 13
Source File: GIFImageWriter.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Writes any extension blocks, the Image Descriptor, and the image data
 *
 * @param iioimage The image and image metadata.
 * @param param The write parameters.
 * @param globalColorTable The Global Color Table.
 * @param sourceBounds The source region.
 * @param destSize The destination dimensions.
 */
private void writeImage(RenderedImage image,
                        GIFWritableImageMetadata imageMetadata,
                        ImageWriteParam param, byte[] globalColorTable,
                        Rectangle sourceBounds, Dimension destSize)
  throws IOException {
    ColorModel colorModel = image.getColorModel();
    SampleModel sampleModel = image.getSampleModel();

    boolean writeGraphicsControlExtension;
    if (imageMetadata == null) {
        // Create default metadata.
        imageMetadata = (GIFWritableImageMetadata)getDefaultImageMetadata(
            new ImageTypeSpecifier(image), param);

        // Set GraphicControlExtension flag only if there is
        // transparency.
        writeGraphicsControlExtension = imageMetadata.transparentColorFlag;
    } else {
        // Check for GraphicControlExtension element.
        NodeList list = null;
        try {
            IIOMetadataNode root = (IIOMetadataNode)
                imageMetadata.getAsTree(IMAGE_METADATA_NAME);
            list = root.getElementsByTagName("GraphicControlExtension");
        } catch(IllegalArgumentException iae) {
            // Should never happen.
        }

        // Set GraphicControlExtension flag if element present.
        writeGraphicsControlExtension =
            list != null && list.getLength() > 0;

        // If progressive mode is not MODE_COPY_FROM_METADATA, ensure
        // the interlacing is set per the ImageWriteParam mode setting.
        if (param != null && param.canWriteProgressive()) {
            if (param.getProgressiveMode() ==
                ImageWriteParam.MODE_DISABLED) {
                imageMetadata.interlaceFlag = false;
            } else if (param.getProgressiveMode() ==
                       ImageWriteParam.MODE_DEFAULT) {
                imageMetadata.interlaceFlag = true;
            }
        }
    }

    // Unset local color table if equal to global color table.
    if (Arrays.equals(globalColorTable, imageMetadata.localColorTable)) {
        imageMetadata.localColorTable = null;
    }

    // Override dimensions
    imageMetadata.imageWidth = destSize.width;
    imageMetadata.imageHeight = destSize.height;

    // Write Graphics Control Extension.
    if (writeGraphicsControlExtension) {
        writeGraphicControlExtension(imageMetadata);
    }

    // Write extension blocks.
    writePlainTextExtension(imageMetadata);
    writeApplicationExtension(imageMetadata);
    writeCommentExtension(imageMetadata);

    // Write Image Descriptor
    int bitsPerPixel =
        getNumBits(imageMetadata.localColorTable == null ?
                   (globalColorTable == null ?
                    sampleModel.getSampleSize(0) :
                    globalColorTable.length/3) :
                   imageMetadata.localColorTable.length/3);
    writeImageDescriptor(imageMetadata, bitsPerPixel);

    // Write image data
    writeRasterData(image, sourceBounds, destSize,
                    param, imageMetadata.interlaceFlag);
}
 
Example 14
Source File: GIFImageWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Writes any extension blocks, the Image Descriptor, and the image data
 *
 * @param iioimage The image and image metadata.
 * @param param The write parameters.
 * @param globalColorTable The Global Color Table.
 * @param sourceBounds The source region.
 * @param destSize The destination dimensions.
 */
private void writeImage(RenderedImage image,
                        GIFWritableImageMetadata imageMetadata,
                        ImageWriteParam param, byte[] globalColorTable,
                        Rectangle sourceBounds, Dimension destSize)
  throws IOException {
    ColorModel colorModel = image.getColorModel();
    SampleModel sampleModel = image.getSampleModel();

    boolean writeGraphicsControlExtension;
    if (imageMetadata == null) {
        // Create default metadata.
        imageMetadata = (GIFWritableImageMetadata)getDefaultImageMetadata(
            new ImageTypeSpecifier(image), param);

        // Set GraphicControlExtension flag only if there is
        // transparency.
        writeGraphicsControlExtension = imageMetadata.transparentColorFlag;
    } else {
        // Check for GraphicControlExtension element.
        NodeList list = null;
        try {
            IIOMetadataNode root = (IIOMetadataNode)
                imageMetadata.getAsTree(IMAGE_METADATA_NAME);
            list = root.getElementsByTagName("GraphicControlExtension");
        } catch(IllegalArgumentException iae) {
            // Should never happen.
        }

        // Set GraphicControlExtension flag if element present.
        writeGraphicsControlExtension =
            list != null && list.getLength() > 0;

        // If progressive mode is not MODE_COPY_FROM_METADATA, ensure
        // the interlacing is set per the ImageWriteParam mode setting.
        if (param != null && param.canWriteProgressive()) {
            if (param.getProgressiveMode() ==
                ImageWriteParam.MODE_DISABLED) {
                imageMetadata.interlaceFlag = false;
            } else if (param.getProgressiveMode() ==
                       ImageWriteParam.MODE_DEFAULT) {
                imageMetadata.interlaceFlag = true;
            }
        }
    }

    // Unset local color table if equal to global color table.
    if (Arrays.equals(globalColorTable, imageMetadata.localColorTable)) {
        imageMetadata.localColorTable = null;
    }

    // Override dimensions
    imageMetadata.imageWidth = destSize.width;
    imageMetadata.imageHeight = destSize.height;

    // Write Graphics Control Extension.
    if (writeGraphicsControlExtension) {
        writeGraphicControlExtension(imageMetadata);
    }

    // Write extension blocks.
    writePlainTextExtension(imageMetadata);
    writeApplicationExtension(imageMetadata);
    writeCommentExtension(imageMetadata);

    // Write Image Descriptor
    int bitsPerPixel =
        getNumBits(imageMetadata.localColorTable == null ?
                   (globalColorTable == null ?
                    sampleModel.getSampleSize(0) :
                    globalColorTable.length/3) :
                   imageMetadata.localColorTable.length/3);
    writeImageDescriptor(imageMetadata, bitsPerPixel);

    // Write image data
    writeRasterData(image, sourceBounds, destSize,
                    param, imageMetadata.interlaceFlag);
}
 
Example 15
Source File: GIFImageWriter.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Writes any extension blocks, the Image Descriptor, and the image data
 *
 * @param iioimage The image and image metadata.
 * @param param The write parameters.
 * @param globalColorTable The Global Color Table.
 * @param sourceBounds The source region.
 * @param destSize The destination dimensions.
 */
private void writeImage(RenderedImage image,
                        GIFWritableImageMetadata imageMetadata,
                        ImageWriteParam param, byte[] globalColorTable,
                        Rectangle sourceBounds, Dimension destSize)
  throws IOException {
    ColorModel colorModel = image.getColorModel();
    SampleModel sampleModel = image.getSampleModel();

    boolean writeGraphicsControlExtension;
    if (imageMetadata == null) {
        // Create default metadata.
        imageMetadata = (GIFWritableImageMetadata)getDefaultImageMetadata(
            new ImageTypeSpecifier(image), param);

        // Set GraphicControlExtension flag only if there is
        // transparency.
        writeGraphicsControlExtension = imageMetadata.transparentColorFlag;
    } else {
        // Check for GraphicControlExtension element.
        NodeList list = null;
        try {
            IIOMetadataNode root = (IIOMetadataNode)
                imageMetadata.getAsTree(IMAGE_METADATA_NAME);
            list = root.getElementsByTagName("GraphicControlExtension");
        } catch(IllegalArgumentException iae) {
            // Should never happen.
        }

        // Set GraphicControlExtension flag if element present.
        writeGraphicsControlExtension =
            list != null && list.getLength() > 0;

        // If progressive mode is not MODE_COPY_FROM_METADATA, ensure
        // the interlacing is set per the ImageWriteParam mode setting.
        if (param != null && param.canWriteProgressive()) {
            if (param.getProgressiveMode() ==
                ImageWriteParam.MODE_DISABLED) {
                imageMetadata.interlaceFlag = false;
            } else if (param.getProgressiveMode() ==
                       ImageWriteParam.MODE_DEFAULT) {
                imageMetadata.interlaceFlag = true;
            }
        }
    }

    // Unset local color table if equal to global color table.
    if (Arrays.equals(globalColorTable, imageMetadata.localColorTable)) {
        imageMetadata.localColorTable = null;
    }

    // Override dimensions
    imageMetadata.imageWidth = destSize.width;
    imageMetadata.imageHeight = destSize.height;

    // Write Graphics Control Extension.
    if (writeGraphicsControlExtension) {
        writeGraphicControlExtension(imageMetadata);
    }

    // Write extension blocks.
    writePlainTextExtension(imageMetadata);
    writeApplicationExtension(imageMetadata);
    writeCommentExtension(imageMetadata);

    // Write Image Descriptor
    int bitsPerPixel =
        getNumBits(imageMetadata.localColorTable == null ?
                   (globalColorTable == null ?
                    sampleModel.getSampleSize(0) :
                    globalColorTable.length/3) :
                   imageMetadata.localColorTable.length/3);
    writeImageDescriptor(imageMetadata, bitsPerPixel);

    // Write image data
    writeRasterData(image, sourceBounds, destSize,
                    param, imageMetadata.interlaceFlag);
}
 
Example 16
Source File: ImageTypeSpecifier.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * Constructs an {@code ImageTypeSpecifier} from a
 * {@code RenderedImage}.  If a {@code BufferedImage} is
 * being used, one of the factory methods
 * {@code createFromRenderedImage} or
 * {@code createFromBufferedImageType} should be used instead in
 * order to get a more accurate result.
 *
 * @param image a {@code RenderedImage}.
 *
 * @exception IllegalArgumentException if the argument is
 * {@code null}.
 */
public ImageTypeSpecifier(RenderedImage image) {
    if (image == null) {
        throw new IllegalArgumentException("image == null!");
    }
    colorModel = image.getColorModel();
    sampleModel = image.getSampleModel();
}
 
Example 17
Source File: ImageTypeSpecifier.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Constructs an <code>ImageTypeSpecifier</code> from a
 * <code>RenderedImage</code>.  If a <code>BufferedImage</code> is
 * being used, one of the factory methods
 * <code>createFromRenderedImage</code> or
 * <code>createFromBufferedImageType</code> should be used instead in
 * order to get a more accurate result.
 *
 * @param image a <code>RenderedImage</code>.
 *
 * @exception IllegalArgumentException if the argument is
 * <code>null</code>.
 */
public ImageTypeSpecifier(RenderedImage image) {
    if (image == null) {
        throw new IllegalArgumentException("image == null!");
    }
    colorModel = image.getColorModel();
    sampleModel = image.getSampleModel();
}
 
Example 18
Source File: ImageTypeSpecifier.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Constructs an <code>ImageTypeSpecifier</code> from a
 * <code>RenderedImage</code>.  If a <code>BufferedImage</code> is
 * being used, one of the factory methods
 * <code>createFromRenderedImage</code> or
 * <code>createFromBufferedImageType</code> should be used instead in
 * order to get a more accurate result.
 *
 * @param image a <code>RenderedImage</code>.
 *
 * @exception IllegalArgumentException if the argument is
 * <code>null</code>.
 */
public ImageTypeSpecifier(RenderedImage image) {
    if (image == null) {
        throw new IllegalArgumentException("image == null!");
    }
    colorModel = image.getColorModel();
    sampleModel = image.getSampleModel();
}
 
Example 19
Source File: ImageTypeSpecifier.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * Constructs an <code>ImageTypeSpecifier</code> from a
 * <code>RenderedImage</code>.  If a <code>BufferedImage</code> is
 * being used, one of the factory methods
 * <code>createFromRenderedImage</code> or
 * <code>createFromBufferedImageType</code> should be used instead in
 * order to get a more accurate result.
 *
 * @param image a <code>RenderedImage</code>.
 *
 * @exception IllegalArgumentException if the argument is
 * <code>null</code>.
 */
public ImageTypeSpecifier(RenderedImage image) {
    if (image == null) {
        throw new IllegalArgumentException("image == null!");
    }
    colorModel = image.getColorModel();
    sampleModel = image.getSampleModel();
}
 
Example 20
Source File: ImageTypeSpecifier.java    From JDKSourceCode1.8 with MIT License 3 votes vote down vote up
/**
 * Constructs an <code>ImageTypeSpecifier</code> from a
 * <code>RenderedImage</code>.  If a <code>BufferedImage</code> is
 * being used, one of the factory methods
 * <code>createFromRenderedImage</code> or
 * <code>createFromBufferedImageType</code> should be used instead in
 * order to get a more accurate result.
 *
 * @param image a <code>RenderedImage</code>.
 *
 * @exception IllegalArgumentException if the argument is
 * <code>null</code>.
 */
public ImageTypeSpecifier(RenderedImage image) {
    if (image == null) {
        throw new IllegalArgumentException("image == null!");
    }
    colorModel = image.getColorModel();
    sampleModel = image.getSampleModel();
}