1
/****************************************************************************/
2
/* MPEG4 Visual Texture Coding (VTC) Mode Software */
4
/* This software was jointly developed by the following participants: */
6
/* Single-quant, multi-quant and flow control */
7
/* are provided by Sarnoff Corporation */
8
/* Iraj Sodagar (iraj@sarnoff.com) */
9
/* Hung-Ju Lee (hjlee@sarnoff.com) */
10
/* Paul Hatrack (hatrack@sarnoff.com) */
11
/* Shipeng Li (shipeng@sarnoff.com) */
12
/* Bing-Bing Chai (bchai@sarnoff.com) */
13
/* B.S. Srinivas (bsrinivas@sarnoff.com) */
15
/* Bi-level is provided by Texas Instruments */
16
/* Jie Liang (liang@ti.com) */
18
/* Shape Coding is provided by OKI Electric Industry Co., Ltd. */
19
/* Zhixiong Wu (sgo@hlabs.oki.co.jp) */
20
/* Yoshihiro Ueda (yueda@hlabs.oki.co.jp) */
21
/* Toshifumi Kanamaru (kanamaru@hlabs.oki.co.jp) */
23
/* OKI, Sharp, Sarnoff, TI and Microsoft contributed to bitstream */
24
/* exchange and bug fixing. */
27
/* In the course of development of the MPEG-4 standard, this software */
28
/* module is an implementation of a part of one or more MPEG-4 tools as */
29
/* specified by the MPEG-4 standard. */
31
/* The copyright of this software belongs to ISO/IEC. ISO/IEC gives use */
32
/* of the MPEG-4 standard free license to use this software module or */
33
/* modifications thereof for hardware or software products claiming */
34
/* conformance to the MPEG-4 standard. */
36
/* Those intending to use this software module in hardware or software */
37
/* products are advised that use may infringe existing patents. The */
38
/* original developers of this software module and their companies, the */
39
/* subsequent editors and their companies, and ISO/IEC have no liability */
40
/* and ISO/IEC have no liability for use of this software module or */
41
/* modification thereof in an implementation. */
43
/* Permission is granted to MPEG members to use, copy, modify, */
44
/* and distribute the software modules ( or portions thereof ) */
45
/* for standardization activity within ISO/IEC JTC1/SC29/WG11. */
47
/* Copyright 1995, 1996, 1997, 1998 ISO/IEC */
48
/****************************************************************************/
50
/****************************************************************************/
51
/* Texas Instruments Predictive Embedded Zerotree (PEZW) Image Codec */
52
/* Developed by Jie Liang (liang@ti.com) */
54
/* Copyright 1996, 1997, 1998 Texas Instruments */
55
/****************************************************************************/
57
/****************************************************************************
58
File name: wvtpezw_tree_decode.c
59
Author: Jie Liang (liang@ti.com)
60
Functions: Core functions for decoding the tree blocks of coeffs.
61
Revisions: v1.0 (10/04/98)
62
*****************************************************************************/
64
#include "wvtPEZW.hpp"
65
#include "PEZW_zerotree.hpp"
66
#include "wvtpezw_tree_codec.hpp"
67
#include "PEZW_functions.hpp"
69
/* decode a block of wavelet coefficients */
71
void PEZW_decode_block (WINT **coeffsBlk, Int width, Int height)
73
Int dc_hsize, dc_vsize;
74
Int i,j,k,m,n,band, hpos, vpos;
76
int hpos_start, hpos_end;
77
int vpos_start, vpos_end;
79
Int hstart, vstart,start, end;
89
dc_hsize = width>>levels;
90
dc_vsize = height>>levels;
92
/* decode the AC coefficients:
93
loop over all zerotrees */
95
for(i=0;i<dc_vsize;i++)
96
for (j=0;j<dc_hsize;j++)
97
for(band=0;band<3;band++)
99
if(band==0) { /* HL band */
103
else if (band==1) { /* LH band */
114
/* determin weighting */
115
for (lev=0;lev<levels;lev++)
122
for(m=1;m<len_tree_struct;m++){
130
fprintf(fp_debug,"\n***NEW TREE %d***", NumTree);
132
/* encoder one wavelet tree. this function demonstrates that
133
the requirement for memory is very low for this entropy coder.
134
if combined with a localized wavelet transform, the total
135
memory requirement will be extremely low. */
136
PEZW_tree_decode (band,the_wvt_tree,snr_weight);
138
/* dequantize the coefficients */
139
for(k=0;k<num_Sig;k++){
143
the_wvt_tree[n]=(SignBit>0)?m:-m;
148
fprintf(fp_debug,"\n***NEW TREE %d *****\n",NumTree);
149
fprintf(fp_debug,"%d ",the_wvt_tree[0]);
153
/* copy the data from wvt_tree to output */
154
coeffsBlk[y][x]=the_wvt_tree[0];
155
for (lev=1;lev<levels;lev++)
158
pos = level_pos[lev];
159
hstart=hpos*(1<<(lev-1));
160
vstart=vpos*(1<<(lev-1));
161
start=level_pos[lev-1];
164
for(k=start;k<end;k++)
166
hpos_start = (hstart+hloc_map[k])*2;
167
hpos_end = hpos_start+2;
168
vpos_start = (vstart+vloc_map[k])*2;
169
vpos_end = vpos_start+2;
170
for(y=vpos_start;y<vpos_end;y++)
171
for(x=hpos_start;x<hpos_end;x++){
172
coeffsBlk[y][x]=the_wvt_tree[pos++];
175
fprintf(fp_debug,"%d ",coeffsBlk[y][x]);
181
} /* end of for(lev) */
187
/* decode a tree structure */
188
void PEZW_tree_decode (int band,WINT *wvt_tree,int *snr_weight)
196
int num_ScanTree, next_numScanTree;
206
for(bplane=Max_Bitplane-1;bplane>=Min_Bitplane;bplane--){
209
fprintf(fp_debug,"\n****bitplane: %d",bplane);
211
/* determine bitplane */
213
for(i=0;i<tree_depth-spatial_leveloff;i++){
214
bitplane[i] = bplane+snr_weight[i];
215
if(bitplane[i]>=Max_Bitplane)
219
continue; /* skip this bitplane */
221
/* receive refinement bits */
222
if(bplane<Max_Bitplane-1){
223
for(i=0;i<num_Sig;i++){
227
/* context for refinement bit */
228
context = m*MAX_BITPLANE+bitplane[m];
231
// #define FLAG reach_budget[m][n] deleted by swinder
232
if(reach_budget[m][n]==1)
235
Bit=Ac_decode_symbol(&Decoder[m][bitplane[m]],
236
&model_sub[context]);
238
if( (Decoder[m][n].stream - PEZW_bitstream[m][n]) >= Init_Bufsize[m][n]+AC_offset){
239
reach_budget[m][n] = 1;
243
wvt_tree[sig_pos[i]] |= (Bit<<bitplane[m]);
247
/* form the zerotree and encode the zerotree symbols
248
and encode the sign bit for new sigifnicant coeffs
249
ScanTree: the intervals of coefficients that are
250
not descendants of zerotree roots.
251
Use ScanTree and next_ScanTree to alternate as
252
buffer, so that we do not need to spend the cycles
253
to copy from one buffer to the other.
255
numScanTree and next_numScanTrees are the number
256
of intervals that need to be looked at.
262
for(i=0;i<tree_depth-spatial_leveloff;i++){
266
fprintf(fp_debug,"\n****tree_depth %d: ",i);
269
num_ScanTree=next_numScanTree;
272
ScanTrees=next_ScanTrees;
273
next_ScanTrees=temp_ptr;
277
// #define FLAG reach_budget[i][bpos] deleted by swinder
278
if(reach_budget[i][bpos]==1)
282
for(j=0;j<num_ScanTree;j++)
283
for(k=ScanTrees[2*j];k<ScanTrees[2*j+1];k++)
285
/* decide the zerotree symbol */
286
if((prev_label[k]==IVAL)||(prev_label[k]==ZTRV)){
289
fprintf(fp_debug,"SKIP%d ", prev_label[k]);
295
/* set upt the scann tree for next level */
296
temp1=2*next_numScanTree;
297
next_ScanTrees[temp1]=level_pos[i+1]+4*(k-level_pos[i]);
298
next_ScanTrees[temp1+1]=next_ScanTrees[temp1]+4;
306
/* decode the zerotree symbol */
307
context=bpos*NumContexts*tree_depth+i*NumContexts+
308
prev_label[k]*NumBands+band;
309
label = Ac_decode_symbol(&Decoder[i][bpos],&context_model[context]);
312
if( (Decoder[i][bpos].stream - PEZW_bitstream[i][bpos]) >= Init_Bufsize[i][bpos]+AC_offset){
313
reach_budget[i][bpos] = 1;
319
fprintf(fp_debug,"%d ", label);
325
/* context for sign model */
326
context = i*MAX_BITPLANE+bpos;
328
if((label==IVAL)||(label==IZER)){
332
wvt_tree[k] |= (Bit<<bitplane[i]);
335
sig_layer[num_Sig]=i;
337
sign_bit[num_Sig]= Ac_decode_symbol(&Decoder[i][bpos],&model_sign[context]);
338
if( (Decoder[i][bpos].stream - PEZW_bitstream[i][bpos]) >= Init_Bufsize[i][bpos]+AC_offset){
339
reach_budget[i][bpos] = 1;
346
if(sign_bit[num_Sig]==1)
347
fprintf(fp_debug,"%d+ ",sign_bit[num_Sig]);
349
fprintf(fp_debug,"%d- ",sign_bit[num_Sig]);
356
/* set upt the scann tree for next level */
358
temp1=2*next_numScanTree;
359
next_ScanTrees[temp1]=level_pos[i+1]+4*(k-level_pos[i]);
360
next_ScanTrees[temp1+1]=next_ScanTrees[temp1]+4;
368
wvt_tree[k] |= (Bit<<bitplane[i]);
370
sig_layer[num_Sig]=i;
372
sign_bit[num_Sig]= Ac_decode_symbol(&Decoder[i][bpos],&model_sign[context]);
373
if( (Decoder[i][bpos].stream - PEZW_bitstream[i][bpos]) >= Init_Bufsize[i][bpos]+AC_offset){
374
reach_budget[i][bpos] = 1;
380
if(sign_bit[num_Sig]==1)
381
fprintf(fp_debug,"%d+ ",sign_bit[num_Sig]);
383
fprintf(fp_debug,"%d- ",sign_bit[num_Sig]);
391
/* set up prev_label */
393
} /* end of if(prev_label */
396
/* no subordinate none zero descendants */
400
} /* end of tree depth */
402
} /* end of bitplane */