<br><br><div class="gmail_quote">On Tue, Sep 25, 2012 at 10:07 AM, Dmitry Kazakov <span dir="ltr"><<a href="mailto:dimula73@gmail.com" target="_blank">dimula73@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi!<br><br>I started fixing the grayscale selections problem yesterday. We've discussed the details of it several times already, so I'll try not to write too much. So, the working solution is the following:<br><br>

1) Every paint device has an additional method paintingColorSpace(). This method tells the painting tools which colorspace they should use for their dabs.<br>2) Some KoCompositeOp's have an ability to work cross-colorspace, that is with the source in one colorspace and the destination in the other. The alpha8 colorspace has such compositeOps. The methods are:<br>

<br>    /**<br>     * Returns true if the composite op can write pixels into the parent<br>     * colorspace from a colorspace \p srcSpace. If this function returns<br>     * true, then a special method<br>     * composite(const ParameterInfo&, const KoColorSpace*)<br>

     * becomes available to the user. Otherwise the CS should be<br>     * converted before calling a usual composite() method<br>     *<br>     * \see composite(const ParameterInfo&, const KoColorSpace*)<br>     */<br>

    virtual bool supportsCrossColorspaceComposition(const KoColorSpace* srcSpace) const;<br><br>    /**<br>     * Composes pixels from any arbitrary colorspace \p srcSpace<br>     * to the destination buffer. It is available only in case<br>

     * supportsCrossColorspaceComposition() returns true<br>     */<br>    virtual void composite(const ParameterInfo& params, const KoColorSpace* srcSpace) const;<br><br>3) The selection nodes still keeps the alpha8 colorspace for their paint devices, but return a grayscale8 colorspace as their painting colorspace. In a result, the bitBlt operation for the dabs will convert the pixels right.<br>

<br>The only trouble I see here is that in all the paintOps I'll have to change device()->colorSpace() to device->paintingColorSpace(), which is quite doable.<br><br>So what do you think of it?</blockquote><div>
<br></div><div>If we make a few assumptions that:</div><div>-source and destination colorspace are the same colorspace, except that the destination doesn't have the alpha channel</div><div>-source alpha is the last channel so RGBA</div>
<div><br></div><div>it could be done in the composite op. We add another method like "compositeWithAlphaToNoAlpha" that would work like the current one, just pretend that it read full opacity from the destination. Then it would simply composite the color channels in the colorspace that doesn't have alpha with passing the alpha it calculated. With the alpha at the end it's sure the the no-alpha colorspace will never read into the alpha while compositing. Then it just needs to advance source by color + alpha size and destination with color size and start again.</div>
<div><br></div><div>As most composite ops are based on KoCompositeOpAlphaBase anyway only very few composite ops (for the default ops it't alpha darken, copy, and erase) need some additinal code. </div></div>