javax.imageio.ImageTypeSpecifier Java Examples

The following examples show how to use javax.imageio.ImageTypeSpecifier. 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: JPEGImageWriter.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void checkAdobe(AdobeMarkerSegment adobe,
                       ImageTypeSpecifier type,
                       boolean input) {
    if (adobe != null) {
        int rightTransform = JPEG.transformForType(type, input);
        if (adobe.transform != rightTransform) {
            warningOccurred(input
                            ? WARNING_IMAGE_METADATA_ADOBE_MISMATCH
                            : WARNING_DEST_METADATA_ADOBE_MISMATCH);
            if (rightTransform == JPEG.ADOBE_IMPOSSIBLE) {
                ignoreAdobe = true;
            } else {
                newAdobeTransform = rightTransform;
            }
        }
    }
}
 
Example #2
Source File: GIFImageWriterSpi.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
public boolean canEncodeImage(ImageTypeSpecifier type) {
    if (type == null) {
        throw new IllegalArgumentException("type == null!");
    }

    SampleModel sm = type.getSampleModel();
    ColorModel cm = type.getColorModel();

    boolean canEncode = sm.getNumBands() == 1 &&
        sm.getSampleSize(0) <= 8 &&
        sm.getWidth() <= 65535 &&
        sm.getHeight() <= 65535 &&
        (cm == null || cm.getComponentSize()[0] <= 8);

    if (canEncode) {
        return true;
    } else {
        return PaletteBuilder.canCreatePalette(type);
    }
}
 
Example #3
Source File: JPEG.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Given an image type, return the Adobe transform corresponding to
 * that type, or ADOBE_IMPOSSIBLE if the image type is incompatible
 * with an Adobe marker segment.  If <code>input</code> is true, then
 * the image type is considered before colorspace conversion.
 */
static int transformForType(ImageTypeSpecifier imageType, boolean input) {
    int retval = ADOBE_IMPOSSIBLE;
    ColorModel cm = imageType.getColorModel();
    switch (cm.getColorSpace().getType()) {
    case ColorSpace.TYPE_GRAY:
        retval = ADOBE_UNKNOWN;
        break;
    case ColorSpace.TYPE_RGB:
        retval = input ? ADOBE_YCC : ADOBE_UNKNOWN;
        break;
    case ColorSpace.TYPE_YCbCr:
        retval = ADOBE_YCC;
        break;
    case ColorSpace.TYPE_CMYK:
        retval = input ? ADOBE_YCCK : ADOBE_IMPOSSIBLE;
    }
    return retval;
}
 
Example #4
Source File: GIFImageWriterSpi.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public boolean canEncodeImage(ImageTypeSpecifier type) {
    if (type == null) {
        throw new IllegalArgumentException("type == null!");
    }

    SampleModel sm = type.getSampleModel();
    ColorModel cm = type.getColorModel();

    boolean canEncode = sm.getNumBands() == 1 &&
        sm.getSampleSize(0) <= 8 &&
        sm.getWidth() <= 65535 &&
        sm.getHeight() <= 65535 &&
        (cm == null || cm.getComponentSize()[0] <= 8);

    if (canEncode) {
        return true;
    } else {
        return PaletteBuilder.canCreatePalette(type);
    }
}
 
Example #5
Source File: JPEGImageReader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public ImageTypeSpecifier getRawImageType(int imageIndex)
    throws IOException {
    setThreadLock();
    try {
        if (currentImage != imageIndex) {
            cbLock.check();

            readHeader(imageIndex, true);
        }

        // Returns null if it can't be represented
        return getImageType(colorSpaceCode).getType();
    } finally {
        clearThreadLock();
    }
}
 
