Exemple #1
0
        public static StandardRgbBitmap ToStandardRgbBitmap(this BitmapSource bitmap)
        {
            BitmapSource convertedSource = bitmap;

            if (bitmap.Format != PixelFormats.Bgra32)
            {
                convertedSource = new FormatConvertedBitmap(bitmap, PixelFormats.Bgra32, null, 1.0);
            }

            int stride = convertedSource.PixelWidth * sizeof(int);

            byte[] rawPixels = new byte[stride * convertedSource.PixelHeight];
            convertedSource.CopyPixels(rawPixels, stride, offset: 0);

            StandardRgbColor[] pixels = new StandardRgbColor[convertedSource.PixelWidth * convertedSource.PixelHeight];

            for (int i = 0; i < rawPixels.Length; i += 4)
            {
                int target = i / 4;
                pixels[target].B = rawPixels[i];
                pixels[target].G = rawPixels[i + 1];
                pixels[target].R = rawPixels[i + 2];
            }

            return(new StandardRgbBitmap(pixels, bitmap.PixelWidth, bitmap.PixelHeight, bitmap.DpiX, bitmap.DpiY));
        }
Exemple #2
0
 public Task <StandardRgbColor[]> RenderAsync()
 {
     return(Task.Run(() =>
     {
         StandardRgbColor[] bitmap = new StandardRgbColor[pixelClusters.Length];
         Parallel.For(0, pixelClusters.Length, i =>
         {
             bitmap[i] = colorSpace.ConvertToStandardRgb(clusterMeans[pixelClusters[i]]);
         });
         return bitmap;
     }));
 }
Exemple #3
0
 public static bool TryParse(string raw, out StandardRgbColor color)
 {
     if (ColorConverter.ConvertFromString(raw) is Color c)
     {
         color.R = c.R;
         color.G = c.G;
         color.B = c.B;
         return(true);
     }
     else
     {
         color = default(StandardRgbColor);
         return(false);
     }
 }
Exemple #4
0
        public static LinearRgbColor ToLinearRgb(this StandardRgbColor source)
        {
            float sR = source.R / 255.0f;
            float sG = source.G / 255.0f;
            float sB = source.B / 255.0f;

            return(new LinearRgbColor
            {
                R = convertGammaToLinear(sR),
                G = convertGammaToLinear(sG),
                B = convertGammaToLinear(sB)
            });

            float convertGammaToLinear(float u)
            {
                return(u <= 0.04045f ? u / 12.92f : (float)Math.Pow((u + 0.055) / 1.055, 2.4));
            }
        }
Exemple #5
0
 public Vector3 ConvertFromStandardRgb(StandardRgbColor pixel)
 {
     return((Vector3)pixel.ToCieLuv());
 }
Exemple #6
0
 public static Color ToWindowsColor(this StandardRgbColor pixel)
 {
     return(Color.FromRgb(pixel.R, pixel.G, pixel.B));
 }
Exemple #7
0
 public static CieLuvColor ToCieLuv(this StandardRgbColor source)
 {
     return(source.ToLinearRgb().ToCieLuv());
 }
Exemple #8
0
 public WeightedColor(int pixelCount, StandardRgbColor color)
 {
     PixelCount = pixelCount;
     Color      = color;
 }