From 9e48bcf8c4a1baf69228357a2921b48a6bb72b93 Mon Sep 17 00:00:00 2001 From: tavmjong Date: Sat, 6 Oct 2007 19:58:48 +0000 Subject: [PATCH] Composite Filter: Handle negative K's in Arithmetic mode. --- src/display/nr-filter-composite.cpp | 8 ++++---- src/display/nr-filter-utils.cpp | 6 ++++++ src/display/nr-filter-utils.h | 9 +++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/display/nr-filter-composite.cpp b/src/display/nr-filter-composite.cpp index a5b1d5297..29207b6b9 100644 --- a/src/display/nr-filter-composite.cpp +++ b/src/display/nr-filter-composite.cpp @@ -73,13 +73,13 @@ static int arith_k1, arith_k2, arith_k3, arith_k4; inline void composite_arithmetic(unsigned char *r, unsigned char const *a, unsigned char const *b) { - r[0] = NR::clamp(NR_NORMALIZE_31(arith_k1 * a[0] * b[0] + r[0] = NR_NORMALIZE_31(NR::clamp3(arith_k1 * a[0] * b[0] + arith_k2 * a[0] + arith_k3 * b[0] + arith_k4)); - r[1] = NR::clamp(NR_NORMALIZE_31(arith_k1 * a[1] * b[1] + r[1] = NR_NORMALIZE_31(NR::clamp3(arith_k1 * a[1] * b[1] + arith_k2 * a[1] + arith_k3 * b[1] + arith_k4)); - r[2] = NR::clamp(NR_NORMALIZE_31(arith_k1 * a[2] * b[2] + r[2] = NR_NORMALIZE_31(NR::clamp3(arith_k1 * a[2] * b[2] + arith_k2 * a[2] + arith_k3 * b[2] + arith_k4)); - r[3] = NR::clamp(NR_NORMALIZE_31(arith_k1 * a[3] * b[3] + r[3] = NR_NORMALIZE_31(NR::clamp3(arith_k1 * a[3] * b[3] + arith_k2 * a[3] + arith_k3 * b[3] + arith_k4)); } diff --git a/src/display/nr-filter-utils.cpp b/src/display/nr-filter-utils.cpp index 52c8ecc7d..ddd41298c 100644 --- a/src/display/nr-filter-utils.cpp +++ b/src/display/nr-filter-utils.cpp @@ -8,6 +8,12 @@ int clamp(int const val) { return val; } +int clamp3(int const val) { + if (val < 0) return 0; + if (val > 16581375) return 16581375; + return val; +} + int clamp_alpha(int const val, int const alpha) { if (val < 0) return 0; if (val > alpha) return alpha; diff --git a/src/display/nr-filter-utils.h b/src/display/nr-filter-utils.h index 5ac6fa5ab..91c295e94 100644 --- a/src/display/nr-filter-utils.h +++ b/src/display/nr-filter-utils.h @@ -14,6 +14,7 @@ #include "round.h" +/* Shouldn't these be inlined? */ namespace NR { /** @@ -25,6 +26,14 @@ namespace NR { */ int clamp(int const val); +/** + * Clamps an integer value to a value between 0 and 255^3. + * + * \return 0 if the value is smaller than 0, 255^3 (16581375) if it is greater than 255^3, else v + * \param v the value to clamp + */ +int clamp3(int const val); + /** * Macro to use the clamp function with double inputs and unsigned char output */ -- 2.30.2