# image processing: tint algorithm

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

## 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 on other sites
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 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, 
 0 
 Share this post Link to post Share on other sites 
 
 
 Melekor    379 Melekor Member 379 Posted May 23, 2005 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; // cyanfloat 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 0 Share this post Link to post Share on other sites Josh Yelon    220 Josh Yelon Member 220 Posted May 23, 2005 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 desaturatedif (time-of-day == SUNSET) then tint = (1.0,0.8,0.6) // reddish tint saturation = 0.7 // not that desaturatedmono = original DOT (0.333,0.333,0.333)tinted = mono * tintfinal = saturation * original + (1-saturation) * tinted- Josh Yelon-- Distribution Maintainer, Panda3D 0 Share this post Link to post Share on other sites 
 Sign in to follow this   Followers 0 
 Go To Topic Listing Graphics and GPU Programming Advertisement 
 Advertisement What is your GameDev Story? In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us. (You must login to your GameDev.net account.) Share My Story Popular Tags 2D 3D Advice Algorithm C# C++ Character Concept Design DX12 GameMaker Gameplay General Graphics Mobile Music OpenGL Open Source Optimization PC Pixel Unity Unreal VR Vulkan Popular Now 19 Anyone who wants to write a little game engine? By DaTueOwnerStarted Friday at 10:12 PM 14 OpenGL Textures, Pixel Alignment And Texture Mistakes. What Am I Doing Wrong? By babaliarisStarted Friday at 07:34 PM 10 Managing pointers upon object destruction in C++ By too_many_starsStarted Friday at 09:21 AM 9 A Functional Impass - Advise me on how to proceed? (C#) By A4LStarted Friday at 04:32 AM 11 MMORPG Brilliant Game Idea. By Tara LouiseStarted Thursday at 01:03 AM Advertisement Forum Statistics Total Topics 634097 Total Posts 3015507 GameDev.net GameDev.net Articles GameDev.net Event Coverage GameDev.net Forums GameDev.net Blogs GameDev.net Gallery GameDev.net News GameDev.net Projects GDNet Chat All Activity Search In Everywhere This Forum This Topic More options... Find results that contain... All of my search term words Any of my search term words Find results in... Content titles and body Content titles only Home Forums Programming Graphics and GPU Programming image processing: tint algorithm 
 
 
 × Existing user? Sign In Sign Up Browse Back Articles & Tutorials Back All Categories Audio Business Game Design Industry Programming Visual Arts Columns Back GameDev Unboxed Event Coverage Back All Events Game Developers Conference Power Up Digital Games Conference GameDev.Market Links News Podcasts Back All Podcasts Game Dev Loadout Archive Community Back Beginners Back Beginners Group Beginners Forum Beginners Resources Blogs Calendar Chat Forums Back All Forums Audio Business Game Design Programming Visual Arts Community GameDev Challenges Affiliates Topical Workshops Gallery Groups Back For Beginners GameDev Challenges All Groups Projects Back All Projects Games Game Assets Game Mods Developer Tools Store Forums Back All Forums For Beginners Audio Back Music and Sound FX Games Career Development Business Back Games Career Development Production and Management Games Business and Law Game Design Back Game Design and Theory Writing for Games Programming Back Artificial Intelligence Engines and Middleware General and Gameplay Programming Graphics and GPU Programming Math and Physics Networking and Multiplayer Visual Arts Back 2D and 3D Art Critique and Feedback Community Back GameDev Challenges GDNet Lounge GDNet Comments, Suggestions, and Ideas Coding Horrors Your Announcements Hobby Project Classifieds Indie Showcase Affiliates Back NeHe Productions AngelCode Topical Workshops Careers Back Contractors Hobby Projects Game Jobs Back Browse on GameDev.Jobs Post a Job Members Back Subscriptions Chat Guidelines Leaderboard Online Users Awards Search Back All Activity My Activity Streams Back Latest Topics Featured Blogs Search Important Information By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.   I accept GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry. Sign me up! 
 $('body').click(function (e) { var container =$("#pagecontainer"); if (($(e.target).parent().prop('nodeName') == 'BODY') && (container.has(e.target).length === 0) && (e.button == 0) && (!$(e.target).hasClass('ipsDialog'))) { window.open('https://ad.doubleclick.net/ddm/trackclk/N129002.1825GAMEDEV.NET/B11085475.236262913;dc_trk_aid=433791501;dc_trk_cid=90245747;dc_lat=;dc_rdid=;tag_for_child_directed_treatment=;tfua='); ga('send','event','Advertisement','Click','3q_fb_gamedev_skin_2019_1'); } }); $(document).ready(function() { setInterval(function() { window.googletag.pubads().refresh(); }, 30000); });$(document).ready(function() { if (ipsSettings.memberID > 0) { ga('send','event','User','View','Member'); } else { ga('send','event','User','View','Guest'); } });