Loading...
Logo
Processing Forum

Blend algorithm

in Programming Questions  •  3 years ago  
I am trying to develop a more versatile blending algorithm.

I am currently using Processing blend (...,ADD) function.

Basically I would like to write an algorithm which accepts two images and blends them together without having a grey cast due to the overlapping alpha values.

For example:
Copy code
  1. void newblend(PImage src1, PImage src2){
  2.  PImage _src1 = createImage(src1.width,src1.height,ARGB);
  3.  PImage _src2 = createImage(src2.width,src2.height,ARGB);
  4. arraycopy(src1.pixels,_src1.pixels);
  5. arraycopy(src2.pixels,_src2.pixels);
  6. _src2.blend(_src1,0,0,_src2.width,_src2.height,0,0,_src2.width,_src2.height,ADD);
  7. }

Basically I want to write an algorithm to replace line 6 with a function that blends the two without the algorithm using either as the master sum of the r,g,b values. I want the blend to be mutually exclusive.

Replies(4)

Re: Blend algorithm

3 years ago
I don't understand what you mean by " mutually exclusive" but a way to achieve whatever you want is to create one PImage like you did, skip the arraycopy, walk simultaneously the two pixels[] arrays of the sources (assuming they have the same size, some adjustment might be needed otherwise) and combine the values of the pixels in the way you need.

Re: Blend algorithm

3 years ago
Thanks I will try that.

Re: Blend algorithm

3 years ago

You could try looping like phi.lho said and using lerpColor on the pixels...

Or, if you need more specific control, break out the components using the red() green() blue() and alpha() commands and then interpolate between the two sets and recombine with color().

If you need it done in real-time you'll either need to check out OpenGL's fixed function blend functionality or write a custom shader.

Jack

Re: Blend algorithm

3 years ago
I will try the open gl blending functions...however I am leaning more towards a customer shader.