예제 #1
0
        public YUVToRGBLookup(PixelFormat format, LuminanceScale scale)
        {
            _format = format;
            _scale  = scale;

            var r_2_pix_alloc = 0 * 768;
            var g_2_pix_alloc = 1 * 768;
            var b_2_pix_alloc = 2 * 768;

            if (scale == LuminanceScale.ScaleFull)
            {
                // Set up entries 0-255 in rgb-to-pixel value tables.
                for (int i = 0; i < 256; i++)
                {
                    _rgbToPix[r_2_pix_alloc + i + 256] = ColorHelper.RGBToColor((byte)i, 0, 0);
                    _rgbToPix[g_2_pix_alloc + i + 256] = ColorHelper.RGBToColor(0, (byte)i, 0);
                    _rgbToPix[b_2_pix_alloc + i + 256] = ColorHelper.RGBToColor(0, 0, (byte)i);
                }

                // Spread out the values we have to the rest of the array so that we do
                // not need to check for overflow.
                for (int i = 0; i < 256; i++)
                {
                    _rgbToPix[r_2_pix_alloc + i]       = _rgbToPix[r_2_pix_alloc + 256];
                    _rgbToPix[r_2_pix_alloc + i + 512] = _rgbToPix[r_2_pix_alloc + 511];
                    _rgbToPix[g_2_pix_alloc + i]       = _rgbToPix[g_2_pix_alloc + 256];
                    _rgbToPix[g_2_pix_alloc + i + 512] = _rgbToPix[g_2_pix_alloc + 511];
                    _rgbToPix[b_2_pix_alloc + i]       = _rgbToPix[b_2_pix_alloc + 256];
                    _rgbToPix[b_2_pix_alloc + i + 512] = _rgbToPix[b_2_pix_alloc + 511];
                }
            }
            else
            {
                // Set up entries 16-235 in rgb-to-pixel value tables
                for (int i = 16; i < 236; i++)
                {
                    byte scaledValue = (byte)((i - 16) * 255 / 219);
                    _rgbToPix[r_2_pix_alloc + i + 256] = ColorHelper.RGBToColor(scaledValue, 0, 0);
                    _rgbToPix[g_2_pix_alloc + i + 256] = ColorHelper.RGBToColor(0, scaledValue, 0);
                    _rgbToPix[b_2_pix_alloc + i + 256] = ColorHelper.RGBToColor(0, 0, scaledValue);
                }

                // Spread out the values we have to the rest of the array so that we do
                // not need to check for overflow. We have to do it here in two steps.
                for (int i = 0; i < 256 + 16; i++)
                {
                    _rgbToPix[r_2_pix_alloc + i] = _rgbToPix[r_2_pix_alloc + 256 + 16];
                    _rgbToPix[g_2_pix_alloc + i] = _rgbToPix[g_2_pix_alloc + 256 + 16];
                    _rgbToPix[b_2_pix_alloc + i] = _rgbToPix[b_2_pix_alloc + 256 + 16];
                }

                for (int i = 256 + 236; i < 768; i++)
                {
                    _rgbToPix[r_2_pix_alloc + i] = _rgbToPix[r_2_pix_alloc + 256 + 236 - 1];
                    _rgbToPix[g_2_pix_alloc + i] = _rgbToPix[g_2_pix_alloc + 256 + 236 - 1];
                    _rgbToPix[b_2_pix_alloc + i] = _rgbToPix[b_2_pix_alloc + 256 + 236 - 1];
                }
            }
        }
