Desaturate a graphics surface - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3) +---- Forum: Utilities (https://staging.qb64phoenix.com/forumdisplay.php?fid=8) +---- Thread: Desaturate a graphics surface (/showthread.php?tid=1499) |
Desaturate a graphics surface - johannhowitzer - 02-25-2023 This routine will apply a desaturation effect to a graphics surface. You pass the handle and a number from 0 to 1, where 0 does not desaturate at all, and 1 turns everything to greyscale. Code: (Select All) sub desaturate(d~&, rate) Limitations: - The desaturation is rather expensive, so you may have performance issues if you are doing this many times per second. The way I've used this in my own project is to desaturate a background that isn't going to change, then store the desaturated version for use in redrawing the screen, so the desaturation effect only needs to be applied once. - This is currently using _rgb(), which means it's not accounting for alpha values. I haven't tested extensively how point() interacts with alpha, and I seem to remember having some issues in the past, so I have no plans to update this to use _rgba() or _rgba32(). So if you use this on a graphics surface, expect to lose any transparency. |