Dirac - A Video Codec

Created by the British Broadcasting Corporation.


band_codec.h

Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002 *
00003 * $Id: band_codec.h,v 1.36 2009/01/21 05:18:09 asuraparaju Exp $ $Name: Dirac_1_0_2 $
00004 *
00005 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00006 *
00007 * The contents of this file are subject to the Mozilla Public License
00008 * Version 1.1 (the "License"); you may not use this file except in compliance
00009 * with the License. You may obtain a copy of the License at
00010 * http://www.mozilla.org/MPL/
00011 *
00012 * Software distributed under the License is distributed on an "AS IS" basis,
00013 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
00014 * the specific language governing rights and limitations under the License.
00015 *
00016 * The Original Code is BBC Research and Development code.
00017 *
00018 * The Initial Developer of the Original Code is the British Broadcasting
00019 * Corporation.
00020 * Portions created by the Initial Developer are Copyright (C) 2004.
00021 * All Rights Reserved.
00022 *
00023 * Contributor(s): Thomas Davies (Original Author),
00024 *                 Scott R Ladd,
00025 *                 Steve Bearcroft
00026 *                 Andrew Kennedy
00027 *
00028 * Alternatively, the contents of this file may be used under the terms of
00029 * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
00030 * Public License Version 2.1 (the "LGPL"), in which case the provisions of
00031 * the GPL or the LGPL are applicable instead of those above. If you wish to
00032 * allow use of your version of this file only under the terms of the either
00033 * the GPL or LGPL and not to allow others to use your version of this file
00034 * under the MPL, indicate your decision by deleting the provisions above
00035 * and replace them with the notice and other provisions required by the GPL
00036 * or LGPL. If you do not delete the provisions above, a recipient may use
00037 * your version of this file under the terms of any one of the MPL, the GPL
00038 * or the LGPL.
00039 * ***** END LICENSE BLOCK ***** */
00040 
00041 #ifndef _BAND_CODEC_H_
00042 #define _BAND_CODEC_H_
00043 
00044 #include <libdirac_common/arith_codec.h>
00045 #include <libdirac_common/wavelet_utils.h>
00046 
00047 
00048 namespace dirac
00049 {
00050 
00051    class SubbandByteIO;
00052 
00053     //Subclasses the arithmetic codec to produce a coding/decoding tool for subbands
00054 
00055 
00057     template<typename EntropyCodec>
00058     class GenericBandCodec: public EntropyCodec
00059     {
00060     public:
00061 
00063 
00071         GenericBandCodec(SubbandByteIO* subband_byteio,
00072                   size_t number_of_contexts,
00073                   const SubbandList& band_list,
00074                   int band_num,
00075                   const bool is_intra);
00076 
00077     protected:
00079         inline void CodeVal( CoeffArray& in_data , const int xpos , const int ypos , const CoeffType val);
00080 
00082         inline void DecodeVal(CoeffArray& out_data , const int xpos , const int ypos );
00083 
00085         void CodeQuantIndexOffset( const int offset );
00086 
00088         int DecodeQuantIndexOffset();
00089 
00091         inline void SetToVal( const CodeBlock& code_block , CoeffArray& coeff_data , const CoeffType val);
00092 
00094         virtual void ClearBlock( const CodeBlock& code_block , CoeffArray& coeff_data);
00095 
00096     protected:
00097         //functions
00098         // Overridden from the base class
00099         virtual void DoWorkCode(CoeffArray& in_data);
00100         // Ditto
00101         virtual void DoWorkDecode(CoeffArray& out_data);
00102 
00103         virtual void CodeCoeffBlock(const CodeBlock& code_block , CoeffArray& in_data);
00104         virtual void DecodeCoeffBlock(const CodeBlock& code_block , CoeffArray& out_data);
00105 
00106         virtual void CodeCoeff(CoeffArray& in_data, const int xpos, const int ypos);
00107 
00108         virtual void DecodeCoeff(CoeffArray& in_data, const int xpos, const int ypos);
00110         inline int ChooseFollowContext( const int bin_number ) const;
00111 
00113         inline int ChooseInfoContext() const;
00114 
00116         inline int ChooseSignContext(const CoeffArray& data , const int xpos , const int ypos ) const;
00117 
00118     private:
00120         GenericBandCodec(const GenericBandCodec& cpy);
00122         GenericBandCodec& operator=(const GenericBandCodec& rhs);
00123 
00124     protected:
00125 
00127         bool m_is_intra;
00128 
00130         int m_bnum;
00131 
00133         const Subband m_node;
00134 
00136         int m_last_qf_idx;
00137 
00139         int m_qf;
00140 
00142         CoeffType m_offset;
00143 
00145         bool m_nhood_nonzero;
00146 
00148         Subband m_pnode;
00149 
00151         int m_pxpos, m_pypos;
00152 
00154         bool m_parent_notzero;
00155 
00156     };
00157 
00159 
00162     typedef GenericBandCodec<ArithCodec<CoeffArray> > BandCodec;
00163     typedef BandCodec LFBandCodec;
00164 
00166     //Finally,special class incorporating prediction for the DC band of intra frames//
00168 
00170     template<typename EntropyCodec>
00171     class GenericIntraDCBandCodec : public GenericBandCodec<EntropyCodec>
00172     {
00173     public:
00175 
00181         GenericIntraDCBandCodec(SubbandByteIO* subband_byteio,
00182                          size_t number_of_contexts,
00183                          const SubbandList& band_list)
00184           : GenericBandCodec<EntropyCodec>(subband_byteio,number_of_contexts,
00185                                            band_list, band_list.Length(),
00186                                            true){}
00187 
00188     protected:
00190         void ClearBlock( const CodeBlock& code_block , CoeffArray& coeff_data);
00191 
00193         CoeffType GetPrediction(const CoeffArray& data , const int xpos , const int ypos ) const;
00194 
00196         void DecodeCoeffBlock(const CodeBlock& code_block , CoeffArray& out_data);
00197     };
00198 
00199 
00201 
00206     class IntraDCBandCodec: public GenericIntraDCBandCodec<ArithCodec<CoeffArray> >
00207     {
00208     public:
00210 
00216         IntraDCBandCodec(SubbandByteIO* subband_byteio,
00217                          size_t number_of_contexts,
00218                          const SubbandList& band_list)
00219           : GenericIntraDCBandCodec<ArithCodec<CoeffArray> >(subband_byteio,
00220                                               number_of_contexts,
00221                                               band_list){}
00222 
00223 
00224     private:
00226         void DoWorkCode(CoeffArray& in_data);                    //overridden from the base class
00227 
00229         void DoWorkDecode(CoeffArray& out_data);
00230 
00232         void CodeCoeff(CoeffArray& in_data, const int xpos, const int ypos);
00233 
00235         void DecodeCoeff(CoeffArray& out_data, const int xpos, const int ypos);
00236 
00238         IntraDCBandCodec(const IntraDCBandCodec& cpy);
00239 
00241         IntraDCBandCodec& operator=(const IntraDCBandCodec& rhs);
00242 
00243     private:
00244         CoeffArray m_dc_pred_res;
00245     };
00246 
00247 }// end namespace dirac
00248 #endif

© 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.