Dirac Video Codec

# 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.78 2008/08/27 00:17:10 asuraparaju Exp $ $Name: Dirac_1_0_0 $
    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)
    00074     typedef int CoeffType;
    00075 #else
    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         MB_SPLIT_BIN1_CTX,  // bin 1, MB split mode vals
    00164         MB_SPLIT_BIN2_CTX,  // bin 2, MB split mode vals. Bin 3 not required
    00165
    00166         MB_SPLIT_INFO_CTX,  // info context for MB 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 XNumMB() const {return m_x_num_mb;}
    00995
    00997         int YNumMB() const {return m_y_num_mb;}
    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 SetXNumMB(const int xn){m_x_num_mb=xn;}
    01016
    01018         void SetYNumMB(const int yn){m_y_num_mb=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_mb;
    01063
    01065         int m_y_num_mb;
    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
    01114
    01116
    01120         int PictureCodingMode() const {return m_pic_coding_mode;}
    01121
    01123         bool FieldCoding() const { return  (m_pic_coding_mode==1); }
    01124
    01126         bool TopFieldFirst() const {return m_topfieldfirst;}
    01127
    01129         int Xl() const {return m_xl;}
    01130
    01132         int Yl() const {return m_yl;}
    01133
    01135         int ChromaXl() const {return m_cxl;}
    01136
    01138         int ChromaYl() const {return m_cyl;}
    01139
    01141         unsigned int LumaDepth() const { return m_luma_depth; }
    01142
    01144         unsigned int ChromaDepth() const { return m_chroma_depth; }
    01145
    01147         bool ZeroTransform() const { return m_zero_transform; }
    01148
    01150         WltFilter TransformFilter() const { return m_wlt_filter; }
    01151
    01153         unsigned int TransformDepth() const { return m_wlt_depth; }
    01154
    01156         CodeBlockMode GetCodeBlockMode() const { return m_cb_mode; }
    01157
    01159         bool SpatialPartition() const { return m_spatial_partition; }
    01160
    01162         const CodeBlocks &GetCodeBlocks(unsigned int level) const;
    01163
    01165         VideoFormat GetVideoFormat() const { return m_video_format; }
    01166
    01168     PicturePredParams& GetPicPredParams(){return m_picpredparams;}
    01169
    01171     const PicturePredParams& GetPicPredParams() const {return m_picpredparams;}
    01172
    01173        // ... and Sets
    01175         void SetPictureCodingMode(int pic_coding){m_pic_coding_mode=pic_coding;}
    01176
    01178         void SetTopFieldFirst(bool topf){m_topfieldfirst=topf;}
    01179
    01181         void SetXl(const int x){m_xl=x;}
    01182
    01184         void SetYl(const int y){m_yl=y;}
    01185
    01187         void SetChromaXl(const int x){m_cxl=x;}
    01188
    01190         void SetChromaYl(const int y){m_cyl=y;}
    01191
    01193         void SetLumaDepth(unsigned int luma_depth) { m_luma_depth = luma_depth; }
    01194
    01196         void SetChromaDepth(unsigned int chroma_depth) { m_chroma_depth = chroma_depth; }
    01197
    01199         void SetZeroTransform(bool zero_transform)  { m_zero_transform = zero_transform; }
    01200
    01202         void SetTransformFilter(const WltFilter wf) { m_wlt_filter=wf; }
    01203
    01205         void SetTransformFilter(unsigned int wf_idx);
    01206
    01208         void SetTransformDepth(unsigned int wd);
    01209
    01211         void SetCodeBlockMode(unsigned int cb_mode);
    01212
    01214         void SetSpatialPartition(bool spatial_partition) { m_spatial_partition=spatial_partition; }
    01215
    01217         void  SetCodeBlocks(unsigned int level, unsigned int hblocks, unsigned int vblocks);
    01218
    01220         void SetVideoFormat(const VideoFormat vd) { m_video_format=vd; }
    01221
    01222    protected:
    01224         WltFilter TransformFilter (unsigned int wf_idx);
    01225     private:
    01226
    01228     PicturePredParams m_picpredparams;
    01229
    01231         int m_pic_coding_mode;
    01232
    01234         bool m_topfieldfirst;
    01235
    01237         int m_xl;
    01238
    01240         int m_yl;
    01241
    01243         int m_cxl;
    01244
    01246         int m_cyl;
    01247
    01249         unsigned int m_luma_depth;
    01250
    01252         unsigned int m_chroma_depth;
    01253
    01255         VideoFormat m_video_format;
    01256
    01258         bool m_zero_transform;
    01259
    01261         WltFilter m_wlt_filter;
    01262
    01264         unsigned int m_wlt_depth;
    01265
    01267         CodeBlockMode m_cb_mode;
    01268
    01270         bool m_spatial_partition;
    01271
    01273         OneDArray<CodeBlocks> m_cb;
    01274     };
    01275
    01277
    01280     class EncoderParams: public CodecParams
    01281     {
    01282         //codec params plus parameters relating solely to the operation of the encoder
    01283
    01284     public:
    01286         EncoderParams(const VideoFormat& video_format,
    01287                       PictureType ftype = INTER_PICTURE,
    01288                       unsigned int num_refs = 2,
    01289                       bool set_defaults=true);
    01290
    01292             //NB: Assume default copy constructor, assignment = and destructor//
    01293             //This means pointers are copied, not the objects they point to.////
    01295
    01296          // Gets ...
    01297
    01298
    01300         bool Verbose() const {return m_verbose;}
    01301
    01303         bool LocalDecode() const {return m_loc_decode;}
    01304
    01306         bool Lossless() const {return m_lossless;}
    01307
    01309         bool FullSearch() const {return m_full_search; }
    01310
    01312         int XRangeME() const {return m_x_range_me;}
    01313
    01315         int YRangeME() const {return m_y_range_me;}
    01316
    01318         float Qf() const {return m_qf;}
    01319
    01321
    01326         int NumL1() const {return m_num_L1;}
    01327
    01329         int L1Sep() const {return m_L1_sep;}
    01330
    01332         float UFactor() const {return m_ufactor;}
    01333
    01335         float VFactor() const {return m_vfactor;}
    01336
    01338         float CPD() const {return m_cpd;}
    01339
    01341         PrefilterType Prefilter() const {return m_prefilter;}
    01342
    01344         int PrefilterStrength() const {return m_prefilter_strength;}
    01345
    01347         float ILambda() const {return m_I_lambda;}
    01348
    01350         float L1Lambda() const {return m_L1_lambda;}
    01351
    01353         float L2Lambda() const {return m_L2_lambda;}
    01354
    01356         float L1MELambda() const {return m_L1_me_lambda;}
    01357
    01359         float L2MELambda() const {return m_L2_me_lambda;}
    01360
    01362         int GOPLength() const;
    01363
    01365         char * OutputPath() const {return ( char* ) m_output_path.c_str();}
    01366
    01368         const EntropyCorrector& EntropyFactors() const {return *m_ent_correct;}
    01369
    01371         EntropyCorrector& EntropyFactors() {return *m_ent_correct;}
    01372
    01374         WltFilter IntraTransformFilter() { return m_intra_wltfilter; }
    01375
    01377         WltFilter InterTransformFilter() { return m_inter_wltfilter; }
    01378
    01380         int TargetRate() {return m_target_rate;}
    01381
    01383         bool UsingAC()  const {return m_using_ac;}
    01384
    01385         // ... and Sets
    01386
    01388         void SetVerbose(bool v){m_verbose=v;}
    01389
    01391         void SetLocalDecode( const bool decode ){m_loc_decode=decode;}
    01392
    01394         void SetLossless(const bool l){m_lossless = l;}
    01395
    01397         void SetFullSearch(const bool fs){m_full_search = fs;}
    01398
    01400         void SetXRangeME(const int xr){m_x_range_me = xr;}
    01401
    01403         void SetYRangeME(const int yr){m_y_range_me = yr;}
    01404
    01406         void SetQf(const float qfac){ m_qf=qfac; CalcLambdas(m_qf); }
    01407
    01409         void SetNumL1(const int nl){m_num_L1=nl;}
    01410
    01412         void SetL1Sep(const int lsep){m_L1_sep=lsep;}
    01413
    01415         void SetUFactor(const float uf){m_ufactor=uf;}
    01416
    01418         void SetVFactor(const float vf){m_vfactor=vf;}
    01419
    01421         void SetCPD(const float cpd){m_cpd=cpd;}
    01422
    01424         void SetPrefilter(const PrefilterType pf, const int str){m_prefilter=pf;
    01425                                                                  m_prefilter_strength=str;}
    01426
    01428         void SetOutputPath(const char * op){ m_output_path = op; }
    01429
    01431         void SetEntropyFactors(EntropyCorrector* entcorrect){m_ent_correct=entcorrect;}
    01433         void SetIntraTransformFilter(unsigned int wf_idx);
    01434
    01436         void SetInterTransformFilter(unsigned int wf_idx);
    01437
    01439         void SetIntraTransformFilter(WltFilter wf) { m_intra_wltfilter = wf; }
    01440
    01442         void  SetUsualCodeBlocks(const PictureType& ftype);
    01443
    01445         void SetInterTransformFilter(WltFilter wf) { m_inter_wltfilter = wf; }
    01446
    01448         void SetTargetRate(const int rate){m_target_rate = rate;}
    01449
    01451         void SetUsingAC(bool using_ac) {m_using_ac = using_ac;}
    01452     private:
    01453
    01455         void CalcLambdas(const float qf);
    01456
    01457     private:
    01458
    01460         bool m_verbose;
    01461
    01463         bool m_loc_decode;
    01464
    01466         bool m_lossless;
    01467
    01469         bool m_full_search;
    01470
    01472         int m_x_range_me;
    01473
    01475         int m_y_range_me;
    01476
    01478         float m_qf;
    01479
    01481         int m_num_L1;
    01482
    01484         int m_L1_sep;
    01485
    01487         float m_ufactor;
    01488
    01490         float m_vfactor;
    01491
    01493         float m_cpd;
    01494
    01496         PrefilterType m_prefilter;
    01497
    01499         int m_prefilter_strength;
    01500
    01502         float m_I_lambda;
    01503
    01505         float m_L1_lambda;
    01506
    01508         float m_L2_lambda;
    01509
    01511         float m_L1_me_lambda;
    01512
    01514         float m_L2_me_lambda;
    01515
    01517         EntropyCorrector* m_ent_correct;
    01518
    01520         std::string m_output_path;
    01521
    01523         WltFilter m_intra_wltfilter;
    01524
    01526         WltFilter m_inter_wltfilter;
    01527
    01529         int m_target_rate;
    01530
    01532         bool m_using_ac;
    01533
    01534     };
    01535
    01537
    01540     class DecoderParams: public CodecParams
    01541     {
    01542     public:
    01544         DecoderParams(const VideoFormat& video_format = VIDEO_FORMAT_CIF, PictureType ftype=INTRA_PICTURE, unsigned int num_refs = 0, bool set_defaults = false);
    01545
    01547         bool Verbose() const {return m_verbose;}
    01548
    01550         void SetVerbose(bool v){m_verbose=v;}
    01551
    01553             //NB: Assume default copy constructor, assignment = and destructor//
    01554             //This means pointers are copied, not the objects they point to.////
    01556
    01557
    01558     private:
    01559
    01561         bool m_verbose;
    01562
    01563     };
    01564
    01566     inline ValueType BChk(const ValueType &num, const ValueType &max)
    01567     {
    01568         if(num < 0) return 0;
    01569         else if(num >= max) return max-1;
    01570         else return num;
    01571     }
    01572
    01574     class QuantiserLists
    01575     {
    01576     public:
    01578         QuantiserLists();
    01579
    01581         inline int QuantFactor4( const int index ) const {return m_qflist4[index]; }
    01582
    01584         inline int IntraQuantOffset4( const int index ) const {return m_intra_offset4[index]; }
    01586         inline int InterQuantOffset4( const int index ) const {return m_inter_offset4[index]; }
    01587
    01589         inline int MaxQuantIndex() const {return m_max_qindex; }
    01590
    01591
    01592     private:
    01593         unsigned int m_max_qindex;
    01594         OneDArray<int> m_qflist4;
    01595         OneDArray<int> m_intra_offset4;
    01596         OneDArray<int> m_inter_offset4;
    01597
    01598     };
    01599
    01601     static const QuantiserLists dirac_quantiser_lists;
    01602
    01603 } // namespace dirac
    01604
    01605 #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.