~ubuntu-branches/ubuntu/wily/libde265/wily

« back to all changes in this revision

Viewing changes to libde265/encoder/algo/tb-intrapredmode.h

  • Committer: Package Import Robot
  • Author(s): Joachim Bauch
  • Date: 2015-07-16 11:07:46 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20150716110746-76vsv24j3yux7tnu
Tags: 1.0.2-1
* Imported Upstream version 1.0.2
* Added new files to copyright information.
* Only export decoder API and update symbols for new version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 TB_INTRAPREDMODE_H
 
24
#define TB_INTRAPREDMODE_H
 
25
 
 
26
#include "libde265/nal-parser.h"
 
27
#include "libde265/decctx.h"
 
28
#include "libde265/encoder/encode.h"
 
29
#include "libde265/slice.h"
 
30
#include "libde265/scan.h"
 
31
#include "libde265/intrapred.h"
 
32
#include "libde265/transform.h"
 
33
#include "libde265/fallback-dct.h"
 
34
#include "libde265/quality.h"
 
35
#include "libde265/fallback.h"
 
36
#include "libde265/configparam.h"
 
37
 
 
38
 
 
39
/*  Encoder search tree, bottom up:
 
40
 
 
41
    - Algo_TB_Split - whether TB is split or not
 
42
 
 
43
    - Algo_TB_IntraPredMode - choose the intra prediction mode (or NOP, if at the wrong tree level)
 
44
 
 
45
    - Algo_CB_IntraPartMode - choose between NxN and 2Nx2N intra parts
 
46
 
 
47
    - Algo_CB_Split - whether CB is split or not
 
48
 
 
49
    - Algo_CTB_QScale - select QScale on CTB granularity
 
50
 */
 
51
 
 
52
 
 
53
// ========== TB intra prediction mode ==========
 
54
 
 
55
enum ALGO_TB_IntraPredMode {
 
56
  ALGO_TB_IntraPredMode_BruteForce,
 
57
  ALGO_TB_IntraPredMode_FastBrute,
 
58
  ALGO_TB_IntraPredMode_MinResidual
 
59
};
 
60
 
 
61
class option_ALGO_TB_IntraPredMode : public choice_option<enum ALGO_TB_IntraPredMode>
 
62
{
 
63
 public:
 
64
  option_ALGO_TB_IntraPredMode() {
 
65
    add_choice("min-residual",ALGO_TB_IntraPredMode_MinResidual);
 
66
    add_choice("brute-force" ,ALGO_TB_IntraPredMode_BruteForce);
 
67
    add_choice("fast-brute"  ,ALGO_TB_IntraPredMode_FastBrute, true);
 
68
  }
 
69
};
 
70
 
 
71
 
 
72
enum TBBitrateEstimMethod {
 
73
  //TBBitrateEstim_AccurateBits,
 
74
  TBBitrateEstim_SSD,
 
75
  TBBitrateEstim_SAD,
 
76
  TBBitrateEstim_SATD_DCT,
 
77
  TBBitrateEstim_SATD_Hadamard
 
78
};
 
79
 
 
80
class option_TBBitrateEstimMethod : public choice_option<enum TBBitrateEstimMethod>
 
81
{
 
82
 public:
 
83
  option_TBBitrateEstimMethod() {
 
84
    add_choice("ssd",TBBitrateEstim_SSD);
 
85
    add_choice("sad",TBBitrateEstim_SAD);
 
86
    add_choice("satd-dct",TBBitrateEstim_SATD_DCT);
 
87
    add_choice("satd",TBBitrateEstim_SATD_Hadamard, true);
 
88
  }
 
89
};
 
90
 
 
91
class Algo_TB_Split;
 
92
 
 
93
 
 
94
/** Base class for intra prediction-mode algorithms.
 
95
    Selects one of the 35 prediction modes.
 
96
 */
 
97
class Algo_TB_IntraPredMode
 
