Package org.apache.sanselan

Examples of org.apache.sanselan.ImageReadException


        int Reserved = read2Bytes("Reserved", is, "Not a Valid ICO File");
        int IconType = read2Bytes("IconType", is, "Not a Valid ICO File");
        int IconCount = read2Bytes("IconCount", is, "Not a Valid ICO File");

        if (Reserved != 0)
            throw new ImageReadException("Not a Valid ICO File: reserved is " + Reserved);
        if (IconType != 1 && IconType != 2)
            throw new ImageReadException("Not a Valid ICO File: icon type is " + IconType);

        return new FileHeader(Reserved, IconType, IconCount);

    }
View Full Code Here


            BlueMask = read4Bytes("BlueMask", is, "Not a Valid ICO File");
        }
        byte[] RestOfFile = readByteArray("RestOfFile", is.available(), is);

        if (Size != 40)
            throw new ImageReadException("Not a Valid ICO File: Wrong bitmap header size " + Size);
        if (Planes != 1)
            throw new ImageReadException("Not a Valid ICO File: Planes can't be " + Planes);

        if (Compression == 0 && BitCount == 32)
        {
            // 32 BPP RGB icons need an alpha channel, but BMP files don't have
            // one unless BI_BITFIELDS is used...
View Full Code Here

        ImageContents contents = readImage(byteSource);
        FileHeader fileHeader = contents.fileHeader;
        if (fileHeader.iconCount > 0)
            return contents.iconDatas[0].readBufferedImage();
        else
            throw new ImageReadException("No icons in ICO file");
    }
View Full Code Here

//                        Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
//                raster = colorModel.createCompatibleWritableRaster(
//                        sofnSegment.width, sofnSegment.height);
            }
            else
                throw new ImageReadException(sofnSegment.numberOfComponents +
                        " components are invalid or unsupported");
            DataBuffer dataBuffer = raster.getDataBuffer();

           
            for (int y1 = 0; y1 < vSize*yMCUs; y1 += vSize)
            {
                for (int x1 = 0; x1 < hSize*xMCUs; x1 += hSize)
                {
                    readMCU(bitInputStream, preds, mcu);
                    rescaleMCU(mcu, hSize, vSize, scaledMCU);
                    int srcRowOffset = 0;
                    int dstRowOffset = y1*sofnSegment.width + x1;
                    for (int y2 = 0; y2 < vSize && y1 + y2 < sofnSegment.height; y2++)
                    {
                        for (int x2 = 0; x2 < hSize && x1 + x2 < sofnSegment.width; x2++)
                        {
                            if (scaledMCU.length == 3)
                            {
                                int Y = scaledMCU[0].samples[srcRowOffset + x2];
                                int Cb = scaledMCU[1].samples[srcRowOffset + x2];
                                int Cr = scaledMCU[2].samples[srcRowOffset + x2];
                                int rgb = YCbCrConverter.convertYCbCrToRGB(Y, Cb, Cr);
                                dataBuffer.setElem(dstRowOffset + x2, rgb);
                            }
                            else if (mcu.length == 1)
                            {
                                int Y = scaledMCU[0].samples[srcRowOffset + x2];
                                dataBuffer.setElem(dstRowOffset + x2,
                                        (Y << 16) | (Y << 8) | Y);
                            }
                            else
                                throw new ImageReadException("Unsupported JPEG with " +
                                        mcu.length + " components");
                        }
                        srcRowOffset += hSize;
                        dstRowOffset += sofnSegment.width;
                    }
                }
            }
            image = new BufferedImage(colorModel, raster,
                    colorModel.isAlphaPremultiplied(), new Properties());
            //byte[] remainder = super.getStreamBytes(is);
            //for (int i = 0; i < remainder.length; i++)
            //{
            //    System.out.println("" + i + " = " + Integer.toHexString(remainder[i]));
            //}
        }
        catch (ImageReadException imageReadEx)
        {
            imageReadException = imageReadEx;
        }
        catch (IOException ioEx)
        {
            ioException = ioEx;
        }
        catch (RuntimeException ex)
        {
            // Corrupt images can throw NPE and IOOBE
            imageReadException = new ImageReadException("Error parsing JPEG", ex);
        }
    }
