<div dir="ltr">Hello, Thanks for your answer.<div><br></div><div>Below is a small test program (works on little endian machines).</div><div><br></div><div>As is the result is already strange to me :</div><div><div>     in: r=20 g=20 b=80 a=FF</div>
<div>     out: r=90 g=90 b=C0 a=FF</div></div><div>Where as I expected the fill color #FFFFFFFF x the mask 0x80 = #FFFFFF80 and so an output of #9090FFFF.</div><div><br></div><div>However, if I set the fill color to #FFFFFF80, the result seems really wrong :</div>
<div><div>in: r=20 g=20 b=80 a=FF</div><div>out: r=98 g=98 b=E0 a=FF</div></div><div><br></div><div>I would expect fill x mask => #FFFFFF40 and thus out: #606060C0FF.</div><div><br></div><div>I especially do not understand how a lower alpha input color can end up in a lighter output on the target image.</div>
<div><br></div><div>What I am doing wrong here ?</div><div><br></div><div>Thanks.</div><div><br></div><div><br></div><div><p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(232,35,0)"><span style="color:rgb(119,121,151)">#include </span><stdlib.h></p>

<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(119,121,151)">#include <span style="color:rgb(232,35,0)"><stdio.h></span></p>
<p style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><br></p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(53,86,138)">union<span style="color:rgb(0,0,0)"> C {</span></p>
<p style="margin:0px;font-size:11px;font-family:Menlo"><span class="" style="white-space:pre">        </span><span style="color:rgb(195,89,0)">uint32_t</span> value;</p>
<p style="margin:0px;font-size:11px;font-family:Menlo"><span class="" style="white-space:pre">        </span><span style="color:rgb(53,86,138)">struct</span> RGBA8888 {</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(195,89,0)"><span style="color:rgb(0,0,0)"><span class="" style="white-space:pre">             </span></span>uint8_t<span style="color:rgb(0,0,0)"> a;</span></p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(195,89,0)"><span style="color:rgb(0,0,0)"><span class="" style="white-space:pre">             </span></span>uint8_t<span style="color:rgb(0,0,0)"> b;</span></p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(195,89,0)"><span style="color:rgb(0,0,0)"><span class="" style="white-space:pre">             </span></span>uint8_t<span style="color:rgb(0,0,0)"> g;</span></p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(195,89,0)"><span style="color:rgb(0,0,0)"><span class="" style="white-space:pre">             </span></span>uint8_t<span style="color:rgb(0,0,0)"> r;</span></p>
<p style="margin:0px;font-size:11px;font-family:Menlo"><span class="" style="white-space:pre">        </span>} rgba;</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">};</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><br></p>
<p style="margin:0px;font-size:11px;font-family:Menlo"><span style="color:rgb(53,86,138)">void</span> testPixmapOps()</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">{</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(207,135,36)"><span style="color:rgb(0,0,0)">    </span>// create target image full with r=0x20 g=0x20 b=0x80 a=0xFF</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(207,135,36)"><span style="color:rgb(0,0,0)">    </span><span style="color:rgb(195,89,0)">size_t</span><span style="color:rgb(0,0,0)"> w = </span><span style="color:rgb(53,86,138)">100</span><span style="color:rgb(0,0,0)">; </span>// multiple of 4 for alignment</p>

<p style="margin:0px;font-size:11px;font-family:Menlo">    <span style="color:rgb(195,89,0)">size_t</span> h = <span style="color:rgb(53,86,138)">100</span>;</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">    <span style="color:rgb(195,89,0)">C</span> *target = (<span style="color:rgb(195,89,0)">C</span>*)<span style="color:rgb(88,126,168)">malloc</span>(w * h * <span style="color:rgb(53,86,138)">sizeof</span>(<span style="color:rgb(195,89,0)">C</span>));</p>

<p style="margin:0px;font-size:11px;font-family:Menlo">    <span style="color:rgb(53,86,138)">for</span>(<span style="color:rgb(195,89,0)">size_t</span> i = <span style="color:rgb(53,86,138)">0</span>; i < w * h; ++i)</p>

<p style="margin:0px;font-size:11px;font-family:Menlo">        target[i].<span style="color:rgb(88,126,168)">value</span> = <span style="color:rgb(53,86,138)">0x202080FF</span>;</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">    <span style="color:rgb(88,126,168)">printf</span>(<span style="color:rgb(232,35,0)">"in: r=%02X g=%02X b=%02X a=%02X\n"</span>, </p><p style="margin:0px;font-size:11px;font-family:Menlo">
        target[<span style="color:rgb(53,86,138)">0</span>].<span style="color:rgb(88,126,168)">rgba</span>.<span style="color:rgb(88,126,168)">r</span>, target[<span style="color:rgb(53,86,138)">0</span>].<span style="color:rgb(88,126,168)">rgba</span>.<span style="color:rgb(88,126,168)">g</span>, target[<span style="color:rgb(53,86,138)">0</span>].<span style="color:rgb(88,126,168)">rgba</span>.<span style="color:rgb(88,126,168)">b</span>, target[<span style="color:rgb(53,86,138)">0</span>].<span style="color:rgb(88,126,168)">rgba</span>.<span style="color:rgb(88,126,168)">a</span>);</p>

<p style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><br></p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(207,135,36)"><span style="color:rgb(0,0,0)">    </span>// connect target to pixman image</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">    <span style="color:rgb(195,89,0)">pixman_image_t</span> *ptarget = <span style="color:rgb(88,126,168)">pixman_image_create_bits</span>(<span style="color:rgb(88,126,168)">PIXMAN_r8g8b8a8</span>, w, h, (<span style="color:rgb(195,89,0)">uint32_t</span>*)target, w * <span style="color:rgb(53,86,138)">sizeof</span>(<span style="color:rgb(195,89,0)">uint32_t</span>));</p>

<p style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><br></p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(207,135,36)"><span style="color:rgb(0,0,0)">    </span>// create fill</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(195,89,0)"><span style="color:rgb(0,0,0)">    </span>pixman_color_t<span style="color:rgb(0,0,0)"> cfill;</span></p>
<p style="margin:0px;font-size:11px;font-family:Menlo">    cfill.<span style="color:rgb(88,126,168)">red</span>   = <span style="color:rgb(195,89,0)">uint16_t</span>(<span style="color:rgb(53,86,138)">0xFF</span>) << <span style="color:rgb(53,86,138)">8</span>;</p>

<p style="margin:0px;font-size:11px;font-family:Menlo">    cfill.<span style="color:rgb(88,126,168)">green</span> = <span style="color:rgb(195,89,0)">uint16_t</span>(<span style="color:rgb(53,86,138)">0xFF</span>) << <span style="color:rgb(53,86,138)">8</span>;</p>

<p style="margin:0px;font-size:11px;font-family:Menlo">    cfill.<span style="color:rgb(88,126,168)">blue</span>  = <span style="color:rgb(195,89,0)">uint16_t</span>(<span style="color:rgb(53,86,138)">0xFF</span>) << <span style="color:rgb(53,86,138)">8</span>;</p>

<p style="margin:0px;font-size:11px;font-family:Menlo">    cfill.<span style="color:rgb(88,126,168)">alpha</span> = <span style="color:rgb(195,89,0)">uint16_t</span>(<span style="color:rgb(53,86,138)">0xFF</span>) << <span style="color:rgb(53,86,138)">8</span>;</p>

<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(88,126,168)"><span style="color:rgb(0,0,0)">    </span><span style="color:rgb(195,89,0)">pixman_image_t</span><span style="color:rgb(0,0,0)"> *pfill = </span>pixman_image_create_solid_fill<span style="color:rgb(0,0,0)">(&cfill);</span></p>

<p style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px">    </p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(207,135,36)"><span style="color:rgb(0,0,0)">    </span>// create mask with a=0x80</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">    <span style="color:rgb(195,89,0)">uint8_t</span> *mask = (<span style="color:rgb(195,89,0)">uint8_t</span>*)<span style="color:rgb(88,126,168)">malloc</span>(w * h);</p>

<p style="margin:0px;font-size:11px;font-family:Menlo">    <span style="color:rgb(53,86,138)">for</span>(<span style="color:rgb(195,89,0)">size_t</span> i = <span style="color:rgb(53,86,138)">0</span>; i < w * h; ++i)</p>

<p style="margin:0px;font-size:11px;font-family:Menlo">        mask[i] = <span style="color:rgb(53,86,138)">0x80</span>;</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">    <span style="color:rgb(195,89,0)">pixman_image_t</span> *pmask = <span style="color:rgb(88,126,168)">pixman_image_create_bits</span>(<span style="color:rgb(88,126,168)">PIXMAN_a8</span>, w, h, (<span style="color:rgb(195,89,0)">uint32_t</span>*)mask, w);</p>

<p style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px">    </p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(207,135,36)"><span style="color:rgb(0,0,0)">    </span>// do compositing</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(88,126,168)"><span style="color:rgb(0,0,0)">    </span>pixman_image_composite<span style="color:rgb(0,0,0)">(</span></p>
<p style="margin:0px;font-size:11px;font-family:Menlo">                           <span style="color:rgb(88,126,168)">PIXMAN_OP_OVER</span>,</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">                           pfill, pmask, ptarget,</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">                           <span style="color:rgb(207,135,36)">// src_x, src_y</span></p>
<p style="margin:0px;font-size:11px;font-family:Menlo">                           <span style="color:rgb(53,86,138)">0</span>, <span style="color:rgb(53,86,138)">0</span>,</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">                           <span style="color:rgb(207,135,36)">// mask_x, mask_y</span></p>
<p style="margin:0px;font-size:11px;font-family:Menlo">                           <span style="color:rgb(53,86,138)">0</span>, <span style="color:rgb(53,86,138)">0</span>,</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(207,135,36)"><span style="color:rgb(0,0,0)">                           </span>// dest_x, dest_y, width, height</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">                           <span style="color:rgb(53,86,138)">0</span>, <span style="color:rgb(53,86,138)">0</span>, w, h);</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px">    </p>
<p style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(207,135,36)"><span style="color:rgb(0,0,0)">    </span>// display one pixel of target</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">    <span style="color:rgb(88,126,168)">printf</span>(<span style="color:rgb(232,35,0)">"out: r=%02X g=%02X b=%02X a=%02X\n"</span>, </p><p style="margin:0px;font-size:11px;font-family:Menlo">
        target[<span style="color:rgb(53,86,138)">0</span>].<span style="color:rgb(88,126,168)">rgba</span>.<span style="color:rgb(88,126,168)">r</span>, target[<span style="color:rgb(53,86,138)">0</span>].<span style="color:rgb(88,126,168)">rgba</span>.<span style="color:rgb(88,126,168)">g</span>, target[<span style="color:rgb(53,86,138)">0</span>].<span style="color:rgb(88,126,168)">rgba</span>.<span style="color:rgb(88,126,168)">b</span>, target[<span style="color:rgb(53,86,138)">0</span>].<span style="color:rgb(88,126,168)">rgba</span>.<span style="color:rgb(88,126,168)">a</span>);</p>

<p style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px">}</p><p style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><br></p><p style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px">
<br></p></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-06-11 21:49 GMT+02:00 Søren Sandmann <span dir="ltr"><<a href="mailto:soren.sandmann@gmail.com" target="_blank">soren.sandmann@gmail.com</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">Eric Nicolas <<a href="mailto:erik.nicolas@gmail.com">erik.nicolas@gmail.com</a>> writes:<br>

<br>
> Hello,<br>
><br>
> I have a question about the OP modes when compositing with Pixman. I had a look at the source code, but this part of the code is quite complex, so I couldn’t find the answer there.<br>
><br>
> What I would like to do is :<br>
> -          Use a plain color via a pixman_image_create_solid_fill on a RGBA color ;<br>
> -          Use a PIXMAN_a8 mask ;<br>
> -          Modify a target PIXMAN_r8g8b8a8 image.<br>
> So I do a pixman_image_composite(OP, fill, mask, target, …).<br>
><br>
> My problem is that I cannot find an OP which would allow me to blend fill and mask together into target. I mean if ‘fill’ color has an alpha (for instance 0x80), mask is also an alpha (for instance 0x80), I expect the target to be blent with the color modified with an alpha of 0x40 (full fill color x mask alpha => blent to target).<br>

><br>
> The closest I found is PIXMAN_OP_ATOP, but it always use the RGB from<br>
> the fill color and the A from the mask, it never blends the color with<br>
> the mask before compositing onto the target.<br>
<br>
</div></div>The PIXMAN_OP_OVER operator used with a solid color, a PIXMAN_a8 mask<br>
and a PIXMAN_r8g8b8a8 target will multiply the fill color with the pixel<br>
from the a8 mask and then blend the result onto the target image.<br>
<br>
But maybe this is not what you want to do. If not, it might be helpful<br>
if you could post images showing what you would like to get, and what<br>
you are getting.<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
Søren<br>
</font></span></blockquote></div><br></div>