# Convert Pegtop Equation to G'MIC Equation

#1

http://www.pegtop.net/delphi/articles/blendmodes/final.htm

I been having a lot of fun testing equation on Pegtop Blending Modes demo program, but I would like to know how to convert equation into something G’MIC can read.

For example - (sin(a/255)*b)*2

That’s a slight modified version of the equation that was already in the demostration program. How would I convert that to something G’MIC can read? Would it be nice if this was it own filter with opacity and blending mode options?

#2

G’MIC already has plenty of blend modes, which you could examine in the stdlib.

In G’MIC, the math operator is behind the fill command. E.g., to multiply the image by 2, you do

``````gmic sample tiger +fill i*2 cut 0,255 append y
``````

– sample image “tiger”
– multiply all pixel values by 2
– “+” means make a copy from fill
– cut the upper bounds for 8-bit output
– concatenate images

PS What does a and b stand for in your equation? Could you link to the actual code?

Foreground extraction (command line)
#3

A means RGB of channel of every layer combined below the current layer, and B means the RGB channel of current layer. That applies to everything in the Peptop blending modes link.

I am reading the document, but the issue is that I find it a little long to read, but Peptop demo software certainly makes me really interested into making my own blending modes for Krita, and I start to understand how the coding works now and the syntax in Krita (I was looking at hard mix change commit for Krita, and I actually finally understand how to create new blending modes for Krita). There is the issue of building Krita that never works out for me under Windows, so I can’t create anything for it. I’ll build under Linux VM myself.

#4

What does it mean to have a represent all layers below current layer? Is it an average blend?

If we had to 2 image layers only, the command would be as follows:

``````gmic sample tiger +blur 5 mirror. x ^
+fill. (sin(i#0/255)*i#1)*2 cut 0,255 append y
``````

– this time I added a blur (copy)
– horizontally flipped that copy
– “^” means new line in CMD.exe
– “#” denotes the image it is acting on
– other commands as described in previous post

(G'MIC staff) #5

There is a quite simple way to create a new custom blending mode in G’MIC.
Let me explain it briefly.

There is a command `blend` in G’MIC that takes a blending mode `bmode` as a parameter, and then internally do a call to a command `_blend_bmode`, which can be actually defined or redefined by the user if necessary (to create new blending modes or modify the behavior of existing ones).

What you have to know is that in a `_blend_bmode` command, you’ll always have only two images selected, the first one being the base layer (so layer `a` with Pegtop’s convention), and the second one, the blend layer (so layer `b`). G’MIC expects you only modify the second image, with the result of the blending at 100% opacity, so in your case, implementing your new blending mode is as simple as adding :

``````_blend_custom :
fill. "(sin(i#0/255)*i#1)*2"
cut. 0,255
``````

in your `.gmic` file. Then, you can use it directly in the `blend` command, and the `opacity` argument is automatically managed.

``````\$ gmic sample tiger,lena +blend[0] [1],custom +blend[0] [1],custom,0.4
``````

(image `[2]` is blended with 100% opacity, image `[3]` with 40% opacity).

(G'MIC staff) #6

This actually makes me think that a defining a `Custom` blending mode like this directly in the G’MIC filter `Blend [standard]` would be great. I’ll add this option hopefully in a few minutes

(G'MIC staff) #7

Here it is, new blending mode `custom formula` in the plug-in, to allow you to enter directly the Pegtop expressions to create your custom blending modes:

#8

I have a question for the new blending mode custom formula. What if a becomes the destination layer/blend layer, and b, and c are the following layers below the destination layer? Or can you do multiple layer i.e with i#0? I find it easier to understand a,b,c… than i#0, i#1, i#2… Does this sound more efficient?

#9

The equation is more like `c=(sin(a/255)*b)*2`, where `c` is the result of applying it using `fill`. Process as controls how multiple layers are paired off.