libpgf  6.11.42
PGF - Progressive Graphics File
CSubband Class Reference

Wavelet channel class. More...

#include <Subband.h>

List of all members.

Public Member Functions

 CSubband ()
 ~CSubband ()
bool AllocMemory ()
void FreeMemory ()
void ExtractTile (CEncoder &encoder, bool tile=false, UINT32 tileX=0, UINT32 tileY=0) THROW_
void PlaceTile (CDecoder &decoder, int quantParam, bool tile=false, UINT32 tileX=0, UINT32 tileY=0) THROW_
void Quantize (int quantParam)
void Dequantize (int quantParam)
void SetData (UINT32 pos, DataT v)
DataTGetBuffer ()
DataT GetData (UINT32 pos) const
int GetLevel () const
int GetHeight () const
int GetWidth () const
Orientation GetOrientation () const
UINT32 BufferWidth () const
void IncBuffRow (UINT32 pos)

Private Member Functions

void Initialize (UINT32 width, UINT32 height, int level, Orientation orient)
void WriteBuffer (DataT val)
void SetBuffer (DataT *b)
DataT ReadBuffer ()
UINT32 GetBuffPos () const
void TilePosition (UINT32 tileX, UINT32 tileY, UINT32 &left, UINT32 &top, UINT32 &w, UINT32 &h) const
void SetROI (CROIs *roi)
void InitBuffPos (UINT32 left=0, UINT32 top=0)

Private Attributes

UINT32 m_width
 width in pixels
UINT32 m_height
 height in pixels
UINT32 m_size
 size of data buffer m_data
int m_level
 recursion level
Orientation m_orientation
 0=LL, 1=HL, 2=LH, 3=HH L=lowpass filtered , H=highpass filterd
UINT32 m_dataPos
 current position in m_data
DataTm_data
 buffer
CROIsm_ROIs
 ROI information.
UINT32 m_dataWidth
 row width of the data buffer

Friends

class CWaveletTransform

Detailed Description

Wavelet channel class.

PGF wavelet channel subband class.

Author:
C. Stamm, R. Spuler

Definition at line 42 of file Subband.h.


Constructor & Destructor Documentation

CSubband::CSubband ( )

Standard constructor.

Definition at line 35 of file Subband.cpp.

                   : m_size(0), m_data(0)
#ifdef __PGFROISUPPORT__
, m_ROIs(0), m_dataWidth(0) 
#endif
{
}
CSubband::~CSubband ( )

Destructor.

Definition at line 44 of file Subband.cpp.

                    {
        FreeMemory();
}

Member Function Documentation

bool CSubband::AllocMemory ( )

Allocate a memory buffer to store all wavelet coefficients of this subband.

Returns:
True if the allocation did work without any problems

Definition at line 68 of file Subband.cpp.

                           {
        UINT32 oldSize = m_size;

#ifdef __PGFROISUPPORT__
        if (m_ROIs) {
                // reset dataWidth and size
                const PGFRect& roi = m_ROIs->GetROI(m_level);
                m_dataWidth = __min(m_width, roi.right) - roi.left;
                ASSERT(m_dataWidth > 0);
                m_size = m_dataWidth*(__min(m_height, roi.bottom) - roi.top);
        }
#endif
        ASSERT(m_size > 0);

        if (m_data) {
                if (oldSize >= m_size) {
                        return true;
                } else {
                        delete[] m_data;
                        m_data = new(std::nothrow) DataT[m_size];
                        return (m_data != 0);
                }
        } else {
                m_data = new(std::nothrow) DataT[m_size];
                return (m_data != 0);
        }
}
UINT32 CSubband::BufferWidth ( ) const [inline]

Return data buffer line width.

Definition at line 140 of file Subband.h.

{ return m_dataWidth; }
void CSubband::Dequantize ( int  quantParam)

Perform subband dequantization with given quantization parameter. A scalar quantization (with dead-zone) is used. A large quantization value results in strong quantization and therefore in big quality loss.

