Package org.apache.commons.imaging

Examples of org.apache.commons.imaging.ImageReadException


        final JFIFPieces jfifPieces = analyzeJFIF(byteSource);
        final List<JFIFPiece> oldPieces = jfifPieces.pieces;
        final List<JFIFPiece> photoshopApp13Segments = findPhotoshopApp13Segments(oldPieces);

        if (photoshopApp13Segments.size() > 1) {
            throw new ImageReadException(
                    "Image contains more than one Photoshop App13 segment.");
        }
        List<JFIFPiece> newPieces = removePhotoshopApp13Segments(oldPieces);

        {
View Full Code Here


            nextByte = readByte("Header", is, "Error reading WBMP header");
            value <<= 7;
            value |= nextByte & 0x7f;
            totalBits += 7;
            if (totalBits > 31) {
                throw new ImageReadException(
                        "Overflow reading WBMP multi-byte field");
            }
        } while ((nextByte & 0x80) != 0);
        return value;
    }
View Full Code Here

    private WbmpHeader readWbmpHeader(final InputStream is)
            throws ImageReadException, IOException {
        final int typeField = readMultiByteInteger(is);
        if (typeField != 0) {
            throw new ImageReadException("Invalid/unsupported WBMP type "
                    + typeField);
        }

        final byte fixHeaderField = readByte("FixHeaderField", is,
                "Invalid WBMP File");
        if ((fixHeaderField & 0x9f) != 0) {
            throw new ImageReadException(
                    "Invalid/unsupported WBMP FixHeaderField 0x"
                            + Integer.toHexString(0xff & fixHeaderField));
        }

        final int width = readMultiByteInteger(is);
View Full Code Here

                profileData = read4Bytes("ProfileData", is, "Not a Valid BMP File", getByteOrder());
                profileSize = read4Bytes("ProfileSize", is, "Not a Valid BMP File", getByteOrder());
                reservedV5 = read4Bytes("Reserved", is, "Not a Valid BMP File", getByteOrder());
            }
        } else {
            throw new ImageReadException("Invalid/unsupported BMP file");
        }

        if (verbose) {
            debugNumber("identifier1", identifier1, 1);
            debugNumber("identifier2", identifier2, 1);
View Full Code Here

            // BytesPerPixel = 2;
            // BytesPerPaletteEntry = 4;
            break;

        default:
            throw new ImageReadException("BMP: Unknown Compression: "
                    + bhi.compression);
        }

        byte[] colorTable = null;
        if (paletteLength > 0) {
            colorTable = readBytes("ColorTable", is, paletteLength,
                    "Not a Valid BMP File");
        }

        if (verbose) {
            debugNumber("paletteLength", paletteLength, 4);
            System.out.println("ColorTable: "
                    + ((colorTable == null) ? "null" : Integer.toString(colorTable.length)));
        }

        final int pixelCount = bhi.width * bhi.height;

        int imageLineLength = (((bhi.bitsPerPixel) * bhi.width) + 7) / 8;

        if (verbose) {
            // this.debugNumber("Total BitsPerPixel",
            // (ExtraBitsPerPixel + bhi.BitsPerPixel), 4);
            // this.debugNumber("Total Bit Per Line",
            // ((ExtraBitsPerPixel + bhi.BitsPerPixel) * bhi.Width), 4);
            // this.debugNumber("ExtraBitsPerPixel", ExtraBitsPerPixel, 4);
            debugNumber("bhi.Width", bhi.width, 4);
            debugNumber("bhi.Height", bhi.height, 4);
            debugNumber("ImageLineLength", imageLineLength, 4);
            // this.debugNumber("imageDataSize", imageDataSize, 4);
            debugNumber("PixelCount", pixelCount, 4);
        }
        // int ImageLineLength = BytesPerPixel * bhi.Width;
        while ((imageLineLength % 4) != 0) {
            imageLineLength++;
        }

        final int headerSize = BITMAP_FILE_HEADER_SIZE
                + bhi.bitmapHeaderSize
                + (bhi.bitmapHeaderSize == 40
                        && bhi.compression == BI_BITFIELDS ? 3 * 4 : 0);
        final int expectedDataOffset = headerSize + paletteLength;

        if (verbose) {
            debugNumber("bhi.BitmapDataOffset", bhi.bitmapDataOffset, 4);
            debugNumber("expectedDataOffset", expectedDataOffset, 4);
        }
        final int extraBytes = bhi.bitmapDataOffset - expectedDataOffset;
        if (extraBytes < 0) {
            throw new ImageReadException("BMP has invalid image data offset: "
                    + bhi.bitmapDataOffset + " (expected: "
                    + expectedDataOffset + ", paletteLength: " + paletteLength
                    + ", headerSize: " + headerSize + ")");
        } else if (extraBytes > 0) {
            readBytes("BitmapDataOffset", is, extraBytes, "Not a Valid BMP File");
        }

        final int imageDataSize = bhi.height * imageLineLength;

        if (verbose) {
            debugNumber("imageDataSize", imageDataSize, 4);
        }

        byte[] imageData;
        if (rle) {
            imageData = getRLEBytes(is, rleSamplesPerByte);
        } else {
            imageData = readBytes("ImageData", is, imageDataSize,
                    "Not a Valid BMP File");
        }

        if (verbose) {
            debugNumber("ImageData.length", imageData.length, 4);
        }

        PixelParser pixelParser;

        switch (bhi.compression) {
        case BI_RLE4:
        case BI_RLE8:
            pixelParser = new PixelParserRle(bhi, colorTable, imageData);
            break;
        case BI_RGB:
            pixelParser = new PixelParserRgb(bhi, colorTable, imageData);
            break;
        case BI_BITFIELDS:
            pixelParser = new PixelParserBitFields(bhi, colorTable, imageData);
            break;
        default:
            throw new ImageReadException("BMP: Unknown Compression: "
                    + bhi.compression);
        }

        return new ImageContents(bhi, colorTable, imageData, pixelParser);
    }
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 BmpHeaderInfo bhi = readBmpHeaderInfo(byteSource, verbose);

        if (bhi == null) {
            throw new ImageReadException("BMP: couldn't read header");
        }

        return new Dimension(bhi.width, bhi.height);

    }
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);
        }

        InputStream is = null;
        ImageContents ic = null;
        boolean canThrow = false;
        try {
            is = byteSource.getInputStream();
            ic = readImageContents(is, FormatCompliance.getDefault(), verbose);
            canThrow = true;
        } finally {
            IoUtils.closeQuietly(canThrow, is);
        }

        if (ic == null) {
            throw new ImageReadException("Couldn't read BMP Data");
        }

        final BmpHeaderInfo bhi = ic.bhi;
        final byte[] colorTable = ic.colorTable;

        if (bhi == null) {
            throw new ImageReadException("BMP: couldn't read header");
        }

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

            params.remove(BUFFERED_IMAGE_FACTORY);
        }

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

        final ImageContents ic = readImageContents(inputStream,
                FormatCompliance.getDefault(), verbose);
        if (ic == null) {
            throw new ImageReadException("Couldn't read BMP Data");
        }

        final BmpHeaderInfo bhi = ic.bhi;
        // byte colorTable[] = ic.colorTable;
        // byte imageData[] = ic.imageData;
View Full Code Here

                TiffTagConstants.TIFF_TAG_IMAGE_WIDTH, true);
        final TiffField heightField = directory.findField(
                TiffTagConstants.TIFF_TAG_IMAGE_LENGTH, true);

        if ((widthField == null) || (heightField == null)) {
            throw new ImageReadException("TIFF image missing size info.");
        }

        final int height = heightField.getIntValue();
        final int width = widthField.getIntValue();
View Full Code Here

                TiffTagConstants.TIFF_TAG_IMAGE_WIDTH, true);
        final TiffField heightField = directory.findField(
                TiffTagConstants.TIFF_TAG_IMAGE_LENGTH, true);

        if ((widthField == null) || (heightField == null)) {
            throw new ImageReadException("TIFF image missing size info.");
        }

        final int height = heightField.getIntValue();
        final int width = widthField.getIntValue();
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.