Package org.apache.sanselan

Examples of org.apache.sanselan.ImageReadException


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

        if (verbose)
        {
            this.debugNumber("identifier1", identifier1, 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 = this.readByteArray("ColorTable", paletteLength, is,
                    "Not a Valid BMP File");

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

        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);
            this.debugNumber("bhi.Width", bhi.width, 4);
            this.debugNumber("bhi.Height", bhi.height, 4);
            this.debugNumber("ImageLineLength", imageLineLength, 4);
            // this.debugNumber("imageDataSize", imageDataSize, 4);
            this.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);
        int expectedDataOffset = headerSize + paletteLength;

        if (verbose)
        {
            this.debugNumber("bhi.BitmapDataOffset", bhi.bitmapDataOffset, 4);
            this.debugNumber("expectedDataOffset", expectedDataOffset, 4);
        }
        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)
            this.readByteArray("BitmapDataOffset", extraBytes, is,
                    "Not a Valid BMP File");

        int imageDataSize = bhi.height * imageLineLength;

        if (verbose)
            this.debugNumber("imageDataSize", imageDataSize, 4);

        byte imageData[];
        if (rle)
            imageData = getRLEBytes(is, rleSamplesPerByte);
        else
            imageData = this.readByteArray("ImageData", imageDataSize, is,
                    "Not a Valid BMP File");

        if (verbose)
            this.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.size() > 0)
        {
            Object firstKey = params.keySet().iterator().next();
            throw new ImageReadException("Unknown parameter: " + firstKey);
        }

        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.size() > 0)
        {
            Object firstKey = params.keySet().iterator().next();
            throw new ImageReadException("Unknown parameter: " + firstKey);
        }

        ImageContents ic = readImageContents(byteSource.getInputStream(),
                FormatCompliance.getDefault(), verbose);

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

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

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

        int height = bhi.height;
        int width = bhi.width;

        ArrayList comments = new ArrayList();
View Full Code Here

            params.remove(BUFFERED_IMAGE_FACTORY);

        if (params.size() > 0)
        {
            Object firstKey = params.keySet().iterator().next();
            throw new ImageReadException("Unknown parameter: " + firstKey);
        }

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

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

                    xHot = Integer.parseInt((String)entry.getValue());
                else if (name.endsWith("_y_hot"))
                    yHot = Integer.parseInt((String)entry.getValue());
            }
            if (width == -1)
                throw new ImageReadException("width not found");
            if (height == -1)
                throw new ImageReadException("height not found");

            XbmParseResult xbmParseResult = new XbmParseResult();
            xbmParseResult.cParser = new BasicCParser(
                    new ByteArrayInputStream(preprocessedFile.toByteArray()));
            xbmParseResult.xbmHeader = new XbmHeader(width, height, xHot, yHot);
View Full Code Here

            throws ImageReadException, IOException
    {
        String token;
        token = cParser.nextToken();
        if (token == null || !token.equals("static"))
            throw new ImageReadException("Parsing XBM file failed, no 'static' token");
        token = cParser.nextToken();
        if (token == null)
            throw new ImageReadException("Parsing XBM file failed, no 'unsigned' " +
                    "or 'char' token");
        if (token.equals("unsigned"))
            token = cParser.nextToken();
        if (token == null || !token.equals("char"))
            throw new ImageReadException("Parsing XBM file failed, no 'char' token");
        String name = cParser.nextToken();
        if (name == null)
            throw new ImageReadException("Parsing XBM file failed, no variable name");
        if (name.charAt(0) != '_' && !Character.isLetter(name.charAt(0)))
            throw new ImageReadException("Parsing XBM file failed, variable name " +
                    "doesn't start with letter or underscore");
        for (int i = 0; i < name.length(); i++)
        {
            char c = name.charAt(i);
            if (!Character.isLetterOrDigit(c) && c != '_')
                throw new ImageReadException("Parsing XBM file failed, variable name " +
                        "contains non-letter non-digit non-underscore");
        }
        token = cParser.nextToken();
        if (token == null || !token.equals("["))
            throw new ImageReadException("Parsing XBM file failed, no '[' token");
        token = cParser.nextToken();
        if (token == null || !token.equals("]"))
            throw new ImageReadException("Parsing XBM file failed, no ']' token");
        token = cParser.nextToken();
        if (token == null || !token.equals("="))
            throw new ImageReadException("Parsing XBM file failed, no '=' token");
        token = cParser.nextToken();
        if (token == null || !token.equals("{"))
            throw new ImageReadException("Parsing XBM file failed, no '{' token");

        int rowLength = (xbmHeader.width + 7) / 8;
        byte[] imageData = new byte[rowLength * xbmHeader.height];
        for (int i = 0; i < imageData.length; i++)
        {
            token = cParser.nextToken();
            if (token == null || !token.startsWith("0x"))
                throw new ImageReadException("Parsing XBM file failed, " +
                        "hex value missing");
            if (token.length() > 4)
                throw new ImageReadException("Parsing XBM file failed, " +
                        "hex value too long");
            int value = Integer.parseInt(token.substring(2), 16);
            int flipped = 0;
            for (int j = 0; j < 8; j++)
            {
                if ((value & (1 << j)) != 0)
                    flipped |= (0x80 >>> j);
            }
            imageData[i] = (byte) flipped;

            token = cParser.nextToken();
            if (token == null)
                throw new ImageReadException("Parsing XBM file failed, " +
                        "premature end of file");
            if (!token.equals(",") && (i < (imageData.length - 1) || !token.equals("}")))
                throw new ImageReadException("Parsing XBM file failed, " +
                        "punctuation error");
        }

        int[] palette = {0xffffff, 0x000000};
        ColorModel colorModel = new IndexColorModel(1, 2,
View Full Code Here

        // LayerAndMaskDataLength, is, "Not a Valid PSD File");

        if (section == PSD_SECTION_IMAGE_DATA)
            return is;

        throw new ImageReadException("getInputStream: Unknown Section: "
                + section);
    }
View Full Code Here

            {
                Debug.debug(e);
            }

        }
        throw new ImageReadException("getInputStream: Unknown Section: "
                + section);
    }
View Full Code Here

    public Dimension getImageSize(ByteSource byteSource, Map params)
            throws ImageReadException, IOException
    {
        PSDHeaderInfo bhi = readHeader(byteSource);
        if (bhi == null)
            throw new ImageReadException("PSD: couldn't read header");

        return new Dimension(bhi.Columns, bhi.Rows);

    }
View Full Code Here

TOP

Related Classes of org.apache.sanselan.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.