Example #1
0
 private void button2_Click(object sender, EventArgs e)
 {
     openFileDialog1.ShowDialog();
     if (openFileDialog1.FileName == "") return;
     BitmapW a = new BitmapW(openFileDialog1.FileName);
     pictureBox1.Image = a.GetBitmap();
 }
Example #2
0
        /// <summary>
        /// #### Vignette
        /// (red,green,blue) of the vignette effect to apply
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public BitmapW vignette(BitmapW image, int r, int g, int b)
        {
            float cr = 0, cg = 0, cb = 0, ca;
            int   i = 0, j = 0,
                  h       = image.Height(),
                  w       = image.Width(),
                  centerw = w / 2,
                  centerh = h / 2,
                  maxdist = dist(0, 0, centerw, centerh);


            maxdist = (int)(maxdist * 0.6f);
            int radius = maxdist / 2;

            for (i = 0; i < w; i++)
            {
                for (j = 0; j < h; j++)
                {
                    Color temp = image.GetPixel(i, j);
                    cr = temp.R; cg = temp.G; cb = temp.B; ca = temp.A;
                    int distance = dist(i, j, centerw, centerh);
                    distance = (distance > radius)?distance - radius:0;

                    float ratio = ((distance / (float)(maxdist)));
                    cr = (1 - ratio) * cr + (ratio * r);
                    cg = (1 - ratio) * cg + (ratio * g);
                    cb = (1 - ratio) * cb + (ratio * b);

                    image.SetPixel(i, j, Color.FromArgb((int)Util.clamp(ca, 0, 255), (int)Util.clamp(cr, 0, 255),
                                                        (int)Util.clamp(cg, 0, 255), (int)Util.clamp(cb, 0, 255)));
                }
            }
            return(image);
        }
Example #3
0
        /// <summary>
        /// #### Constrast [-100, 100]
        /// </summary>
        /// <param name="f"></param>
        /// <param name="c"></param>
        /// <returns></returns>
        public BitmapW contrast(BitmapW image, float p)
        {
            p = Util.normalize(p, 0, 2, -100, 100);

            float cr = 0, cg = 0, cb = 0, ca;
            int   i = 0, j = 0,
                  h = image.Height(),
                  w = image.Width();

            for (i = 0; i < w; i++)
            {
                for (j = 0; j < h; j++)
                {
                    Color temp = image.GetPixel(i, j);
                    cr = temp.R; cg = temp.G; cb = temp.B; ca = temp.A;

                    cr = 255 * contrastc(cr / 255, p);
                    cg = 255 * contrastc(cg / 255, p);
                    cb = 255 * contrastc(cb / 255, p);

                    image.SetPixel(i, j, Color.FromArgb((int)Util.clamp(ca, 0, 255), (int)Util.clamp(cr, 0, 255),
                                                        (int)Util.clamp(cg, 0, 255), (int)Util.clamp(cb, 0, 255)));
                }
            }
            return(image);
        }
Example #4
0
        /// <summary>
        /// #### Saturate [-100, 100]
        /// </summary>
        /// <param name="image"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public BitmapW saturate(BitmapW image, float p)
        {
            p = Util.normalize(p, 0, 2, -100, 100);
            float cr = 0, cg = 0, cb = 0, ca;
            int   i = 0, j = 0,
                  h = image.Height(),
                  w = image.Width();

            for (i = 0; i < w; i++)
            {
                for (j = 0; j < h; j++)
                {
                    Color temp = image.GetPixel(i, j);
                    cr = temp.R; cg = temp.G; cb = temp.B; ca = temp.A;
                    float avg = (cr + cg + cb) / 3;

                    cr = avg + p * (cr - avg);
                    cg = avg + p * (cg - avg);
                    cb = avg + p * (cb - avg);

                    image.SetPixel(i, j, Color.FromArgb((int)Util.clamp(ca, 0, 255), (int)Util.clamp(cr, 0, 255),
                                                        (int)Util.clamp(cg, 0, 255), (int)Util.clamp(cb, 0, 255)));
                }
            }
            return(image);
        }
Example #5
0
        /// <summary>
        /// #### Posterize [1, 255]
        /// </summary>
        /// <param name="image"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public BitmapW posterize(BitmapW image, float p)
        {
            p = Util.clamp(p, 1, 255);
            int   step = (int)Math.Floor(255 / p);
            float cr = 0, cg = 0, cb = 0, ca;
            int   i = 0, j = 0,
                  h = image.Height(),
                  w = image.Width();

            for (i = 0; i < w; i++)
            {
                for (j = 0; j < h; j++)
                {
                    Color temp = image.GetPixel(i, j);
                    cr = temp.R; cg = temp.G; cb = temp.B; ca = temp.A;


                    cr = (float)Math.Floor(cr / (float)(step)) * step;
                    cg = (float)Math.Floor(cg / (float)(step)) * step;
                    cb = (float)Math.Floor(cb / (float)(step)) * step;

                    image.SetPixel(i, j, Color.FromArgb((int)Util.clamp(ca, 0, 255), (int)Util.clamp(cr, 0, 255),
                                                        (int)Util.clamp(cg, 0, 255), (int)Util.clamp(cb, 0, 255)));
                }
            }
            return(image);
        }
Example #6
0
        BitmapW curves(BitmapW image, Point s, Point c1, Point c2, Point e)
        {
            Util.Bezier bezier = new Util.Bezier(s, c1, c2, e);
            int[]       points = bezier.genColorTable();

            float cr = 0, cg = 0, cb = 0, ca;
            int   i = 0, j = 0,
                  h = image.Height(),
                  w = image.Width();

            for (i = 0; i < w; i++)
            {
                for (j = 0; j < h; j++)
                {
                    Color temp = image.GetPixel(i, j);
                    cr = temp.R; cg = temp.G; cb = temp.B; ca = temp.A;

                    cr = points[(int)cr];
                    cg = points[(int)cg];
                    cb = points[(int)cb];

                    image.SetPixel(i, j, Color.FromArgb((int)Util.clamp(ca, 0, 255), (int)Util.clamp(cr, 0, 255),
                                                        (int)Util.clamp(cg, 0, 255), (int)Util.clamp(cb, 0, 255)));
                }
            }
            return(image);
        }
