opj_t1_updateflags(): tiny optimization

We can avoid using a loop-up table with some shift arithmetics.
This commit is contained in:
Even Rouault 2016-05-21 15:41:36 +02:00
parent 426bf8d337
commit c539808d09
2 changed files with 11 additions and 10 deletions

View File

@ -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;
}

View File

@ -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 */