| OLD | NEW | 
|    1 /* |    1 /* | 
|    2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved. |    2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 
|    3  * |    3  * | 
|    4  *  Use of this source code is governed by a BSD-style license |    4  *  Use of this source code is governed by a BSD-style license | 
|    5  *  that can be found in the LICENSE file in the root of the source |    5  *  that can be found in the LICENSE file in the root of the source | 
|    6  *  tree. An additional intellectual property rights grant can be found |    6  *  tree. An additional intellectual property rights grant can be found | 
|    7  *  in the file PATENTS.  All contributing project authors may |    7  *  in the file PATENTS.  All contributing project authors may | 
|    8  *  be found in the AUTHORS file in the root of the source tree. |    8  *  be found in the AUTHORS file in the root of the source tree. | 
|    9  */ |    9  */ | 
|   10  |   10  | 
|   11 #include <math.h> |   11 #include <math.h> | 
|   12  |   12  | 
|   13 #include "vpx_mem/vpx_mem.h" |   13 #include "vpx_mem/vpx_mem.h" | 
|   14  |   14  | 
|   15 #include "vp9/common/vp9_quant_common.h" |   15 #include "vp9/common/vp9_quant_common.h" | 
|   16 #include "vp9/common/vp9_seg_common.h" |   16 #include "vp9/common/vp9_seg_common.h" | 
|   17  |   17  | 
|   18 #include "vp9/encoder/vp9_encoder.h" |   18 #include "vp9/encoder/vp9_encoder.h" | 
|   19 #include "vp9/encoder/vp9_quantize.h" |   19 #include "vp9/encoder/vp9_quantize.h" | 
|   20 #include "vp9/encoder/vp9_rd.h" |   20 #include "vp9/encoder/vp9_rd.h" | 
|   21  |   21  | 
|   22 void vp9_quantize_dc(const tran_low_t *coeff_ptr, int skip_block, |   22 void vp9_quantize_dc(const tran_low_t *coeff_ptr, | 
 |   23                      int n_coeffs, int skip_block, | 
|   23                      const int16_t *round_ptr, const int16_t quant, |   24                      const int16_t *round_ptr, const int16_t quant, | 
|   24                      tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, |   25                      tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, | 
|   25                      const int16_t dequant_ptr, uint16_t *eob_ptr) { |   26                      const int16_t dequant_ptr, uint16_t *eob_ptr) { | 
|   26   const int rc = 0; |   27   const int rc = 0; | 
|   27   const int coeff = coeff_ptr[rc]; |   28   const int coeff = coeff_ptr[rc]; | 
|   28   const int coeff_sign = (coeff >> 31); |   29   const int coeff_sign = (coeff >> 31); | 
|   29   const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |   30   const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; | 
|   30   int tmp, eob = -1; |   31   int tmp, eob = -1; | 
|   31  |   32  | 
 |   33   vpx_memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); | 
 |   34   vpx_memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); | 
 |   35  | 
|   32   if (!skip_block) { |   36   if (!skip_block) { | 
|   33     tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX); |   37     tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX); | 
|   34     tmp = (tmp * quant) >> 16; |   38     tmp = (tmp * quant) >> 16; | 
|   35     qcoeff_ptr[rc]  = (tmp ^ coeff_sign) - coeff_sign; |   39     qcoeff_ptr[rc]  = (tmp ^ coeff_sign) - coeff_sign; | 
|   36     dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr; |   40     dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr; | 
|   37     if (tmp) |   41     if (tmp) | 
|   38       eob = 0; |   42       eob = 0; | 
|   39   } |   43   } | 
|   40   *eob_ptr = eob + 1; |   44   *eob_ptr = eob + 1; | 
|   41 } |   45 } | 
|   42  |   46  | 
|   43 #if CONFIG_VP9_HIGHBITDEPTH |   47 #if CONFIG_VP9_HIGHBITDEPTH | 
|   44 void vp9_highbd_quantize_dc(const tran_low_t *coeff_ptr, int skip_block, |   48 void vp9_highbd_quantize_dc(const tran_low_t *coeff_ptr, | 
 |   49                             int n_coeffs, int skip_block, | 
|   45                             const int16_t *round_ptr, const int16_t quant, |   50                             const int16_t *round_ptr, const int16_t quant, | 
|   46                             tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, |   51                             tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, | 
|   47                             const int16_t dequant_ptr, uint16_t *eob_ptr) { |   52                             const int16_t dequant_ptr, uint16_t *eob_ptr) { | 
|   48   int eob = -1; |   53   int eob = -1; | 
|   49  |   54  | 
 |   55   vpx_memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); | 
 |   56   vpx_memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); | 
 |   57  | 
