8template<
typename EntropyCodec>
10 size_t number_of_contexts,
14 EntropyCodec(subband_byteio,number_of_contexts),
17 m_node(band_list(band_num)),
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() )
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() )
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)
81 for (
int xpos=xbeg; xpos<xend ;++xpos)
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 )
154 in_data[ypos][xpos] =
static_cast<CoeffType>( abs_val );
159 in_data[ypos][xpos] *=
m_qf;
161 in_data[ypos][xpos] >>= 2;
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() )
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() )
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)
275 p_out_data = out_data[
m_pypos];
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)
305template<
typename EntropyCodec>
329template<
typename EntropyCodec>
333 CoeffType& out_pixel = out_data[ypos][xpos];
353 out_pixel = -out_pixel;
357template<
typename EntropyCodec>
364 switch ( bin_number )
386 switch ( bin_number )
412template<
typename EntropyCodec>
418template<
typename EntropyCodec>
428 if (data[ypos-1][xpos]>0)
430 else if (data[ypos-1][xpos]<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
virtual void DecodeCoeffBlock(const CodeBlock &code_block, CoeffArray &out_data)
Definition band_codec_template.h:231
int m_qf
quantisation value
Definition band_codec.h:139
int m_bnum
variables
Definition band_codec.h:130
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
int m_pypos
Definition band_codec.h:151
bool m_parent_notzero
True if the parent of a coeff is not zero.
Definition band_codec.h:154
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
int m_last_qf_idx
the quantisation index of the last codeblock
Definition band_codec.h:136
int m_pxpos
position of the parent coefficient
Definition band_codec.h:151
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
CoeffType m_offset
reconstruction point
Definition band_codec.h:142
GenericBandCodec(SubbandByteIO *subband_byteio, size_t number_of_contexts, const SubbandList &band_list, int band_num, const bool is_intra)
Constructor.
Definition band_codec_template.h:9
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
bool m_nhood_nonzero
True if neighbours non-zero.
Definition band_codec.h:145
bool m_is_intra
Flag indicating whether the band comes from an intra picture.
Definition band_codec.h:127
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
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