summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2016-05-21 15:41:36 +0200
committerEven Rouault <even.rouault@spatialys.com>2016-05-21 15:46:56 +0200
commitc539808d097945866c0f7120ccdea28921a011a2 (patch)
tree3b2d1e555074c1792141be8d96a7d9e5f8843bed /src
parent426bf8d337715f7b2e867cb2643128e5c2e3b5bb (diff)
opj_t1_updateflags(): tiny optimization
We can avoid using a loop-up table with some shift arithmetics.
Diffstat (limited to 'src')
-rw-r--r--src/lib/openjp2/t1.c19
-rw-r--r--src/lib/openjp2/t1.h2
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 */