# Dirac - A Video Codec

Created by the British Broadcasting Corporation.

band_codec.h
Go to the documentation of this file.
1/* ***** BEGIN LICENSE BLOCK *****
2*
3* $Id: band_codec.h,v 1.36 2009/01/21 05:18:09 asuraparaju Exp $ $Name: Dirac_1_0_2 $
4*
5* Version: MPL 1.1/GPL 2.0/LGPL 2.1
6*
7* The contents of this file are subject to the Mozilla Public License
8* Version 1.1 (the "License"); you may not use this file except in compliance
9* with the License. You may obtain a copy of the License at
10* http://www.mozilla.org/MPL/
11*
12* Software distributed under the License is distributed on an "AS IS" basis,
13* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
14* the specific language governing rights and limitations under the License.
15*
16* The Original Code is BBC Research and Development code.
17*
18* The Initial Developer of the Original Code is the British Broadcasting
19* Corporation.
20* Portions created by the Initial Developer are Copyright (C) 2004.
21* All Rights Reserved.
22*
23* Contributor(s): Thomas Davies (Original Author),
24* Scott R Ladd,
25* Steve Bearcroft
26* Andrew Kennedy
27*
28* Alternatively, the contents of this file may be used under the terms of
29* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
30* Public License Version 2.1 (the "LGPL"), in which case the provisions of
31* the GPL or the LGPL are applicable instead of those above. If you wish to
32* allow use of your version of this file only under the terms of the either
33* the GPL or LGPL and not to allow others to use your version of this file
34* under the MPL, indicate your decision by deleting the provisions above
35* and replace them with the notice and other provisions required by the GPL
36* or LGPL. If you do not delete the provisions above, a recipient may use
37* your version of this file under the terms of any one of the MPL, the GPL
38* or the LGPL.
39* ***** END LICENSE BLOCK ***** */
40
41#ifndef _BAND_CODEC_H_
42#define _BAND_CODEC_H_
43
44#include <libdirac_common/arith_codec.h>
45#include <libdirac_common/wavelet_utils.h>
46
47
48 namespace dirac
49{
50
51 class SubbandByteIO;
52
53 //Subclasses the arithmetic codec to produce a coding/decoding tool for subbands
54
55
57 template<typename EntropyCodec>
58 class GenericBandCodec: public EntropyCodec
59 {
60 public:
61
63
71 GenericBandCodec(SubbandByteIO* subband_byteio,
72 size_t number_of_contexts,
73 const SubbandList& band_list,
74 int band_num,
75 const bool is_intra);
76
77 protected:
79 inline void CodeVal( CoeffArray& in_data , const int xpos , const int ypos , const CoeffType val);
80
82 inline void DecodeVal(CoeffArray& out_data , const int xpos , const int ypos );
83
85 void CodeQuantIndexOffset( const int offset );
86
88 int DecodeQuantIndexOffset();
89
91 inline void SetToVal( const CodeBlock& code_block , CoeffArray& coeff_data , const CoeffType val);
92
94 virtual void ClearBlock( const CodeBlock& code_block , CoeffArray& coeff_data);
95
96 protected:
97 //functions
98 // Overridden from the base class
99 virtual void DoWorkCode(CoeffArray& in_data);
100 // Ditto
101 virtual void DoWorkDecode(CoeffArray& out_data);
102
103 virtual void CodeCoeffBlock(const CodeBlock& code_block , CoeffArray& in_data);
104 virtual void DecodeCoeffBlock(const CodeBlock& code_block , CoeffArray& out_data);
105
106 virtual void CodeCoeff(CoeffArray& in_data, const int xpos, const int ypos);
107
108 virtual void DecodeCoeff(CoeffArray& in_data, const int xpos, const int ypos);
110 inline int ChooseFollowContext( const int bin_number ) const;
111
113 inline int ChooseInfoContext() const;
114
116 inline int ChooseSignContext(const CoeffArray& data , const int xpos , const int ypos ) const;
117
118 private:
120 GenericBandCodec(const GenericBandCodec& cpy);
122 GenericBandCodec& operator=(const GenericBandCodec& rhs);
123
124 protected:
125
127 bool m_is_intra;
128
130 int m_bnum;
131
133 const Subband m_node;
134
136 int m_last_qf_idx;
137
139 int m_qf;
140
142 CoeffType m_offset;
143
145 bool m_nhood_nonzero;
146
148 Subband m_pnode;
149
151 int m_pxpos, m_pypos;
152
154 bool m_parent_notzero;
155
156 };
157
159
162 typedef GenericBandCodec<ArithCodec<CoeffArray> > BandCodec;
163 typedef BandCodec LFBandCodec;
164
166 //Finally,special class incorporating prediction for the DC band of intra frames//
168
170 template<typename EntropyCodec>
171 class GenericIntraDCBandCodec : public GenericBandCodec<EntropyCodec>
172 {
173 public:
175
181 GenericIntraDCBandCodec(SubbandByteIO* subband_byteio,
182 size_t number_of_contexts,
183 const SubbandList& band_list)
184 : GenericBandCodec<EntropyCodec>(subband_byteio,number_of_contexts,
185 band_list, band_list.Length(),
186 true){}
187
188 protected:
190 void ClearBlock( const CodeBlock& code_block , CoeffArray& coeff_data);
191
193 CoeffType GetPrediction(const CoeffArray& data , const int xpos , const int ypos ) const;
194
196 void DecodeCoeffBlock(const CodeBlock& code_block , CoeffArray& out_data);
197 };
198
199
201
206 class IntraDCBandCodec: public GenericIntraDCBandCodec<ArithCodec<CoeffArray> >
207 {
208 public:
210
216 IntraDCBandCodec(SubbandByteIO* subband_byteio,
217 size_t number_of_contexts,
218 const SubbandList& band_list)
219 : GenericIntraDCBandCodec<ArithCodec<CoeffArray> >(subband_byteio,
220 number_of_contexts,
221 band_list){}
222
223
224 private:
226 void DoWorkCode(CoeffArray& in_data); //overridden from the base class
227
229 void DoWorkDecode(CoeffArray& out_data);
230
232 void CodeCoeff(CoeffArray& in_data, const int xpos, const int ypos);
233
235 void DecodeCoeff(CoeffArray& out_data, const int xpos, const int ypos);
236
238 IntraDCBandCodec(const IntraDCBandCodec& cpy);
239
241 IntraDCBandCodec& operator=(const IntraDCBandCodec& rhs);
242
243 private:
244 CoeffArray m_dc_pred_res;
245 };
246
247}// end namespace dirac
248#endif
wavelet_utils.h
arith_codec.h
dirac
Definition of class SequenceHeaderByteIO.
Definition: accessunit_byteio.h:52
dirac::CoeffType
int CoeffType
Type of wavelet coefficient data (should be larger than ValueType)
Definition: common.h:74
dirac::BandCodec
GenericBandCodec< ArithCodec< CoeffArray > > BandCodec
A general class for coding and decoding wavelet subband data.
Definition: band_codec.h:162
dirac::LFBandCodec
BandCodec LFBandCodec
Definition: band_codec.h:163
dirac::SubbandByteIO
Subband Dirac-bytestream input/output.
Definition: subband_byteio.h:57
dirac::ArithCodec
Abstract binary arithmetic coding class.
Definition: arith_codec.h:376
dirac::GenericBandCodec
A template class for coding and decoding wavelet subband data.
Definition: band_codec.h:59
dirac::GenericBandCodec::DecodeCoeffBlock
virtual void DecodeCoeffBlock(const CodeBlock &code_block, CoeffArray &out_data)
Definition: band_codec_template.h:231
dirac::GenericBandCodec::m_qf
int m_qf
quantisation value
Definition: band_codec.h:139
dirac::GenericBandCodec::m_bnum
int m_bnum
variables
Definition: band_codec.h:130
dirac::GenericBandCodec::CodeCoeff
virtual void CodeCoeff(CoeffArray &in_data, const int xpos, const int ypos)
Definition: band_codec_template.h:106
dirac::GenericBandCodec::ChooseSignContext
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
dirac::GenericBandCodec::m_node
const Subband m_node
the subband being coded
Definition: band_codec.h:133
dirac::GenericBandCodec::GenericBandCodec
GenericBandCodec(const GenericBandCodec &cpy)
Private, bodyless copy constructor: class should not be copied.
dirac::GenericBandCodec::CodeQuantIndexOffset
void CodeQuantIndexOffset(const int offset)
Encode the offset for a code block quantiser.
Definition: band_codec_template.h:176
dirac::GenericBandCodec::DecodeQuantIndexOffset
int DecodeQuantIndexOffset()
Decode the offset for a code block quantiser.
Definition: band_codec_template.h:456
dirac::GenericBandCodec::ChooseInfoContext
int ChooseInfoContext() const
A function for choosing the context for "information bits".
Definition: band_codec_template.h:413
dirac::GenericBandCodec::DecodeVal
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
dirac::GenericBandCodec::m_pypos
int m_pypos
Definition: band_codec.h:151
dirac::GenericBandCodec::m_parent_notzero
bool m_parent_notzero
True if the parent of a coeff is not zero.
Definition: band_codec.h:154
dirac::GenericBandCodec::CodeCoeffBlock
virtual void CodeCoeffBlock(const CodeBlock &code_block, CoeffArray &in_data)
Definition: band_codec_template.h:53
dirac::GenericBandCodec::m_pnode
Subband m_pnode
the parent subband
Definition: band_codec.h:148
dirac::GenericBandCodec::ClearBlock
virtual void ClearBlock(const CodeBlock &code_block, CoeffArray &coeff_data)
Set all block values to 0.
Definition: band_codec_template.h:488
dirac::GenericBandCodec::m_last_qf_idx
int m_last_qf_idx
the quantisation index of the last codeblock
Definition: band_codec.h:136
dirac::GenericBandCodec::m_pxpos
int m_pxpos
position of the parent coefficient
Definition: band_codec.h:151
dirac::GenericBandCodec::DoWorkCode
virtual void DoWorkCode(CoeffArray &in_data)
Definition: band_codec_template.h:27
dirac::GenericBandCodec::SetToVal
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
dirac::GenericBandCodec::operator=
GenericBandCodec & operator=(const GenericBandCodec &rhs)
Private, bodyless copy operator=: class should not be assigned.
dirac::GenericBandCodec::DecodeCoeff
virtual void DecodeCoeff(CoeffArray &in_data, const int xpos, const int ypos)
Definition: band_codec_template.h:306
dirac::GenericBandCodec::m_offset
CoeffType m_offset
reconstruction point
Definition: band_codec.h:142
dirac::GenericBandCodec::GenericBandCodec
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
dirac::GenericBandCodec::ChooseFollowContext
int ChooseFollowContext(const int bin_number) const
A function for choosing the context for "follow bits".
Definition: band_codec_template.h:358
dirac::GenericBandCodec::CodeVal
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
dirac::GenericBandCodec::m_nhood_nonzero
bool m_nhood_nonzero
True if neighbours non-zero.
Definition: band_codec.h:145
dirac::GenericBandCodec::m_is_intra
bool m_is_intra
Flag indicating whether the band comes from an intra picture.
Definition: band_codec.h:127
dirac::GenericBandCodec::DoWorkDecode
virtual void DoWorkDecode(CoeffArray &out_data)
Definition: band_codec_template.h:205
dirac::GenericIntraDCBandCodec
A template class specially for coding the DC subband of Intra frames.
Definition: band_codec.h:172
dirac::GenericIntraDCBandCodec::ClearBlock
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
dirac::GenericIntraDCBandCodec::GenericIntraDCBandCodec
GenericIntraDCBandCodec(SubbandByteIO *subband_byteio, size_t number_of_contexts, const SubbandList &band_list)
Constructor.
Definition: band_codec.h:181
dirac::GenericIntraDCBandCodec::GetPrediction
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
dirac::GenericIntraDCBandCodec::DecodeCoeffBlock
void DecodeCoeffBlock(const CodeBlock &code_block, CoeffArray &out_data)
Decode codeblock of coefficients and perform DC prediction.
Definition: band_codec_template.h:500
dirac::IntraDCBandCodec
A class specially for coding the DC subband of Intra frames.
Definition: band_codec.h:207
dirac::IntraDCBandCodec::DoWorkDecode
void DoWorkDecode(CoeffArray &out_data)
Ditto.
dirac::IntraDCBandCodec::CodeCoeff
void CodeCoeff(CoeffArray &in_data, const int xpos, const int ypos)
Encode a single coefficient using error-feedback DC quantization.
dirac::IntraDCBandCodec::IntraDCBandCodec
IntraDCBandCodec(const IntraDCBandCodec &cpy)
Private, bodyless copy constructor: class should not be copied.
dirac::IntraDCBandCodec::DecodeCoeff
void DecodeCoeff(CoeffArray &out_data, const int xpos, const int ypos)
Decode a single coefficient using error-feedback DC quantization.
dirac::IntraDCBandCodec::operator=
IntraDCBandCodec & operator=(const IntraDCBandCodec &rhs)
Private, bodyless copy operator=: class should not be assigned.
dirac::IntraDCBandCodec::IntraDCBandCodec
IntraDCBandCodec(SubbandByteIO *subband_byteio, size_t number_of_contexts, const SubbandList &band_list)
Constructor.
Definition: band_codec.h:216
dirac::IntraDCBandCodec::DoWorkCode
void DoWorkCode(CoeffArray &in_data)
Initialize extra data required for error-feedback DC quantization.
dirac::IntraDCBandCodec::m_dc_pred_res
CoeffArray m_dc_pred_res
Definition: band_codec.h:244
dirac::CodeBlock
Class for encapsulating metadata concerning a block of coefficients in a subband.
Definition: wavelet_utils.h:60
dirac::Subband
Class encapsulating all the metadata relating to a wavelet subband.
Definition: wavelet_utils.h:140
dirac::SubbandList
A class encapulating all the subbands produced by a transform.
Definition: wavelet_utils.h:280
dirac::CoeffArray
A class for wavelet coefficient data.
Definition: wavelet_utils.h:623

© 2004 British Broadcasting Corporation. Dirac code licensed under the Mozilla Public License (MPL) Version 1.1.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.