98
{
 
99
 public:
 
100
  Algo_TB_IntraPredMode() : mTBSplitAlgo(NULL) { }
 
101
  virtual ~Algo_TB_IntraPredMode() { }
 
102
 
 
103
  virtual enc_tb* analyze(encoder_context*,
 
104
                          context_model_table&,
 
105
                          const de265_image* input,
 
106
                          const enc_tb* parent,
 
107
                          enc_cb* cb,
 
108
                          int x0,int y0, int xBase,int yBase, int log2TbSize,
 
109
                          int blkIdx,
 
110
                          int TrafoDepth, int MaxTrafoDepth, int IntraSplitFlag) = 0;
 
111
 
 
112
  void setChildAlgo(Algo_TB_Split* algo) { mTBSplitAlgo = algo; }
 
113
 
 
114
 protected:
 
115
  Algo_TB_Split* mTBSplitAlgo;
 
116
};
 
117
 
 
118
 
 
119
enum ALGO_TB_IntraPredMode_Subset {
 
120
  ALGO_TB_IntraPredMode_Subset_All,
 
121
  ALGO_TB_IntraPredMode_Subset_HVPlus,
 
122
  ALGO_TB_IntraPredMode_Subset_DC,
 
123
  ALGO_TB_IntraPredMode_Subset_Planar
 
124
};
 
125
 
 
126
class option_ALGO_TB_IntraPredMode_Subset : public choice_option<enum ALGO_TB_IntraPredMode_Subset>
 
127
{
 
128
 public:
 
129
  option_ALGO_TB_IntraPredMode_Subset() {
 
130
    add_choice("all"   ,ALGO_TB_IntraPredMode_Subset_All, true);
 
131
    add_choice("HV+"   ,ALGO_TB_IntraPredMode_Subset_HVPlus);
 
132
    add_choice("DC"    ,ALGO_TB_IntraPredMode_Subset_DC);
 
133
    add_choice("planar",ALGO_TB_IntraPredMode_Subset_Planar);
 
134
  }
 
135
};
 
136
 
 
137
 
 
138
/** Utility class for intra prediction-mode algorithm that uses a subset of modes.
 
139
 */
 
140
class Algo_TB_IntraPredMode_ModeSubset : public Algo_TB_IntraPredMode
 
141
{
 
142
 public:
 
143
  Algo_TB_IntraPredMode_ModeSubset() {
 
144
    for (int i=0;i<35;i++) {
 
145
      mPredMode_enabled[i] = true;
 
146
    }
 
147
  }
 
148
 
 
149
  void disableAllIntraPredModes() {
 
150
    for (int i=0;i<35;i++) {
 
151
      mPredMode_enabled[i] = false;
 
152
    }
 
153
  }
 
154
 
 
155
  void enableIntraPredMode(int mode, bool flag=true) {
 
156
    mPredMode_enabled[mode] = flag;
 
157
  }
 
158
 
 
159
  void enableIntraPredModeSubset(enum ALGO_TB_IntraPredMode_Subset subset) {
 
160
    switch (subset)
 
161
      {
 
162
      case ALGO_TB_IntraPredMode_Subset_All: // activate all is the default
 
163
        for (int i=0;i<35;i++) { enableIntraPredMode(i); }
 
164
        break;
 
165
      case ALGO_TB_IntraPredMode_Subset_DC:
 
166
        disableAllIntraPredModes();
 
167
        enableIntraPredMode(INTRA_DC);
 
168
        break;
 
169
      case ALGO_TB_IntraPredMode_Subset_Planar:
 
170
        disableAllIntraPredModes();
 
171
        enableIntraPredMode(INTRA_PLANAR);
 
172
        break;
 
173
      case ALGO_TB_IntraPredMode_Subset_HVPlus:
 
174
        disableAllIntraPredModes();
 
175
        enableIntraPredMode(INTRA_DC);
 
176
        enableIntraPredMode(INTRA_PLANAR);
 
177
        enableIntraPredMode(INTRA_ANGULAR_10);
 
178
        enableIntraPredMode(INTRA_ANGULAR_26);
 
179
        break;
 
180
      }
 
181
  }
 
182
 
 
183
 protected:
 
184
  bool mPredMode_enabled[35];
 
185
};
 