Example #7
0
        /// <summary>
        /// #### Noise [0 - 100]
        /// </summary>
        /// <param name="image"></param>
        /// <param name="r"></param>
        /// <param name="g"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public BitmapW noise(BitmapW image, int p)
        {
            int    adjust   = (int)(p * 2.55f);
            Random rand     = new Random(adjust);
            int    temprand = 0;

            float cr = 0, cg = 0, cb = 0, ca;
            int   i = 0, j = 0,
                  h = image.Height(),
                  w = image.Width();

            for (i = 0; i < w; i++)
            {
                for (j = 0; j < h; j++)
                {
                    Color temp = image.GetPixel(i, j);
                    cr = temp.R; cg = temp.G; cb = temp.B; ca = temp.A;

                    temprand = rand.Next(adjust * -1, adjust);

                    cr += temprand;
                    cg += temprand;
                    cb += temprand;

                    image.SetPixel(i, j, Color.FromArgb((int)Util.clamp(ca, 0, 255), (int)Util.clamp(cr, 0, 255),
                                                        (int)Util.clamp(cg, 0, 255), (int)Util.clamp(cb, 0, 255)));
                }
            }
            return(image);
        }
Example #8
0
        /// <summary>
        /// #### Adjust [-255,255 for each channel]
        /// </summary>
        /// <param name="image"></param>
        /// <param name="pr"></param>
        /// <param name="pg"></param>
        /// <param name="pb"></param>
        /// <returns></returns>
        public BitmapW adjust(BitmapW image, float pr, float pg, float pb)
        {
            float cr = 0, cg = 0, cb = 0;
            pr /= 100; pg /= 100; pb /= 100;
            int i = 0, j = 0,
            h = image.Height(),
            w = image.Width();

            for (i = 0; i < w; i++)
            {
                for (j = 0; j < h; j++)
                {
                    Color temp = image.GetPixel(i, j);
                    cr = temp.R; cg = temp.G; cb = temp.B;

                    if (pr > 0) cr += (255 - cr) * pr; else cr -= cr * Math.Abs(pr);
                    if (pg > 0) cg += (255 - cg) * pg; else cg -= cg * Math.Abs(pg);
                    if (pb > 0) cb += (255 - cb) * pb; else cb -= cb * Math.Abs(pb);
                    /*
                    cr *= (1.0f + pr);
                    cg *= (1.0f + pg);
                    cb *= (1.0f + pb);
                    */

                    image.SetPixel(i, j, Color.FromArgb((int)Util.clamp(cr, 0, 255), (int)Util.clamp(cg, 0, 255), (int)Util.clamp(cb, 0, 255)));
                }
            }
            return image;
        }
Example #9
0
        private void button6_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.FileName == "")
            {
                MessageBox.Show("Select an image first"); return;
            }


            BitmapW a = new BitmapW(openFileDialog1.FileName);

            pictureBox1.Image = a.GetBitmap(); //show the original image

            //apply effects

            BitmapW layer1 = a.Clone(); //working layer 1
            BitmapW res    = a.Clone(); //this will hold the final result

            //do some adjustments
            res = effects.brighten(res, 10);
            res = effects.contrast(res, 30);

            //add a sepia softlight to the image
            layer1 = res.Clone();
            layer1 = effects.sepia(layer1);
            layer1 = effects.vignette(layer1, 0, 0, 0);      //some vignette too
            res    = layers.merge("softLight", res, layer1); //add this layer to our image as softlight



            //desaturate a little
            res = effects.saturate(res, -30);

            //tadaaa
            pictureBox2.Image = res.GetBitmap(); //show the resulting image
        }
Example #10
0
        private void button5_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.FileName == "")
            {
                MessageBox.Show("Select an image first"); return;
            }


            BitmapW a = new BitmapW(openFileDialog1.FileName);

            pictureBox1.Image = a.GetBitmap(); //show the original image

            //apply effects

            BitmapW res = a.Clone(); //this will hold the final result

            //do some adjustments
            res = effects.brighten(res, 20);
            res = effects.saturate(res, -90);

            //add a purplish color
            BitmapW purple = a.Clone();

            purple = effects.fill(purple, 34, 43, 109);
            res    = layers.merge("softLight", res, purple);

            //do some more adjustments
            res = effects.gamma(res, -5);
            res = effects.contrast(res, 50);


            pictureBox2.Image = res.GetBitmap(); //show the resulting image
        }
Example #11
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.FileName == "")
            {
                MessageBox.Show("Select an image first");  return;
            }



            BitmapW a = new BitmapW(openFileDialog1.FileName);

            pictureBox1.Image = a.GetBitmap();

            BitmapW layer1 = a.Clone(), layer2 = a.Clone(), layer3 = a.Clone(); //make three copies of the image l1,l2,l3
            BitmapW res = a.Clone();                                            //this will hold the final result

            layer3 = effects.fill(layer3, 167, 118, 12);                        //layer 3 is a solid fill of this rgb color

            layer2 = effects.blur(layer2, "gaussian");                          //layer2 is a blurred version of original image
            layer1 = effects.saturate(layer1, -50);                             //layer1 is a saturated version


            res = layers.merge("overlay", res, layer1);   //merge layer1 onto original with "overlay" layer blending
            res = layers.merge("softLight", res, layer2); //now merge layer2 onto this, with "softlight" layer blending
            res = layers.merge("softLight", res, layer3); //now merge layer3 onto this, with "softlight" layer blending
            res = effects.saturate(res, -40);             //apply -40 saturate effect on this now
            res = effects.contrast(res, 10);              //apply 10 contrast

            pictureBox2.Image = res.GetBitmap();          //show the resulting image
        }
Example #12
0
        private void button7_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.FileName == "")
            {
                MessageBox.Show("Select an image first"); return;
            }


            BitmapW a = new BitmapW(openFileDialog1.FileName);

            pictureBox1.Image = a.GetBitmap(); //show the original image

            //apply effect
            BitmapW res = a.Clone();

            res = effects.saturate(res, -100); //grayscale it
            res = effects.contrast(res, 125);
            res = effects.noise(res, 3);
            res = effects.sepia(res);

            res = effects.adjust(res, 8, 2, 4);


            //tadaaa
            pictureBox2.Image = res.GetBitmap(); //show the resulting image
        }
Example #13
0
        /// <summary>
        /// #### Blur ['simple', 'gaussian']
        /// </summary>
        /// <param name="image"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public BitmapW blur(BitmapW image, string p)
        {
            BitmapW result;

            if (p == "simple")
            {
                result = convolve(image, new float[, ] {
                    { 1.0f / 9, 1.0f / 9, 1.0f / 9 },
                    { 1.0f / 9, 1.0f / 9, 1.0f / 9 },
                    { 1.0f / 9, 1.0f / 9, 1.0f / 9 }
                }, 1, 1
                                  );
            }
            else //gaussian
            {
                result = convolve(image, new float[, ] {
                    { 1.0f / 273, 4.0f / 273, 7.0f / 273, 4.0f / 273, 1.0f / 273 },
                    { 4.0f / 273, 16.0f / 273, 26.0f / 273, 16.0f / 273, 4.0f / 273 },
                    { 7.0f / 273, 26.0f / 273, 41.0f / 273, 26.0f / 273, 7.0f / 273 },
                    { 4.0f / 273, 16.0f / 273, 26.0f / 273, 16.0f / 273, 4.0f / 273 },
                    { 1.0f / 273, 4.0f / 273, 7.0f / 273, 4.0f / 273, 1.0f / 273 }
                }, 2, 2);
            }

            return(result);
        }
Example #14
0
        public BitmapW opacity(int value, BitmapW bottom, BitmapW top) // in Form1.cs for example: "layer3 = layers.opacity(50,layer2, layer1);" *"50" = 50% the value from 0-100
        {
            if (value >= 0 && value <= 100)
            {
                float percentge = (float)value / 100;
                int   i = 0, j = 0,
                      h = Math.Min(bottom.Height(), top.Height()),
                      w = Math.Min(bottom.Width(), top.Width());

                for (i = 0; i < w; i++)
                {
                    for (j = 0; j < h; j++)
                    {
                        Color b = bottom.GetPixel(i, j);
                        Color t = top.GetPixel(i, j);
                        float cr = 0, cg = 0, cb = 0, ca = 0;
                        ca = b.A * (1 - percentge) + t.A * percentge;
                        cr = b.R * (1 - percentge) + t.R * percentge;
                        cg = b.G * (1 - percentge) + t.G * percentge;
                        cb = b.B * (1 - percentge) + t.B * percentge;

                        bottom.SetPixel(i, j, Color.FromArgb((int)Util.clamp(ca, 0, 255), (int)Util.clamp(cr, 0, 255), (int)Util.clamp(cg, 0, 255), (int)Util.clamp(cb, 0, 255)));
                    }
                }
            }
            return(bottom);
        }
Example #15
0
        /// <summary>
        /// #### Expose [-100, 100]
        /// </summary>
        /// <param name="image"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public BitmapW expose(BitmapW image, float p)
        {
            p = Util.normalize(p, -1, 1, -100, 100);
            Point c1 = new Point(0, (int)(255 * p));
            Point c2 = new Point((int)(255 - (255 * p)), 255);

            return(curves(image, new Point(0, 0), c1, c2, new Point(255, 255)));
        }
Example #16
0
        private BitmapW FastGaussianBlur(BitmapW src, int Raduis)
        {
            var     bxs   = boxesForGaussian(Raduis, 3);
            BitmapW img   = FastBoxBlur(src, bxs[0]);
            BitmapW img_2 = FastBoxBlur(img, bxs[1]);
            BitmapW img_3 = FastBoxBlur(img_2, bxs[2]);

            return(img_3);
        }
Example #17
0
        private void button2_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            if (openFileDialog1.FileName == "")
            {
                return;
            }
            BitmapW a = new BitmapW(openFileDialog1.FileName);

            pictureBox1.Image = a.GetBitmap();
        }
Example #18
0
        /// <summary>
        /// #### Adjust [-255,255 for each channel]
        /// </summary>
        /// <param name="image"></param>
        /// <param name="pr"></param>
        /// <param name="pg"></param>
        /// <param name="pb"></param>
        /// <returns></returns>
        public BitmapW adjust(BitmapW image, float pr, float pg, float pb)
        {
            float cr = 0, cg = 0, cb = 0;

            pr /= 100; pg /= 100; pb /= 100;
            int i = 0, j = 0,
                h = image.Height(),
                w = image.Width();

            for (i = 0; i < w; i++)
            {
                for (j = 0; j < h; j++)
                {
                    Color temp = image.GetPixel(i, j);
                    cr = temp.R; cg = temp.G; cb = temp.B;

                    if (pr > 0)
                    {
                        cr += (255 - cr) * pr;
                    }
                    else
                    {
                        cr -= cr * Math.Abs(pr);
                    }
                    if (pg > 0)
                    {
                        cg += (255 - cg) * pg;
                    }
                    else
                    {
                        cg -= cg * Math.Abs(pg);
                    }
                    if (pb > 0)
                    {
                        cb += (255 - cb) * pb;
                    }
                    else
                    {
                        cb -= cb * Math.Abs(pb);
                    }

                    /*
                     * cr *= (1.0f + pr);
                     * cg *= (1.0f + pg);
                     * cb *= (1.0f + pb);
                     */


                    image.SetPixel(i, j, Color.FromArgb((int)Util.clamp(cr, 0, 255), (int)Util.clamp(cg, 0, 255), (int)Util.clamp(cb, 0, 255)));
                }
            }
            return(image);
        }
Example #19
0
        /// <summary>
        /// #### Sharpen
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public BitmapW sharpen(BitmapW image)
        {
            BitmapW result;

            result = convolve(image, new float[, ] {
                { 0.0f, -0.2f, 0.0f },
                { -0.2f, 1.8f, -0.2f },
                { 0.0f, -0.2f, 0.0f }
            }, 1, 1
                              );


            return(result);
        }
Example #20
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.FileName == "")
            { MessageBox.Show("Select an image first"); return; }

            BitmapW a = new BitmapW(openFileDialog1.FileName);
            pictureBox1.Image = a.GetBitmap();

            BitmapW res = a.Clone(); //this will hold the final result

            res = effects.vignette(res, 0, 0, 0);

            pictureBox2.Image = res.GetBitmap(); //show the resulting image
        }