예제 #2
0
        public YUVToRGBLookup(PixelFormat format, LuminanceScale scale)
        {
            _format = format;
            _scale = scale;

            var r_2_pix_alloc = 0 * 768;
            var g_2_pix_alloc = 1 * 768;
            var b_2_pix_alloc = 2 * 768;

            if (scale == LuminanceScale.ScaleFull)
            {
                // Set up entries 0-255 in rgb-to-pixel value tables.
                for (int i = 0; i < 256; i++)
                {
                    _rgbToPix[r_2_pix_alloc + i + 256] = ColorHelper.RGBToColor((byte)i, 0, 0);
                    _rgbToPix[g_2_pix_alloc + i + 256] = ColorHelper.RGBToColor(0, (byte)i, 0);
                    _rgbToPix[b_2_pix_alloc + i + 256] = ColorHelper.RGBToColor(0, 0, (byte)i);
                }

                // Spread out the values we have to the rest of the array so that we do
                // not need to check for overflow.
                for (int i = 0; i < 256; i++)
                {
                    _rgbToPix[r_2_pix_alloc + i] = _rgbToPix[r_2_pix_alloc + 256];
                    _rgbToPix[r_2_pix_alloc + i + 512] = _rgbToPix[r_2_pix_alloc + 511];
                    _rgbToPix[g_2_pix_alloc + i] = _rgbToPix[g_2_pix_alloc + 256];
                    _rgbToPix[g_2_pix_alloc + i + 512] = _rgbToPix[g_2_pix_alloc + 511];
                    _rgbToPix[b_2_pix_alloc + i] = _rgbToPix[b_2_pix_alloc + 256];
                    _rgbToPix[b_2_pix_alloc + i + 512] = _rgbToPix[b_2_pix_alloc + 511];
                }
            }
            else {
                // Set up entries 16-235 in rgb-to-pixel value tables
                for (int i = 16; i < 236; i++)
                {
                    byte scaledValue = (byte)((i - 16) * 255 / 219);
                    _rgbToPix[r_2_pix_alloc + i + 256] = ColorHelper.RGBToColor(scaledValue, 0, 0);
                    _rgbToPix[g_2_pix_alloc + i + 256] = ColorHelper.RGBToColor(0, scaledValue, 0);
                    _rgbToPix[b_2_pix_alloc + i + 256] = ColorHelper.RGBToColor(0, 0, scaledValue);
                }

                // Spread out the values we have to the rest of the array so that we do
                // not need to check for overflow. We have to do it here in two steps.
                for (int i = 0; i < 256 + 16; i++)
                {
                    _rgbToPix[r_2_pix_alloc + i] = _rgbToPix[r_2_pix_alloc + 256 + 16];
                    _rgbToPix[g_2_pix_alloc + i] = _rgbToPix[g_2_pix_alloc + 256 + 16];
                    _rgbToPix[b_2_pix_alloc + i] = _rgbToPix[b_2_pix_alloc + 256 + 16];
                }

                for (int i = 256 + 236; i < 768; i++)
                {
                    _rgbToPix[r_2_pix_alloc + i] = _rgbToPix[r_2_pix_alloc + 256 + 236 - 1];
                    _rgbToPix[g_2_pix_alloc + i] = _rgbToPix[g_2_pix_alloc + 256 + 236 - 1];
                    _rgbToPix[b_2_pix_alloc + i] = _rgbToPix[b_2_pix_alloc + 256 + 236 - 1];
                }
            }
        }
예제 #3
0
        private static YUVToRGBLookup GetLookup(PixelFormat format, LuminanceScale scale)
        {
            if (_lookup != null && _lookup.PixelFormat == format && _lookup.Scale == scale)
            {
                return(_lookup);
            }

            _lookup = new YUVToRGBLookup(format, scale);
            return(_lookup);
        }
예제 #4
0
        public static void Convert420(Surface dst, LuminanceScale scale, byte[] ySrc, byte[] uSrc, byte[] vSrc, int yWidth, int yHeight, int yPitch, int uvPitch)
        {
            // Sanity checks
            Debug.Assert(dst != null && dst.Pixels != null);
            Debug.Assert(dst.BytesPerPixel == 2 || dst.BytesPerPixel == 4);

            Debug.Assert(ySrc != null && uSrc != null && vSrc != null);

            Debug.Assert((yWidth & 1) == 0);
            Debug.Assert((yHeight & 1) == 0);

            var lookup = GetLookup(dst.PixelFormat, scale);

            // Use a templated function to avoid an if check on every pixel
            if (dst.BytesPerPixel == 2)
            {
                ConvertYUV420ToRGB(dst.Pixels, dst.Pitch, lookup, _colorTab.Value, ySrc, uSrc, vSrc, yWidth, yHeight, yPitch, uvPitch, sizeof(ushort));
            }
            else
            {
                ConvertYUV420ToRGB(dst.Pixels, dst.Pitch, lookup, _colorTab.Value, ySrc, uSrc, vSrc, yWidth, yHeight, yPitch, uvPitch, sizeof(uint));
            }
        }
예제 #5
0
        private static YUVToRGBLookup GetLookup(PixelFormat format, LuminanceScale scale)
        {
            if (_lookup != null && _lookup.PixelFormat == format && _lookup.Scale == scale)
                return _lookup;

            _lookup = new YUVToRGBLookup(format, scale);
            return _lookup;
        }
예제 #6
0
        public static void Convert420(Surface dst, LuminanceScale scale, byte[] ySrc, byte[] uSrc, byte[] vSrc, int yWidth, int yHeight, int yPitch, int uvPitch)
        {
            // Sanity checks
            Debug.Assert(dst != null && dst.Pixels != null);
            Debug.Assert(dst.BytesPerPixel == 2 || dst.BytesPerPixel == 4);

            Debug.Assert(ySrc != null && uSrc != null && vSrc != null);

            Debug.Assert((yWidth & 1) == 0);
            Debug.Assert((yHeight & 1) == 0);

            var lookup = GetLookup(dst.PixelFormat, scale);

            // Use a templated function to avoid an if check on every pixel
            if (dst.BytesPerPixel == 2)
                ConvertYUV420ToRGB(dst.Pixels, dst.Pitch, lookup, _colorTab.Value, ySrc, uSrc, vSrc, yWidth, yHeight, yPitch, uvPitch, sizeof(ushort));
            else
                ConvertYUV420ToRGB(dst.Pixels, dst.Pitch, lookup, _colorTab.Value, ySrc, uSrc, vSrc, yWidth, yHeight, yPitch, uvPitch, sizeof(uint));
        }