[cairo] Image Format / Pre-Multiplied Alpha Related Feature Request
William Kappler
wekapple at ncsu.edu
Wed Jan 27 19:25:42 PST 2016
Hello,
I am currently working on a 3D graphics/GUI project utilizing Cairo and
Pango, primarily for text rendering. However, I have run into an issue with
how Cairo handles its image data, and wanted to make a feature request
regarding that.
Currently, Cairo uses pre-multiplied alpha for CAIRO_FORMAT_ARGB32, which
is the only format currently supported combining color and alpha data. I
require the capability to have a full RGBA texel, but alpha
pre-multiplication presents several major issues for my use, or indeed any
use, of Cairo in 3D contexts:
- Most libraries, shaders, and users/programmers expect textures in 3D
contexts to be non-pre-multiplied. My system is no different – for various
reasons, I need to use standard independent alpha for textures not
generated by Cairo. I cannot easily include special handling of Cairo
textures to sidestep that as it would make texture handling needlessly
complex. I don't want to have to know which library the texture came from
in a GLSL shader.
- Reversing pre-multiplication is fairly simple, but still requires
special conversion functionality in my library.
- Conversion of texels introduces unnecessary texture write latency,
especially for large images.
- Most importantly, the dynamic range of the color is effectively
reduced to 256*(1-alpha%) values, even on back-converted texels. For nearly
transparent textures, this is especially problematic.
- A texel with independent alpha has 256 discrete values (counting
zero) per channel no matter its alpha
- A pre-multiplied alpha texel with 50% opacity only supports 128
discrete values per channel rounding issues make that even worse.
- Going down to 12.5% opacity, only 32 values are possible per
channel.
- All this makes grayscale images that might have low opacity, which
I expect I will use Pango-Cairo for fairly often, extremely poor quality.
As such, I would like to make a feature request that Cairo implement one of
the following:
- The option to turn off pre-multiplied alpha in the existing
CAIRO_FORMAT_ARGB32 format, without alpha reducing the range of possible
values in the format.
- A floating point image format, which would ease back-conversion of the
pre-multiplication and eliminate most of the dynamic range issues.
- An extended size integer format, such as 32 bits per channel ARGB /
128 total, which would eliminate the dynamic range issues.
I’d prefer the options in that order, with the simple ability to turn off
premult the best from where I stand, but any would solve my problem and I
would be extremely appreciative if any could be implemented.
Thank you in advance for any assistance you might offer. If desired I can
help implement this change, but I have no prior experience with the
internals of Cairo, only experience with my usage of it thus far.
:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-
William E. Kappler II
LinkedIn <https://www.linkedin.com/in/williamkappler> · Blog
<http://williamkappler.blogspot.com/> · Project Website
<https://github.com/WilliamKappler/onathacar/wiki>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20160127/e0cf3dcd/attachment.html>
More information about the cairo
mailing list