public FlateDecode(Library library, Hashtable props, InputStream input) { super(); originalInputKeptSolelyForDebugging = input; width = 0; numComponents = 0; bitsPerComponent = 0; bpp = 1; int intermediateBufferSize = 4096; // get decode parameters from stream properties Hashtable decodeParmsDictionary = library.getDictionary(props, "DecodeParms"); predictor = library.getInt(decodeParmsDictionary, "Predictor"); if (predictor != LZW_FLATE_PREDICTOR_NONE && predictor != LZW_FLATE_PREDICTOR_TIFF_2 && predictor != LZW_FLATE_PREDICTOR_PNG_NONE && predictor != LZW_FLATE_PREDICTOR_PNG_SUB && predictor != LZW_FLATE_PREDICTOR_PNG_UP && predictor != LZW_FLATE_PREDICTOR_PNG_AVG && predictor != LZW_FLATE_PREDICTOR_PNG_PAETH && predictor != LZW_FLATE_PREDICTOR_PNG_OPTIMUM) { predictor = LZW_FLATE_PREDICTOR_NONE; } // System.out.println("predictor: " + predictor); if (predictor != LZW_FLATE_PREDICTOR_NONE) { Number widthNumber = library.getNumber(props, "Width"); if (widthNumber != null) width = widthNumber.intValue(); else width = library.getInt(decodeParmsDictionary, "Columns"); // System.out.println("Width: " + width); // int height = (int) library.getFloat(entries, "Height"); // Since DecodeParms.BitsPerComponent has a default value, I don't think we'd // look at entries.ColorSpace to know the number of components. But, here's the info: // /ColorSpace /DeviceGray: 1 comp, /DeviceRBG: 3 comps, /DeviceCMYK: 4 comps, /DeviceN: N // comps // I'm going to extend that to mean I won't look at entries.BitsPerComponent either numComponents = 1; // DecodeParms.Colors: 1,2,3,4 Default=1 bitsPerComponent = 8; // DecodeParms.BitsPerComponent: 1,2,4,8,16 Default=8 Object numComponentsDecodeParmsObj = library.getObject(decodeParmsDictionary, "Colors"); if (numComponentsDecodeParmsObj instanceof Number) { numComponents = ((Number) numComponentsDecodeParmsObj).intValue(); // System.out.println("numComponents: " + numComponents); } Object bitsPerComponentDecodeParmsObj = library.getObject(decodeParmsDictionary, "BitsPerComponent"); if (bitsPerComponentDecodeParmsObj instanceof Number) { bitsPerComponent = ((Number) bitsPerComponentDecodeParmsObj).intValue(); // System.out.println("bitsPerComponent: " + bitsPerComponent); } bpp = Math.max(1, Utils.numBytesToHoldBits(numComponents * bitsPerComponent)); // System.out.println("bpp: " + bpp); // Make buffer exactly large enough for one row of data (without predictor) intermediateBufferSize = Utils.numBytesToHoldBits(width * numComponents * bitsPerComponent); // System.out.println("intermediateBufferSize: " + intermediateBufferSize); } // Create the inflater input stream which will do the encoding setInputStream(new InflaterInputStream(input)); setBufferSize(intermediateBufferSize); aboveBuffer = new byte[intermediateBufferSize]; }