views:

361

answers:

2

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?

+1  A: 

Those are blending modes for compositing images on top of each other. The name of the blending mode already tells you the underlying operation.

The BLEND_* constants are simply aliases for the BLEND_RGB_* constants and the BLEND_RGBA_* variants operate on all four channels (including the alpha channel) as opposed to only RGB.

For general information about the different blending modes and their respective effects, see here.

Joey
Thanks for the answer. Can you give some tipps when to use which blend type?
Aaron Digulla
Thad all depends on what you want to achieve. It can be a bit counterintuitive, but keeping in mind what each mode does tells you what color yields what effect. You can use graphics software like GIMP or Paint.NET to play around with the blending modes as they are largely the same for layers.
Joey
A: 

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 (100,10,100)

MAX: Opposite of MIN

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).

Aaron Digulla