BitMiracle.LibJpeg.Classic.Internal.jpeg_color_converter.rgb_ycc_convert C# (CSharp) Méthode

rgb_ycc_convert() private méthode

RGB -> YCbCr conversion: most common case YCbCr is defined per CCIR 601-1, except that Cb and Cr are normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5. The conversion equations to be implemented are therefore Y = 0.29900 * R + 0.58700 * G + 0.11400 * B Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.) To avoid floating-point arithmetic, we represent the fractional constants as integers scaled up by 2^16 (about 4 digits precision); we have to divide the products by 2^16, with appropriate rounding, to get the correct answer. For even more speed, we avoid doing any multiplications in the inner loop by precalculating the constants times R,G,B for all possible values. For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table); for 12-bit samples it is still acceptable. It's not very reasonable for 16-bit samples, but if you want lossless storage you shouldn't be changing colorspace anyway. The CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included in the tables to save adding them separately in the inner loop.
private rgb_ycc_convert ( byte input_buf, int input_row, byte output_buf, int output_row, int num_rows ) : void
input_buf byte
input_row int
output_buf byte
output_row int
num_rows int
Résultat void
        private void rgb_ycc_convert(byte[][] input_buf, int input_row, byte[][][] output_buf, int output_row, int num_rows)
        {
            int num_cols = m_cinfo.m_image_width;
            for (int row = 0; row < num_rows; row++)
            {
                int columnOffset = 0;
                for (int col = 0; col < num_cols; col++)
                {
                    int r = input_buf[input_row + row][columnOffset + JpegConstants.RGB_RED];
                    int g = input_buf[input_row + row][columnOffset + JpegConstants.RGB_GREEN];
                    int b = input_buf[input_row + row][columnOffset + JpegConstants.RGB_BLUE];
                    columnOffset += JpegConstants.RGB_PIXELSIZE;

                    /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
                     * must be too; we do not need an explicit range-limiting operation.
                     * Hence the value being shifted is never negative, and we don't
                     * need the general RIGHT_SHIFT macro.
                     */
                    /* Y */
                    output_buf[0][output_row][col] = (byte)((m_rgb_ycc_tab[r + R_Y_OFF] + m_rgb_ycc_tab[g + G_Y_OFF] + m_rgb_ycc_tab[b + B_Y_OFF]) >> SCALEBITS);
                    /* Cb */
                    output_buf[1][output_row][col] = (byte)((m_rgb_ycc_tab[r + R_CB_OFF] + m_rgb_ycc_tab[g + G_CB_OFF] + m_rgb_ycc_tab[b + B_CB_OFF]) >> SCALEBITS);
                    /* Cr */
                    output_buf[2][output_row][col] = (byte)((m_rgb_ycc_tab[r + R_CR_OFF] + m_rgb_ycc_tab[g + G_CR_OFF] + m_rgb_ycc_tab[b + B_CR_OFF]) >> SCALEBITS);
                }

                output_row++;
            }
        }