Exemple #1
0
 private void initNotAlphaIDAT(FileStream fs, string colorspace, int n)
 {
     if (Dictionary["ColorSpace"] == null)
     {
         Dictionary.AddItem("ColorSpace", new PDFName(colorspace));
     }
     if (_interface == 1)
     {
         MemoryStream compressionStream = new MemoryStream();
         compressionStream.Position = 0;
         writeIDAT(compressionStream, fs);
         MemoryStream decodeStream = FlateDecoder.Decode(compressionStream, null);
         if (_bitdepth == 16)
         {
             n *= 2;
         }
         byte[] pdfData = toPDFData(decodeStream, n);
         GetStream().Write(pdfData, 0, pdfData.Length);
     }
     else
     {
         writeIDAT(GetStream(), fs);
         PDFDictionary dict = new PDFDictionary();
         dict.AddItem("Predictor", new PDFNumber(15));
         dict.AddItem("Colors", new PDFNumber(n));
         dict.AddItem("BitsPerComponent", new PDFNumber(_bitdepth));
         dict.AddItem("Columns", new PDFNumber(_width));
         Dictionary.AddItem("Filter", new PDFName("FlateDecode"));
         Dictionary.AddItem("DecodeParms", dict);
     }
 }
Exemple #2
0
        private void initAlphaIDAT(FileStream fs, string colorspace, int n)
        {
            if (Dictionary["ColorSpace"] == null)
            {
                Dictionary.AddItem("ColorSpace", new PDFName(colorspace));
            }
            MemoryStream        streamSMask = new MemoryStream();
            PDFDictionaryStream dictSMask   = new PDFDictionaryStream(new PDFDictionary(), streamSMask);

            initSMask(dictSMask);
            Dictionary.AddItem("SMask", dictSMask);
            MemoryStream compressionStream = new MemoryStream();

            compressionStream.Position = 0;
            writeIDAT(compressionStream, fs);
            MemoryStream decodeStream = FlateDecoder.Decode(compressionStream, null);

            byte[] pdfData = toPDFData(decodeStream, (n + 1) * (_bitdepth / 8));
            for (int i = 0; i < pdfData.Length; i += (n + 1) * (_bitdepth / 8))
            {
                GetStream().Write(pdfData, i, n * (_bitdepth / 8));
                byte b = pdfData[i + n * (_bitdepth / 8)];
                if (_bitdepth == 16)
                {
                    b = (byte)((((int)b << 8) | (int)pdfData[i + n * (_bitdepth / 8) + 1]) / 256);
                }
                streamSMask.WriteByte(b);
            }
        }
Exemple #3
0
 private void initialize3IDAT(FileStream fs, long positionTRNS)
 {
     if (positionTRNS != 0)
     {
         long oldPosition = fs.Position;
         fs.Position = positionTRNS;
         byte[] buf = new byte[4];
         fs.Read(buf, 0, buf.Length);
         fs.Position += 4;
         byte[] data = new byte[toInt32(buf)];
         fs.Read(data, 0, data.Length);
         fs.Position = oldPosition;
         byte max = 0;
         for (int i = 0; i < data.Length; ++i)
         {
             if (max < data[i])
             {
                 max = data[i];
             }
         }
         PDFArray array = new PDFArray();
         array.AddItem(new PDFNumber(max));
         array.AddItem(new PDFNumber(max));
         Dictionary.AddItem("Mask", array);
     }
     if (_interface == 1)
     {
         MemoryStream compressionStream = new MemoryStream();
         compressionStream.Position = 0;
         writeIDAT(compressionStream, fs);
         MemoryStream decodeStream = FlateDecoder.Decode(compressionStream, null);
         byte[]       pdfData      = toPDFData(decodeStream, 1);
         GetStream().Write(pdfData, 0, pdfData.Length);
     }
     else
     {
         writeIDAT(GetStream(), fs);
         PDFDictionary dict = new PDFDictionary();
         dict.AddItem("Predictor", new PDFNumber(15));
         dict.AddItem("Colors", new PDFNumber(1));
         dict.AddItem("BitsPerComponent", new PDFNumber(_bitdepth));
         dict.AddItem("Columns", new PDFNumber(_width));
         Dictionary.AddItem("Filter", new PDFName("FlateDecode"));
         Dictionary.AddItem("DecodeParms", dict);
     }
 }
Exemple #4
0
        public void Decode()
        {
            Filter[] filters = getFilters();
            if (filters.Length == 0)
            {
                return;
            }

            _stream.Position = 0;
            try
            {
                for (int i = 0; i < filters.Length; ++i)
                {
                    switch (filters[i])
                    {
                    case Filter.ASCII85:
                        _stream = ASCII85Decoder.Decode(_stream);
                        break;

                    case Filter.ASCIIHex:
                        _stream = ASCIIHexDecoder.Decode(_stream);
                        break;

                    case Filter.RunLength:
                        _stream = RunLengthDecoder.Decode(_stream);
                        break;

                    case Filter.JPX:
                        _stream = JPXDecoder.Decode(_stream);
                        break;

                    case Filter.CCITTFax:
                        _stream = CCITTFaxDecoder.Decode(_stream, getDecodeParameters(i));
                        break;

                    case Filter.DCT:
                        _stream = DCTDecoder.Decode(_stream, getDecodeParameters(i));
                        break;

                    case Filter.Flate:
                        _stream = FlateDecoder.Decode(_stream, getDecodeParameters(i));
                        break;

                    case Filter.JBIG2:
                        _stream = JBIG2Decoder.Decode(_stream, getDecodeParameters(i));
                        break;

                    case Filter.LZW:
                        _stream = LZWDecoder.Decode(_stream, getDecodeParameters(i));
                        break;
                    }
                    _stream.Position = 0;
                }
            }
            catch
            {
                return;
            }

            _dictionary.RemoveItem("Filter");
            _dictionary.RemoveItem("DecodeParms");
        }