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

« back to all changes in this revision

Viewing changes to libs/dimg/filters/fx/distortionfxfilter.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-07-18
 
7
 * Description : Distortion FX threaded image filter.
 
8
 *
 
9
 * Copyright (C) 2005-2010 by Gilles Caulier <caulier dot gilles at gmail dot com>
 
10
 * Copyright (C) 2006-2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
 
11
 *
 
12
 * Original Distortion algorithms copyrighted 2004-2005 by
 
13
 * Pieter Z. Voloshyn <pieter dot voloshyn at gmail dot com>.
 
14
 *
 
15
 * This program is free software; you can redistribute it
 
16
 * and/or modify it under the terms of the GNU General
 
17
 * Public License as published by the Free Software Foundation;
 
18
 * either version 2, or (at your option)
 
19
 * any later version.
 
20
 *
 
21
 * This program is distributed in the hope that it will be useful,
 
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
24
 * GNU General Public License for more details.
 
25
 *
 
26
 * ============================================================ */
 
27
 
 
28
#ifndef DISTORTION_FX_FILTER_H
 
29
#define DISTORTION_FX_FILTER_H
 
30
 
 
31
// Qt includes
 
32
 
 
33
#include <QSize>
 
34
 
 
35
// Local includes
 
36
 
 
37
#include "digikam_export.h"
 
38
#include "dimgthreadedfilter.h"
 
39
#include "globals.h"
 
40
 
 
41
namespace Digikam
 
42
{
 
43
 
 
44
class DIGIKAM_EXPORT DistortionFXFilter : public DImgThreadedFilter
 
45
{
 
46
 
 
47
public:
 
48
 
 
49
    explicit DistortionFXFilter(DImg* orgImage, QObject* parent=0, int effectType=0,
 
50
                                int level=0, int iteration=0, bool antialiasing=true);
 
51
 
 
52
    ~DistortionFXFilter(){};
 
53
 
 
54
public:
 
55
 
 
56
    enum DistortionFXTypes
 
57
    {
 
58
        FishEye=0,
 
59
        Twirl,
 
60
        CilindricalHor,
 
61
        CilindricalVert,
 
62
        CilindricalHV,
 
63
        Caricature,
 
64
        MultipleCorners,
 
65
        WavesHorizontal,
 
66
        WavesVertical,
 
67
        BlockWaves1,
 
68
        BlockWaves2,
 
69
        CircularWaves1,
 
70
        CircularWaves2,
 
71
        PolarCoordinates,
 
72
        UnpolarCoordinates,
 
73
        Tile
 
74
    };
 
75
 
 
76
private:
 
77
 
 
78
    void filterImage();
 
79
 
 
80
    // Backported from ImageProcessing version 2
 
81
    void fisheye(DImg *orgImage, DImg *destImage, double Coeff, bool AntiAlias=true);
 
82
    void twirl(DImg *orgImage, DImg *destImage, int Twirl, bool AntiAlias=true);
 
83
    void cilindrical(DImg *orgImage, DImg *destImage, double Coeff,
 
84
                     bool Horizontal, bool Vertical, bool AntiAlias=true);
 
85
    void multipleCorners(DImg *orgImage, DImg *destImage, int Factor, bool AntiAlias=true);
 
86
    void polarCoordinates(DImg *orgImage, DImg *destImage, bool Type, bool AntiAlias=true);
 
87
    void circularWaves(DImg *orgImage, DImg *destImage, int X, int Y, double Amplitude,
 
88
                       double Frequency, double Phase, bool WavesType, bool AntiAlias=true);
 
89
 
 
90
    // Backported from ImageProcessing version 1
 
91
    void waves(DImg *orgImage, DImg *destImage, int Amplitude, int Frequency,
 
92
               bool FillSides, bool Direction);
 
93
    void blockWaves(DImg *orgImage, DImg *destImage, int Amplitude, int Frequency, bool Mode);
 
94
    void tile(DImg *orgImage, DImg *destImage, int WSize, int HSize, int Random);
 
95
 
 
96
    void setPixelFromOther(int Width, int Height, bool sixteenBit, int bytesDepth,
 
97
                           uchar *data, uchar *pResBits,
 
98
                           int w, int h, double nw, double nh, bool AntiAlias);
 
99
    /*
 
100
    //UNUSED
 
101
 
 
102
    inline double maximumRadius(int Height, int Width, double Angle);
 
103
 
 
104
    // This function does the same thing that ShadeColors function but using double variables.
 
105
    inline double proportionalValue (double DestValue, double SrcValue, double Shade)
 
106
    {
 
107
        if (Shade == 0.0) return DestValue;
 
108
        if (Shade == 255.0) return SrcValue;
 
109
        return ((DestValue * (255.0 - Shade) + SrcValue * Shade) / 256.0);
 
110
    };
 
111
    */
 
112
 
 
113
    // Return the limit defined the max and min values.
 
114
    inline int Lim_Max(int Now, int Up, int Max)
 
115
    {
 
116
        --Max;
 
117
        while (Now > Max - Up) --Up;
 
118
        return (Up);
 
119
    };
 
120
 
 
121
    inline bool isInside (int Width, int Height, int X, int Y)
 
122
    {
 
123
        bool bIsWOk = ((X < 0) ? false : (X >= Width ) ? false : true);
 
124
        bool bIsHOk = ((Y < 0) ? false : (Y >= Height) ? false : true);
 
125
        return (bIsWOk && bIsHOk);
 
126
    };
 
127
 
 
128
    inline int getOffset(int Width, int X, int Y, int bytesDepth)
 
129
    {
 
130
        return (Y * Width * bytesDepth) + (X * bytesDepth);
 
131
    };
 
132
 
 
133
    inline int getOffsetAdjusted(int Width, int Height, int X, int Y, int bytesDepth)
 
134
    {
 
135
        X = (X < 0) ?  0  :  ((X >= Width ) ? (Width  - 1) : X);
 
136
        Y = (Y < 0) ?  0  :  ((Y >= Height) ? (Height - 1) : Y);
 
137
        return getOffset(Width, X, Y, bytesDepth);
 
138
    };
 
139
 
 
140
private:
 
141
 
 
142
    bool m_antiAlias;
 
143
 
 
144
    int  m_level;
 
145
    int  m_iteration;
 
146
    int  m_effectType;
 
147
};
 
148
 
 
149
}  // namespace Digikam
 
150
 
 
151
#endif /* DISTORTION_FX_FILTER_H */