3
* Copyright (c) 2013-2014 struktur AG, Dirk Farin <farin@struktur.de>
5
* Authors: Dirk Farin <farin@struktur.de>
7
* This file is part of libde265.
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.
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.
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/>.
23
#ifndef TB_INTRAPREDMODE_H
24
#define TB_INTRAPREDMODE_H
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"
39
/* Encoder search tree, bottom up:
41
- Algo_TB_Split - whether TB is split or not
43
- Algo_TB_IntraPredMode - choose the intra prediction mode (or NOP, if at the wrong tree level)
45
- Algo_CB_IntraPartMode - choose between NxN and 2Nx2N intra parts
47
- Algo_CB_Split - whether CB is split or not
49
- Algo_CTB_QScale - select QScale on CTB granularity
53
// ========== TB intra prediction mode ==========
55
enum ALGO_TB_IntraPredMode {
56
ALGO_TB_IntraPredMode_BruteForce,
57
ALGO_TB_IntraPredMode_FastBrute,
58
ALGO_TB_IntraPredMode_MinResidual
61
class option_ALGO_TB_IntraPredMode : public choice_option<enum ALGO_TB_IntraPredMode>
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);
72
enum TBBitrateEstimMethod {
73
//TBBitrateEstim_AccurateBits,
76
TBBitrateEstim_SATD_DCT,
77
TBBitrateEstim_SATD_Hadamard
80
class option_TBBitrateEstimMethod : public choice_option<enum TBBitrateEstimMethod>
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);
94
/** Base class for intra prediction-mode algorithms.
95
Selects one of the 35 prediction modes.
97
class Algo_TB_IntraPredMode
100
Algo_TB_IntraPredMode() : mTBSplitAlgo(NULL) { }
101
virtual ~Algo_TB_IntraPredMode() { }
103
virtual enc_tb* analyze(encoder_context*,
104
context_model_table&,
105
const de265_image* input,
106
const enc_tb* parent,
108
int x0,int y0, int xBase,int yBase, int log2TbSize,
110
int TrafoDepth, int MaxTrafoDepth, int IntraSplitFlag) = 0;
112
void setChildAlgo(Algo_TB_Split* algo) { mTBSplitAlgo = algo; }
115
Algo_TB_Split* mTBSplitAlgo;
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
126
class option_ALGO_TB_IntraPredMode_Subset : public choice_option<enum ALGO_TB_IntraPredMode_Subset>
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);
138
/** Utility class for intra prediction-mode algorithm that uses a subset of modes.
140
class Algo_TB_IntraPredMode_ModeSubset : public Algo_TB_IntraPredMode
143
Algo_TB_IntraPredMode_ModeSubset() {
144
for (int i=0;i<35;i++) {
145
mPredMode_enabled[i] = true;
149
void disableAllIntraPredModes() {
150
for (int i=0;i<35;i++) {
151
mPredMode_enabled[i] = false;
155
void enableIntraPredMode(int mode, bool flag=true) {
156
mPredMode_enabled[mode] = flag;
159
void enableIntraPredModeSubset(enum ALGO_TB_IntraPredMode_Subset subset) {
162
case ALGO_TB_IntraPredMode_Subset_All: // activate all is the default
163
for (int i=0;i<35;i++) { enableIntraPredMode(i); }
165
case ALGO_TB_IntraPredMode_Subset_DC:
166
disableAllIntraPredModes();
167
enableIntraPredMode(INTRA_DC);
169
case ALGO_TB_IntraPredMode_Subset_Planar:
170
disableAllIntraPredModes();
171
enableIntraPredMode(INTRA_PLANAR);
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);
184
bool mPredMode_enabled[35];
188
/** Algorithm that brute-forces through all intra prediction mode.
190
class Algo_TB_IntraPredMode_BruteForce : public Algo_TB_IntraPredMode_ModeSubset
194
virtual enc_tb* analyze(encoder_context*,
195
context_model_table&,
196
const de265_image* input,
197
const enc_tb* parent,
199
int x0,int y0, int xBase,int yBase, int log2TbSize,
201
int TrafoDepth, int MaxTrafoDepth, int IntraSplitFlag);
205
/** Algorithm that makes a quick pre-selection of modes and then brute-forces through them.
207
class Algo_TB_IntraPredMode_FastBrute : public Algo_TB_IntraPredMode_ModeSubset
214
keepNBest.set_ID("IntraPredMode-FastBrute-keepNBest");
215
keepNBest.set_range(0,32);
216
keepNBest.set_default(5);
218
bitrateEstimMethod.set_ID("IntraPredMode-FastBrute-estimator");
221
option_TBBitrateEstimMethod bitrateEstimMethod;
222
option_int keepNBest;
225
void registerParams(config_parameters& config) {
226
config.add_option(&mParams.keepNBest);
227
config.add_option(&mParams.bitrateEstimMethod);
230
void setParams(const params& p) { mParams=p; }
233
virtual enc_tb* analyze(encoder_context*,
234
context_model_table&,
235
const de265_image* input,
236
const enc_tb* parent,
238
int x0,int y0, int xBase,int yBase, int log2TbSize,
240
int TrafoDepth, int MaxTrafoDepth, int IntraSplitFlag);
247
/** Algorithm that selects the intra prediction mode on minimum residual only.
249
class Algo_TB_IntraPredMode_MinResidual : public Algo_TB_IntraPredMode_ModeSubset
256
bitrateEstimMethod.set_ID("IntraPredMode-MinResidual-estimator");
259
option_TBBitrateEstimMethod bitrateEstimMethod;
262
void setParams(const params& p) { mParams=p; }
264
void registerParams(config_parameters& config) {
265
config.add_option(&mParams.bitrateEstimMethod);
268
virtual enc_tb* analyze(encoder_context*,
269
context_model_table&,
270
const de265_image* input,
271
const enc_tb* parent,
273
int x0,int y0, int xBase,int yBase, int log2TbSize,
275
int TrafoDepth, int MaxTrafoDepth, int IntraSplitFlag);