<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="moz-cite-prefix">Thank you so much for your time and
effort! Especially at this time of the year :)</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">But I am afraid your method does not
yet accomplish my goal. At first I was totally convinced by the
image your code produced and ported the code to GJS. Then I
realized that the result is actually pretty similar to me method
(e)! The checkerboard made this very difficult to spot in the
first place. But if you replace the checkerboard with a white
background you receive this image:</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix"><img
src="cid:part1.52D0DF08.DA0E2314@simonschneegans.de" alt=""></div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">If you use e.g. Gimp to look at the
color channels you see that there is a darkening in the red
channel which shouldn't be there:</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix"><img
src="cid:part2.20ABA99C.21637C72@simonschneegans.de" alt=""></div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">If you modify the color of the upper
gradient in your input() function to produce the desired image
directly, you get this:</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix"><img
src="cid:part3.EF4C1545.C7C9A58A@simonschneegans.de" alt=""></div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">Not only the upper, but also the bottom
gradient looks quite different actually!</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">Do you have an idea how to approach
this?</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">Again, thank you so much - and a happy
Christmas!</div>
<div class="moz-cite-prefix">Simon<br>
</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">On 25.12.20 14:07, Uli Schlachter
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:7c91574e-6803-4115-3f3b-bda193e0abbe@znc.in">
<pre class="moz-quote-pre" wrap="">Am 24.12.20 um 21:10 schrieb Simon Schneegans:
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">Hi Uli,
thank you for the kind reply!
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">Could you explain a bit more what exactly you want to achieve? E.g.,
what should happen when tinting with r=0.5, g=1, b=0, a=0.5 to colors
such as full red and... basically all the other colors.
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">
I think you understood my issue very well, but I will try to explain it
with more examples.
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">
Thanks a lot. The image helped. My checkerboard pattern does not look as
well as yours, but attached is a program which seems to do what you
want. You want to look at the function tint().
It works like this:
A given surface is split into its color component and alpha channel by
copying it to a color-only (CAIRO_CONTENT_COLOR / CAIRO_FORMAT_RGB24)
and an alpha-only (CAIRO_CONTENT_ALPHA / CAIRO_FORMAT_A8) surface,
respectively. This is done via the function copy_with_content() in the
attached program. The color-only part is multiplied with your color via
CAIRO_OPERATOR_MULTIPLY.
The multiplication result is then copied back to the target surface. By
doing this with cairo_mask(cr,
the_alpha_channel_of_the_original_surface), the alpha channel of the
original surface is recombined with the color components.
Since you also asked how to add tint with an ARGB-color: You can modify
the alpha-only surface before re-applying it. I think the following
should work (well, you have to extract the underlying cairo_surface_t
from the cairo_pattern_t in the code, but I bet you can figure out how
to do that):
cairo_t *cr = cairo_create(alpha);
cairo_set_source_rgba(cr, 0, 0, 0, alpha_factor);
cairo_set_operator(cr, CAIRO_OPERATOR_IN);
cairo_paint(cr);
cairo_destroy(cr);
Cheers,
Uli
P.S.: Error handling left as an exercise for the reader. I am not sure
if ignoring the return value of cairo_pattern_get_surface() really is a
good idea...
</pre>
</blockquote>
<p><br>
</p>
</body>
</html>