示例#1
0
文件: Program.cs 项目: EFanZh/EFanZh
        private static void GenerateColorRing(Bitmap bitmap, double bigY)
        {
            double centerX = (bitmap.Width - 1) / 2.0;
            double centerY = (bitmap.Height - 1) / 2.0;

            for (int y = 0; y < bitmap.Height; y++)
            {
                for (int x = 0; x < bitmap.Width; x++)
                {
                    double dx = x - centerX;
                    double dy = y - centerY;
                    double dxp = dx / (bitmap.Width / 2.0);
                    double dyp = dy / (bitmap.Height / 2.0);
                    double dp = Math.Sqrt(dxp * dxp + dyp * dyp);
                    double angle = (Math.Atan2(dy, dx) / Math.PI + 1.0) * 3.0;
                    ColorVector color = new ColorVector();

                    if (angle < 1.0) // Red To Yellow.
                    {
                        color.Component1 = 1.0;
                        color.Component2 = angle;
                    }
                    else if (angle < 2.0) // Yellow To Green.
                    {
                        color.Component1 = 2.0 - angle;
                        color.Component2 = 1.0;
                    }
                    else if (angle < 3.0) // Green To Cyan.
                    {
                        color.Component2 = 1.0;
                        color.Component3 = angle - 2.0;
                    }
                    else if (angle < 4.0)//Cyan To Blue.
                    {
                        color.Component2 = 4.0 - angle;
                        color.Component3 = 1.0;
                    }
                    else if (angle < 5.0) // Blue To Purple.
                    {
                        color.Component1 = angle - 4.0;
                        color.Component3 = 1.0;
                    }
                    else // Purple To Red.
                    {
                        color.Component1 = 1.0;
                        color.Component3 = 6.0 - angle;
                    }

                    color.Component1 = 1.0 + (color.Component1 - 1.0) * dp;
                    color.Component2 = 1.0 + (color.Component2 - 1.0) * dp;
                    color.Component3 = 1.0 + (color.Component3 - 1.0) * dp;

                    color.ConvertLinearSRgbToSRgb();

                    bitmap.SetPixel(x, y, color.ToColor());
                }
            }
        }
示例#2
0
文件: Program.cs 项目: EFanZh/EFanZh
        private static void GenerateXyyColors(Bitmap bitmap, double bigY)
        {
            double width = bitmap.Width - 1;
            double height = bitmap.Width - 1;

            for (int y = 0; y < bitmap.Height; y++)
            {
                for (int x = 0; x <= y; x++)
                {
                    double cx = (x + 0.5) / width;
                    double cy = 1.0 - (y + 0.5) / height;

                    ColorVector colorVector = new ColorVector()
                    {
                        Component1 = cx,
                        Component2 = cy,
                        Component3 = bigY
                    };

                    colorVector.ConvertXyyToLinearSRgb();

                    if (colorVector.IsCanonical())
                    {
                        colorVector.ConvertLinearSRgbToSRgb();

                        bitmap.SetPixel(x, y, colorVector.ToColor());
                    }
                }
            }
        }
示例#3
0
文件: Program.cs 项目: EFanZh/EFanZh
        private static void GenerateXyYPlane(Bitmap bitmap, double bigY)
        {
            for (int y = 0; y < bitmap.Height; y++)
            {
                for (int x = 0; x < bitmap.Width; x++)
                {
                    double cx = (x + 0.5) / bitmap.Width;
                    double cy = (y + 0.5) / bitmap.Height;
                    ColorVector colorVector = new ColorVector(cx, cy, bigY);

                    colorVector.ConvertXyyToLinearSRgb();
                    colorVector.CompressLuminance();
                    colorVector.ConvertLinearSRgbToSRgb();

                    bitmap.SetPixel(x, bitmap.Height - 1 - y, colorVector.ToColor());
                }
                Console.WriteLine(y);
            }
        }
示例#4
0
文件: Program.cs 项目: EFanZh/EFanZh
        private static Tuple<Color, double, double>[] GenerateColors()
        {
            var result = new Tuple<Color, double, double>[256 * 256 * 256];
            int i = 0;

            for (short r = 0; r < 256; ++r)
            {
                for (short g = 0; g < 256; ++g)
                {
                    for (short b = 0; b < 256; ++b)
                    {
                        ColorVector colorVector = new ColorVector(r / 255.0, g / 255.0, b / 255.0);

                        colorVector.ConvertSRgbToLinearSRgb();
                        colorVector.ConvertLinearSRgbToXyz();
                        colorVector.ConvertXyzToXyy();
                        double hue = Math.Atan2(colorVector.Component2 - D65.SmallY, colorVector.Component1 - D65.SmallX);

                        result[i] = new Tuple<Color, double, double>(Color.FromArgb(r, g, b), colorVector.Component3, hue);

                        if (i % 1000000 == 0)
                        {
                            Console.WriteLine(i);
                        }

                        i++;
                    }
                }
            }

            return result;
        }
示例#5
0
文件: Program.cs 项目: EFanZh/EFanZh
        private static Tuple<double, double, double> XyYToSRgb(double x, double y, double bigY)
        {
            ColorVector color = new ColorVector(x, y, bigY);

            color.ConvertXyyToSRgbSmart();

            return Tuple.Create(color.Component1, color.Component2, color.Component3);
        }