Remove TODO for overflow check (#842)

The check was already done. It’s been simplified.
Reformat to get consistent style throughout the functions.
This commit is contained in:
Matthieu Darbois 2016-09-15 23:51:34 +02:00 committed by GitHub
parent 9a07ccb3d0
commit 6e7616c83c
1 changed files with 119 additions and 105 deletions

View File

@ -627,7 +627,8 @@ static void opj_dwt_decode_v_func(void* user_data, opj_tls_t* tls)
/* <summary> */ /* <summary> */
/* Inverse wavelet transform in 2-D. */ /* Inverse wavelet transform in 2-D. */
/* </summary> */ /* </summary> */
static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres, DWT1DFN dwt_1D) { static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres, DWT1DFN dwt_1D)
{
opj_dwt_t h; opj_dwt_t h;
opj_dwt_t v; opj_dwt_t v;
@ -673,7 +674,7 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, opj_tcd_tilecomp_t* t
h.dn = (OPJ_INT32)(rw - (OPJ_UINT32)h.sn); h.dn = (OPJ_INT32)(rw - (OPJ_UINT32)h.sn);
h.cas = tr->x0 % 2; h.cas = tr->x0 % 2;
if( num_threads <= 1 || rh == 1 ) if( num_threads <= 1 || rh <= 1 )
{ {
for(j = 0; j < rh; ++j) { for(j = 0; j < rh; ++j) {
opj_dwt_interleave_h(&h, &tiledp[j*w]); opj_dwt_interleave_h(&h, &tiledp[j*w]);
@ -684,9 +685,13 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, opj_tcd_tilecomp_t* t
else else
{ {
OPJ_UINT32 num_jobs = (OPJ_UINT32)num_threads; OPJ_UINT32 num_jobs = (OPJ_UINT32)num_threads;
OPJ_UINT32 step_j;
if( rh < num_jobs ) { if( rh < num_jobs ) {
num_jobs = rh; num_jobs = rh;
} }
step_j = (rh / num_jobs);
for(j = 0; j < num_jobs; j++) for(j = 0; j < num_jobs; j++)
{ {
opj_dwd_decode_h_job_t* job; opj_dwd_decode_h_job_t* job;
@ -707,10 +712,11 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, opj_tcd_tilecomp_t* t
job->rw = rw; job->rw = rw;
job->w = w; job->w = w;
job->tiledp = tiledp; job->tiledp = tiledp;
job->min_j = j * (rh / num_jobs); job->min_j = j * step_j;
job->max_j = (j+1) * (rh / num_jobs); /* TODO this can overflow */ job->max_j = (j + 1U) * step_j; /* this can overflow */
if( job->max_j > rh || j == num_jobs - 1 ) if( j == (num_jobs - 1U) ) { /* this will take care of the overflow */
job->max_j = rh; job->max_j = rh;
}
job->h.mem = (OPJ_INT32*)opj_aligned_malloc(h_mem_size); job->h.mem = (OPJ_INT32*)opj_aligned_malloc(h_mem_size);
if (!job->h.mem) if (!job->h.mem)
{ {
@ -728,10 +734,11 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, opj_tcd_tilecomp_t* t
v.dn = (OPJ_INT32)(rh - (OPJ_UINT32)v.sn); v.dn = (OPJ_INT32)(rh - (OPJ_UINT32)v.sn);
v.cas = tr->y0 % 2; v.cas = tr->y0 % 2;
if( num_threads <= 1 || rw == 1 ) if( num_threads <= 1 || rw <= 1 )
{ {
for(j = 0; j < rw; ++j){ for(j = 0; j < rw; ++j){
OPJ_UINT32 k; OPJ_UINT32 k;
opj_dwt_interleave_v(&v, &tiledp[j], (OPJ_INT32)w); opj_dwt_interleave_v(&v, &tiledp[j], (OPJ_INT32)w);
(dwt_1D)(&v); (dwt_1D)(&v);
for(k = 0; k < rh; ++k) { for(k = 0; k < rh; ++k) {
@ -742,8 +749,13 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, opj_tcd_tilecomp_t* t
else else
{ {
OPJ_UINT32 num_jobs = (OPJ_UINT32)num_threads; OPJ_UINT32 num_jobs = (OPJ_UINT32)num_threads;
if( rw < num_jobs ) OPJ_UINT32 step_j;
if( rw < num_jobs ) {
num_jobs = rw; num_jobs = rw;
}
step_j = (rw / num_jobs);
for( j = 0; j < num_jobs; j++ ) for( j = 0; j < num_jobs; j++ )
{ {
opj_dwd_decode_v_job_t* job; opj_dwd_decode_v_job_t* job;
@ -764,10 +776,11 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, opj_tcd_tilecomp_t* t
job->rh = rh; job->rh = rh;
job->w = w; job->w = w;
job->tiledp = tiledp; job->tiledp = tiledp;
job->min_j = j * (rw / num_jobs); job->min_j = j * step_j;
job->max_j = (j+1) * (rw / num_jobs); /* TODO this can overflow */ job->max_j = (j + 1U) * step_j; /* this can overflow */
if( job->max_j > rw || j == num_jobs - 1 ) if( j == (num_jobs - 1U) ) { /* this will take care of the overflow */
job->max_j = rw; job->max_j = rw;
}
job->v.mem = (OPJ_INT32*)opj_aligned_malloc(h_mem_size); job->v.mem = (OPJ_INT32*)opj_aligned_malloc(h_mem_size);
if (!job->v.mem) if (!job->v.mem)
{ {
@ -786,7 +799,8 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, opj_tcd_tilecomp_t* t
return OPJ_TRUE; return OPJ_TRUE;
} }
static void opj_v4dwt_interleave_h(opj_v4dwt_t* OPJ_RESTRICT w, OPJ_FLOAT32* OPJ_RESTRICT a, OPJ_INT32 x, OPJ_INT32 size){ static void opj_v4dwt_interleave_h(opj_v4dwt_t* OPJ_RESTRICT w, OPJ_FLOAT32* OPJ_RESTRICT a, OPJ_INT32 x, OPJ_INT32 size)
{
OPJ_FLOAT32* OPJ_RESTRICT bi = (OPJ_FLOAT32*) (w->wavelet + w->cas); OPJ_FLOAT32* OPJ_RESTRICT bi = (OPJ_FLOAT32*) (w->wavelet + w->cas);
OPJ_INT32 count = w->sn; OPJ_INT32 count = w->sn;
OPJ_INT32 i, k; OPJ_INT32 i, k;