Example #21
0
        BitmapW apply(BitmapW bottom, BitmapW top, string fn)
        {
            int i = 0, j = 0,
            h = Math.Min(bottom.Height(), top.Height()),
            w = Math.Min(bottom.Width(), top.Width());

            for (i = 0; i < w; i++)
            {
                for (j = 0; j < h; j++)
                {
                    // Execute blend on each pixel.
                    bottom.SetPixel(i, j, func(fn, bottom.GetPixel(i, j), top.GetPixel(i, j)));
                }
            }
            return bottom;
        }
Example #22
0
        BitmapW apply(BitmapW bottom, BitmapW top, string fn)
        {
            int i = 0, j = 0,
            h = Math.Min(bottom.Height(), top.Height()),
            w = Math.Min(bottom.Width(), top.Width());

            for (i = 0; i < w; i++)
            {
                for (j = 0; j < h; j++)
                {
                    // Execute blend on each pixel.
                    bottom.SetPixel(i, j, func(fn, bottom.GetPixel(i, j), top.GetPixel(i, j)));
                }
            }
            return bottom;
        }
Example #23
0
        public Blur CustomBlur = new Blur(); //the use in Form1.cs for example: "layer1 = effects.CustomBlur.Gaussain(layer1, 10);"
        BitmapW convolve(BitmapW image, float[,] kernel, int kw, int kh)
        {
            BitmapW temp = image.Clone();

            // int kh = kernel;
            //int kw = kh; //kernel[0].Length / 2;
            int i = 0, j = 0, n = 0, m = 0, cr, cg, cb, ca,
                h = image.Height(),
                w = image.Width();

            for (i = 0; i < h; i++)
            {
                for (j = 0; j < w; j++)
                {
                    //kernel loop
                    float r = 0, g = 0, b = 0, a = 0;
                    for (n = -kh; n <= kh; n++)
                    {
                        for (m = -kw; m <= kw; m++)
                        {
                            if (i + n >= 0 && i + n < h)
                            {
                                if (j + m >= 0 && j + m < w)
                                {
                                    float f = kernel[m + kw, n + kh];
                                    if (f == 0)
                                    {
                                        continue;
                                    }
                                    Color colortemp = image.GetPixel(j + m, i + n);
                                    cr = colortemp.R; cg = colortemp.G; cb = colortemp.B; ca = colortemp.A;

                                    r += cr * f;
                                    g += cg * f;
                                    b += cb * f;
                                    a += ca * f;
                                }
                            }
                        }
                    }
                    //kernel loop end

                    temp.SetPixel(j, i, Color.FromArgb((int)Util.clamp(a, 0, 255), (int)Util.clamp(r, 0, 255), (int)Util.clamp(g, 0, 255), (int)Util.clamp(b, 0, 255)));
                }
            }
            return(temp);
        }
Example #24
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.FileName == "")
            {
                MessageBox.Show("Select an image first"); return;
            }

            BitmapW a = new BitmapW(openFileDialog1.FileName);

            pictureBox1.Image = a.GetBitmap();


            BitmapW res = a.Clone(); //this will hold the final result

            res = effects.vignette(res, 0, 0, 0);

            pictureBox2.Image = res.GetBitmap(); //show the resulting image
        }
Example #25
0
        /// <summary>
        /// #### Alpha [-100, 100]
        /// </summary>
        /// <param name="image"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public BitmapW alpha(BitmapW image, float p)
        {
            p = Util.normalize(p, 0, 255, -100, 100);
            float cr = 0, cg = 0, cb = 0, ca;
            int i = 0, j = 0,
            h = image.Height(),
            w = image.Width();

            for (i = 0; i < w; i++)
            {
                for (j = 0; j < h; j++)
                {
                    Color temp = image.GetPixel(i, j);
                    cr = temp.R; cg = temp.G; cb = temp.B; ca = temp.A;

                    ca = (p);

                    image.SetPixel(i, j, Color.FromArgb((int)Util.clamp(ca, 0, 255), (int)Util.clamp(cr, 0, 255),
                        (int)Util.clamp(cg, 0, 255), (int)Util.clamp(cb, 0, 255)));
                }
            }
            return image;
        }
Example #26
0
        /// <summary>
        /// #### Brighten [-100, 100]
        /// </summary>
        /// <param name="image"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public BitmapW brighten(BitmapW image, float p)
        {
            p = Util.normalize(p, -255, 255, -100, 100);
            float cr = 0, cg = 0, cb = 0;
            int   i = 0, j = 0,
                  h = image.Height(),
                  w = image.Width();

            for (i = 0; i < w; i++)
            {
                for (j = 0; j < h; j++)
                {
                    Color temp = image.GetPixel(i, j);
                    cr = temp.R; cg = temp.G; cb = temp.B;

                    cr += (p);
                    cg += (p);
                    cb += (p);

                    image.SetPixel(i, j, Color.FromArgb((int)Util.clamp(cr, 0, 255), (int)Util.clamp(cg, 0, 255), (int)Util.clamp(cb, 0, 255)));
                }
            }
            return(image);
        }
Example #27
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.FileName == "")
            { MessageBox.Show("Select an image first");  return; }

            BitmapW a = new BitmapW(openFileDialog1.FileName);
            pictureBox1.Image = a.GetBitmap();

            BitmapW layer1 = a.Clone(), layer2 = a.Clone(), layer3 = a.Clone(); //make three copies of the image l1,l2,l3
            BitmapW res = a.Clone(); //this will hold the final result

            layer3 = effects.fill(layer3, 167, 118, 12); //layer 3 is a solid fill of this rgb color

            layer2 = effects.blur(layer2, "gaussian"); //layer2 is a blurred version of original image
            layer1 = effects.saturate(layer1, -50); //layer1 is a saturated version

            res = layers.merge("overlay", res, layer1); //merge layer1 onto original with "overlay" layer blending
            res = layers.merge("softLight", res, layer2); //now merge layer2 onto this, with "softlight" layer blending
            res = layers.merge("softLight", res, layer3); //now merge layer3 onto this, with "softlight" layer blending
            res = effects.saturate(res,-40); //apply -40 saturate effect on this now
            res = effects.contrast(res, 10); //apply 10 contrast

            pictureBox2.Image = res.GetBitmap(); //show the resulting image
        }
