Colorize grayscale image
I have a grayscale image and a some color, represented in RGB triplet. And i need to colorize grayscale image using this triplet.

<img src="https://lh5.googleusercontent.com/-hb5AvEY9obk/TnuZDajInxI/AAAAAAAAAk0/ltC5Kf0Wjxo/coloring_image.jpg">

The left image represents what we have and the right what i need to have.
Now in program i have some function where in input is R, G and B value of source image and and RGB value color which should be used as coloring value. 
And i can't decide how can i increase or decrease source RGB using color RGB to have the right color pallette.

The language is C++, but it's not so important.
Thanks in advance.
Colorize grayscale image
===

I have a grayscale image and a some color, represented in RGB triplet. And i need to colorize grayscale image using this triplet.

<img src="https://lh5.googleusercontent.com/-hb5AvEY9obk/TnuZDajInxI/AAAAAAAAAk0/ltC5Kf0Wjxo/coloring_image.jpg">

The left image represents what we have and the right what i need to have.
Now in program i have some function where in input is R, G and B value of source image and and RGB value color which should be used as coloring value. 
And i can't decide how can i increase or decrease source RGB using color RGB to have the right color pallette.

The language is C++, but it's not so important.
Thanks in advance.