Subversion Repositories Scribus

Rev

Rev 16771 | Rev 19721 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
15796 fschmid 1
/*
2
 * The Progressive Graphics File; http://www.libpgf.org
16771 fschmid 3
 *
15796 fschmid 4
 * $Date: 2006-05-18 16:03:32 +0200 (Do, 18 Mai 2006) $
5
 * $Revision: 194 $
16771 fschmid 6
 *
15796 fschmid 7
 * This file Copyright (C) 2006 xeraina GmbH, Switzerland
16771 fschmid 8
 *
15796 fschmid 9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE
11
 * as published by the Free Software Foundation; either version 2.1
12
 * of the License, or (at your option) any later version.
16771 fschmid 13
 *
15796 fschmid 14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
16771 fschmid 18
 *
15796 fschmid 19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
18122 mrdocs 21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
15796 fschmid 22
 */
23
 
16771 fschmid 24
//////////////////////////////////////////////////////////////////////
25
/// @file WaveletTransform.h
26
/// @brief PGF wavelet transform class
27
/// @author C. Stamm
28
 
15796 fschmid 29
#ifndef PGF_WAVELETTRANSFORM_H
30
#define PGF_WAVELETTRANSFORM_H
31
 
32
#include "PGFtypes.h"
33
#include "Subband.h"
34
 
35
//////////////////////////////////////////////////////////////////////
36
// Constants
37
#define FilterWidth                     5                                       // number of coefficients of the row wavelet filter
38
#define FilterHeight            3                                       // number of coefficients of the column wavelet filter
39
 
40
#ifdef __PGFROISUPPORT__
41
//////////////////////////////////////////////////////////////////////
42
/// PGF ROI and tile support. This is a helper class for CWaveletTransform.
43
/// @author C. Stamm
16771 fschmid 44
/// @brief ROI and tile support
15796 fschmid 45
class CROIs {
46
        friend class CWaveletTransform;
47
 
48
        //////////////////////////////////////////////////////////////////////
49
        /// Constructor: Creates a ROI helper object
50
        /// @param levels The number of levels (>= 0)
51
        CROIs(int levels) : m_nLevels(levels), m_ROIs(0), m_indices(0) { ASSERT(levels > 0); }
52
 
53
        //////////////////////////////////////////////////////////////////////
54
        /// Destructor
55
        ~CROIs() { Destroy(); }
56
 
57
        void Destroy()                                                          { delete[] m_ROIs; m_ROIs = 0; delete[] m_indices; m_indices = 0; }
58
        void CreateROIs();
59
        void CreateIndices();
60
        void ComputeIndices(UINT32 width, UINT32 height, const PGFRect& rect);
61
        void SetROI(int level, const PGFRect& rect)     { ASSERT(m_ROIs); ASSERT(level >= 0 && level < m_nLevels); m_ROIs[level] = rect; }
62
        const PGFRect& GetIndices(int level) const      { ASSERT(m_indices); ASSERT(level >= 0 && level < m_nLevels); return m_indices[level]; }
63
        UINT32 Left(int level) const                            { ASSERT(m_ROIs); ASSERT(level >= 0 && level < m_nLevels); return m_ROIs[level].left; }
64
        UINT32 Top(int level) const                                     { ASSERT(m_ROIs); ASSERT(level >= 0 && level < m_nLevels); return m_ROIs[level].top; }
65
        bool ROIisSupported() const                                     { return m_ROIs != 0; }
66
        void ComputeTileIndex(UINT32 width, UINT32 height, UINT32 pos, bool horizontal, bool isMin);
67
 
68
public:
69
        //////////////////////////////////////////////////////////////////////
70
        /// Returns the number of tiles at a given level.
71
        /// @param level A wavelet transform pyramid level (>= 0 && < Levels())
72
        UINT32 GetNofTiles(int level) const                     { ASSERT(level >= 0 && level < m_nLevels); return 1 << (m_nLevels - level - 1); }
73
 
74
        //////////////////////////////////////////////////////////////////////
75
        /// Return region of interest at a given level.
76
        /// @param level A wavelet transform pyramid level (>= 0 && < Levels())
77
        const PGFRect& GetROI(int level) const          { ASSERT(m_ROIs); ASSERT(level >= 0 && level < m_nLevels); return m_ROIs[level]; }
78
 
79
private:
80
        int      m_nLevels;                     // number of levels of the image
81
        PGFRect *m_ROIs;                        // array of region of interests (ROI)
82
        PGFRect *m_indices;                     // array of tile indices
83
 
84
};
85
#endif //__PGFROISUPPORT__
86
 
87
 