Example #6
Source File: MergeStdCommentTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    String format = "javax_imageio_1.0";
    BufferedImage img =
        new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
    ImageWriter iw = ImageIO.getImageWritersByMIMEType("image/png").next();
    IIOMetadata meta =
        iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), null);
    DOMImplementationRegistry registry;
    registry = DOMImplementationRegistry.newInstance();
    DOMImplementation impl = registry.getDOMImplementation("XML 3.0");
    Document doc = impl.createDocument(null, format, null);
    Element root, text, entry;
    root = doc.getDocumentElement();
    root.appendChild(text = doc.createElement("Text"));
    text.appendChild(entry = doc.createElement("TextEntry"));
    // keyword isn't #REQUIRED by the standard metadata format.
    // However, it is required by the PNG format, so we include it here.
    entry.setAttribute("keyword", "Comment");
    entry.setAttribute("value", "Some demo comment");
    meta.mergeTree(format, root);
}
 
Example #7
Source File: JPEG.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Given an image type, return the Adobe transform corresponding to
 * that type, or ADOBE_IMPOSSIBLE if the image type is incompatible
 * with an Adobe marker segment.  If <code>input</code> is true, then
 * the image type is considered before colorspace conversion.
 */
static int transformForType(ImageTypeSpecifier imageType, boolean input) {
    int retval = ADOBE_IMPOSSIBLE;
    ColorModel cm = imageType.getColorModel();
    switch (cm.getColorSpace().getType()) {
    case ColorSpace.TYPE_GRAY:
        retval = ADOBE_UNKNOWN;
        break;
    case ColorSpace.TYPE_RGB:
        retval = input ? ADOBE_YCC : ADOBE_UNKNOWN;
        break;
    case ColorSpace.TYPE_YCbCr:
        retval = ADOBE_YCC;
        break;
    case ColorSpace.TYPE_CMYK:
        retval = input ? ADOBE_YCCK : ADOBE_IMPOSSIBLE;
    }
    return retval;
}
 
Example #8
Source File: ShortHistogramTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
protected File writeImageWithHist(BufferedImage bi) throws IOException {
    File f = File.createTempFile("hist_", ".png", new File("."));

    ImageWriter writer = ImageIO.getImageWritersByFormatName("PNG").next();

    ImageOutputStream ios = ImageIO.createImageOutputStream(f);
    writer.setOutput(ios);

    ImageWriteParam param = writer.getDefaultWriteParam();
    ImageTypeSpecifier type = new ImageTypeSpecifier(bi);

    IIOMetadata imgMetadata = writer.getDefaultImageMetadata(type, param);

    /* add hIST node to image metadata */
    imgMetadata = upgradeMetadata(imgMetadata, bi);

    IIOImage iio_img = new IIOImage(bi,
                                    null, // no thumbnails
                                    imgMetadata);

    writer.write(iio_img);
    ios.flush();
    ios.close();
    return f;
}
 
Example #9
Source File: JPEGImageReader.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public ImageTypeSpecifier getRawImageType(int imageIndex)
    throws IOException {
    setThreadLock();
    try {
        if (currentImage != imageIndex) {
            cbLock.check();

            readHeader(imageIndex, true);
        }

        // Returns null if it can't be represented
        return getImageType(colorSpaceCode).getType();
    } finally {
        clearThreadLock();
    }
}
 
Example #10
Source File: TIFFImageWriter.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
public void prepareInsertEmpty(int imageIndex,
                               ImageTypeSpecifier imageType,
                               int width,
                               int height,
                               IIOMetadata imageMetadata,
                               List<? extends BufferedImage> thumbnails,
                               ImageWriteParam param) throws IOException {
    checkParamsEmpty(imageType, width, height, thumbnails);

    this.isInsertingEmpty = true;

    SampleModel emptySM = imageType.getSampleModel();
    RenderedImage emptyImage =
        new EmptyImage(0, 0, width, height,
                       0, 0, emptySM.getWidth(), emptySM.getHeight(),
                       emptySM, imageType.getColorModel());

    insert(imageIndex, new IIOImage(emptyImage, null, imageMetadata),
           param, false);
}
 