|   50   if (!skip_block) { |   58   if (!skip_block) { | 
|   51     const int rc = 0; |   59     const int rc = 0; | 
|   52     const int coeff = coeff_ptr[rc]; |   60     const int coeff = coeff_ptr[rc]; | 
|   53     const int coeff_sign = (coeff >> 31); |   61     const int coeff_sign = (coeff >> 31); | 
|   54     const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |   62     const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; | 
|   55  |   63  | 
|   56     const int64_t tmp = |   64     const int64_t tmp = | 
|   57         (clamp(abs_coeff + round_ptr[rc != 0], INT32_MIN, INT32_MAX) * |   65         (clamp(abs_coeff + round_ptr[rc != 0], INT32_MIN, INT32_MAX) * | 
|   58          quant) >> 16; |   66          quant) >> 16; | 
|   59     qcoeff_ptr[rc] = (tran_low_t)((tmp ^ coeff_sign) - coeff_sign); |   67     qcoeff_ptr[rc] = (tran_low_t)((tmp ^ coeff_sign) - coeff_sign); | 
|   60     dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr; |   68     dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr; | 
|   61     if (tmp) |   69     if (tmp) | 
|   62       eob = 0; |   70       eob = 0; | 
|   63   } |   71   } | 
|   64   *eob_ptr = eob + 1; |   72   *eob_ptr = eob + 1; | 
|   65 } |   73 } | 
|   66 #endif |   74 #endif | 
|   67  |   75  | 
|   68 void vp9_quantize_dc_32x32(const tran_low_t *coeff_ptr, int skip_block, |   76 void vp9_quantize_dc_32x32(const tran_low_t *coeff_ptr, int skip_block, | 
|   69                            const int16_t *round_ptr, const int16_t quant, |   77                            const int16_t *round_ptr, const int16_t quant, | 
|   70                            tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, |   78                            tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, | 
|   71                            const int16_t dequant_ptr, uint16_t *eob_ptr) { |   79                            const int16_t dequant_ptr, uint16_t *eob_ptr) { | 
 |   80   const int n_coeffs = 1024; | 
|   72   const int rc = 0; |   81   const int rc = 0; | 
|   73   const int coeff = coeff_ptr[rc]; |   82   const int coeff = coeff_ptr[rc]; | 
|   74   const int coeff_sign = (coeff >> 31); |   83   const int coeff_sign = (coeff >> 31); | 
|   75   const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |   84   const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; | 
|   76   int tmp, eob = -1; |   85   int tmp, eob = -1; | 
|   77  |   86  | 
 |   87   vpx_memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); | 
 |   88   vpx_memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); | 
 |   89  | 
|   78   if (!skip_block) { |   90   if (!skip_block) { | 
|   79  |   91  | 
|   80     tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX); |   92     tmp = clamp(abs_coeff + ROUND_POWER_OF_TWO(round_ptr[rc != 0], 1), | 
 |   93                 INT16_MIN, INT16_MAX); | 
|   81     tmp = (tmp * quant) >> 15; |   94     tmp = (tmp * quant) >> 15; | 
|   82     qcoeff_ptr[rc]  = (tmp ^ coeff_sign) - coeff_sign; |   95     qcoeff_ptr[rc]  = (tmp ^ coeff_sign) - coeff_sign; | 
|   83     dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr / 2; |   96     dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr / 2; | 
|   84     if (tmp) |   97     if (tmp) | 
|   85       eob = 0; |   98       eob = 0; | 
|   86   } |   99   } | 
|   87   *eob_ptr = eob + 1; |  100   *eob_ptr = eob + 1; | 
|   88 } |  101 } | 
|   89  |  102  | 
|   90 #if CONFIG_VP9_HIGHBITDEPTH |  103 #if CONFIG_VP9_HIGHBITDEPTH | 
|   91 void vp9_highbd_quantize_dc_32x32(const tran_low_t *coeff_ptr, |  104 void vp9_highbd_quantize_dc_32x32(const tran_low_t *coeff_ptr, | 
|   92                                   int skip_block, |  105                                   int skip_block, | 
|   93                                   const int16_t *round_ptr, |  106                                   const int16_t *round_ptr, | 
|   94                                   const int16_t quant, |  107                                   const int16_t quant, | 
|   95                                   tran_low_t *qcoeff_ptr, |  108                                   tran_low_t *qcoeff_ptr, | 
|   96                                   tran_low_t *dqcoeff_ptr, |  109                                   tran_low_t *dqcoeff_ptr, | 
|   97                                   const int16_t dequant_ptr, |  110                                   const int16_t dequant_ptr, | 
|   98                                   uint16_t *eob_ptr) { |  111                                   uint16_t *eob_ptr) { | 
 |  112   const int n_coeffs = 1024; | 
|   99   int eob = -1; |  113   int eob = -1; | 
|  100  |  114  | 
 |  115   vpx_memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); | 
 |  116   vpx_memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); | 
 |  117  | 
|  101   if (!skip_block) { |  118   if (!skip_block) { | 
|  102     const int rc = 0; |  119     const int rc = 0; | 
|  103     const int coeff = coeff_ptr[rc]; |  120     const int coeff = coeff_ptr[rc]; | 
|  104     const int coeff_sign = (coeff >> 31); |  121     const int coeff_sign = (coeff >> 31); | 
|  105     const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; |  122     const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; | 
|  106  |  123  | 
|  107     const int64_t tmp = |  124     const int64_t tmp = | 
|  108         (clamp(abs_coeff + round_ptr[rc != 0], INT32_MIN, INT32_MAX) * |  125         (clamp(abs_coeff + ROUND_POWER_OF_TWO(round_ptr[rc != 0], 1), | 
|  109          quant) >> 15; |  126                INT32_MIN, INT32_MAX) * quant) >> 15; | 
|  110     qcoeff_ptr[rc] = (tran_low_t)((tmp ^ coeff_sign) - coeff_sign); |  127     qcoeff_ptr[rc] = (tran_low_t)((tmp ^ coeff_sign) - coeff_sign); | 
|  111     dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr / 2; |  128     dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr / 2; | 
|  112     if (tmp) |  129     if (tmp) | 
|  113       eob = 0; |  130       eob = 0; | 
|  114   } |  131   } | 
|  115   *eob_ptr = eob + 1; |  132   *eob_ptr = eob + 1; | 
|  116 } |  133 } | 
|  117 #endif |  134 #endif | 
|  118  |  135  | 
|  119 void vp9_quantize_fp_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, |  136 void vp9_quantize_fp_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs, | 
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  514  |  531  | 
|  515 void vp9_regular_quantize_b_4x4(MACROBLOCK *x, int plane, int block, |  532 void vp9_regular_quantize_b_4x4(MACROBLOCK *x, int plane, int block, | 
|  516                                 const int16_t *scan, const int16_t *iscan) { |  533                                 const int16_t *scan, const int16_t *iscan) { | 
|  517   MACROBLOCKD *const xd = &x->e_mbd; |  534   MACROBLOCKD *const xd = &x->e_mbd; | 
|  518   struct macroblock_plane *p = &x->plane[plane]; |  535   struct macroblock_plane *p = &x->plane[plane]; | 
|  519   struct macroblockd_plane *pd = &xd->plane[plane]; |  536   struct macroblockd_plane *pd = &xd->plane[plane]; | 
|  520  |  537  | 
|  521 #if CONFIG_VP9_HIGHBITDEPTH |  538 #if CONFIG_VP9_HIGHBITDEPTH | 
|  522   if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |  539   if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { | 
|  523     vp9_highbd_quantize_b(BLOCK_OFFSET(p->coeff, block), |  540     vp9_highbd_quantize_b(BLOCK_OFFSET(p->coeff, block), | 
|  524                         16, x->skip_block, |  541                           16, x->skip_block, | 
|  525                         p->zbin, p->round, p->quant, p->quant_shift, |  542                           p->zbin, p->round, p->quant, p->quant_shift, | 
|  526                         BLOCK_OFFSET(p->qcoeff, block), |  543                           BLOCK_OFFSET(p->qcoeff, block), | 
|  527                         BLOCK_OFFSET(pd->dqcoeff, block), |  544                           BLOCK_OFFSET(pd->dqcoeff, block), | 
|  528                         pd->dequant, &p->eobs[block], |  545                           pd->dequant, &p->eobs[block], | 
|  529                         scan, iscan); |  546                           scan, iscan); | 
|  530     return; |  547     return; | 
|  531   } |  548   } | 
|  532 #endif |  549 #endif | 
|  533   vp9_quantize_b(BLOCK_OFFSET(p->coeff, block), |  550   vp9_quantize_b(BLOCK_OFFSET(p->coeff, block), | 
|  534            16, x->skip_block, |  551                  16, x->skip_block, | 
|  535            p->zbin, p->round, p->quant, p->quant_shift, |  552                  p->zbin, p->round, p->quant, p->quant_shift, | 
|  536            BLOCK_OFFSET(p->qcoeff, block), |  553                  BLOCK_OFFSET(p->qcoeff, block), | 
|  537            BLOCK_OFFSET(pd->dqcoeff, block), |  554                  BLOCK_OFFSET(pd->dqcoeff, block), | 
|  538            pd->dequant, &p->eobs[block], scan, iscan); |  555                  pd->dequant, &p->eobs[block], scan, iscan); | 
|  539 } |  556 } | 
|  540  |  557  | 
|  541 static void invert_quant(int16_t *quant, int16_t *shift, int d) { |  558 static void invert_quant(int16_t *quant, int16_t *shift, int d) { | 
|  542   unsigned t; |  559   unsigned t; | 
|  543   int l; |  560   int l; | 
|  544   t = d; |  561   t = d; | 
|  545   for (l = 0; t > 1; l++) |  562   for (l = 0; t > 1; l++) | 
|  546     t >>= 1; |  563     t >>= 1; | 
|  547   t = 1 + (1 << (16 + l)) / d; |  564   t = 1 + (1 << (16 + l)) / d; | 
|  548   *quant = (int16_t)(t - (1 << 16)); |  565   *quant = (int16_t)(t - (1 << 16)); | 
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  701  |  718  | 
|  702 int vp9_qindex_to_quantizer(int qindex) { |  719 int vp9_qindex_to_quantizer(int qindex) { | 
|  703   int quantizer; |  720   int quantizer; | 
|  704  |  721  | 
|  705   for (quantizer = 0; quantizer < 64; ++quantizer) |  722   for (quantizer = 0; quantizer < 64; ++quantizer) | 
|  706     if (quantizer_to_qindex[quantizer] >= qindex) |  723     if (quantizer_to_qindex[quantizer] >= qindex) | 
|  707       return quantizer; |  724       return quantizer; | 
|  708  |  725  | 
|  709   return 63; |  726   return 63; | 
|  710 } |  727 } | 
| OLD | NEW |