Parameters:
quantParamA quantization parameter (larger or equal to 0)

Definition at line 151 of file Subband.cpp.

                                        {
        if (m_orientation == LL) {
                quantParam -= m_level + 1;
        } else if (m_orientation == HH) {
                quantParam -= m_level - 1;
        } else {
                quantParam -= m_level;
        }
        if (quantParam > 0) {
                for (UINT32 i=0; i < m_size; i++) {
                        m_data[i] <<= quantParam;
                }
        }
}
void CSubband::ExtractTile ( CEncoder encoder,
bool  tile = false,
UINT32  tileX = 0,
UINT32  tileY = 0 
)

Extracts a rectangular subregion of this subband. Write wavelet coefficients into buffer. It might throw an IOException.

Parameters:
encoderAn encoder instance
quantA quantization value (linear scalar quantization)
tileTrue if just a rectangular region is extracted, false if the entire subband is extracted.
tileXTile index in x-direction
tileYTile index in y-direction

Extracts a rectangular subregion of this subband. Write wavelet coefficients into buffer. It might throw an IOException.

Parameters:
encoderAn encoder instance
tileTrue if just a rectangular region is extracted, false if the entire subband is extracted.
tileXTile index in x-direction
tileYTile index in y-direction

Definition at line 174 of file Subband.cpp.

                                                                                                {
#ifdef __PGFROISUPPORT__
        if (tile) {
                // compute tile position and size
                UINT32 xPos, yPos, w, h;
                TilePosition(tileX, tileY, xPos, yPos, w, h);

                // write values into buffer using partitiong scheme
                encoder.Partition(this, w, h, xPos + yPos*m_width, m_width);
        } else 
#endif
        {
                // write values into buffer using partitiong scheme
                encoder.Partition(this, m_width, m_height, 0, m_width);
        }
}
void CSubband::FreeMemory ( )

Delete the memory buffer of this subband.

Definition at line 98 of file Subband.cpp.

                          {
        if (m_data) {
                delete[] m_data; m_data = 0;
        }
}
DataT* CSubband::GetBuffer ( ) [inline]

Get a pointer to an array of all wavelet coefficients of this subband.

Returns:
Pointer to array of wavelet coefficients

Definition at line 107 of file Subband.h.

{ return m_data; }
UINT32 CSubband::GetBuffPos ( ) const [inline, private]

Definition at line 155 of file Subband.h.

{ return m_dataPos; }
DataT CSubband::GetData ( UINT32  pos) const [inline]

Return wavelet coefficient at given position.

Parameters:
posA subband position (>= 0)
Returns:
Wavelet coefficient

Definition at line 113 of file Subband.h.

{ ASSERT(pos < m_size); return m_data[pos]; }
int CSubband::GetHeight ( ) const [inline]

Return height of this subband.

Returns:
Height of this subband (in pixels)

Definition at line 123 of file Subband.h.

{ return m_height; }
int CSubband::GetLevel ( ) const [inline]

Return level of this subband.

Returns:
Level of this subband

Definition at line 118 of file Subband.h.

{ return m_level; }
Orientation CSubband::GetOrientation ( ) const [inline]

Return orientation of this subband. LL LH HL HH

Returns:
Orientation of this subband (LL, HL, LH, HH)

Definition at line 135 of file Subband.h.

{ return m_orientation; }
int CSubband::GetWidth ( ) const [inline]

Return width of this subband.

Returns:
Width of this subband (in pixels)

Definition at line 128 of file Subband.h.

{ return m_width; }
void CSubband::IncBuffRow ( UINT32  pos) [inline]

Set data buffer position to given position + one row.

Parameters:
posGiven position

Definition at line 145 of file Subband.h.

{ m_dataPos = pos + m_dataWidth; }
void CSubband::InitBuffPos ( UINT32  left = 0,
UINT32  top = 0 
) [inline, private]

