From c539808d097945866c0f7120ccdea28921a011a2 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 21 May 2016 15:41:36 +0200 Subject: [PATCH] opj_t1_updateflags(): tiny optimization We can avoid using a loop-up table with some shift arithmetics. --- src/lib/openjp2/t1.c | 19 +++++++++---------- src/lib/openjp2/t1.h | 2 ++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/lib/openjp2/t1.c b/src/lib/openjp2/t1.c index 1bf7205e..37fc4fc1 100644 --- a/src/lib/openjp2/t1.c +++ b/src/lib/openjp2/t1.c @@ -343,23 +343,22 @@ static void opj_t1_updateflags(opj_flag_t *flagsp, OPJ_UINT32 s, OPJ_UINT32 stri opj_flag_t *np = flagsp - stride; opj_flag_t *sp = flagsp + stride; - static const opj_flag_t mod[] = { - T1_SIG_S, T1_SIG_S|T1_SGN_S, - T1_SIG_E, T1_SIG_E|T1_SGN_E, - T1_SIG_W, T1_SIG_W|T1_SGN_W, - T1_SIG_N, T1_SIG_N|T1_SGN_N - }; + /* We strongly rely on (T1_SGN_N == 0x0100) == (T1_SIG_N == 0x0010) << 4 */ + /* and T1_SIG_E == T1_SIG_N << 1, T1_SIG_W == T1_SIG_N << 2 and T1_SIG_S == T1_SIG_N << 2 */ + /* and T1_SGN_E == T1_SGN_N << 1, T1_SGN_W == T1_SGN_N << 2 and T1_SGN_S == T1_SGN_N << 2 */ + + opj_flag_t flag_N = T1_SIG_N | (T1_SIG_N << (4 * s)); np[-1] |= T1_SIG_SE; - np[0] |= mod[s]; + np[0] |= flag_N << 2; np[1] |= T1_SIG_SW; - flagsp[-1] |= mod[s+2]; + flagsp[-1] |= flag_N << 1; flagsp[0] |= T1_SIG; - flagsp[1] |= mod[s+4]; + flagsp[1] |= flag_N << 3; sp[-1] |= T1_SIG_NE; - sp[0] |= mod[s+6]; + sp[0] |= flag_N; sp[1] |= T1_SIG_NW; } diff --git a/src/lib/openjp2/t1.h b/src/lib/openjp2/t1.h index 3bc0ad9e..e9d3db57 100644 --- a/src/lib/openjp2/t1.h +++ b/src/lib/openjp2/t1.h @@ -50,6 +50,8 @@ in T1.C are used by some function in TCD.C. /* ----------------------------------------------------------------------- */ #define T1_NMSEDEC_BITS 7 +/* CAUTION: the value of those constants must not be changed, otherwise the */ +/* optimization of opj_t1_updateflags() will break! */ #define T1_SIG_NE 0x0001 /**< Context orientation : North-East direction */ #define T1_SIG_SE 0x0002 /**< Context orientation : South-East direction */ #define T1_SIG_SW 0x0004 /**< Context orientation : South-West direction */