Read() public méthode

public Read ( int bitCount ) : int
bitCount int
Résultat int
        internal Sample(BitStream bitStream, byte bitsPerComponent, byte componentCount)
        {
            if (bitStream == null)
                throw new ArgumentNullException("bitStream");

            if (bitsPerComponent <= 0 || bitsPerComponent > 16)
                throw new ArgumentOutOfRangeException("bitsPerComponent");

            if (componentCount <= 0 || componentCount > 5)
                throw new ArgumentOutOfRangeException("componentCount");

            m_bitsPerComponent = bitsPerComponent;

			componentsLength = componentCount;
			if (componentCount >= 1) m_components_r = (short)bitStream.Read(bitsPerComponent);
			else m_components_r = 0;

			if (componentCount >= 2) m_components_g = (short)bitStream.Read(bitsPerComponent);
			else m_components_g = 0;

			if (componentCount >= 3) m_components_b = (short)bitStream.Read(bitsPerComponent);
			else m_components_b = 0;

			if (componentCount >= 4) m_components_a = (short)bitStream.Read(bitsPerComponent);
			else m_components_a = 0;
			//m_components = new short[componentCount];
			//for (short i = 0; i < componentCount; ++i)
			//	m_components[i] = (short)bitStream.Read(bitsPerComponent);
        }
Exemple #2
0
        internal Sample(BitStream bitStream, byte bitsPerComponent, byte componentCount)
        {
            if (bitStream is null)
            {
                throw new ArgumentNullException(nameof(bitStream));
            }

            if (bitsPerComponent <= 0 || bitsPerComponent > 16)
            {
                throw new ArgumentOutOfRangeException(nameof(bitsPerComponent));
            }

            if (componentCount <= 0 || componentCount > 5)
            {
                throw new ArgumentOutOfRangeException(nameof(componentCount));
            }

            BitsPerComponent = bitsPerComponent;

            m_components = new short[componentCount];
            for (short i = 0; i < componentCount; ++i)
            {
                m_components[i] = (short)bitStream.Read(bitsPerComponent);
            }
        }
Exemple #3
0
        internal Sample(BitStream bitStream, byte bitsPerComponent, byte componentCount)
        {
            if (bitStream == null)
                throw new ArgumentNullException("bitStream");

            if (bitsPerComponent <= 0 || bitsPerComponent > 16)
                throw new ArgumentOutOfRangeException("bitsPerComponent");

            if (componentCount <= 0 || componentCount > 5)
                throw new ArgumentOutOfRangeException("componentCount");

            m_bitsPerComponent = bitsPerComponent;

            m_components = new short[componentCount];
            for (short i = 0; i < componentCount; ++i)
                m_components[i] = (short)bitStream.Read(bitsPerComponent);
        }
