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.15 2005/12/02 10:16:52 asuraparaju Exp $ $Name: Dirac_0_5_4 $
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 *
00027 * Alternatively, the contents of this file may be used under the terms of
00028 * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
00029 * Public License Version 2.1 (the "LGPL"), in which case the provisions of
00030 * the GPL or the LGPL are applicable instead of those above. If you wish to
00031 * allow use of your version of this file only under the terms of the either
00032 * the GPL or LGPL and not to allow others to use your version of this file
00033 * under the MPL, indicate your decision by deleting the provisions above
00034 * and replace them with the notice and other provisions required by the GPL
00035 * or LGPL. If you do not delete the provisions above, a recipient may use
00036 * your version of this file under the terms of any one of the MPL, the GPL
00037 * or the LGPL.
00038 * ***** END LICENSE BLOCK ***** */
00039 
00040 #ifndef _BAND_CODEC_H_
00041 #define _BAND_CODEC_H_
00042 
00043 #include <libdirac_common/arith_codec.h>
00044 #include <libdirac_common/wavelet_utils.h>
00045 
00046 namespace dirac
00047 {
00048 
00049     //Subclasses the arithmetic codec to produce a coding/decoding tool for subbands
00050 
00051 
00053 
00056     class BandCodec: public ArithCodec<PicArray >
00057     {
00058     public:
00059 
00061 
00068         BandCodec(BasicOutputManager* bits_out,
00069                   size_t number_of_contexts,
00070                   const SubbandList& band_list,
00071                   int band_num);
00072 
00074 
00081         BandCodec(BitInputManager* bits_in,
00082                   size_t number_of_contexts,
00083                   const SubbandList& band_list,
00084                   int band_num);
00085 
00087         void InitContexts();
00088 
00089     protected:
00091         void CodeVal( PicArray& in_data , const int xpos , const int ypos , const ValueType val);
00092 
00094         void DecodeVal(PicArray& out_data , const int xpos , const int ypos );
00095 
00097         inline void SetToVal( const CodeBlock& code_block , PicArray& pic_data , const ValueType val);
00098 
00100         inline void ClearBlock( const CodeBlock& code_block , PicArray& pic_data);
00101 
00102     private:
00103         //functions
00104         // Overridden from the base class
00105         virtual void DoWorkCode(PicArray& in_data);
00106         // Ditto
00107         virtual void DoWorkDecode(PicArray& out_data);
00108 
00109         virtual void CodeCoeffBlock(const CodeBlock& code_block , PicArray& in_data);
00110         virtual void DecodeCoeffBlock(const CodeBlock& code_block , PicArray& out_data);
00111 
00112         void ResetAll();
00113 
00114         // structure used to select the contexts used to encode / decode a symbol
00115         typedef struct 
00116         {
00117             int firstContext;
00118             int secondContext;
00119             int endContext;
00120         } ContextTriple;
00121 
00122         typedef enum ContextTripleAliases
00123         {
00124             Z_z_CTXT,
00125             Z_nz_CTXT,
00126             NZ_z_CTXT,
00127             NZ_b_CTXT,
00128             NZ_a_CTXT,
00129             lastCTXTAlias
00130         } ;
00131 
00132         static const ContextTriple m_context_triples[lastCTXTAlias];
00133 
00134         const ContextTriple& ChooseContexts() const;
00135 
00136         int ChooseSignContext(const PicArray& data , const int xpos , const int ypos ) const;
00137 
00139         BandCodec(const BandCodec& cpy);
00141         BandCodec& operator=(const BandCodec& rhs);
00142 
00143     protected:
00145         int m_bnum;
00146 
00148         const Subband m_node;
00149     
00151         int m_vol;
00152     
00154         int m_reset_coeff_num;
00155     
00157         int m_coeff_count;
00158     
00160         int m_qf, m_qfinv;
00161     
00163         ValueType m_offset;
00164     
00166         ValueType m_nhood_sum;
00167     
00169         Subband m_pnode;
00170     
00172         int m_pxp, m_pyp, m_pxl, m_pyl;
00173     
00175         int m_pxpos, m_pypos;
00176     
00178         bool m_parent_notzero;
00179     
00181         ValueType m_cut_off_point;
00182     };
00183 
00185 
00189     class LFBandCodec: public BandCodec
00190     {
00191     public:
00193 
00200         LFBandCodec(BasicOutputManager* bits_out,
00201                     size_t number_of_contexts,
00202                     const SubbandList& band_list,
00203                     int band_num)
00204               : BandCodec(bits_out,number_of_contexts,band_list,band_num){}
00205 
00207 
00214         LFBandCodec(BitInputManager* bits_in,
00215                     size_t number_of_contexts,
00216                     const SubbandList& band_list,
00217                     int band_num)
00218           : BandCodec(bits_in,number_of_contexts,band_list,band_num){}
00219 
00220     private:
00221         // Overridden from the base class
00222         void DoWorkCode(PicArray& in_data);
00223         // Ditto
00224         void DoWorkDecode(PicArray& out_data);
00225 
00226         void CodeCoeffBlock(const CodeBlock& code_block , PicArray& in_data);
00227         void DecodeCoeffBlock(const CodeBlock& code_block , PicArray& out_data);
00228 
00230         LFBandCodec(const LFBandCodec& cpy);
00232         LFBandCodec& operator=(const LFBandCodec& rhs);
00233 
00234     };
00235 
00236 
00238     //Finally,special class incorporating prediction for the DC band of intra frames//
00240 
00242 
00246     class IntraDCBandCodec: public BandCodec
00247     {
00248     public:
00250 
00256         IntraDCBandCodec(BasicOutputManager* bits_out,
00257                          size_t number_of_contexts,
00258                          const SubbandList& band_list)
00259           : BandCodec(bits_out,number_of_contexts,band_list,band_list.Length()){}
00260 
00262 
00268         IntraDCBandCodec(BitInputManager* bits_in,
00269                          size_t number_of_contexts,
00270                          const SubbandList& band_list)
00271           : BandCodec(bits_in,number_of_contexts,band_list,band_list.Length()){}
00272 
00273     private:
00274         void DoWorkCode(PicArray& in_data);                    //overridden from the base class
00275         void DoWorkDecode(PicArray& out_data); //ditto
00276 
00277         void CodeCoeffBlock(const CodeBlock& code_block , PicArray& in_data);
00278         void DecodeCoeffBlock(const CodeBlock& code_block , PicArray& out_data);
00279 
00281         IntraDCBandCodec(const IntraDCBandCodec& cpy); 
00282 
00284         IntraDCBandCodec& operator=(const IntraDCBandCodec& rhs);
00285 
00287         ValueType GetPrediction(const PicArray& data , const int xpos , const int ypos ) const;
00288 
00289     private:
00290         PicArray m_dc_pred_res;
00291     };
00292 
00293 
00294 }// end namespace dirac
00295 #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.