summaryrefslogtreecommitdiffstats
path: root/src/libs/dimg/filters/dimggaussianblur.h
blob: e88944bc97752e10e27dc0110871df9dd67437ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* ============================================================
 *
 * This file is a part of digiKam project
 * http://www.digikam.org
 *
 * Date        : 2005-17-07
 * Description : A Gaussian Blur threaded image filter.
 * 
 * Copyright (C) 2005-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
 *
 * This program is free software; you can redistribute it
 * and/or modify it under the terms of the GNU General
 * Public License as published by the Free Software Foundation;
 * either version 2, or (at your option)
 * any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * ============================================================ */
  
#ifndef DIMGGAUSSIAN_BLUR_H
#define DIMGGAUSSIAN_BLUR_H

// Digikam includes.

#include "digikam_export.h"

// Local includes.

#include "dimgthreadedfilter.h"

namespace Digikam
{

class DIGIKAM_EXPORT DImgGaussianBlur : public DImgThreadedFilter
{

public:
    
    DImgGaussianBlur(DImg *orgImage, TQObject *parent=0, int radius=3);

    // Constructor for slave mode: execute immediately in current thread with specified master filter
    DImgGaussianBlur(DImgThreadedFilter *parentFilter, const DImg &orgImage, const DImg &destImage,
                     int progressBegin=0, int progressEnd=100, int radius=3);
    
    ~DImgGaussianBlur(){};
    
private:  // Gaussian blur filter data.

    int m_radius;
    
private:  // Gaussian blur filter methods.

    virtual void filterImage(void);
    
    void gaussianBlurImage(uchar *data, int width, int height, bool sixteenBit, int radius);

    // function to allocate a 2d array   
    int** Alloc2DArray (int Columns, int Rows)
    {
       // First, we declare our future 2d array to be returned
       int** lpcArray = 0L;

       // Now, we alloc the main pointer with Columns
       lpcArray = new int*[Columns];
        
       for (int i = 0; i < Columns; i++)
           lpcArray[i] = new int[Rows];

       return (lpcArray);
    };
    
    // Function to deallocates the 2d array previously created
    void Free2DArray (int** lpcArray, int Columns)
    {
       // loop to dealocate the columns
       for (int i = 0; i < Columns; i++)
           delete [] lpcArray[i];

       // now, we delete the main pointer
       delete [] lpcArray;
    };
       
    inline bool IsInside (int Width, int Height, int X, int Y)
    {
       bool bIsWOk = ((X < 0) ? false : (X >= Width ) ? false : true);
       bool bIsHOk = ((Y < 0) ? false : (Y >= Height) ? false : true);
       return (bIsWOk && bIsHOk);
    };
};    

}  // NameSpace Digikam

#endif /* DIMGGAUSSIAN_BLUR_H */