digiKam
coding-options.h
Go to the documentation of this file.
1 /*
2  * H.265 video codec.
3  * Copyright (c) 2013-2014 struktur AG, Dirk Farin <farin@struktur.de>
4  *
5  * Authors: Dirk Farin <farin@struktur.de>
6  *
7  * This file is part of libde265.
8  *
9  * libde265 is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser General Public License as
11  * published by the Free Software Foundation, either version 3 of
12  * the License, or (at your option) any later version.
13  *
14  * libde265 is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with libde265. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef CODING_OPTIONS_H
24 #define CODING_OPTIONS_H
25 
27 
28 
29 template <class node> class CodingOption;
30 
31 
32 template <class node>
34 {
35  public:
38 
40 
41  // --- init --- call before object use
42 
43  CodingOption<node> new_option(bool active=true);
44 
46  {
47  Rate_Default, // take default value from encoder_context
50  };
51 
53 
54 
55  // --- processing ---
56 
57  // compute RDO cost (D + lambda*R) for all options
59 
60 
61  // --- end processing --- do not call any function after this one
62 
63  /* Return the CB with the lowest RDO cost. All other CBs are destroyed.
64  If the current metadata stored in the image are not from the returned block,
65  its metadata flags are set to zero.
66  */
68 
69  private:
70  struct CodingOptionData
71  {
72  node* mNode;
73 
74  context_model_table context;
75  bool mOptionActive;
76  bool computed;
77  float rdoCost;
78  };
79 
80 
81  encoder_context* mECtx;
82 
83  bool mCBMode;
84  node* mInputNode;
85 
86  context_model_table* mContextModelInput;
87 
88  int mBestRDO;
89 
90  std::vector<CodingOptionData> mOptions;
91 
92  CABAC_encoder_estim cabac_adaptive;
93  CABAC_encoder_estim_constant cabac_constant;
95 
96  friend class CodingOption<node>;
97 
98  int find_best_rdo_index();
99 };
100 
101 
102 template <class node>
104 {
105  public:
107  mParent = nullptr;
108  mOptionIdx = 0;
109  }
110 
111  node* get_node() { return mParent->mOptions[mOptionIdx].mNode; }
112  void set_node(node* _node) {
113  if (_node != mParent->mOptions[mOptionIdx].mNode) {
114  //printf("delete TB %p\n", mParent->mOptions[mOptionIdx].tb);
115  //delete mParent->mOptions[mOptionIdx].mNode;
116  }
117  mParent->mOptions[mOptionIdx].mNode = _node;
118  }
119 
120  context_model_table& get_context() { return mParent->mOptions[mOptionIdx].context; }
121 
124  operator bool() const { return mParent; }
125 
126  /* When modifying the metadata stored in the image, you have to
127  encapsulate the modification between these two functions to ensure
128  that the correct reconstruction will be active after return_best_rdo().
129  */
130  void begin();
131  void end();
132 
133  // Manually set RDO costs instead of computing them with compute_rdo_costs.
134  // Only required when using custom costs.
135  void set_rdo_cost(float rdo) { mParent->mOptions[mOptionIdx].rdoCost=rdo; }
136 
137  CABAC_encoder_estim* get_cabac() { return mParent->cabac; }
138  float get_cabac_rate() const { return mParent->cabac->getRDBits(); }
139 
140 private:
141  CodingOption(class CodingOptions<node>* parent, int idx)
142  : mParent(parent), mOptionIdx(idx) { }
143 
144  class CodingOptions<node>* mParent;
145  int mOptionIdx;
146 
147  friend class CodingOptions<node>;
148 };
149 
150 
151 #endif
Definition: cabac.h:204
Definition: cabac.h:166
Definition: coding-options.h:104
CodingOption()
Definition: coding-options.h:106
context_model_table & get_context()
Definition: coding-options.h:120
float get_cabac_rate() const
Definition: coding-options.h:138
void set_node(node *_node)
Definition: coding-options.h:112
CABAC_encoder_estim * get_cabac()
Definition: coding-options.h:137
void set_rdo_cost(float rdo)
Definition: coding-options.h:135
node * get_node()
Definition: coding-options.h:111
Definition: coding-options.h:34
CodingOptions(encoder_context *, node *, context_model_table &tab)
CodingOption< node > Option
Definition: coding-options.h:39
CodingOption< node > new_option(bool active=true)
void start(enum RateEstimationMethod=Rate_Default)
RateEstimationMethod
Definition: coding-options.h:46
@ Rate_FixedContext
Definition: coding-options.h:49
@ Rate_Default
Definition: coding-options.h:47
@ Rate_AdaptiveContext
Definition: coding-options.h:48
void compute_rdo_costs()
node * return_best_rdo_node()
Definition: contextmodel.h:100
Definition: encoder-context.h:39