186
 
 
187
 
 
188
/** Algorithm that brute-forces through all intra prediction mode.
 
189
 */
 
190
class Algo_TB_IntraPredMode_BruteForce : public Algo_TB_IntraPredMode_ModeSubset
 
191
{
 
192
 public:
 
193
 
 
194
  virtual enc_tb* analyze(encoder_context*,
 
195
                          context_model_table&,
 
196
                          const de265_image* input,
 
197
                          const enc_tb* parent,
 
198
                          enc_cb* cb,
 
199
                          int x0,int y0, int xBase,int yBase, int log2TbSize,
 
200
                          int blkIdx,
 
201
                          int TrafoDepth, int MaxTrafoDepth, int IntraSplitFlag);
 
202
};
 
203
 
 
204
 
 
205
/** Algorithm that makes a quick pre-selection of modes and then brute-forces through them.
 
206
 */
 
207
class Algo_TB_IntraPredMode_FastBrute : public Algo_TB_IntraPredMode_ModeSubset
 
208
{
 
209
 public:
 
210
 
 
211
  struct params
 
212
  {
 
213
    params() {
 
214
      keepNBest.set_ID("IntraPredMode-FastBrute-keepNBest");
 
215
      keepNBest.set_range(0,32);
 
216
      keepNBest.set_default(5);
 
217
 
 
218
      bitrateEstimMethod.set_ID("IntraPredMode-FastBrute-estimator");
 
219
    }
 
220
 
 
221
    option_TBBitrateEstimMethod bitrateEstimMethod;
 
222
    option_int keepNBest;
 
223
  };
 
224
 
 
225
  void registerParams(config_parameters& config) {
 
226
    config.add_option(&mParams.keepNBest);
 
227
    config.add_option(&mParams.bitrateEstimMethod);
 
228
  }
 
229
 
 
230
  void setParams(const params& p) { mParams=p; }
 
231
 
 
232
 
 
233
  virtual enc_tb* analyze(encoder_context*,
 
234
                          context_model_table&,
 
235
                          const de265_image* input,
 
236
                          const enc_tb* parent,
 
237
                          enc_cb* cb,
 
238
                          int x0,int y0, int xBase,int yBase, int log2TbSize,
 
239
                          int blkIdx,
 
240
                          int TrafoDepth, int MaxTrafoDepth, int IntraSplitFlag);
 
241
 
 
242
 private:
 
243
  params mParams;
 
244
};
 
245
 
 
246
 
 
247
/** Algorithm that selects the intra prediction mode on minimum residual only.
 
248
 */
 
249
class Algo_TB_IntraPredMode_MinResidual : public Algo_TB_IntraPredMode_ModeSubset
 
250
{
 
251
 public:
 
252
 
 
253
  struct params
 
254
  {
 
255
    params() {
 
256
      bitrateEstimMethod.set_ID("IntraPredMode-MinResidual-estimator");
 
257
    }
 
258
 
 
259
    option_TBBitrateEstimMethod bitrateEstimMethod;
 
260
  };
 
261
 
 
262
  void setParams(const params& p) { mParams=p; }
 
263
 
 
264
  void registerParams(config_parameters& config) {
 
265
    config.add_option(&mParams.bitrateEstimMethod);
 
266
  }
 
267
 
 
268
  virtual enc_tb* analyze(encoder_context*,
 
269
                          context_model_table&,
 
270
                          const de265_image* input,
 
271
                          const enc_tb* parent,
 
272
                          enc_cb* cb,
 
273
                          int x0,int y0, int xBase,int yBase, int log2TbSize,
 
274
                          int blkIdx,
 
275
                          int TrafoDepth, int MaxTrafoDepth, int IntraSplitFlag);
 
276
 
 
277
 private:
 
278
  params mParams;
 
279
};
 
280
 
 
281
#endif