Example #28
0
        /// <summary>
        /// #### Fill [No Range]
        /// </summary>
        /// <param name="image"></param>
        /// <param name="r"></param>
        /// <param name="g"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public BitmapW fill(BitmapW image, int r, int g, int b)
        {
            float cr = 0, cg = 0, cb = 0, ca;
            int   i = 0, j = 0,
                  h = image.Height(),
                  w = image.Width();

            for (i = 0; i < w; i++)
            {
                for (j = 0; j < h; j++)
                {
                    Color temp = image.GetPixel(i, j);
                    cr = temp.R; cg = temp.G; cb = temp.B; ca = temp.A;

                    cr = r;
                    cg = g;
                    cb = b;

                    image.SetPixel(i, j, Color.FromArgb((int)Util.clamp(ca, 0, 255), (int)Util.clamp(cr, 0, 255),
                                                        (int)Util.clamp(cg, 0, 255), (int)Util.clamp(cb, 0, 255)));
                }
            }
            return(image);
        }
Example #29
0
        /// <summary>
        /// #### Sepia
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public BitmapW sepia(BitmapW image)
        {
            float cr = 0, cg = 0, cb = 0, ca;
            int   i = 0, j = 0,
                  h = image.Height(),
                  w = image.Width();

            for (i = 0; i < w; i++)
            {
                for (j = 0; j < h; j++)
                {
                    Color temp = image.GetPixel(i, j);
                    cr = temp.R; cg = temp.G; cb = temp.B; ca = temp.A;
                    float tcr = cr, tcg = cg, tcb = cb;
                    cr = (tcr * 0.393f) + (tcg * 0.769f) + (tcb * 0.189f);
                    cg = (tcr * 0.349f) + (tcg * 0.686f) + (tcb * 0.168f);
                    cb = (tcr * 0.272f) + (tcg * 0.534f) + (tcb * 0.131f);

                    image.SetPixel(i, j, Color.FromArgb((int)Util.clamp(ca, 0, 255), (int)Util.clamp(cr, 0, 255),
                                                        (int)Util.clamp(cg, 0, 255), (int)Util.clamp(cb, 0, 255)));
                }
            }
            return(image);
        }
Example #30
0
        /// <summary>
        /// #### Vignette 
        /// (red,green,blue) of the vignette effect to apply
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public BitmapW vignette(BitmapW image, int r, int g, int b)
        {
            float cr = 0, cg = 0, cb = 0, ca;
            int i = 0, j = 0,
            h = image.Height(),
            w = image.Width(),
            centerw = w / 2,
            centerh = h / 2,
            maxdist = dist(0, 0, centerw, centerh);

            maxdist = (int)(maxdist*0.6f);
            int radius = maxdist / 2;

            for (i = 0; i < w; i++)
            {
                for (j = 0; j < h; j++)
                {
                    Color temp = image.GetPixel(i, j);
                    cr = temp.R; cg = temp.G; cb = temp.B; ca = temp.A;
                    int distance = dist(i, j, centerw, centerh);
                    distance = (distance>radius)?distance-radius:0;

                    float ratio = ((distance / (float)(maxdist)));
                    cr = (1 - ratio) * cr + (ratio * r);
                    cg = (1 - ratio) * cg + (ratio * g);
                    cb = (1 - ratio) * cb + (ratio * b);

                    image.SetPixel(i, j, Color.FromArgb((int)Util.clamp(ca, 0, 255), (int)Util.clamp(cr, 0, 255),
                        (int)Util.clamp(cg, 0, 255), (int)Util.clamp(cb, 0, 255)));
                }
            }
            return image;
        }
Example #31
0
        /// <summary>
        /// #### Subtract [No Range]
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public BitmapW subtract(BitmapW image)
        {
            float cr = 0, cg = 0, cb = 0, ca;
            int i = 0, j = 0,
            h = image.Height(),
            w = image.Width();

            for (i = 0; i < w; i++)
            {
                for (j = 0; j < h; j++)
                {
                    Color temp = image.GetPixel(i, j);
                    cr = temp.R; cg = temp.G; cb = temp.B; ca = temp.A;

                    cr -= cr;
                    cg -= cg;
                    cb -= cb;

                    image.SetPixel(i, j, Color.FromArgb((int)Util.clamp(ca, 0, 255), (int)Util.clamp(cr, 0, 255),
                        (int)Util.clamp(cg, 0, 255), (int)Util.clamp(cb, 0, 255)));
                }
            }
            return image;
        }
Example #32
0
        /// <summary>
        /// #### Sharpen
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public BitmapW sharpen(BitmapW image)
        {
            BitmapW result;

            result = convolve(image, new float[,]{
            {0.0f, -0.2f,  0.0f},
            {-0.2f, 1.8f, -0.2f},
            {0.0f, -0.2f,  0.0f}
            }, 1, 1
            );

            return result;
        }
Example #33
0
        /// <summary>
        /// #### Sepia
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public BitmapW sepia(BitmapW image)
        {
            float cr = 0, cg = 0, cb = 0, ca;
            int i = 0, j = 0,
            h = image.Height(),
            w = image.Width();

            for (i = 0; i < w; i++)
            {
                for (j = 0; j < h; j++)
                {
                    Color temp = image.GetPixel(i, j);
                    cr = temp.R; cg = temp.G; cb = temp.B; ca = temp.A;
                    float tcr = cr, tcg = cg, tcb = cb;
                    cr = (tcr * 0.393f) + (tcg * 0.769f) + (tcb * 0.189f);
                    cg = (tcr * 0.349f) + (tcg * 0.686f) + (tcb * 0.168f);
                    cb = (tcr * 0.272f) + (tcg * 0.534f) + (tcb * 0.131f);

                    image.SetPixel(i, j, Color.FromArgb((int)Util.clamp(ca, 0, 255), (int)Util.clamp(cr, 0, 255),
                        (int)Util.clamp(cg, 0, 255), (int)Util.clamp(cb, 0, 255)));
                }
            }
            return image;
        }
