Exemplo n.º 1
0
        public static void Convert(PngHeader header, byte[] inData, byte[] outData)
        {
            int stride = header.Stride;
            PngFilter decoder = new PngFilter(stride,header.BytesPerPixel);

            int inOfs=1;
            int outOfs= 0;
            for(int row = 0; row < header.Height; row++)
            {
                decoder.Decode(inData,outData,inOfs,outOfs);

                inOfs  += stride+1;
                outOfs += stride;
            }
        }
Exemplo n.º 2
0
        public static void WriteRows(byte[] data, PngHeader header, Stream stream)
        {
            int stride=header.Stride;

            if(header.IsMonochrome)
            {
                int ofs = 0;
                for(int row=0; row < header.Height; row++)
                {
                    stream.WriteByte((byte)Filter.None);
                    stream.Write(data,ofs,stride);

                    ofs+=stride;
                };
            }
            else
            {
                var lines=new Dictionary<Filter, byte[]>();
                foreach(Filter filter in Enum.GetValues(typeof(Filter)))
                    lines.Add(filter,new byte[stride]);

                PngFilter encoder = new PngFilter(stride,header.BytesPerPixel);

                int ofs = 0;
                for(int row=0; row < header.Height; row++)
                {
                    Filter filter = encoder.Encode(data,ofs,lines);

                    stream.WriteByte((byte)filter);
                    stream.Write(lines[filter],0,stride);

                    ofs+=stride;
                };
            }
        }