Example #11
Source File: JPEGImageWriter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void checkAdobe(AdobeMarkerSegment adobe,
                       ImageTypeSpecifier type,
                       boolean input) {
    if (adobe != null) {
        int rightTransform = JPEG.transformForType(type, input);
        if (adobe.transform != rightTransform) {
            warningOccurred(input
                            ? WARNING_IMAGE_METADATA_ADOBE_MISMATCH
                            : WARNING_DEST_METADATA_ADOBE_MISMATCH);
            if (rightTransform == JPEG.ADOBE_IMPOSSIBLE) {
                ignoreAdobe = true;
            } else {
                newAdobeTransform = rightTransform;
            }
        }
    }
}
 
Example #12
Source File: JpegRawImageTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        //nomarkers.jpg has YCbCr color space
        String fileName = "nomarkers.jpg";
        String sep = System.getProperty("file.separator");
        String dir = System.getProperty("test.src", ".");
        String filePath = dir+sep+fileName;
        System.out.println("Test file: " + filePath);
        File imageFile = new File(filePath);

        ImageInputStream inputStream = ImageIO.
            createImageInputStream(imageFile);
        Iterator<ImageReader> readers = ImageIO.getImageReaders(inputStream);

        if(readers.hasNext()) {
            ImageReader reader = readers.next();
            reader.setInput(inputStream);

            ImageTypeSpecifier typeSpecifier = reader.getRawImageType(0);
            //check if ImageTypeSpecifier is null for YCbCr JPEG Image
            if (typeSpecifier == null) {
                throw new RuntimeException("ImageReader returns null raw image"
                    + " type");
            }
        }
    }
 
Example #13
Source File: BMPImageWriterSpi.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public boolean canEncodeImage(ImageTypeSpecifier type) {
    int dataType= type.getSampleModel().getDataType();
    if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_INT)
        return false;

    SampleModel sm = type.getSampleModel();
    int numBands = sm.getNumBands();
    if (!(numBands == 1 || numBands == 3))
        return false;

    if (numBands == 1 && dataType != DataBuffer.TYPE_BYTE)
        return false;

    if (dataType > DataBuffer.TYPE_BYTE &&
          !(sm instanceof SinglePixelPackedSampleModel))
        return false;

    return true;
}
 
Example #14
Source File: GIFImageWriterSpi.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public boolean canEncodeImage(ImageTypeSpecifier type) {
    if (type == null) {
        throw new IllegalArgumentException("type == null!");
    }

    SampleModel sm = type.getSampleModel();
    ColorModel cm = type.getColorModel();

    boolean canEncode = sm.getNumBands() == 1 &&
        sm.getSampleSize(0) <= 8 &&
        sm.getWidth() <= 65535 &&
        sm.getHeight() <= 65535 &&
        (cm == null || cm.getComponentSize()[0] <= 8);

    if (canEncode) {
        return true;
    } else {
        return PaletteBuilder.canCreatePalette(type);
    }
}
 
Example #15
Source File: BMPImageWriterSpi.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public boolean canEncodeImage(ImageTypeSpecifier type) {
    int dataType= type.getSampleModel().getDataType();
    if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_INT)
        return false;

    SampleModel sm = type.getSampleModel();
    int numBands = sm.getNumBands();
    if (!(numBands == 1 || numBands == 3))
        return false;

    if (numBands == 1 && dataType != DataBuffer.TYPE_BYTE)
        return false;

    if (dataType > DataBuffer.TYPE_BYTE &&
          !(sm instanceof SinglePixelPackedSampleModel))
        return false;

    return true;
}
 
Example #16
Source File: ImageReaderReadAll.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public Iterator getImageTypes(int imageIndex) throws IOException {
    if (input == null)
        throw new IllegalStateException();
    if (imageIndex >= 1 || imageIndex < 0)
        throw new IndexOutOfBoundsException();

    Vector imageTypes = new Vector();
    imageTypes.add(ImageTypeSpecifier.createFromBufferedImageType
                   (BufferedImage.TYPE_BYTE_GRAY ));
    return imageTypes.iterator();
}
 
Example #17
Source File: JPEG.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns <code>true</code> if the given imageType can be used
 * in a JFIF file.  If <code>input</code> is true, then the
 * image type is considered before colorspace conversion.
 */
