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

0001 /*
0002  * The Progressive Graphics File; http://www.libpgf.org
0003  *
0004  * $Date: 2006-06-04 22:05:59 +0200 (So, 04 Jun 2006) $
0005  * $Revision: 229 $
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 Subband.h
0026 /// @brief PGF wavelet subband class
0027 /// @author C. Stamm
0028 
0029 #ifndef PGF_SUBBAND_H
0030 #define PGF_SUBBAND_H
0031 
0032 #include "PGFtypes.h"
0033 
0034 class CEncoder;
0035 class CDecoder;
0036 class CRoiIndices;
0037 
0038 //////////////////////////////////////////////////////////////////////
0039 /// PGF wavelet channel subband class.
0040 /// @author C. Stamm, R. Spuler
0041 /// @brief Wavelet channel class
0042 class CSubband {
0043     friend class CWaveletTransform;
0044     friend class CRoiIndices;
0045 
0046 public:
0047     //////////////////////////////////////////////////////////////////////
0048     /// Standard constructor.
0049     CSubband();
0050 
0051     //////////////////////////////////////////////////////////////////////
0052     /// Destructor.
0053     ~CSubband();
0054 
0055     //////////////////////////////////////////////////////////////////////
0056     /// Allocate a memory buffer to store all wavelet coefficients of this subband.
0057     /// @return True if the allocation did work without any problems
0058     bool AllocMemory();
0059 
0060     //////////////////////////////////////////////////////////////////////
0061     /// Delete the memory buffer of this subband.
0062     void FreeMemory();
0063 
0064     /////////////////////////////////////////////////////////////////////
0065     /// Extracts a rectangular subregion of this subband.
0066     /// Write wavelet coefficients into buffer.
0067     /// It might throw an IOException.
0068     /// @param encoder An encoder instance
0069     /// @param tile True if just a rectangular region is extracted, false if the entire subband is extracted.
0070     /// @param tileX Tile index in x-direction
0071     /// @param tileY Tile index in y-direction
0072     void ExtractTile(CEncoder& encoder, bool tile = false, UINT32 tileX = 0, UINT32 tileY = 0);
0073 
0074     /////////////////////////////////////////////////////////////////////
0075     /// Decoding and dequantization of this subband.
0076     /// It might throw an IOException.
0077     /// @param decoder A decoder instance
0078     /// @param quantParam Dequantization value
0079     /// @param tile True if just a rectangular region is placed, false if the entire subband is placed.
0080     /// @param tileX Tile index in x-direction
0081     /// @param tileY Tile index in y-direction
0082     void PlaceTile(CDecoder& decoder, int quantParam, bool tile = false, UINT32 tileX = 0, UINT32 tileY = 0);
0083 
0084     //////////////////////////////////////////////////////////////////////
0085     /// Perform subband quantization with given quantization parameter.
0086     /// A scalar quantization (with dead-zone) is used. A large quantization value
0087     /// results in strong quantization and therefore in big quality loss.
0088     /// @param quantParam A quantization parameter (larger or equal to 0)
0089     void Quantize(int quantParam);
0090 
0091     //////////////////////////////////////////////////////////////////////
0092     /// Perform subband dequantization with given quantization parameter.
0093     /// A scalar quantization (with dead-zone) is used. A large quantization value
0094     /// results in strong quantization and therefore in big quality loss.
0095     /// @param quantParam A quantization parameter (larger or equal to 0)
0096     void Dequantize(int quantParam);
0097 
0098     //////////////////////////////////////////////////////////////////////
0099     /// Store wavelet coefficient in subband at given position.
0100     /// @param pos A subband position (>= 0)
0101     /// @param v A wavelet coefficient
0102     void SetData(UINT32 pos, DataT v)   { ASSERT(pos < m_size); m_data[pos] = v; }
0103 
0104     //////////////////////////////////////////////////////////////////////
0105     /// Get a pointer to an array of all wavelet coefficients of this subband.
0106     /// @return Pointer to array of wavelet coefficients
0107     DataT* GetBuffer()                  { return m_data; }
0108 
0109     //////////////////////////////////////////////////////////////////////
0110     /// Return wavelet coefficient at given position.
0111     /// @param pos A subband position (>= 0)
0112     /// @return Wavelet coefficient
0113     DataT GetData(UINT32 pos) const     { ASSERT(pos < m_size); return m_data[pos]; }
0114 
0115     //////////////////////////////////////////////////////////////////////
0116     /// Return level of this subband.
0117     /// @return Level of this subband
0118     int GetLevel() const                { return m_level; }
0119 
0120     //////////////////////////////////////////////////////////////////////
0121     /// Return height of this subband.
0122     /// @return Height of this subband (in pixels)
0123     int GetHeight() const               { return m_height; }
0124 
0125     //////////////////////////////////////////////////////////////////////
0126     /// Return width of this subband.
0127     /// @return Width of this subband (in pixels)
0128     int GetWidth() const                { return m_width; }
0129 
0130     //////////////////////////////////////////////////////////////////////
0131     /// Return orientation of this subband.
0132     /// LL LH
0133     /// HL HH
0134     /// @return Orientation of this subband (LL, HL, LH, HH)
0135     Orientation GetOrientation() const  { return m_orientation; }
0136 
0137 #ifdef __PGFROISUPPORT__
0138     /////////////////////////////////////////////////////////////////////
0139     /// Set data buffer position to given position + one row.
0140     /// @param pos Given position
0141     void IncBuffRow(UINT32 pos) { m_dataPos = pos + BufferWidth(); }
0142 
0143 #endif
0144 
0145 private:
0146     void Initialize(UINT32 width, UINT32 height, int level, Orientation orient);
0147     void WriteBuffer(DataT val)         { ASSERT(m_dataPos < m_size); m_data[m_dataPos++] = val; }
0148     void SetBuffer(DataT* b)            { ASSERT(b); m_data = b; }
0149     DataT ReadBuffer()                  { ASSERT(m_dataPos < m_size); return m_data[m_dataPos++]; }
0150 
0151     UINT32 GetBuffPos() const           { return m_dataPos; }
0152 
0153 #ifdef __PGFROISUPPORT__
0154     UINT32 BufferWidth() const          { return m_ROI.Width(); }
0155     void TilePosition(UINT32 tileX, UINT32 tileY, UINT32& left, UINT32& top, UINT32& w, UINT32& h) const;
0156     void TileIndex(bool topLeft, UINT32 xPos, UINT32 yPos, UINT32& tileX, UINT32& tileY, UINT32& x, UINT32& y) const;
0157     const PGFRect& GetAlignedROI() const { return m_ROI; }
0158     void SetNTiles(UINT32 nTiles)       { m_nTiles = nTiles; }
0159     void SetAlignedROI(const PGFRect& roi);
0160     void InitBuffPos(UINT32 left = 0, UINT32 top = 0)   { m_dataPos = top*BufferWidth() + left; ASSERT(m_dataPos < m_size); }
0161 #else
0162     void InitBuffPos()                  { m_dataPos = 0; }
0163 #endif
0164 
0165 private:
0166     UINT32 m_width;                 ///< width in pixels
0167     UINT32 m_height;                ///< height in pixels
0168     UINT32 m_size;                  ///< size of data buffer m_data
0169     int m_level;                    ///< recursion level
0170     Orientation m_orientation;      ///< 0=LL, 1=HL, 2=LH, 3=HH L=lowpass filtered, H=highpass filterd
0171     UINT32 m_dataPos;               ///< current position in m_data
0172     DataT* m_data;                  ///< buffer
0173 
0174 #ifdef __PGFROISUPPORT__
0175     PGFRect m_ROI;                  ///< region of interest (block aligned)
0176     UINT32  m_nTiles;               ///< number of tiles in one dimension in this subband
0177 #endif
0178 };
0179 
0180 #endif //PGF_SUBBAND_H