示例#1
0
        /// <summary>
        /// Returns the height and width of the chroma components
        /// </summary>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="ratio">The subsampling ratio.</param>
        /// <returns>The <see cref="Size"/> of the chrominance channel</returns>
        internal static Size CalculateChrominanceSize(
            int width,
            int height,
            YCbCrSubsampleRatio ratio)
        {
            switch (ratio)
            {
            case YCbCrSubsampleRatio.YCbCrSubsampleRatio422:
                return(new Size((width + 1) / 2, height));

            case YCbCrSubsampleRatio.YCbCrSubsampleRatio420:
                return(new Size((width + 1) / 2, (height + 1) / 2));

            case YCbCrSubsampleRatio.YCbCrSubsampleRatio440:
                return(new Size(width, (height + 1) / 2));

            case YCbCrSubsampleRatio.YCbCrSubsampleRatio411:
                return(new Size((width + 3) / 4, height));

            case YCbCrSubsampleRatio.YCbCrSubsampleRatio410:
                return(new Size((width + 3) / 4, (height + 1) / 2));

            default:
                // Default to 4:4:4 subsampling.
                return(new Size(width, height));
            }
        }
示例#2
0
        /// <summary>
        /// gets the size of the cb cr.
        /// </summary>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="ratio">The ratio.</param>
        /// <param name="cw">The cw.</param>
        /// <param name="ch">The ch.</param>
        private static void yCbCrSize(int width, int height, YCbCrSubsampleRatio ratio, out int cw, out int ch)
        {
            switch (ratio)
            {
            case YCbCrSubsampleRatio.YCbCrSubsampleRatio422:
                cw = (width + 1) / 2;
                ch = height;
                break;

            case YCbCrSubsampleRatio.YCbCrSubsampleRatio420:
                cw = (width + 1) / 2;
                ch = (height + 1) / 2;
                break;

            case YCbCrSubsampleRatio.YCbCrSubsampleRatio440:
                cw = width;
                ch = (height + 1) / 2;
                break;

            case YCbCrSubsampleRatio.YCbCrSubsampleRatio411:
                cw = (width + 3) / 4;
                ch = height;
                break;

            case YCbCrSubsampleRatio.YCbCrSubsampleRatio410:
                cw = (width + 3) / 4;
                ch = (height + 1) / 2;
                break;

            default:
                cw = width;
                ch = height;
                break;
            }
        }
示例#3
0
 public static @string String(this YCbCrSubsampleRatio s)
 {
     if (s == YCbCrSubsampleRatio444)
     {
         return("YCbCrSubsampleRatio444");
     }
     else if (s == YCbCrSubsampleRatio422)
     {
         return("YCbCrSubsampleRatio422");
     }
     else if (s == YCbCrSubsampleRatio420)
     {
         return("YCbCrSubsampleRatio420");
     }
     else if (s == YCbCrSubsampleRatio440)
     {
         return("YCbCrSubsampleRatio440");
     }
     else if (s == YCbCrSubsampleRatio411)
     {
         return("YCbCrSubsampleRatio411");
     }
     else if (s == YCbCrSubsampleRatio410)
     {
         return("YCbCrSubsampleRatio410");
     }
     return("YCbCrSubsampleRatioUnknown");
 }
示例#4
0
#pragma warning restore SA1401

        /// <summary>
        /// Initializes a new instance of the <see cref="YCbCrImage" /> class.
        /// </summary>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="ratio">The ratio.</param>
        public YCbCrImage(int width, int height, YCbCrSubsampleRatio ratio)
        {
            Size cSize = CalculateChrominanceSize(width, height, ratio);

            this.Ratio   = ratio;
            this.YStride = width;
            this.CStride = cSize.Width;

            this.YChannel  = JpegPixelArea.CreatePooled(width, height);
            this.CbChannel = JpegPixelArea.CreatePooled(cSize.Width, cSize.Height);
            this.CrChannel = JpegPixelArea.CreatePooled(cSize.Width, cSize.Height);
        }
示例#5
0
#pragma warning restore SA1401

        /// <summary>
        /// Initializes a new instance of the <see cref="YCbCrImage" /> class.
        /// </summary>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="ratio">The ratio.</param>
        public YCbCrImage(int width, int height, YCbCrSubsampleRatio ratio)
        {
            Size cSize = CalculateChrominanceSize(width, height, ratio);

            this.Ratio   = ratio;
            this.YStride = width;
            this.CStride = cSize.Width;

            this.YChannel = Buffer2D <byte> .CreateClean(width, height);

            this.CbChannel = Buffer2D <byte> .CreateClean(cSize.Width, cSize.Height);

            this.CrChannel = Buffer2D <byte> .CreateClean(cSize.Width, cSize.Height);
        }
