Dirac - A Video Codec

Created by the British Broadcasting Corporation.


common.h

Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002 *
00003 * $Id: common.h,v 1.79 2008/10/01 01:26:47 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 *                 Tim Borer,
00026 *                 Anuradha Suraparaju,
00027 *                 Andrew Kennedy
00028 *                 Myo Tun (Brunel University, myo.tun@brunel.ac.uk)
00029 *
00030 * Alternatively, the contents of this file may be used under the terms of
00031 * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
00032 * Public License Version 2.1 (the "LGPL"), in which case the provisions of
00033 * the GPL or the LGPL are applicable instead of those above. If you wish to
00034 * allow use of your version of this file only under the terms of the either
00035 * the GPL or LGPL and not to allow others to use your version of this file
00036 * under the MPL, indicate your decision by deleting the provisions above
00037 * and replace them with the notice and other provisions required by the GPL
00038 * or LGPL. If you do not delete the provisions above, a recipient may use
00039 * your version of this file under the terms of any one of the MPL, the GPL
00040 * or the LGPL.
00041 * ***** END LICENSE BLOCK ***** */
00042 
00043 #ifndef _COMMON_H_
00044 #define _COMMON_H_
00045 
00046 #ifdef  _MSC_VER
00047 #define  _CRT_SECURE_NO_DEPRECATE
00048 #endif // _MSC_VER
00049 
00050 #include <libdirac_common/arrays.h>
00051 #include <libdirac_common/common_types.h>
00052 #include <libdirac_common/dirac_assertions.h>
00053 #include <vector>
00054 #include <cmath>
00055 namespace dirac
00056 {
00066     //Some basic types used throughout the codec ...//
00068 
00070     typedef short ValueType;
00071 
00072 #if !defined(HAVE_MMX)
00073 
00074     typedef int CoeffType;
00075 #else
00076 
00077     typedef short CoeffType;
00078 #endif
00079 
00081     typedef int CalcValueType;
00082 
00084     enum PredMode{ INTRA , REF1_ONLY , REF2_ONLY , REF1AND2, UNDEFINED };
00085 
00087     enum CompSort{ Y_COMP , U_COMP , V_COMP };
00088 
00090     enum AddOrSub{ ADD , SUBTRACT };
00091 
00093     enum Direction { FORWARD , BACKWARD };
00094 
00096     enum CtxAliases
00097     {//used for residual coding
00098         SIGN0_CTX,          // -sign, previous symbol is 0
00099         SIGN_POS_CTX,       // -sign, previous symbol is +ve
00100         SIGN_NEG_CTX,       // -sign, previous symbol is -ve
00101 
00102         // Follow bit contexts
00103         Z_FBIN1z_CTX,       // -bin 1, parent is zero, neighbours zero
00104         Z_FBIN1nz_CTX,      // -bin 1, parent is zero, neighbours non-zero
00105         Z_FBIN2_CTX,        // -bin 2, parent is zero
00106         Z_FBIN3_CTX,        // -bin 3, parent is zero
00107         Z_FBIN4_CTX,        // -bin 4, parent is zero
00108         Z_FBIN5_CTX,        // -bin 5, parent is zero
00109         Z_FBIN6plus_CTX,    // -bins 6 plus, parent is zero
00110 
00111         NZ_FBIN1z_CTX,      // -bin 1, parent is non-zero, neighbours zero
00112         NZ_FBIN1nz_CTX,     // -bin 1, parent is non-zero, neighbours non-zero
00113         NZ_FBIN2_CTX,       // -bin 2, parent is non-zero
00114         NZ_FBIN3_CTX,       // -bin 3, parent is non-zero
00115         NZ_FBIN4_CTX,       // -bin 4, parent is non-zero
00116         NZ_FBIN5_CTX,       // -bin 5, parent is non-zero
00117         NZ_FBIN6plus_CTX,   // -bins 6 plus, parent is non-zero
00118 
00119         // Information bit contexts
00120         INFO_CTX,
00121 
00122         BLOCK_SKIP_CTX,     // - blocks are skipped
00123         Q_OFFSET_FOLLOW_CTX,   // - code block quantiser offset magnitude
00124         Q_OFFSET_INFO_CTX,  // - code block quantiser offset info context
00125         Q_OFFSET_SIGN_CTX,   // - code block quantiser offset sign
00126         TOTAL_COEFF_CTXS   // The total number of coefficient contexts
00127     };
00128 
00130     enum MvCtxAliases
00131     {
00132         // DC value contexts //
00134 
00135         DC_FBIN1_CTX,
00136         DC_FBIN2plus_CTX,
00137         DC_INFO_CTX,
00138         DC_SIGN_CTX,
00139 
00140         // Motion vector contexts //
00142 
00143 
00144         MV_FBIN1_CTX,
00145         MV_FBIN2_CTX,
00146         MV_FBIN3_CTX,
00147         MV_FBIN4_CTX,
00148         MV_FBIN5plus_CTX,
00149 
00150         MV_INFO_CTX,
00151 
00152         MV_SIGN_CTX,
00153 
00154 
00155         // Prediction mode contexts
00156 
00157         PMODE_BIT0_CTX,     // -bit 0, prediction mode value
00158         PMODE_BIT1_CTX,     // -bin 1, prediction mode value
00159 
00160 
00161         // Macroblock contexts
00162 
00163         SB_SPLIT_BIN1_CTX,  // bin 1, SB split mode vals
00164         SB_SPLIT_BIN2_CTX,  // bin 2, SB split mode vals. Bin 3 not required
00165 
00166         SB_SPLIT_INFO_CTX,  // info context for SB split mode
00167 
00168         TOTAL_MV_CTXS       // The total number of motion vector contexts
00169     };
00170 
00171 
00177     VideoFormat IntToVideoFormat(int video_format);
00178 
00184     ChromaFormat IntToChromaFormat(int chroma_format);
00185 
00191     FrameRateType IntToFrameRateType(int frame_rate_idx);
00192 
00198     PixelAspectRatioType IntToPixelAspectRatioType(int pix_asr_idx);
00199 
00205     SignalRangeType IntToSignalRangeType(int signal_range_idx);
00206 
00212     MVPrecisionType IntToMVPrecisionType(int mv_prec);
00213 
00214     //Classes used throughout the codec//
00216  
00218     class Rational
00219     {
00220     public:
00222         unsigned int m_num;
00224         unsigned int m_denom;
00225     };
00226 
00228     class PictureSort
00229     {
00230     public:
00231         PictureSort() { fs = 0x00; } // default intra non-ref
00232 
00233         void SetIntra() { fs &= 0xfe; }
00234         void SetInter() { fs |= 0x01; }
00235         void SetNonRef() { fs &= 0xfd; }
00236         void SetRef() { fs |= 0x02; }
00237 
00238         bool IsInter () const { return fs & 0x01; }
00239         bool IsIntra () const { return !IsInter(); }
00240         bool IsRef() const { return fs & 0x02; };
00241         bool IsNonRef() const { return !IsRef(); }
00242 
00243         void SetIntraNonRef() { SetIntra(); SetNonRef(); }
00244         void SetIntraRef() { SetIntra(); SetRef(); }
00245         void SetInterNonRef() { SetInter(); SetNonRef(); }
00246         void SetInterRef() { SetInter(); SetRef(); }
00247 
00248         bool IsIntraNonRef() const { return (fs & 0x03) == 0x00; }
00249         bool IsIntraRef() const { return (fs & 0x03) == 0x02; }
00250         bool IsInterNonRef() const { return (fs & 0x03) == 0x01; }
00251         bool IsInterRef() const { return (fs & 0x03) == 0x03; }
00252 
00253         void Clear() { fs=0x00; }
00254 
00255         static PictureSort IntraRefPictureSort()
00256         {
00257             PictureSort fs;
00258             fs.SetIntraRef();
00259             return fs;
00260         }
00261 
00262         static PictureSort InterRefPictureSort()
00263         {
00264             PictureSort fs;
00265             fs.SetInterRef();
00266             return fs;
00267         }
00268 
00269         static PictureSort IntraNonRefPictureSort()
00270         {
00271             PictureSort fs;
00272             fs.SetIntraNonRef();
00273             return fs;
00274         }
00275 
00276         static PictureSort InterNonRefPictureSort()
00277         {
00278             PictureSort fs;
00279             fs.SetInterNonRef();
00280             return fs;
00281         }
00282 
00283     private:
00284         unsigned char fs;
00285     };
00286 
00288     class SourceParams
00289     {
00290     public:
00292         SourceParams (const VideoFormat &vf = VIDEO_FORMAT_CUSTOM,
00293                       bool set_defaults=true);
00294 
00296         //NB: Assume default copy constructor, assignment = and destructor//
00298 
00299         // Gets
00301         VideoFormat GetVideoFormat() const { return m_video_format;}
00302 
00304         unsigned int Xl() const {return m_xl;}
00305 
00307         unsigned int Yl() const {return m_yl;}
00308 
00310         ChromaFormat CFormat() const {return m_cformat;}
00311 
00313         int ChromaWidth() const;
00314 
00316         int ChromaHeight() const;
00317 
00319         unsigned int SourceSampling() const { return m_source_sampling; }
00320 
00322         bool TopFieldFirst() const { return m_topfieldfirst; }
00323 
00325         Rational FrameRate() const { return m_framerate; }
00326 
00328         FrameRateType FrameRateIndex() const { return m_fr_idx; }
00329 
00331         Rational PixelAspectRatio() const { return m_pixel_aspect_ratio; }
00332 
00334         PixelAspectRatioType PixelAspectRatioIndex() const { return m_pix_asr_idx; }
00335 
00336         // Clean area parameters
00338         unsigned int CleanWidth() const { return m_clean_width; }
00340         unsigned int CleanHeight() const { return m_clean_height; }
00342         unsigned int LeftOffset() const { return m_left_offset; }
00344         unsigned int TopOffset() const { return m_top_offset; }
00345 
00346         // Signal Range parameters
00347 
00349         SignalRangeType SignalRangeIndex() const { return m_sr_idx; }
00350 
00352         unsigned int LumaOffset() const { return m_luma_offset; }
00354         unsigned int LumaExcursion() const { return m_luma_excursion; }
00356         unsigned int ChromaOffset() const { return m_chroma_offset; }
00358         unsigned int ChromaExcursion() const { return m_chroma_excursion; }
00359 
00361         unsigned int ColourSpecificationIndex() const { return m_cs_idx; }
00362 
00364         ColourPrimaries ColourPrimariesIndex() const { return m_col_primary; }
00366         ColourMatrix ColourMatrixIndex() const { return m_col_matrix; }
00368         TransferFunction TransferFunctionIndex() const { return m_transfer_func; }
00369 
00370         // Sets
00371 
00373         void SetXl(unsigned int xlen) {m_xl = xlen;}
00374 
00376         void SetYl(unsigned int ylen) {m_yl = ylen;}
00377 
00379         void SetCFormat(ChromaFormat cf) {m_cformat=cf;}
00380 
00382         void SetSourceSampling(unsigned int source_sampling) 
00383         { m_source_sampling = source_sampling; }
00384 
00386         void SetTopFieldFirst(bool tff) { m_topfieldfirst = tff; }
00387 
00389         void SetVideoFormat(VideoFormat vf){ m_video_format=vf;}
00390 
00392         void SetFrameRate(const Rational &frate )
00393         {
00394             m_fr_idx = FRAMERATE_CUSTOM; m_framerate = frate;
00395         }
00396 
00398         void SetFrameRate(unsigned int fr_num, unsigned int fr_denom )
00399         {
00400             m_fr_idx = FRAMERATE_CUSTOM;
00401             m_framerate.m_num = fr_num;
00402             m_framerate.m_denom = fr_denom;
00403         }
00404 
00406         void SetFrameRate(FrameRateType fr);
00407 
00409         void SetPixelAspectRatio(const Rational &pix_asr)
00410         {
00411             m_pix_asr_idx = PIXEL_ASPECT_RATIO_CUSTOM;
00412             m_pixel_aspect_ratio = pix_asr;
00413         }
00414 
00416         void SetPixelAspectRatio(unsigned int pix_as_num, unsigned int pix_as_denom )
00417         {
00418             m_pix_asr_idx = PIXEL_ASPECT_RATIO_CUSTOM;
00419             m_pixel_aspect_ratio.m_num = pix_as_num;
00420             m_pixel_aspect_ratio.m_denom = pix_as_denom;
00421         }
00422 
00424         void SetPixelAspectRatio(PixelAspectRatioType pixel_aspect_ratio);
00425 
00426         // Clean area parameters
00428         void SetCleanWidth(unsigned int clean_width) { m_clean_width = clean_width; }
00430         void SetCleanHeight(unsigned int clean_height) { m_clean_height = clean_height; }
00432         void SetLeftOffset(unsigned int left_offset) { m_left_offset = left_offset; }
00434         void SetTopOffset(unsigned int top_offset) { m_top_offset = top_offset; }
00435 
00436         // Signal Range parameters
00438         void SetSignalRange(SignalRangeType sr);
00439 
00441         void SetLumaOffset(unsigned int luma_offset) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_luma_offset = luma_offset; }
00443         void SetLumaExcursion(unsigned int luma_exc) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_luma_excursion = luma_exc; }
00445         void SetChromaOffset(unsigned int chroma_off) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_chroma_offset = chroma_off; }
00447         void SetChromaExcursion(unsigned int chroma_exc) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_chroma_excursion = chroma_exc; }
00448 
00450         void SetColourSpecification(unsigned int cs_idx);
00452         void SetColourPrimariesIndex(unsigned int cp);
00454         void SetColourMatrixIndex(unsigned int cm);
00456         void SetTransferFunctionIndex(unsigned int tf);
00457 
00458     private:
00460         VideoFormat m_video_format;
00461 
00463         unsigned int m_xl;
00464 
00466         unsigned int m_yl;
00467 
00469         ChromaFormat m_cformat;
00470 
00472         unsigned int m_source_sampling;
00473 
00475         bool m_topfieldfirst;
00476 
00478         FrameRateType m_fr_idx;
00479 
00481         Rational m_framerate;
00482 
00484         PixelAspectRatioType m_pix_asr_idx;
00485 
00487         Rational m_pixel_aspect_ratio;
00488 
00489         // Clean area parameters
00490 
00492         unsigned int m_clean_width;
00493 
00495         unsigned int m_clean_height;
00496 
00498         unsigned int m_left_offset;
00499 
00501         unsigned int m_top_offset;
00502 
00503         // signal range parameters
00504 
00506         SignalRangeType m_sr_idx;
00507 
00509         unsigned int m_luma_offset;
00511         unsigned int m_luma_excursion;
00513         unsigned int m_chroma_offset;
00515         unsigned int m_chroma_excursion;
00516 
00518         unsigned int m_cs_idx;
00519 
00521         ColourPrimaries m_col_primary;
00522 
00523         // Colour Matrix index
00524         ColourMatrix m_col_matrix;
00525 
00526         // Transfer function index
00527         TransferFunction m_transfer_func;
00528     };
00529 
00530 
00532     class PictureParams
00533     {
00534 
00535     public:
00537         PictureParams();
00538 
00540 
00543         PictureParams(const ChromaFormat& cf, int xlen, int ylen,
00544                     unsigned int luma_depth, unsigned int chroma_depth);
00545 
00547 
00550         PictureParams(const ChromaFormat& cf, const PictureSort& fs);
00551 
00553 
00556         PictureParams(const SourceParams& sparams);
00557 
00559         //NB: Assume default copy constructor, assignment = and destructor//
00561 
00562         // Gets ...
00563 
00565         const ChromaFormat& CFormat() const{return m_cformat;}
00566 
00568         int Xl() const {return m_xl;}
00569 
00571         int Yl() const {return m_yl;}
00572 
00574         int ChromaXl() const{return m_cxl;}
00575 
00577         int ChromaYl() const{return m_cyl;}
00578 
00580         unsigned int LumaDepth() const { return m_luma_depth; }
00581 
00583         unsigned int ChromaDepth() const { return m_chroma_depth; }
00584 
00586         const PictureSort& PicSort() const {return m_psort;}
00587 
00589         int PictureNum() const {return m_fnum;}
00590 
00592         int RetiredPictureNum() const {return m_retd_fnum;}
00593 
00595         bool IsBPicture() const;
00596 
00598         int ExpiryTime() const {return m_expiry_time;}
00599 
00601         bool Output() const {return m_output;}
00602 
00604         const std::vector<int>& Refs() const {return m_refs;}
00605 
00607         std::vector<int>& Refs(){return m_refs;}
00608 
00610         unsigned int NumRefs()const {return m_refs.size();}
00611 
00613         PictureType GetPictureType () const { return m_picture_type; }
00614 
00616         ReferenceType GetReferenceType() const { return m_reference_type;}
00617 
00619         bool UsingAC() const { return m_using_ac; }
00620 
00621         // ... Sets
00622 
00624         void SetPicSort( const PictureSort& ps );
00625 
00627         void SetPictureType(const PictureType ftype);
00628 
00630         void SetReferenceType(const ReferenceType rtype);
00631 
00633         void SetPictureNum( const int fn ){ m_fnum=fn; }
00634 
00636         void SetExpiryTime( const int expt ){ m_expiry_time=expt; }
00637 
00639         void SetAsOutput(){m_output=true;}
00640 
00642         void SetCFormat(ChromaFormat cf){ m_cformat = cf; }
00643 
00645         void SetXl(int xlen);
00646 
00648         void SetYl(int ylen);
00649 
00651         void SetLumaDepth(unsigned int luma_depth) { m_luma_depth = luma_depth; }
00652 
00654         void SetChromaDepth(unsigned int chroma_depth) { m_chroma_depth = chroma_depth; }
00655 
00657         void SetRetiredPictureNum(int retd_fnum) {m_retd_fnum = retd_fnum;}
00658 
00660         void SetUsingAC(bool using_ac) { m_using_ac = using_ac; }
00661 
00662     private:
00663 
00665         ChromaFormat m_cformat;
00666 
00668         PictureSort m_psort;
00669 
00671         std::vector<int> m_refs;
00672 
00674         int m_expiry_time;
00675 
00677         int m_fnum;
00678 
00680         PictureType m_picture_type;
00681 
00683         ReferenceType m_reference_type;
00684 
00686         bool m_output;
00687 
00689         mutable  int m_retd_fnum;
00690 
00692         int m_xl;
00693 
00695         int m_yl;
00696 
00698         int m_cxl;
00699 
00701         int m_cyl;
00702 
00704         unsigned int m_luma_depth;
00705 
00707         unsigned int m_chroma_depth;
00708 
00710         bool m_using_ac;
00711     };
00712 
00713 
00715 
00718     class PicArray: public TwoDArray<ValueType>
00719     {
00720     public:
00722 
00725         PicArray(): TwoDArray<ValueType>(){}
00726 
00728 
00732         PicArray(int height, int width, CompSort cs=Y_COMP): 
00733             TwoDArray<ValueType>(height, width), m_csort(cs){}
00734 
00735         //copy constructor and assignment= derived by inheritance
00736 
00738         ~PicArray(){}
00739 
00741         const CompSort& CSort() const {return m_csort;}
00742         
00744         void SetCSort(const CompSort cs){ m_csort = cs; }
00745 
00746     private:
00747 
00748         CompSort m_csort;
00749     };
00750 
00751 
00753     class CostType
00754     {
00755     public:
00757         double Error;
00758 
00760         double ENTROPY;
00761 
00763         double TOTAL;
00764     };
00765 
00766 
00768 
00773     class EntropyCorrector
00774     {
00775     public:
00777 
00781         EntropyCorrector(int depth);
00782 
00784         //NB: Assume default copy constructor, assignment = and destructor//
00786 
00788 
00792         float Factor(const int bandnum, const PictureParams& pp,
00793                      const CompSort c) const;
00794 
00796 
00804         void Update(int bandnum, const PictureParams& pp, 
00805                     CompSort c,int est_bits,int actual_bits);
00806 
00807     private:
00809         void Init();
00810 
00811         TwoDArray<float> m_Yfctrs;
00812         TwoDArray<float> m_Ufctrs;
00813         TwoDArray<float> m_Vfctrs;
00814     };
00815 
00817     class OLBParams
00818     {
00819 
00820     public:
00821 
00823         OLBParams(){}
00824 
00826         /*
00827             Constructor rationalises proposed parameters to allow suitable
00828             overlap and fit in with chroma format
00829             \param    xblen    the horizontal block length
00830             \param    yblen    the vertical block length
00831             \param    xblen    the horizontal block separation
00832             \param    yblen    the vertical block separation
00833 
00834         */
00835         OLBParams(const int xblen, const int yblen,
00836                   const int xbsep, const int ybsep);
00837 
00838         // Gets ...
00839 
00841         int Xblen() const {return m_xblen;}
00842 
00844         int Yblen() const {return m_yblen;}
00845 
00847         int Xbsep() const {return m_xbsep;}
00848 
00850         int Ybsep() const {return m_ybsep;}
00851 
00853         int Xoffset() const {return m_xoffset;}
00854 
00856         int Yoffset() const {return m_yoffset;}
00857 
00858         // ... and sets
00859 
00861         void SetXblen( int xblen ){ m_xblen = xblen; m_xoffset = (m_xblen-m_xbsep)/2;}
00862 
00864         void SetYblen( int yblen ){ m_yblen = yblen; m_yoffset = (m_yblen-m_ybsep)/2;}
00865 
00867         void SetXbsep( int xbsep ){ m_xbsep = xbsep; m_xoffset = (m_xblen-m_xbsep)/2;}
00868 
00870         void SetYbsep( int ybsep ){ m_ybsep = ybsep; m_yoffset = (m_yblen-m_ybsep)/2;}
00871 
00872         bool operator == (const OLBParams bparams) const;
00873 
00874         // overloaded stream operators
00875         friend std::ostream & operator<< (std::ostream &, OLBParams &);
00876         friend std::istream & operator>> (std::istream &, OLBParams &);
00877 
00878 
00879     private:
00880 
00881         int m_xblen;
00882         int m_yblen;
00883         int m_xbsep;
00884         int m_ybsep;
00885         int m_xoffset;
00886         int m_yoffset;
00887     };
00888 
00890     class ParseParams
00891     {
00892     public:
00894         ParseParams();
00895 
00896         // Gets
00897 
00899         unsigned int MajorVersion() const { return m_major_ver; }
00900 
00902         unsigned int MinorVersion() const { return m_minor_ver; }
00903 
00905         unsigned int Profile() const { return m_profile; }
00906 
00908         unsigned int Level() const { return m_level; }
00909 
00910         // Sets
00911 
00913         void SetMajorVersion(unsigned int major_ver) {m_major_ver = major_ver; }
00914 
00916         void SetMinorVersion(unsigned int minor_ver) { m_minor_ver = minor_ver; }
00917 
00919         void SetProfile(unsigned int profile) { m_profile = profile; }
00920 
00922         void SetLevel(unsigned int level) { m_level = level; }
00923 
00924     private:
00926         unsigned int m_major_ver;
00928         unsigned int m_minor_ver;
00930         unsigned int m_profile;
00932         unsigned int m_level;
00933     };
00934 
00936     class CodeBlocks
00937     {
00938     public:
00940         CodeBlocks () : m_hblocks(1), m_vblocks(1)
00941         {}
00942 
00944         CodeBlocks (unsigned int  hblocks, unsigned int vblocks) :
00945             m_hblocks(hblocks),
00946             m_vblocks(vblocks)
00947             {}
00948 
00949         // Gets
00951         unsigned int HorizontalCodeBlocks() const { return m_hblocks; }
00953         unsigned int VerticalCodeBlocks() const { return m_vblocks; }
00954         // Sets
00956         void SetHorizontalCodeBlocks(unsigned int hblocks) { m_hblocks = hblocks; }
00958         void SetVerticalCodeBlocks(unsigned int vblocks) { m_vblocks = vblocks; }
00959     private:
00961         unsigned int m_hblocks;
00963         unsigned int m_vblocks;
00964     };
00965 
00967     class PicturePredParams
00968     {
00969     public:
00970         PicturePredParams():
00971     m_lbparams(3),
00972         m_cbparams(3) {}
00973 
00975         bool UsingGlobalMotion() const { return m_use_global_motion; }
00976 
00978         unsigned int PictureWeightsBits() const { return m_picture_weights_bits; }
00979 
00981         int Ref1Weight() const { return m_ref1_weight; }
00982 
00984         int Ref2Weight() const { return m_ref2_weight; }
00985 
00986         bool CustomRefWeights()
00987         {
00988             return (m_picture_weights_bits != 1 ||
00989                     m_ref1_weight != 1 ||
00990                     m_ref2_weight != 1);
00991         }
00992 
00994         int XNumSB() const {return m_x_num_sb;}
00995 
00997         int YNumSB() const {return m_y_num_sb;}
00998 
01000         int XNumBlocks() const {return m_x_num_blocks;}
01001 
01003         int YNumBlocks() const {return m_y_num_blocks;}
01004 
01006         const OLBParams& LumaBParams(int n) const {return m_lbparams[n];}
01007 
01009         const OLBParams& ChromaBParams(int n) const {return m_cbparams[n];}
01010 
01012         MVPrecisionType MVPrecision() const { return m_mv_precision; }
01013 
01015         void SetXNumSB(const int xn){m_x_num_sb=xn;}
01016 
01018         void SetYNumSB(const int yn){m_y_num_sb=yn;}
01019 
01021         void SetXNumBlocks(const int xn){m_x_num_blocks=xn;}
01022 
01024         void SetYNumBlocks(const int yn){m_y_num_blocks=yn;}
01025 
01027         void SetBlockSizes(const OLBParams& olbparams , const ChromaFormat cformat);
01028 
01030         void SetLumaBlockParams(const OLBParams& olbparams) {m_lbparams[2] = olbparams;}
01031 
01033         void SetMVPrecision(const MVPrecisionType p)
01034         {
01035             // Assert in debug mode. Maybe we should throw an exception???
01036             TESTM((p >=0 && p <=3), "Motion precision value in range 0..3");
01037             m_mv_precision = p;
01038         }
01039 
01040         void SetMVPrecision(const MVPrecisionType p) const
01041         {
01042             // Assert in debug mode. Maybe we should throw an exception???
01043             TESTM((p >=0 && p <=3), "Motion precision value in range 0..3");
01044             m_mv_precision = p;
01045         }
01046 
01048         void SetUsingGlobalMotion(bool gm) { m_use_global_motion=gm; }
01049 
01051         void SetPictureWeightsPrecision(unsigned int wt_prec) { m_picture_weights_bits=wt_prec; }
01052 
01054         void SetRef1Weight(int wt) { m_ref1_weight=wt; }
01055 
01057         void SetRef2Weight(int wt) { m_ref2_weight=wt; }
01058 
01059     private:
01060 
01062         int m_x_num_sb;
01063 
01065         int m_y_num_sb;
01066 
01068         int m_x_num_blocks;
01069 
01071         int m_y_num_blocks;
01072 
01073         OneDArray<OLBParams> m_lbparams;
01074 
01075         OneDArray<OLBParams> m_cbparams;
01076 
01078         mutable MVPrecisionType m_mv_precision;
01079 
01081         unsigned int m_picture_weights_bits;
01082 
01084         int m_ref1_weight;
01085 
01087         int m_ref2_weight;
01088 
01090         bool m_use_global_motion;
01091 
01092     };
01093 
01095 
01098     class CodecParams
01099     {
01100     public:
01101 
01103         CodecParams (const VideoFormat& video_format = VIDEO_FORMAT_CUSTOM,
01104                       PictureType ftype = INTRA_PICTURE,
01105                       unsigned int num_refs = 0,
01106                       bool set_defaults=true);
01107 
01109         //NB: Assume default copy constructor, assignment = and destructor//
01111 
01112         // Gets ...
01113 
01115 
01119         int PictureCodingMode() const {return m_pic_coding_mode;}
01120 
01122         bool FieldCoding() const { return  (m_pic_coding_mode==1); }
01123 
01125         bool TopFieldFirst() const {return m_topfieldfirst;}
01126 
01128         int Xl() const {return m_xl;}
01129 
01131         int Yl() const {return m_yl;}
01132 
01134         int ChromaXl() const {return m_cxl;}
01135 
01137         int ChromaYl() const {return m_cyl;}
01138 
01140         unsigned int LumaDepth() const { return m_luma_depth; }
01141 
01143         unsigned int ChromaDepth() const { return m_chroma_depth; }
01144 
01146         bool ZeroTransform() const { return m_zero_transform; }
01147 
01149         WltFilter TransformFilter() const { return m_wlt_filter; }
01150 
01152         unsigned int TransformDepth() const { return m_wlt_depth; }
01153 
01155         CodeBlockMode GetCodeBlockMode() const { return m_cb_mode; }
01156 
01158         bool SpatialPartition() const { return m_spatial_partition; }
01159 
01161         const CodeBlocks &GetCodeBlocks(unsigned int level) const;
01162 
01164         VideoFormat GetVideoFormat() const { return m_video_format; }
01165 
01167     PicturePredParams& GetPicPredParams(){return m_picpredparams;}
01168 
01170     const PicturePredParams& GetPicPredParams() const {return m_picpredparams;}
01171 
01172        // ... and Sets
01174         void SetPictureCodingMode(int pic_coding){m_pic_coding_mode=pic_coding;}
01175 
01177         void SetTopFieldFirst(bool topf){m_topfieldfirst=topf;}
01178 
01180         void SetXl(const int x){m_xl=x;}
01181 
01183         void SetYl(const int y){m_yl=y;}
01184 
01186         void SetChromaXl(const int x){m_cxl=x;}
01187 
01189         void SetChromaYl(const int y){m_cyl=y;}
01190 
01192         void SetLumaDepth(unsigned int luma_depth) { m_luma_depth = luma_depth; }
01193 
01195         void SetChromaDepth(unsigned int chroma_depth) { m_chroma_depth = chroma_depth; }
01196 
01198         void SetZeroTransform(bool zero_transform)  { m_zero_transform = zero_transform; }
01199 
01201         void SetTransformFilter(const WltFilter wf) { m_wlt_filter=wf; }
01202 
01204         void SetTransformFilter(unsigned int wf_idx);
01205 
01207         void SetTransformDepth(unsigned int wd);
01208 
01210         void SetCodeBlockMode(unsigned int cb_mode);
01211 
01213         void SetSpatialPartition(bool spatial_partition) { m_spatial_partition=spatial_partition; }
01214 
01216         void  SetCodeBlocks(unsigned int level, unsigned int hblocks, unsigned int vblocks);
01217 
01219         void SetVideoFormat(const VideoFormat vd) { m_video_format=vd; }
01220 
01221    protected:
01223         WltFilter TransformFilter (unsigned int wf_idx);
01224     private:
01225 
01227     PicturePredParams m_picpredparams;
01228 
01230         int m_pic_coding_mode;
01231 
01233         bool m_topfieldfirst;
01234 
01236         int m_xl;
01237 
01239         int m_yl;
01240 
01242         int m_cxl;
01243 
01245         int m_cyl;
01246 
01248         unsigned int m_luma_depth;
01249 
01251         unsigned int m_chroma_depth;
01252 
01254         VideoFormat m_video_format;
01255 
01257         bool m_zero_transform;
01258 
01260         WltFilter m_wlt_filter;
01261 
01263         unsigned int m_wlt_depth;
01264 
01266         CodeBlockMode m_cb_mode;
01267 
01269         bool m_spatial_partition;
01270 
01272         OneDArray<CodeBlocks> m_cb;
01273     };
01274 
01276 
01279     class EncoderParams: public CodecParams
01280     {
01281         //codec params plus parameters relating solely to the operation of the encoder
01282 
01283     public:
01285         EncoderParams(const VideoFormat& video_format,
01286                       PictureType ftype = INTER_PICTURE,
01287                       unsigned int num_refs = 2,
01288                       bool set_defaults=true);
01289 
01291             //NB: Assume default copy constructor, assignment = and destructor//
01292             //This means pointers are copied, not the objects they point to.////
01294 
01295          // Gets ...
01296 
01297 
01299         bool Verbose() const {return m_verbose;}
01300 
01302         bool LocalDecode() const {return m_loc_decode;}
01303 
01305         bool Lossless() const {return m_lossless;}
01306 
01308         bool FullSearch() const {return m_full_search; }
01309 
01311         int XRangeME() const {return m_x_range_me;}
01312 
01314         int YRangeME() const {return m_y_range_me;}
01315 
01317         bool CombinedME() const {return m_combined_me; }
01318 
01320         float Qf() const {return m_qf;}
01321 
01323 
01328         int NumL1() const {return m_num_L1;}
01329 
01331         int L1Sep() const {return m_L1_sep;}
01332 
01334         float UFactor() const {return m_ufactor;}
01335 
01337         float VFactor() const {return m_vfactor;}
01338 
01340         float CPD() const {return m_cpd;}
01341 
01343         PrefilterType Prefilter() const {return m_prefilter;}
01344 
01346         int PrefilterStrength() const {return m_prefilter_strength;}
01347 
01349         float ILambda() const {return m_I_lambda;}
01350 
01352         float L1Lambda() const {return m_L1_lambda;}
01353 
01355         float L2Lambda() const {return m_L2_lambda;}
01356 
01358         float L1MELambda() const {return m_L1_me_lambda;}
01359 
01361         float L2MELambda() const {return m_L2_me_lambda;}
01362 
01364         int GOPLength() const;
01365 
01367         char * OutputPath() const {return ( char* ) m_output_path.c_str();}
01368 
01370         const EntropyCorrector& EntropyFactors() const {return *m_ent_correct;}
01371 
01373         EntropyCorrector& EntropyFactors() {return *m_ent_correct;}
01374 
01376         WltFilter IntraTransformFilter() { return m_intra_wltfilter; }
01377 
01379         WltFilter InterTransformFilter() { return m_inter_wltfilter; }
01380 
01382         int TargetRate() {return m_target_rate;}
01383 
01385         bool UsingAC()  const {return m_using_ac;}
01386 
01387         // ... and Sets
01388 
01390         void SetVerbose(bool v){m_verbose=v;}
01391 
01393         void SetLocalDecode( const bool decode ){m_loc_decode=decode;}
01394 
01396         void SetLossless(const bool l){m_lossless = l;}
01397 
01399         void SetFullSearch(const bool fs){m_full_search = fs;}
01400 
01402         void SetCombinedME(const bool cme){m_combined_me = cme;}
01403 
01405         void SetXRangeME(const int xr){m_x_range_me = xr;}
01406 
01408         void SetYRangeME(const int yr){m_y_range_me = yr;}
01409 
01411         void SetQf(const float qfac){ m_qf=qfac; CalcLambdas(m_qf); }
01412 
01414         void SetNumL1(const int nl){m_num_L1=nl;}
01415 
01417         void SetL1Sep(const int lsep){m_L1_sep=lsep;}
01418 
01420         void SetUFactor(const float uf){m_ufactor=uf;}
01421 
01423         void SetVFactor(const float vf){m_vfactor=vf;}
01424 
01426         void SetCPD(const float cpd){m_cpd=cpd;}
01427 
01429         void SetPrefilter(const PrefilterType pf, const int str){m_prefilter=pf;
01430                                                                  m_prefilter_strength=str;}
01431 
01433         void SetOutputPath(const char * op){ m_output_path = op; }
01434 
01436         void SetEntropyFactors(EntropyCorrector* entcorrect){m_ent_correct=entcorrect;}
01438         void SetIntraTransformFilter(unsigned int wf_idx);
01439 
01441         void SetInterTransformFilter(unsigned int wf_idx);
01442 
01444         void SetIntraTransformFilter(WltFilter wf) { m_intra_wltfilter = wf; }
01445         
01447         void  SetUsualCodeBlocks(const PictureType& ftype);
01448 
01450         void SetInterTransformFilter(WltFilter wf) { m_inter_wltfilter = wf; }
01451 
01453         void SetTargetRate(const int rate){m_target_rate = rate;}
01454 
01456         void SetUsingAC(bool using_ac) {m_using_ac = using_ac;}
01457     private:
01458 
01460         void CalcLambdas(const float qf);
01461 
01462     private:
01463 
01465         bool m_verbose;
01466 
01468         bool m_loc_decode;
01469 
01471         bool m_lossless;
01472 
01474         bool m_full_search;
01475 
01477         bool m_combined_me;
01478 
01480         int m_x_range_me;
01481 
01483         int m_y_range_me;
01484 
01486         float m_qf;
01487 
01489         int m_num_L1;
01490 
01492         int m_L1_sep;
01493 
01495         float m_ufactor;
01496 
01498         float m_vfactor;
01499 
01501         float m_cpd;
01502 
01504         PrefilterType m_prefilter;
01505 
01507         int m_prefilter_strength;
01508 
01510         float m_I_lambda;
01511 
01513         float m_L1_lambda;
01514 
01516         float m_L2_lambda;
01517 
01519         float m_L1_me_lambda;
01520 
01522         float m_L2_me_lambda;
01523 
01525         EntropyCorrector* m_ent_correct;
01526 
01528         std::string m_output_path;
01529 
01531         WltFilter m_intra_wltfilter;
01532 
01534         WltFilter m_inter_wltfilter;
01535 
01537         int m_target_rate;
01538 
01540         bool m_using_ac;
01541 
01542     };
01543 
01545 
01548     class DecoderParams: public CodecParams
01549     {
01550     public:
01552         DecoderParams(const VideoFormat& video_format = VIDEO_FORMAT_CIF, PictureType ftype=INTRA_PICTURE, unsigned int num_refs = 0, bool set_defaults = false);
01553 
01555         bool Verbose() const {return m_verbose;}
01556 
01558         void SetVerbose(bool v){m_verbose=v;}
01559 
01561             //NB: Assume default copy constructor, assignment = and destructor//
01562             //This means pointers are copied, not the objects they point to.////
01564 
01565 
01566     private:
01567 
01569         bool m_verbose;
01570 
01571     };
01572 
01574     inline ValueType BChk(const ValueType &num, const ValueType &max)
01575     {
01576         if(num < 0) return 0;
01577         else if(num >= max) return max-1;
01578         else return num;
01579     }
01580 
01582     class QuantiserLists
01583     {
01584     public:
01586         QuantiserLists();
01587 
01589         inline int QuantFactor4( const int index ) const {return m_qflist4[index]; }
01590 
01592         inline int IntraQuantOffset4( const int index ) const {return m_intra_offset4[index]; }
01594         inline int InterQuantOffset4( const int index ) const {return m_inter_offset4[index]; }
01595 
01597         inline int MaxQuantIndex() const {return m_max_qindex; }
01598 
01599 
01600     private:
01601         unsigned int m_max_qindex;
01602         OneDArray<int> m_qflist4;
01603         OneDArray<int> m_intra_offset4;
01604         OneDArray<int> m_inter_offset4;
01605 
01606     };
01607 
01609     static const QuantiserLists dirac_quantiser_lists;
01610 
01611 } // namespace dirac
01612 
01613 #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.