Example #1
0
        internal void SetImage(Color2[,] imagen)
        {
            this.LockImage();

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    this.SetPixel(x, y, imagen[y, x]);
                }
            }
            this.UnlockImage();
        }
Example #2
0
        public Info ConvertFromRgb(Color2 rgb)
        {
            Info yCbCr;

            // Valores YCbCr
            yCbCr.a = rgb.r * mRgbYcbcr[0, 0] + rgb.g * mRgbYcbcr[0, 1] + rgb.b * mRgbYcbcr[0, 2] - 128;
            yCbCr.b = rgb.r * mRgbYcbcr[1, 0] + rgb.g * mRgbYcbcr[1, 1] + rgb.b * mRgbYcbcr[1, 2];
            yCbCr.c = rgb.r * mRgbYcbcr[2, 0] + rgb.g * mRgbYcbcr[2, 1] + rgb.b * mRgbYcbcr[2, 2];

            //if (ycbcr.a > 255f || ycbcr.b > 255f || ycbcr.c > 255f)
            //    Console.WriteLine("Valor ycbcr desbordado");

            return yCbCr;
        }
Example #3
0
        internal Color2[,] GetImage()
        {
            Color2[,] imagen = new Color2[height, width];

            this.LockImage();
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    imagen[y, x] = this.GetPixel(x, y);
                }
            }
            this.UnlockImage();

            return imagen;
        }
Example #4
0
        internal Info RgbToXyz(Color2 color)
        {
            Info rgb;
            Info xyz;

            // Valores rgb lineales [0, 1]
            //rgb.a = (float)Math.Pow(color.R / 255.0, 2.2);
            //rgb.b = (float)Math.Pow(color.G / 255.0, 2.2);
            //rgb.c = (float)Math.Pow(color.B / 255.0, 2.2);

            rgb.a = lutPow[color.r];
            rgb.b = lutPow[color.g];
            rgb.c = lutPow[color.b];

            // Valores xyz
            xyz.a = rgb.a * msRgbXyz[0, 0] + rgb.b * msRgbXyz[0, 1] + rgb.c * msRgbXyz[0, 2];
            xyz.b = rgb.a * msRgbXyz[1, 0] + rgb.b * msRgbXyz[1, 1] + rgb.c * msRgbXyz[1, 2];
            xyz.c = rgb.a * msRgbXyz[2, 0] + rgb.b * msRgbXyz[2, 1] + rgb.c * msRgbXyz[2, 2];

            return xyz;
        }
Example #5
0
        internal Info RgbToXyz(Color2 color)
        {
            Info rgb;
            Info xyz;

            // Valores rgb lineales [0, 1]
            //rgb.a = (float)Math.Pow(color.R / 255.0, 2.2);
            //rgb.b = (float)Math.Pow(color.G / 255.0, 2.2);
            //rgb.c = (float)Math.Pow(color.B / 255.0, 2.2);

            rgb.a = lutPow[color.r];
            rgb.b = lutPow[color.g];
            rgb.c = lutPow[color.b];

            // Valores xyz
            xyz.a = rgb.a * msRgbXyz[0, 0] + rgb.b * msRgbXyz[0, 1] + rgb.c * msRgbXyz[0, 2];
            xyz.b = rgb.a * msRgbXyz[1, 0] + rgb.b * msRgbXyz[1, 1] + rgb.c * msRgbXyz[1, 2];
            xyz.c = rgb.a * msRgbXyz[2, 0] + rgb.b * msRgbXyz[2, 1] + rgb.c * msRgbXyz[2, 2];

            return(xyz);
        }
Example #6
0
 internal void SetPixel(int x, int y, Color2 color)
 {
     PixelData* data = (PixelData*)(pBase + y * stride + x * sizeof(PixelData));
     data->alpha = color.a;
     data->red = color.r;
     data->green = color.g;
     data->blue = color.b;
 }
Example #7
0
 public Info ConvertFromRgb(Color2 color)
 {
     return new Info() { a = color.r - 128, b = color.g - 128, c = color.b - 128 };
 }
Example #8
0
 public Info ConvertFromRgb(Color2 rgb)
 {
     Info info = RgbToXyz(rgb);
     return XyzToLab(info);
 }
Example #9
0
        public Info ConvertFromRgb(Color2 rgb)
        {
            Info info = RgbToXyz(rgb);

            return(XyzToLab(info));
        }
Example #10
0
        /// <summary>
        /// Converts from their colorspace to RGB and combines all previously decoded channels
        /// </summary>
        /// <param name="imgInfo"></param>
        /// <param name="imgS"></param>
        /// <returns>A 2D array representing the color data from the image</returns>
        internal static Color2[,] MergeChannels(ImgInfo imgInfo, float[][,] imgS)
        {
            Color2[,] img = new Color2[imgInfo.height, imgInfo.width];
            IColorspaceConverter converter;

            if (imgInfo.app14MarkerFound)
            {
                switch (imgInfo.colorMode)
                {
                    case Markers.App14ColorMode.Unknown:
                        if (imgInfo.numOfComponents == 3)
                        {
                            converter = new Rgb();
                        }
                        else
                        {
                            converter = new YCbCr();
                        }
                        break;
                    case Markers.App14ColorMode.YCbCr:
                        converter = new YCbCr();
                        break;
                    case Markers.App14ColorMode.YCCK:
                        converter = new YCbCr();
                        break;
                    default:
                        converter = new Rgb();
                        break;
                }
            }
            else
            {
                converter = new Colorspaces.YCbCr();
            }

            for (int y = 0; y < imgInfo.height; y++)
            {
                for (int x = 0; x < imgInfo.width; x++)
                {
                    Info info;

                    if (imgInfo.numOfComponents == 1) // Y
                    {
                        info.a = imgS[0][y, x];
                        info.b = 0;
                        info.c = 0;
                    }
                    else // YCbCr
                    {
                        info.a = imgS[0][y, x];
                        info.b = imgS[1][y, x];
                        info.c = imgS[2][y, x];
                    }

                    img[y, x] = converter.ConvertToRgb(info);
                }
            }

            return img;
        }