From dfa3efdb4ebaef7ae79f64ade0e1555b326e5e8e Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Fri, 25 Jul 2025 16:41:53 +0900 Subject: [PATCH] api: polsih up the composition blending --- inc/thorvg.h | 12 ++++++------ src/renderer/tvgPaint.cpp | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/inc/thorvg.h b/inc/thorvg.h index af7c9407..2ff92564 100644 --- a/inc/thorvg.h +++ b/inc/thorvg.h @@ -209,13 +209,13 @@ enum class BlendMethod : uint8_t SoftLight, ///< The same as Overlay but with applying pure black or white does not result in pure black or white. (255 - 2 * S) * (D * D) + (2 * S * D) Difference, ///< Subtracts the bottom layer from the top layer or the other way around, to always get a non-negative value. (S - D) if (S > D), otherwise (D - S) Exclusion, ///< The result is twice the product of the top and bottom layers, subtracted from their sum. S + D - (2 * S * D) - Hue, ///< Combine with HSL(Sh + Ds + Dl) then convert it to RGB. - Saturation, ///< Combine with HSL(Dh + Ss + Dl) then convert it to RGB. - Color, ///< Combine with HSL(Sh + Ss + Dl) then convert it to RGB. - Luminosity, ///< Combine with HSL(Dh + Ds + Sl) then convert it to RGB. + Hue, ///< Combine with HSL(Sh + Ds + Dl) then convert it to RGB. @since 1.0 + Saturation, ///< Combine with HSL(Dh + Ss + Dl) then convert it to RGB. @since 1.0 + Color, ///< Combine with HSL(Sh + Ss + Dl) then convert it to RGB. @since 1.0 + Luminosity, ///< Combine with HSL(Dh + Ds + Sl) then convert it to RGB. @since 1.0 Add, ///< Simply adds pixel values of one layer with the other. (S + D) - HardMix, ///< Adds S and D; result is 255 if the sum is greater than or equal to 255, otherwise 0. - Composition = 255 ///< Used for intermediate composition. @since 1.0 + HardMix, ///< Adds S and D; result is 255 if the sum is greater than or equal to 255, otherwise 0. @since 1.0 + Composition = 255 ///< Used for intermediate composition. Only valid when applied to a Scene. @since 1.0 }; diff --git a/src/renderer/tvgPaint.cpp b/src/renderer/tvgPaint.cpp index 42ed7074..a2450373 100644 --- a/src/renderer/tvgPaint.cpp +++ b/src/renderer/tvgPaint.cpp @@ -429,7 +429,8 @@ uint8_t Paint::opacity() const noexcept Result Paint::blend(BlendMethod method) noexcept { - if (method <= BlendMethod::HardMix || method == BlendMethod::Composition) { + //Composition is only allowed to Scene. + if (method <= BlendMethod::HardMix || (method == BlendMethod::Composition && type() == Type::Scene)) { pImpl->blend(method); return Result::Success; }