What do the blend modes in pygame mean?

…衆ロ難τιáo~ 提交于 2019-11-27 15:03:47

问题


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:


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




回答2:


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.



来源:https://stackoverflow.com/questions/601776/what-do-the-blend-modes-in-pygame-mean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!