Package org.apache.commons.imaging

Examples of org.apache.commons.imaging.ImageReadException


        super(length, chunkType, crc, bytes);
        // this.parser = parser;

        final int index = findNull(bytes);
        if (index < 0) {
            throw new ImageReadException("PngChunkIccp: No Profile Name");
        }
        final byte[] nameBytes = new byte[index];
        System.arraycopy(bytes, 0, nameBytes, 0, index);
        profileName = new String(nameBytes, "ISO-8859-1");
View Full Code Here


    }

    private byte[] assembleSegments(final List<App2Segment> segments, final boolean startWithZero)
            throws ImageReadException {
        if (segments.isEmpty()) {
            throw new ImageReadException("No App2 Segments Found.");
        }

        final int markerCount = segments.get(0).numMarkers;

        if (segments.size() != markerCount) {
            throw new ImageReadException("App2 Segments Missing.  Found: "
                    + segments.size() + ", Expected: " + markerCount + ".");
        }

        Collections.sort(segments);

        final int offset = startWithZero ? 0 : 1;

        int total = 0;
        for (int i = 0; i < segments.size(); i++) {
            final App2Segment segment = segments.get(i);

            if ((i + offset) != segment.curMarker) {
                dumpSegments(segments);
                throw new ImageReadException(
                        "Incoherent App2 Segment Ordering.  i: " + i
                                + ", segment[" + i + "].curMarker: "
                                + segment.curMarker + ".");
            }

            if (markerCount != segment.numMarkers) {
                dumpSegments(segments);
                throw new ImageReadException(
                        "Inconsistent App2 Segment Count info.  markerCount: "
                                + markerCount + ", segment[" + i
                                + "].numMarkers: " + segment.numMarkers + ".");
            }
View Full Code Here

        // TODO: concatenate if multiple segments, need example.
        if (exifSegments.isEmpty()) {
            return null;
        }
        if (exifSegments.size() > 1) {
            throw new ImageReadException(
                    "Imaging currently can't parse EXIF metadata split across multiple APP1 segments.  "
                            + "Please send this image to the Imaging project.");
        }

        final GenericSegment segment = (GenericSegment) exifSegments.get(0);
View Full Code Here

        if (result.isEmpty()) {
            return null;
        }
        if (result.size() > 1) {
            throw new ImageReadException(
                    "Jpeg file contains more than one XMP segment.");
        }
        return result.get(0);
    }
View Full Code Here

        for (Segment s : segments) {
            final App13Segment segment = (App13Segment) s;

            final PhotoshopApp13Data data = segment.parsePhotoshopSegment(params);
            if (data != null && photoshopApp13Data != null) {
                throw new ImageReadException(
                        "Jpeg contains more than one Photoshop App13 segment.");
            }

            photoshopApp13Data = data;
        }
View Full Code Here

                JpegConstants.SOF15_MARKER,

        }, true);

        if ((segments == null) || (segments.isEmpty())) {
            throw new ImageReadException("No JFIF Data Found.");
        }

        if (segments.size() > 1) {
            throw new ImageReadException("Redundant JFIF Data Found.");
        }

        final SofnSegment fSOFNSegment = (SofnSegment) segments.get(0);

        return new Dimension(fSOFNSegment.width, fSOFNSegment.height);
View Full Code Here

                JpegConstants.SOF15_MARKER,

        }, false);

        if (SOF_segments == null) {
            throw new ImageReadException("No SOFN Data Found.");
        }

        // if (SOF_segments.size() != 1)
        // System.out.println("Incoherent SOFN Data Found: "
        // + SOF_segments.size());

        final List<Segment> jfifSegments = readSegments(byteSource,
                new int[] { JpegConstants.JFIF_MARKER, }, true);

        final SofnSegment fSOFNSegment = (SofnSegment) SOF_segments.get(0);
        // SofnSegment fSOFNSegment = (SofnSegment) findSegment(segments,
        // SOFNmarkers);

        if (fSOFNSegment == null) {
            throw new ImageReadException("No SOFN Data Found.");
        }

        final int width = fSOFNSegment.width;
        final int height = fSOFNSegment.height;
View Full Code Here

        {
            final List<Segment> segments = readSegments(byteSource, null, false);

            if (segments == null) {
                throw new ImageReadException("No Segments Found.");
            }

            for (int d = 0; d < segments.size(); d++) {

                final Segment segment = segments.get(d);
View Full Code Here

    public PngChunkItxt(final int length, final int chunkType, final int crc, final byte[] bytes)
            throws ImageReadException, IOException {
        super(length, chunkType, crc, bytes);
        int terminator = findNull(bytes);
        if (terminator < 0) {
            throw new ImageReadException(
                    "PNG iTXt chunk keyword is not terminated.");
        }

        keyword = new String(bytes, 0, terminator, "ISO-8859-1");
        int index = terminator + 1;

        final int compressionFlag = bytes[index++];
        if (compressionFlag != 0 && compressionFlag != 1) {
            throw new ImageReadException(
                    "PNG iTXt chunk has invalid compression flag: "
                            + compressionFlag);
        }

        final boolean compressed = compressionFlag == 1;

        final int compressionMethod = bytes[index++];
        if (compressed && compressionMethod != PngConstants.COMPRESSION_DEFLATE_INFLATE) {
            throw new ImageReadException("PNG iTXt chunk has unexpected compression method: " + compressionMethod);
        }

        terminator = findNull(bytes, index);
        if (terminator < 0) {
            throw new ImageReadException("PNG iTXt chunk language tag is not terminated.");
        }

        languageTag = new String(bytes, index, terminator - index, "ISO-8859-1");
        index = terminator + 1;

        terminator = findNull(bytes, index);
        if (terminator < 0) {
            throw new ImageReadException("PNG iTXt chunk translated keyword is not terminated.");
        }

        translatedKeyword = new String(bytes, index, terminator - index, "utf-8");
        index = terminator + 1;
View Full Code Here

                    length--;
                } else if (precision == 1) {
                    elements[i] = read2Bytes("QuantizationTableElement", is, "Not a Valid JPEG File", getByteOrder());
                    length -= 2;
                } else {
                    throw new ImageReadException(
                            "Quantization table precision '" + precision
                                    + "' is invalid");
                }
            }
View Full Code Here

TOP

Related Classes of org.apache.commons.imaging.ImageReadException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.