[FFmpeg-devel] [PATCH 1/2] proresenc_anatoliy: use tables in proresdata.c instead of redefining them

Timothy Gu timothygu99 at gmail.com
Fri Jul 18 03:04:06 CEST 2014


Signed-off-by: Timothy Gu <timothygu99 at gmail.com>
---
 libavcodec/Makefile             |  4 ++--
 libavcodec/proresenc_anatoliy.c | 43 ++++++++++++++---------------------------
 2 files changed, 16 insertions(+), 31 deletions(-)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 307ad22..e3f75f5 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -369,8 +369,8 @@ OBJS-$(CONFIG_PPM_DECODER)             += pnmdec.o pnm.o
 OBJS-$(CONFIG_PPM_ENCODER)             += pnmenc.o
 OBJS-$(CONFIG_PRORES_DECODER)          += proresdec2.o proresdsp.o proresdata.o
 OBJS-$(CONFIG_PRORES_LGPL_DECODER)     += proresdec_lgpl.o proresdsp.o proresdata.o
-OBJS-$(CONFIG_PRORES_ENCODER)          += proresenc_anatoliy.o
-OBJS-$(CONFIG_PRORES_AW_ENCODER)       += proresenc_anatoliy.o
+OBJS-$(CONFIG_PRORES_ENCODER)          += proresenc_anatoliy.o proresdata.o
+OBJS-$(CONFIG_PRORES_AW_ENCODER)       += proresenc_anatoliy.o proresdata.o
 OBJS-$(CONFIG_PRORES_KS_ENCODER)       += proresenc_kostya.o proresdata.o
 OBJS-$(CONFIG_PTX_DECODER)             += ptx.o
 OBJS-$(CONFIG_QCELP_DECODER)           += qcelpdec.o                     \
diff --git a/libavcodec/proresenc_anatoliy.c b/libavcodec/proresenc_anatoliy.c
index f471f49..b8531cd 100644
--- a/libavcodec/proresenc_anatoliy.c
+++ b/libavcodec/proresenc_anatoliy.c
@@ -32,6 +32,7 @@
 #include "put_bits.h"
 #include "bytestream.h"
 #include "fdctdsp.h"
+#include "proresdata.h"
 
 #define DEFAULT_SLICE_MB_WIDTH 8
 
@@ -52,17 +53,6 @@ static const int qp_start_table[4] = { 4, 1, 1, 1 };
 static const int qp_end_table[4]   = { 8, 9, 6, 6 };
 static const int bitrate_table[5]  = { 1000, 2100, 3500, 5400 };
 
-static const uint8_t progressive_scan[64] = {
-     0,  1,  8,  9,  2,  3, 10, 11,
-    16, 17, 24, 25, 18, 19, 26, 27,
-     4,  5, 12, 20, 13,  6,  7, 14,
-    21, 28, 29, 22, 15, 23, 30, 31,
-    32, 33, 40, 48, 41, 34, 35, 42,
-    49, 56, 57, 50, 43, 36, 37, 44,
-    51, 58, 59, 52, 45, 38, 39, 46,
-    53, 60, 61, 54, 47, 55, 62, 63
-};
-
 static const uint8_t QMAT_LUMA[4][64] = {
     {
          4,  7,  9, 11, 13, 14, 15, 63,
@@ -196,10 +186,6 @@ static av_always_inline int get_level(int val)
     return (val ^ sign) - sign;
 }
 
-#define FIRST_DC_CB 0xB8
-
-static const uint8_t dc_codebook[7] = { 0x04, 0x28, 0x28, 0x4D, 0x4D, 0x70, 0x70};
-
 static void encode_dc_coeffs(PutBitContext *pb, int16_t *in,
         int blocks_per_slice, int *qmat)
 {
@@ -211,48 +197,47 @@ static void encode_dc_coeffs(PutBitContext *pb, int16_t *in,
     code = TO_GOLOMB(prev_dc);
     encode_codeword(pb, code, FIRST_DC_CB);
 
-    code = 5; sign = 0; idx = 64;
+    code = 3; sign = 0; idx = 64;
     for (i = 1; i < blocks_per_slice; i++, idx += 64) {
         new_dc    = QSCALE(qmat, 0, in[idx] - 16384);
         delta     = new_dc - prev_dc;
         diff_sign = DIFF_SIGN(delta, sign);
         new_code  = TO_GOLOMB2(get_level(delta), diff_sign);
-
-        encode_codeword(pb, new_code, dc_codebook[FFMIN(code, 6)]);
-
-        code      = new_code;
+        encode_codeword(pb, new_code, ff_prores_dc_codebook[code]);
+        code      = (new_code + (new_code & 1)) >> 1;
+        code      = FFMIN(code, 3);
         sign      = delta >> 31;
         prev_dc   = new_dc;
     }
 }
 
-static const uint8_t run_to_cb[16] = { 0x06, 0x06, 0x05, 0x05, 0x04, 0x29,
-        0x29, 0x29, 0x29, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x4C };
-static const uint8_t lev_to_cb[10] = { 0x04, 0x0A, 0x05, 0x06, 0x04, 0x28,
-        0x28, 0x28, 0x28, 0x4C };
-
 static void encode_ac_coeffs(AVCodecContext *avctx, PutBitContext *pb,
         int16_t *in, int blocks_per_slice, int *qmat)
 {
     int prev_run = 4;
     int prev_level = 2;
 
-    int run = 0, level, code, i, j;
+    int run = 0, level, code, i, j, run_cb, lev_cb;
+    run_cb     = ff_prores_run_to_cb_index[4];
+    lev_cb     = ff_prores_lev_to_cb_index[2];
+
     for (i = 1; i < 64; i++) {
-        int indp = progressive_scan[i];
+        int indp = ff_prores_progressive_scan[i];
         for (j = 0; j < blocks_per_slice; j++) {
             int val = QSCALE(qmat, indp, in[(j << 6) + indp]);
             if (val) {
-                encode_codeword(pb, run, run_to_cb[FFMIN(prev_run, 15)]);
+                encode_codeword(pb, run, ff_prores_ac_codebook[run_cb]);
 
                 prev_run   = run;
                 run        = 0;
                 level      = get_level(val);
                 code       = level - 1;
 
-                encode_codeword(pb, code, lev_to_cb[FFMIN(prev_level, 9)]);
+                encode_codeword(pb, code, ff_prores_ac_codebook[lev_cb]);
 
                 prev_level = level;
+                run_cb = ff_prores_run_to_cb_index[FFMIN(prev_run,  15)];
+                lev_cb = ff_prores_lev_to_cb_index[FFMIN(prev_level, 9)];
 
                 put_bits(pb, 1, IS_NEGATIVE(val));
             } else {
-- 
1.9.1



More information about the ffmpeg-devel mailing list