Definition at line 161 of file Subband.h.

{ m_dataPos = top*m_dataWidth + left; ASSERT(m_dataPos < m_size); }
void CSubband::Initialize ( UINT32  width,
UINT32  height,
int  level,
Orientation  orient 
) [private]

Definition at line 50 of file Subband.cpp.

                                                                                    {
        m_width = width;
        m_height = height;
        m_size = m_width*m_height;
        m_level = level;
        m_orientation = orient;
        m_data = 0;
        m_dataPos = 0;
#ifdef __PGFROISUPPORT__
        m_ROIs = 0;
        m_dataWidth = width;
#endif
}
void CSubband::PlaceTile ( CDecoder decoder,
int  quantParam,
bool  tile = false,
UINT32  tileX = 0,
UINT32  tileY = 0 
)

Decoding and dequantization of this subband. It might throw an IOException.

Parameters:
decoderA decoder instance
quantParamDequantization value
tileTrue if just a rectangular region is placed, false if the entire subband is placed.
tileXTile index in x-direction
tileYTile index in y-direction

Definition at line 199 of file Subband.cpp.

                                                                                                              {
        // allocate memory
        if (!AllocMemory()) ReturnWithError(InsufficientMemory);

        // correct quantParam with normalization factor
        if (m_orientation == LL) {
                quantParam -= m_level + 1;
        } else if (m_orientation == HH) {
                quantParam -= m_level - 1;
        } else {
                quantParam -= m_level;
        }
        if (quantParam < 0) quantParam = 0;

#ifdef __PGFROISUPPORT__
        if (tile) {
                // compute tile position and size
                const PGFRect& roi = m_ROIs->GetROI(m_level);
                UINT32 xPos, yPos, w, h;
                TilePosition(tileX, tileY, xPos, yPos, w, h);

                // read values into buffer using partitiong scheme
                decoder.Partition(this, quantParam, w, h, (xPos - roi.left) + (yPos - roi.top)*m_dataWidth, m_dataWidth);
        } else 
#endif
        {
                // read values into buffer using partitiong scheme
                decoder.Partition(this, quantParam, m_width, m_height, 0, m_width);
        }
}
void CSubband::Quantize ( int  quantParam)

Perform subband quantization with given quantization parameter. A scalar quantization (with dead-zone) is used. A large quantization value results in strong quantization and therefore in big quality loss.

Parameters:
quantParamA quantization parameter (larger or equal to 0)

Definition at line 109 of file Subband.cpp.

                                      {
        if (m_orientation == LL) {
                quantParam -= (m_level + 1);
                // uniform rounding quantization
                if (quantParam > 0) {
                        quantParam--;
                        for (UINT32 i=0; i < m_size; i++) {
                                if (m_data[i] < 0) {
                                        m_data[i] = -(((-m_data[i] >> quantParam) + 1) >> 1);
                                } else {
                                        m_data[i] = ((m_data[i] >> quantParam) + 1) >> 1;
                                }
                        }
                }
        } else {
                if (m_orientation == HH) {
                        quantParam -= (m_level - 1);
                } else {
                        quantParam -= m_level;
                }
                // uniform deadzone quantization
                if (quantParam > 0) {
                        int threshold = ((1 << quantParam) * 7)/5;      // good value
                        quantParam--;
                        for (UINT32 i=0; i < m_size; i++) {
                                if (m_data[i] < -threshold) {
                                        m_data[i] = -(((-m_data[i] >> quantParam) + 1) >> 1);
                                } else if (m_data[i] > threshold) {
                                        m_data[i] = ((m_data[i] >> quantParam) + 1) >> 1;
                                } else {
                                        m_data[i] = 0;
                                }
                        }
                }
        }
}
DataT CSubband::ReadBuffer ( ) [inline, private]

Definition at line 153 of file Subband.h.