88
//////////////////////////////////////////////////////////////////////
89
/// PGF wavelet transform class.
90
/// @author C. Stamm, R. Spuler
16771 fschmid 91
/// @brief PGF wavelet transform
15796 fschmid 92
class CWaveletTransform {
93
        friend class CSubband;
94
 
95
public:
96
        //////////////////////////////////////////////////////////////////////
97
        /// Constructor: Constructs a wavelet transform pyramid of given size and levels.
98
        /// @param width The width of the original image (at level 0) in pixels
99
        /// @param height The height of the original image (at level 0) in pixels
100
        /// @param levels The number of levels (>= 0)
101
        /// @param data Input data of subband LL at level 0
102
        CWaveletTransform(UINT32 width, UINT32 height, int levels, DataT* data = NULL);
103
 
104
        //////////////////////////////////////////////////////////////////////
105
        /// Destructor
106
        ~CWaveletTransform() { Destroy(); }
16771 fschmid 107
 
15796 fschmid 108
        //////////////////////////////////////////////////////////////////////
109
        /// Compute fast forward wavelet transform of LL subband at given level and
110
        /// stores result on all 4 subbands of level + 1.
111
        /// @param level A wavelet transform pyramid level (>= 0 && < Levels())
112
        void ForwardTransform(int level);
113
 
114
        //////////////////////////////////////////////////////////////////////
115
        /// Compute fast inverse wavelet transform of all 4 subbands of given level and
116
        /// stores result in LL subband of level - 1.
117
        /// @param level A wavelet transform pyramid level (> 0 && <= Levels())
118
        /// @param width A pointer to the returned width of subband LL (in pixels)
119
        /// @param height A pointer to the returned height of subband LL (in pixels)
120
        /// @param data A pointer to the returned array of image data
121
        void InverseTransform(int level, UINT32* width, UINT32* height, DataT** data);
122
 
123
        //////////////////////////////////////////////////////////////////////
124
        /// Get pointer to one of the 4 subband at a given level.
125
        /// @param level A wavelet transform pyramid level (>= 0 && <= Levels())
126
        /// @param orientation A quarter of the subband (LL, LH, HL, HH)
127
        CSubband* GetSubband(int level, Orientation orientation) {
128
                ASSERT(level >= 0 && level < m_nLevels);
129
                return &m_subband[level][orientation];
130
        }
16771 fschmid 131
 
15796 fschmid 132
#ifdef __PGFROISUPPORT__
133
        //////////////////////////////////////////////////////////////////////
134
        /// Compute and store ROIs for each level
135
        /// @param rect rectangular region of interest (ROI)
136
        void SetROI(const PGFRect& rect);
137
 
138
        //////////////////////////////////////////////////////////////////////
139
        /// For each subband set a referenct to ROI information
140
        void SetROI();
141
 
142
        //////////////////////////////////////////////////////////////////////
143
        /// Get tile indices of a ROI at given level.
144
        /// @param level A valid subband level.
145
        const PGFRect& GetTileIndices(int level) const  { return m_ROIs.GetIndices(level); }
146
 
147
        //////////////////////////////////////////////////////////////////////
148
        /// Get number of tiles in x- or y-direction at given level.
149
        /// @param level A valid subband level.
150
        UINT32 GetNofTiles(int level) const                             { return m_ROIs.GetNofTiles(level); }
151
 
152
        //////////////////////////////////////////////////////////////////////
153
        /// Return ROI at given level.
154
        /// @param level A valid subband level.
155
        const PGFRect& GetROI(int level) const                  { return m_ROIs.GetROI(level); }
156
 
157
#endif // __PGFROISUPPORT__
158
 
159
private:
16771 fschmid 160
        void Destroy() { delete[] m_subband; m_subband = 0;
15796 fschmid 161
                #ifdef __PGFROISUPPORT__
16771 fschmid 162
                m_ROIs.Destroy();
15796 fschmid 163
                #endif
164
        }
165
        void InitSubbands(UINT32 width, UINT32 height, DataT* data);
166
        void ForwardRow(DataT* buff, UINT32 width);
167
        void InverseRow(DataT* buff, UINT32 width);
168
        void LinearToMallat(int destLevel,DataT* loRow, DataT* hiRow, UINT32 width);
169
        void MallatToLinear(int srcLevel, DataT* loRow, DataT* hiRow, UINT32 width);
170
 
171
#ifdef __PGFROISUPPORT__
172
        CROIs           m_ROIs;                                                 // ROI information
173
#endif //__PGFROISUPPORT__
174
 
175
        int                     m_nLevels;                                              // number of transform levels: one more than the number of level in PGFimage
16771 fschmid 176
        CSubband        (*m_subband)[NSubbands];                // quadtree of subbands: LL HL
15796 fschmid 177
                                                                                                //                       LH HH
178
};
179
 
180
#endif //PGF_WAVELETTRANSFORM_H