Question

I'm working on processing and I'd like to recreate on low level code the function blend lightest.

I saw in documentation that C = max(A * factor, B)

  • C is the returned color
  • A is the source
  • B is the image to mix with

I've seen on web that the factor specified is based on the alpha component of the source pixel, which is represented by the first 8 bits ( from the left ) of the 32-bit integer representing the pixel color. These leftmost bits are also referred to as the highest bits.

Source: this book, page 464

What should i think of it?

This is my code of that part:

for (int y = 0; y < capWidth * capHeight; y++) {
    int factor = (pixels[y] >> 24) & 0xFF;
    pixels[y] = max(pixels[y] * factor, previousFrame.pixels[y]);      
} 

That doesn't work, any help?

Was it helpful?

Solution

For each color: C = A(a/255) + B(1-(a/255)), where:

A is the foreground value,

B is the background value,

C is the resultant value, and

a is the alpha component.

This is per the alpha blending wiki page: http://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending

OTHER TIPS

  1. this won't work because the factor in your original formula is a floating-point number between 0 and 1, and the factor in your code is an integer from 0 to 255.
  2. this isn't a formula for blending, not really. For blending you have to add the colors, not take the maximum

http://processing.googlecode.com/svn/trunk/processing/build/javadoc/core/index.html

I got it in here, the SVG processing javadoc for blending Lighten ! Well !

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top