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

« back to all changes in this revision

Viewing changes to libs/dimg/filters/fx/filmgrainfilter.h

  • Committer: Bazaar Package Importer
  • Author(s): Christian Mangold
  • Date: 2010-04-09 21:30:01 UTC
  • mfrom: (1.2.28 upstream)
  • Revision ID: james.westby@ubuntu.com-20100409213001-4bfyibrd359rn7o3
Tags: 2:1.2.0-0ubuntu1
* New upstream release (LP: #560576)
* Remove all patches, fixed upstream
  - Remove quilt build-depend

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        : 2005-05-25
 
7
 * Description : filter to add Film Grain to image.
 
8
 * 
 
9
 * Copyright (C) 2005-2010 by Gilles Caulier <caulier dot gilles at gmail dot com>
 
10
 * Copyright (C) 2005-2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
 
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 FILMGRAINFILTER_H
 
26
#define FILMGRAINFILTER_H
 
27
 
 
28
// Local includes
 
29
 
 
30
#include "digikam_export.h"
 
31
#include "dimgthreadedfilter.h"
 
32
#include "globals.h"
 
33
#include "dcolor.h"
 
34
 
 
35
namespace Digikam
 
36
{
 
37
  
 
38
class FilmGrainFilterPriv;  
 
39
 
 
40
class DIGIKAM_EXPORT FilmGrainContainer
 
41
{
 
42
 
 
43
public:
 
44
 
 
45
    FilmGrainContainer()
 
46
    {
 
47
        grainSize               = 1;
 
48
        photoDistribution       = false;
 
49
 
 
50
        addLuminanceNoise       = true;
 
51
        lumaIntensity           = 25;
 
52
        lumaShadows             = -100;
 
53
        lumaMidtones            = 0; 
 
54
        lumaHighlights          = -100;
 
55
 
 
56
        addChrominanceBlueNoise = false;
 
57
        chromaBlueIntensity     = 25;
 
58
        chromaBlueShadows       = -100;
 
59
        chromaBlueMidtones      = 0;
 
60
        chromaBlueHighlights    = -100;
 
61
 
 
62
        addChrominanceRedNoise  = false;
 
63
        chromaRedIntensity      = 25;
 
64
        chromaRedShadows        = -100;
 
65
        chromaRedMidtones       = 0;
 
66
        chromaRedHighlights     = -100;
 
67
    };
 
68
 
 
69
    ~FilmGrainContainer(){};
 
70
 
 
71
    bool isDirty()
 
72
    {
 
73
        return (addLuminanceNoise || addChrominanceBlueNoise || addChrominanceRedNoise);
 
74
    };
 
75
 
 
76
public:
 
77
 
 
78
    int  grainSize;
 
79
    bool photoDistribution;
 
80
 
 
81
    bool addLuminanceNoise;
 
82
    int  lumaIntensity;
 
83
    int  lumaShadows;
 
84
    int  lumaMidtones;
 
85
    int  lumaHighlights;
 
86
 
 
87
    bool addChrominanceBlueNoise;
 
88
    int  chromaBlueIntensity;
 
89
    int  chromaBlueShadows;
 
90
    int  chromaBlueMidtones;
 
91
    int  chromaBlueHighlights;
 
92
 
 
93
    bool addChrominanceRedNoise;
 
94
    int  chromaRedIntensity;
 
95
    int  chromaRedShadows; 
 
96
    int  chromaRedMidtones;
 
97
    int  chromaRedHighlights;
 
98
};
 
99
 
 
100
// -----------------------------------------------------------------------------------------------
 
101
  
 
102
class DIGIKAM_EXPORT FilmGrainFilter : public DImgThreadedFilter
 
103
{
 
104
 
 
105
public:
 
106
 
 
107
    explicit FilmGrainFilter(DImg* orgImage, QObject* parent=0, const FilmGrainContainer& settings=FilmGrainContainer());
 
108
    // Constructor for slave mode: execute immediately in current thread with specified master filter
 
109
    explicit FilmGrainFilter(DImgThreadedFilter* parentFilter, const DImg& orgImage, const DImg& destImage,
 
110
                             int progressBegin=0, int progressEnd=100,
 
111
                             const FilmGrainContainer& settings=FilmGrainContainer());
 
112
    ~FilmGrainFilter();
 
113
 
 
114
private:
 
115
 
 
116
    void filterImage();
 
117
 
 
118
    inline void computeNoiseSettings(const DColor& col,
 
119
                                     double& luRange, double& luNoise,
 
120
                                     double& cbRange, double& cbNoise,
 
121
                                     double& crRange, double& crNoise);
 
122
    inline double interpolate(int shadows, int midtones, int highlights, const DColor& col);
 
123
    inline double randomizeUniform(double range);
 
124
    inline double randomizeGauss(double sigma);
 
125
    inline double randomizePoisson(double lambda);
 
126
    inline void   adjustYCbCr(DColor& col, double range, double nRand, int channel);
 
127
 
 
128
private:
 
129
 
 
130
    FilmGrainFilterPriv* const d;
 
131
};
 
132
 
 
133
}  // namespace Digikam
 
134
 
 
135
#endif /* FILMGRAINFILTER_H */