Example #1
0
        public JpegReadStatusInt DecodeACFirst(JpegBinaryReader stream, float[] zz)
        {
            if (stream.eobRun > 0)
            {
                stream.eobRun--;
                return(JpegReadStatusInt.GetSuccess());
            }

            for (int k = spectralStart; k <= spectralEnd; k++)
            {
                var status = ACTable.Decode(stream);
                if (status.Status != Status.Success)
                {
                    return(status);
                }
                int s = status.Result;
                int r = s >> 4;
                s &= 15;

                if (s != 0)
                {
                    k     += r;
                    status = stream.ReadBits(s);
                    if (status.Status != Status.Success)
                    {
                        return(status);
                    }
                    r     = status.Result;
                    s     = HuffmanTable.Extend(r, s);
                    zz[k] = s << successiveLow;
                }
                else
                {
                    if (r != 15)
                    {
                        stream.eobRun = 1 << r;

                        if (r != 0)
                        {
                            status = stream.ReadBits(r);
                            if (status.Status != Status.Success)
                            {
                                return(status);
                            }
                            stream.eobRun += status.Result;
                        }

                        stream.eobRun--;
                        break;
                    }

                    k += 15;
                }
            }
            return(JpegReadStatusInt.GetSuccess());
        }
Example #2
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>
        /// <param name="diff">The DC coefficient</param>
        /// <returns>The result of the read</returns>
        public JpegReadStatusInt decode_dc_coefficient(JpegBinaryReader jpegStream, out float diff)
        {
            diff = 0;
            var status = DCTable.Decode(jpegStream);

            if (status.Status != Status.Success)
            {
                return(status);
            }
            int t = status.Result;

            status = jpegStream.ReadBits(t);
            if (status.Status != Status.Success)
            {
                return(status);
            }
            diff       = HuffmanTable.Extend(status.Result, t);
            diff       = (previousDC + diff);
            previousDC = diff;
            return(status);
        }
Example #3
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 JpegReadStatusInt decode_ac_coefficients(JpegBinaryReader jpegStream, float[] zz)
        {
            var status = new JpegReadStatusInt();

            for (int k = 1; k < 64; k++)
            {
                status = ACTable.Decode(jpegStream);
                if (status.Status != Status.Success)
                {
                    return(status);
                }
                int s = status.Result;
                int r = s >> 4;
                s &= 15;

                if (s != 0)
                {
                    k     += r;
                    status = jpegStream.ReadBits(s);
                    if (status.Status != Status.Success)
                    {
                        return(status);
                    }
                    s     = HuffmanTable.Extend(status.Result, s);
                    zz[k] = s;
                }
                else
                {
                    if (r != 15)
                    {
                        //throw new JPEGMarkerFoundException();
                        return(status);
                    }
                    k += 15;
                }
            }
            return(status);
        }
Example #4
0
        public JpegReadStatusInt DecodeDCFirst(JpegBinaryReader stream, float[] dest)
        {
            var status = DCTable.Decode(stream);

            if (status.Status != Status.Success)
            {
                return(status);                // We reached the end of the stream.
            }
            int s = status.Result;

            status = stream.ReadBits(s);
            if (status.Status != Status.Success)
            {
                return(status);
            }
            int r = status.Result;

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

            dest[0] = s << successiveLow;
            return(status);
        }