summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Dennedy <dan@dennedy.org>2015-07-19 17:52:16 (GMT)
committer Dan Dennedy <dan@dennedy.org>2015-07-19 17:52:16 (GMT)
commitd206609b52fbdbb23cb086b04ae1698f9021b73f (patch)
treed19ea98bdd2360dc60bf977fd76ac708c5c9e23b
parentbaa08d27193d758b5139dfa503dbedc881298f1c (diff)
Factor out redefinitions of CLAMP0255.
-rw-r--r--src/filter/cluster/cluster.c9
-rw-r--r--src/filter/edgeglow/edgeglow.cpp9
-rw-r--r--src/filter/equaliz0r/equaliz0r.cpp9
-rw-r--r--src/filter/hueshift0r/matrix.h8
-rw-r--r--src/filter/sobel/sobel.cpp9
5 files changed, 5 insertions, 39 deletions
diff --git a/src/filter/cluster/cluster.c b/src/filter/cluster/cluster.c
index e77b133..b4a13ad 100644
--- a/src/filter/cluster/cluster.c
+++ b/src/filter/cluster/cluster.c
@@ -24,6 +24,7 @@
#include <stdio.h>
#include "frei0r.h"
+#include "frei0r_math.h"
#define MAXNUM 40
@@ -64,14 +65,6 @@ typedef struct cluster_instance
int initted;
} cluster_instance_t;
-/* Clamps a int32-range int between 0 and 255 inclusive. */
-unsigned char CLAMP0255(int32_t a)
-{
- return (unsigned char)
- ( (((-a) >> 31) & a) // 0 if the number was negative
- | (255 - a) >> 31); // -1 if the number was greater than 255
-}
-
int f0r_init()
{
diff --git a/src/filter/edgeglow/edgeglow.cpp b/src/filter/edgeglow/edgeglow.cpp
index deb66ca..f0c0eb6 100644
--- a/src/filter/edgeglow/edgeglow.cpp
+++ b/src/filter/edgeglow/edgeglow.cpp
@@ -18,16 +18,9 @@
*/
#include "frei0r.hpp"
+#include "frei0r_math.h"
#include <stdlib.h>
-/* Clamps a int32-range int between 0 and 255 inclusive. */
-unsigned char CLAMP0255(int32_t a)
-{
- return (unsigned char)
- ( (((-a) >> 31) & a) // 0 if the number was negative
- | (255 - a) >> 31); // -1 if the number was greater than 255
-}
-
class edgeglow : public frei0r::filter
{
public:
diff --git a/src/filter/equaliz0r/equaliz0r.cpp b/src/filter/equaliz0r/equaliz0r.cpp
index b9c6354..b4eae1e 100644
--- a/src/filter/equaliz0r/equaliz0r.cpp
+++ b/src/filter/equaliz0r/equaliz0r.cpp
@@ -18,18 +18,11 @@
*/
#include "frei0r.hpp"
+#include "frei0r_math.h"
#include <string.h>
#include <cstring>
-/* Clamps a int32-range int between 0 and 255 inclusive. */
-unsigned char CLAMP0255(int32_t a)
-{
- return (unsigned char)
- ( (((-a) >> 31) & a) // 0 if the number was negative
- | (255 - a) >> 31); // -1 if the number was greater than 255
-}
-
class equaliz0r : public frei0r::filter
{
// Look-up tables for equaliz0r values.
diff --git a/src/filter/hueshift0r/matrix.h b/src/filter/hueshift0r/matrix.h
index 10092aa..7d52ab9 100644
--- a/src/filter/hueshift0r/matrix.h
+++ b/src/filter/hueshift0r/matrix.h
@@ -7,6 +7,7 @@
*
* Paul Haeberli - 1993
*/
+#include "frei0r_math.h"
#include <math.h>
#include <stdio.h>
@@ -27,13 +28,6 @@
#define OFFSET_B 2
#define OFFSET_A 3
-unsigned char CLAMP0255(int32_t a)
-{
- return (unsigned char)
- ( (((-a) >> 31) & a) // 0 if the number was negative
- | (255 - a) >> 31); // -1 if the number was greater than 255
-}
-
/*
* printmat -
* print a 4 by 4 matrix
diff --git a/src/filter/sobel/sobel.cpp b/src/filter/sobel/sobel.cpp
index f0f2961..60c5020 100644
--- a/src/filter/sobel/sobel.cpp
+++ b/src/filter/sobel/sobel.cpp
@@ -18,16 +18,9 @@
*/
#include "frei0r.hpp"
+#include "frei0r_math.h"
#include <stdlib.h>
-/* Clamps a int32-range int between 0 and 255 inclusive. */
-unsigned char CLAMP0255(int32_t a)
-{
- return (unsigned char)
- ( (((-a) >> 31) & a) // 0 if the number was negative
- | (255 - a) >> 31); // -1 if the number was greater than 255
-}
-
class sobel : public frei0r::filter
{
public: