summaryrefslogtreecommitdiffstats
path: root/encoder/ih264e_intra_modes_eval.h
blob: c8402e5c04a3aa1027deb0f1e2104cb3e6ff9e1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
/******************************************************************************
 *
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *****************************************************************************
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
*/

/**
*******************************************************************************
* @file
*  ih264e_intra_modes_eval.h
*
* @brief
*  This file contains declarations of routines that perform rate distortion
*  analysis on a macroblock if coded as intra.
*
* @author
*  ittiam
*
* @remarks
*  none
*
*******************************************************************************
*/

#ifndef IH264E_INTRA_MODES_EVAL_H_
#define IH264E_INTRA_MODES_EVAL_H_

/*****************************************************************************/
/* Extern Function Declarations                                              */
/*****************************************************************************/

/**
******************************************************************************
*
* @brief
*  derivation process for macroblock availability
*
* @par   Description
*  Calculates the availability of the left, top, topright and topleft macroblocks.
*
* @param[in] ps_proc_ctxt
*  pointer to proc context (handle)
*
* @remarks Based on section 6.4.5 in H264 spec
*
* @return  none
*
******************************************************************************
*/
void ih264e_derive_nghbr_avbl_of_mbs
        (
            process_ctxt_t *ps_proc_ctxt
        );

/**
******************************************************************************
*
* @brief
*  derivation process for subblock/partition availability
*
* @par   Description
*  Calculates the availability of the left, top, topright and topleft subblock
*  or partitions.
*
* @param[in]    ps_proc_ctxt
*  pointer to macroblock context (handle)
*
* @param[in]    i1_pel_pos_x
*  column position of the pel wrt the current block
*
* @param[in]    i1_pel_pos_y
*  row position of the pel in wrt current block
*
* @remarks     Assumptions: before calling this function it is assumed that
*   the neighbor availability of the current macroblock is already derived.
*   Based on table 6-3 of H264 specification
*
* @return      availability status (yes or no)
*
******************************************************************************
*/
UWORD8 ih264e_derive_ngbr_avbl_of_mb_partitions
        (
            block_neighbors_t *s_ngbr_avbl,
            WORD8 i1_pel_pos_x,
            WORD8 i1_pel_pos_y
        );

/**
******************************************************************************
*
* @brief
*  evaluate best intra 16x16 mode (rate distortion opt off)
*
* @par Description
*  This function evaluates all the possible intra 16x16 modes and finds the mode
*  that best represents the macro-block (least distortion) and occupies fewer
*  bits in the bit-stream.
*
* @param[in]   ps_proc_ctxt
*  pointer to process context (handle)
*
* @remarks
*  Ideally the cost of encoding a macroblock is calculated as
*  (distortion + lambda*rate). Where distortion is SAD/SATD,... between the
*  input block and the reconstructed block and rate is the number of bits taken
*  to place the macroblock in the bit-stream. In this routine the rate does not
*  exactly point to the total number of bits it takes, rather it points to header
*  bits necessary for encoding the macroblock. Assuming the deltaQP, cbp bits
*  and residual bits fall in to texture bits the number of bits taken to encoding
*  mbtype is considered as rate, we compute cost. Further we will approximate
*  the distortion as the deviation b/w input and the predicted block as opposed
*  to input and reconstructed block.
*
*  NOTE: As per the Document JVT-O079, for intra 16x16 macroblock,
*  the SAD and cost are one and the same.
*
* @return     none
*
******************************************************************************
*/
void ih264e_evaluate_intra16x16_modes_for_least_cost_rdoptoff
        (
            process_ctxt_t *ps_proc_ctxt
        );

/**
******************************************************************************
*
* @brief
*  evaluate best intra 8x8 mode (rate distortion opt on)
*
* @par Description
*  This function evaluates all the possible intra 8x8 modes and finds the mode
*  that best represents the macro-block (least distortion) and occupies fewer
*  bits in the bit-stream.
*
* @param[in]    ps_proc_ctxt
*  pointer to proc ctxt
*
* @remarks Ideally the cost of encoding a macroblock is calculated as
*  (distortion + lambda*rate). Where distortion is SAD/SATD,... between the
*  input block and the reconstructed block and rate is the number of bits taken
*  to place the macroblock in the bit-stream. In this routine the rate does not
*  exactly point to the total number of bits it takes, rather it points to header
*  bits necessary for encoding the macroblock. Assuming the deltaQP, cbp bits
*  and residual bits fall in to texture bits the number of bits taken to encoding
*  mbtype is considered as rate, we compute cost. Further we will approximate
*  the distortion as the deviation b/w input and the predicted block as opposed
*  to input and reconstructed block.
*
*  NOTE: TODO: This function needs to be tested
*
*  @return      none
*
******************************************************************************
*/
void ih264e_evaluate_intra8x8_modes_for_least_cost_rdoptoff
        (
            process_ctxt_t *ps_proc_ctxt
        );

