File indexing completed on 2025-01-19 03:56:11

0001 /*
0002  * The Progressive Graphics File; http://www.libpgf.org
0003  *
0004  * $Date: 2006-05-18 16:03:32 +0200 (Do, 18 Mai 2006) $
0005  * $Revision: 194 $
0006  *
0007  * This file Copyright (C) 2006 xeraina GmbH, Switzerland
0008  *
0009  * This program is free software; you can redistribute it and/or
0010  * modify it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE
0011  * as published by the Free Software Foundation; either version 2.1
0012  * of the License, or (at your option) any later version.
0013  *
0014  * This program is distributed in the hope that it will be useful,
0015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017  * GNU General Public License for more details.
0018  *
0019  * You should have received a copy of the GNU General Public License
0020  * along with this program; if not, write to the Free Software
0021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
0022  */
0023 
0024 //////////////////////////////////////////////////////////////////////
0025 /// @file WaveletTransform.h
0026 /// @brief PGF wavelet transform class
0027 /// @author C. Stamm
0028 
0029 #ifndef PGF_WAVELETTRANSFORM_H
0030 #define PGF_WAVELETTRANSFORM_H
0031 
0032 #if defined(__GNUC__)
0033 #pragma GCC diagnostic push
0034 #pragma GCC diagnostic ignored "-Wignored-qualifiers"
0035 #endif
0036 
0037 #if defined(__APPLE__)
0038 #pragma clang diagnostic push
0039 #pragma clang diagnostic ignored "-Wignored-qualifiers"
0040 #endif
0041 
0042 #include "PGFtypes.h"
0043 #include "Subband.h"
0044 
0045 //////////////////////////////////////////////////////////////////////
0046 // Constants
0047 const UINT32 FilterSizeL = 5;                   ///< number of coefficients of the low pass filter
0048 const UINT32 FilterSizeH = 3;                   ///< number of coefficients of the high pass filter
0049 const UINT32 FilterSize = __max(FilterSizeL, FilterSizeH);
0050 
0051 #ifdef __PGFROISUPPORT__
0052 //////////////////////////////////////////////////////////////////////
0053 /// PGF ROI and tile support. This is a helper class for CWaveletTransform.
0054 /// @author C. Stamm
0055 /// @brief ROI indices
0056 class CRoiIndices {
0057 };
0058 #endif //__PGFROISUPPORT__
0059 
0060 
0061 //////////////////////////////////////////////////////////////////////
0062 /// PGF wavelet transform class.
0063 /// @author C. Stamm, R. Spuler
0064 /// @brief PGF wavelet transform
0065 class CWaveletTransform {
0066     friend class CSubband;
0067 
0068 public:
0069     //////////////////////////////////////////////////////////////////////
0070     /// Constructor: Constructs a wavelet transform pyramid of given size and levels.
0071     /// @param width The width of the original image (at level 0) in pixels
0072     /// @param height The height of the original image (at level 0) in pixels
0073     /// @param levels The number of levels (>= 0)
0074     /// @param data Input data of subband LL at level 0
0075     CWaveletTransform(UINT32 width, UINT32 height, int levels, DataT* data = nullptr);
0076 
0077     //////////////////////////////////////////////////////////////////////
0078     /// Destructor
0079     ~CWaveletTransform() { Destroy(); }
0080 
0081     //////////////////////////////////////////////////////////////////////
0082     /// Compute fast forward wavelet transform of LL subband at given level and
0083     /// stores result in all 4 subbands of level + 1.
0084     /// @param level A wavelet transform pyramid level (>= 0 && < Levels())
0085     /// @param quant A quantization value (linear scalar quantization)
0086     /// @return error in case of a memory allocation problem
0087     OSError ForwardTransform(int level, int quant);
0088 
0089     //////////////////////////////////////////////////////////////////////
0090     /// Compute fast inverse wavelet transform of all 4 subbands of given level and
0091     /// stores result in LL subband of level - 1.
0092     /// @param level A wavelet transform pyramid level (> 0 && <= Levels())
0093     /// @param width A pointer to the returned width of subband LL (in pixels)
0094     /// @param height A pointer to the returned height of subband LL (in pixels)
0095     /// @param data A pointer to the returned array of image data
0096     /// @return error in case of a memory allocation problem
0097     OSError InverseTransform(int level, UINT32* width, UINT32* height, DataT** data);
0098 
0099     //////////////////////////////////////////////////////////////////////
0100     /// Get pointer to one of the 4 subband at a given level.
0101     /// @param level A wavelet transform pyramid level (>= 0 && <= Levels())
0102     /// @param orientation A quarter of the subband (LL, LH, HL, HH)
0103     CSubband* GetSubband(int level, Orientation orientation) {
0104         ASSERT(level >= 0 && level < m_nLevels);
0105         return &m_subband[level][orientation];
0106     }
0107 
0108 #ifdef __PGFROISUPPORT__
0109     //////////////////////////////////////////////////////////////////////
0110     /// Compute and store ROIs for nLevels
0111     /// @param rect rectangular region of interest (ROI) at level 0
0112     void SetROI(PGFRect rect);
0113 
0114     //////////////////////////////////////////////////////////////////////
0115     /// Checks the relevance of a given tile at given level.
0116     /// @param level A valid subband level.
0117     /// @param tileX x-index of the given tile
0118     /// @param tileY y-index of the given tile
0119     const bool TileIsRelevant(int level, UINT32 tileX, UINT32 tileY) const { ASSERT(m_indices); ASSERT(level >= 0 && level < m_nLevels); return m_indices[level].IsInside(tileX, tileY); }
0120 
0121     //////////////////////////////////////////////////////////////////////
0122     /// Get number of tiles in x- or y-direction at given level.
0123     /// This number is independent of the given ROI.
0124     /// @param level A valid subband level.
0125     UINT32 GetNofTiles(int level) const { ASSERT(level >= 0 && level < m_nLevels); return 1 << (m_nLevels - level - 1); }
0126 
0127     //////////////////////////////////////////////////////////////////////
0128     /// Return ROI at given level.
0129     /// @param level A valid subband level.
0130     const PGFRect& GetAlignedROI(int level) const       { return m_subband[level][LL].GetAlignedROI(); }
0131 
0132 #endif // __PGFROISUPPORT__
0133 
0134 private:
0135     void Destroy() {
0136         delete[] m_subband; m_subband = nullptr;
0137     #ifdef __PGFROISUPPORT__
0138         delete[] m_indices; m_indices = nullptr;
0139     #endif
0140     }
0141     void InitSubbands(UINT32 width, UINT32 height, DataT* data);
0142     void ForwardRow(DataT* buff, UINT32 width);
0143     void InverseRow(DataT* buff, UINT32 width);
0144     void InterleavedToSubbands(int destLevel, DataT* loRow, DataT* hiRow, UINT32 width);
0145     void SubbandsToInterleaved(int srcLevel, DataT* loRow, DataT* hiRow, UINT32 width);
0146 
0147     int         m_nLevels;                      ///< number of LL levels: one more than header.nLevels in PGFimage
0148     CSubband    (*m_subband)[NSubbands];        ///< quadtree of subbands: LL HL LH HH
0149 
0150 #ifdef __PGFROISUPPORT__
0151     PGFRect *m_indices;                         ///< array of length m_nLevels of tile indices
0152 #endif //__PGFROISUPPORT__
0153 
0154 };
0155 
0156 #if defined(__GNUC__)
0157 #pragma GCC diagnostic pop
0158 #endif
0159 
0160 #if defined(__APPLE__)
0161 #pragma clang diagnostic pop
0162 #endif
0163 
0164 #endif //PGF_WAVELETTRANSFORM_H