Package org.apache.commons.imaging

Examples of org.apache.commons.imaging.ImageReadException


    private final int bytesPerSample;

    public PgmFileInfo(final int width, final int height, final boolean rawbits, final int max) throws ImageReadException {
        super(width, height, rawbits);
        if (max <= 0) {
            throw new ImageReadException("PGM maxVal " + max
                    + " is out of range [1;65535]");
        } else if (max <= 255) {
            scale = 255f;
            bytesPerSample = 1;
        } else if (max <= 65535) {
            scale = 65535f;
            bytesPerSample = 2;
        } else {
            throw new ImageReadException("PGM maxVal " + max
                    + " is out of range [1;65535]");
        }
        this.max = max;
    }
View Full Code Here


            return b & bitmask;
        } else if (bitDepth == 16) {
            return (((0xff & bytes[sampleIndexBytes]) << 8) | (0xff & bytes[sampleIndexBytes + 1]));
        }

        throw new ImageReadException("PNG: bad BitDepth: " + bitDepth);
    }
View Full Code Here

        // entry
        final int totalBytes = (image.getWidth() * image.getHeight() + 7) / 8;
        if (maskData.length >= 2 * totalBytes) {
            position = totalBytes;
        } else {
            throw new ImageReadException("1 BPP mask underrun parsing ICNS file");
        }

        for (int y = 0; y < image.getHeight(); y++) {
            for (int x = 0; x < image.getWidth(); x++) {
                if (bitsLeft == 0) {
View Full Code Here

    private final int bytesPerSample;

    public PpmFileInfo(final int width, final int height, final boolean rawbits, final int max) throws ImageReadException {
        super(width, height, rawbits);
        if (max <= 0) {
            throw new ImageReadException("PPM maxVal " + max + " is out of range [1;65535]");
        } else if (max <= 255) {
            scale = 255f;
            bytesPerSample = 1;
        } else if (max <= 65535) {
            scale = 65535f;
            bytesPerSample = 2;
        } else {
            throw new ImageReadException("PPM maxVal " + max + " is out of range [1;65535]");
        }
        this.max = max;
    }
View Full Code Here

                if (imageType.getBitsPerPixel() == 32) {
                    imageData = Rle24Compression.decompress(
                            imageType.getWidth(), imageType.getHeight(),
                            imageElement.data);
                } else {
                    throw new ImageReadException("Short image data but not a 32 bit compressed type");
                }
            } else {
                imageData = imageElement.data;
            }

            final ImageBuilder imageBuilder = new ImageBuilder(imageType.getWidth(),
                    imageType.getHeight(), true);
            switch (imageType.getBitsPerPixel()) {
            case 1:
                decode1BPPImage(imageType, imageData, imageBuilder);
                break;
            case 4:
                decode4BPPImage(imageType, imageData, imageBuilder);
                break;
            case 8:
                decode8BPPImage(imageType, imageData, imageBuilder);
                break;
            case 32:
                decode32BPPImage(imageType, imageData, imageBuilder);
                break;
            default:
                throw new ImageReadException("Unsupported bit depth " + imageType.getBitsPerPixel());
            }

            if (maskElement != null) {
                if (maskType.getBitsPerPixel() == 1) {
                    apply1BPPMask(maskElement.data, imageBuilder);
                } else if (maskType.getBitsPerPixel() == 8) {
                    apply8BPPMask(maskElement.data, imageBuilder);
                } else {
                    throw new ImageReadException("Unsupport mask bit depth " + maskType.getBitsPerPixel());
                }
            }

            result.add(imageBuilder.getBufferedImage());
        }
View Full Code Here

        super(length, chunkType, crc, bytes);

        final ByteArrayInputStream is = new ByteArrayInputStream(bytes);

        if ((length % 3) != 0) {
            throw new ImageReadException("PLTE: wrong length: " + length);
        }

        final int count = length / 3;

        rgb = new int[count];
View Full Code Here

        return rgb;
    }

    public int getRGB(final int index) throws ImageReadException {
        if ((index < 0) || (index >= rgb.length)) {
            throw new ImageReadException("PNG: unknown Palette reference: "
                    + index);
        }
        return rgb[index];
    }
View Full Code Here

            params.remove(PARAM_KEY_VERBOSE);
        }

        if (!params.isEmpty()) {
            final Object firstKey = params.keySet().iterator().next();
            throw new ImageReadException("Unknown parameter: " + firstKey);
        }

        final IcnsContents contents = readImage(byteSource);
        final List<BufferedImage> images = IcnsDecoder
                .decodeAllImages(contents.icnsElements);
        if (images.isEmpty()) {
            throw new ImageReadException("No icons in ICNS file");
        }
        final BufferedImage image0 = images.get(0);
        return new ImageInfo("Icns", 32, new ArrayList<String>(),
                ImageFormats.ICNS, "ICNS Apple Icon Image",
                image0.getHeight(), "image/x-icns", images.size(), 0, 0, 0, 0,
View Full Code Here

            params.remove(PARAM_KEY_VERBOSE);
        }

        if (!params.isEmpty()) {
            final Object firstKey = params.keySet().iterator().next();
            throw new ImageReadException("Unknown parameter: " + firstKey);
        }

        final IcnsContents contents = readImage(byteSource);
        final List<BufferedImage> images = IcnsDecoder
                .decodeAllImages(contents.icnsElements);
        if (images.isEmpty()) {
            throw new ImageReadException("No icons in ICNS file");
        }
        final BufferedImage image0 = images.get(0);
        return new Dimension(image0.getWidth(), image0.getHeight());
    }
View Full Code Here

            throws ImageReadException, IOException {
        final int magic = read4Bytes("Magic", is, "Not a Valid ICNS File", getByteOrder());
        final int fileSize = read4Bytes("FileSize", is, "Not a Valid ICNS File", getByteOrder());

        if (magic != ICNS_MAGIC) {
            throw new ImageReadException("Not a Valid ICNS File: " + "magic is 0x" + Integer.toHexString(magic));
        }

        return new IcnsHeader(magic, fileSize);
    }
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.