コード例 #1
0
        protected unsafe void Apply(int *input, int *output, int width, int height, Int32Rect area, int hue,
                                    float saturation, float lightness)
        {
            int startX = area.X;
            int startY = area.Y;
            int endX   = area.X + area.Width;
            int endY   = area.Y + area.Height;

            lightness  = lightness / 100.0F;
            saturation = saturation / 100.0F;

            Parallel.For(0, height, (y) =>
            {
                for (int x = 0; x < width; ++x)
                {
                    if (x >= startX && x < endX && y >= startY && y < endY)
                    {
                        int argb = input[y * width + x];

                        byte r = (byte)(argb >> 16);
                        byte g = (byte)(argb >> 8);
                        byte b = (byte)(argb);

                        int h;
                        float s;
                        float l;

                        ColorEx.ToHSL(r, g, b, out h, out s, out l);

                        h = (h + hue) % 360;
                        s = (s + saturation).Clamp(0.0F, 1.0F);
                        l = (l + lightness).Clamp(0.0F, 1.0F);

                        ColorEx.ToRgb(h, s, l, out r, out g, out b);

                        output[y * width + x] = (argb & -0x1000000) | (r << 16) | (g << 8) | (b);
                    }
                    else
                    {
                        output[y * width + x] = input[y * width + x];
                    }
                }
            });
        }