Example #34
0
        /// <summary>
        /// #### Posterize [1, 255]
        /// </summary>
        /// <param name="image"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public BitmapW posterize(BitmapW image, float p)
        {
            p = Util.clamp(p, 1, 255);
            int step = (int)Math.Floor(255 / p);
            float cr = 0, cg = 0, cb = 0, ca;
            int i = 0, j = 0,
            h = image.Height(),
            w = image.Width();

            for (i = 0; i < w; i++)
            {
                for (j = 0; j < h; j++)
                {
                    Color temp = image.GetPixel(i, j);
                    cr = temp.R; cg = temp.G; cb = temp.B; ca = temp.A;

                    cr = (float)Math.Floor(cr / (float)(step)) * step;
                    cg = (float)Math.Floor(cg / (float)(step)) * step;
                    cb = (float)Math.Floor(cb / (float)(step)) * step;

                    image.SetPixel(i, j, Color.FromArgb((int)Util.clamp(ca, 0, 255), (int)Util.clamp(cr, 0, 255),
                        (int)Util.clamp(cg, 0, 255), (int)Util.clamp(cb, 0, 255)));
                }
            }
            return image;
        }
Example #35
0
        /// <summary>
        /// #### Noise [0 - 100]
        /// </summary>
        /// <param name="image"></param>
        /// <param name="r"></param>
        /// <param name="g"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public BitmapW noise(BitmapW image, int p)
        {
            int adjust = (int)(p * 2.55f);
            Random rand = new Random(adjust);
            int temprand = 0;

            float cr = 0, cg = 0, cb = 0, ca;
            int i = 0, j = 0,
            h = image.Height(),
            w = image.Width();

            for (i = 0; i < w; i++)
            {
                for (j = 0; j < h; j++)
                {
                    Color temp = image.GetPixel(i, j);
                    cr = temp.R; cg = temp.G; cb = temp.B; ca = temp.A;

                    temprand = rand.Next(adjust * -1, adjust);

                    cr += temprand;
                    cg += temprand;
                    cb += temprand;

                    image.SetPixel(i, j, Color.FromArgb((int)Util.clamp(ca, 0, 255), (int)Util.clamp(cr, 0, 255),
                        (int)Util.clamp(cg, 0, 255), (int)Util.clamp(cb, 0, 255)));
                }
            }
            return image;
        }
Example #36
0
        private void button6_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.FileName == "")
            { MessageBox.Show("Select an image first"); return; }

            BitmapW a = new BitmapW(openFileDialog1.FileName);
            pictureBox1.Image = a.GetBitmap(); //show the original image

            //apply effects

            BitmapW layer1 = a.Clone(); //working layer 1
            BitmapW res = a.Clone(); //this will hold the final result

            //do some adjustments
            res = effects.brighten(res, 10);
            res = effects.contrast(res, 30);

            //add a sepia softlight to the image
            layer1 = res.Clone();
            layer1 = effects.sepia(layer1);
            layer1 = effects.vignette(layer1, 0, 0, 0); //some vignette too
            res = layers.merge("softLight", res, layer1); //add this layer to our image as softlight

            //desaturate a little
            res = effects.saturate(res, -30);

            //tadaaa
            pictureBox2.Image = res.GetBitmap(); //show the resulting image
        }
Example #37
0
 /// <summary>
 /// #### Expose [-100, 100]
 /// </summary>
 /// <param name="image"></param>
 /// <param name="p"></param>
 /// <returns></returns>
 public BitmapW expose(BitmapW image, float p)
 {
     p = Util.normalize(p, -1, 1, -100, 100);
     Point c1 = new Point(0, (int)(255 * p));
     Point c2 = new Point((int)(255 - (255 * p)), 255);
     return curves(image, new Point(0, 0), c1, c2, new Point(255, 255));
 }
Example #38
0
        /// <summary>
        ///  Merges two layers. Takes a 'type' parameter and 
        /// a bottom and top layer. The 'type' parameter specifies
        /// the blending mode. type options are:
        ///- multiply
        ///- screen
        ///- overlay
        ///- softLight
        ///- addition
        ///- exclusion
        ///- difference
        /// </summary>
        /// <param name="type"></param>
        /// <param name="bottom"></param>
        /// <param name="top"></param>
        /// <returns></returns>
        public BitmapW merge(string type, BitmapW bottom, BitmapW top)
        {

            return apply(bottom, top, type);
        }
Example #39
0
        BitmapW curves(BitmapW image, Point s, Point c1, Point c2, Point e)
        {
            Util.Bezier bezier = new Util.Bezier(s, c1, c2, e);
            int[] points = bezier.genColorTable();

            float cr = 0, cg = 0, cb = 0, ca;
            int i = 0, j = 0,
            h = image.Height(),
            w = image.Width();

            for (i = 0; i < w; i++)
            {
                for (j = 0; j < h; j++)
                {
                    Color temp = image.GetPixel(i, j);
                    cr = temp.R; cg = temp.G; cb = temp.B; ca = temp.A;

                    cr = points[(int)cr];
                    cg = points[(int)cg];
                    cb = points[(int)cb];

                    image.SetPixel(i, j, Color.FromArgb((int)Util.clamp(ca, 0, 255), (int)Util.clamp(cr, 0, 255),
                        (int)Util.clamp(cg, 0, 255), (int)Util.clamp(cb, 0, 255)));
                }
            }
            return image;
        }
Example #40
0
        private void button5_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.FileName == "")
            { MessageBox.Show("Select an image first"); return; }

            BitmapW a = new BitmapW(openFileDialog1.FileName);
            pictureBox1.Image = a.GetBitmap(); //show the original image

            //apply effects

            BitmapW res = a.Clone(); //this will hold the final result

            //do some adjustments
            res = effects.brighten(res, 20);
            res = effects.saturate(res, -90);

            //add a purplish color
            BitmapW purple = a.Clone();
            purple = effects.fill(purple, 34, 43, 109);
            res = layers.merge("softLight", res, purple);

            //do some more adjustments
            res = effects.gamma(res, -5);
            res = effects.contrast(res, 50);

            pictureBox2.Image = res.GetBitmap(); //show the resulting image
        }
