Move some MQC functions into a header for speed
Allow these hot functions to be inlined. This boosts decode performance by ~10%.
This commit is contained in:
parent
d0babeb6f6
commit
426bf8d337
@ -29,6 +29,7 @@ set(OPENJPEG_SRCS
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/mct.h
|
${CMAKE_CURRENT_SOURCE_DIR}/mct.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/mqc.c
|
${CMAKE_CURRENT_SOURCE_DIR}/mqc.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/mqc.h
|
${CMAKE_CURRENT_SOURCE_DIR}/mqc.h
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/mqc_inl.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/openjpeg.c
|
${CMAKE_CURRENT_SOURCE_DIR}/openjpeg.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/openjpeg.h
|
${CMAKE_CURRENT_SOURCE_DIR}/openjpeg.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/opj_clock.c
|
${CMAKE_CURRENT_SOURCE_DIR}/opj_clock.c
|
||||||
|
@ -70,28 +70,6 @@ Fill mqc->c with 1's for flushing
|
|||||||
@param mqc MQC handle
|
@param mqc MQC handle
|
||||||
*/
|
*/
|
||||||
static void opj_mqc_setbits(opj_mqc_t *mqc);
|
static void opj_mqc_setbits(opj_mqc_t *mqc);
|
||||||
/**
|
|
||||||
FIXME DOC
|
|
||||||
@param mqc MQC handle
|
|
||||||
@return
|
|
||||||
*/
|
|
||||||
static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc);
|
|
||||||
/**
|
|
||||||
FIXME DOC
|
|
||||||
@param mqc MQC handle
|
|
||||||
@return
|
|
||||||
*/
|
|
||||||
static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc);
|
|
||||||
/**
|
|
||||||
Input a byte
|
|
||||||
@param mqc MQC handle
|
|
||||||
*/
|
|
||||||
static INLINE void opj_mqc_bytein(opj_mqc_t *const mqc);
|
|
||||||
/**
|
|
||||||
Renormalize mqc->a and mqc->c while decoding
|
|
||||||
@param mqc MQC handle
|
|
||||||
*/
|
|
||||||
static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc);
|
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
|
||||||
/*@}*/
|
/*@}*/
|
||||||
@ -284,82 +262,6 @@ static void opj_mqc_setbits(opj_mqc_t *mqc) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc) {
|
|
||||||
OPJ_INT32 d;
|
|
||||||
if (mqc->a < (*mqc->curctx)->qeval) {
|
|
||||||
d = (OPJ_INT32)(1 - (*mqc->curctx)->mps);
|
|
||||||
*mqc->curctx = (*mqc->curctx)->nlps;
|
|
||||||
} else {
|
|
||||||
d = (OPJ_INT32)(*mqc->curctx)->mps;
|
|
||||||
*mqc->curctx = (*mqc->curctx)->nmps;
|
|
||||||
}
|
|
||||||
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
|
|
||||||
static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc) {
|
|
||||||
OPJ_INT32 d;
|
|
||||||
if (mqc->a < (*mqc->curctx)->qeval) {
|
|
||||||
mqc->a = (*mqc->curctx)->qeval;
|
|
||||||
d = (OPJ_INT32)(*mqc->curctx)->mps;
|
|
||||||
*mqc->curctx = (*mqc->curctx)->nmps;
|
|
||||||
} else {
|
|
||||||
mqc->a = (*mqc->curctx)->qeval;
|
|
||||||
d = (OPJ_INT32)(1 - (*mqc->curctx)->mps);
|
|
||||||
*mqc->curctx = (*mqc->curctx)->nlps;
|
|
||||||
}
|
|
||||||
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef MQC_PERF_OPT
|
|
||||||
static INLINE void opj_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 opj_mqc_bytein(opj_mqc_t *const mqc) {
|
|
||||||
if (mqc->bp != mqc->end) {
|
|
||||||
OPJ_UINT32 c;
|
|
||||||
if (mqc->bp + 1 != mqc->end) {
|
|
||||||
c = *(mqc->bp + 1);
|
|
||||||
} else {
|
|
||||||
c = 0xff;
|
|
||||||
}
|
|
||||||
if (*mqc->bp == 0xff) {
|
|
||||||
if (c > 0x8f) {
|
|
||||||
mqc->c += 0xff00;
|
|
||||||
mqc->ct = 8;
|
|
||||||
} else {
|
|
||||||
mqc->bp++;
|
|
||||||
mqc->c += c << 9;
|
|
||||||
mqc->ct = 7;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mqc->bp++;
|
|
||||||
mqc->c += c << 8;
|
|
||||||
mqc->ct = 8;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mqc->c += 0xff00;
|
|
||||||
mqc->ct = 8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc) {
|
|
||||||
do {
|
|
||||||
if (mqc->ct == 0) {
|
|
||||||
opj_mqc_bytein(mqc);
|
|
||||||
}
|
|
||||||
mqc->a <<= 1;
|
|
||||||
mqc->c <<= 1;
|
|
||||||
mqc->ct--;
|
|
||||||
} while (mqc->a < 0x8000);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
==========================================================
|
==========================================================
|
||||||
MQ-Coder interface
|
MQ-Coder interface
|
||||||
@ -585,25 +487,6 @@ OPJ_BOOL opj_mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len) {
|
|||||||
return OPJ_TRUE;
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
OPJ_INT32 opj_mqc_decode(opj_mqc_t *const mqc) {
|
|
||||||
OPJ_INT32 d;
|
|
||||||
mqc->a -= (*mqc->curctx)->qeval;
|
|
||||||
if ((mqc->c >> 16) < (*mqc->curctx)->qeval) {
|
|
||||||
d = opj_mqc_lpsexchange(mqc);
|
|
||||||
opj_mqc_renormd(mqc);
|
|
||||||
} else {
|
|
||||||
mqc->c -= (*mqc->curctx)->qeval << 16;
|
|
||||||
if ((mqc->a & 0x8000) == 0) {
|
|
||||||
d = opj_mqc_mpsexchange(mqc);
|
|
||||||
opj_mqc_renormd(mqc);
|
|
||||||
} else {
|
|
||||||
d = (OPJ_INT32)(*mqc->curctx)->mps;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
|
|
||||||
void opj_mqc_resetstates(opj_mqc_t *mqc) {
|
void opj_mqc_resetstates(opj_mqc_t *mqc) {
|
||||||
OPJ_UINT32 i;
|
OPJ_UINT32 i;
|
||||||
for (i = 0; i < MQC_NUMCTXS; i++) {
|
for (i = 0; i < MQC_NUMCTXS; i++) {
|
||||||
|
@ -82,6 +82,8 @@ typedef struct opj_mqc {
|
|||||||
#endif
|
#endif
|
||||||
} opj_mqc_t;
|
} opj_mqc_t;
|
||||||
|
|
||||||
|
#include "mqc_inl.h"
|
||||||
|
|
||||||
/** @name Exported functions */
|
/** @name Exported functions */
|
||||||
/*@{*/
|
/*@{*/
|
||||||
/* ----------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------- */
|
||||||
@ -198,7 +200,7 @@ Decode a symbol
|
|||||||
@param mqc MQC handle
|
@param mqc MQC handle
|
||||||
@return Returns the decoded symbol (0 or 1)
|
@return Returns the decoded symbol (0 or 1)
|
||||||
*/
|
*/
|
||||||
OPJ_INT32 opj_mqc_decode(opj_mqc_t * const mqc);
|
static INLINE OPJ_INT32 opj_mqc_decode(opj_mqc_t * const mqc);
|
||||||
/* ----------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------- */
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
|
||||||
|
159
src/lib/openjp2/mqc_inl.h
Normal file
159
src/lib/openjp2/mqc_inl.h
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
/*
|
||||||
|
* The copyright in this software is being made available under the 2-clauses
|
||||||
|
* BSD License, included below. This software may be subject to other third
|
||||||
|
* party and contributor rights, including patent rights, and no such rights
|
||||||
|
* are granted under this license.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
|
||||||
|
* Copyright (c) 2002-2014, Professor Benoit Macq
|
||||||
|
* Copyright (c) 2001-2003, David Janssens
|
||||||
|
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||||
|
* Copyright (c) 2003-2007, Francois-Olivier Devaux
|
||||||
|
* Copyright (c) 2003-2014, Antonin Descampe
|
||||||
|
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||||
|
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __MQC_INL_H
|
||||||
|
#define __MQC_INL_H
|
||||||
|
/**
|
||||||
|
FIXME DOC
|
||||||
|
@param mqc MQC handle
|
||||||
|
@return
|
||||||
|
*/
|
||||||
|
static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc) {
|
||||||
|
OPJ_INT32 d;
|
||||||
|
if (mqc->a < (*mqc->curctx)->qeval) {
|
||||||
|
d = (OPJ_INT32)(1 - (*mqc->curctx)->mps);
|
||||||
|
*mqc->curctx = (*mqc->curctx)->nlps;
|
||||||
|
} else {
|
||||||
|
d = (OPJ_INT32)(*mqc->curctx)->mps;
|
||||||
|
*mqc->curctx = (*mqc->curctx)->nmps;
|
||||||
|
}
|
||||||
|
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
FIXME DOC
|
||||||
|
@param mqc MQC handle
|
||||||
|
@return
|
||||||
|
*/
|
||||||
|
static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc) {
|
||||||
|
OPJ_INT32 d;
|
||||||
|
if (mqc->a < (*mqc->curctx)->qeval) {
|
||||||
|
mqc->a = (*mqc->curctx)->qeval;
|
||||||
|
d = (OPJ_INT32)(*mqc->curctx)->mps;
|
||||||
|
*mqc->curctx = (*mqc->curctx)->nmps;
|
||||||
|
} else {
|
||||||
|
mqc->a = (*mqc->curctx)->qeval;
|
||||||
|
d = (OPJ_INT32)(1 - (*mqc->curctx)->mps);
|
||||||
|
*mqc->curctx = (*mqc->curctx)->nlps;
|
||||||
|
}
|
||||||
|
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Input a byte
|
||||||
|
@param mqc MQC handle
|
||||||
|
*/
|
||||||
|
#ifdef MQC_PERF_OPT
|
||||||
|
static INLINE void opj_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 INLINE void opj_mqc_bytein(opj_mqc_t *const mqc) {
|
||||||
|
if (mqc->bp != mqc->end) {
|
||||||
|
OPJ_UINT32 c;
|
||||||
|
if (mqc->bp + 1 != mqc->end) {
|
||||||
|
c = *(mqc->bp + 1);
|
||||||
|
} else {
|
||||||
|
c = 0xff;
|
||||||
|
}
|
||||||
|
if (*mqc->bp == 0xff) {
|
||||||
|
if (c > 0x8f) {
|
||||||
|
mqc->c += 0xff00;
|
||||||
|
mqc->ct = 8;
|
||||||
|
} else {
|
||||||
|
mqc->bp++;
|
||||||
|
mqc->c += c << 9;
|
||||||
|
mqc->ct = 7;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mqc->bp++;
|
||||||
|
mqc->c += c << 8;
|
||||||
|
mqc->ct = 8;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mqc->c += 0xff00;
|
||||||
|
mqc->ct = 8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
Renormalize mqc->a and mqc->c while decoding
|
||||||
|
@param mqc MQC handle
|
||||||
|
*/
|
||||||
|
static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc) {
|
||||||
|
do {
|
||||||
|
if (mqc->ct == 0) {
|
||||||
|
opj_mqc_bytein(mqc);
|
||||||
|
}
|
||||||
|
mqc->a <<= 1;
|
||||||
|
mqc->c <<= 1;
|
||||||
|
mqc->ct--;
|
||||||
|
} while (mqc->a < 0x8000);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Decode a symbol
|
||||||
|
@param mqc MQC handle
|
||||||
|
@return Returns the decoded symbol (0 or 1)
|
||||||
|
*/
|
||||||
|
static INLINE OPJ_INT32 opj_mqc_decode(opj_mqc_t *const mqc) {
|
||||||
|
OPJ_INT32 d;
|
||||||
|
mqc->a -= (*mqc->curctx)->qeval;
|
||||||
|
if ((mqc->c >> 16) < (*mqc->curctx)->qeval) {
|
||||||
|
d = opj_mqc_lpsexchange(mqc);
|
||||||
|
opj_mqc_renormd(mqc);
|
||||||
|
} else {
|
||||||
|
mqc->c -= (*mqc->curctx)->qeval << 16;
|
||||||
|
if ((mqc->a & 0x8000) == 0) {
|
||||||
|
d = opj_mqc_mpsexchange(mqc);
|
||||||
|
opj_mqc_renormd(mqc);
|
||||||
|
} else {
|
||||||
|
d = (OPJ_INT32)(*mqc->curctx)->mps;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __MQC_INL_H */
|
Loading…
Reference in New Issue
Block a user