Package com.lightcrafts.image

Examples of com.lightcrafts.image.BadImageFileException


        try {
            buf.position( 2 );          // skip JPEG magic number
            while ( true ) {
                final byte b = buf.get();
                if ( b != JPEG_MARKER_BYTE )
                    throw new BadImageFileException(
                        jpegFile,
                        "JPEG marker byte (0xFF) expected; got: 0x"
                        + Integer.toHexString( b & 0x00FF )
                    );

                byte segID;
                do {                    // skip padding, if any
                    segID = buf.get();
                } while ( segID == JPEG_MARKER_BYTE );

                final int segLength;
                switch ( segID ) {

                    case JPEG_EOI_MARKER:
                        //
                        // We should never get here... but just in case.
                        //
                        return;

                    case JPEG_SOS_MARKER:
                        //
                        // The Start-of-Scan segment doesn't have a length.
                        //
                        segLength = 0;
                        break;

                    default:
                        //
                        // The segment length includes itself, so subtract 2 to
                        // get the actual length of the segment data.
                        //
                        segLength = buf.getUnsignedShort() - 2;
                        final int segRemaining = buf.remaining();
                        if ( segLength > segRemaining )
                            throw new BadImageFileException(
                                jpegFile,
                                "JPEG segment length (" + segLength
                                + ") > actual length (" + segRemaining + ')'
                            );
                        break;
                }

                final int savedPos = buf.position();
                final boolean continueParsing =
                    handler.gotSegment( segID, segLength, jpegFile, buf );
                if ( segID == JPEG_SOS_MARKER || !continueParsing )
                    break;
                buf.position( savedPos + segLength );
            }
        }
        catch ( BufferUnderflowException e ) {
            throw new BadImageFileException( jpegFile, e );
        }
        catch ( IllegalArgumentException e ) {
            throw new BadImageFileException( jpegFile, e );
        }
    }
View Full Code Here


        final XmlDocument xml = getDocument( imageInfo );
        final XmlNode cache = getCacheNode( xml );
        final byte[] bytes = cache.getData();
        if (bytes == null) {
            // no cache data in the file
            throw new BadImageFileException( imageInfo.getFile() );
        }
        try {
            final InputStream in = new ByteArrayInputStream( bytes );
            final LCImageDataProvider provider =
                new InputStreamImageDataProvider( in );
            final LCJPEGReader reader = new LCJPEGReader( provider );
            return reader.getImage( thread, null );
        }
        catch ( LCImageLibException e ) {
            throw new BadImageFileException( imageInfo.getFile() );
        }
    }
View Full Code Here

        // The first block ("MRM") is a special case in that its size is the
        // total size of all blocks; hence, we ignore its size and move forward
        // to the next block that is immediately after.
        //
        if ( m_buf.get() != 0 )
            throw new BadImageFileException( m_imageInfo.getFile() );
        if ( !m_buf.getEquals( "MRM", "ASCII" ) )
            throw new BadImageFileException( m_imageInfo.getFile() );
        int blockSize = m_buf.getInt();

        while ( true ) {
            if ( m_buf.get() != 0 )
                throw new BadImageFileException( m_imageInfo.getFile() );
            final String blockName = m_buf.getString( 3, "ASCII" );
            blockSize = m_buf.getInt();

            if ( blockName.equals( "PRD" ) ) {
                // TODO
View Full Code Here

                  buf.get() != 0 )      // terminating null
                return;
            AdobeResourceParser.parse( handler, jpegFile, buf );
        }
        catch ( BufferUnderflowException e ) {
            throw new BadImageFileException( jpegFile, e );
        }
    }
View Full Code Here

     * @throws BadImageFileException if the header isn't as it's expected to be.
     */
    public void parseHeader() throws BadImageFileException, IOException {
        m_buf.position( 0 );
        if ( m_buf.remaining() < EXIF_HEADER_SIZE )
            throw new BadImageFileException( m_imageFile );
        if ( !m_buf.getEquals( "Exif", "ASCII" ) )
            throw new BadImageFileException( m_imageFile );
        m_buf.skipBytes( 2 );

        final int byteOrder = m_buf.getShort();
        if ( byteOrder == TIFF_LITTLE_ENDIAN )
            m_buf.order( ByteOrder.LITTLE_ENDIAN );
        else if ( byteOrder == TIFF_BIG_ENDIAN )
            m_buf.order( ByteOrder.BIG_ENDIAN );
        else
            throw new BadImageFileException( m_imageFile );

        if ( m_buf.getUnsignedShort() != TIFF_MAGIC_NUMBER )
            throw new BadImageFileException( m_imageFile );
    }
View Full Code Here

                dataLength += dataLength & 1;
                buf.position( savedPos + dataLength );
            }
            catch ( BufferUnderflowException e ) {
                throw new BadImageFileException( file, e );
            }
        }
    }
View Full Code Here

     * header isn't as it's expected to be.
     */
    protected void readHeader() throws BadImageFileException, IOException {
        m_buf.position( 0 );
        if ( m_buf.remaining() < CIFF_HEADER_SIZE )
            throw new BadImageFileException( m_imageInfo.getFile() );
        final int byteOrder = m_buf.getShort();
        if ( byteOrder == CIFF_LITTLE_ENDIAN )
            m_buf.order( ByteOrder.LITTLE_ENDIAN );
        else if ( byteOrder != CIFF_BIG_ENDIAN )
            throw new BadImageFileException( m_imageInfo.getFile() );
    }
View Full Code Here

     * header isn't as it's expected to be.
     */
    protected void readHeader() throws BadImageFileException, IOException {
        final String s = m_buf.getString( 0, 15, "ASCII" );
        if ( !s.equals( "FUJIFILMCCD-RAW" ) )
            throw new BadImageFileException( m_imageInfo.getFile() );

        //
        // The pointer to where the TIFF header starts is 84 bytes in.  The
        // value found there + 12 is the absolute position.
        //
View Full Code Here

        catch ( Exception e ) {
            //
            // Assume that any other exception is the result of a bad image
            // file.
            //
            throw new BadImageFileException( m_imageInfo.getFile(), e );
        }

        try {
            readAllDirectories();
        }
View Full Code Here

        final byte[] iccProfileData;
        try {
            iccProfileData = assembleICCProfile( iccSegBufs );
        }
        catch ( BufferUnderflowException e ) {
            throw new BadImageFileException( imageInfo.getFile() );
        }
        catch ( IllegalArgumentException e ) {
            throw new BadImageFileException( imageInfo.getFile() );
        }
        try {
            return ICC_Profile.getInstance( iccProfileData );
        }
        catch ( IllegalArgumentException e ) {
View Full Code Here

TOP

Related Classes of com.lightcrafts.image.BadImageFileException

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.