Exemple #1
0
        /// <summary>
        /// Generated from text on F-23, F.13 - Huffman decoded of AC coefficients
        /// on ISO DIS 10918-1. Requirements and Guidelines.
        /// </summary>
        internal void decode_ac_coefficients(JPEGBinaryReader JPEGStream, float[] zz)
        {
            for (int k = 1; k < 64; k++)
            {
                int s = ACTable.Decode(JPEGStream);
                int r = s >> 4;
                s &= 15;


                if (s != 0)
                {
                    k += r;

                    r     = (int)JPEGStream.ReadBits(s);
                    s     = (int)HuffmanTable.Extend(r, s);
                    zz[k] = s;
                }
                else
                {
                    if (r != 15)
                    {
                        //throw new JPEGMarkerFoundException();
                        return;
                    }
                    k += 15;
                }
            }
        }
Exemple #2
0
        public JpegComponent(JpegScan parentScan, byte id, byte factorHorizontal, byte factorVertical,
                             byte quantizationID, byte colorMode)
        {
            parent = parentScan;

            /* Set default tables in case they're not provided.  J. Powers */
            // TODO: only gen if needed

            if (colorMode == JPEGFrame.JPEG_COLOR_YCbCr)
            {
                if (id == 1) // Luminance
                {
                    ACTable = new HuffmanTable(JpegHuffmanTable.StdACLuminance);
                    DCTable = new HuffmanTable(JpegHuffmanTable.StdDCLuminance);
                }
                else
                {
                    ACTable = new HuffmanTable( JpegHuffmanTable.StdACChrominance);
                    DCTable = new HuffmanTable( JpegHuffmanTable.StdACLuminance);
                }
            }

            component_id = id;

            factorH = factorHorizontal;
            factorV = factorVertical;

            quant_id = quantizationID;
        }
Exemple #3
0
        public JpegComponent(JpegScan parentScan, byte id, byte factorHorizontal, byte factorVertical,
                             byte quantizationID, byte colorMode)
        {
            parent = parentScan;

            /* Set default tables in case they're not provided.  J. Powers */
            // TODO: only gen if needed

            if (colorMode == JPEGFrame.JPEG_COLOR_YCbCr)
            {
                if (id == 1) // Luminance
                {
                    ACTable = new HuffmanTable(JpegHuffmanTable.StdACLuminance);
                    DCTable = new HuffmanTable(JpegHuffmanTable.StdDCLuminance);
                }
                else
                {
                    ACTable = new HuffmanTable(JpegHuffmanTable.StdACChrominance);
                    DCTable = new HuffmanTable(JpegHuffmanTable.StdACLuminance);
                }
            }

            component_id = id;

            factorH = factorHorizontal;
            factorV = factorVertical;

            quant_id = quantizationID;
        }
Exemple #4
0
        /// <summary>
        /// Generated from text on F-22, F.2.2.1 - Huffman decoding of DC
        /// coefficients on ISO DIS 10918-1. Requirements and Guidelines.
        /// </summary>
        /// <param name="JPEGStream">Stream that contains huffman bits</param>
        /// <returns>DC coefficient</returns>
        public float decode_dc_coefficient(JPEGBinaryReader JPEGStream)
        {
            int   t    = DCTable.Decode(JPEGStream);
            float diff = JPEGStream.ReadBits(t);

            diff       = HuffmanTable.Extend((int)diff, t);
            diff       = (previousDC + diff);
            previousDC = diff;
            return(diff);
        }
Exemple #5
0
        public void DecodeDCFirst(JPEGBinaryReader stream, float[] dest)
        {
            float[] datablock = new float[64];
            int     s         = DCTable.Decode(stream);
            int     r         = stream.ReadBits(s);

            s          = HuffmanTable.Extend(r, s);
            s          = (int)previousDC + s;
            previousDC = s;

            dest[0] = s << successiveLow;
        }
Exemple #6
0
        /// <summary>
        /// Encodes a JPEG, preserving the colorspace and metadata of the input JPEG.
        /// </summary>
        /// <param name="decodedJpeg">Decoded Jpeg to start with.</param>
        /// <param name="quality">Quality of the image from 0 to 100.  (Compression from max to min.)</param>
        /// <param name="outStream">Stream where the result will be placed.</param>
        public JpegEncoder(DecodedJpeg decodedJpeg, int quality, Stream outStream)
        {
            _input = decodedJpeg;

            /* This encoder requires YCbCr */
            _input.Image.ChangeColorSpace(ColorSpace.YCbCr);

            _quality = quality;

            _height = _input.Image.Height;
            _width = _input.Image.Width;
            _outStream = outStream;
            _dct = new DCT(_quality);
            _huf = new HuffmanTable(null);
        }
Exemple #7
0
        public void DecodeACFirst(JPEGBinaryReader stream, float[] zz)
        {
            if (stream.eob_run > 0)
            {
                stream.eob_run--;
                return;
            }

            for (int k = spectralStart; k <= spectralEnd; k++)
            {
                int s = ACTable.Decode(stream);
                int r = s >> 4;
                s &= 15;


                if (s != 0)
                {
                    k += r;

                    r     = (int)stream.ReadBits(s);
                    s     = (int)HuffmanTable.Extend(r, s);
                    zz[k] = s << successiveLow;
                }
                else
                {
                    if (r != 15)
                    {
                        stream.eob_run = 1 << r;

                        if (r != 0)
                        {
                            stream.eob_run += stream.ReadBits(r);
                        }

                        stream.eob_run--;

                        break;
                    }

                    k += 15;
                }
            }
        }
Exemple #8
0
 public void setDCTable(JpegHuffmanTable table)
 {
     DCTable = new HuffmanTable(table);
 }
Exemple #9
0
 public void setACTable(JpegHuffmanTable table)
 {
     ACTable = new HuffmanTable(table);
 }