~ubuntu-branches/ubuntu/maverick/digikam/maverick

« back to all changes in this revision

Viewing changes to imageplugins/localcontrast/ToneMappingFloat.h

  • Committer: Bazaar Package Importer
  • Author(s): Luka Renko
  • Date: 2009-12-22 21:38:14 UTC
  • mfrom: (1.2.26 upstream)
  • Revision ID: james.westby@ubuntu.com-20091222213814-dtgz0u1068y5rql7
Tags: 2:1.0.0-1ubuntu1
* Merge with Debian, remaining changes:
  - Export .pot name and copy to plugins in debian/rules
  - Build-depend on libkipi7-dev, libkexiv2-8-dev and 
    libkdcraw8-dev (KDE 4.3 -> 4.4)
* Build-depend on liblqr-1-0-dev: now in main (LP: #493508)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* ============================================================
2
 
 *
3
 
 * This file is a part of digiKam project
4
 
 * http://www.digikam.org
5
 
 *
6
 
 * Date        : 2009-08-09
7
 
 * Description : LDR ToneMapper <http://zynaddsubfx.sourceforge.net/other/tonemapping>.
8
 
 *
9
 
 * Copyright (C) 2009 by Nasca Octavian Paul <zynaddsubfx at yahoo dot com>
10
 
 * Copyright (C) 2009 by Gilles Caulier <caulier dot gilles at gmail dot com>
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 TONE_MAPPING_FLOAT_H
26
 
#define TONE_MAPPING_FLOAT_H
27
 
 
28
 
// Local includes.
29
 
 
30
 
#include "ToneMappingBase.h"
31
 
 
32
 
namespace DigikamLocalContrastImagesPlugin
33
 
{
34
 
 
35
 
class ToneMappingFloat : public ToneMappingBase
36
 
{
37
 
 
38
 
public:
39
 
 
40
 
    ToneMappingFloat();
41
 
    ~ToneMappingFloat();
42
 
 
43
 
    void process_8bit_rgb_image(unsigned char *img, int sizex, int sizey);
44
 
    void process_16bit_rgb_image(unsigned short int *img, int sizex, int sizey);
45
 
    void process_rgb_image(REALTYPE *img, int sizex, int sizey);
46
 
    void update_preprocessed_values();
47
 
 
48
 
private:
49
 
 
50
 
    void inplace_blur(REALTYPE *data, int sizex, int sizey, REALTYPE blur);
51
 
    void stretch_contrast(REALTYPE *data, int datasize);
52
 
 
53
 
    inline void rgb2hsv(const REALTYPE& r, const REALTYPE& g, const REALTYPE& b,
54
 
                        REALTYPE& h, REALTYPE& s, REALTYPE& v)
55
 
    {
56
 
        REALTYPE maxrg = (r>g) ? r : g;
57
 
        REALTYPE max   = (maxrg>b) ? maxrg : b;
58
 
 
59
 
        REALTYPE minrg = (r<g) ? r : g;
60
 
        REALTYPE min   = (minrg<b) ? minrg : b;
61
 
 
62
 
        REALTYPE delta = max-min;
63
 
 
64
 
        //hue
65
 
        if (min == max)
66
 
        {
67
 
            h = 0.0;
68
 
        }
69
 
        else
70
 
        {
71
 
            if (max == r)
72
 
            {
73
 
                h = (REALTYPE)(fmod(60.0*(g-b)/delta+360.0, 360.0));
74
 
            }
75
 
            else
76
 
            {
77
 
                if (max == g)
78
 
                {
79
 
                    h = (REALTYPE)(60.0*(b-r)/delta+120.0);
80
 
                }
81
 
                else
82
 
                {
83
 
                    //max==b
84
 
                    h = (REALTYPE)(60.0*(r-g)/delta+240.0);
85
 
                }
86
 
            }
87
 
        }
88
 
 
89
 
        //saturation
90
 
        if (max < 1e-6)
91
 
        {
92
 
            s = 0;
93
 
        }
94
 
        else
95
 
        {
96
 
            s = (REALTYPE)(1.0-min/max);
97
 
        }
98
 
 
99
 
        //value
100
 
        v = max;
101
 
    };
102
 
 
103
 
    inline void hsv2rgb(const REALTYPE& h, const REALTYPE& s, const REALTYPE& v,
104
 
                        REALTYPE& r, REALTYPE& g, REALTYPE& b)
105
 
    {
106
 
        REALTYPE hfi = (REALTYPE)(floor(h/60.0));
107
 
        REALTYPE f   = (REALTYPE)((h/60.0)-hfi);
108
 
        int hi       = ((int)hfi)%6;
109
 
 
110
 
        REALTYPE p   = (REALTYPE)(v*(1.0-s));
111
 
        REALTYPE q   = (REALTYPE)(v*(1.0-f*s));
112
 
        REALTYPE t   = (REALTYPE)(v*(1.0-(1.0-f)*s));
113
 
 
114
 
        switch (hi)
115
 
        {
116
 
            case 0:
117
 
                r = v ; g = t ; b = p;
118
 
                break;
119
 
            case 1:
120
 
                r = q ; g = v ; b = p;
121
 
                break;
122
 
            case 2:
123
 
                r = p ; g = v ; b = t;
124
 
                break;
125
 
            case 3:
126
 
                r = p ; g = q ; b = v;
127
 
                break;
128
 
            case 4:
129
 
                r = t ; g = p; b = v;
130
 
                break;
131
 
            case 5:
132
 
                r = v ; g = p ; b = q;
133
 
                break;
134
 
        }
135
 
    }
136
 
};
137
 
 
138
 
} // namespace DigikamNoiseReductionImagesPlugin
139
 
 
140
 
#endif // TONE_MAPPING_FLOAT_H