[FFmpeg-cvslog] Merge commit 'fd92dafaff8844b5fedf94679b93d953939a7f7b'

James Almer git at videolan.org
Tue Nov 7 23:50:17 EET 2017


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Tue Nov  7 18:44:44 2017 -0300| [17fa37cf413ad4a109caf5147c36953e60ab2b3a] | committer: James Almer

Merge commit 'fd92dafaff8844b5fedf94679b93d953939a7f7b'

* commit 'fd92dafaff8844b5fedf94679b93d953939a7f7b':
  bink: Split read_dct_coeffs()

Merged-by: James Almer <jamrial at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=17fa37cf413ad4a109caf5147c36953e60ab2b3a
---

 libavcodec/bink.c | 43 +++++++++++++++++++++++++++++--------------
 1 file changed, 29 insertions(+), 14 deletions(-)

diff --git a/libavcodec/bink.c b/libavcodec/bink.c
index 346b6cda9d..c4cf617a8b 100644
--- a/libavcodec/bink.c
+++ b/libavcodec/bink.c
@@ -601,17 +601,16 @@ static inline int binkb_get_value(BinkContext *c, int bundle_num)
  * @param quant_matrices quantization matrices
  * @return 0 for success, negative value in other cases
  */
-static int read_dct_coeffs(GetBitContext *gb, int32_t block[64], const uint8_t *scan,
-                           const int32_t quant_matrices[16][64], int q)
+static int read_dct_coeffs(GetBitContext *gb, int32_t block[64],
+                           const uint8_t *scan, int *coef_count_,
+                           int coef_idx[64], int q)
 {
     int coef_list[128];
     int mode_list[128];
     int i, t, bits, ccoef, mode, sign;
     int list_start = 64, list_end = 64, list_pos;
     int coef_count = 0;
-    int coef_idx[64];
     int quant_idx;
-    const int32_t *quant;
 
     coef_list[list_end] = 4;  mode_list[list_end++] = 0;
     coef_list[list_end] = 24; mode_list[list_end++] = 0;
@@ -690,15 +689,21 @@ static int read_dct_coeffs(GetBitContext *gb, int32_t block[64], const uint8_t *
         }
     }
 
-    quant = quant_matrices[quant_idx];
+    *coef_count_ = coef_count;
 
+    return quant_idx;
+}
+
+static void unquantize_dct_coeffs(int32_t block[64], const int32_t quant[64],
+                                  int coef_count, int coef_idx[64],
+                                  const uint8_t *scan)
+{
+    int i;
     block[0] = (block[0] * quant[0]) >> 11;
     for (i = 0; i < coef_count; i++) {
         int idx = coef_idx[i];
         block[scan[idx]] = (block[scan[idx]] * quant[idx]) >> 11;
     }
-
-    return 0;
 }
 
 /**
@@ -817,7 +822,7 @@ static int binkb_decode_plane(BinkContext *c, AVFrame *frame, GetBitContext *gb,
     LOCAL_ALIGNED_16(int32_t, dctblock, [64]);
     int coordmap[64];
     int ybias = is_key ? -15 : 0;
-    int qp;
+    int qp, quant_idx, coef_count, coef_idx[64];
 
     const int stride = frame->linesize[plane_idx];
     int bw = is_chroma ? (c->avctx->width  + 15) >> 4 : (c->avctx->width  + 7) >> 3;
@@ -872,7 +877,9 @@ static int binkb_decode_plane(BinkContext *c, AVFrame *frame, GetBitContext *gb,
                 memset(dctblock, 0, sizeof(*dctblock) * 64);
                 dctblock[0] = binkb_get_value(c, BINKB_SRC_INTRA_DC);
                 qp = binkb_get_value(c, BINKB_SRC_INTRA_Q);
-                read_dct_coeffs(gb, dctblock, bink_scan, (const int32_t (*)[64])binkb_intra_quant, qp);
+                if ((quant_idx = read_dct_coeffs(gb, dctblock, bink_scan, &coef_count, coef_idx, qp)) < 0)
+                    return quant_idx;
+                unquantize_dct_coeffs(dctblock, binkb_intra_quant[quant_idx], coef_count, coef_idx, bink_scan);
                 c->binkdsp.idct_put(dst, stride, dctblock);
                 break;
             case 3:
@@ -905,7 +912,9 @@ static int binkb_decode_plane(BinkContext *c, AVFrame *frame, GetBitContext *gb,
                 memset(dctblock, 0, sizeof(*dctblock) * 64);
                 dctblock[0] = binkb_get_value(c, BINKB_SRC_INTER_DC);
                 qp = binkb_get_value(c, BINKB_SRC_INTER_Q);
-                read_dct_coeffs(gb, dctblock, bink_scan, (const int32_t (*)[64])binkb_inter_quant, qp);
+                if ((quant_idx = read_dct_coeffs(gb, dctblock, bink_scan, &coef_count, coef_idx, qp)) < 0)
+                    return quant_idx;
+                unquantize_dct_coeffs(dctblock, binkb_inter_quant[quant_idx], coef_count, coef_idx, bink_scan);
                 c->binkdsp.idct_add(dst, stride, dctblock);
                 break;
             case 5:
@@ -979,7 +988,7 @@ static int bink_decode_plane(BinkContext *c, AVFrame *frame, GetBitContext *gb,
     LOCAL_ALIGNED_32(int16_t, block, [64]);
     LOCAL_ALIGNED_16(uint8_t, ublock, [64]);
     LOCAL_ALIGNED_16(int32_t, dctblock, [64]);
-    int coordmap[64];
+    int coordmap[64], quant_idx, coef_count, coef_idx[64];
 
     const int stride = frame->linesize[plane_idx];
     int bw = is_chroma ? (c->avctx->width  + 15) >> 4 : (c->avctx->width  + 7) >> 3;
@@ -1065,7 +1074,9 @@ static int bink_decode_plane(BinkContext *c, AVFrame *frame, GetBitContext *gb,
                 case INTRA_BLOCK:
                     memset(dctblock, 0, sizeof(*dctblock) * 64);
                     dctblock[0] = get_value(c, BINK_SRC_INTRA_DC);
-                    read_dct_coeffs(gb, dctblock, bink_scan, bink_intra_quant, -1);
+                    if ((quant_idx = read_dct_coeffs(gb, dctblock, bink_scan, &coef_count, coef_idx, -1)) < 0)
+                        return quant_idx;
+                    unquantize_dct_coeffs(dctblock, bink_intra_quant[quant_idx], coef_count, coef_idx, bink_scan);
                     c->binkdsp.idct_put(ublock, 8, dctblock);
                     break;
                 case FILL_BLOCK:
@@ -1138,7 +1149,9 @@ static int bink_decode_plane(BinkContext *c, AVFrame *frame, GetBitContext *gb,
             case INTRA_BLOCK:
                 memset(dctblock, 0, sizeof(*dctblock) * 64);
                 dctblock[0] = get_value(c, BINK_SRC_INTRA_DC);
-                read_dct_coeffs(gb, dctblock, bink_scan, bink_intra_quant, -1);
+                if ((quant_idx = read_dct_coeffs(gb, dctblock, bink_scan, &coef_count, coef_idx, -1)) < 0)
+                    return quant_idx;
+                unquantize_dct_coeffs(dctblock, bink_intra_quant[quant_idx], coef_count, coef_idx, bink_scan);
                 c->binkdsp.idct_put(dst, stride, dctblock);
                 break;
             case FILL_BLOCK:
@@ -1152,7 +1165,9 @@ static int bink_decode_plane(BinkContext *c, AVFrame *frame, GetBitContext *gb,
                     return ret;
                 memset(dctblock, 0, sizeof(*dctblock) * 64);
                 dctblock[0] = get_value(c, BINK_SRC_INTER_DC);
-                read_dct_coeffs(gb, dctblock, bink_scan, bink_inter_quant, -1);
+                if ((quant_idx = read_dct_coeffs(gb, dctblock, bink_scan, &coef_count, coef_idx, -1)) < 0)
+                    return quant_idx;
+                unquantize_dct_coeffs(dctblock, bink_inter_quant[quant_idx], coef_count, coef_idx, bink_scan);
                 c->binkdsp.idct_add(dst, stride, dctblock);
                 break;
             case PATTERN_BLOCK:


======================================================================

diff --cc libavcodec/bink.c
index 346b6cda9d,98fc46e026..c4cf617a8b
--- a/libavcodec/bink.c
+++ b/libavcodec/bink.c
@@@ -601,17 -594,16 +601,16 @@@ static inline int binkb_get_value(BinkC
   * @param quant_matrices quantization matrices
   * @return 0 for success, negative value in other cases
   */
- static int read_dct_coeffs(GetBitContext *gb, int32_t block[64], const uint8_t *scan,
-                            const int32_t quant_matrices[16][64], int q)
 -static int read_dct_coeffs(BitstreamContext *bc, int32_t block[64],
++static int read_dct_coeffs(GetBitContext *gb, int32_t block[64],
+                            const uint8_t *scan, int *coef_count_,
+                            int coef_idx[64], int q)
  {
      int coef_list[128];
      int mode_list[128];
 -    int i, t, bits, ccoef, mode;
 +    int i, t, bits, ccoef, mode, sign;
      int list_start = 64, list_end = 64, list_pos;
      int coef_count = 0;
-     int coef_idx[64];
      int quant_idx;
-     const int32_t *quant;
  
      coef_list[list_end] = 4;  mode_list[list_end++] = 0;
      coef_list[list_end] = 24; mode_list[list_end++] = 0;
@@@ -681,17 -671,24 +680,25 @@@
      }
  
      if (q == -1) {
 -        quant_idx = bitstream_read(bc, 4);
 +        quant_idx = get_bits(gb, 4);
      } else {
          quant_idx = q;
 +        if (quant_idx > 15U) {
 +            av_log(NULL, AV_LOG_ERROR, "quant_index %d out of range\n", quant_idx);
 +            return AVERROR_INVALIDDATA;
 +        }
      }
  
-     quant = quant_matrices[quant_idx];
 -    if (quant_idx >= 16)
 -        return AVERROR_INVALIDDATA;
 -
+     *coef_count_ = coef_count;
  
+     return quant_idx;
+ }
+ 
+ static void unquantize_dct_coeffs(int32_t block[64], const int32_t quant[64],
+                                   int coef_count, int coef_idx[64],
+                                   const uint8_t *scan)
+ {
+     int i;
      block[0] = (block[0] * quant[0]) >> 11;
      for (i = 0; i < coef_count; i++) {
          int idx = coef_idx[i];
@@@ -872,7 -863,9 +877,9 @@@ static int binkb_decode_plane(BinkConte
                  memset(dctblock, 0, sizeof(*dctblock) * 64);
                  dctblock[0] = binkb_get_value(c, BINKB_SRC_INTRA_DC);
                  qp = binkb_get_value(c, BINKB_SRC_INTRA_Q);
-                 read_dct_coeffs(gb, dctblock, bink_scan, (const int32_t (*)[64])binkb_intra_quant, qp);
 -                if ((quant_idx = read_dct_coeffs(bc, dctblock, bink_scan, &coef_count, coef_idx, qp)) < 0)
++                if ((quant_idx = read_dct_coeffs(gb, dctblock, bink_scan, &coef_count, coef_idx, qp)) < 0)
+                     return quant_idx;
+                 unquantize_dct_coeffs(dctblock, binkb_intra_quant[quant_idx], coef_count, coef_idx, bink_scan);
                  c->binkdsp.idct_put(dst, stride, dctblock);
                  break;
              case 3:
@@@ -905,7 -898,9 +912,9 @@@
                  memset(dctblock, 0, sizeof(*dctblock) * 64);
                  dctblock[0] = binkb_get_value(c, BINKB_SRC_INTER_DC);
                  qp = binkb_get_value(c, BINKB_SRC_INTER_Q);
-                 read_dct_coeffs(gb, dctblock, bink_scan, (const int32_t (*)[64])binkb_inter_quant, qp);
 -                if ((quant_idx = read_dct_coeffs(bc, dctblock, bink_scan, &coef_count, coef_idx, qp)) < 0)
++                if ((quant_idx = read_dct_coeffs(gb, dctblock, bink_scan, &coef_count, coef_idx, qp)) < 0)
+                     return quant_idx;
+                 unquantize_dct_coeffs(dctblock, binkb_inter_quant[quant_idx], coef_count, coef_idx, bink_scan);
                  c->binkdsp.idct_add(dst, stride, dctblock);
                  break;
              case 5:
@@@ -976,10 -971,10 +985,10 @@@ static int bink_decode_plane(BinkContex
      uint8_t *dst, *prev, *ref_start, *ref_end;
      int v, col[2];
      const uint8_t *scan;
 -    LOCAL_ALIGNED_16(int16_t, block, [64]);
 +    LOCAL_ALIGNED_32(int16_t, block, [64]);
      LOCAL_ALIGNED_16(uint8_t, ublock, [64]);
      LOCAL_ALIGNED_16(int32_t, dctblock, [64]);
-     int coordmap[64];
+     int coordmap[64], quant_idx, coef_count, coef_idx[64];
  
      const int stride = frame->linesize[plane_idx];
      int bw = is_chroma ? (c->avctx->width  + 15) >> 4 : (c->avctx->width  + 7) >> 3;
@@@ -1065,7 -1060,9 +1074,9 @@@
                  case INTRA_BLOCK:
                      memset(dctblock, 0, sizeof(*dctblock) * 64);
                      dctblock[0] = get_value(c, BINK_SRC_INTRA_DC);
-                     read_dct_coeffs(gb, dctblock, bink_scan, bink_intra_quant, -1);
 -                    if ((quant_idx = read_dct_coeffs(bc, dctblock, bink_scan, &coef_count, coef_idx, -1)) < 0)
++                    if ((quant_idx = read_dct_coeffs(gb, dctblock, bink_scan, &coef_count, coef_idx, -1)) < 0)
+                         return quant_idx;
+                     unquantize_dct_coeffs(dctblock, bink_intra_quant[quant_idx], coef_count, coef_idx, bink_scan);
                      c->binkdsp.idct_put(ublock, 8, dctblock);
                      break;
                  case FILL_BLOCK:
@@@ -1138,7 -1135,9 +1149,9 @@@
              case INTRA_BLOCK:
                  memset(dctblock, 0, sizeof(*dctblock) * 64);
                  dctblock[0] = get_value(c, BINK_SRC_INTRA_DC);
-                 read_dct_coeffs(gb, dctblock, bink_scan, bink_intra_quant, -1);
 -                if ((quant_idx = read_dct_coeffs(bc, dctblock, bink_scan, &coef_count, coef_idx, -1)) < 0)
++                if ((quant_idx = read_dct_coeffs(gb, dctblock, bink_scan, &coef_count, coef_idx, -1)) < 0)
+                     return quant_idx;
+                 unquantize_dct_coeffs(dctblock, bink_intra_quant[quant_idx], coef_count, coef_idx, bink_scan);
                  c->binkdsp.idct_put(dst, stride, dctblock);
                  break;
              case FILL_BLOCK:
@@@ -1152,7 -1151,9 +1165,9 @@@
                      return ret;
                  memset(dctblock, 0, sizeof(*dctblock) * 64);
                  dctblock[0] = get_value(c, BINK_SRC_INTER_DC);
-                 read_dct_coeffs(gb, dctblock, bink_scan, bink_inter_quant, -1);
 -                if ((quant_idx = read_dct_coeffs(bc, dctblock, bink_scan, &coef_count, coef_idx, -1)) < 0)
++                if ((quant_idx = read_dct_coeffs(gb, dctblock, bink_scan, &coef_count, coef_idx, -1)) < 0)
+                     return quant_idx;
+                 unquantize_dct_coeffs(dctblock, bink_inter_quant[quant_idx], coef_count, coef_idx, bink_scan);
                  c->binkdsp.idct_add(dst, stride, dctblock);
                  break;
              case PATTERN_BLOCK:



More information about the ffmpeg-cvslog mailing list