8template<
typename EntropyCodec>
10 size_t number_of_contexts,
14 EntropyCodec(subband_byteio,number_of_contexts),
17 m_node(band_list(band_num)),
18 m_last_qf_idx(m_node.QuantIndex())
26template<
typename EntropyCodec>
34 bool code_skip = (block_list.
LengthX() > 1 || block_list.
LengthY() > 1);
36 for (
int j=block_list.
FirstY() ; j<=block_list.
LastY() ; ++j)
39 for (
int i=block_list.
FirstX() ; i<=block_list.
LastX() ; ++i)
43 if ( !block[i].Skipped() )
44 CodeCoeffBlock( block[i] , in_data );
46 ClearBlock (block[i] , in_data);
52template<
typename EntropyCodec>
57 const int xbeg = code_block.
Xstart();
58 const int ybeg = code_block.
Ystart();
59 const int xend = code_block.
Xend();
60 const int yend = code_block.
Yend();
64 bool has_parent = m_node.Parent() != 0;
66 if ( m_node.UsingMultiQuants() )
68 CodeQuantIndexOffset( qf_idx - m_last_qf_idx);
69 m_last_qf_idx = qf_idx;
72 m_qf = dirac_quantiser_lists.QuantFactor4( qf_idx );
74 m_offset = dirac_quantiser_lists.IntraQuantOffset4( qf_idx );
76 m_offset = dirac_quantiser_lists.InterQuantOffset4( qf_idx );
78 for (
int ypos=ybeg; ypos<yend ;++ypos)
80 m_pypos=(( ypos-m_node.Yp() )>>1)+m_pnode.Yp();
81 for (
int xpos=xbeg; xpos<xend ;++xpos)
83 m_pxpos=(( xpos-m_node.Xp() )>>1)+m_pnode.Xp();
85 m_nhood_nonzero =
false;
86 if (ypos > m_node.Yp())
87 m_nhood_nonzero |=
bool(in_data[ypos-1][xpos]);
88 if (xpos > m_node.Xp())
89 m_nhood_nonzero |=
bool(in_data[ypos][xpos-1]);
90 if (ypos > m_node.Yp() && xpos > m_node.Xp())
91 m_nhood_nonzero |=
bool(in_data[ypos-1][xpos-1]);
94 m_parent_notzero =
static_cast<bool> ( in_data[m_pypos][m_pxpos] );
96 m_parent_notzero =
false;
98 CodeCoeff( in_data , xpos , ypos );
105template<
typename EntropyCodec>
108 CodeVal( in_data , xpos , ypos , in_data[ypos][xpos] );
130template<
typename EntropyCodec>
136 unsigned int abs_val( std::abs(val) );
140 const int N = abs_val+1;
141 int num_follow_zeroes=0;
143 while ( N >= (1<<num_follow_zeroes) )
147 for (
int i=num_follow_zeroes-1, c=1; i>=0; --i, ++c )
149 EntropyCodec::EncodeSymbol( 0, ChooseFollowContext( c ) );
150 EntropyCodec::EncodeSymbol( N&(1<<i), ChooseInfoContext() );
152 EntropyCodec::EncodeSymbol( 1, ChooseFollowContext( num_follow_zeroes+1 ) );
154 in_data[ypos][xpos] =
static_cast<CoeffType>( abs_val );
159 in_data[ypos][xpos] *= m_qf;
160 in_data[ypos][xpos] += m_offset+2;
161 in_data[ypos][xpos] >>= 2;
165 EntropyCodec::EncodeSymbol( 0 , ChooseSignContext( in_data , xpos , ypos ) );
169 EntropyCodec::EncodeSymbol( 1 , ChooseSignContext( in_data , xpos , ypos ) );
170 in_data[ypos][xpos] = -in_data[ypos][xpos];
175template<
typename EntropyCodec>
179 const int abs_val = std::abs( offset );
182 int num_follow_zeroes=0;
184 while ( N>= (1<<num_follow_zeroes) )
188 for (
int i=num_follow_zeroes-1, c=1; i>=0; --i, ++c )
204template<
typename EntropyCodec>
211 bool decode_skip= (block_list.
LengthX() > 1 || block_list.
LengthY() > 1);
213 for (
int j=block_list.
FirstY() ; j<=block_list.
LastY() ; ++j)
216 for (
int i=block_list.
FirstX() ; i<=block_list.
LastX() ; ++i)
220 if ( !block[i].Skipped() )
221 DecodeCoeffBlock( block[i] , out_data );
223 ClearBlock (block[i] , out_data);
230template<
typename EntropyCodec>
235 const int xbeg = code_block.
Xstart();
236 const int ybeg = code_block.
Ystart();
237 const int xend = code_block.
Xend();
238 const int yend = code_block.
Yend();
240 int qf_idx = m_node.QuantIndex();
242 bool has_parent = m_node.Parent() != 0;
244 if ( m_node.UsingMultiQuants() )
246 qf_idx = m_last_qf_idx+DecodeQuantIndexOffset();
247 m_last_qf_idx = qf_idx;
250 if (qf_idx > (
int)dirac_quantiser_lists.MaxQuantIndex())
252 std::ostringstream errstr;
253 errstr <<
"Quantiser index out of range [0.."
254 << (int)dirac_quantiser_lists.MaxQuantIndex() <<
"]";
261 m_qf = dirac_quantiser_lists.QuantFactor4( qf_idx );
264 m_offset = dirac_quantiser_lists.IntraQuantOffset4( qf_idx );
266 m_offset = dirac_quantiser_lists.InterQuantOffset4( qf_idx );
270 for (
int ypos=ybeg; ypos<yend ;++ypos)
272 m_pypos=(( ypos-m_node.Yp() )>>1)+m_pnode.Yp();
275 p_out_data = out_data[m_pypos];
277 if (ypos!=m_node.Yp())
278 c_out_data_1 = out_data[ypos-1];
279 CoeffType *c_out_data_2 = out_data[ypos];
280 for (
int xpos=xbeg; xpos<xend ;++xpos)
282 m_pxpos=(( xpos-m_node.Xp() )>>1)+m_pnode.Xp();
284 m_nhood_nonzero =
false;
287 if (ypos > m_node.Yp())
288 m_nhood_nonzero |=
bool(c_out_data_1[xpos]);
289 if (xpos > m_node.Xp())
290 m_nhood_nonzero |=
bool(c_out_data_2[xpos-1]);
291 if (ypos > m_node.Yp() && xpos > m_node.Xp())
292 m_nhood_nonzero |=
bool(c_out_data_1[xpos-1]);
295 m_parent_notzero = ( p_out_data[m_pxpos] != 0 );
297 m_parent_notzero =
false;
299 DecodeCoeff( out_data , xpos , ypos );
305template<
typename EntropyCodec>
308 DecodeVal( in_data , xpos , ypos );
329template<
typename EntropyCodec>
333 CoeffType& out_pixel = out_data[ypos][xpos];
338 while ( !EntropyCodec::DecodeSymbol( ChooseFollowContext( bit_count ) ) )
341 out_pixel |= EntropyCodec::DecodeSymbol( ChooseInfoContext() );
349 out_pixel += m_offset+2;
352 if ( EntropyCodec::DecodeSymbol( ChooseSignContext(out_data, xpos, ypos)) )
353 out_pixel = -out_pixel;
357template<
typename EntropyCodec>
362 if (!m_parent_notzero)
364 switch ( bin_number )
367 if(m_nhood_nonzero ==
false)
386 switch ( bin_number )
389 if(m_nhood_nonzero ==
false)
412template<
typename EntropyCodec>
418template<
typename EntropyCodec>
421 if ( m_node.Yp()==0 && m_node.Xp()!=0 )
428 if (data[ypos-1][xpos]>0)
430 else if (data[ypos-1][xpos]<0)
436 else if ( m_node.Xp()==0 && m_node.Yp()!=0 )
443 if ( data[ypos][xpos-1] > 0 )
445 else if ( data[ypos][xpos-1] < 0 )
455template<
typename EntropyCodec>
475template<
typename EntropyCodec>
478 for (
int j=code_block.
Ystart() ; j<code_block.
Yend() ; j++)
480 for (
int i=code_block.
Xstart() ; i<code_block.
Xend() ; i++)
482 pic_data[j][i] = val;
487template<
typename EntropyCodec>
490 for (
int j=code_block.
Ystart() ; j<code_block.
Yend() ; j++)
499template<
typename EntropyCodec>
504 for (
int ypos=code_block.
Ystart() ; ypos<code_block.
Yend() ; ++ypos)
506 for (
int xpos=code_block.
Xstart() ; xpos<code_block.
Xend() ; ++xpos)
508 out_data[ypos][xpos] += GetPrediction( out_data , xpos , ypos );
517template<
typename EntropyCodec>
520 for (
int ypos=code_block.
Ystart() ; ypos<code_block.
Yend() ; ++ypos)
522 for (
int xpos=code_block.
Xstart() ; xpos<code_block.
Xend() ; ++xpos)
525 coeff_data[ypos][xpos] = GetPrediction( coeff_data , xpos , ypos );
530template<
typename EntropyCodec>
541 int sum = data[ypos][xpos-1] + data[ypos-1][xpos-1] + data[ypos-1][xpos] + 3/2;
548 return data[ypos - 1][0];
553 return data[0][xpos - 1];
#define DIRAC_THROW_EXCEPTION(arg1, arg2, arg3)
Construct an exception from 3 arguments, log it, and throw it.
Definition: dirac_exception.h:196
Definition of class SequenceHeaderByteIO.
Definition: accessunit_byteio.h:52
int CoeffType
Type of wavelet coefficient data (should be larger than ValueType)
Definition: common.h:74
@ SEVERITY_PICTURE_ERROR
Definition: dirac_exception.h:78
@ NZ_FBIN2_CTX
Definition: common.h:113
@ Z_FBIN4_CTX
Definition: common.h:107
@ INFO_CTX
Definition: common.h:120
@ NZ_FBIN5_CTX
Definition: common.h:116
@ SIGN_POS_CTX
Definition: common.h:99
@ Z_FBIN2_CTX
Definition: common.h:105
@ Z_FBIN1nz_CTX
Definition: common.h:104
@ NZ_FBIN6plus_CTX
Definition: common.h:117
@ Q_OFFSET_SIGN_CTX
Definition: common.h:125
@ NZ_FBIN1nz_CTX
Definition: common.h:112
@ NZ_FBIN3_CTX
Definition: common.h:114
@ NZ_FBIN4_CTX
Definition: common.h:115
@ NZ_FBIN1z_CTX
Definition: common.h:111
@ SIGN0_CTX
Definition: common.h:98
@ SIGN_NEG_CTX
Definition: common.h:100
@ Z_FBIN1z_CTX
Definition: common.h:103
@ Z_FBIN5_CTX
Definition: common.h:108
@ Q_OFFSET_FOLLOW_CTX
Definition: common.h:123
@ BLOCK_SKIP_CTX
Definition: common.h:122
@ Z_FBIN3_CTX
Definition: common.h:106
@ Q_OFFSET_INFO_CTX
Definition: common.h:124
@ Z_FBIN6plus_CTX
Definition: common.h:109
@ ERR_UNSUPPORTED_STREAM_DATA
Definition: dirac_exception.h:59
Subband Dirac-bytestream input/output.
Definition: subband_byteio.h:57
A template class for two-dimensional arrays.
Definition: arrays.h:285
int LengthX() const
Returns the width.
Definition: arrays.h:362
int LastX() const
Returns the index of the last element of a row.
Definition: arrays.h:374
int LastY() const
Returns the index of the first element of a column.
Definition: arrays.h:377
int FirstX() const
Returns the index of the first element of a row.
Definition: arrays.h:368
int LengthY() const
Returns the height.
Definition: arrays.h:365
int FirstY() const
Returns the index of the first element of a column.
Definition: arrays.h:371
A template class for coding and decoding wavelet subband data.
Definition: band_codec.h:59
virtual void DecodeCoeffBlock(const CodeBlock &code_block, CoeffArray &out_data)
Definition: band_codec_template.h:231
virtual void CodeCoeff(CoeffArray &in_data, const int xpos, const int ypos)
Definition: band_codec_template.h:106
int ChooseSignContext(const CoeffArray &data, const int xpos, const int ypos) const
A function for choosing the context for sign bits.
Definition: band_codec_template.h:419
const Subband m_node
the subband being coded
Definition: band_codec.h:133
void CodeQuantIndexOffset(const int offset)
Encode the offset for a code block quantiser.
Definition: band_codec_template.h:176
int DecodeQuantIndexOffset()
Decode the offset for a code block quantiser.
Definition: band_codec_template.h:456
int ChooseInfoContext() const
A function for choosing the context for "information bits".
Definition: band_codec_template.h:413
void DecodeVal(CoeffArray &out_data, const int xpos, const int ypos)
Decode an individual quantised value and perform inverse-quantisation.
Definition: band_codec_template.h:330
virtual void CodeCoeffBlock(const CodeBlock &code_block, CoeffArray &in_data)
Definition: band_codec_template.h:53
Subband m_pnode
the parent subband
Definition: band_codec.h:148
virtual void ClearBlock(const CodeBlock &code_block, CoeffArray &coeff_data)
Set all block values to 0.
Definition: band_codec_template.h:488
virtual void DoWorkCode(CoeffArray &in_data)
Definition: band_codec_template.h:27
void SetToVal(const CodeBlock &code_block, CoeffArray &coeff_data, const CoeffType val)
Set a code block area to a given value.
Definition: band_codec_template.h:476
virtual void DecodeCoeff(CoeffArray &in_data, const int xpos, const int ypos)
Definition: band_codec_template.h:306
int ChooseFollowContext(const int bin_number) const
A function for choosing the context for "follow bits".
Definition: band_codec_template.h:358
void CodeVal(CoeffArray &in_data, const int xpos, const int ypos, const CoeffType val)
Code an individual quantised value and perform inverse-quantisation.
Definition: band_codec_template.h:131
virtual void DoWorkDecode(CoeffArray &out_data)
Definition: band_codec_template.h:205
void ClearBlock(const CodeBlock &code_block, CoeffArray &coeff_data)
When coding a skipped block, propegate the predicted values for future non skipped blocks.
Definition: band_codec_template.h:518
CoeffType GetPrediction(const CoeffArray &data, const int xpos, const int ypos) const
Prediction of a DC value from its previously coded neighbours.
Definition: band_codec_template.h:531
void DecodeCoeffBlock(const CodeBlock &code_block, CoeffArray &out_data)
Decode codeblock of coefficients and perform DC prediction.
Definition: band_codec_template.h:500
Class for encapsulating metadata concerning a block of coefficients in a subband.
Definition: wavelet_utils.h:60
int Xstart() const
Returns the horizontal start of the block.
Definition: wavelet_utils.h:82
void SetSkip(bool skip)
Sets whether the code block is skipped or not.
Definition: wavelet_utils.h:109
int Ystart() const
Returns the vertical start of the block.
Definition: wavelet_utils.h:85
int QuantIndex() const
Returns the quantisation index associated to the code block.
Definition: wavelet_utils.h:100
int Xend() const
Returns one past the last coefficient coord, horizontally.
Definition: wavelet_utils.h:88
int Yend() const
Returns one past the last coefficient coord, vertically.
Definition: wavelet_utils.h:91
int Parent() const
Return the index of the parent subband.
Definition: wavelet_utils.h:205
A class encapulating all the subbands produced by a transform.
Definition: wavelet_utils.h:280
A class for wavelet coefficient data.
Definition: wavelet_utils.h:623