Created by the British Broadcasting Corporation.
00001 /* ***** BEGIN LICENSE BLOCK ***** 00002 * 00003 * $Id: common.h,v 1.59 2007/09/26 12:18:43 asuraparaju Exp $ $Name: Dirac_0_8_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 AspectRatioType IntToAspectRatioType(int aspect_ratio_idx); 00199 00205 SignalRangeType IntToSignalRangeType(int signal_range_idx); 00206 00212 MVPrecisionType IntToMVPrecisionType(int mv_prec); 00213 00214 //Classes used throughout the codec// 00217 class FrameSort 00218 { 00219 public: 00220 FrameSort() { fs = 0x00; } // default intra non-ref 00221 00222 void SetIntra() { fs &= 0xfe; } 00223 void SetInter() { fs |= 0x01; } 00224 void SetNonRef() { fs &= 0xfd; } 00225 void SetRef() { fs |= 0x02; } 00226 00227 bool IsInter () const { return fs & 0x01; } 00228 bool IsIntra () const { return !IsInter(); } 00229 bool IsRef() const { return fs & 0x02; }; 00230 bool IsNonRef() const { return !IsRef(); } 00231 00232 void SetIntraNonRef() { SetIntra(); SetNonRef(); } 00233 void SetIntraRef() { SetIntra(); SetRef(); } 00234 void SetInterNonRef() { SetInter(); SetNonRef(); } 00235 void SetInterRef() { SetInter(); SetRef(); } 00236 00237 bool IsIntraNonRef() const { return (fs & 0x03) == 0x00; } 00238 bool IsIntraRef() const { return (fs & 0x03) == 0x02; } 00239 bool IsInterNonRef() const { return (fs & 0x03) == 0x01; } 00240 bool IsInterRef() const { return (fs & 0x03) == 0x03; } 00241 00242 void Clear() { fs=0x00; } 00243 00244 static FrameSort IntraRefFrameSort() 00245 { 00246 FrameSort fs; 00247 fs.SetIntraRef(); 00248 return fs; 00249 } 00250 00251 static FrameSort InterRefFrameSort() 00252 { 00253 FrameSort fs; 00254 fs.SetInterRef(); 00255 return fs; 00256 } 00257 00258 static FrameSort IntraNonRefFrameSort() 00259 { 00260 FrameSort fs; 00261 fs.SetIntraNonRef(); 00262 return fs; 00263 } 00264 00265 static FrameSort InterNonRefFrameSort() 00266 { 00267 FrameSort fs; 00268 fs.SetInterNonRef(); 00269 return fs; 00270 } 00271 00272 private: 00273 unsigned char fs; 00274 }; 00275 00277 00280 class PicArray: public TwoDArray<ValueType> 00281 { 00282 public: 00284 00287 PicArray(): TwoDArray<ValueType>(){} 00288 00290 00294 PicArray(int height, int width, CompSort cs=Y_COMP); 00295 00296 //copy constructor and assignment= derived by inheritance 00297 00299 ~PicArray(){} 00300 00302 const CompSort& CSort() const; 00303 00305 void SetCSort(const CompSort cs); 00306 00307 private: 00308 00309 CompSort m_csort; 00310 }; 00311 00313 00316 class CoeffArray: public TwoDArray<CoeffType> 00317 { 00318 public: 00320 00323 CoeffArray(): TwoDArray<CoeffType>(){} 00324 00326 00330 CoeffArray(int height, int width): TwoDArray<CoeffType>(height, width){} 00331 00332 //copy constructor and assignment= derived by inheritance 00333 00335 ~CoeffArray(){} 00336 00337 }; 00338 00339 00341 class CostType 00342 { 00343 public: 00345 double Error; 00346 00348 double ENTROPY; 00349 00351 double TOTAL; 00352 }; 00353 00354 00356 00361 class EntropyCorrector 00362 { 00363 public: 00365 00369 EntropyCorrector(int depth); 00370 00372 //NB: Assume default copy constructor, assignment = and destructor// 00374 00376 00380 float Factor(const int bandnum, const FrameSort fsort,const CompSort c) const; 00381 00383 00391 void Update(int bandnum, FrameSort fsort, CompSort c,int est_bits,int actual_bits); 00392 00393 private: 00395 void Init(); 00396 00397 TwoDArray<float> m_Yfctrs; 00398 TwoDArray<float> m_Ufctrs; 00399 TwoDArray<float> m_Vfctrs; 00400 }; 00401 00403 class OLBParams 00404 { 00405 00406 public: 00407 00409 OLBParams(){} 00410 00412 /* 00413 Constructor rationalises proposed parameters to allow suitable 00414 overlap and fit in with chroma format 00415 \param xblen the horizontal block length 00416 \param yblen the vertical block length 00417 \param xblen the horizontal block separation 00418 \param yblen the vertical block separation 00419 00420 */ 00421 OLBParams(const int xblen, const int yblen, 00422 const int xbsep, const int ybsep); 00423 00424 // Gets ... 00425 00427 int Xblen() const {return m_xblen;} 00428 00430 int Yblen() const {return m_yblen;} 00431 00433 int Xbsep() const {return m_xbsep;} 00434 00436 int Ybsep() const {return m_ybsep;} 00437 00439 int Xoffset() const {return m_xoffset;} 00440 00442 int Yoffset() const {return m_yoffset;} 00443 00444 // ... and sets 00445 00447 void SetXblen( int xblen ){ m_xblen = xblen; m_xoffset = (m_xblen-m_xbsep)/2;} 00448 00450 void SetYblen( int yblen ){ m_yblen = yblen; m_yoffset = (m_yblen-m_ybsep)/2;} 00451 00453 void SetXbsep( int xbsep ){ m_xbsep = xbsep; m_xoffset = (m_xblen-m_xbsep)/2;} 00454 00456 void SetYbsep( int ybsep ){ m_ybsep = ybsep; m_yoffset = (m_yblen-m_ybsep)/2;} 00457 00458 bool operator == (const OLBParams bparams) const; 00459 00460 // overloaded stream operators 00461 friend std::ostream & operator<< (std::ostream &, OLBParams &); 00462 friend std::istream & operator>> (std::istream &, OLBParams &); 00463 00464 00465 private: 00466 00467 int m_xblen; 00468 int m_yblen; 00469 int m_xbsep; 00470 int m_ybsep; 00471 int m_xoffset; 00472 int m_yoffset; 00473 }; 00474 00476 class Rational 00477 { 00478 public: 00480 unsigned int m_num; 00482 unsigned int m_denom; 00483 }; 00484 00486 class ParseParams 00487 { 00488 public: 00490 ParseParams(); 00491 00492 // Gets 00493 00495 unsigned int MajorVersion() const { return m_major_ver; } 00496 00498 unsigned int MinorVersion() const { return m_minor_ver; } 00499 00501 unsigned int Profile() const { return m_profile; } 00502 00504 unsigned int Level() const { return m_level; } 00505 00506 // Sets 00507 00509 void SetMajorVersion(unsigned int major_ver) {m_major_ver = major_ver; } 00510 00512 void SetMinorVersion(unsigned int minor_ver) { m_minor_ver = minor_ver; } 00513 00515 void SetProfile(unsigned int level) { m_level = level; } 00516 00518 void SetLevel(unsigned int profile) { m_profile = profile; } 00519 00520 private: 00522 unsigned int m_major_ver; 00524 unsigned int m_minor_ver; 00526 unsigned int m_profile; 00528 unsigned int m_level; 00529 }; 00530 00532 class SourceParams 00533 { 00534 public: 00536 SourceParams (const VideoFormat &vf = VIDEO_FORMAT_CUSTOM, 00537 bool set_defaults=true); 00538 00540 //NB: Assume default copy constructor, assignment = and destructor// 00542 00543 // Gets 00545 VideoFormat GetVideoFormat() const { return m_video_format;} 00546 00548 unsigned int Xl() const {return m_xl;} 00549 00551 unsigned int Yl() const {return m_yl;} 00552 00554 ChromaFormat CFormat() const {return m_cformat;} 00555 00557 int ChromaWidth() const; 00558 00560 int ChromaHeight() const; 00561 00563 bool Interlace() const { return m_interlace; } 00564 00566 bool TopFieldFirst() const { return m_topfieldfirst; } 00567 00569 Rational FrameRate() const { return m_framerate; } 00570 00572 FrameRateType FrameRateIndex() const { return m_fr_idx; } 00573 00575 Rational AspectRatio() const { return m_aspect_ratio; } 00576 00578 AspectRatioType AspectRatioIndex() const { return m_asr_idx; } 00579 00580 // Clean area parameters 00582 unsigned int CleanWidth() const { return m_clean_width; } 00584 unsigned int CleanHeight() const { return m_clean_height; } 00586 unsigned int LeftOffset() const { return m_left_offset; } 00588 unsigned int TopOffset() const { return m_top_offset; } 00589 00590 // Signal Range parameters 00591 00593 SignalRangeType SignalRangeIndex() const { return m_sr_idx; } 00594 00596 unsigned int LumaOffset() const { return m_luma_offset; } 00598 unsigned int LumaExcursion() const { return m_luma_excursion; } 00600 unsigned int ChromaOffset() const { return m_chroma_offset; } 00602 unsigned int ChromaExcursion() const { return m_chroma_excursion; } 00603 00605 unsigned int ColourSpecificationIndex() const { return m_cs_idx; } 00606 00608 ColourPrimaries ColourPrimariesIndex() const { return m_col_primary; } 00610 ColourMatrix ColourMatrixIndex() const { return m_col_matrix; } 00612 TransferFunction TransferFunctionIndex() const { return m_transfer_func; } 00613 00614 // Sets 00615 00617 void SetXl(unsigned int xlen) {m_xl = xlen;} 00618 00620 void SetYl(unsigned int ylen) {m_yl = ylen;} 00621 00623 void SetCFormat(ChromaFormat cf) {m_cformat=cf;} 00624 00626 void SetInterlace(bool interlace) { m_interlace = interlace; } 00627 00629 void SetTopFieldFirst(bool tff) { m_topfieldfirst = tff; } 00630 00632 void SetVideoFormat(VideoFormat vf){ m_video_format=vf;} 00633 00635 void SetFrameRate(const Rational &frate ) 00636 { 00637 m_fr_idx = FRAMERATE_CUSTOM; m_framerate = frate; 00638 } 00639 00641 void SetFrameRate(unsigned int fr_num, unsigned int fr_denom ) 00642 { 00643 m_fr_idx = FRAMERATE_CUSTOM; 00644 m_framerate.m_num = fr_num; 00645 m_framerate.m_denom = fr_denom; 00646 } 00647 00649 void SetFrameRate(FrameRateType fr); 00650 00652 void SetAspectRatio(const Rational &asr) 00653 { 00654 m_asr_idx = ASPECT_RATIO_CUSTOM; 00655 m_aspect_ratio = asr; 00656 } 00657 00659 void SetAspectRatio(unsigned int as_num, unsigned int as_denom ) 00660 { 00661 m_asr_idx = ASPECT_RATIO_CUSTOM; 00662 m_aspect_ratio.m_num = as_num; 00663 m_aspect_ratio.m_denom = as_denom; 00664 } 00665 00667 void SetAspectRatio(AspectRatioType aspect_ratio); 00668 00669 // Clean area parameters 00671 void SetCleanWidth(unsigned int clean_width) { m_clean_width = clean_width; } 00673 void SetCleanHeight(unsigned int clean_height) { m_clean_height = clean_height; } 00675 void SetLeftOffset(unsigned int left_offset) { m_left_offset = left_offset; } 00677 void SetTopOffset(unsigned int top_offset) { m_top_offset = top_offset; } 00678 00679 // Signal Range parameters 00681 void SetSignalRange(SignalRangeType sr); 00682 00684 void SetLumaOffset(unsigned int luma_offset) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_luma_offset = luma_offset; } 00686 void SetLumaExcursion(unsigned int luma_exc) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_luma_excursion = luma_exc; } 00688 void SetChromaOffset(unsigned int chroma_off) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_chroma_offset = chroma_off; } 00690 void SetChromaExcursion(unsigned int chroma_exc) { m_sr_idx = SIGNAL_RANGE_CUSTOM; m_chroma_excursion = chroma_exc; } 00691 00693 void SetColourSpecification(unsigned int cs_idx); 00695 void SetColourPrimariesIndex(unsigned int cp); 00697 void SetColourMatrixIndex(unsigned int cm); 00699 void SetTransferFunctionIndex(unsigned int tf); 00700 00701 private: 00703 VideoFormat m_video_format; 00704 00706 unsigned int m_xl; 00707 00709 unsigned int m_yl; 00710 00712 ChromaFormat m_cformat; 00713 00715 bool m_interlace; 00716 00718 bool m_topfieldfirst; 00719 00721 FrameRateType m_fr_idx; 00722 00724 Rational m_framerate; 00725 00727 AspectRatioType m_asr_idx; 00728 00730 Rational m_aspect_ratio; 00731 00732 // Clean area parameters 00733 00735 unsigned int m_clean_width; 00736 00738 unsigned int m_clean_height; 00739 00741 unsigned int m_left_offset; 00742 00744 unsigned int m_top_offset; 00745 00746 // signal range parameters 00747 00749 SignalRangeType m_sr_idx; 00750 00752 unsigned int m_luma_offset; 00754 unsigned int m_luma_excursion; 00756 unsigned int m_chroma_offset; 00758 unsigned int m_chroma_excursion; 00759 00761 unsigned int m_cs_idx; 00762 00764 ColourPrimaries m_col_primary; 00765 00766 // Colour Matrix index 00767 ColourMatrix m_col_matrix; 00768 00769 // Transfer function index 00770 TransferFunction m_transfer_func; 00771 }; 00772 00774 class FrameParams 00775 { 00776 00777 public: 00779 FrameParams(); 00780 00782 00785 FrameParams(const ChromaFormat& cf, int orig_xlen, int orig_ylen, 00786 int dwt_xlen, int dwt_ylen, 00787 int c_dwt_xlen, int c_dwt_ylen, 00788 unsigned int luma_depth, unsigned int chroma_depth); 00789 00791 00794 FrameParams(const ChromaFormat& cf, const FrameSort& fs); 00795 00797 /* 00798 All data is derived from the sequence parameters 00799 */ 00800 FrameParams(const SourceParams& sparams); 00801 00803 /* 00804 All data is derived from the sequence parameters 00805 */ 00806 FrameParams(const SourceParams& sparams, const FrameSort& fs); 00807 00809 //NB: Assume default copy constructor, assignment = and destructor// 00811 00812 // Gets ... 00813 00815 const ChromaFormat& CFormat() const{return m_cformat;} 00816 00818 int DwtXl() const{return m_dwt_xl;} 00819 00821 int DwtYl() const{return m_dwt_yl;} 00822 00824 int DwtChromaXl() const{return m_dwt_chroma_xl;} 00825 00827 int DwtChromaYl() const{return m_dwt_chroma_yl;} 00828 00830 int OrigXl() const {return m_orig_xl;} 00831 00833 int OrigYl() const {return m_orig_yl;} 00834 00836 int OrigChromaXl() const{return m_orig_cxl;} 00837 00839 int OrigChromaYl() const{return m_orig_cyl;} 00840 00842 unsigned int LumaDepth() const { return m_luma_depth; } 00843 00845 unsigned int ChromaDepth() const { return m_chroma_depth; } 00846 00848 const FrameSort& FSort() const {return m_fsort;} 00849 00851 int FrameNum() const {return m_fnum;} 00852 00854 bool IsBFrame() const; 00855 00857 int ExpiryTime() const {return m_expiry_time;} 00858 00860 bool Output() const {return m_output;} 00861 00863 const std::vector<int>& Refs() const {return m_refs;} 00864 00866 std::vector<int>& Refs(){return m_refs;} 00867 00869 unsigned int NumRefs()const {return m_refs.size();} 00870 00872 FrameType GetFrameType () const { return m_frame_type; } 00873 00875 ReferenceType GetReferenceType() const { return m_reference_type;} 00876 00877 // ... Sets 00878 00880 void SetFSort( const FrameSort& fs ); 00881 00883 void SetFrameType(const FrameType ftype); 00884 00886 void SetReferenceType(const ReferenceType rtype); 00887 00889 void SetFrameNum( const int fn ){ m_fnum=fn; } 00890 00892 void SetExpiryTime( const int expt ){ m_expiry_time=expt; } 00893 00895 void SetAsOutput(){m_output=true;} 00896 00898 void SetCFormat(ChromaFormat cf){ m_cformat = cf; } 00899 00901 void SetDwtXl(int xl){m_dwt_xl = xl; } 00902 00904 void SetDwtYl(int yl){m_dwt_yl = yl; } 00905 00907 void SetOrigXl(int orig_xlen); 00908 00910 void SetOrigYl(int orig_ylen); 00911 00913 void SetDwtChromaXl(int xl){m_dwt_chroma_xl = xl; } 00914 00916 void SetDwtChromaYl(int yl){m_dwt_chroma_yl = yl; } 00917 00919 void SetLumaDepth(unsigned int luma_depth) { m_luma_depth = luma_depth; } 00920 00922 void SetChromaDepth(unsigned int chroma_depth) { m_chroma_depth = chroma_depth; } 00923 00925 std::vector<int>& RetiredFrames() const {return m_retd_list;} 00926 00928 std::vector<int>& RetiredFrames() {return m_retd_list;} 00929 00930 private: 00931 00933 ChromaFormat m_cformat; 00934 00936 int m_dwt_xl; 00937 00939 int m_dwt_yl; 00940 00942 FrameSort m_fsort; 00943 00945 std::vector<int> m_refs; 00946 00948 int m_expiry_time; 00949 00951 int m_fnum; 00952 00954 FrameType m_frame_type; 00955 00957 ReferenceType m_reference_type; 00958 00960 bool m_output; 00961 00963 int m_dwt_chroma_xl; 00964 00966 int m_dwt_chroma_yl; 00967 00969 mutable std::vector<int> m_retd_list; 00970 00972 int m_orig_xl; 00973 00975 int m_orig_yl; 00976 00978 int m_orig_cxl; 00979 00981 int m_orig_cyl; 00982 00984 unsigned int m_luma_depth; 00985 00987 unsigned int m_chroma_depth; 00988 00989 }; 00990 00992 class CodeBlocks 00993 { 00994 public: 00996 CodeBlocks () : m_hblocks(0), m_vblocks(0) 00997 {} 00998 01000 CodeBlocks (unsigned int hblocks, unsigned int vblocks) : 01001 m_hblocks(hblocks), 01002 m_vblocks(vblocks) 01003 {} 01004 01005 // Gets 01007 unsigned int HorizontalCodeBlocks() const { return m_hblocks; } 01009 unsigned int VerticalCodeBlocks() const { return m_vblocks; } 01010 // Sets 01012 void SetHorizontalCodeBlocks(unsigned int hblocks) { m_hblocks = hblocks; } 01014 void SetVerticalCodeBlocks(unsigned int vblocks) { m_vblocks = vblocks; } 01015 private: 01017 unsigned int m_hblocks; 01019 unsigned int m_vblocks; 01020 }; 01022 01025 class CodecParams 01026 { 01027 public: 01028 01030 CodecParams (const VideoFormat& video_format = VIDEO_FORMAT_CUSTOM, 01031 FrameType ftype = INTRA_FRAME, 01032 unsigned int num_refs = 0, 01033 bool set_defaults=true); 01034 01036 //NB: Assume default copy constructor, assignment = and destructor// 01038 01039 // Gets ... 01040 01042 int XNumMB() const {return m_x_num_mb;} 01043 01045 int YNumMB() const {return m_y_num_mb;} 01046 01048 int XNumBlocks() const {return m_x_num_blocks;} 01049 01051 int YNumBlocks() const {return m_y_num_blocks;} 01052 01054 bool Interlace() const {return m_interlace;} 01055 01057 bool TopFieldFirst() const {return m_topfieldfirst;} 01058 01060 int OrigXl() const {return m_orig_xl;} 01061 01063 int OrigYl() const {return m_orig_yl;} 01064 01066 int OrigChromaXl() const {return m_orig_cxl;} 01067 01069 int OrigChromaYl() const {return m_orig_cyl;} 01070 01072 unsigned int LumaDepth() const { return m_luma_depth; } 01073 01075 unsigned int ChromaDepth() const { return m_chroma_depth; } 01076 01077 01079 const OLBParams& LumaBParams(int n) const {return m_lbparams[n];} 01080 01082 const OLBParams& ChromaBParams(int n) const {return m_cbparams[n];} 01083 01085 MVPrecisionType MVPrecision() const { return m_mv_precision; } 01086 01088 bool ZeroTransform() const { return m_zero_transform; } 01089 01091 WltFilter TransformFilter() const { return m_wlt_filter; } 01092 01094 unsigned int TransformDepth() const { return m_wlt_depth; } 01095 01097 CodeBlockMode GetCodeBlockMode() const { return m_cb_mode; } 01098 01100 bool SpatialPartition() const { return m_spatial_partition; } 01101 01103 bool DefaultSpatialPartition() const { return m_def_spatial_partition; } 01105 const CodeBlocks &GetCodeBlocks(unsigned int level) const; 01106 01108 VideoFormat GetVideoFormat() const { return m_video_format; } 01109 01111 bool UsingGlobalMotion() const { return m_use_global_motion; } 01112 01114 unsigned int FrameWeightsBits() const { return m_frame_weights_bits; } 01115 01117 unsigned int Ref1Weight() const { return m_ref1_weight; } 01118 01120 unsigned int Ref2Weight() const { return m_ref2_weight; } 01121 01122 // ... and Sets 01124 void SetXNumMB(const int xn){m_x_num_mb=xn;} 01125 01127 void SetYNumMB(const int yn){m_y_num_mb=yn;} 01128 01130 void SetXNumBlocks(const int xn){m_x_num_blocks=xn;} 01131 01133 void SetYNumBlocks(const int yn){m_y_num_blocks=yn;} 01134 01136 void SetInterlace(bool intlc){m_interlace=intlc;} 01137 01139 void SetTopFieldFirst(bool topf){m_topfieldfirst=topf;} 01140 01142 void SetOrigXl(const int x){m_orig_xl=x;} 01143 01145 void SetOrigYl(const int y){m_orig_yl=y;} 01146 01147 01149 void SetOrigChromaXl(const int x){m_orig_cxl=x;} 01150 01152 void SetOrigChromaYl(const int y){m_orig_cyl=y;} 01153 01155 void SetLumaDepth(unsigned int luma_depth) { m_luma_depth = luma_depth; } 01156 01158 void SetChromaDepth(unsigned int chroma_depth) { m_chroma_depth = chroma_depth; } 01159 01161 void SetBlockSizes(const OLBParams& olbparams , const ChromaFormat cformat); 01163 void SetLumaBlockParams(const OLBParams& olbparams) {m_lbparams[2] = olbparams;} 01164 01166 void SetMVPrecision(const MVPrecisionType p) 01167 { 01168 // Assert in debug mode. Maybe we should throw an exception??? 01169 TESTM((p >=0 && p <=3), "Motion precision value in range 0..3"); 01170 m_mv_precision = p; 01171 } 01172 01173 void SetMVPrecision(const MVPrecisionType p) const 01174 { 01175 // Assert in debug mode. Maybe we should throw an exception??? 01176 TESTM((p >=0 && p <=3), "Motion precision value in range 0..3"); 01177 m_mv_precision = p; 01178 } 01179 01181 void SetZeroTransform(bool zero_transform) { m_zero_transform = zero_transform; } 01182 01184 void SetTransformFilter(const WltFilter wf) { m_wlt_filter=wf; } 01185 01187 void SetTransformFilter(unsigned int wf_idx); 01188 01190 void SetTransformDepth(unsigned int wd); 01191 01193 void SetCodeBlockMode(unsigned int cb_mode); 01194 01196 void SetSpatialPartition(bool spatial_partition) { m_spatial_partition=spatial_partition; } 01197 01199 void SetDefaultSpatialPartition(bool def_spatial_partition) { m_def_spatial_partition=def_spatial_partition; } 01200 01202 void SetCodeBlocks(unsigned int level, unsigned int hblocks, unsigned int vblocks); 01203 01205 void SetDefaultCodeBlocks(const FrameType& ftype); 01206 01208 void SetVideoFormat(const VideoFormat vd) { m_video_format=vd; } 01209 01211 void SetUsingGlobalMotion(bool gm) { m_use_global_motion=gm; } 01212 01214 void SetFrameWeightsPrecision(unsigned int wt_prec) { m_frame_weights_bits=wt_prec; } 01215 01217 void SetRef1Weight(unsigned int wt) { m_ref1_weight=wt; } 01218 01220 void SetRef2Weight(unsigned int wt) { m_ref2_weight=wt; } 01221 01222 protected: 01224 WltFilter TransformFilter (unsigned int wf_idx); 01225 private: 01226 01228 bool m_interlace; 01229 01231 bool m_topfieldfirst; 01232 01234 int m_orig_xl; 01235 01237 int m_orig_yl; 01238 01240 int m_orig_cxl; 01241 01243 int m_orig_cyl; 01244 01246 unsigned int m_luma_depth; 01247 01249 unsigned int m_chroma_depth; 01250 01252 int m_x_num_mb; 01253 01255 int m_y_num_mb; 01256 01258 int m_x_num_blocks; 01259 01261 int m_y_num_blocks; 01262 01263 OneDArray<OLBParams> m_lbparams; 01264 01265 OneDArray<OLBParams> m_cbparams; 01266 01268 mutable MVPrecisionType m_mv_precision; 01269 01271 VideoFormat m_video_format; 01272 01274 bool m_use_global_motion; 01275 01277 unsigned int m_frame_weights_bits; 01278 01280 unsigned int m_ref1_weight; 01281 01283 unsigned int m_ref2_weight; 01284 01286 bool m_zero_transform; 01287 01289 WltFilter m_wlt_filter; 01290 01292 unsigned int m_wlt_depth; 01293 01295 CodeBlockMode m_cb_mode; 01296 01298 bool m_spatial_partition; 01299 01301 bool m_def_spatial_partition; 01302 01304 OneDArray<CodeBlocks> m_cb; 01305 }; 01306 01308 01311 class EncoderParams: public CodecParams 01312 { 01313 //codec params plus parameters relating solely to the operation of the encoder 01314 01315 public: 01317 EncoderParams(const VideoFormat& video_format, 01318 FrameType ftype = INTER_FRAME, 01319 unsigned int num_refs = 2, 01320 bool set_defaults=true); 01321 01323 //NB: Assume default copy constructor, assignment = and destructor// 01324 //This means pointers are copied, not the objects they point to.//// 01326 01327 // Gets ... 01328 01329 01331 bool Verbose() const {return m_verbose;} 01332 01334 bool LocalDecode() const {return m_loc_decode;} 01335 01337 bool Lossless() const {return m_lossless;} 01338 01340 bool FullSearch() const {return m_full_search; } 01341 01343 int XRangeME() const {return m_x_range_me;} 01344 01346 int YRangeME() const {return m_y_range_me;} 01347 01349 float Qf() const {return m_qf;} 01350 01352 01357 int NumL1() const {return m_num_L1;} 01358 01360 int L1Sep() const {return m_L1_sep;} 01361 01363 float UFactor() const {return m_ufactor;} 01364 01366 float VFactor() const {return m_vfactor;} 01367 01369 float CPD() const {return m_cpd;} 01370 01372 bool Denoise() const {return m_denoise;} 01373 01375 float ILambda() const {return m_I_lambda;} 01376 01378 float L1Lambda() const {return m_L1_lambda;} 01379 01381 float L2Lambda() const {return m_L2_lambda;} 01382 01384 float L1MELambda() const {return m_L1_me_lambda;} 01385 01387 float L2MELambda() const {return m_L2_me_lambda;} 01388 01390 int GOPLength() const; 01391 01393 char * OutputPath() const {return ( char* ) m_output_path.c_str();} 01394 01396 const EntropyCorrector& EntropyFactors() const {return *m_ent_correct;} 01397 01399 EntropyCorrector& EntropyFactors() {return *m_ent_correct;} 01400 01402 WltFilter IntraTransformFilter() { return m_intra_wltfilter; } 01403 01405 WltFilter InterTransformFilter() { return m_inter_wltfilter; } 01406 01408 int TargetRate() {return m_target_rate;} 01409 01410 // ... and Sets 01411 01413 void SetVerbose(bool v){m_verbose=v;} 01414 01416 void SetLocalDecode( const bool decode ){m_loc_decode=decode;} 01417 01419 void SetLossless(const bool l){m_lossless = l;} 01420 01422 void SetFullSearch(const bool fs){m_full_search = fs;} 01423 01425 void SetXRangeME(const int xr){m_x_range_me = xr;} 01426 01428 void SetYRangeME(const int yr){m_y_range_me = yr;} 01429 01431 void SetQf(const float qfac){ m_qf=qfac; CalcLambdas(m_qf); } 01432 01434 void SetNumL1(const int nl){m_num_L1=nl;} 01435 01437 void SetL1Sep(const int lsep){m_L1_sep=lsep;} 01438 01440 void SetUFactor(const float uf){m_ufactor=uf;} 01441 01443 void SetVFactor(const float vf){m_vfactor=vf;} 01444 01446 void SetCPD(const float cpd){m_cpd=cpd;} 01447 01448 01450 void SetDenoise(const bool denoise){m_denoise=denoise;} 01451 01453 void SetOutputPath(const char * op){ m_output_path = op; } 01454 01456 void SetEntropyFactors(EntropyCorrector* entcorrect){m_ent_correct=entcorrect;} 01458 void SetIntraTransformFilter(unsigned int wf_idx); 01459 01461 void SetInterTransformFilter(unsigned int wf_idx); 01462 01464 void SetIntraTransformFilter(WltFilter wf) { m_intra_wltfilter = wf; } 01465 01467 void SetInterTransformFilter(WltFilter wf) { m_inter_wltfilter = wf; } 01468 01470 void SetTargetRate(const int rate){m_target_rate = rate;} 01471 private: 01472 01474 void CalcLambdas(const float qf); 01475 01476 private: 01477 01479 bool m_verbose; 01480 01482 bool m_loc_decode; 01483 01485 bool m_lossless; 01486 01488 bool m_full_search; 01489 01491 int m_x_range_me; 01492 01494 int m_y_range_me; 01495 01497 float m_qf; 01498 01500 int m_num_L1; 01501 01503 int m_L1_sep; 01504 01506 float m_ufactor; 01507 01509 float m_vfactor; 01510 01512 float m_cpd; 01513 01515 bool m_denoise; 01516 01518 float m_I_lambda; 01519 01521 float m_L1_lambda; 01522 01524 float m_L2_lambda; 01525 01527 float m_L1_me_lambda; 01528 01530 float m_L2_me_lambda; 01531 01533 EntropyCorrector* m_ent_correct; 01534 01536 std::string m_output_path; 01537 01539 WltFilter m_intra_wltfilter; 01540 01542 WltFilter m_inter_wltfilter; 01543 01545 int m_target_rate; 01546 01547 }; 01548 01550 01553 class DecoderParams: public CodecParams 01554 { 01555 public: 01557 DecoderParams(const VideoFormat& video_format = VIDEO_FORMAT_CIF, FrameType ftype=INTRA_FRAME, unsigned int num_refs = 0, bool set_defaults = false); 01558 01560 bool Verbose() const {return m_verbose;} 01561 01563 void SetVerbose(bool v){m_verbose=v;} 01564 01566 //NB: Assume default copy constructor, assignment = and destructor// 01567 //This means pointers are copied, not the objects they point to.//// 01569 01570 01571 private: 01572 01574 bool m_verbose; 01575 01576 }; 01577 01579 inline ValueType BChk(const ValueType &num, const ValueType &max) 01580 { 01581 if(num < 0) return 0; 01582 else if(num >= max) return max-1; 01583 else return num; 01584 } 01585 01587 class QuantiserLists 01588 { 01589 public: 01591 QuantiserLists(); 01592 01594 inline int QuantFactor4( const int index ) const {return m_qflist4[index]; } 01595 01597 inline int IntraQuantOffset4( const int index ) const {return m_intra_offset4[index]; } 01599 inline int InterQuantOffset4( const int index ) const {return m_inter_offset4[index]; } 01600 01602 inline int MaxQIndex() const {return m_max_qindex; } 01603 01604 01605 private: 01606 unsigned int m_max_qindex; 01607 OneDArray<int> m_qflist4; 01608 OneDArray<int> m_intra_offset4; 01609 OneDArray<int> m_inter_offset4; 01610 01611 }; 01612 01614 static const QuantiserLists dirac_quantiser_lists; 01615 01616 } // namespace dirac 01617 01618 #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.