Esempio n. 1
0
 public override void Write(
     byte[]  bytes,
     int off,
     int len)
 {
     _out.Write(bytes, off, len);
 }
Esempio n. 2
0
 static Image ProcessExtraSamples(ZDeflaterOutputStream zip, ZDeflaterOutputStream mzip, byte[] outBuf, int samplePerPixel, int bitsPerSample, int width, int height)
 {
     if (bitsPerSample == 8)
     {
         byte[] mask  = new byte[width * height];
         int    mptr  = 0;
         int    optr  = 0;
         int    total = width * height * samplePerPixel;
         for (int k = 0; k < total; k += samplePerPixel)
         {
             for (int s = 0; s < samplePerPixel - 1; ++s)
             {
                 outBuf[optr++] = outBuf[k + s];
             }
             mask[mptr++] = outBuf[k + samplePerPixel - 1];
         }
         zip.Write(outBuf, 0, optr);
         mzip.Write(mask, 0, mptr);
     }
     else
     {
         throw new ArgumentException(MessageLocalization.GetComposedMessage("extra.samples.are.not.supported"));
     }
     return(null);
 }
Esempio n. 3
0
        virtual public void WriteData(byte[] data, int stride)
        {
            MemoryStream          stream = new MemoryStream();
            ZDeflaterOutputStream zip    = new ZDeflaterOutputStream(stream, 5);
            int k;

            for (k = 0; k < data.Length - stride; k += stride)
            {
                zip.WriteByte(0);
                zip.Write(data, k, stride);
            }
            int remaining = data.Length - k;

            if (remaining > 0)
            {
                zip.WriteByte(0);
                zip.Write(data, k, remaining);
            }
            zip.Close();
            WriteChunk(IDAT, stream.ToArray());
        }
Esempio n. 4
0
        public static void FlateEncode(Stream rawData, Stream result)
        {
            ZDeflaterOutputStream stream = new ZDeflaterOutputStream(result);

            byte[] buffer = new byte[0x400];
            int    count  = 0;

            while ((count = rawData.Read(buffer, 0, buffer.Length)) > 0)
            {
                stream.Write(buffer, 0, count);
            }
            stream.Finish();
        }
Esempio n. 5
0
        /// <summary>
        /// Encodes the inner.
        /// </summary>
        /// <param name="rawData">The raw data.</param>
        /// <param name="result">The result.</param>
        /// <param name="options">The options.</param>
        protected override void EncodeInner(Stream rawData, Stream result, Dictionary <PdfName, PdfObjectBase> options)
        {
            ZDeflaterOutputStream stream = new ZDeflaterOutputStream(result);

            byte[] buffer = new byte[0x400];
            int    count  = 0;

            while ((count = rawData.Read(buffer, 0, buffer.Length)) > 0)
            {
                stream.Write(buffer, 0, count);
            }
            stream.Finish();
        }
Esempio n. 6
0
        public void WriteData(byte[] data, int stride)
        {
            MemoryStream          stream = new MemoryStream();
            ZDeflaterOutputStream zip    = new ZDeflaterOutputStream(stream, 5);

            for (int k = 0; k < data.Length; k += stride)
            {
                zip.WriteByte(0);
                zip.Write(data, k, stride);
            }
            zip.Finish();
            WriteChunk(IDAT, stream.ToArray());
        }
Esempio n. 7
0
        virtual public void WriteIccProfile(byte[] data)
        {
            MemoryStream stream = new MemoryStream();

            stream.WriteByte((byte)'I');
            stream.WriteByte((byte)'C');
            stream.WriteByte((byte)'C');
            stream.WriteByte(0);
            stream.WriteByte(0);
            ZDeflaterOutputStream zip = new ZDeflaterOutputStream(stream, 5);

            zip.Write(data, 0, data.Length);
            zip.Close();
            WriteChunk(iCCP, stream.ToArray());
        }
Esempio n. 8
0
 /**
  * Creates a new PDF stream object that will replace a stream
  * in a existing PDF file.
  * @param   reader  the reader that holds the existing PDF
  * @param   conts   the new content
  * @param   compressionLevel    the compression level for the content
  * @since   2.1.3 (replacing the existing constructor without param compressionLevel)
  */
 public PRStream(PdfReader reader, byte[] conts, int compressionLevel)
 {
     this.reader = reader;
     this.offset = -1;
     if (Document.Compress)
     {
         MemoryStream          stream = new MemoryStream();
         ZDeflaterOutputStream zip    = new ZDeflaterOutputStream(stream, compressionLevel);
         zip.Write(conts, 0, conts.Length);
         zip.Close();
         bytes = stream.ToArray();
         Put(PdfName.FILTER, PdfName.FLATEDECODE);
     }
     else
     {
         bytes = conts;
     }
     Length = bytes.Length;
 }
