Example usage for org.apache.commons.imaging.formats.jpeg JpegImageParser readSegments

List of usage examples for org.apache.commons.imaging.formats.jpeg JpegImageParser readSegments

Introduction

In this page you can find the example usage for org.apache.commons.imaging.formats.jpeg JpegImageParser readSegments.

Prototype

public List<Segment> readSegments(final ByteSource byteSource, final int markers[],
            final boolean returnAfterFirst) throws ImageReadException, IOException 

Source Link

Usage

From source file:org.gmdev.pdftrick.utils.CustomExtraImgReader.java

/**
 * Check if the images has Adobe byte marker and if is a YCCK type
 * @param imageByteArray// w ww. ja  v a2 s .com
 * @throws IOException
 * @throws ImageReadException
 */
private static void checkAdobeMarker(byte[] imageByteArray) throws IOException, ImageReadException {
    JpegImageParser parser = new JpegImageParser();
    ByteSource byteSource = new ByteSourceArray(imageByteArray);
    List<Segment> segments = parser.readSegments(byteSource, new int[] { 0xffee }, true);
    if (segments != null && segments.size() >= 1) {
        //UnknownSegment app14Segment = (UnknownSegment) segments.get(0);
        //App14Segment app14Segment = (App14Segment) segments.get(0);
        GenericSegment app14Segment = (GenericSegment) segments.get(0);
        byte[] data = app14Segment.getSegmentData();
        if (data.length >= 12 && data[0] == 'A' && data[1] == 'd' && data[2] == 'o' && data[3] == 'b'
                && data[4] == 'e') {
            hasAdobeMarker = true;
            byte[] data_2 = app14Segment.getSegmentData();
            int transform = data_2[11] & 0xff;
            if (transform == 2)
                colorType = COLOR_TYPE_YCCK;
        }
    }
}