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

« back to all changes in this revision

Viewing changes to libs/dimg/filters/cb/cbfilter.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:
43
43
{
44
44
public:
45
45
 
46
 
    CBFilterPriv(){}
 
46
    CBFilterPriv() {}
47
47
 
48
48
    int         redMap[256];
49
49
    int         greenMap[256];
59
59
};
60
60
 
61
61
CBFilter::CBFilter(DImg* orgImage, QObject* parent, const CBContainer& settings)
62
 
        : DImgThreadedFilter(orgImage, parent, "CBFilter"),
63
 
          d(new CBFilterPriv)
 
62
    : DImgThreadedFilter(orgImage, parent, "CBFilter"),
 
63
      d(new CBFilterPriv)
64
64
{
65
65
    d->settings = settings;
66
66
    reset();
108
108
        for (int i = 0; i < 256; ++i)
109
109
        {
110
110
            if (redMap)
 
111
            {
111
112
                d->redMap[i]   = redMap[i];
 
113
            }
 
114
 
112
115
            if (greenMap)
 
116
            {
113
117
                d->greenMap[i] = greenMap[i];
 
118
            }
 
119
 
114
120
            if (blueMap)
 
121
            {
115
122
                d->blueMap[i]  = blueMap[i];
 
123
            }
 
124
 
116
125
            if (alphaMap)
 
126
            {
117
127
                d->alphaMap[i] = alphaMap[i];
 
128
            }
118
129
        }
119
130
    }
120
131
    else
122
133
        for (int i = 0; i < 65536; ++i)
123
134
        {
124
135
            if (redMap)
 
136
            {
125
137
                d->redMap16[i]   = redMap[i];
 
138
            }
 
139
 
126
140
            if (greenMap)
 
141
            {
127
142
                d->greenMap16[i] = greenMap[i];
 
143
            }
 
144
 
128
145
            if (blueMap)
 
146
            {
129
147
                d->blueMap16[i]  = blueMap[i];
 
148
            }
 
149
 
130
150
            if (alphaMap)
 
151
            {
131
152
                d->alphaMap16[i] = alphaMap[i];
 
153
            }
132
154
        }
133
155
    }
134
156
}
138
160
    if (!sixteenBit)
139
161
    {
140
162
        if (redMap)
 
163
        {
141
164
            memcpy(redMap, d->redMap, (256 * sizeof(int)));
 
165
        }
 
166
 
142
167
        if (greenMap)
 
168
        {
143
169
            memcpy(greenMap, d->greenMap, (256 * sizeof(int)));
 
170
        }
 
171
 
144
172
        if (blueMap)
 
173
        {
145
174
            memcpy(blueMap, d->blueMap, (256 * sizeof(int)));
 
175
        }
 
176
 
146
177
        if (alphaMap)
 
178
        {
147
179
            memcpy(alphaMap, d->alphaMap, (256 * sizeof(int)));
 
180
        }
148
181
    }
149
182
    else
150
183
    {
151
184
        if (redMap)
 
185
        {
152
186
            memcpy(redMap, d->redMap16, (65536 * sizeof(int)));
 
187
        }
 
188
 
153
189
        if (greenMap)
 
190
        {
154
191
            memcpy(greenMap, d->greenMap16, (65536 * sizeof(int)));
 
192
        }
 
193
 
155
194
        if (blueMap)
 
195
        {
156
196
            memcpy(blueMap, d->blueMap16, (65536 * sizeof(int)));
 
197
        }
 
198
 
157
199
        if (alphaMap)
 
200
        {
158
201
            memcpy(alphaMap, d->alphaMap16, (65536 * sizeof(int)));
 
202
        }
159
203
    }
160
204
}
161
205
 
162
206
void CBFilter::applyCBFilter(DImg& image, double r, double g, double b, double a)
163
207
{
164
208
    if (image.isNull())
 
209
    {
165
210
        return;
 
211
    }
166
212
 
167
213
    uint size = image.width()*image.height();
168
214
    int  progress;
183
229
            data += 4;
184
230
 
185
231
            progress = (int)(((double)i * 100.0) / size);
 
232
 
186
233
            if ( progress%5 == 0 )
 
234
            {
187
235
                postProgress( progress );
 
236
            }
188
237
        }
189
238
    }
190
239
    else                                        // 16 bits image.
201
250
            data += 4;
202
251
 
203
252
            progress = (int)(((double)i * 100.0) / size);
 
253
 
204
254
            if ( progress%5 == 0 )
 
255
            {
205
256
                postProgress( progress );
 
257
            }
206
258
        }
207
259
    }
208
260
}
252
304
    int dummy_table[65536];
253
305
 
254
306
    if (r == 1.0 && g == 1.0 && b == 1.0 && a == 1.0)
 
307
    {
255
308
        return ;
 
309
    }
256
310
 
257
311
    if (r == g && r == b && r == a)
258
312
    {
259
 
       setGamma(r);
 
313
        setGamma(r);
260
314
    }
261
315
    else
262
316
    {
263
 
       getTables(r_table, g_table, b_table, a_table, sixteenBit);
264
 
 
265
 
       if(r != 1.0)
266
 
       {
267
 
          setGamma(r);
268
 
          getTables(r_table, dummy_table, dummy_table, dummy_table, sixteenBit);
269
 
          reset();
270
 
       }
271
 
 
272
 
       if(g != 1.0)
273
 
       {
274
 
          setGamma(g);
275
 
          getTables(dummy_table, g_table, dummy_table, dummy_table, sixteenBit);
276
 
          reset();
277
 
       }
278
 
 
279
 
       if(b != 1.0)
280
 
       {
281
 
          setGamma(b);
282
 
          getTables(dummy_table, dummy_table, b_table, dummy_table, sixteenBit);
283
 
          reset();
284
 
       }
285
 
 
286
 
       if(a != 1.0)
287
 
       {
288
 
          setGamma(a);
289
 
          getTables(dummy_table, dummy_table, dummy_table, a_table, sixteenBit);
290
 
          reset();
291
 
       }
292
 
 
293
 
       setTables(r_table, g_table, b_table, a_table, sixteenBit);
 
317
        getTables(r_table, g_table, b_table, a_table, sixteenBit);
 
318
 
 
319
        if (r != 1.0)
 
320
        {
 
321
            setGamma(r);
 
322
            getTables(r_table, dummy_table, dummy_table, dummy_table, sixteenBit);
 
323
            reset();
 
324
        }
 
325
 
 
326
        if (g != 1.0)
 
327
        {
 
328
            setGamma(g);
 
329
            getTables(dummy_table, g_table, dummy_table, dummy_table, sixteenBit);
 
330
            reset();
 
331
        }
 
332
 
 
333
        if (b != 1.0)
 
334
        {
 
335
            setGamma(b);
 
336
            getTables(dummy_table, dummy_table, b_table, dummy_table, sixteenBit);
 
337
            reset();
 
338
        }
 
339
 
 
340
        if (a != 1.0)
 
341
        {
 
342
            setGamma(a);
 
343
            getTables(dummy_table, dummy_table, dummy_table, a_table, sixteenBit);
 
344
            reset();
 
345
        }
 
346
 
 
347
        setTables(r_table, g_table, b_table, a_table, sixteenBit);
294
348
    }
295
349
}
296
350