From 607444cee46a8762a2b004377d600d1f9a56d7d2 Mon Sep 17 00:00:00 2001 From: Nathan Caldwell Date: Thu, 13 Aug 2009 01:00:35 -0600 Subject: [PATCH] Use a function instead of a table for 0 run calculation. --- libavcodec/lagarith.c | 15 +++++++++++++-- libavcodec/lagarith.h | 19 ------------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/libavcodec/lagarith.c b/libavcodec/lagarith.c index 8ca4c16dce..7dcced90c7 100644 --- a/libavcodec/lagarith.c +++ b/libavcodec/lagarith.c @@ -81,6 +81,16 @@ static inline int lag_predict(uint8_t *src, int stride, int step) return mid_pred(T, L, L + T - TL); } +static uint8_t lag_calc_zero_run(int8_t x) +{ +#if 0 + x <<= 1; + if (x > 255) return ~x; + return x; +#endif + return (x << 1) ^ (x >> 7); +} + static uint32_t lag_decode_prob(GetBitContext *gb) { static const uint8_t series[] = { 1, 2, 3, 5, 8, 13, 21, 34 }; @@ -246,7 +256,7 @@ static int lag_decode_line(LagarithContext *l, lag_rac *rac, l->zeros = 0; l->zeros_rem = - count = run_table[index]; + count = lag_calc_zero_run(index); if (i + count > width) count = width - i; @@ -294,7 +304,8 @@ static int lag_decode_zero_run_line(LagarithContext *l, uint8_t *dst, i += esc_count; lag_memcpy(dst, src, i, step); dst += i; - l->zeros_rem = count = run_table[src[i]]; + l->zeros_rem = + count = lag_calc_zero_run(src[i]); if (dst + l->zeros_rem * step > end) count = (end - dst) / step; diff --git a/libavcodec/lagarith.h b/libavcodec/lagarith.h index 1907d14217..f2cc78feca 100644 --- a/libavcodec/lagarith.h +++ b/libavcodec/lagarith.h @@ -43,23 +43,4 @@ enum LagarithFrameType { FRAME_REDUCED_RES = 11, /*!< Reduced resolution frame */ }; - -static const uint8_t run_table[] = { 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, - 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, - 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, - 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, - 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, - 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, - 190, 192, 194, 196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, - 220, 222, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, - 250, 252, 254, 255, 253, 251, 249, 247, 245, 243, 241, 239, 237, 235, 233, - 231, 229, 227, 225, 223, 221, 219, 217, 215, 213, 211, 209, 207, 205, 203, - 201, 199, 197, 195, 193, 191, 189, 187, 185, 183, 181, 179, 177, 175, 173, - 171, 169, 167, 165, 163, 161, 159, 157, 155, 153, 151, 149, 147, 145, 143, - 141, 139, 137, 135, 133, 131, 129, 127, 125, 123, 121, 119, 117, 115, 113, - 111, 109, 107, 105, 103, 101, 99, 97, 95, 93, 91, 89, 87, 85, 83, 81, 79, - 77, 75, 73, 71, 69, 67, 65, 63, 61, 59, 57, 55, 53, 51, 49, 47, 45, 43, 41, - 39, 37, 35, 33, 31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1 -}; - #endif /* AVCODEC_LAGARITH_H */ -- 2.11.4.GIT