All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jpedal.parser.image.ID Maven / Gradle / Ivy

There is a newer version: 20151002
Show newest version
/*
 * ===========================================
 * Java Pdf Extraction Decoding Access Library
 * ===========================================
 *
 * Project Info:  http://www.idrsolutions.com
 * Help section for developers at http://www.idrsolutions.com/support/
 *
 * (C) Copyright 1997-2016 IDRsolutions and Contributors.
 *
 * This file is part of JPedal/JPDF2HTML5
 *
     This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


 *
 * ---------------
 * ID.java
 * ---------------
 */
package org.jpedal.parser.image;

import java.awt.Color;
import java.awt.image.BufferedImage;
import org.jpedal.color.ColorspaceFactory;
import org.jpedal.color.DeviceRGBColorSpace;
import org.jpedal.color.GenericColorSpace;
import org.jpedal.external.ErrorTracker;
import org.jpedal.external.ImageHandler;
import org.jpedal.io.*;
import org.jpedal.objects.PdfImageData;
import org.jpedal.objects.PdfPageData;
import org.jpedal.objects.raw.PdfArrayIterator;
import org.jpedal.objects.raw.PdfDictionary;
import org.jpedal.objects.raw.PdfObject;
import org.jpedal.parser.PdfObjectCache;
import org.jpedal.parser.image.data.ImageData;

public class ID extends ImageDecoder {
    public ID(final int imageCount, final PdfObjectReader currentPdfFile, final ErrorTracker errorTracker, final ImageHandler customImageHandler, final ObjectStore objectStoreStreamRef, final PdfImageData pdfImages, final PdfPageData pageData, final String imagesInFile) {
        super(imageCount, currentPdfFile, errorTracker, customImageHandler, objectStoreStreamRef, pdfImages, pageData, imagesInFile);
    }


    @Override
    public int processImage(int dataPointer, final int startInlineStream, final byte[] stream, final int tokenNumber) throws Exception{

        /*
         * read Dictionary
         */
        final PdfObject XObject=new org.jpedal.objects.raw.XObject(PdfDictionary.ID);

        final IDObjectDecoder objectDecoder=new IDObjectDecoder(currentPdfFile.getObjectReader());
        objectDecoder.setEndPt(dataPointer-2);

        objectDecoder.readDictionaryAsObject(XObject,startInlineStream,stream);

        BufferedImage image =   null;

        final boolean inline_imageMask;

        //store pointer to current place in file
        int inline_start_pointer = dataPointer + 1;
        final int i_w;
        final int i_h;
        final int i_bpc;

        //find end of stream
        int i = inline_start_pointer;
        final int streamLength=stream.length;

        //find end
        while (true) {
            //look for end EI

            //handle Pdflib and xenos variety
            if ( streamLength-i>3 &&  stream[i + 1] == 69 && stream[i + 2] == 73 && ((stream[i+3] == 10 && (streamLength==i+4 || stream[i+4]==81))  || (stream[i+3]==32 && stream[i+4] == 10))){
                break;
            }
            //general case
            if ((streamLength-i>3)&&(stream[i] == 32 || stream[i] == 10 || stream[i] == 13 ||  (stream[i+3] == 32 && stream[i+4] == 'Q'))
                    && (stream[i + 1] == 69)
                    && (stream[i + 2] == 73)
                    && ( stream[i+3] == 32 || stream[i+3] == 10 || stream[i+3] == 13)) {
                break;
            }
            

            i++;

            if(i==streamLength) {
                break;
            }
        }
        
        if(parserOptions.imagesNeeded()){

            //load the data
            //		generate the name including file name to make it unique
            final String image_name =parserOptions.getFileName()+ "-IN-" + tokenNumber;

            int endPtr=i;
            //hack for odd files
            if(i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy