[cairo] Image Format / Pre-Multiplied Alpha Related Feature Request

William Kappler wekapple at ncsu.edu
Sat Jan 30 14:20:30 PST 2016


Thanks for that suggestion. I will give it a try if I notice transition
distortions due to the pre-mult. Although, I think if there's a chance of
at some point getting some sort of floating point format, I will just keep
directly converting the pre-multiplied values until then; my library won't
be ready for release for a good while.


:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-
William E. Kappler II
LinkedIn <https://www.linkedin.com/in/williamkappler> · Blog
<http://williamkappler.blogspot.com/> · Project Website
<https://github.com/WilliamKappler/onathacar/wiki>

On Thu, Jan 28, 2016 at 6:12 PM, Lawrence D'Oliveiro <
ldo at geek-central.gen.nz> wrote:

> On Thu, 28 Jan 2016 17:18:04 -0500, William Kappler wrote:
>
> > perhaps I could render color without alpha and then alpha on its own,
> > and just blend the data together on my end.
>
> Try oversampling.
>
> Say you want to create an image that is m × n pixels. Create it at,
> say, 2m x 2n pixels instead. Undo the premultiplied alpha, then add
> each square grouping of 2 × 2 pixel values into a new, deeper pixel
> value, creating an image at m × n pixels.
>
> Each original pixel component value in CAIRO_FORMAT_ARGB32 format is 8
> bits, with a range of 0..255. Adding together 4 of these gives a range
> of 0..1020; replicate the top 2 bits into the bottom 2 to extend the
> dynamic range to 0..1023. This gives you an effective bit depth of log₂
> 1021 ≅ 10 bits. Even if not all 8 bits were meaningful to begin with
> (e.g. because of rounding caused by the original premultiplied alpha),
> you still gain log₂ 1021 - 8 ≅ 2 extra bits regardless.
>
> If that’s not enough, you can try starting with a 4m × 4n image, and
> add together groupings of 4 × 4 pixels to end up with a maximum of log₂
> 4081 ≅ 12 bits per pixel component at m × n resolution. Here you
> replicate the top 4 bits into the bottom 4 bits to extend the 0..4080
> dynamic range to 0..4095. And again, even if not all the bits are
> meaningful, you still gain log₂ 4081 - 8 ≅ 4 extra bits per pixel
> component.
>
> That’s oversampling in a nutshell.
> --
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20160130/6ba90f54/attachment.html>


More information about the cairo mailing list