~ubuntu-branches/ubuntu/karmic/digikam/karmic-backports

« back to all changes in this revision

Viewing changes to libs/dimg/filters/dimgimagefilters.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ubuntu Archive Auto-Backport
  • Date: 2009-12-07 19:03:53 UTC
  • mfrom: (54.1.4 lucid)
  • Revision ID: james.westby@ubuntu.com-20091207190353-oara3lenjxymto3i
Tags: 2:1.0.0~rc-1ubuntu1~karmic1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include <cstring>
38
38
#include <cstdlib>
39
39
 
 
40
// KDE includes
 
41
 
 
42
#include <kdebug.h>
 
43
 
40
44
// Local includes
41
45
 
42
46
#include "imagehistogram.h"
46
50
#include "dimgsharpen.h"
47
51
#include "dimgunsharpmask.h"
48
52
#include "dimgrefocus.h"
49
 
#include "debug.h"
50
53
#include "globals.h"
51
54
 
52
55
namespace Digikam
65
68
{
66
69
    if (!data || !w || !h)
67
70
    {
68
 
       kWarning(digiKamAreaCode) << ("DImgImageFilters::equalizeImage: no image data available!");
 
71
       kWarning() << ("DImgImageFilters::equalizeImage: no image data available!");
69
72
       return;
70
73
    }
71
74
 
93
96
       if(equalize_map)
94
97
           delete [] equalize_map;
95
98
 
96
 
       kWarning(digiKamAreaCode) << ("DImgImageFilters::equalizeImage: Unable to allocate memory!");
 
99
       kWarning() << ("DImgImageFilters::equalizeImage: Unable to allocate memory!");
97
100
       return;
98
101
    }
99
102
 
109
112
       intensity.green += histogram->getValue(GreenChannel, i);
110
113
       intensity.blue  += histogram->getValue(BlueChannel, i);
111
114
       intensity.alpha += histogram->getValue(AlphaChannel, i);
112
 
       map[i]          = intensity;
 
115
       map[i]           = intensity;
113
116
    }
114
117
 
115
118
    // Stretch the histogram.
118
121
    high = map[histogram->getHistogramSegments()-1];
119
122
    memset(equalize_map, 0, histogram->getHistogramSegments()*sizeof(int_packet));
120
123
 
 
124
    // TODO magic number 256
121
125
    for(i = 0 ; i < histogram->getHistogramSegments() ; ++i)
122
126
    {
123
127
       if(high.red != low.red)
141
145
    delete [] map;
142
146
 
143
147
    // Apply results to image.
144
 
 
 
148
    // TODO magic number 257
145
149
    if (!sixteenBit)        // 8 bits image.
146
150
    {
147
151
        uchar red, green, blue, alpha;
170
174
            ptr[1] = green;
171
175
            ptr[2] = red;
172
176
            ptr[3] = alpha;
173
 
            ptr += 4;
 
177
            ptr   += 4;
174
178
        }
175
179
    }
176
180
    else               // 16 bits image.
201
205
            ptr[1] = green;
202
206
            ptr[2] = red;
203
207
            ptr[3] = alpha;
204
 
            ptr += 4;
 
208
            ptr   += 4;
205
209
        }
206
210
    }
207
211
 
215
219
{
216
220
    if (!data || !w || !h)
217
221
    {
218
 
       kWarning(digiKamAreaCode) << ("DImgImageFilters::stretchContrastImage: no image data available!");
 
222
       kWarning() << ("DImgImageFilters::stretchContrastImage: no image data available!");
219
223
       return;
220
224
    }
221
225
 
240
244
       if(normalize_map)
241
245
           delete [] normalize_map;
242
246
 
243
 
       kWarning(digiKamAreaCode) << ("DImgImageFilters::stretchContrastImage: Unable to allocate memory!");
 
247
       kWarning() << ("DImgImageFilters::stretchContrastImage: Unable to allocate memory!");
244
248
       return;
245
249
    }
246
250
 
256
260
 
257
261
    memset(&intensity, 0, sizeof(struct double_packet));
258
262
 
259
 
    for(high.red = histogram->getHistogramSegments()-1 ; high.red != 0 ; --high.red)
 
263
    for(high.red = histogram->getMaxSegmentIndex() ; high.red != 0 ; --high.red)
