Пример #1
0
        public static Color YcbcrToRgb(YCbCr ycbcr)
        {
            double Y = ycbcr.Y, Cb = ycbcr.Cb, Cr = ycbcr.Cr;

            byte r = (byte)Math.Max(0, Math.Min(255, (Y + 1.402 * (Cr - 128))));
            byte g = (byte)Math.Max(0, Math.Min(255, (Y - 0.344136 * (Cb - 128) - 0.714136 * (Cr - 128))));
            byte b = (byte)Math.Max(0, Math.Min(255, (Y + 1.772 * (Cb - 128))));

            return(Color.FromArgb(r, g, b));
        }
Пример #2
0
        public static YCbCr[,] ReadYCbCrs(Bitmap image)
        {
            int w = image.Width, h = image.Height;

            // convert rgb array to ycbcr
            var ycbcrs = new YCbCr[h, w];

            for (int row = 0; row < h; ++row)
            {
                for (int col = 0; col < w; ++col)
                {
                    ycbcrs[row, col] = ColorChannel.RgbToYcbcr(image.GetPixel(col, row));
                }
            }
            return(ycbcrs);
        }
Пример #3
0
        // duplicate cb cr channels to reproduce ycbcr pixels
        public static YCbCr[,] UpSample(YCbCrSubSample chans)
        {
            int h = chans.Y.GetLength(0), w = chans.Y.GetLength(1);

            YCbCr[,] yCbCrs = new YCbCr[h, w];

            for (int row = 0; row < h; ++row)
            {
                for (int col = 0; col < w; ++col)
                {
                    yCbCrs[row, col].Y = chans.Y[row, col];
                    // fill up the square with top left number
                    int subR = row >> 1, subC = col >> 1;
                    yCbCrs[row, col].Cb = chans.Cb[subR, subC];
                    yCbCrs[row, col].Cr = chans.Cr[subR, subC];
                }
            }
            return(yCbCrs);
        }