~ubuntu-branches/ubuntu/edgy/digikam/edgy-updates

« back to all changes in this revision

Viewing changes to digikam/libs/filters/imagefilters.h

  • Committer: Bazaar Package Importer
  • Author(s): Achim Bohnet
  • Date: 2005-03-10 02:39:02 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050310023902-023nymfst5mg696c
Tags: 0.7.2-2
* debian/TODO: clean
* digikam manpage: better --detect-camera description

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ============================================================
 
2
 * Author: Gilles Caulier <caulier dot gilles at free.fr>
 
3
 * Date  : 2005-24-01
 
4
 * Description : image filters methods. 
 
5
 * 
 
6
 * Copyright 2004-2005 by Gilles Caulier
 
7
 *
 
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)
 
12
 * any later version.
 
13
 * 
 
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.
 
18
 * 
 
19
 * ============================================================ */
 
20
 
 
21
#ifndef IMAGE_FILTERS_H
 
22
#define IMAGE_FILTERS_H
 
23
 
 
24
// C++ includes.
 
25
 
 
26
#include <cmath>
 
27
 
 
28
namespace Digikam
 
29
{
 
30
 
 
31
class ImageFilters
 
32
{
 
33
 
 
34
private:    // Private structures used internally.
 
35
 
 
36
struct double_packet
 
37
    {
 
38
    double red;
 
39
    double green;
 
40
    double blue;
 
41
    double alpha;
 
42
    };
 
43
 
 
44
struct short_packet
 
45
    {
 
46
    unsigned short int red;
 
47
    unsigned short int green;
 
48
    unsigned short int blue;
 
49
    unsigned short int alpha;
 
50
    };
 
51
 
 
52
struct NormalizeParam 
 
53
    {
 
54
    uchar  lut[256];
 
55
    double min;
 
56
    double max;
 
57
    };
 
58
 
 
59
private:    // Private methods used internally.
 
60
    
 
61
    // Methods for Gaussian blur.   
 
62
    
 
63
    static inline int GetStride (int Width)
 
64
       { 
 
65
       int LineWidth = Width * 4;
 
66
       if (LineWidth % 4) return (4 - (LineWidth % 4)); 
 
67
       return (0); 
 
68
       };
 
69
 
 
70
    // function to allocate a 2d array   
 
71
    static inline int** Alloc2DArray (int Columns, int Rows)
 
72
       {
 
73
       // First, we declare our future 2d array to be returned
 
74
       int** lpcArray = NULL;
 
75
 
 
76
       // Now, we alloc the main pointer with Columns
 
77
       lpcArray = new int*[Columns];
 
78
        
 
79
       for (int i = 0; i < Columns; i++)
 
80
           lpcArray[i] = new int[Rows];
 
81
 
 
82
       return (lpcArray);
 
83
       }   
 
84
    
 
85
    // Function to deallocates the 2d array previously created
 
86
    static inline void Free2DArray (int** lpcArray, int Columns)
 
87
       {
 
88
       // loop to dealocate the columns
 
89
       for (int i = 0; i < Columns; i++)
 
90
           delete [] lpcArray[i];
 
91
 
 
92
       // now, we delete the main pointer
 
93
       delete [] lpcArray;
 
94
       }   
 
95
       
 
96
    static inline bool IsInside (int Width, int Height, int X, int Y)
 
97
       {
 
98
       bool bIsWOk = ((X < 0) ? false : (X >= Width ) ? false : true);
 
99
       bool bIsHOk = ((Y < 0) ? false : (Y >= Height) ? false : true);
 
100
       return (bIsWOk && bIsHOk);
 
101
       };       
 
102
 
 
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)
 
107
       {
 
108
       if (ColorValue > 255) ColorValue = 255;        
 
109
       if (ColorValue < 0) ColorValue = 0;
 
110
       return ((uchar) ColorValue);
 
111
       };        
 
112
       
 
113
    // Methods for Channel mixer.   
 
114
       
 
115
    static inline double CalculateNorm(float RedGain, float GreenGain, float BlueGain, bool bPreserveLum)
 
116
       {
 
117
       double lfSum = RedGain + GreenGain + BlueGain;
 
118
 
 
119
       if ((lfSum == 0.0) || (bPreserveLum == false))
 
120
           return (1.0);
 
121
 
 
122
       return( fabs (1.0 / lfSum) );
 
123
       }
 
124
 
 
125
    static inline uchar MixPixel(float RedGain, float GreenGain, float BlueGain, uchar R, uchar G, uchar B, double Norm)
 
126
       {
 
127
       double lfMix = RedGain * (double)R + GreenGain * (double)G + BlueGain * (double)B;
 
128
       lfMix *= Norm;
 
129
       
 
130
       if (lfMix > 255.0) return 255;        
 
131
       if (lfMix < 0) return 0;
 
132
       return( (uchar)lfMix );
 
133
       }       
 
134
 
 
135
public:   // Public methods.
 
136
 
 
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);
 
148
};
 
149
 
 
150
}  // NameSpace Digikam
 
151
 
 
152
#endif /* IMAGE_FILTERS_H */