~kiko/pixman/trunk

« back to all changes in this revision

Viewing changes to pixman/pixman-image.c

  • Committer: Bryce Harrington
  • Author(s): Basile Clement
  • Date: 2019-05-25 14:29:55 UTC
  • Revision ID: git-v1:ddcc41b999562efdd9f88daa51ffbf39782748b5
Implement basic dithering for the wide pipeline, v3

This patch implements dithering in pixman.  A "dither" property is added
to BITS images, which is used to:

 - Force rendering to the image to go through the floating point
   pipeline.  Note that this is different from FAST_PATH_NARROW_FORMAT
   as it should not enable the floating point pipeline when reading from
   the image.

 - Enable dithering in dest_write_back_wide.  The dithering uses the
   destination format to determine noise amplitude.

This does not change pixman's behavior when dithering is disabled (the
default).

Additional types and functions are added to the public API:

 - The `pixman_dither_t` enum exposes the available dithering methods.
   Currently a single dithering method based on 8x8 Bayer matrices is
   implemented (PIXMAN_DITHER_ORDERED_BAYER_8).  The PIXMAN_DITHER_FAST,
   PIXMAN_DITHER_GOOD and PIXMAN_DITHER_BEST aliases are provided and
   should be used to benefit from future specializations.

 - The `pixman_image_set_dither` function allows to set the dithering
   method to use when rendering to a bits image.

 - The `pixman_image_set_dither_offset` function allows to set a
   vertical and horizontal offsets for the dither matrix.  This can be
   used after scrolling to ensure a consistent spatial positioning of
   the dither matrix.

Changes since previous version (v2):
 - linear_gradient_is_horizontal optimization is still compatible with
   the wide pipeline.  The code disabling it was a remnant of a previous
   patch which performed dithering directly inside linear_get_scanline,
   and thus needed to be called independently for each scanline.

Changes since v1:
 - Renamed PIXMAN_DITHER_BAYER_8 to PIXMAN_DITHER_ORDERED_BAYER_8
 - Disable dithering for channels with 32bpp or more (since they can
   represent exactly the wide values already).  This makes the patches
   compatible with the newly added floating point format.

Dithering is compatible with linear_gradient_is_horizontal

Show diffs side-by-side

added added

removed removed

Lines of Context:
684
684
    image_property_changed (image);
685
685
}
686
686
 
 
687
PIXMAN_EXPORT void
 
688
pixman_image_set_dither (pixman_image_t *image,
 
689
                         pixman_dither_t dither)
 
690
{
 
691
    if (image->type == BITS)
 
692
    {
 
693
        if (image->bits.dither == dither)
 
694
            return;
 
695
 
 
696
        image->bits.dither = dither;
 
697
 
 
698
        image_property_changed (image);
 
699
    }
 
700
}
 
701
 
 
702
PIXMAN_EXPORT void
 
703
pixman_image_set_dither_offset (pixman_image_t *image,
 
704
                                int             offset_x,
 
705
                                int             offset_y)
 
706
{
 
707
    if (image->type == BITS)
 
708
    {
 
709
        if (image->bits.dither_offset_x == offset_x &&
 
710
            image->bits.dither_offset_y == offset_y)
 
711
        {
 
712
            return;
 
713
        }
 
714
 
 
715
        image->bits.dither_offset_x = offset_x;
 
716
        image->bits.dither_offset_y = offset_y;
 
717
 
 
718
        image_property_changed (image);
 
719
    }
 
720
}
 
721
 
687
722
PIXMAN_EXPORT pixman_bool_t
688
723
pixman_image_set_filter (pixman_image_t *      image,
689
724
                         pixman_filter_t       filter,