~ubuntu-branches/ubuntu/intrepid/digikam/intrepid

« back to all changes in this revision

Viewing changes to digikam/utilities/imageeditor/imageiface.h

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2008-07-17 20:25:39 UTC
  • mfrom: (1.3.2 upstream) (37 hardy)
  • mto: This revision was merged to the branch mainline in revision 39.
  • Revision ID: james.westby@ubuntu.com-20080717202539-1bw3w3nrsso7yj4z
* New upstream release
  - digiKam 0.9.4 Release Plan (KDE3) ~ 13 July 08 (Closes: #490144)
* DEB_CONFIGURE_EXTRA_FLAGS := --without-included-sqlite3
* Debhelper compatibility level V7
* Install pixmaps in debian/*.install
* Add debian/digikam.lintian-overrides

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* ============================================================
2
 
 * Author: Renchi Raju <renchi@pooh.tam.uiuc.edu>
3
 
 * Date  : 2004-02-14
4
 
 * Description : 
5
 
 * 
6
 
 * Copyright 2004 by Renchi Raju
7
 
 *
8
 
 * Includes code from gimp version 2.0  
9
 
 * LIBGIMP - The GIMP Library
10
 
 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
11
 
 * 
12
 
 * This program is free software; you can redistribute it
13
 
 * and/or modify it under the terms of the GNU General
14
 
 * Public License as published by the Free Software Foundation;
15
 
 * either version 2, or (at your option)
16
 
 * any later version.
17
 
 * 
18
 
 * This program is distributed in the hope that it will be useful,
19
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 
 * GNU General Public License for more details.
22
 
 * 
23
 
 * ============================================================ */
24
 
 
25
 
#ifndef IMAGEIFACE_H
26
 
#define IMAGEIFACE_H
27
 
 
28
 
#include <qglobal.h>
29
 
#include <klocale.h>
30
 
#include "digikam_export.h"
31
 
#define MAX3(a, b, c) (QMAX(QMAX(a,b),b))
32
 
#define MIN3(a, b, c) (QMIN(QMIN(a,b),b))
33
 
#define ROUND(x) ((int) ((x) + 0.5))
34
 
 
35
 
class QPaintDevice;
36
 
class QString;
37
 
 
38
 
namespace Digikam
39
 
{
40
 
 
41
 
class ImageIfacePriv;
42
 
 
43
 
class DIGIKAMIMAGEEDITOR_EXPORT ImageIface
44
 
{
45
 
public:
46
 
 
47
 
    ImageIface(int w=0, int h=0);
48
 
    ~ImageIface();
49
 
 
50
 
    uint* getPreviewData();
51
 
    uint* getOriginalData();
52
 
    uint* getSelectedData();
53
 
 
54
 
    void  putPreviewData(uint* data);
55
 
    void  putOriginalData(const QString &caller, uint* data, int w=-1, int h=-1);
56
 
    void  putSelectedData(uint* data);
57
 
 
58
 
    int   previewWidth();
59
 
    int   previewHeight();
60
 
    uint* setPreviewSize(int w, int h);
61
 
 
62
 
    int  originalWidth();
63
 
    int  originalHeight();
64
 
 
65
 
    // Get selected dimensions.
66
 
    int  selectedWidth();
67
 
    int  selectedHeight();
68
 
    
69
 
    // Get selected (X, Y) position on the top/left corner.
70
 
    int  selectedXOrg();
71
 
    int  selectedYOrg();
72
 
        
73
 
    void setPreviewBCG(double brightness, double contrast, double gamma);
74
 
    void setOriginalBCG(double brightness, double contrast, double gamma);
75
 
    
76
 
    void paint(QPaintDevice* device, int x, int y, int w, int h);
77
 
    
78
 
private:
79
 
 
80
 
    ImageIfacePriv* d;
81
 
};
82
 
 
83
 
 
84
 
inline static int hsl_value (double n1,
85
 
                      double n2,
86
 
                      double hue)
87
 
{
88
 
    double value;
89
 
 
90
 
    if (hue > 255)
91
 
        hue -= 255;
92
 
    else if (hue < 0)
93
 
        hue += 255;
94
 
 
95
 
    if (hue < 42.5)
96
 
        value = n1 + (n2 - n1) * (hue / 42.5);
97
 
    else if (hue < 127.5)
98
 
        value = n2;
99
 
    else if (hue < 170)
100
 
        value = n1 + (n2 - n1) * ((170 - hue) / 42.5);
101
 
    else
102
 
        value = n1;
103
 
 
104
 
    return ROUND(value * 255.0);
105
 
}
106
 
 
107
 
inline static void rgb_to_hsl (int& r, int& g, int& b)
108
 
{
109
 
    double h, s, l;
110
 
    int    min, max;
111
 
    int    delta;
112
 
 
113
 
    if (r > g)
114
 
    {
115
 
        max = QMAX (r, b);
116
 
        min = QMIN (g, b);
117
 
    }
118
 
    else
119
 
    {
120
 
        max = QMAX (g, b);
121
 
        min = QMIN (r, b);
122
 
    }
123
 
 
124
 
    l = (max + min) / 2.0;
125
 
 
126
 
    if (max == min)
127
 
    {
128
 
        s = 0.0;
129
 
        h = 0.0;
130
 
    }
131
 
    else
132
 
    {
133
 
        delta = (max - min);
134
 
 
135
 
        if (l < 128)
136
 
            s = 255 * (double) delta / (double) (max + min);
137
 
        else
138
 
            s = 255 * (double) delta / (double) (511 - max - min);
139
 
 
140
 
        if (r == max)
141
 
            h = (g - b) / (double) delta;
142
 
        else if (g == max)
143
 
            h = 2 + (b - r) / (double) delta;
144
 
        else
145
 
            h = 4 + (r - g) / (double) delta;
146
 
 
147
 
        h = h * 42.5;
148
 
 
149
 
        if (h < 0)
150
 
            h += 255;
151
 
        else if (h > 255)
152
 
            h -= 255;
153
 
    }
154
 
 
155
 
    r = ROUND (h);
156
 
    g = ROUND (s);
157
 
    b = ROUND (l);
158
 
}
159
 
 
160
 
 
161
 
inline static void hsl_to_rgb (int& hue, int& saturation, int& lightness)
162
 
{
163
 
    double h, s, l;
164
 
 
165
 
    h = hue;
166
 
    s = saturation;
167
 
    l = lightness;
168
 
 
169
 
    if (s == 0)
170
 
    {
171
 
        /*  achromatic case  */
172
 
        hue        = (int) l;
173
 
        lightness  = (int) l;
174
 
        saturation = (int) l;
175
 
    }
176
 
    else
177
 
    {
178
 
        double m1, m2;
179
 
 
180
 
        if (l < 128)
181
 
            m2 = (l * (255 + s)) / 65025.0;
182
 
        else
183
 
            m2 = (l + s - (l * s) / 255.0) / 255.0;
184
 
 
185
 
        m1 = (l / 127.5) - m2;
186
 
 
187
 
        /*  chromatic case  */
188
 
        hue        = hsl_value (m1, m2, h + 85);
189
 
        saturation = hsl_value (m1, m2, h);
190
 
        lightness  = hsl_value (m1, m2, h - 85);
191
 
    }
192
 
}
193
 
 
194
 
 
195
 
inline static int rgb_to_l (int red, int green, int blue)
196
 
{
197
 
    int min, max;
198
 
 
199
 
    if (red > green)
200
 
    {
201
 
        max = QMAX (red,   blue);
202
 
        min = QMIN (green, blue);
203
 
    }
204
 
    else
205
 
    {
206
 
        max = QMAX (green, blue);
207
 
        min = QMIN (red,   blue);
208
 
    }
209
 
 
210
 
    return ROUND ((max + min) / 2.0);
211
 
}
212
 
 
213
 
 
214
 
}
215
 
 
216
 
#endif /* IMAGEIFACE_H */