Glitch Art Filters?

(G'MIC staff) #21

I didn’t communicate too much on this one, but this was quite fun to do.
I’ll be probably away for a long time (summer holidays, two months), sorry for not being responsive until September :slight_smile:


Well, gotta bump this as I figured out how cumulative math from the ‘Paint.NET’ works.

The formula for initial part of cumulative Math is something like this :

  • ix > c ? ix - floor(i*x/c)c : ix

    • where i, is channel value of image, and x is multiplier, and c is the maximum channel value visible. Like 1.0 is the maximum visible channel value in float images even if float images permits 2.0.

    • The other part of cumulative math is pixel length transition between layer, and the application of binary blend mode. And then you should have cumulative math.

Maybe cumulative math add is simply adding channel value per layer divided by the maximum channel value.

They both should lead to very similar effect.

QAM looks tricky to figure out, but all it seems to be using curves per w and h where the curves is the initial graph, and any shift in graph uses the difference between the graphs multiplied by the color channel. That should stimulate QAM fault glitch in Paint.NET.

There, I think I said all there is to it to leave someone to figure it out (or even me if I ever figure out how to code for G’MIC.).


If I read “initial part” correctly, I think it’s the same as modulo:

gmic image.jpg max={iM} mul 2 mod \$max


Yes, that would be it.

Also, my cumulative add hypothesis seem to be working. I coded a blending mode for Krita since that’s the only coding I know of, it does look very similar to the one in Paint.NET

How is this?


Do you have a step by step of what that does? Or the code?

Edit: Especially including when a new layer is created


For krita, part of the code :

template<class T>
inline T cfCumulativeAdd(T src, T dst) {
    using namespace Arithmetic;

qreal fsrc = scale<qreal>(src);
qreal fdst = scale<qreal>(dst);

return scale<T>(fsrc + fdst > 1.0 ? fsrc + fdst - 1.0 : fsrc + fdst);  

If the addition of the above layer adds more than 1.0, then it returns the decimal point only. That’s how the blending mode works. This blending mode treats numbers as floating point between 0 to 1 due to the usage of qreal, and scale. Replace 1.0 with floor (fsrc+fdst) and it’s good enough.


OK that’s good, the calculations all make sense but we’re missing the step by step (i.e. you’re showing a blend, but how was the second layer created?). Could you show something like this:

  1. create a new layer with formula x=…
  2. blend that layer using formula x=…

Edit: as an example, it seems like you mean

  1. create a new layer with o = (n*i) mod (max) (what’s the value of multiplier n?)
  2. blend this layer with the original layer using o = (x + y) mod (max)


I duplicated the layer, and assigned the Cumulative Add Blending Mode.

See the screenshot here -

You can duplicate the image on the two pages icon next to + arrow.

As for multiplier, there is no multiplier. It’s simply addition of two layers, and then subtracting that by the floor of two layers. That is how the Paint.NET plugin works. If you use already blended image gradients with cumulative add and copy that again and assign the blending mode, you get the result of 4 black and white gradients.

I’m not sure how I can make this easier to understand.


There is our missing step, which means it’s actually exactly what I posted above (by a bit of coincidence). Multiply by two, modulo the original maximum (or you could supply a maximum e.g. 1.0 or 255):

gmic image.jpg max={iM} mul 2 mod \$max


Yes. Although, there’s one more suggestion I have. Scaling the layer, apply the effect, and rescale again to original result for more smoother result.

Just had to bump this thread. I would like to work to make the filter possible, but there seem to be a bug accordingly to garagecoder. @David_Tschumperle is now here, so the bug could be looked into.

Basically, the cumulative filter use modulo addition per layer, and, or, but we could also use XOR or randomize binary operations per layer as well as having options to have different direction, and randomize direction a bit. Basically a better version of the Paint.NET one.

Also, I believe modulo operations could be it own filter based on float operation with different color spaces options. Anything that goes after 1.0 will becomes 0 to 1.0 where to implies it doesn’t reach 1.0. Even modulo operation filter could also be extended to being a blending mode on it own. That helps me fix the disco filter, and the result is what you expect from preview on that filter after you apply blur.


@Reptorian @David_Tschumperle here’s an exact replica of cumulative math:

cumul_math : skip ${1=1},${2=1},${3="add"},${4=0}
  repeat $! l[$>]
    100%,100%,100%,1,1 (0,$2) if $4 z. 1,1 fi
    +mul. $1 shift[1] {^} rm. m={^} rm. [0]
    repeat $1 +shift. $m +mul. [1] $3[0,-1] rm.. done k[0] mod 256
  endl done

I must admit it’s a very annoying thing to try and replicate for such a simple operation :dizzy_face:


There’s still binary and, binary or operations. But, I think xor could be added, and randomization of binary blending modes + modulo addition per layer as well.

I’m working on modulo operations filter with the option of addition, and multiplication. I don’t know what subtract does in GIFXR.

A glimpse here -

#@gui _
#@gui <i>Reptorian</i>
#@gui Modulo Operations : fx_modulo, fx_modulo_preview(0)
#@gui : note = note("Applies modulo operations based on arithmetric operations)
#@gui : Modulo Operations = choice ("Addition", Multiplication")
#@gui : Number = float(1,0,64)
#@gui : sep = separator(), note = note("<small>Author : <i>Reptorian</i>.      Latest update : <i>2018/08/18</i>.</small>")

The next part, I’m not feeling too confident. Coding has always been an alien concept, but I’ll try to understand.


I’ve added it as a testing filter (Cumulative Math), it should be available after filter refresh within the next 30 mins. Was trying to avoid adding it to mine since some are already “official”, but I guess it can be undone easily enough :slight_smile:

Here’s the commit in github if you want to view the code.

Edit: might be another hour yet. The update seems to do what it likes sometimes :roll_eyes:
Edit2: whahaha! now it appears. It knows…


I am testing it, and I love it as it is. There’s one little thing that needs to be added. Binary And operation. And then, I consider it completely done.

Maybe random inversion of layers, and random listed binary operations could be added, but that’s not needed, and not being restricted to one direction could also be considered. Left to Right, Right to Left, Top to Bottom, Bottom to Up, or Diagonal based on X,Y coordinates.

EDIT: I found a glitch with XOR.
Amount - 5, Step 2 erases part of image.


Ah yes I see, opacity channel problem - fixed (30 mins to update again…). I may have time this week to do more, but no promises!

Edit: whoops, fixed one thing broke another. Avoid refresh for an hour if you can :blush:


Well, I solved my own filter which is basically a “branch-off” from the cumulative math filter. Some people might want to have modulo add part of the cumulative math filter without layers effect, so I added a new filter just for that. @David_Tschumperle should have received my message about the new filter.

(G'MIC staff) #37

I’m really wondering why this effect has been called “Cumulative math”. :thinking:
It seems to be basically a modulo done after a math operation, where the accumulation comes from ?


Hah I was wondering the same! The author admits to it all being very “hacky”. Without wanting to diminish the creativity of it, it’s really quite a dumb filter :grin:

Apart from the type which replicates certain flaws (e.g. compression) it’s generally far easier to break an image than to do something “useful” with it!

(G'MIC staff) #39

Also, just for the sake of fun, I’ll try implementing my own version of this filter.
Not that I think this will be better, but because I want to try using mainly the G’MIC math evaluator to do it. Also I’d like to use one of the new point() parameter to allow shifting the blending image along XY.


It suddenly hits my head that there is another idea I had in my mind. Wraparound mode as a option instead of just pasting layers over layers ignoring the wraparound.

I guess math evaluator means custom math expression can be used with the filter along with premade options like custom blending modes filter. If I’m not mistaken, that’s a great idea.