1
/* ============================================================
3
* This file is a part of digiKam project
4
* http://www.digikam.org
7
* Description : LDR ToneMapper <http://zynaddsubfx.sourceforge.net/other/tonemapping>.
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>
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)
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.
23
* ============================================================ */
25
#ifndef TONE_MAPPING_FLOAT_H
26
#define TONE_MAPPING_FLOAT_H
30
#include "ToneMappingBase.h"
32
namespace DigikamLocalContrastImagesPlugin
35
class ToneMappingFloat : public ToneMappingBase
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();
50
void inplace_blur(REALTYPE *data, int sizex, int sizey, REALTYPE blur);
51
void stretch_contrast(REALTYPE *data, int datasize);
53
inline void rgb2hsv(const REALTYPE& r, const REALTYPE& g, const REALTYPE& b,
54
REALTYPE& h, REALTYPE& s, REALTYPE& v)
56
REALTYPE maxrg = (r>g) ? r : g;
57
REALTYPE max = (maxrg>b) ? maxrg : b;
59
REALTYPE minrg = (r<g) ? r : g;
60
REALTYPE min = (minrg<b) ? minrg : b;
62
REALTYPE delta = max-min;
73
h = (REALTYPE)(fmod(60.0*(g-b)/delta+360.0, 360.0));
79
h = (REALTYPE)(60.0*(b-r)/delta+120.0);
84
h = (REALTYPE)(60.0*(r-g)/delta+240.0);
96
s = (REALTYPE)(1.0-min/max);
103
inline void hsv2rgb(const REALTYPE& h, const REALTYPE& s, const REALTYPE& v,
104
REALTYPE& r, REALTYPE& g, REALTYPE& b)
106
REALTYPE hfi = (REALTYPE)(floor(h/60.0));
107
REALTYPE f = (REALTYPE)((h/60.0)-hfi);
108
int hi = ((int)hfi)%6;
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));
117
r = v ; g = t ; b = p;
120
r = q ; g = v ; b = p;
123
r = p ; g = v ; b = t;
126
r = p ; g = q ; b = v;
129
r = t ; g = p; b = v;
132
r = v ; g = p ; b = q;
138
} // namespace DigikamNoiseReductionImagesPlugin
140
#endif // TONE_MAPPING_FLOAT_H