示例#6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="YcbcrImg"/> class.
        /// </summary>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="ratio">The ratio.</param>
        public YcbcrImg(int width, int height, YCbCrSubsampleRatio ratio)
        {
            int cw, ch;

            yCbCrSize(width, height, ratio, out cw, out ch);
            YPixels  = new byte[width * height];
            CBPixels = new byte[cw * ch];
            CRPixels = new byte[cw * ch];
            Ratio    = ratio;
            YStride  = width;
            CStride  = cw;
            X        = 0;
            Y        = 0;
            Width    = width;
            Height   = height;
        }
示例#7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="YCbCrImage"/> class.
        /// </summary>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="ratio">The ratio.</param>
        public YCbCrImage(int width, int height, YCbCrSubsampleRatio ratio)
        {
            int cw, ch;

            YCbCrSize(width, height, ratio, out cw, out ch);
            this.YChannel  = new byte[width * height];
            this.CbChannel = new byte[cw * ch];
            this.CrChannel = new byte[cw * ch];
            this.Ratio     = ratio;
            this.YStride   = width;
            this.CStride   = cw;
            this.X         = 0;
            this.Y         = 0;
            this.Width     = width;
            this.Height    = height;
        }
示例#8
0
        /// <summary>
        /// Returns the height and width of the chroma components
        /// </summary>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="ratio">The subsampling ratio.</param>
        /// <param name="chromaWidth">The chroma width.</param>
        /// <param name="chromaHeight">The chroma height.</param>
        private static void YCbCrSize(int width, int height, YCbCrSubsampleRatio ratio, out int chromaWidth, out int chromaHeight)
        {
            switch (ratio)
            {
            case YCbCrSubsampleRatio.YCbCrSubsampleRatio422:
                chromaWidth  = (width + 1) / 2;
                chromaHeight = height;
                break;

            case YCbCrSubsampleRatio.YCbCrSubsampleRatio420:
                chromaWidth  = (width + 1) / 2;
                chromaHeight = (height + 1) / 2;
                break;

            case YCbCrSubsampleRatio.YCbCrSubsampleRatio440:
                chromaWidth  = width;
                chromaHeight = (height + 1) / 2;
                break;

            case YCbCrSubsampleRatio.YCbCrSubsampleRatio411:
                chromaWidth  = (width + 3) / 4;
                chromaHeight = height;
                break;

            case YCbCrSubsampleRatio.YCbCrSubsampleRatio410:
                chromaWidth  = (width + 3) / 4;
                chromaHeight = (height + 1) / 2;
                break;

            default:

                // Default to 4:4:4 subsampling.
                chromaWidth  = width;
                chromaHeight = height;
                break;
            }
        }
示例#9
0
            private static void yCbCrSize(int w, int h, YCbCrSubsampleRatio ratio, out int cw, out int ch)
            {
                switch (ratio){
                    case YCbCrSubsampleRatio.YCbCrSubsampleRatio422:
                        cw = (w + 1)/2;
                        ch = h;
                        break;
                    case YCbCrSubsampleRatio.YCbCrSubsampleRatio420:
                        cw = (w + 1)/2;
                        ch = (h + 1)/2;
                        break;
                    case YCbCrSubsampleRatio.YCbCrSubsampleRatio440:
                        cw = w;
                        ch = (h + 1)/2;
                        break;
                    case YCbCrSubsampleRatio.YCbCrSubsampleRatio411:
                        cw = (w + 3)/4;
                        ch = h;
                        break;
                    case YCbCrSubsampleRatio.YCbCrSubsampleRatio410:
                        cw = (w + 3)/4;
                        ch = (h + 1)/2;
                        break;
                    default:

                        // Default to 4:4:4 subsampling.
                        cw = w;
                        ch = h;
                        break;
                }
            }
示例#10
0
 public YCbCrImage(int w, int h, YCbCrSubsampleRatio ratio)
 {
     int cw, ch;
     yCbCrSize(w, h, ratio, out cw, out ch);
     pix_y = new byte[w*h];
     pix_cb = new byte[cw*ch];
     pix_cr = new byte[cw*ch];
     this.ratio = ratio;
     y_stride = w;
     c_stride = cw;
     x = 0;
     y = 0;
     this.w = w;
     this.h = h;
 }
示例#11
0
 public YCbCr(slice <byte> Y = default, slice <byte> Cb = default, slice <byte> Cr = default, long YStride = default, long CStride = default, YCbCrSubsampleRatio SubsampleRatio = default, Rectangle Rect = default)
 {
     this.Y              = Y;
     this.Cb             = Cb;
     this.Cr             = Cr;
     this.YStride        = YStride;
     this.CStride        = CStride;
     this.SubsampleRatio = SubsampleRatio;
     this.Rect           = Rect;
 }