Example #1
0
        internal Colour(Stream stream)
        {
            ElementReader reader = new ElementReader(stream);

            while (!reader.EOF)
            {
                eElement id = reader.readElementId();
                switch (id)
                {
                case eElement.MatrixCoefficients:
                    matrixCoefficients = (eMatrixCoefficients)reader.readByte(2);
                    break;

                case eElement.BitsPerChannel:
                    bitsPerChannel = reader.readUlong(0);
                    break;

                case eElement.ChromaSubsamplingHorz:
                    chromaSubsamplingHorz = reader.readUlong();
                    break;

                case eElement.ChromaSubsamplingVert:
                    chromaSubsamplingVert = reader.readUlong();
                    break;

                case eElement.CbSubsamplingHorz:
                    cbSubsamplingHorz = reader.readUlong();
                    break;

                case eElement.CbSubsamplingVert:
                    cbSubsamplingVert = reader.readUlong();
                    break;

                case eElement.ChromaSitingHorz:
                    chromaSitingHorz = (eChromaSitingHorz)reader.readByte(0);
                    break;

                case eElement.ChromaSitingVert:
                    chromaSitingVert = (eChromaSitingVert)reader.readByte(0);
                    break;

                case eElement.Range:
                    range = (eRange)reader.readByte(0);
                    break;

                case eElement.TransferCharacteristics:
                    transferCharacteristics = (eTransferCharacteristics)reader.readByte(2);
                    break;

                case eElement.Primaries:
                    primaries = (ePrimaries)reader.readByte(2);
                    break;

                case eElement.MaxCLL:
                    maxCLL = reader.readUlong();
                    break;

                case eElement.MaxFALL:
                    maxFALL = reader.readUlong();
                    break;

                case eElement.MasteringMetadata:
                    masteringMetadata = new MasteringMetadata(stream);
                    break;

                default:
                    reader.skipElement();
                    break;
                }
            }
        }
Example #2
0
        internal VideoUsabilityInfo(ref BitReader reader)
        {
            flags             = default;
            sampleAspectRatio = default;
            // When the video_format syntax element is not present, video_format value shall be inferred to be equal to 5.
            videoFormat             = eVideoFormat.Unspecified;
            colorPrimaries          = eColorPrimaries.Unspecified;
            transferCharacteristics = eTransferFunc.Unspecified;
            matrixCoefficients      = eMatrixCoefficients.Unspecified;
            numUnitsInTick          = timeScale = 0;
            chromaLocationTop       = chromaLocationBottom = 0;
            hrd = default;

            if (!reader.readBit())
            {
                return;
            }

            flags = eVuiFlags.VUI;
            if (reader.readBit())
            {
                // aspect_ratio_info_present_flag
                flags |= eVuiFlags.AspectRatio;
                byte index = (byte)reader.readInt(8);
                if (index < sSampleAspectRatio.predefined.Length)
                {
                    sampleAspectRatio = sSampleAspectRatio.predefined[index];
                }
                else if (index == 0xFF)
                {
                    checked
                    {
                        ushort w = (ushort)reader.readInt(16);
                        ushort h = (ushort)reader.readInt(16);
                        sampleAspectRatio = new sSampleAspectRatio(w, h);
                    }
                }
                else
                {
                    throw new ArgumentException($"Unexpected sample aspect ratio index { index }; it must be < 14, or 0xFF for \"Extended_SAR\"");
                }
            }

            if (reader.readBit())
            {
                // overscan_info_present_flag
                flags |= eVuiFlags.OverscanPresent;
                if (reader.readBit())
                {
                    flags |= eVuiFlags.OverscanAppropriate;
                }
            }

            if (reader.readBit())
            {
                // video_signal_type_present_flag
                flags      |= eVuiFlags.VideoSignal;
                videoFormat = (eVideoFormat)reader.readInt(3);
                if (reader.readBit())
                {
                    flags |= eVuiFlags.VideoSignalFullRange;
                }
                if (reader.readBit())                   // colour_description_present_flag
                {
                    flags                  |= eVuiFlags.VideoSignalColorDesc;
                    colorPrimaries          = (eColorPrimaries)reader.readInt(8);
                    transferCharacteristics = (eTransferFunc)reader.readInt(8);
                    matrixCoefficients      = (eMatrixCoefficients)(byte)reader.readInt(8);
                }
            }

            if (reader.readBit())
            {
                // chroma_loc_info_present_flag
                flags |= eVuiFlags.ChromaLocation;
                checked
                {
                    chromaLocationTop    = (byte)reader.unsignedGolomb();
                    chromaLocationBottom = (byte)reader.unsignedGolomb();
                    if (chromaLocationTop > 5 || chromaLocationBottom > 5)
                    {
                        throw new ArgumentException("Invalid chroma location values, must be in [ 0 .. 5 ] interval");
                    }
                }
            }

            if (reader.readBit())
            {
                flags         |= eVuiFlags.Timing;
                numUnitsInTick = reader.readInt(32);                    //
                timeScale      = reader.readInt(32);
                if (reader.readBit())
                {
                    flags |= eVuiFlags.TimingFixedRate;
                }
            }

            if (reader.readBit())
            {
                flags |= eVuiFlags.NalHrd;
                hrd    = new HRD(ref reader);
            }
            if (reader.readBit())
            {
                flags |= eVuiFlags.VclHrd;
                hrd    = new HRD(ref reader);
            }
            if (0 != (flags & (eVuiFlags.NalHrd | eVuiFlags.VclHrd)))
            {
                if (reader.readBit())
                {
                    flags |= eVuiFlags.LowDelay;
                }
            }

            if (reader.readBit())
            {
                flags |= eVuiFlags.PicStruct;
            }
        }
Example #3
0
 public static eYCbCrEncoding?map(this eMatrixCoefficients mc) => s_encoding.lookup(mc);