Irreversible decoding: align code more closely to the standard by avoid messing up with stepsize (no functional change)

This commit is contained in:
Even Rouault 2020-05-20 13:14:16 +02:00
parent e46e300de5
commit f38c069547
No known key found for this signature in database
GPG Key ID: 33EBBFC47B3DD87D
2 changed files with 10 additions and 8 deletions

View File

@ -1725,10 +1725,11 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls)
datap[i] /= 2; datap[i] /= 2;
} }
} else { /* if (tccp->qmfbid == 0) */ } else { /* if (tccp->qmfbid == 0) */
const float stepsize = 0.5f * band->stepsize;
i = 0; i = 0;
#ifdef __SSE2__ #ifdef __SSE2__
{ {
const __m128 xmm_stepsize = _mm_set1_ps(band->stepsize); const __m128 xmm_stepsize = _mm_set1_ps(stepsize);
for (; i < (cblk_size & ~15U); i += 16) { for (; i < (cblk_size & ~15U); i += 16) {
__m128 xmm0_data = _mm_cvtepi32_ps(_mm_load_si128((__m128i * const)( __m128 xmm0_data = _mm_cvtepi32_ps(_mm_load_si128((__m128i * const)(
datap + 0))); datap + 0)));
@ -1747,7 +1748,7 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls)
} }
#endif #endif
for (; i < cblk_size; ++i) { for (; i < cblk_size; ++i) {
OPJ_FLOAT32 tmp = ((OPJ_FLOAT32)(*datap)) * band->stepsize; OPJ_FLOAT32 tmp = ((OPJ_FLOAT32)(*datap)) * stepsize;
memcpy(datap, &tmp, sizeof(tmp)); memcpy(datap, &tmp, sizeof(tmp));
datap++; datap++;
} }
@ -1773,12 +1774,13 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls)
} }
} }
} else { /* if (tccp->qmfbid == 0) */ } else { /* if (tccp->qmfbid == 0) */
const float stepsize = 0.5f * band->stepsize;
OPJ_FLOAT32* OPJ_RESTRICT tiledp = (OPJ_FLOAT32*) &tilec->data[(OPJ_SIZE_T)y * OPJ_FLOAT32* OPJ_RESTRICT tiledp = (OPJ_FLOAT32*) &tilec->data[(OPJ_SIZE_T)y *
tile_w + (OPJ_SIZE_T)x]; tile_w + (OPJ_SIZE_T)x];
for (j = 0; j < cblk_h; ++j) { for (j = 0; j < cblk_h; ++j) {
OPJ_FLOAT32* OPJ_RESTRICT tiledp2 = tiledp; OPJ_FLOAT32* OPJ_RESTRICT tiledp2 = tiledp;
for (i = 0; i < cblk_w; ++i) { for (i = 0; i < cblk_w; ++i) {
OPJ_FLOAT32 tmp = (OPJ_FLOAT32) * datap * band->stepsize; OPJ_FLOAT32 tmp = (OPJ_FLOAT32) * datap * stepsize;
*tiledp2 = tmp; *tiledp2 = tmp;
datap++; datap++;
tiledp2++; tiledp2++;

View File

@ -112,7 +112,7 @@ void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t * img)
* Initializes tile coding/decoding * Initializes tile coding/decoding
*/ */
static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
OPJ_BOOL isEncoder, OPJ_FLOAT32 fraction, OPJ_SIZE_T sizeof_block, OPJ_BOOL isEncoder, OPJ_SIZE_T sizeof_block,
opj_event_mgr_t* manager); opj_event_mgr_t* manager);
/** /**
@ -721,7 +721,7 @@ OPJ_BOOL opj_alloc_tile_component_data(opj_tcd_tilecomp_t *l_tilec)
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
OPJ_BOOL isEncoder, OPJ_FLOAT32 fraction, OPJ_SIZE_T sizeof_block, OPJ_BOOL isEncoder, OPJ_SIZE_T sizeof_block,
opj_event_mgr_t* manager) opj_event_mgr_t* manager)
{ {
OPJ_UINT32(*l_gain_ptr)(OPJ_UINT32) = 00; OPJ_UINT32(*l_gain_ptr)(OPJ_UINT32) = 00;
@ -1013,7 +1013,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
/* Delta_b value of Equation E-3 in "E.1 Inverse quantization /* Delta_b value of Equation E-3 in "E.1 Inverse quantization
* procedure" of the standard */ * procedure" of the standard */
l_band->stepsize = (OPJ_FLOAT32)(((1.0 + l_step_size->mant / 2048.0) * pow(2.0, l_band->stepsize = (OPJ_FLOAT32)(((1.0 + l_step_size->mant / 2048.0) * pow(2.0,
(OPJ_INT32)(numbps - l_step_size->expn)))) * fraction; (OPJ_INT32)(numbps - l_step_size->expn))));
/* Mb value of Equation E-2 in "E.1 Inverse quantization /* Mb value of Equation E-2 in "E.1 Inverse quantization
* procedure" of the standard */ * procedure" of the standard */
l_band->numbps = l_step_size->expn + (OPJ_INT32)l_tccp->numgbits - l_band->numbps = l_step_size->expn + (OPJ_INT32)l_tccp->numgbits -
@ -1196,14 +1196,14 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
OPJ_BOOL opj_tcd_init_encode_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, OPJ_BOOL opj_tcd_init_encode_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
opj_event_mgr_t* p_manager) opj_event_mgr_t* p_manager)
{ {
return opj_tcd_init_tile(p_tcd, p_tile_no, OPJ_TRUE, 1.0F, return opj_tcd_init_tile(p_tcd, p_tile_no, OPJ_TRUE,
sizeof(opj_tcd_cblk_enc_t), p_manager); sizeof(opj_tcd_cblk_enc_t), p_manager);
} }
OPJ_BOOL opj_tcd_init_decode_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, OPJ_BOOL opj_tcd_init_decode_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
opj_event_mgr_t* p_manager) opj_event_mgr_t* p_manager)
{ {
return opj_tcd_init_tile(p_tcd, p_tile_no, OPJ_FALSE, 0.5F, return opj_tcd_init_tile(p_tcd, p_tile_no, OPJ_FALSE,
sizeof(opj_tcd_cblk_dec_t), p_manager); sizeof(opj_tcd_cblk_dec_t), p_manager);
} }