31 #define c1 1 // best value 1
32 #define c2 2 // best value 2
46 #ifdef __PGFROISUPPORT__
47 m_ROIindices.SetLevels(levels + 1);
60 UINT32 loWidth =
width;
61 UINT32 hiWidth =
width;
70 hiWidth = loWidth >> 1; hiHeight = loHeight >> 1;
71 loWidth = (loWidth + 1) >> 1; loHeight = (loHeight + 1) >> 1;
88 OSError CWaveletTransform::ForwardTransform(
int level,
int quant) {
90 const int destLevel = level + 1;
93 const UINT32
width = srcBand->GetWidth();
94 const UINT32
height = srcBand->GetHeight();
96 DataT *row0, *row1, *row2, *row3;
100 if (!
m_subband[destLevel][i].AllocMemory())
return InsufficientMemory;
106 row0 = src; row1 = row0 +
width; row2 = row1 +
width;
111 row1[
k] -= ((row0[
k] + row2[
k] +
c1) >> 1);
112 row0[
k] += ((row1[
k] +
c1) >> 1);
115 row0 = row1; row1 = row2; row2 +=
width; row3 = row2 +
width;
118 for (UINT32 i=3; i < height-1; i += 2) {
122 row2[
k] -= ((row1[
k] + row3[
k] +
c1) >> 1);
123 row1[
k] += ((row0[
k] + row2[
k] +
c2) >> 2);
126 row0 = row2; row1 = row3; row2 = row3 +
width; row3 = row2 +
width;
132 row1[
k] += ((row0[
k] +
c1) >> 1);
135 row0 = row1; row1 +=
width;
140 row1[
k] += ((row0[
k] + row2[
k] +
c2) >> 2);
143 row0 = row1; row1 = row2; row2 +=
width;
147 row0 = src; row1 = row0 +
width;
153 row0 += width << 1; row1 += width << 1;
186 src[1] -= ((src[0] + src[2] +
c1) >> 1);
187 src[0] += ((src[1] +
c1) >> 1);
190 for (; i < width-1; i += 2) {
191 src[i] -= ((src[i-1] + src[i+1] +
c1) >> 1);
192 src[i-1] += ((src[i-2] + src[i] +
c2) >> 2);
197 src[i-1] += ((src[i-2] +
c1) >> 1);
200 src[i-1] += ((src[i-2] + src[i] +
c2) >> 2);
208 const UINT32 wquot = width >> 1;
209 const bool wrem = width & 1;
214 for (UINT32 i=0; i < wquot; i++) {
216 hl.WriteBuffer(*loRow++);
218 hh.WriteBuffer(*hiRow++);
225 for (UINT32 i=0; i < wquot; i++) {
227 hl.WriteBuffer(*loRow++);
245 OSError CWaveletTransform::InverseTransform(
int srcLevel, UINT32* w, UINT32* h,
DataT**
data) {
247 const int destLevel = srcLevel - 1;
253 if (!destBand->
AllocMemory())
return InsufficientMemory;
254 DataT *dest = destBand->
GetBuffer(), *origin = dest, *row0, *row1, *row2, *row3;
256 #ifdef __PGFROISUPPORT__
257 PGFRect destROI = destBand->GetROI();
258 width = destROI.
Width();
259 height = destROI.
Height();
260 const UINT32 destWidth =
width;
261 const UINT32 destHeight =
height;
264 if (destROI.
top & 1) {
269 if (destROI.
left & 1) {
277 UINT32 left = (destROI.
left >> 1) -
m_subband[srcLevel][i].GetROI().left;
278 UINT32 top = (destROI.
top >> 1) -
m_subband[srcLevel][i].GetROI().top;
282 width = destBand->GetWidth();
283 height = destBand->GetHeight();
284 PGFRect destROI(0, 0, width, height);
285 const UINT32 destWidth =
width;
286 const UINT32 destHeight =
height;
296 row0 = origin; row1 = row0 + destWidth;
299 row0[
k] -= ((row1[
k] +
c1) >> 1);
303 row2 = row1 + destWidth; row3 = row2 + destWidth;
304 for (UINT32 i=destROI.
top + 2; i < destROI.
bottom - 1; i += 2) {
307 row2[
k] -= ((row1[
k] + row3[
k] +
c2) >> 2);
308 row1[
k] += ((row0[
k] + row2[
k] +
c1) >> 1);
312 row0 = row2; row1 = row3; row2 = row1 + destWidth; row3 = row2 + destWidth;
319 row2[
k] -= ((row1[
k] +
c1) >> 1);
320 row1[
k] += ((row0[
k] + row2[
k] +
c1) >> 1);
325 row0 = row1; row1 = row2; row2 += destWidth;
332 row0 = row1; row1 += destWidth;
336 row0 = origin; row1 = row0 + destWidth;
342 row0 += destWidth << 1; row1 += destWidth << 1;
372 dest[0] -= ((dest[1] +
c1) >> 1);
375 for (; i < width - 1; i += 2) {
376 dest[i] -= ((dest[i-1] + dest[i+1] +
c2) >> 2);
377 dest[i-1] += ((dest[i-2] + dest[i] +
c1) >> 1);
382 dest[i] -= ((dest[i-1] +
c1) >> 1);
383 dest[i-1] += ((dest[i-2] + dest[i] +
c1) >> 1);
385 dest[i-1] += dest[i-2];
393 const UINT32 wquot = width >> 1;
394 const bool wrem = width & 1;
399 #ifdef __PGFROISUPPORT__
400 const bool storePos = wquot < ll.BufferWidth();
401 UINT32 llPos = 0, hlPos = 0, lhPos = 0, hhPos = 0;
406 hlPos = hl.GetBuffPos();
408 hhPos = hh.GetBuffPos();
412 for (UINT32 i=0; i < wquot; i++) {
414 *loRow++ = hl.ReadBuffer();
416 *hiRow++ = hh.ReadBuffer();
424 #ifdef __PGFROISUPPORT__
427 ll.IncBuffRow(llPos);
428 hl.IncBuffRow(hlPos);
429 lh.IncBuffRow(lhPos);
430 hh.IncBuffRow(hhPos);
435 #ifdef __PGFROISUPPORT__
436 const bool storePos = wquot < ll.BufferWidth();
437 UINT32 llPos = 0, hlPos = 0;
442 hlPos = hl.GetBuffPos();
446 for (UINT32 i=0; i < wquot; i++) {
448 *loRow++ = hl.ReadBuffer();
452 #ifdef __PGFROISUPPORT__
455 ll.IncBuffRow(llPos);
456 hl.IncBuffRow(hlPos);
462 #ifdef __PGFROISUPPORT__
466 void CWaveletTransform::SetROI(
const PGFRect& rect) {
468 m_ROIindices.CreateIndices();
478 const PGFRect& indices = m_ROIindices.GetIndices(i);
483 subband.SetNTiles(m_ROIindices.GetNofTiles(i));
484 subband.TilePosition(indices.
left, indices.
top, r.
left, r.
top, w, h);
496 void CRoiIndices::CreateIndices() {
510 void CRoiIndices::ComputeTileIndex(UINT32 width, UINT32 height, UINT32
pos,
bool horizontal,
bool isMin) {
514 UINT32 tileIndex = 0;
515 UINT32 tileMin = 0, tileMax = (horizontal) ? width : height;
519 for (
int i=m_nLevels - 1; i >= 0; i--) {
523 m_indices[i].left = tileIndex;
525 m_indices[i].right = tileIndex + 1;
529 m_indices[i].top = tileIndex;
531 m_indices[i].bottom = tileIndex + 1;
537 m = (tileMin + tileMax)/2;
552 void CRoiIndices::ComputeIndices(UINT32 width, UINT32 height,
const PGFRect& rect) {
553 ComputeTileIndex(width, height, rect.
left,
true,
true);
554 ComputeTileIndex(width, height, rect.
top,
false,
true);
555 ComputeTileIndex(width, height, rect.
right,
true,
false);
556 ComputeTileIndex(width, height, rect.
bottom,
false,
false);
559 #endif // __PGFROISUPPORT__