View Full Code Here

        };

        if (Arrays.binarySearch(sofnSegments, marker) >= 0)
        {
            if (marker != SOF0Marker)
                throw new ImageReadException("Only sequential, baseline JPEGs " +
                        "are supported at the moment");
            sofnSegment = new SOFNSegment(marker, segmentData);
        }
        else if (marker == DQTMarker)
        {
            DQTSegment dqtSegment = new DQTSegment(marker, segmentData);
            for (int i = 0; i < dqtSegment.quantizationTables.size(); i++)
            {
                DQTSegment.QuantizationTable table = (DQTSegment.QuantizationTable)
                        dqtSegment.quantizationTables.get(i);
                if (0 > table.destinationIdentifier ||
                        table.destinationIdentifier >= quantizationTables.length)
                    throw new ImageReadException("Invalid quantization table identifier " +
                            table.destinationIdentifier);
                quantizationTables[table.destinationIdentifier] = table;
                int[] quantizationMatrixInt = new int[64];
                ZigZag.zigZagToBlock(table.elements, quantizationMatrixInt);
                float[] quantizationMatrixFloat = new float[64];
                for (int j = 0; j < 64; j++)
                    quantizationMatrixFloat[j] = quantizationMatrixInt[j];
                DCT.scaleDequantizationMatrix(quantizationMatrixFloat);
                scaledQuantizationTables[table.destinationIdentifier] =
                        quantizationMatrixFloat;
            }
        }
        else if (marker == DHTMarker)
        {
            DHTSegment dhtSegment = new DHTSegment(marker, segmentData);
            for (int i = 0; i < dhtSegment.huffmanTables.size(); i++)
            {
                DHTSegment.HuffmanTable table = (DHTSegment.HuffmanTable)
                        dhtSegment.huffmanTables.get(i);
                DHTSegment.HuffmanTable[] tables;
                if (table.tableClass == 0)
                    tables = huffmanDCTables;
                else if (table.tableClass == 1)
                    tables = huffmanACTables;
                else
                    throw new ImageReadException("Invalid huffman table class " +
                            table.tableClass);
                if (0 > table.destinationIdentifier ||
                        table.destinationIdentifier >= tables.length)
                    throw new ImageReadException("Invalid huffman table identifier " +
                            table.destinationIdentifier);
                tables[table.destinationIdentifier] = table;
            }
        }
        return true;
View Full Code Here

                    frameComponent = sofnSegment.components[j];
                    break;
                }
            }
            if (frameComponent == null)
                throw new ImageReadException("Invalid component");
            Block fullBlock = new Block(
                    8*frameComponent.horizontalSamplingFactor,
                    8*frameComponent.verticalSamplingFactor);
            mcu[i] = fullBlock;
        }
View Full Code Here

                    frameComponent = sofnSegment.components[j];
                    break;
                }
            }
            if (frameComponent == null)
                throw new ImageReadException("Invalid component");
            Block fullBlock = mcu[i];
            for (int y = 0; y < frameComponent.verticalSamplingFactor; y++)
            {
                for (int x = 0; x < frameComponent.horizontalSamplingFactor; x++)
                {
View Full Code Here

    {
        if (cnt == 0)
        {
            b = is.read();
            if (b < 0)
                throw new ImageReadException("Premature End of File");
            cnt = 8;
            if (b == 0xff)
            {
                int b2 = is.read();
                if (b2 < 0)
                    throw new ImageReadException("Premature End of File");
                if (b2 != 0)
                {
                    if (b2 == (0xff & JpegConstants.DNLMarker))
                        throw new ImageReadException("DNL not yet supported");
                    else
                        throw new ImageReadException("Invalid marker found " +
                                "in entropy data");
                }
            }
        }
        int bit = (b >> 7) & 0x1;
View Full Code Here

                            is, "Not a Valid JPEG File");
                    length -= 2;
                }
                else
                {
                    throw new ImageReadException("Quantization table precision '" +
                            precision + "' is invalid");
                }
            }

            quantizationTables.add(new QuantizationTable(
View Full Code Here

        switch (compression)
        {
            case 1 : // None;
                return compressed;
            case 2 : // CCITT Group 3 1-Dimensional Modified Huffman run-length encoding.
                throw new ImageReadException("Tiff: unknown compression: "
                        + compression);
            case TIFF_COMPRESSION_LZW : // LZW
            {
                InputStream is = new ByteArrayInputStream(compressed);

                int LZWMinimumCodeSize = 8;

                MyLZWDecompressor myLzwDecompressor = new MyLZWDecompressor(
                        LZWMinimumCodeSize, BYTE_ORDER_NETWORK);

                myLzwDecompressor.setTiffLZWMode();

                byte[] result = myLzwDecompressor.decompress(is, expected_size);

                return result;
            }

            case TIFF_COMPRESSION_PACKBITS : // Packbits
            {
                byte unpacked[] = new PackBits().decompress(compressed,
                        expected_size);
                count++;

                return unpacked;
            }

            default :
                throw new ImageReadException("Tiff: unknown compression: "
                        + compression);
        }
    }
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.