static boolean isJFIFcompliant(ImageTypeSpecifier imageType,
                               boolean input) {
    ColorModel cm = imageType.getColorModel();
    // Can't have alpha
    if (cm.hasAlpha()) {
        return false;
    }
    // Gray is OK, always
    int numComponents = imageType.getNumComponents();
    if (numComponents == 1) {
        return true;
    }

    // If it isn't gray, it must have 3 channels
    if (numComponents != 3) {
        return false;
    }

    if (input) {
        // Must be RGB
        if (cm.getColorSpace().getType() == ColorSpace.TYPE_RGB) {
            return true;
        }
    } else {
        // Must be YCbCr
        if (cm.getColorSpace().getType() == ColorSpace.TYPE_YCbCr) {
            return true;
        }
    }

    return false;
}
 
Example #18
Source File: JPEGImageWriter.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private int getDestCSType(ImageTypeSpecifier destType) {
ColorModel cm = destType.getColorModel();
boolean alpha = cm.hasAlpha();
ColorSpace cs = cm.getColorSpace();
int retval = JPEG.JCS_UNKNOWN;
switch (cs.getType()) {
case ColorSpace.TYPE_GRAY:
        retval = JPEG.JCS_GRAYSCALE;
        break;
    case ColorSpace.TYPE_RGB:
        if (alpha) {
            retval = JPEG.JCS_RGBA;
        } else {
            retval = JPEG.JCS_RGB;
        }
        break;
    case ColorSpace.TYPE_YCbCr:
        if (alpha) {
            retval = JPEG.JCS_YCbCrA;
        } else {
            retval = JPEG.JCS_YCbCr;
        }
        break;
    case ColorSpace.TYPE_3CLR:
        if (cs == JPEG.JCS.getYCC()) {
            if (alpha) {
                retval = JPEG.JCS_YCCA;
            } else {
                retval = JPEG.JCS_YCC;
            }
        }
    case ColorSpace.TYPE_CMYK:
        retval = JPEG.JCS_CMYK;
        break;
    }
return retval;
}
 
Example #19
Source File: JPEGImageReader.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public ImageTypeSpecifier next() {
    if (theNext != null || hasNext()) {
        ImageTypeSpecifier t = theNext;
        theNext = null;
        return t;
    } else {
        throw new NoSuchElementException();
    }
}
 
Example #20
Source File: JPEGImageReader.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public synchronized ImageTypeSpecifier getType() {
    if (!failed && type == null) {
        try {
            type = produce();
        } catch (Throwable e) {
            failed = true;
        }
    }
    return type;
}
 
Example #21
Source File: JPEG.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns <code>true</code> if the given imageType can be used
 * in a JFIF file.  If <code>input</code> is true, then the
 * image type is considered before colorspace conversion.
 */
static boolean isJFIFcompliant(ImageTypeSpecifier imageType,
                               boolean input) {
    ColorModel cm = imageType.getColorModel();
    // Can't have alpha
    if (cm.hasAlpha()) {
        return false;
    }
    // Gray is OK, always
    int numComponents = imageType.getNumComponents();
    if (numComponents == 1) {
        return true;
    }

    // If it isn't gray, it must have 3 channels
    if (numComponents != 3) {
        return false;
    }

    if (input) {
        // Must be RGB
        if (cm.getColorSpace().getType() == ColorSpace.TYPE_RGB) {
            return true;
        }
    } else {
        // Must be YCbCr
        if (cm.getColorSpace().getType() == ColorSpace.TYPE_YCbCr) {
            return true;
        }
    }

    return false;
}
 
Example #22
Source File: JPEGMetadataFormat.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public boolean canNodeAppear(String elementName,
                             ImageTypeSpecifier imageType) {
    // Just check if it appears in the format
    if (isInSubtree(elementName, getRootName())){
        return true;
    }
    return false;
}
 
Example #23
Source File: JPEGImageReader.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public synchronized ImageTypeSpecifier getType() {
    if (!failed && type == null) {
        try {
            type = produce();
        } catch (Throwable e) {
            failed = true;
        }
    }
    return type;
}
 
