~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to libs/dimg/filters/bcg/bcgfilter.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-12-21 23:19:11 UTC
  • mfrom: (1.2.33 upstream) (3.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20101221231911-z9jip7s5aht1jqn9
Tags: 2:1.7.0-1ubuntu1
* Merge from Debian Experimental. Remaining Ubuntu changes:
  - Export .pot name and copy to plugins in debian/rules
  - Version build-depends on kipi-plugins-dev to ensure build is against the
    same version on all archs
* Drop debian/patches/kubuntu_01_linker.diff, incoporated upstream
* Remove patches directory and unused patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
{
45
45
public:
46
46
 
47
 
    BCGFilterPriv(){}
 
47
    BCGFilterPriv() {}
48
48
 
49
49
    int          map16[65536];
50
50
    int          map[256];
53
53
};
54
54
 
55
55
BCGFilter::BCGFilter(DImg* orgImage, QObject* parent, const BCGContainer& settings)
56
 
         : DImgThreadedFilter(orgImage, parent, "BCGFilter"),
57
 
           d(new BCGFilterPriv)
 
56
    : DImgThreadedFilter(orgImage, parent, "BCGFilter"),
 
57
      d(new BCGFilterPriv)
58
58
{
59
59
    d->settings = settings;
60
60
    reset();
81
81
    val = (val < 0.01) ? 0.01 : val;
82
82
 
83
83
    for (int i=0; i<65536; ++i)
 
84
    {
84
85
        d->map16[i] = lround(pow(((double)d->map16[i] / 65535.0), (1.0 / val)) * 65535.0);
 
86
    }
85
87
 
86
88
    for (int i=0; i<256; ++i)
 
89
    {
87
90
        d->map[i] = lround(pow(((double)d->map[i] / 255.0), (1.0 / val)) * 255.0);
 
91
    }
88
92
}
89
93
 
90
94
void BCGFilter::setBrightness(double val)
92
96
    int val1 = lround(val * 65535);
93
97
 
94
98
    for (int i = 0; i < 65536; ++i)
 
99
    {
95
100
        d->map16[i] = d->map16[i] + val1;
 
101
    }
96
102
 
97
103
    val1 = lround(val * 255);
98
104
 
99
105
    for (int i = 0; i < 256; ++i)
 
106
    {
100
107
        d->map[i] = d->map[i] + val1;
 
108
    }
101
109
}
102
110
 
103
111
void BCGFilter::setContrast(double val)
104
112
{
105
113
    for (int i = 0; i < 65536; ++i)
 
114
    {
106
115
        d->map16[i] = lround((d->map16[i] - 32767) * val) + 32767;
 
116
    }
107
117
 
108
118
    for (int i = 0; i < 256; ++i)
 
119
    {
109
120
        d->map[i] = lround((d->map[i] - 127) * val) + 127;
 
121
    }
110
122
}
111
123
 
112
124
void BCGFilter::reset()
114
126
    // initialize to linear mapping
115
127
 
116
128
    for (int i=0; i<65536; ++i)
 
129
    {
117
130
        d->map16[i] = i;
 
131
    }
118
132
 
119
133
    for (int i=0; i<256; ++i)
 
134
    {
120
135
        d->map[i] = i;
 
136
    }
121
137
}
122
138
 
123
139
void BCGFilter::applyBCG(DImg& image)
124
140
{
125
 
    if (image.isNull()) return;
 
141
    if (image.isNull())
 
142
    {
 
143
        return;
 
144
    }
126
145
 
127
146
    applyBCG(image.bits(), image.width(), image.height(), image.sixteenBit());
128
147
}
129
148
 
130
149
void BCGFilter::applyBCG(uchar* bits, uint width, uint height, bool sixteenBits)
131
150
{
132
 
    if (!bits) return;
 
151
    if (!bits)
 
152
    {
 
153
        return;
 
154
    }
133
155
 
134
156
    uint size = width*height;
135
157
    int  progress;
164
186
            data += 4;
165
187
 
166
188
            progress = (int)(((double)i * 100.0) / size);
 
189
 
167
190
            if ( progress%5 == 0 )
 
191
            {
168
192
                postProgress( progress );
 
193
            }
169
194
        }
170
195
    }
171
196
    else                                        // 16 bits image.
198
223
            data += 4;
199
224
 
200
225
            progress = (int)(((double)i * 100.0) / size);
 
226
 
201
227
            if ( progress%5 == 0 )
 
228
            {
202
229
                postProgress( progress );
 
230
            }
203
231
        }
204
232
    }
205
233
}