1
/* ============================================================
2
* Author: Gilles Caulier <caulier dot gilles at free.fr>
4
* Description : image filters methods.
6
* Copyright 2004-2005 by Gilles Caulier
8
* This program is free software; you can redistribute it
9
* and/or modify it under the terms of the GNU General
10
* Public License as published by the Free Software Foundation;
11
* either version 2, or (at your option)
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* ============================================================ */
21
#ifndef IMAGE_FILTERS_H
22
#define IMAGE_FILTERS_H
34
private: // Private structures used internally.
46
unsigned short int red;
47
unsigned short int green;
48
unsigned short int blue;
49
unsigned short int alpha;
59
private: // Private methods used internally.
61
// Methods for Gaussian blur.
63
static inline int GetStride (int Width)
65
int LineWidth = Width * 4;
66
if (LineWidth % 4) return (4 - (LineWidth % 4));
70
// function to allocate a 2d array
71
static inline int** Alloc2DArray (int Columns, int Rows)
73
// First, we declare our future 2d array to be returned
74
int** lpcArray = NULL;
76
// Now, we alloc the main pointer with Columns
77
lpcArray = new int*[Columns];
79
for (int i = 0; i < Columns; i++)
80
lpcArray[i] = new int[Rows];
85
// Function to deallocates the 2d array previously created
86
static inline void Free2DArray (int** lpcArray, int Columns)
88
// loop to dealocate the columns
89
for (int i = 0; i < Columns; i++)
90
delete [] lpcArray[i];
92
// now, we delete the main pointer
96
static inline bool IsInside (int Width, int Height, int X, int Y)
98
bool bIsWOk = ((X < 0) ? false : (X >= Width ) ? false : true);
99
bool bIsHOk = ((Y < 0) ? false : (Y >= Height) ? false : true);
100
return (bIsWOk && bIsHOk);
103
// A color is represented in RGB value (e.g. 0xFFFFFF is white color).
104
// But R, G and B values has 256 values to be used so, this function analize
105
// the value and limits to this range.
106
static inline uchar LimitValues (int ColorValue)
108
if (ColorValue > 255) ColorValue = 255;
109
if (ColorValue < 0) ColorValue = 0;
110
return ((uchar) ColorValue);
113
// Methods for Channel mixer.
115
static inline double CalculateNorm(float RedGain, float GreenGain, float BlueGain, bool bPreserveLum)
117
double lfSum = RedGain + GreenGain + BlueGain;
119
if ((lfSum == 0.0) || (bPreserveLum == false))
122
return( fabs (1.0 / lfSum) );
125
static inline uchar MixPixel(float RedGain, float GreenGain, float BlueGain, uchar R, uchar G, uchar B, double Norm)
127
double lfMix = RedGain * (double)R + GreenGain * (double)G + BlueGain * (double)B;
130
if (lfMix > 255.0) return 255;
131
if (lfMix < 0) return 0;
132
return( (uchar)lfMix );
135
public: // Public methods.
137
static void equalizeImage(uint *data, int w, int h);
138
static void stretchContrastImage(uint *data, int w, int h);
139
static void normalizeImage(uint *data, int w, int h);
140
static void autoLevelsCorrectionImage(uint *data, int w, int h);
141
static void invertImage(uint *data, int w, int h);
142
static void smartBlurImage(uint *data, int Width, int Height);
143
static void gaussianBlurImage(uint *data, int Width, int Height, int Radius);
144
static void channelMixerImage(uint *data, int Width, int Height, bool bPreserveLum, bool bMonochrome,
145
float rrGain, float rgGain, float rbGain,
146
float grGain, float ggGain, float gbGain,
147
float brGain, float bgGain, float bbGain);
150
} // NameSpace Digikam
152
#endif /* IMAGE_FILTERS_H */