Subject. I want to achieve colorization of one pixel by other pixel like "Color" blending mode in Photoshop (with 100% opacity). What I do now:
- get hue of mask pixel;
- convert source pixel from RGB to HSL;
- replace hue and convert back to RGB;
If you are interested in the formula - check this: Please explain this color blending mode formula so I can replicate it in PHP/ImageMagick
But for this task converting back'n'forth from/to HSL/RGB seems too excessive.
So I am looking for a faster approach. I guess there should be way to calculate RGB-multiplying coefficients somehow and then for source pixel just simply do something like this:
src_R *= mult_R;
src_G *= mult_G;
src_B *= mult_B;
UPD: Actually I don't need it to be exactly like in Photoshop. I mentioned PS blending mode just for example. I use it in my custom convolving routine, so I want it to be fast, but precision is not important, so it even if it could be approximated by a few percents. It's just that I want to find an approach to change pixel's tone without these complex HSL/RGB conversions...
UPD2: After some tests I've realized that my approach (replacing hue) is actually pretty far from what I wanted. Also after some digging I've found that "Color" blend-mode in PS replaces not only Hue but also Saturation. And surprisingly that makes algorithm not more complex, but on a contrary a bit simpler (faster):
- we need to get not only Hue, but also Saturation of mask-pixel
- but now we don't need to convert src-pixel from RGB to HSL, cuz all we need is luminocity which calculated much faster than full RGB->HSL routine...
- with src-Luminocity, mask-Hue and Sat. we convert it to RGB...
It is still pretty complex though, and I still believe it could be simplified.