tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

cdef.h (4515B)


      1 /*
      2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
      3 *
      4 * This source code is subject to the terms of the BSD 2 Clause License and
      5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
      6 * was not distributed with this source code in the LICENSE file, you can
      7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
      8 * Media Patent License 1.0 was not distributed with this source code in the
      9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
     10 */
     11 #ifndef AOM_AV1_COMMON_CDEF_H_
     12 #define AOM_AV1_COMMON_CDEF_H_
     13 
     14 #define CDEF_STRENGTH_BITS 6
     15 
     16 #define CDEF_PRI_STRENGTHS 16
     17 #define CDEF_SEC_STRENGTHS 4
     18 
     19 #include "config/aom_config.h"
     20 
     21 #include "aom/aom_integer.h"
     22 #include "aom_ports/mem.h"
     23 #include "av1/common/av1_common_int.h"
     24 #include "av1/common/cdef_block.h"
     25 
     26 enum { TOP, LEFT, BOTTOM, RIGHT, BOUNDARIES } UENUM1BYTE(BOUNDARY);
     27 
     28 struct AV1CdefSyncData;
     29 
     30 /*!\brief Parameters related to CDEF Block */
     31 typedef struct {
     32  uint16_t *src;                       /*!< CDEF intermediate buffer */
     33  uint16_t *top_linebuf[MAX_MB_PLANE]; /*!< CDEF top line buffer */
     34  uint16_t *bot_linebuf[MAX_MB_PLANE]; /*!< CDEF bottom line buffer */
     35  uint8_t *dst;                        /*!< CDEF destination buffer */
     36  cdef_list
     37      dlist[MI_SIZE_64X64 * MI_SIZE_64X64]; /*!< CDEF 8x8 block positions */
     38 
     39  int xdec;                       /*!< Sub-sampling X */
     40  int ydec;                       /*!< Sub-sampling X */
     41  int mi_wide_l2;                 /*!< Pixels per mi unit in width */
     42  int mi_high_l2;                 /*!< Pixels per mi unit in height */
     43  int frame_boundary[BOUNDARIES]; /*!< frame boundaries */
     44 
     45  int damping;     /*!< CDEF damping factor */
     46  int coeff_shift; /*!< Bit-depth based shift for calculating filter strength */
     47  int level;       /*!< CDEF filtering level */
     48  int sec_strength; /*!< CDEF secondary strength */
     49  int cdef_count;   /*!< Number of CDEF sub-blocks in superblock */
     50  int dir[CDEF_NBLOCKS]
     51         [CDEF_NBLOCKS]; /*!< CDEF filter direction for all 8x8 sub-blocks*/
     52  int var[CDEF_NBLOCKS][CDEF_NBLOCKS]; /*!< variance for all 8x8 sub-blocks */
     53 
     54  int dst_stride; /*!< CDEF destination buffer stride */
     55  int coffset;    /*!< current superblock offset in a row */
     56  int roffset;    /*!< current row offset */
     57 } CdefBlockInfo;
     58 
     59 static inline int sign(int i) { return i < 0 ? -1 : 1; }
     60 
     61 static inline int constrain(int diff, int threshold, int damping) {
     62  if (!threshold) return 0;
     63 
     64  int shift = damping - get_msb(threshold);
     65  shift = AOMMAX(0, shift);
     66  return sign(diff) * clamp(threshold - (abs(diff) >> shift), 0, abs(diff));
     67 }
     68 
     69 #ifdef __cplusplus
     70 extern "C" {
     71 #endif
     72 
     73 int av1_cdef_compute_sb_list(const CommonModeInfoParams *const mi_params,
     74                             int mi_row, int mi_col, cdef_list *dlist,
     75                             BLOCK_SIZE bsize);
     76 
     77 typedef void (*cdef_init_fb_row_t)(
     78    const AV1_COMMON *const cm, const MACROBLOCKD *const xd,
     79    CdefBlockInfo *const fb_info, uint16_t **const linebuf, uint16_t *const src,
     80    struct AV1CdefSyncData *const cdef_sync, int fbr);
     81 
     82 /*!\brief Function for applying CDEF to a frame
     83 *
     84 * \ingroup in_loop_cdef
     85 * This function applies CDEF to a frame.
     86 *
     87 * \param[in, out]  frame     Compressed frame buffer
     88 * \param[in, out]  cm        Pointer to top level common structure
     89 * \param[in]       xd        Pointer to common current coding block structure
     90 * \param[in]       cdef_init_fb_row_fn   Function Pointer
     91 *
     92 * \remark Nothing is returned. Instead, the filtered frame is output in
     93 * \c frame.
     94 */
     95 void av1_cdef_frame(YV12_BUFFER_CONFIG *frame, AV1_COMMON *const cm,
     96                    MACROBLOCKD *xd, cdef_init_fb_row_t cdef_init_fb_row_fn);
     97 void av1_cdef_fb_row(const AV1_COMMON *const cm, MACROBLOCKD *xd,
     98                     uint16_t **const linebuf, uint16_t **const colbuf,
     99                     uint16_t *const src, int fbr,
    100                     cdef_init_fb_row_t cdef_init_fb_row_fn,
    101                     struct AV1CdefSyncData *const cdef_sync,
    102                     struct aom_internal_error_info *error_info);
    103 void av1_cdef_init_fb_row(const AV1_COMMON *const cm,
    104                          const MACROBLOCKD *const xd,
    105                          CdefBlockInfo *const fb_info,
    106                          uint16_t **const linebuf, uint16_t *const src,
    107                          struct AV1CdefSyncData *const cdef_sync, int fbr);
    108 
    109 #ifdef __cplusplus
    110 }  // extern "C"
    111 #endif
    112 #endif  // AOM_AV1_COMMON_CDEF_H_