260
264
    {
261
265
       intensity.red += histogram->getValue(RedChannel, (int)high.red);
262
266
 
269
273
       threshold_intensity = 0;
270
274
       memset(&intensity, 0, sizeof(struct double_packet));
271
275
 
272
 
       for(low.red = 0 ; low.red < histogram->getHistogramSegments()-1 ; ++low.red)
 
276
       for(low.red = 0 ; low.red < histogram->getMaxSegmentIndex() ; ++low.red)
273
277
       {
274
278
          intensity.red += histogram->getValue(RedChannel, (int)low.red);
275
279
 
279
283
 
280
284
       memset(&intensity, 0, sizeof(struct double_packet));
281
285
 
282
 
       for(high.red = histogram->getHistogramSegments()-1 ; high.red != 0 ; --high.red)
 
286
       for(high.red = histogram->getMaxSegmentIndex() ; high.red != 0 ; --high.red)
283
287
       {
284
288
          intensity.red += histogram->getValue(RedChannel, (int)high.red);
285
289
 
292
296
 
293
297
    memset(&intensity, 0, sizeof(struct double_packet));
294
298
 
295
 
    for(high.green = histogram->getHistogramSegments()-1 ; high.green != 0 ; --high.green)
 
299
    for(high.green = histogram->getMaxSegmentIndex() ; high.green != 0 ; --high.green)
296
300
    {
297
301
       intensity.green += histogram->getValue(GreenChannel, (int)high.green);
298
302
 
305
309
       threshold_intensity = 0;
306
310
       memset(&intensity, 0, sizeof(struct double_packet));
307
311
 
308
 
       for(low.green = 0 ; low.green < histogram->getHistogramSegments()-1 ; ++low.green)
 
312
       for(low.green = 0 ; low.green < histogram->getMaxSegmentIndex() ; ++low.green)
309
313
       {
310
314
          intensity.green += histogram->getValue(GreenChannel, (int)low.green);
311
315
 
315
319
 
316
320
       memset(&intensity, 0, sizeof(struct double_packet));
317
321
 
318
 
       for(high.green = histogram->getHistogramSegments()-1 ; high.green != 0 ; --high.green)
 
322
       for(high.green = histogram->getMaxSegmentIndex() ; high.green != 0 ; --high.green)
319
323
       {
320
324
          intensity.green += histogram->getValue(GreenChannel, (int)high.green);
321
325
 
328
332
 
329
333
    memset(&intensity, 0, sizeof(struct double_packet));
330
334
 
331
 
    for(high.blue = histogram->getHistogramSegments()-1 ; high.blue != 0 ; --high.blue)
 
335
    for(high.blue = histogram->getMaxSegmentIndex() ; high.blue != 0 ; --high.blue)
332
336
    {
333
337
       intensity.blue += histogram->getValue(BlueChannel, (int)high.blue);
334
338
 
341
345
       threshold_intensity = 0;
342
346
       memset(&intensity, 0, sizeof(struct double_packet));
343
347
 
344
 
       for(low.blue = 0 ; low.blue < histogram->getHistogramSegments()-1 ; ++low.blue)
 
348
       for(low.blue = 0 ; low.blue < histogram->getMaxSegmentIndex() ; ++low.blue)
345
349
       {
346
350
          intensity.blue += histogram->getValue(BlueChannel, (int)low.blue);
347
351
 
351
355
 
352
356
       memset(&intensity, 0, sizeof(struct double_packet));
353
357
 
354
 
       for(high.blue = histogram->getHistogramSegments()-1 ; high.blue != 0 ; --high.blue)
 
358
       for(high.blue = histogram->getMaxSegmentIndex() ; high.blue != 0 ; --high.blue)
355
359
       {
356
360
          intensity.blue += histogram->getValue(BlueChannel, (int)high.blue);
357
361
 
364
368
 
365
369
    memset(&intensity, 0, sizeof(struct double_packet));
366
370
 
367
 
    for(high.alpha = histogram->getHistogramSegments()-1 ; high.alpha != 0 ; --high.alpha)
 
371
    for(high.alpha = histogram->getMaxSegmentIndex() ; high.alpha != 0 ; --high.alpha)
368
372
    {
369
373
       intensity.alpha += histogram->getValue(AlphaChannel, (int)high.alpha);
370
374
 
377
381
       threshold_intensity = 0;
378
382
       memset(&intensity, 0, sizeof(struct double_packet));
379
383
 
380
 
       for(low.alpha = 0 ; low.alpha < histogram->getHistogramSegments()-1 ; ++low.alpha)
 
384
       for(low.alpha = 0 ; low.alpha < histogram->getMaxSegmentIndex() ; ++low.alpha)
381
385
       {
382
386
          intensity.alpha += histogram->getValue(AlphaChannel, (int)low.alpha);
383
387
 
387
391
 
388
392
       memset(&intensity, 0, sizeof(struct double_packet));
389
393
 
390
 
       for(high.alpha = histogram->getHistogramSegments()-1 ; high.alpha != 0 ; --high.alpha)
 
394
       for(high.alpha = histogram->getMaxSegmentIndex() ; high.alpha != 0 ; --high.alpha)
391
395
       {
392
396
          intensity.alpha += histogram->getValue(AlphaChannel, (int)high.alpha);
393
397
 
396
400
       }
397
401
    }
398
402
 
399
 
    delete histogram;
400
 
 
401
403
    // Stretch the histogram to create the normalized image mapping.
402
404
 
403
405
    memset(normalize_map, 0, histogram->getHistogramSegments()*sizeof(struct int_packet));
404
406
 
405
 
    for(i = 0 ; i <= (long)histogram->getHistogramSegments()-1 ; ++i)
 
407
    // TODO magic number 256
 
408
    for(i = 0 ; i <= (long)histogram->getMaxSegmentIndex() ; ++i)
406
409
    {
407
410
       if(i < (long) low.red)
408
411
          normalize_map[i].red = 0;
434
437
    }
435
438
 
436
439
    // Apply result to image.
437
 
 
 
440
    // TODO magic number 257
438
441
    if (!sixteenBit)        // 8 bits image.
439
442
    {
440
443
        uchar red, green, blue, alpha;
498
501
        }
499
502
    }
500
503
 
 
504
    delete histogram;
501
505
    delete [] normalize_map;
502
506
}
503
507
 
512
516
    int             x, i;
513
517
    unsigned short  range;
514
518
 
515
 
    int segments = sixteenBit ? 65536 : 256;
 
519
    int segments = sixteenBit ? NUM_SEGMENTS_16BIT : NUM_SEGMENTS_8BIT;
516
520
 
517
521
    // Memory allocation.
518
522
 
633
637
{
634
638
    if (!data || !w || !h)
635
639
    {
636
 
       kWarning(digiKamAreaCode) << ("DImgImageFilters::autoLevelsCorrectionImage: no image data available!");
 
640
       kWarning() << ("DImgImageFilters::autoLevelsCorrectionImage: no image data available!");
637
641
       return;
638
642
    }
639
643
    uchar* desData;
676
680
{
677
681
    if (!data || !w || !h)
678
682
    {
679
 
       kWarning(digiKamAreaCode) << ("DImgImageFilters::invertImage: no image data available!");
 
683
       kWarning() << ("DImgImageFilters::invertImage: no image data available!");
680
684
       return;
681
685
    }
682
686
 
717
721
{
718
722
    if (!data || !Width || !Height)
719
723
    {
720
 
       kWarning(digiKamAreaCode) << ("DImgImageFilters::channelMixerImage: no image data available!");
 
724
       kWarning() << ("DImgImageFilters::channelMixerImage: no image data available!");
721
725
       return;
722
726
    }
723
727
 
795
799
{
796
800
    if (!data || !width || !height)
797
801
    {
798
 
       kWarning(digiKamAreaCode) << ("DImgImageFilters::changeTonality: no image data available!");
 
802
       kWarning() << ("DImgImageFilters::changeTonality: no image data available!");
799
803
       return;
800
804
    }
801
805
 
848
852
{
849
853
    if (!data || !width || !height)
850
854
    {
851
 
       kWarning(digiKamAreaCode) << ("DImgImageFilters::gaussianBlurImage: no image data available!");
 
855
       kWarning() << ("DImgImageFilters::gaussianBlurImage: no image data available!");
852
856
       return;
853
857
    }
854
858
 
869
873
{
870
874
    if (!data || !width || !height)
871
875
    {
872
 
       kWarning(digiKamAreaCode) << ("DImgImageFilters::sharpenImage: no image data available!");
 
876
       kWarning() << ("DImgImageFilters::sharpenImage: no image data available!");
873
877
       return;
874
878
    }
875
879
 
889
893
{
890
894
    if (!data || !width || !height)
891
895
    {
892
 
       kWarning(digiKamAreaCode) << ("DImgImageFilters::unsharpMaskImage: no image data available!");
 
896
       kWarning() << ("DImgImageFilters::unsharpMaskImage: no image data available!");
893
897
       return;
894
898
    }
895
899
 
906
910
{
907
911
    if (!data || !width || !height)
908
912
    {
909
 
       kWarning(digiKamAreaCode) << ("DImgImageFilters::refocusImage: no image data available!");
 
913
       kWarning() << ("DImgImageFilters::refocusImage: no image data available!");
910
914
       return;
911
915
    }
912
916