/**
******************************************************************************
*
* @brief
*  evaluate best intra 4x4 mode (rate distortion opt on)
*
* @par Description
*  This function evaluates all the possible intra 4x4 modes and finds the mode
*  that best represents the macro-block (least distortion) and occupies fewer
*  bits in the bit-stream.
*
* @param[in]    ps_proc_ctxt
*  pointer to proc ctxt
*
* @remarks
*  Ideally the cost of encoding a macroblock is calculated as
*  (distortion + lambda*rate). Where distortion is SAD/SATD,... between the
*  input block and the reconstructed block and rate is the number of bits taken
*  to place the macroblock in the bit-stream. In this routine the rate does not
*  exactly point to the total number of bits it takes, rather it points to header
*  bits necessary for encoding the macroblock. Assuming the deltaQP, cbp bits
*  and residual bits fall in to texture bits the number of bits taken to encoding
*  mbtype is considered as rate, we compute cost. Further we will approximate
*  the distortion as the deviation b/w input and the predicted block as opposed
*  to input and reconstructed block.
*
*  NOTE: As per the Document JVT-O079, for the whole intra 4x4 macroblock,
*  24*lambda is added to the SAD before comparison with the best SAD for
*  inter prediction. This is an empirical value to prevent using too many intra
*  blocks.
*
* @return      none
*
******************************************************************************
*/
void ih264e_evaluate_intra4x4_modes_for_least_cost_rdopton
        (
            process_ctxt_t *ps_proc_ctxt
        );

/**
******************************************************************************
*
* @brief
*  evaluate best intra 4x4 mode (rate distortion opt off)
*
* @par Description
*  This function evaluates all the possible intra 4x4 modes and finds the mode
*  that best represents the macro-block (least distortion) and occupies fewer
*  bits in the bit-stream.
*
* @param[in]    ps_proc_ctxt
*  pointer to proc ctxt
*
* @remarks
*  Ideally the cost of encoding a macroblock is calculated as
*  (distortion + lambda*rate). Where distortion is SAD/SATD,... between the
*  input block and the reconstructed block and rate is the number of bits taken
*  to place the macroblock in the bit-stream. In this routine the rate does not
*  exactly point to the total number of bits it takes, rather it points to header
*  bits necessary for encoding the macroblock. Assuming the deltaQP, cbp bits
*  and residual bits fall in to texture bits the number of bits taken to encoding
*  mbtype is considered as rate, we compute cost. Further we will approximate
*  the distortion as the deviation b/w input and the predicted block as opposed
*  to input and reconstructed block.
*
*  NOTE: As per the Document JVT-O079, for the whole intra 4x4 macroblock,
*  24*lambda is added to the SAD before comparison with the best SAD for
*  inter prediction. This is an empirical value to prevent using too many intra
*  blocks.
*
* @return      none
*
******************************************************************************
*/
void ih264e_evaluate_intra4x4_modes_for_least_cost_rdoptoff
        (
            process_ctxt_t *ps_proc_ctxt
        );

/**
******************************************************************************
*
* @brief
*  evaluate best chroma intra 8x8 mode (rate distortion opt off)
*
* @par Description
*  This function evaluates all the possible chroma intra 8x8 modes and finds
*  the mode that best represents the macroblock (least distortion) and occupies
*  fewer bits in the bitstream.
*
* @param[in] ps_proc_ctxt
*  pointer to macroblock context (handle)
*
* @remarks
*  For chroma best intra pred mode is calculated based only on SAD
*
* @returns none
*
******************************************************************************
*/
void ih264e_evaluate_chroma_intra8x8_modes_for_least_cost_rdoptoff
        (
            process_ctxt_t *ps_proc_ctxt
        );