Example #41
0
        private BitmapW FastBoxBlur(BitmapW img, int radius)
        {
            int kSize = radius;

            if (kSize % 2 == 0)
            {
                kSize++;
            }
            BitmapW Hblur = img.Clone();
            float   Avg   = (float)1 / kSize;

            for (int j = 0; j < img.Height(); j++)
            {
                float[] hSum = new float[] { 0f, 0f, 0f, 0f };
                float[] iAvg = new float[] { 0f, 0f, 0f, 0f };

                for (int x = 0; x < kSize; x++)
                {
                    Color tmpColor = img.GetPixel(x, j);
                    hSum[0] += tmpColor.A;
                    hSum[1] += tmpColor.R;
                    hSum[2] += tmpColor.G;
                    hSum[3] += tmpColor.B;
                }

                iAvg[0] = hSum[0] * Avg;
                iAvg[1] = hSum[1] * Avg;
                iAvg[2] = hSum[2] * Avg;
                iAvg[3] = hSum[3] * Avg;


                for (int i = 0; i < img.Width(); i++)
                {
                    if (i - kSize / 2 >= 0 && i + 1 + kSize / 2 < img.Width())
                    {
                        Color tmp_pColor = img.GetPixel(i - kSize / 2, j);
                        hSum[0] -= tmp_pColor.A;
                        hSum[1] -= tmp_pColor.R;
                        hSum[2] -= tmp_pColor.G;
                        hSum[3] -= tmp_pColor.B;
                        Color tmp_nColor = img.GetPixel(i + 1 + kSize / 2, j);
                        hSum[0] += tmp_nColor.A;
                        hSum[1] += tmp_nColor.R;
                        hSum[2] += tmp_nColor.G;
                        hSum[3] += tmp_nColor.B;
                        //
                        iAvg[0] = hSum[0] * Avg;
                        iAvg[1] = hSum[1] * Avg;
                        iAvg[2] = hSum[2] * Avg;
                        iAvg[3] = hSum[3] * Avg;
                    }


                    Hblur.SetPixel(i, j, Color.FromArgb((int)iAvg[0], (int)iAvg[1], (int)iAvg[2], (int)iAvg[3]));
                }
            }

            BitmapW total = Hblur.Clone();

            for (int i = 0; i < Hblur.Width(); i++)
            {
                float[] tSum = new float[] { 0f, 0f, 0f, 0f };
                float[] iAvg = new float[] { 0f, 0f, 0f, 0f };
                for (int y = 0; y < kSize; y++)
                {
                    Color tmpColor = Hblur.GetPixel(i, y);
                    tSum[0] += tmpColor.A;
                    tSum[1] += tmpColor.R;
                    tSum[2] += tmpColor.G;
                    tSum[3] += tmpColor.B;
                }
                iAvg[0] = tSum[0] * Avg;
                iAvg[1] = tSum[1] * Avg;
                iAvg[2] = tSum[2] * Avg;
                iAvg[3] = tSum[3] * Avg;

                for (int j = 0; j < Hblur.Height(); j++)
                {
                    if (j - kSize / 2 >= 0 && j + 1 + kSize / 2 < Hblur.Height())
                    {
                        Color tmp_pColor = Hblur.GetPixel(i, j - kSize / 2);
                        tSum[0] -= tmp_pColor.A;
                        tSum[1] -= tmp_pColor.R;
                        tSum[2] -= tmp_pColor.G;
                        tSum[3] -= tmp_pColor.B;
                        Color tmp_nColor = Hblur.GetPixel(i, j + 1 + kSize / 2);
                        tSum[0] += tmp_nColor.A;
                        tSum[1] += tmp_nColor.R;
                        tSum[2] += tmp_nColor.G;
                        tSum[3] += tmp_nColor.B;
                        //
                        iAvg[0] = tSum[0] * Avg;
                        iAvg[1] = tSum[1] * Avg;
                        iAvg[2] = tSum[2] * Avg;
                        iAvg[3] = tSum[3] * Avg;
                    }
                    total.SetPixel(i, j, Color.FromArgb((int)iAvg[0], (int)iAvg[1], (int)iAvg[2], (int)iAvg[3]));
                }
            }
            return(total);
        }
Example #42
0
 /// <summary>
 ///  Merges two layers. Takes a 'type' parameter and 
 /// a bottom and top layer. The 'type' parameter specifies
 /// the blending mode. type options are:
 ///- multiply
 ///- screen
 ///- overlay
 ///- softLight
 ///- addition
 ///- exclusion
 ///- difference
 /// </summary>
 /// <param name="type"></param>
 /// <param name="bottom"></param>
 /// <param name="top"></param>
 /// <returns></returns>
 public BitmapW merge(string type, BitmapW bottom, BitmapW top)
 {
     return apply(bottom, top, type);
 }
Example #43
0
        BitmapW convolve(BitmapW image, float[,] kernel, int kw, int kh)
        {
            BitmapW temp = image.Clone();

            // int kh = kernel;
            //int kw = kh; //kernel[0].Length / 2;
            int i = 0, j = 0, n = 0, m = 0, cr, cg, cb,
            h = image.Height(),
            w = image.Width();

            for (i = 0; i < h; i++)
            {
                for (j = 0; j < w; j++)
                {
                    //kernel loop
                    float r = 0, g = 0, b = 0;
                    for (n = -kh; n <= kh; n++)
                    {
                        for (m = -kw; m <= kw; m++)
                        {
                            if (i + n >= 0 && i + n < h)
                            {
                                if (j + m >= 0 && j + m < w)
                                {
                                    float f = kernel[m + kw, n + kh];
                                    if (f == 0) { continue; }
                                    Color colortemp = image.GetPixel(j + m, i + n);
                                    cr = colortemp.R; cg = colortemp.G; cb = colortemp.B;

                                    r += cr * f;
                                    g += cg * f;
                                    b += cb * f;
                                }
                            }
                        }
                    }
                    //kernel loop end

                    temp.SetPixel(j, i, Color.FromArgb(255, (int)Util.clamp(r, 0, 255), (int)Util.clamp(g, 0, 255), (int)Util.clamp(b, 0, 255)));
                }
            }
            return temp;
        }
Example #44
0
 public BitmapW Gaussain(BitmapW src, int Radius)
 {
     return(FastGaussianBlur(src, Radius));
 }
Example #45
0
 public BitmapW Box(BitmapW src, int Radius)
 {
     return(FastBoxBlur(src, Radius));
 }
Example #46
0
        private void button7_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.FileName == "")
            { MessageBox.Show("Select an image first"); return; }

            BitmapW a = new BitmapW(openFileDialog1.FileName);
            pictureBox1.Image = a.GetBitmap(); //show the original image

            //apply effect
            BitmapW res = a.Clone();

            res = effects.saturate(res, -100); //grayscale it
            res = effects.contrast(res, 125);
            res = effects.noise(res, 3);
            res = effects.sepia(res);

            res = effects.adjust(res, 8, 2, 4);

            //tadaaa
            pictureBox2.Image = res.GetBitmap(); //show the resulting image
        }
