[cairo] dithering in cairo ?

Marc Jeanmougin marc at jeanmougin.fr
Tue Aug 13 13:04:05 UTC 2019


Hi,

I thought a bit more about this, and I think it would also be possible
(and maybe preferable) to pack several informations into cairo_format_t :

cairo_format_t is an enum (hence an int) so it would be possible to use
it to pack e.g. the dithering information in it, using the low bits with
their current value.

if we reserve 8 more possible "format" values for future use, it is
possible to add e.g.

CAIRO_FORMAT_T_FORMAT_MASK = 0x000f (4 bits)
CAIRO_FORMAT_T_DITHER_MASK = 0x00f0 (4 bits)
(and maybe CAIRO_FORMAT_T_FILTER_MASK = 0x0f00 (4 bits) (This would
change CAIRO_FILTER_{FAST .. GAUSSIAN} = {1..6} << 8))

This would allow directly creating a cairo_surface_t with the required
information for the backend, without breaking changes (current code
would still work, with an implied 0(NONE) for the packed values. The
only real change would be that if choosing to use new values in external
code, the test for invalid values would become "format < 0" instead of
"format == CAIRO_FORMAT_INVALID")

The additional changes to my previous changes would look like
https://gitlab.freedesktop.org/mc/cairo/commit/a822699dff1d1d47e840f1d706ff059e1dabb8bd
(clearly not finalized, but I wanted to get some feedback before
continuing).

Thanks for any answer,

-- 
Mc


Le 14/06/2019 à 17:53, Marc Jeanmougin a écrit :
> Hi all, 
>
> I'm interested in being able to create dithered images in Inkscape (it
> would be useful in a lot of other contexts).
>
> A dithering path has been recently added into pixman which makes it
> possible, but I'm struggling on what would be the best way :
>
> At first I thought that I could do the same as what is done with
> cairo_filter_t at the pattern level : "just"
> cairo_pattern_get/set_filter (
> https://gitlab.freedesktop.org/cairo/cairo/merge_requests/24/diffs?commit_id=730a268b90a60bf050b42505801bc6bc085af759
> ).
>
> However this seems to be not enough : when creating a
> cairo_image_surface with pixman format, the code directly creates the
> pixman_image but I get no direct access to it. I'm also not exactly sure
> what would happen with the surfaces created with push_group(). 
>
> I'm not sure where to go from here: I was thinking about either add a
> cairo_image_surface_get_pixman_image to let the user deal directly with
> it at the pixman level, or having something like
> pixman_image_surface_set_dither().
>
> Could you give me some advice on where to go from here?
>
> Thanks a lot,
>



More information about the cairo mailing list