Exemple #4
0
        /// <summary>
        /// Creates a row from raw samples data.
        /// </summary>
        /// <param name="row">Raw description of samples.<br/>
        /// You can pass collection with more than sampleCount samples - only sampleCount samples
        /// will be parsed and all remaining bytes will be ignored.</param>
        /// <param name="columnCount">The number of samples in row.</param>
        /// <param name="bitsPerComponent">The number of bits per component.</param>
        /// <param name="componentsPerSample">The number of components per sample.</param>
        public SampleRow(byte[] row, int columnCount, byte bitsPerComponent, byte componentsPerSample)
        {
            if (row == null)
            {
                throw new ArgumentNullException("row");
            }

            if (row.Length == 0)
            {
                throw new ArgumentException("row is empty");
            }

            if (columnCount <= 0)
            {
                throw new ArgumentOutOfRangeException("sampleCount");
            }

            if (bitsPerComponent <= 0 || bitsPerComponent > 16)
            {
                throw new ArgumentOutOfRangeException("bitsPerComponent");
            }

            if (componentsPerSample <= 0 || componentsPerSample > 5) //1,2,3,4
            {
                throw new ArgumentOutOfRangeException("componentsPerSample");
            }

            _componentsPerSample = componentsPerSample;


            _columnCount = columnCount;

            using (BitStream bitStream = new BitStream())
            {
                bitStream.ResetInput(row);

                //create long buffer for a single line
                _lineBuffer16 = new short[columnCount * componentsPerSample];
                int byteIndex = 0;
                for (int i = 0; i < columnCount; ++i)
                {
                    //each component
                    //eg. 1,2,3,4
                    switch (componentsPerSample)
                    {
                    case 1:
                        _lineBuffer16[byteIndex] = (short)bitStream.Read(bitsPerComponent);
                        byteIndex++;
                        break;

                    case 2:
                        _lineBuffer16[byteIndex]     = (short)bitStream.Read(bitsPerComponent);
                        _lineBuffer16[byteIndex + 1] = (short)bitStream.Read(bitsPerComponent);
                        byteIndex += 2;
                        break;

                    case 3:
                        _lineBuffer16[byteIndex]     = (short)bitStream.Read(bitsPerComponent);
                        _lineBuffer16[byteIndex + 1] = (short)bitStream.Read(bitsPerComponent);
                        _lineBuffer16[byteIndex + 2] = (short)bitStream.Read(bitsPerComponent);
                        byteIndex += 3;
                        break;

                    case 4:
                        _lineBuffer16[byteIndex]     = (short)bitStream.Read(bitsPerComponent);
                        _lineBuffer16[byteIndex + 1] = (short)bitStream.Read(bitsPerComponent);
                        _lineBuffer16[byteIndex + 2] = (short)bitStream.Read(bitsPerComponent);
                        _lineBuffer16[byteIndex + 4] = (short)bitStream.Read(bitsPerComponent);
                        byteIndex += 4;
                        break;

                    default:
                        throw new NotSupportedException();
                    }
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Creates a row from raw samples data.
        /// </summary>
        /// <param name="row">Raw description of samples.<br/>
        /// You can pass collection with more than sampleCount samples - only sampleCount samples
        /// will be parsed and all remaining bytes will be ignored.</param>
        /// <param name="columnCount">The number of samples in row.</param>
        /// <param name="bitsPerComponent">The number of bits per component.</param>
        /// <param name="componentsPerSample">The number of components per sample.</param>
        public SampleRow(byte[] row, int columnCount, byte bitsPerComponent, byte componentsPerSample)
        {
            if (row == null)
            {
                throw new ArgumentNullException("row");
            }

            if (row.Length == 0)
            {
                throw new ArgumentException("row is empty");
            }

            if (columnCount <= 0)
            {
                throw new ArgumentOutOfRangeException("sampleCount");
            }

            if (bitsPerComponent <= 0 || bitsPerComponent > 16)
            {
                throw new ArgumentOutOfRangeException("bitsPerComponent");
            }

            if (componentsPerSample <= 0 || componentsPerSample > 5) //1,2,3,4
            {
                throw new ArgumentOutOfRangeException("componentsPerSample");
            }

            this.componentsPerSample = componentsPerSample;
            this.m_bytes             = row;
            this.columnCount         = columnCount;
            using (BitStream bitStream = new BitStream(row))
            {
                //create long buffer for a single line
                lineBuffer = new short[columnCount * componentsPerSample];
                int byteIndex = 0;
                for (int i = 0; i < columnCount; ++i)
                {
                    //each component
                    //eg. 1,2,3,4
                    switch (componentsPerSample)
                    {
                    case 1:
                        lineBuffer[byteIndex] = (short)bitStream.Read(bitsPerComponent);
                        byteIndex++;
                        break;

                    case 2:
                        lineBuffer[byteIndex]     = (short)bitStream.Read(bitsPerComponent);
                        lineBuffer[byteIndex + 1] = (short)bitStream.Read(bitsPerComponent);
                        byteIndex += 2;
                        break;

                    case 3:
                        lineBuffer[byteIndex]     = (short)bitStream.Read(bitsPerComponent);
                        lineBuffer[byteIndex + 1] = (short)bitStream.Read(bitsPerComponent);
                        lineBuffer[byteIndex + 2] = (short)bitStream.Read(bitsPerComponent);
                        byteIndex += 3;
                        break;

                    case 4:
                        lineBuffer[byteIndex]     = (short)bitStream.Read(bitsPerComponent);
                        lineBuffer[byteIndex + 1] = (short)bitStream.Read(bitsPerComponent);
                        lineBuffer[byteIndex + 2] = (short)bitStream.Read(bitsPerComponent);
                        lineBuffer[byteIndex + 4] = (short)bitStream.Read(bitsPerComponent);
                        byteIndex += 4;
                        break;

                    default:
                        throw new NotSupportedException();
                    }
                    //for (short i = 0; i < componentCount; ++i)
                    //{
                    //    //bitPerSample may >8 bits
                    //    m_components[i] = (short)bitStream.Read(bitsPerComponent);
                    //}
                }
                //m_samples = new Sample[sampleCount];
                //for (int i = 0; i < sampleCount; ++i)
                //    m_samples[i] = new Sample(bitStream, bitsPerComponent, componentsPerSample);
            }
        }
Exemple #6
0
        /// <summary>
        /// Creates a row from raw samples data.
        /// </summary>
        /// <param name="row">Raw description of samples.<br/>
        /// You can pass collection with more than sampleCount samples - only sampleCount samples 
        /// will be parsed and all remaining bytes will be ignored.</param>
        /// <param name="columnCount">The number of samples in row.</param>
        /// <param name="bitsPerComponent">The number of bits per component.</param>
        /// <param name="componentsPerSample">The number of components per sample.</param>
        public SampleRow(byte[] row, int columnCount, byte bitsPerComponent, byte componentsPerSample)
        {
            if (row == null)
                throw new ArgumentNullException("row");

            if (row.Length == 0)
                throw new ArgumentException("row is empty");

            if (columnCount <= 0)
                throw new ArgumentOutOfRangeException("sampleCount");

            if (bitsPerComponent <= 0 || bitsPerComponent > 16)
                throw new ArgumentOutOfRangeException("bitsPerComponent");

            if (componentsPerSample <= 0 || componentsPerSample > 5) //1,2,3,4
                throw new ArgumentOutOfRangeException("componentsPerSample");

            this.componentsPerSample = componentsPerSample;
            this.m_bytes = row;
            this.columnCount = columnCount;
            using (BitStream bitStream = new BitStream(row))
            {
                //create long buffer for a single line                
                lineBuffer = new short[columnCount * componentsPerSample];
                int byteIndex = 0;
                for (int i = 0; i < columnCount; ++i)
                {
                    //each component
                    //eg. 1,2,3,4 
                    switch (componentsPerSample)
                    {
                        case 1:
                            lineBuffer[byteIndex] = (short)bitStream.Read(bitsPerComponent);
                            byteIndex++;
                            break;
                        case 2:
                            lineBuffer[byteIndex] = (short)bitStream.Read(bitsPerComponent);
                            lineBuffer[byteIndex + 1] = (short)bitStream.Read(bitsPerComponent);
                            byteIndex += 2;
                            break;
                        case 3:
                            lineBuffer[byteIndex] = (short)bitStream.Read(bitsPerComponent);
                            lineBuffer[byteIndex + 1] = (short)bitStream.Read(bitsPerComponent);
                            lineBuffer[byteIndex + 2] = (short)bitStream.Read(bitsPerComponent);
                            byteIndex += 3;
                            break;
                        case 4:
                            lineBuffer[byteIndex] = (short)bitStream.Read(bitsPerComponent);
                            lineBuffer[byteIndex + 1] = (short)bitStream.Read(bitsPerComponent);
                            lineBuffer[byteIndex + 2] = (short)bitStream.Read(bitsPerComponent);
                            lineBuffer[byteIndex + 4] = (short)bitStream.Read(bitsPerComponent);
                            byteIndex += 4;
                            break;
                        default:
                            throw new NotSupportedException();
                    }
                    //for (short i = 0; i < componentCount; ++i)
                    //{
                    //    //bitPerSample may >8 bits                
                    //    m_components[i] = (short)bitStream.Read(bitsPerComponent);
                    //}
                }
                //m_samples = new Sample[sampleCount];
                //for (int i = 0; i < sampleCount; ++i)
                //    m_samples[i] = new Sample(bitStream, bitsPerComponent, componentsPerSample);
            }
        }