Example #47
0
        /// <summary>
        /// #### Blur ['simple', 'gaussian']
        /// </summary>
        /// <param name="image"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public BitmapW blur(BitmapW image, string p)
        {
            BitmapW result;
            if (p == "simple")
            {
                result = convolve(image, new float[,]{
                {1.0f/9, 1.0f/9, 1.0f/9},
                {1.0f/9, 1.0f/9, 1.0f/9},
                {1.0f/9, 1.0f/9, 1.0f/9}
                }, 1, 1
                );
            }
            else //gaussian
            {
                result = convolve(image, new float[,]{
                {1.0f/273, 4.0f/273, 7.0f/273, 4.0f/273, 1.0f/273},
                {4.0f/273, 16.0f/273, 26.0f/273, 16.0f/273, 4.0f/273},
                {7.0f/273, 26.0f/273, 41.0f/273, 26.0f/273, 7.0f/273},
                {4.0f/273, 16.0f/273, 26.0f/273, 16.0f/273, 4.0f/273},
                {1.0f/273, 4.0f/273, 7.0f/273, 4.0f/273, 1.0f/273}
                }, 2, 2);
            }

            return result;
        }
Example #48
0
       public  BitmapW opacity(int value, BitmapW bottom, BitmapW top) // in Form1.cs for example: "layer3 = layers.opacity(50,layer2, layer1);" *"50" = 50% the value from 0-100
        {
            if (value >= 0 && value <= 100)
            {
                float percentge =(float)value/100;
                int i = 0, j = 0,
             h = Math.Min(bottom.Height(), top.Height()),
             w = Math.Min(bottom.Width(), top.Width());
                
                for (i = 0; i < w; i++)
                {
                    for (j = 0; j < h; j++)
                    {
                        Color b = bottom.GetPixel(i, j);
                        Color t = top.GetPixel(i, j);
                        float cr = 0, cg = 0, cb = 0, ca = 0;
                        ca = b.A * (1 - percentge) + t.A  * percentge;
                        cr = b.R * (1 - percentge) + t.R * percentge;
                        cg = b.G * (1 - percentge) + t.G * percentge;
                        cb = b.B * (1 - percentge) + t.B * percentge;
                       
                        bottom.SetPixel(i, j, Color.FromArgb((int)Util.clamp(ca, 0, 255), (int)Util.clamp(cr, 0, 255), (int)Util.clamp(cg, 0, 255), (int)Util.clamp(cb, 0, 255)));
                    }
                }

        Color func(string fn, Color b, Color t)
        {
            int cr = 0, cg = 0, cb = 0, ca = 0;
            //check which function to apply and apply it
            if (fn == "multiply")
            {
                cr = (t.R * b.R) / 255;
                cg = (t.G * b.G) / 255;
                cb = (t.B * b.B) / 255;
                ca = (t.A  * b.A) / 255;
            }
            if (fn == "screen")
            {
                cr = 255 - (((255 - t.R) * (255 - b.R)) / 255);
                cg = 255 - (((255 - t.G) * (255 - b.G)) / 255);
                cb = 255 - (((255 - t.B) * (255 - b.B)) / 255);
                ca = 255 - (((255 - t.A) * (255 - b.A)) / 255);
            }

            if (fn == "overlay")
            {
                cr = coverlay(b.R, t.R);
                cg = coverlay(b.G, t.G);
                cb = coverlay(b.B, t.B);
                ca = coverlay(b.A, t.A);
            }

            // Thanks to @olivierlesnicki for suggesting a better algoritm.
            if (fn == "softLight")
            {
                cr = csoftLight(b.R, t.R);
                cg = csoftLight(b.G, t.G);
                cb = csoftLight(b.B, t.B);
                ca = csoftLight(b.A, t.A);
            }
            if (fn == "addition")
            {
                cr = b.R + t.R;
                cg = b.G + t.G;
                cb = b.B + t.B;
                ca = b.A + t.A;
            }
            if (fn == "exclusion")
            {
                cr = 128 - 2 * (b.R - 128) * (t.R - 128) / 255;
                cg = 128 - 2 * (b.G - 128) * (t.G - 128) / 255;
                cb = 128 - 2 * (b.B - 128) * (t.B - 128) / 255;
                ca = 128 - 2 * (b.A - 128) * (t.A - 128) / 255;
            }
            if (fn == "difference")
            {
                cr = Math.Abs(b.R - t.R);
                cg = Math.Abs(b.G - t.G);
                cb = Math.Abs(b.B - t.B);
                ca = Math.Abs(b.A - t.A);
            }
           if (fn == "colordodge")
            {
               
                double cr_d, cg_d, cb_d, ca_d;
                if ((t.R) != 255)
                    cr_d = ((double)b.R /(255 - t.R))*255 ;
                else cr_d = 0;

                if ((t.G) != 255)
                    cg_d = ((double)b.G/(255 - t.G))*255;
                else cg_d = 0;

                if ((t.B) != 255)
                    cb_d = ((double)b.B/(255 - t.B))*255;
                else cb_d = 0;

                if ((t.A) != 255)
                    ca_d = ((double)b.A/(255 - t.A))*255;
                else ca_d = 0;

                cr = (int)cr_d;
                cg = (int)cg_d;
                cb = (int)cb_d;
                ca = (int)ca_d;

            }
            return Color.FromArgb((int)Util.clamp(ca, 0, 255), (int)Util.clamp(cr, 0, 255), (int)Util.clamp(cg, 0, 255), (int)Util.clamp(cb, 0, 255));

        }

        int coverlay(int b, int t) { return (b > 128) ? 255 - 2 * (255 - t) * (255 - b) / 255 : (b * t * 2) / 255; }
        int csoftLight(float b, float t)
        {
            b /= 255;
            t /= 255;
            return (int)((t < 0.5) ? 255 * ((1 - 2 * t) * b * b + 2 * t * b) : 255 * ((1 - (2 * t - 1)) * b + (2 * t - 1) * (Math.Pow(b, 0.5))));
        }