31 #define c1 1 // best value 1 32 #define c2 2 // best value 2 41 : m_nLevels(levels + 1)
58 UINT32 loWidth = width;
59 UINT32 hiWidth = width;
60 UINT32 loHeight = height;
61 UINT32 hiHeight = height;
63 for (
int level = 0; level <
m_nLevels; level++) {
68 hiWidth = loWidth >> 1; hiHeight = loHeight >> 1;
69 loWidth = (loWidth + 1) >> 1; loHeight = (loHeight + 1) >> 1;
87 ASSERT(level >= 0 && level <
m_nLevels - 1);
88 const int destLevel = level + 1;
91 const UINT32 width = srcBand->
GetWidth();
92 const UINT32 height = srcBand->
GetHeight();
94 DataT *row0, *row1, *row2, *row3;
98 if (!
m_subband[destLevel][i].AllocMemory())
return InsufficientMemory;
103 row0 = src; row1 = row0 + width; row2 = row1 + width;
107 for (UINT32 k=0; k < width; k++) {
108 row1[k] -= ((row0[k] + row2[k] +
c1) >> 1);
109 row0[k] += ((row1[k] +
c1) >> 1);
112 row0 = row1; row1 = row2; row2 += width; row3 = row2 + width;
115 for (UINT32 i=3; i < height-1; i += 2) {
118 for (UINT32 k=0; k < width; k++) {
119 row2[k] -= ((row1[k] + row3[k] +
c1) >> 1);
120 row1[k] += ((row0[k] + row2[k] +
c2) >> 2);
123 row0 = row2; row1 = row3; row2 = row3 + width; row3 = row2 + width;
128 for (UINT32 k=0; k < width; k++) {
129 row1[k] += ((row0[k] +
c1) >> 1);
132 row0 = row1; row1 += width;
135 for (UINT32 k=0; k < width; k++) {
137 row1[k] += ((row0[k] + row2[k] +
c2) >> 2);
140 row0 = row1; row1 = row2; row2 += width;
144 row0 = src; row1 = row0 + width;
146 for (UINT32 k=0; k < height; k += 2) {
150 row0 += width << 1; row1 += width << 1;
183 src[1] -= ((src[0] + src[2] +
c1) >> 1);
184 src[0] += ((src[1] +
c1) >> 1);
187 for (; i < width-1; i += 2) {
188 src[i] -= ((src[i-1] + src[i+1] +
c1) >> 1);
189 src[i-1] += ((src[i-2] + src[i] +
c2) >> 2);
194 src[i-1] += ((src[i-2] +
c1) >> 1);
197 src[i-1] += ((src[i-2] + src[i] +
c2) >> 2);
205 const UINT32 wquot = width >> 1;
206 const bool wrem = (width & 1);
211 for (UINT32 i=0; i < wquot; i++) {
213 hl.WriteBuffer(*loRow++);
215 hh.WriteBuffer(*hiRow++);
222 for (UINT32 i=0; i < wquot; i++) {
224 hl.WriteBuffer(*loRow++);
244 ASSERT(srcLevel > 0 && srcLevel <
m_nLevels);
245 const int destLevel = srcLevel - 1;
248 UINT32 width, height;
251 if (!destBand->
AllocMemory())
return InsufficientMemory;
252 DataT *origin = destBand->
GetBuffer(), *row0, *row1, *row2, *row3;
254 #ifdef __PGFROISUPPORT__ 255 PGFRect destROI = destBand->GetAlignedROI();
256 const UINT32 destWidth = destROI.
Width();
257 const UINT32 destHeight = destROI.
Height();
262 if (destROI.
top & 1) {
267 if (destROI.
left & 1) {
274 const UINT32 leftD = destROI.
left >> 1;
275 const UINT32 left0 =
m_subband[srcLevel][
LL].GetAlignedROI().left;
276 const UINT32 left1 =
m_subband[srcLevel][
HL].GetAlignedROI().left;
277 const UINT32 topD = destROI.
top >> 1;
278 const UINT32 top0 =
m_subband[srcLevel][
LL].GetAlignedROI().top;
279 const UINT32 top1 =
m_subband[srcLevel][
LH].GetAlignedROI().top;
280 ASSERT(
m_subband[srcLevel][
LH].GetAlignedROI().left == left0);
281 ASSERT(
m_subband[srcLevel][
HH].GetAlignedROI().left == left1);
282 ASSERT(
m_subband[srcLevel][
HL].GetAlignedROI().top == top0);
283 ASSERT(
m_subband[srcLevel][
HH].GetAlignedROI().top == top1);
285 UINT32 srcOffsetX[2] = { 0, 0 };
286 UINT32 srcOffsetY[2] = { 0, 0 };
288 if (leftD >=
__max(left0, left1)) {
289 srcOffsetX[0] = leftD - left0;
290 srcOffsetX[1] = leftD - left1;
292 if (left0 <= left1) {
293 const UINT32 dx = (left1 - leftD) << 1;
297 srcOffsetX[0] = left1 - left0;
299 const UINT32 dx = (left0 - leftD) << 1;
303 srcOffsetX[1] = left0 - left1;
306 if (topD >=
__max(top0, top1)) {
307 srcOffsetY[0] = topD - top0;
308 srcOffsetY[1] = topD - top1;
311 const UINT32 dy = (top1 - topD) << 1;
313 origin += dy*destWidth;
315 srcOffsetY[0] = top1 - top0;
317 const UINT32 dy = (top0 - topD) << 1;
319 origin += dy*destWidth;
321 srcOffsetY[1] = top0 - top1;
333 PGFRect destROI(0, 0, width, height);
334 const UINT32 destWidth = width;
335 const UINT32 destHeight = height;
345 row0 = origin; row1 = row0 + destWidth;
347 for (UINT32 k = 0; k < width; k++) {
348 row0[k] -= ((row1[k] +
c1) >> 1);
352 row2 = row1 + destWidth; row3 = row2 + destWidth;
353 for (UINT32 i = destROI.
top + 2; i < destROI.
bottom - 1; i += 2) {
355 for (UINT32 k = 0; k < width; k++) {
356 row2[k] -= ((row1[k] + row3[k] +
c2) >> 2);
357 row1[k] += ((row0[k] + row2[k] +
c1) >> 1);
361 row0 = row2; row1 = row3; row2 = row1 + destWidth; row3 = row2 + destWidth;
367 for (UINT32 k = 0; k < width; k++) {
368 row2[k] -= ((row1[k] +
c1) >> 1);
369 row1[k] += ((row0[k] + row2[k] +
c1) >> 1);
374 row0 = row1; row1 = row2; row2 += destWidth;
376 for (UINT32 k = 0; k < width; k++) {
381 row0 = row1; row1 += destWidth;
385 row0 = origin; row1 = row0 + destWidth;
387 for (UINT32 k = 0; k < height; k += 2) {
391 row0 += destWidth << 1; row1 += destWidth << 1;
422 dest[0] -= ((dest[1] +
c1) >> 1);
425 for (; i < width - 1; i += 2) {
426 dest[i] -= ((dest[i-1] + dest[i+1] +
c2) >> 2);
427 dest[i-1] += ((dest[i-2] + dest[i] +
c1) >> 1);
432 dest[i] -= ((dest[i-1] +
c1) >> 1);
433 dest[i-1] += ((dest[i-2] + dest[i] +
c1) >> 1);
435 dest[i-1] += dest[i-2];
443 const UINT32 wquot = width >> 1;
444 const bool wrem = (width & 1);
449 #ifdef __PGFROISUPPORT__ 450 const bool storePos = wquot < ll.BufferWidth();
451 UINT32 llPos = 0, hlPos = 0, lhPos = 0, hhPos = 0;
456 hlPos = hl.GetBuffPos();
458 hhPos = hh.GetBuffPos();
462 for (UINT32 i=0; i < wquot; i++) {
464 *loRow++ = hl.ReadBuffer();
466 *hiRow++ = hh.ReadBuffer();
474 #ifdef __PGFROISUPPORT__ 477 ll.IncBuffRow(llPos);
478 hl.IncBuffRow(hlPos);
479 lh.IncBuffRow(lhPos);
480 hh.IncBuffRow(hhPos);
485 #ifdef __PGFROISUPPORT__ 486 const bool storePos = wquot < ll.BufferWidth();
487 UINT32 llPos = 0, hlPos = 0;
492 hlPos = hl.GetBuffPos();
496 for (UINT32 i=0; i < wquot; i++) {
498 *loRow++ = hl.ReadBuffer();
502 #ifdef __PGFROISUPPORT__ 505 ll.IncBuffRow(llPos);
506 hl.IncBuffRow(hlPos);
512 #ifdef __PGFROISUPPORT__ 513 void CWaveletTransform::SetROI(
PGFRect roi) {
525 roi.
top = (roi.
top > delta) ? roi.
top - delta : 0;
531 PGFRect& indices = m_indices[l];
532 UINT32 nTiles = GetNofTiles(l);
536 subband.SetNTiles(nTiles);
537 subband.TileIndex(
true, roi.
left, roi.
top, indices.
left, indices.
top, alignedROI.
left, alignedROI.
top);
539 subband.SetAlignedROI(alignedROI);
541 (m_indices[l-1].left >= 2*m_indices[l].left &&
542 m_indices[l-1].top >= 2*m_indices[l].top &&
543 m_indices[l-1].right <= 2*m_indices[l].right &&
544 m_indices[l-1].bottom <= 2*m_indices[l].bottom));
551 sb.SetNTiles(nTiles);
552 sb.TilePosition(indices.
left, indices.
top, aroi.
left, aroi.
top, w, h);
556 sb.SetAlignedROI(aroi);
561 roi.
top = alignedROI.
top >> 1;
567 #endif // __PGFROISUPPORT__
void Initialize(UINT32 width, UINT32 height, int level, Orientation orient)
UINT32 GetBuffPos() const
#define MaxLevel
maximum number of transform levels
void FreeMemory()
Delete the memory buffer of this subband.
void Quantize(int quantParam)
void WriteBuffer(DataT val)
#define NSubbands
number of subbands per level