Esempio n. 9
0
 /**Sets the data associated with the stream
  * @param data raw data, decrypted and uncompressed.
  */
 public void SetData(byte[] data)
 {
     Remove(PdfName.FILTER);
     this.offset = -1;
     if (Document.Compress)
     {
         MemoryStream          stream = new MemoryStream();
         ZDeflaterOutputStream zip    = new ZDeflaterOutputStream(stream);
         zip.Write(data, 0, data.Length);
         zip.Close();
         bytes = stream.ToArray();
         Put(PdfName.FILTER, PdfName.FLATEDECODE);
     }
     else
     {
         bytes = data;
     }
     Length = bytes.Length;
 }
Esempio n. 10
0
 /// <summary>
 /// Creates a new PDF stream object that will replace a stream
 /// in a existing PDF file.
 /// @since   2.1.3 (replacing the existing constructor without param compressionLevel)
 /// </summary>
 /// <param name="reader">the reader that holds the existing PDF</param>
 /// <param name="conts">the new content</param>
 /// <param name="compressionLevel">the compression level for the content</param>
 public PrStream(PdfReader reader, byte[] conts, int compressionLevel)
 {
     this.reader = reader;
     offset      = -1;
     if (Document.Compress)
     {
         MemoryStream          stream = new MemoryStream();
         ZDeflaterOutputStream zip    = new ZDeflaterOutputStream(stream, compressionLevel);
         zip.Write(conts, 0, conts.Length);
         zip.Close();
         Bytes = stream.ToArray();
         Put(PdfName.Filter, PdfName.Flatedecode);
     }
     else
     {
         Bytes = conts;
     }
     Length = Bytes.Length;
 }
Esempio n. 11
0
 /// <summary>
 /// Sets the data associated with the stream, either compressed or
 /// uncompressed. Note that the data will never be compressed if
 /// Document.compress is set to false.
 /// @since   iText 2.1.3
 /// </summary>
 /// <param name="data">raw data, decrypted and uncompressed.</param>
 /// <param name="compress">true if you want the stream to be compresssed.</param>
 /// <param name="compressionLevel">a value between -1 and 9 (ignored if compress == false)</param>
 public void SetData(byte[] data, bool compress, int compressionLevel)
 {
     Remove(PdfName.Filter);
     offset = -1;
     if (Document.Compress && compress)
     {
         MemoryStream          stream = new MemoryStream();
         ZDeflaterOutputStream zip    = new ZDeflaterOutputStream(stream, compressionLevel);
         zip.Write(data, 0, data.Length);
         zip.Close();
         Bytes            = stream.ToArray();
         CompressionLevel = compressionLevel;
         Put(PdfName.Filter, PdfName.Flatedecode);
     }
     else
     {
         Bytes = data;
     }
     Length = Bytes.Length;
 }
Esempio n. 12
0
        /**
         * Compresses the stream.
         * @param compressionLevel the compression level (0 = best speed, 9 = best compression, -1 is default)
         * @since   2.1.3
         */
        virtual public void FlateCompress(int compressionLevel)
        {
            if (!Document.Compress)
            {
                return;
            }
            // check if the flateCompress-method has already been used
            if (compressed)
            {
                return;
            }
            this.compressionLevel = compressionLevel;
            if (inputStream != null)
            {
                compressed = true;
                return;
            }
            // check if a filter already exists
            PdfObject filter = PdfReader.GetPdfObject(Get(PdfName.FILTER));

            if (filter != null)
            {
                if (filter.IsName())
                {
                    if (PdfName.FLATEDECODE.Equals(filter))
                    {
                        return;
                    }
                }
                else if (filter.IsArray())
                {
                    if (((PdfArray)filter).Contains(PdfName.FLATEDECODE))
                    {
                        return;
                    }
                }
                else
                {
                    throw new PdfException(MessageLocalization.GetComposedMessage("stream.could.not.be.compressed.filter.is.not.a.name.or.array"));
                }
            }
            // compress
            MemoryStream          stream = new MemoryStream();
            ZDeflaterOutputStream zip    = new ZDeflaterOutputStream(stream, compressionLevel);

            if (streamBytes != null)
            {
                streamBytes.WriteTo(zip);
            }
            else
            {
                zip.Write(bytes, 0, bytes.Length);
            }
            //zip.Close();
            zip.Finish();
            // update the object
            streamBytes = stream;
            bytes       = null;
            Put(PdfName.LENGTH, new PdfNumber(streamBytes.Length));
            if (filter == null)
            {
                Put(PdfName.FILTER, PdfName.FLATEDECODE);
            }
            else
            {
                PdfArray filters = new PdfArray(filter);
                filters.Add(0, PdfName.FLATEDECODE);
                Put(PdfName.FILTER, filters);
            }
            compressed = true;
        }
Esempio n. 13
0
        // methods

        /**
         * Compresses the stream.
         *
         * @throws PdfException if a filter is allready defined
         */

        public void FlateCompress()
        {
            if (!Document.Compress)
            {
                return;
            }
            // check if the flateCompress-method has allready been
            if (compressed)
            {
                return;
            }
            if (inputStream != null)
            {
                compressed = true;
                return;
            }
            // check if a filter allready exists
            PdfObject filter = Get(PdfName.FILTER);

            if (filter != null)
            {
                if (filter.IsName() && ((PdfName)filter).CompareTo(PdfName.FLATEDECODE) == 0)
                {
                    return;
                }
                else if (filter.IsArray() && ((PdfArray)filter).Contains(PdfName.FLATEDECODE))
                {
                    return;
                }
                else
                {
                    throw new PdfException("Stream could not be compressed: filter is not a name or array.");
                }
            }
            // compress
            MemoryStream          stream = new MemoryStream();
            ZDeflaterOutputStream zip    = new ZDeflaterOutputStream(stream);

            if (streamBytes != null)
            {
                streamBytes.WriteTo(zip);
            }
            else
            {
                zip.Write(bytes, 0, bytes.Length);
            }
            //zip.Close();
            zip.Finish();
            // update the object
            streamBytes = stream;
            bytes       = null;
            Put(PdfName.LENGTH, new PdfNumber(streamBytes.Length));
            if (filter == null)
            {
                Put(PdfName.FILTER, PdfName.FLATEDECODE);
            }
            else
            {
                PdfArray filters = new PdfArray(filter);
                filters.Add(PdfName.FLATEDECODE);
                Put(PdfName.FILTER, filters);
            }
            compressed = true;
        }
        /// <summary>
        /// methods
        /// </summary>
        /// <summary>
        /// Compresses the stream.
        /// @since   2.1.3
        /// </summary>
        /// <param name="compressionLevel">the compression level (0 = best speed, 9 = best compression, -1 is default)</param>
        public void FlateCompress(int compressionLevel)
        {
            if (!Document.Compress)
            {
                return;
            }
            // check if the flateCompress-method has allready been
            if (Compressed)
            {
                return;
            }
            CompressionLevel = compressionLevel;
            if (InputStream != null)
            {
                Compressed = true;
                return;
            }
            // check if a filter allready exists
            PdfObject filter = PdfReader.GetPdfObject(Get(PdfName.Filter));

            if (filter != null)
            {
                if (filter.IsName())
                {
                    if (PdfName.Flatedecode.Equals(filter))
                    {
                        return;
                    }
                }
                else if (filter.IsArray())
                {
                    if (((PdfArray)filter).Contains(PdfName.Flatedecode))
                    {
                        return;
                    }
                }
                else
                {
                    throw new PdfException("Stream could not be compressed: filter is not a name or array.");
                }
            }
            // compress
            MemoryStream          stream = new MemoryStream();
            ZDeflaterOutputStream zip    = new ZDeflaterOutputStream(stream, compressionLevel);

            if (StreamBytes != null)
            {
                StreamBytes.WriteTo(zip);
            }
            else
            {
                zip.Write(Bytes, 0, Bytes.Length);
            }
            //zip.Close();
            zip.Finish();
            // update the object
            StreamBytes = stream;
            Bytes       = null;
            Put(PdfName.LENGTH, new PdfNumber(StreamBytes.Length));
            if (filter == null)
            {
                Put(PdfName.Filter, PdfName.Flatedecode);
            }
            else
            {
                PdfArray filters = new PdfArray(filter);
                filters.Add(PdfName.Flatedecode);
                Put(PdfName.Filter, filters);
            }
            Compressed = true;
        }