Exemplo n.º 1
0
    public YCBCRNode[,] ConvertRGBToYCbCr(RGBChannels channels)
    {
        YCBCRNode[,] yCbCrValues = new YCBCRNode[channels.R.GetLength(1), channels.R.GetLength(0)];

        for (int x = 0; x < channels.R.GetLength(0); x++)
        {
            for (int y = 0; y < channels.R.GetLength(1); y++)
            {
                double fY  = Math.Round((0.0 + (0.299 * channels.R[y, x]) + (0.587 * channels.G[y, x]) + (0.114 * channels.B[y, x])), 0);
                double fCB = Math.Round((128 + (-0.1768736 * channels.R[y, x]) + (-0.331264 * channels.G[y, x]) + (0.5 * channels.B[y, x])), 0);
                double fCR = Math.Round((128 + (0.5 * channels.R[y, x]) + (-0.418688 * channels.G[y, x]) + (-0.081312 * channels.B[y, x])), 0);

                yCbCrValues[y, x] = new YCBCRNode(fY, fCB, fCR);
            }
        }
        return(yCbCrValues);
    }
Exemplo n.º 2
0
    public RGBChannels ConvertYCbCrToRGB(YCBCRNode[,] values)
    {
        RGBChannels channels = new RGBChannels(values.GetLength(0), values.GetLength(1));

        for (int x = 0; x < channels.Width; x++)
        {
            for (int y = 0; y < channels.Height; y++)
            {
                YCBCRNode node = values[y, x];
                double    r, g, b = 0.0;

                r = node.Y + 1.40200 * (node.Cr - 0x80);
                g = node.Y - 0.34414 * (node.Cb - 0x80) - 0.71414 * (node.Cr - 0x80);
                b = node.Y + 1.77200 * (node.Cb - 0x80);


                channels.R[y, x] = Math.Clamp(r, 0, 255);
                channels.G[y, x] = Math.Clamp(g, 0, 255);
                channels.B[y, x] = Math.Clamp(b, 0, 255);
            }
        }
        return(channels);
    }