Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do the blend modes in pygame mean?

Surface.blit has a new parameter in 1.8: blend. The following values are defined:

  • BLEND_ADD
  • BLEND_SUB
  • BLEND_MULT
  • BLEND_MIN
  • BLEND_MAX
  • BLEND_RGBA_ADD
  • BLEND_RGBA_SUB
  • BLEND_RGBA_MULT
  • BLEND_RGBA_MIN
  • BLEND_RGBA_MAX
  • BLEND_RGB_ADD
  • BLEND_RGB_SUB
  • BLEND_RGB_MULT
  • BLEND_RGB_MIN
  • BLEND_RGB_MAX

Can someone explain what these modes mean?

like image 733
Aaron Digulla Avatar asked Mar 02 '09 09:03

Aaron Digulla


People also ask

What do the blend modes mean?

What are blending modes? A blending mode is an effect you can add to a layer to change how the colors blend with colors on lower layers. You can change the look of your illustration simply by changing the blending modes.

What do blending modes affect?

A blending mode is a feature used to combine layers together. If you apply a blending mode to a layer it will affect how it interacts with all of the layers beneath it. If you are familiar with blending modes in Photoshop they work in the exact same way. It's kinda like having a colored filter.

What are the 3 most used blend modes?

Even though Photoshop includes 22 others, these five blend modes are the ones you'll use the most. The Multiply blend mode darkens images, the Screen blend mode lightens them, and the Overlay blend mode increases contrast. The Color blend mode blends only the color of a layer, and Luminosity blends only the brightness!

What is blend mode difference?

As the description implies, the difference blend mode subtracts the pixels of the base and blend layers and the result is the greater brightness value. Well, when you subtract two pixels with the same value, the result is black. This makes it very easy to see where images are aligned in Photoshop.


1 Answers

You can find the source for the blend operations here: surface.h

Basically, ADD adds the two source pixels and clips the result at 255. SUB subtracts the two pixels and clips at 0.

MULT: result = (p1 * p2) / 256

MIN: Select the lower value of each channel (not the whole pixel), so if pixel1 is (100,10,0) and pixel2 is (0,10,100), you get (0,10,0)

MAX: Opposite of MIN (i.e. (100,10,100))

And there is an additional blend mode which isn't obvious from the docs: 0 (or just leave the parameter out). This mode will "stamp" source surface into the destination. If the source surface has an alpha channel, this will be determine how "strong" each pixel is (0=no effect, 255=copy pixel, 128: result = .5*source + .5*destination).

Useful effects: To darken a certain area, use blend mode 0, fill the source/stamp surface black and set alpha to 10: (0,0,0,10).

To lighten it, use white (255,255,255,10).

like image 198
Aaron Digulla Avatar answered Oct 01 '22 17:10

Aaron Digulla