0

I am trying to recreate in C#, a series of photoshop filters. There is a specific look i want to give to an image that I found in a photoshop tutorial. I am creating a program that does this automatically.

I am at a step where I have to Screen blend two colors which I am able to do. The issue I'm having is I need to drop the opacity of just the filter to 30% and I'm not sure how to calculate this all together.

I can do screen between two colors. I can do alpha between two colors.

In photoshop they: 1. create a layer (horizontal white lines with alpha) 2. Apply the layer to the image with screen blend 3. Add a 30% opacity to the layer alone which lessens the screen effect.

I don't have any idea how to calculate that final opacity. My guess is i'd need to some how reduce the effect of the Screen by 70% for a 30% opacity but that doesn't seem quite right.

If anyone can help me with a order of operation that would be awesome!

Terrordoll
  • 173
  • 1
  • 1
  • 10
  • Are you asking specifically for help in photoshop? This site caters to programming, are you developing a filter, or do you just want help with PS? – Ron Beyer Oct 29 '15 at 21:10
  • I'm doing this all in c#. I'll edit the question to be more clear. – Terrordoll Oct 29 '15 at 21:30
  • Are your effects changing on a pixel by pixel basis? Then the difference you should be only 70%, right? So the new and old values would be mixed/blended in that proportion? – TaW Oct 29 '15 at 22:27

1 Answers1

0

I started just trying things out and ended up with this, which seems close if not exact.

  1. Screen blend base image with overlay image and save the result to a new location.
  2. Normal blend the base image with the product of the Screen blend.
  3. dispose of the overlay and the product.

Thinking about it now, it seems obvious but this took me hours of trial and error. Here is a bit of code if anyone is interested.

                        Color oldColor = Color.FromArgb(rgbValues[position + 2], rgbValues[position + 1], rgbValues[position]);                           
                        Color screenProduct = ScreenBlend(oldColor, white);
                        Color newColorScreen = CalculateColorWithAlpha(oldColor, screenProduct, .30f);

    public Color ScreenBlend(Color Base, Color Overlay)
    {
        var float_Red = 1 - (1 - RGB_ByteToFloat(Base.R)) * (1 - RGB_ByteToFloat(Overlay.R));
        var float_Green = 1 - (1 - RGB_ByteToFloat(Base.G)) * (1 - RGB_ByteToFloat(Overlay.G));
        var float_Blue = 1 - (1 - RGB_ByteToFloat(Base.B)) * (1 - RGB_ByteToFloat(Overlay.B));

        var byte_Red = RGB_FloatToByte(float_Red);
        var byte_Green = RGB_FloatToByte(float_Green);
        var byte_Blue = RGB_FloatToByte(float_Blue);

        //this.ScreenColorBase.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(Base.R, Base.G, Base.B));
        //this.ScreenColorOverlay.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(Overlay.R, Overlay.G, Overlay.B));
        //this.ScreenColorResult.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(byte_Red, byte_Green, byte_Blue));
        //this.ScreenColorTarget.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(166, 168, 248));

        return Color.FromArgb(byte_Red, byte_Green, byte_Blue);
    }

    public Color CalculateColorWithAlpha(Color Base, Color Over, float Alpha)
    {
        var finalRed = Alpha * Over.R + (1 - Alpha) * Base.R;
        var finalGreen = Alpha * Over.G + (1 - Alpha) * Base.G;
        var finalBlue = Alpha * Over.B + (1 - Alpha) * Base.B;

        return Color.FromArgb((int)finalRed, (int)finalGreen, (int)finalBlue);
    }

The top three lines are the pertinent code from within a loop, iterating through the pixels in a bitmap.

Hopefully this helps someone :)

Terrordoll
  • 173
  • 1
  • 1
  • 10