T1: avoid pointer indirection for mqc and raw members of opj_t1_t

This commit is contained in:
Even Rouault 2017-06-01 11:15:25 +02:00
parent a5003787ff
commit 10410fe72e
6 changed files with 22 additions and 84 deletions

View File

@ -272,19 +272,6 @@ static void opj_mqc_setbits(opj_mqc_t *mqc)
========================================================== ==========================================================
*/ */
opj_mqc_t* opj_mqc_create(void)
{
opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t));
return mqc;
}
void opj_mqc_destroy(opj_mqc_t *mqc)
{
if (mqc) {
opj_free(mqc);
}
}
OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc) OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc)
{ {
const ptrdiff_t diff = mqc->bp - mqc->start; const ptrdiff_t diff = mqc->bp - mqc->start;

View File

@ -86,16 +86,7 @@ typedef struct opj_mqc {
/** @name Exported functions */ /** @name Exported functions */
/*@{*/ /*@{*/
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/**
Create a new MQC handle
@return Returns a new MQC handle if successful, returns NULL otherwise
*/
opj_mqc_t* opj_mqc_create(void);
/**
Destroy a previously created MQC handle
@param mqc MQC handle to destroy
*/
void opj_mqc_destroy(opj_mqc_t *mqc);
/** /**
Return the number of bytes written/read since initialisation Return the number of bytes written/read since initialisation
@param mqc MQC handle @param mqc MQC handle

View File

@ -48,19 +48,6 @@
========================================================== ==========================================================
*/ */
opj_raw_t* opj_raw_create(void)
{
opj_raw_t *raw = (opj_raw_t*)opj_malloc(sizeof(opj_raw_t));
return raw;
}
void opj_raw_destroy(opj_raw_t *raw)
{
if (raw) {
opj_free(raw);
}
}
OPJ_UINT32 opj_raw_numbytes(opj_raw_t *raw) OPJ_UINT32 opj_raw_numbytes(opj_raw_t *raw)
{ {
const ptrdiff_t diff = raw->bp - raw->start; const ptrdiff_t diff = raw->bp - raw->start;

View File

@ -71,16 +71,7 @@ typedef struct opj_raw {
/** @name Exported functions */ /** @name Exported functions */
/*@{*/ /*@{*/
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/**
Create a new RAW handle
@return Returns a new RAW handle if successful, returns NULL otherwise
*/
opj_raw_t* opj_raw_create(void);
/**
Destroy a previously created RAW handle
@param raw RAW handle to destroy
*/
void opj_raw_destroy(opj_raw_t *raw);
/** /**
Return the number of bytes written/read since initialisation Return the number of bytes written/read since initialisation
@param raw RAW handle to destroy @param raw RAW handle to destroy

View File

@ -379,7 +379,7 @@ static INLINE void opj_t1_enc_sigpass_step(opj_t1_t *t1,
{ {
OPJ_UINT32 v; OPJ_UINT32 v;
opj_mqc_t *mqc = t1->mqc; /* MQC component */ opj_mqc_t *mqc = &(t1->mqc); /* MQC component */
OPJ_UINT32 vsc_mask = vsc ? ~((T1_SIGMA_SW | T1_SIGMA_S | T1_SIGMA_SE | OPJ_UINT32 vsc_mask = vsc ? ~((T1_SIGMA_SW | T1_SIGMA_S | T1_SIGMA_SE |
T1_CHI_S) << (ci * 3U)) : ~0U; T1_CHI_S) << (ci * 3U)) : ~0U;
@ -437,7 +437,7 @@ static INLINE void opj_t1_dec_sigpass_step_raw(
OPJ_UINT32 ci) OPJ_UINT32 ci)
{ {
OPJ_UINT32 v; OPJ_UINT32 v;
opj_raw_t *raw = t1->raw; /* RAW component */ opj_raw_t *raw = &(t1->raw); /* RAW component */
OPJ_UINT32 vsc_mask = vsc ? ~((T1_SIGMA_SW | T1_SIGMA_S | T1_SIGMA_SE | OPJ_UINT32 vsc_mask = vsc ? ~((T1_SIGMA_SW | T1_SIGMA_S | T1_SIGMA_SE |
T1_CHI_S) << (ci * 3U)) : ~0U; T1_CHI_S) << (ci * 3U)) : ~0U;
@ -464,7 +464,7 @@ static INLINE void opj_t1_dec_sigpass_step_mqc(
{ {
OPJ_UINT32 v; OPJ_UINT32 v;
opj_mqc_t *mqc = t1->mqc; /* MQC component */ opj_mqc_t *mqc = &(t1->mqc); /* MQC component */
OPJ_UINT32 const flags = *flagsp; OPJ_UINT32 const flags = *flagsp;
if ((flags & ((T1_SIGMA_THIS | T1_PI_THIS) << (ci * 3U))) == 0U && if ((flags & ((T1_SIGMA_THIS | T1_PI_THIS) << (ci * 3U))) == 0U &&
@ -497,7 +497,7 @@ static INLINE void opj_t1_dec_sigpass_step_mqc_vsc(
{ {
OPJ_UINT32 v; OPJ_UINT32 v;
opj_mqc_t *mqc = t1->mqc; /* MQC component */ opj_mqc_t *mqc = &(t1->mqc); /* MQC component */
OPJ_UINT32 vsc_mask = vsc ? ~((T1_SIGMA_SW | T1_SIGMA_S | T1_SIGMA_SE | OPJ_UINT32 vsc_mask = vsc ? ~((T1_SIGMA_SW | T1_SIGMA_S | T1_SIGMA_SE |
T1_CHI_S) << (ci * 3U)) : ~0U; T1_CHI_S) << (ci * 3U)) : ~0U;
@ -829,7 +829,7 @@ static INLINE void opj_t1_enc_refpass_step(opj_t1_t *t1,
{ {
OPJ_UINT32 v; OPJ_UINT32 v;
opj_mqc_t *mqc = t1->mqc; /* MQC component */ opj_mqc_t *mqc = &(t1->mqc); /* MQC component */
OPJ_UINT32 const shift_flags = OPJ_UINT32 const shift_flags =
vsc ? vsc ?
@ -867,7 +867,7 @@ static INLINE void opj_t1_dec_refpass_step_raw(
OPJ_UINT32 v; OPJ_UINT32 v;
OPJ_INT32 t; OPJ_INT32 t;
opj_raw_t *raw = t1->raw; /* RAW component */ opj_raw_t *raw = &(t1->raw); /* RAW component */
if ((*flagsp & ((T1_SIGMA_THIS | T1_PI_THIS) << (ci * 3U))) == if ((*flagsp & ((T1_SIGMA_THIS | T1_PI_THIS) << (ci * 3U))) ==
(T1_SIGMA_THIS << (ci * 3U))) { (T1_SIGMA_THIS << (ci * 3U))) {
@ -889,7 +889,7 @@ static INLINE void opj_t1_dec_refpass_step_mqc(
OPJ_UINT32 v; OPJ_UINT32 v;
OPJ_INT32 t; OPJ_INT32 t;
opj_mqc_t *mqc = t1->mqc; /* MQC component */ opj_mqc_t *mqc = &(t1->mqc); /* MQC component */
if ((*flagsp & ((T1_SIGMA_THIS | T1_PI_THIS) << (ci * 3U))) == if ((*flagsp & ((T1_SIGMA_THIS | T1_PI_THIS) << (ci * 3U))) ==
(T1_SIGMA_THIS << (ci * 3U))) { (T1_SIGMA_THIS << (ci * 3U))) {
@ -914,7 +914,7 @@ static INLINE void opj_t1_dec_refpass_step_mqc_vsc(
OPJ_UINT32 v; OPJ_UINT32 v;
OPJ_INT32 t; OPJ_INT32 t;
opj_mqc_t *mqc = t1->mqc; /* MQC component */ opj_mqc_t *mqc = &(t1->mqc); /* MQC component */
OPJ_UINT32 const shift_flags = OPJ_UINT32 const shift_flags =
vsc ? vsc ?
@ -1223,7 +1223,7 @@ static void opj_t1_enc_clnpass_step(
{ {
OPJ_UINT32 v; OPJ_UINT32 v;
OPJ_UINT32 ci; OPJ_UINT32 ci;
opj_mqc_t *mqc = t1->mqc; /* MQC component */ opj_mqc_t *mqc = &(t1->mqc); /* MQC component */
const OPJ_UINT32 check = (T1_SIGMA_4 | T1_SIGMA_7 | T1_SIGMA_10 | T1_SIGMA_13 | const OPJ_UINT32 check = (T1_SIGMA_4 | T1_SIGMA_7 | T1_SIGMA_10 | T1_SIGMA_13 |
T1_PI_0 | T1_PI_1 | T1_PI_2 | T1_PI_3); T1_PI_0 | T1_PI_1 | T1_PI_2 | T1_PI_3);
@ -1304,7 +1304,7 @@ static void opj_t1_dec_clnpass_step_partial(
OPJ_UINT32 ci) OPJ_UINT32 ci)
{ {
OPJ_UINT32 v; OPJ_UINT32 v;
opj_mqc_t *mqc = t1->mqc; /* MQC component */ opj_mqc_t *mqc = &(t1->mqc); /* MQC component */
OPJ_UINT32 lu = opj_t1_getctxtno_sc_or_spb_index( OPJ_UINT32 lu = opj_t1_getctxtno_sc_or_spb_index(
*flagsp, flagsp[-1], flagsp[1], *flagsp, flagsp[-1], flagsp[1],
@ -1325,7 +1325,7 @@ static void opj_t1_dec_clnpass_step(
{ {
OPJ_UINT32 v; OPJ_UINT32 v;
opj_mqc_t *mqc = t1->mqc; /* MQC component */ opj_mqc_t *mqc = &(t1->mqc); /* MQC component */
if (!(*flagsp & ((T1_SIGMA_THIS | T1_PI_THIS) << (ci * 3U)))) { if (!(*flagsp & ((T1_SIGMA_THIS | T1_PI_THIS) << (ci * 3U)))) {
OPJ_UINT32 ctxt1 = opj_t1_getctxno_zc(mqc, *flagsp >> (ci * 3U)); OPJ_UINT32 ctxt1 = opj_t1_getctxno_zc(mqc, *flagsp >> (ci * 3U));
opj_mqc_setcurctx(mqc, ctxt1); opj_mqc_setcurctx(mqc, ctxt1);
@ -1352,7 +1352,7 @@ static void opj_t1_dec_clnpass_step_only_if_flag_not_sig_visit(
{ {
OPJ_UINT32 v; OPJ_UINT32 v;
opj_mqc_t *mqc = t1->mqc; /* MQC component */ opj_mqc_t *mqc = &(t1->mqc); /* MQC component */
OPJ_UINT32 ctxt1 = opj_t1_getctxno_zc(mqc, *flagsp >> (ci * 3U)); OPJ_UINT32 ctxt1 = opj_t1_getctxno_zc(mqc, *flagsp >> (ci * 3U));
opj_mqc_setcurctx(mqc, ctxt1); opj_mqc_setcurctx(mqc, ctxt1);
@ -1378,7 +1378,7 @@ static void opj_t1_dec_clnpass_step_vsc(
{ {
OPJ_UINT32 v; OPJ_UINT32 v;
opj_mqc_t *mqc = t1->mqc; /* MQC component */ opj_mqc_t *mqc = &(t1->mqc); /* MQC component */
OPJ_UINT32 vsc_mask = vsc ? ~((T1_SIGMA_SW | T1_SIGMA_S | T1_SIGMA_SE | OPJ_UINT32 vsc_mask = vsc ? ~((T1_SIGMA_SW | T1_SIGMA_S | T1_SIGMA_SE |
T1_CHI_S) << T1_CHI_S) <<
@ -1416,7 +1416,7 @@ static void opj_t1_enc_clnpass(
const OPJ_INT32 one = 1 << (bpno + T1_NMSEDEC_FRACBITS); const OPJ_INT32 one = 1 << (bpno + T1_NMSEDEC_FRACBITS);
OPJ_UINT32 agg, runlen; OPJ_UINT32 agg, runlen;
opj_mqc_t *mqc = t1->mqc; /* MQC component */ opj_mqc_t *mqc = &(t1->mqc); /* MQC component */
const OPJ_UINT32 agg_mask = (cblksty & J2K_CCP_CBLKSTY_VSC) ? const OPJ_UINT32 agg_mask = (cblksty & J2K_CCP_CBLKSTY_VSC) ?
~(T1_SIGMA_15 | T1_SIGMA_16 | T1_SIGMA_17 | T1_CHI_5) : ~(T1_SIGMA_15 | T1_SIGMA_16 | T1_SIGMA_17 | T1_CHI_5) :
@ -1501,7 +1501,7 @@ static void opj_t1_enc_clnpass(
OPJ_UINT32 i, j, k; \ OPJ_UINT32 i, j, k; \
OPJ_INT32 segsym = cblksty & J2K_CCP_CBLKSTY_SEGSYM; \ OPJ_INT32 segsym = cblksty & J2K_CCP_CBLKSTY_SEGSYM; \
\ \
opj_mqc_t *mqc = t1->mqc; /* MQC component */ \ opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ \
\ \
one = 1 << bpno; \ one = 1 << bpno; \
half = one >> 1; \ half = one >> 1; \
@ -1820,18 +1820,6 @@ opj_t1_t* opj_t1_create(OPJ_BOOL isEncoder)
return 00; return 00;
} }
/* create MQC and RAW handles */
l_t1->mqc = opj_mqc_create();
if (! l_t1->mqc) {
opj_t1_destroy(l_t1);
return 00;
}
l_t1->raw = opj_raw_create();
if (! l_t1->raw) {
opj_t1_destroy(l_t1);
return 00;
}
l_t1->encoder = isEncoder; l_t1->encoder = isEncoder;
return l_t1; return l_t1;
@ -1849,12 +1837,6 @@ void opj_t1_destroy(opj_t1_t *p_t1)
return; return;
} }
/* destroy MQC and RAW handles */
opj_mqc_destroy(p_t1->mqc);
p_t1->mqc = 00;
opj_raw_destroy(p_t1->raw);
p_t1->raw = 00;
/* encoder uses tile buffer, so no need to free */ /* encoder uses tile buffer, so no need to free */
if (!p_t1->encoder && p_t1->data) { if (!p_t1->encoder && p_t1->data) {
opj_aligned_free(p_t1->data); opj_aligned_free(p_t1->data);
@ -2047,8 +2029,8 @@ static OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1,
OPJ_UINT32 roishift, OPJ_UINT32 roishift,
OPJ_UINT32 cblksty) OPJ_UINT32 cblksty)
{ {
opj_raw_t *raw = t1->raw; /* RAW component */ opj_raw_t *raw = &(t1->raw); /* RAW component */
opj_mqc_t *mqc = t1->mqc; /* MQC component */ opj_mqc_t *mqc = &(t1->mqc); /* MQC component */
OPJ_INT32 bpno_plus_one; OPJ_INT32 bpno_plus_one;
OPJ_UINT32 passtype; OPJ_UINT32 passtype;
@ -2301,7 +2283,7 @@ static void opj_t1_encode_cblk(opj_t1_t *t1,
{ {
OPJ_FLOAT64 cumwmsedec = 0.0; OPJ_FLOAT64 cumwmsedec = 0.0;
opj_mqc_t *mqc = t1->mqc; /* MQC component */ opj_mqc_t *mqc = &(t1->mqc); /* MQC component */
OPJ_UINT32 passno; OPJ_UINT32 passno;
OPJ_INT32 bpno; OPJ_INT32 bpno;

View File

@ -183,9 +183,9 @@ Tier-1 coding (coding of code-block coefficients)
typedef struct opj_t1 { typedef struct opj_t1 {
/** MQC component */ /** MQC component */
opj_mqc_t *mqc; opj_mqc_t mqc;
/** RAW component */ /** RAW component */
opj_raw_t *raw; opj_raw_t raw;
OPJ_INT32 *data; OPJ_INT32 *data;
/** Flags used by decoder and encoder. /** Flags used by decoder and encoder.