{ ASSERT(m_dataPos < m_size); return m_data[m_dataPos++]; }
void CSubband::SetBuffer ( DataT b) [inline, private]

Definition at line 152 of file Subband.h.

{ ASSERT(b); m_data = b; }
void CSubband::SetData ( UINT32  pos,
DataT  v 
) [inline]

Store wavelet coefficient in subband at given position.

Parameters:
posA subband position (>= 0)
vA wavelet coefficient

Definition at line 102 of file Subband.h.

{ ASSERT(pos < m_size); m_data[pos] = v; }
void CSubband::SetROI ( CROIs roi) [inline, private]

Definition at line 160 of file Subband.h.

{ ASSERT(roi); m_ROIs = roi; }
void CSubband::TilePosition ( UINT32  tileX,
UINT32  tileY,
UINT32 &  xPos,
UINT32 &  yPos,
UINT32 &  w,
UINT32 &  h 
) const [private]

Compute tile position and size.

Parameters:
tileXTile index in x-direction
tileYTile index in y-direction
xPos[out] Offset to left
yPos[out] Offset to top
w[out] Tile width
h[out] Tile height

Definition at line 241 of file Subband.cpp.

                                                                                                              {
        // example
        // band = HH, w = 30, ldTiles = 2 -> 4 tiles in a row/column
        // --> tile widths
        // 8 7 8 7
        // 
        // tile partitioning scheme
        // 0 1 2 3
        // 4 5 6 7
        // 8 9 A B
        // C D E F

        UINT32 nTiles = m_ROIs->GetNofTiles(m_level);
        ASSERT(tileX < nTiles); ASSERT(tileY < nTiles);
        UINT32 m;
        UINT32 left = 0, right = nTiles;
        UINT32 top = 0, bottom = nTiles;

        xPos = 0;
        yPos = 0;
        w = m_width;
        h = m_height;

        while (nTiles > 1) {
                // compute xPos and w with binary search
                m = (left + right) >> 1;
                if (tileX >= m) {
                        xPos += (w + 1) >> 1;
                        w >>= 1;
                        left = m;
                } else {
                        w = (w + 1) >> 1;
                        right = m;
                }
                // compute yPos and h with binary search
                m = (top + bottom) >> 1;
                if (tileY >= m) {
                        yPos += (h + 1) >> 1;
                        h >>= 1;
                        top = m;
                } else {
                        h = (h + 1) >> 1;
                        bottom = m;
                }
                nTiles >>= 1;
        }
        ASSERT(xPos < m_width && (xPos + w <= m_width));
        ASSERT(yPos < m_height && (yPos + h <= m_height));
}
void CSubband::WriteBuffer ( DataT  val) [inline, private]

Definition at line 151 of file Subband.h.

{ ASSERT(m_dataPos < m_size); m_data[m_dataPos++] = val; }

Friends And Related Function Documentation

friend class CWaveletTransform [friend]

Definition at line 43 of file Subband.h.


Member Data Documentation

DataT* CSubband::m_data [private]

buffer

Definition at line 182 of file Subband.h.

UINT32 CSubband::m_dataPos [private]

current position in m_data

Definition at line 181 of file Subband.h.

UINT32 CSubband::m_dataWidth [private]

row width of the data buffer

Definition at line 186 of file Subband.h.

UINT32 CSubband::m_height [private]

height in pixels

Definition at line 177 of file Subband.h.

int CSubband::m_level [private]

recursion level

Definition at line 179 of file Subband.h.

0=LL, 1=HL, 2=LH, 3=HH L=lowpass filtered , H=highpass filterd

Definition at line 180 of file Subband.h.

CROIs* CSubband::m_ROIs [private]

ROI information.

Definition at line 185 of file Subband.h.

UINT32 CSubband::m_size [private]

size of data buffer m_data

Definition at line 178 of file Subband.h.

UINT32 CSubband::m_width [private]

width in pixels

Definition at line 176 of file Subband.h.


The documentation for this class was generated from the following files: