Merge commit 'fd92dafaff8844b5fedf94679b93d953939a7f7b'
authorJames Almer <jamrial@gmail.com>
Tue, 7 Nov 2017 21:44:44 +0000 (18:44 -0300)
committerJames Almer <jamrial@gmail.com>
Tue, 7 Nov 2017 21:44:44 +0000 (18:44 -0300)
* commit 'fd92dafaff8844b5fedf94679b93d953939a7f7b':
  bink: Split read_dct_coeffs()

Merged-by: James Almer <jamrial@gmail.com>
1  2 
libavcodec/bink.c

index 346b6cda9dfb6b965d4b463bb7d95c15f164c9a4,98fc46e0266ace00322f6fa79775cbaa8cf27c25..c4cf617a8bc80232503f6e8127f1a91b09819d04
@@@ -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;
      }
  
      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:
                  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;
                  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:
              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:
                      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: