pygame-ce icon indicating copy to clipboard operation
pygame-ce copied to clipboard

`BLEND_OVERLAY` flag

Open itzpr3d4t0r opened this issue 2 years ago • 1 comments
trafficstars

Description

We've had an essential number of blend modes available for a long time, which are: MAX MIN ADD SUB MULT While these flags can be combined together to achieve more effects, it's not possible to achieve all possible blend modes, even some of the most basic ones.

I propose to add one more blend flag called OVERLAY (both RGB and RGBA) which is:

  • A very common blend mode present in most image editing softwares
  • Can help with creating masked special effects for colorization and achieve generally better contrasted results compared to MULT.

This is an example screenshot comparing the current blend flags with OVERLAY (all use the same "BASE" BW image and the same overlay color):

image This is another example comparing with MULT and a colored base with the same overlay color: image

While it's possible to achieve virtually any blend mode with surfarrays/numpy or even GPU shaders i strongly believe expanding on blend flags is a valid path, especially because it would:

  • Help achieve a wider range of effects in most CPU-based programs
  • Avoid the incovenience of using external libraries and write more complex programs
  • Not everyone with a big project could be willing to switch to GPU stuff because of the time required to switch

Technicalities

Implementing such blend flags includes implementing 6 functions internally, 3 for alpha and 3 non-alpha versions, for single pixel, SSE2 and AVX2 versions), not to mention tests to ensure the correct behaviour. This could lead to difficulties during the review phase since 6 functions would need to be checked individually since they're mostly selected at compile time. So for this very reason i was planning to implement these flags in 2 or 3 phases where either:

  • Only the single pixel and AVX2 versions are implemented first together and then the SSE2 version
  • The single pixel version first, then the SSE2 and then AVX2

Another thing that could simplify the review process is to only add the RGB version first and then the RGBA version in a followup PR.

itzpr3d4t0r avatar Aug 02 '23 12:08 itzpr3d4t0r

While looking for a good refresher on what exactly the overlay blend mode is - I found a pretty good page on photoshop blending modes here, which has a list of the 6 most commonly used:

  1. Multiply
  2. Screen
  3. Overlay
  4. Soft Light
  5. Color
  6. Luminosity

If this gets merged we will have two of these six - leaving four more for us to potentially create. I mean we have other blend modes in common with photoshop too, but only one of these six (multiply) is currently in pygame-ce.

MyreMylar avatar Feb 11 '24 12:02 MyreMylar