/**
******************************************************************************
*
* @brief
*  Evaluate best intra 16x16 mode (among VERT, HORZ and DC) and do the
*  prediction.
*
* @par Description
*  This function evaluates first three 16x16 modes and compute corresponding sad
*  and return the buffer predicted with best mode.
*
* @param[in] pu1_src
*  UWORD8 pointer to the source
*
* @param[in] pu1_ngbr_pels_i16
*  UWORD8 pointer to neighbouring pels
*
* @param[out] pu1_dst
*  UWORD8 pointer to the destination
*
* @param[in] src_strd
*  integer source stride
*
* @param[in] dst_strd
*  integer destination stride
*
* @param[in] u4_n_avblty
*  availability of neighbouring pixels
*
* @param[in] u4_intra_mode
*  Pointer to the variable in which best mode is returned
*
* @param[in] pu4_sadmin
*  Pointer to the variable in which minimum sad is returned
*
* @param[in] u4_valid_intra_modes
*  Says what all modes are valid
*
* @returns      none
*
******************************************************************************
*/
typedef void ih264e_evaluate_intra_modes_ft(UWORD8 *pu1_src,
                                            UWORD8 *pu1_ngbr_pels_i16,
                                            UWORD8 *pu1_dst,
                                            UWORD32 src_strd,
                                            UWORD32 dst_strd,
                                            WORD32 u4_n_avblty,
                                            UWORD32 *u4_intra_mode,
                                            WORD32 *pu4_sadmin,
                                            UWORD32 u4_valid_intra_modes);

ih264e_evaluate_intra_modes_ft ih264e_evaluate_intra16x16_modes;
ih264e_evaluate_intra_modes_ft ih264e_evaluate_intra_chroma_modes;

/* assembly */
ih264e_evaluate_intra_modes_ft ih264e_evaluate_intra16x16_modes_a9q;
ih264e_evaluate_intra_modes_ft ih264e_evaluate_intra_chroma_modes_a9q;

ih264e_evaluate_intra_modes_ft ih264e_evaluate_intra16x16_modes_av8;
ih264e_evaluate_intra_modes_ft ih264e_evaluate_intra_chroma_modes_av8;

/* x86 intrinsics */
ih264e_evaluate_intra_modes_ft ih264e_evaluate_intra16x16_modes_ssse3;
ih264e_evaluate_intra_modes_ft ih264e_evaluate_intra_chroma_modes_ssse3;

/**
******************************************************************************
*
* @brief
*  Evaluate best intra 4x4 mode and perform prediction.
*
* @par Description
*  This function evaluates  4x4 modes and compute corresponding sad
*  and return the buffer predicted with best mode.
*
* @param[in] pu1_src
*  UWORD8 pointer to the source
*
* @param[in] pu1_ngbr_pels
*  UWORD8 pointer to neighbouring pels
*
* @param[out] pu1_dst
*  UWORD8 pointer to the destination
*
* @param[in] src_strd
*  integer source stride
*
* @param[in] dst_strd
*  integer destination stride
*
* @param[in] u4_n_avblty
*  availability of neighbouring pixels
*
* @param[in] u4_intra_mode
*  Pointer to the variable in which best mode is returned
*
* @param[in] pu4_sadmin
*  Pointer to the variable in which minimum cost is returned
*
* @param[in] u4_valid_intra_modes
*  Says what all modes are valid
*
* @param[in] u4_lambda
*  Lamda value for computing cost from SAD
*
* @param[in] u4_predictd_mode
*  Predicted mode for cost computation
*
* @returns      none
*
******************************************************************************
*/
typedef void ih264e_evaluate_intra_4x4_modes_ft(UWORD8 *pu1_src,
                                                UWORD8 *pu1_ngbr_pels,
                                                UWORD8 *pu1_dst,
                                                UWORD32 src_strd,
                                                UWORD32 dst_strd,
                                                WORD32 u4_n_avblty,
                                                UWORD32 *u4_intra_mode,
                                                WORD32 *pu4_sadmin,
                                                UWORD32 u4_valid_intra_modes,
                                                UWORD32  u4_lambda,
                                                UWORD32 u4_predictd_mode);

ih264e_evaluate_intra_4x4_modes_ft ih264e_evaluate_intra_4x4_modes;

/* x86 intrinsics */
ih264e_evaluate_intra_4x4_modes_ft ih264e_evaluate_intra_4x4_modes_ssse3;

/* assembly */
ih264e_evaluate_intra_4x4_modes_ft ih264e_evaluate_intra_4x4_modes_a9q;
ih264e_evaluate_intra_4x4_modes_ft ih264e_evaluate_intra_4x4_modes_av8;

#endif /* IH264E_INTRA_MODES_EVAL_H_ */