diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-06-21 13:47:30 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-06-21 13:47:30 +0400 |
commit | c250ab893c0b0086011d44848b66e53adcff8cad (patch) | |
tree | 0131eb22eb0726c995a4ecf6c6fa2022f7846cd9 /extern/libopenjpeg/mqc.c | |
parent | 11cb213d4509b6a2733210fce934395a86543bae (diff) |
update libopenjpeg from 1.3 to 1.5, since 1.3 has a bug saving alpha channels.
the patches/ dir is NOT applied but perhaps we can get OSX and BSD working using the opj_config.h
Diffstat (limited to 'extern/libopenjpeg/mqc.c')
-rw-r--r-- | extern/libopenjpeg/mqc.c | 74 |
1 files changed, 64 insertions, 10 deletions
diff --git a/extern/libopenjpeg/mqc.c b/extern/libopenjpeg/mqc.c index 9aa9d2c2e5b..14129fbf4e5 100644 --- a/extern/libopenjpeg/mqc.c +++ b/extern/libopenjpeg/mqc.c @@ -68,24 +68,23 @@ FIXME: documentation ??? @param mqc MQC handle @return */ -static int mqc_mpsexchange(opj_mqc_t *mqc); +static INLINE int mqc_mpsexchange(opj_mqc_t *const mqc); /** FIXME: documentation ??? @param mqc MQC handle @return */ -static int mqc_lpsexchange(opj_mqc_t *mqc); +static INLINE int mqc_lpsexchange(opj_mqc_t *const mqc); /** Input a byte @param mqc MQC handle */ -static void mqc_bytein(opj_mqc_t *mqc); +static INLINE void mqc_bytein(opj_mqc_t *const mqc); /** Renormalize mqc->a and mqc->c while decoding @param mqc MQC handle */ -static void mqc_renormd(opj_mqc_t *mqc); - +static INLINE void mqc_renormd(opj_mqc_t *const mqc); /*@}*/ /*@}*/ @@ -271,7 +270,7 @@ static void mqc_setbits(opj_mqc_t *mqc) { } } -static int mqc_mpsexchange(opj_mqc_t *mqc) { +static INLINE int mqc_mpsexchange(opj_mqc_t *const mqc) { int d; if (mqc->a < (*mqc->curctx)->qeval) { d = 1 - (*mqc->curctx)->mps; @@ -284,7 +283,7 @@ static int mqc_mpsexchange(opj_mqc_t *mqc) { return d; } -static int mqc_lpsexchange(opj_mqc_t *mqc) { +static INLINE int mqc_lpsexchange(opj_mqc_t *const mqc) { int d; if (mqc->a < (*mqc->curctx)->qeval) { mqc->a = (*mqc->curctx)->qeval; @@ -299,7 +298,15 @@ static int mqc_lpsexchange(opj_mqc_t *mqc) { return d; } -static void mqc_bytein(opj_mqc_t *mqc) { +#ifdef MQC_PERF_OPT +static INLINE void mqc_bytein(opj_mqc_t *const mqc) { + unsigned int i = *((unsigned int *) mqc->bp); + mqc->c += i & 0xffff00; + mqc->ct = i & 0x0f; + mqc->bp += (i >> 2) & 0x04; +} +#else +static void mqc_bytein(opj_mqc_t *const mqc) { if (mqc->bp != mqc->end) { unsigned int c; if (mqc->bp + 1 != mqc->end) { @@ -326,8 +333,9 @@ static void mqc_bytein(opj_mqc_t *mqc) { mqc->ct = 8; } } +#endif -static void mqc_renormd(opj_mqc_t *mqc) { +static INLINE void mqc_renormd(opj_mqc_t *const mqc) { do { if (mqc->ct == 0) { mqc_bytein(mqc); @@ -346,11 +354,19 @@ static void mqc_renormd(opj_mqc_t *mqc) { opj_mqc_t* mqc_create(void) { opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t)); +#ifdef MQC_PERF_OPT + mqc->buffer = NULL; +#endif return mqc; } void mqc_destroy(opj_mqc_t *mqc) { if(mqc) { +#ifdef MQC_PERF_OPT + if (mqc->buffer) { + opj_free(mqc->buffer); + } +#endif opj_free(mqc); } } @@ -499,13 +515,51 @@ void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) { mqc->bp = bp; if (len==0) mqc->c = 0xff << 16; else mqc->c = *mqc->bp << 16; + +#ifdef MQC_PERF_OPT + { + unsigned int c; + unsigned int *ip; + unsigned char *end = mqc->end - 1; + mqc->buffer = opj_realloc(mqc->buffer, (len + 1) * sizeof(unsigned int)); + ip = (unsigned int *) mqc->buffer; + + while (bp < end) { + c = *(bp + 1); + if (*bp == 0xff) { + if (c > 0x8f) { + break; + } else { + *ip = 0x00000017 | (c << 9); + } + } else { + *ip = 0x00000018 | (c << 8); + } + bp++; + ip++; + } + + /* Handle last byte of data */ + c = 0xff; + if (*bp == 0xff) { + *ip = 0x0000ff18; + } else { + bp++; + *ip = 0x00000018 | (c << 8); + } + ip++; + + *ip = 0x0000ff08; + mqc->bp = mqc->buffer; + } +#endif mqc_bytein(mqc); mqc->c <<= 7; mqc->ct -= 7; mqc->a = 0x8000; } -int mqc_decode(opj_mqc_t *mqc) { +int mqc_decode(opj_mqc_t *const mqc) { int d; mqc->a -= (*mqc->curctx)->qeval; if ((mqc->c >> 16) < (*mqc->curctx)->qeval) { |