From c853ffb5b2f75f5a889ed2e3ef89b818a736e87a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 13:50:49 +0200 Subject: Adding upstream version 1.3+ds. Signed-off-by: Daniel Baumann --- src/ui/widget/canvas/util.h | 75 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/ui/widget/canvas/util.h (limited to 'src/ui/widget/canvas/util.h') diff --git a/src/ui/widget/canvas/util.h b/src/ui/widget/canvas/util.h new file mode 100644 index 0000000..c2c1ad3 --- /dev/null +++ b/src/ui/widget/canvas/util.h @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef INKSCAPE_UI_WIDGET_CANVAS_UTIL_H +#define INKSCAPE_UI_WIDGET_CANVAS_UTIL_H + +#include +#include <2geom/int-rect.h> +#include <2geom/affine.h> +#include +#include "color.h" + +namespace Inkscape { +namespace UI { +namespace Widget { + +// Cairo additions + +/** + * Turn a Cairo region into a path on a given Cairo context. + */ +void region_to_path(Cairo::RefPtr const &cr, Cairo::RefPtr const ®); + +/** + * Shrink a region by d/2 in all directions, while also translating it by (d/2 + t, d/2 + t). + */ +Cairo::RefPtr shrink_region(Cairo::RefPtr const ®, int d, int t = 0); + +inline auto unioned(Cairo::RefPtr a, Cairo::RefPtr const &b) +{ + a->do_union(b); + return a; +} + +// Colour operations + +inline auto rgb_to_array(uint32_t rgb) +{ + return std::array{SP_RGBA32_R_U(rgb) / 255.0f, SP_RGBA32_G_U(rgb) / 255.0f, SP_RGBA32_B_U(rgb) / 255.0f}; +} + +inline auto rgba_to_array(uint32_t rgba) +{ + return std::array{SP_RGBA32_R_U(rgba) / 255.0f, SP_RGBA32_G_U(rgba) / 255.0f, SP_RGBA32_B_U(rgba) / 255.0f, SP_RGBA32_A_U(rgba) / 255.0f}; +} + +inline auto premultiplied(std::array arr) +{ + arr[0] *= arr[3]; + arr[1] *= arr[3]; + arr[2] *= arr[3]; + return arr; +} + +std::array checkerboard_darken(std::array const &rgb, float amount = 1.0f); + +inline auto checkerboard_darken(uint32_t rgba) +{ + return checkerboard_darken(rgb_to_array(rgba), 1.0f - SP_RGBA32_A_U(rgba) / 255.0f); +} + +} // namespace Widget +} // namespace UI +} // namespace Inkscape + +#endif // INKSCAPE_UI_WIDGET_CANVAS_UTIL_H + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : -- cgit v1.2.3