Example #24
Source File: JPEGMetadataFormat.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public boolean canNodeAppear(String elementName,
                             ImageTypeSpecifier imageType) {
    // Just check if it appears in the format
    if (isInSubtree(elementName, getRootName())){
        return true;
    }
    return false;
}
 
Example #25
Source File: GIFImageWriter.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a default image metadata object and merges in the
 * supplied metadata.
 */
public IIOMetadata convertImageMetadata(IIOMetadata inData,
                                        ImageTypeSpecifier imageType,
                                        ImageWriteParam param) {
    if (inData == null) {
        throw new IllegalArgumentException("inData == null!");
    }
    if (imageType == null) {
        throw new IllegalArgumentException("imageType == null!");
    }

    GIFWritableImageMetadata im =
        (GIFWritableImageMetadata)getDefaultImageMetadata(imageType,
                                                          param);

    // Save interlace flag state.

    boolean isProgressive = im.interlaceFlag;

    convertMetadata(IMAGE_METADATA_NAME, inData, im);

    // Undo change to interlace flag if not MODE_COPY_FROM_METADATA.

    if (param != null && param.canWriteProgressive() &&
        param.getProgressiveMode() != param.MODE_COPY_FROM_METADATA) {
        im.interlaceFlag = isProgressive;
    }

    return im;
}
 
Example #26
Source File: BMPSubsamplingTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private boolean canEncodeImage(String compression,
                               ImageTypeSpecifier imgType, int rawType)
{
    int biType = imgType.getBufferedImageType();
    if ((!compression.equals("BI_BITFIELDS")) &&
        ((rawType == BufferedImage.TYPE_USHORT_565_RGB) ||
         (rawType == TYPE_USHORT_565_BGR)))
    {
        return false;
    }

    int bpp = imgType.getColorModel().getPixelSize();
    if (compression.equals("BI_RLE4") && bpp != 4) {
        // only 4bpp images can be encoded as BI_RLE4
        return false;
    }
    if (compression.equals("BI_RLE8") && bpp != 8) {
        // only 8bpp images can be encoded as BI_RLE8
        return false;
    }

    if (compression.equals("BI_PNG") &&
        ((rawType == TYPE_USHORT_555_GRB) ||
         (rawType == TYPE_USHORT_555_BGR)))
    {
        return false;
    }

    return true;
}
 
Example #27
Source File: AppletResourceTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public Iterator getImageTypes(int imageIndex) throws IOException {
    if (input == null)
        throw new IllegalStateException();
    if (imageIndex >= 5 || imageIndex < 0)
        throw new IndexOutOfBoundsException();

    Vector imageTypes = new Vector();
    imageTypes.add(ImageTypeSpecifier.createFromBufferedImageType
                   (BufferedImage.TYPE_BYTE_GRAY ));
    return imageTypes.iterator();
}
 
Example #28
Source File: ImagePnmFile.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static IIOMetadata getWriterMeta(ImageAttributes attributes, BufferedImage image,
        ImageWriter writer, ImageWriteParam param) {
    try {
        PNMMetadata metaData = (PNMMetadata) writer.getDefaultImageMetadata(new ImageTypeSpecifier(image), param);
        return metaData;
    } catch (Exception e) {
        logger.error(e.toString());
        return null;
    }
}
 
Example #29
Source File: PNGImageReader.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public ImageTypeSpecifier getRawImageType(int imageIndex)
  throws IOException {

    Iterator<ImageTypeSpecifier> types = getImageTypes(imageIndex);
    ImageTypeSpecifier raw = null;
    do {
        raw = types.next();
    } while (types.hasNext());
    return raw;
}
 
Example #30
Source File: WBMPImageReader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public Iterator getImageTypes(int imageIndex)
    throws IOException {
    checkIndex(imageIndex);
    readHeader();

    BufferedImage bi =
        new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_BINARY);
    ArrayList list = new ArrayList(1);
    list.add(new ImageTypeSpecifier(bi));
    return list.iterator();
}