Jump to content
  • Advertisement
Sign in to follow this  
MarkyMark

image processing: tint algorithm

This topic is 4901 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Whats the correct way to tint an image a specific colour? I've tried an algorithm which adds the specified R,G,B components to the current pixel value ... but the result is not what quite what I'm looking for ( ok that bit is subjective ). Do I need to be messing around with colour histograms and such to do this properly. Mark

Share this post


Link to post
Share on other sites
Advertisement
You could search the internet for information on different types of blend modes. This page seems to have a simple description of the common blend modes. Try looking at either Multiply or Screen, probably.

Share this post


Link to post
Share on other sites
What do you want to do exactly ? Adding a color tint to an image is usually done using a linear interpolation:


pixel.rgba = originalpixel.rgba * t + tintcolor.rgba * (1 - t)



Do you want omething more precise ?

HTH,

Share this post


Link to post
Share on other sites
One way to do this is by transforming to the HSV colorspace, modifying the H (Hue) then transforming back. This has the effect of preserving the luminosity and saturation while changing the "color". You can find some good conversion routines here.

Example code:

const float tint_hue = 180.0f; // cyan
float h, s, v;
float fr, fg, fb;
RGBtoHSV(r/255.0f, g/255.0f, b/255.0f, &h, &s, &v);
HSVtoRGB(&fr, &fg, &fb, tint_hue, s, v);
r = fr * 255.0f;
g = fg * 255.0f;
b = fb * 255.0f;

Since the calculated H value is unused, you can optimize RGBtoHSV a lot by removing the part that calculates H.

HTH.
-Melekor

Share this post


Link to post
Share on other sites
If what you're trying to do is tint to create a "time-of-day" effect, I've found that it often looks good to convert to black-and-white first. Converting to black-and-white simulates the fact that at night, our eyes switch over from cones to rods.


if (time-of-day == NIGHT) then
tint = (0.8,0.8,1.0) // slightly blue
saturation = 0.4 // fairly desaturated

if (time-of-day == SUNSET) then
tint = (1.0,0.8,0.6) // reddish tint
saturation = 0.7 // not that desaturated

mono = original DOT (0.333,0.333,0.333)
tinted = mono * tint
final = saturation * original + (1-saturation) * tinted


- Josh Yelon
-- Distribution Maintainer, Panda3D

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!