Esempio n. 1
0
        public JpegReadStatusInt ToInt()
        {
            var status = new JpegReadStatusInt();

            status.Status = Status;
            status.Result = Result;
            return(status);
        }
Esempio n. 2
0
        public static JpegReadStatusInt GetSuccess()
        {
            var status = new JpegReadStatusInt();

            status.Status = Status.Success;
            status.Result = 0;
            return(status);
        }
Esempio n. 3
0
        /// <summary>
        /// Places n bits from the stream, where the most-significant bits
        /// from the first byte read end up as the most-significant of the returned
        /// n bits.
        /// </summary>
        /// <param name="n">Number of bits to return</param>
        /// <returns>Integer containing the bits desired -- shifted all the way right.</returns>
        public JpegReadStatusInt ReadBits(int n)
        {
            JpegReadStatusInt status = new JpegReadStatusInt();
            int result = 0;

            #region Special case -- included for optimization purposes
            if (bitsLeft >= n)
            {
                bitsLeft     -= n;
                status.Result = bitBuffer >> (8 - n);
                bitBuffer     = (byte)(bitBuffer << n);
                status.Status = Status.Success;
                return(status);
            }
            #endregion

            while (n > 0)
            {
                if (bitsLeft == 0)
                {
                    var statusByte = ReadJpegByte();
                    status = statusByte.ToInt();
                    if (status.Status != Status.Success)
                    {
                        return(status); // We reached the end of the file, or found a marker.
                    }
                    bitBuffer = statusByte.Result;
                    bitsLeft  = 8;
                }

                int take = n <= bitsLeft ? n : bitsLeft;

                result = result | ((bitBuffer >> 8 - take) << (n - take));

                bitBuffer = (byte)(bitBuffer << take);

                bitsLeft -= take;
                n        -= take;
            }
            status.Result = result;
            return(status);
        }