1 #ifndef __NR_FILTER_UTILS_H__
2 #define __NR_FILTER_UTILS_H__
4 /** \file
5 * filter utils. Definition of functions needed by several filters.
6 *
7 * Authors:
8 * Jean-Rene Reinhard <jr@komite.net>
9 *
10 * Copyright (C) 2007 authors
11 *
12 * Released under GNU GPL, read the file 'COPYING' for more information
13 */
15 #include "round.h"
17 /* Shouldn't these be inlined? */
18 namespace NR {
20 /**
21 * Clamps an integer value to a value between 0 and 255. Needed by filters where
22 * rendering computations can lead to component values out of bound.
23 *
24 * \return 0 if the value is smaller than 0, 255 if it is greater 255, else v
25 * \param v the value to clamp
26 */
27 int clamp(int const val);
29 /**
30 * Clamps an integer value to a value between 0 and 255^3.
31 *
32 * \return 0 if the value is smaller than 0, 255^3 (16581375) if it is greater than 255^3, else v
33 * \param v the value to clamp
34 */
35 int clamp3(int const val);
37 /**
38 * Macro to use the clamp function with double inputs and unsigned char output
39 */
40 #define CLAMP_D_TO_U8(v) (unsigned char) clamp((int)round((v)))
42 /**
43 * Clamps an integer to a value between 0 and alpha. Useful when handling
44 * images with premultiplied alpha, as setting some of RGB channels
45 * to a value bigger than alpha confuses the alpha blending in Inkscape
46 * \return 0 if val is negative, alpha if val is bigger than alpha, val otherwise
47 * \param val the value to clamp
48 * \param alpha the maximum value to clamp to
49 */
50 int clamp_alpha(int const val, int const alpha);
52 } /* namespace NR */
54 #endif /* __NR_FILTER_UTILS_H__ */
55 /*
56 Local Variables:
57 mode:c++
58 c-file-style:"stroustrup"
59 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
60 indent-tabs-mode:nil
61 fill-column:99
62 End:
63 */
64 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :