diff --git a/src/bin/jp2/opj_decompress.c b/src/bin/jp2/opj_decompress.c index 57fe554b..83160c3d 100644 --- a/src/bin/jp2/opj_decompress.c +++ b/src/bin/jp2/opj_decompress.c @@ -911,7 +911,7 @@ OPJ_FLOAT64 opj_clock(void) { #elif defined(__linux) struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); - return( ts.tv_sec + ts.tv_nsec * 1e-9 ); + return( (OPJ_FLOAT64)ts.tv_sec + (OPJ_FLOAT64)ts.tv_nsec * 1e-9 ); #else /* Unix : use resource usage */ /* FIXME: this counts the total CPU time, instead of the user perceived time */ diff --git a/src/lib/openjp2/dwt.c b/src/lib/openjp2/dwt.c index 2e28effc..2d793bb6 100644 --- a/src/lib/openjp2/dwt.c +++ b/src/lib/openjp2/dwt.c @@ -563,13 +563,13 @@ typedef struct OPJ_UINT32 rw; OPJ_UINT32 w; OPJ_INT32 * OPJ_RESTRICT tiledp; - int min_j; - int max_j; + OPJ_UINT32 min_j; + OPJ_UINT32 max_j; } opj_dwd_decode_h_job_t; static void opj_dwt_decode_h_func(void* user_data, opj_tls_t* tls) { - int j; + OPJ_UINT32 j; opj_dwd_decode_h_job_t* job; (void)tls; @@ -592,13 +592,13 @@ typedef struct OPJ_UINT32 rh; OPJ_UINT32 w; OPJ_INT32 * OPJ_RESTRICT tiledp; - int min_j; - int max_j; + OPJ_UINT32 min_j; + OPJ_UINT32 max_j; } opj_dwd_decode_v_job_t; static void opj_dwt_decode_v_func(void* user_data, opj_tls_t* tls) { - int j; + OPJ_UINT32 j; opj_dwd_decode_v_job_t* job; (void)tls; @@ -631,8 +631,8 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, opj_tcd_tilecomp_t* t OPJ_UINT32 rh = (OPJ_UINT32)(tr->y1 - tr->y0); /* height of the resolution level computed */ OPJ_UINT32 w = (OPJ_UINT32)(tilec->x1 - tilec->x0); - size_t h_mem_size; - int num_threads; + size_t h_mem_size; + int num_threads; if (numres == 1U) { return OPJ_TRUE; @@ -671,9 +671,10 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, opj_tcd_tilecomp_t* t } else { - int num_jobs = num_threads; - if( rh < num_jobs ) + OPJ_UINT32 num_jobs = (OPJ_UINT32)num_threads; + if( rh < num_jobs ) { num_jobs = rh; + } for( j = 0; j < num_jobs; j++ ) { opj_dwd_decode_h_job_t* job; @@ -695,7 +696,7 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, opj_tcd_tilecomp_t* t job->w = w; job->tiledp = tiledp; job->min_j = j * (rh / num_jobs); - job->max_j = (j+1) * (rh / num_jobs); + job->max_j = (j+1) * (rh / num_jobs); /* TODO this can overflow */ if( job->max_j > rh || j == num_jobs - 1 ) job->max_j = rh; job->h.mem = (OPJ_INT32*)opj_aligned_malloc(h_mem_size); @@ -728,7 +729,7 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, opj_tcd_tilecomp_t* t } else { - int num_jobs = num_threads; + OPJ_UINT32 num_jobs = (OPJ_UINT32)num_threads; if( rw < num_jobs ) num_jobs = rw; for( j = 0; j < num_jobs; j++ ) @@ -752,7 +753,7 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, opj_tcd_tilecomp_t* t job->w = w; job->tiledp = tiledp; job->min_j = j * (rw / num_jobs); - job->max_j = (j+1) * (rw / num_jobs); + job->max_j = (j+1) * (rw / num_jobs); /* TODO this can overflow */ if( job->max_j > rw || j == num_jobs - 1 ) job->max_j = rw; job->v.mem = (OPJ_INT32*)opj_aligned_malloc(h_mem_size); diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index bdacbe91..66802bb9 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -5953,8 +5953,11 @@ OPJ_BOOL opj_j2k_set_threads(opj_j2k_t *j2k, OPJ_UINT32 num_threads) if( opj_has_thread_support() ) { opj_thread_pool_destroy(j2k->m_tp); - j2k->m_tp = opj_thread_pool_create((int)num_threads); - if( j2k->m_tp == 0 ) + j2k->m_tp = NULL; + if (num_threads <= (OPJ_UINT32)INT_MAX ) { + j2k->m_tp = opj_thread_pool_create((int)num_threads); + } + if( j2k->m_tp == NULL ) { j2k->m_tp = opj_thread_pool_create(0); return OPJ_FALSE; diff --git a/src/lib/openjp2/openjpeg.c b/src/lib/openjp2/openjpeg.c index ee3e14b6..4d12540e 100644 --- a/src/lib/openjp2/openjpeg.c +++ b/src/lib/openjp2/openjpeg.c @@ -361,15 +361,15 @@ void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *paramete } -OPJ_API OPJ_CALLCONV opj_codec_set_threads(opj_codec_t *p_codec, +OPJ_BOOL OPJ_CALLCONV opj_codec_set_threads(opj_codec_t *p_codec, int num_threads) { - if (p_codec ) { - opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; + if (p_codec && (num_threads >= 0)) { + opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; - return l_codec->opj_set_threads(l_codec->m_codec, num_threads); - } - return OPJ_FALSE; + return l_codec->opj_set_threads(l_codec->m_codec, (OPJ_UINT32)num_threads); + } + return OPJ_FALSE; } OPJ_BOOL OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec, diff --git a/src/lib/openjp2/opj_includes.h b/src/lib/openjp2/opj_includes.h index 3576877c..e3de42da 100644 --- a/src/lib/openjp2/opj_includes.h +++ b/src/lib/openjp2/opj_includes.h @@ -54,6 +54,7 @@ #include #include #include +#include /* Use fseeko() and ftello() if they are available since they use diff --git a/src/lib/openjp2/t1.c b/src/lib/openjp2/t1.c index 66884e3b..1b722c9e 100644 --- a/src/lib/openjp2/t1.c +++ b/src/lib/openjp2/t1.c @@ -86,15 +86,15 @@ static INLINE void opj_t1_dec_sigpass_step_raw( OPJ_INT32 *datap, OPJ_INT32 oneplushalf, OPJ_INT32 vsc, - OPJ_INT32 row); + OPJ_UINT32 row); static INLINE void opj_t1_dec_sigpass_step_mqc( opj_t1_t *t1, opj_flag_t *flagsp, opj_colflag_t* colflagsp, OPJ_INT32 *datap, OPJ_INT32 oneplushalf, - OPJ_INT32 row, - OPJ_INT32 flags_stride); + OPJ_UINT32 row, + OPJ_UINT32 flags_stride); static INLINE void opj_t1_dec_sigpass_step_mqc_vsc( opj_t1_t *t1, opj_flag_t *flagsp, @@ -102,7 +102,7 @@ static INLINE void opj_t1_dec_sigpass_step_mqc_vsc( OPJ_INT32 *datap, OPJ_INT32 oneplushalf, OPJ_INT32 vsc, - OPJ_INT32 row); + OPJ_UINT32 row); /** @@ -154,8 +154,7 @@ Decode refinement pass */ static void opj_t1_dec_refpass_raw( opj_t1_t *t1, - OPJ_INT32 bpno, - OPJ_INT32 cblksty); + OPJ_INT32 bpno); static void opj_t1_dec_refpass_mqc_vsc( opj_t1_t *t1, OPJ_INT32 bpno); @@ -176,12 +175,11 @@ static void opj_t1_dec_refpass_step(opj_t1_t *t1, static INLINE void opj_t1_dec_refpass_step_raw( opj_t1_t *t1, - opj_flag_t *flagsp, opj_colflag_t *colflagsp, OPJ_INT32 *datap, OPJ_INT32 poshalf, OPJ_INT32 neghalf, - OPJ_INT32 row); + OPJ_UINT32 row); static INLINE void opj_t1_dec_refpass_step_mqc( opj_t1_t *t1, opj_flag_t *flagsp, @@ -189,7 +187,7 @@ static INLINE void opj_t1_dec_refpass_step_mqc( OPJ_INT32 *datap, OPJ_INT32 poshalf, OPJ_INT32 neghalf, - OPJ_INT32 row); + OPJ_UINT32 row); static INLINE void opj_t1_dec_refpass_step_mqc_vsc( opj_t1_t *t1, opj_flag_t *flagsp, @@ -198,7 +196,7 @@ static INLINE void opj_t1_dec_refpass_step_mqc_vsc( OPJ_INT32 poshalf, OPJ_INT32 neghalf, OPJ_INT32 vsc, - OPJ_INT32 row); + OPJ_UINT32 row); @@ -223,14 +221,14 @@ static void opj_t1_dec_clnpass_step_partial( opj_colflag_t *colflagsp, OPJ_INT32 *datap, OPJ_INT32 oneplushalf, - OPJ_INT32 row); + OPJ_UINT32 row); static void opj_t1_dec_clnpass_step( opj_t1_t *t1, opj_flag_t *flagsp, opj_colflag_t *colflagsp, OPJ_INT32 *datap, OPJ_INT32 oneplushalf, - OPJ_INT32 row); + OPJ_UINT32 row); static void opj_t1_dec_clnpass_step_vsc( opj_t1_t *t1, opj_flag_t *flagsp, @@ -239,7 +237,7 @@ static void opj_t1_dec_clnpass_step_vsc( OPJ_INT32 oneplushalf, OPJ_INT32 partial, OPJ_INT32 vsc, - OPJ_INT32 row); + OPJ_UINT32 row); /** Encode clean-up pass */ @@ -248,13 +246,6 @@ static void opj_t1_enc_clnpass( OPJ_INT32 bpno, OPJ_INT32 *nmsedec, OPJ_UINT32 cblksty); -/** -Decode clean-up pass -*/ -static void opj_t1_dec_clnpass( - opj_t1_t *t1, - OPJ_INT32 bpno, - OPJ_INT32 cblksty); static OPJ_FLOAT64 opj_t1_getwmsedec( OPJ_INT32 nmsedec, @@ -362,10 +353,10 @@ static INLINE void opj_t1_updateflags(opj_flag_t *flagsp, OPJ_UINT32 s, OPJ_UINT sp[1] |= T1_SIG_NW; } -static INLINE void opj_t1_updateflagscolflags(opj_flag_t *flagsp, opj_colflag_t *colflagsp, OPJ_UINT32 s, OPJ_UINT32 stride, OPJ_INT32 row) +static INLINE void opj_t1_updateflagscolflags(opj_flag_t *flagsp, opj_colflag_t *colflagsp, OPJ_UINT32 s, OPJ_UINT32 stride, OPJ_UINT32 row) { opj_t1_updateflags(flagsp, s, stride); - if( row == 0 ) + if( row == 0U ) { *colflagsp |= (T1_COLFLAG_SIG_ROW_0 << (T1_COLFLAG_RBS * row)) | (T1_COLFLAG_SIG_OTHER_ROW_0 << (T1_COLFLAG_RBS * (row+1))); @@ -377,7 +368,7 @@ static INLINE void opj_t1_updateflagscolflags(opj_flag_t *flagsp, opj_colflag_t *(colflagsp - stride) |= (T1_COLFLAG_SIG_OTHER_ROW_3); *(colflagsp - stride + 1) |= (T1_COLFLAG_SIG_OTHER_ROW_3); } - else if( row == 3 ) + else if( row == 3U ) { *colflagsp |= (T1_COLFLAG_SIG_ROW_0 << (T1_COLFLAG_RBS * row)) | (T1_COLFLAG_SIG_OTHER_ROW_0 << (T1_COLFLAG_RBS * (row-1))); @@ -450,7 +441,7 @@ static INLINE void opj_t1_dec_sigpass_step_raw( OPJ_INT32 *datap, OPJ_INT32 oneplushalf, OPJ_INT32 vsc, - OPJ_INT32 row) + OPJ_UINT32 row) { OPJ_INT32 v, flag; opj_raw_t *raw = t1->raw; /* RAW component */ @@ -475,8 +466,8 @@ static INLINE void opj_t1_dec_sigpass_step_mqc( opj_colflag_t* colflagsp, OPJ_INT32 *datap, OPJ_INT32 oneplushalf, - OPJ_INT32 row, - OPJ_INT32 flags_stride) + OPJ_UINT32 row, + OPJ_UINT32 flags_stride) { OPJ_INT32 v, flag; @@ -510,7 +501,7 @@ static INLINE void opj_t1_dec_sigpass_step_mqc_vsc( OPJ_INT32 *datap, OPJ_INT32 oneplushalf, OPJ_INT32 vsc, - OPJ_INT32 row) + OPJ_UINT32 row) { OPJ_INT32 v, flag; @@ -611,16 +602,16 @@ static void opj_t1_dec_sigpass_raw( opj_colflag_t *colflags2 = colflags1 + i; \ if( *colflags2 == 0 ) continue; \ flags2 += flags_stride; \ - opj_t1_dec_sigpass_step_mqc(t1, flags2, colflags2, data2, oneplushalf, 0, flags_stride); \ + opj_t1_dec_sigpass_step_mqc(t1, flags2, colflags2, data2, oneplushalf, 0U, flags_stride); \ data2 += w; \ flags2 += flags_stride; \ - opj_t1_dec_sigpass_step_mqc(t1, flags2, colflags2, data2, oneplushalf, 1, flags_stride); \ + opj_t1_dec_sigpass_step_mqc(t1, flags2, colflags2, data2, oneplushalf, 1U, flags_stride); \ data2 += w; \ flags2 += flags_stride; \ - opj_t1_dec_sigpass_step_mqc(t1, flags2, colflags2, data2, oneplushalf, 2, flags_stride); \ + opj_t1_dec_sigpass_step_mqc(t1, flags2, colflags2, data2, oneplushalf, 2U, flags_stride); \ data2 += w; \ flags2 += flags_stride; \ - opj_t1_dec_sigpass_step_mqc(t1, flags2, colflags2, data2, oneplushalf, 3, flags_stride); \ + opj_t1_dec_sigpass_step_mqc(t1, flags2, colflags2, data2, oneplushalf, 3U, flags_stride); \ data2 += w; \ } \ data1 += w << 2; \ @@ -666,22 +657,22 @@ static void opj_t1_dec_sigpass_mqc_vsc( one = 1 << bpno; half = one >> 1; oneplushalf = one | half; - for (k = 0; k < (t1->h & ~3); k += 4) { + for (k = 0; k < (t1->h & ~(OPJ_UINT32)3); k += 4U) { for (i = 0; i < t1->w; ++i) { OPJ_INT32 *data2 = data1 + i; opj_flag_t *flags2 = flags1 + i; opj_colflag_t *colflags2 = colflags1 + i; flags2 += t1->flags_stride; - opj_t1_dec_sigpass_step_mqc_vsc(t1, flags2, colflags2, data2, oneplushalf, 0, 0); + opj_t1_dec_sigpass_step_mqc_vsc(t1, flags2, colflags2, data2, oneplushalf, 0, 0U); data2 += t1->w; flags2 += t1->flags_stride; - opj_t1_dec_sigpass_step_mqc_vsc(t1, flags2, colflags2, data2, oneplushalf, 0, 1); + opj_t1_dec_sigpass_step_mqc_vsc(t1, flags2, colflags2, data2, oneplushalf, 0, 1U); data2 += t1->w; flags2 += t1->flags_stride; - opj_t1_dec_sigpass_step_mqc_vsc(t1, flags2, colflags2, data2, oneplushalf, 0, 2); + opj_t1_dec_sigpass_step_mqc_vsc(t1, flags2, colflags2, data2, oneplushalf, 0, 2U); data2 += t1->w; flags2 += t1->flags_stride; - opj_t1_dec_sigpass_step_mqc_vsc(t1, flags2, colflags2, data2, oneplushalf, 1, 3); + opj_t1_dec_sigpass_step_mqc_vsc(t1, flags2, colflags2, data2, oneplushalf, 1, 3U); data2 += t1->w; } data1 += t1->w << 2; @@ -736,12 +727,11 @@ static void opj_t1_enc_refpass_step( opj_t1_t *t1, static INLINE void opj_t1_dec_refpass_step_raw( opj_t1_t *t1, - opj_flag_t *flagsp, opj_colflag_t *colflagsp, OPJ_INT32 *datap, OPJ_INT32 poshalf, OPJ_INT32 neghalf, - OPJ_INT32 row) + OPJ_UINT32 row) { OPJ_INT32 v, t; @@ -767,7 +757,7 @@ static INLINE void opj_t1_dec_refpass_step_mqc( OPJ_INT32 *datap, OPJ_INT32 poshalf, OPJ_INT32 neghalf, - OPJ_INT32 row) + OPJ_UINT32 row) { OPJ_INT32 v, t; @@ -775,6 +765,8 @@ static INLINE void opj_t1_dec_refpass_step_mqc( #ifdef CONSISTENCY_CHECK assert( ((*flagsp & (T1_SIG | T1_VISIT)) == T1_SIG) == ((*colflagsp & ((T1_COLFLAG_SIG_ROW_0 | T1_COLFLAG_VISIT_ROW_0) << (T1_COLFLAG_RBS * row))) == ((T1_COLFLAG_SIG_ROW_0) << (T1_COLFLAG_RBS * row))) ); +#else + (void)flagsp_unused; #endif if ((*colflagsp & ((T1_COLFLAG_SIG_ROW_0 | T1_COLFLAG_VISIT_ROW_0) << (T1_COLFLAG_RBS * row))) == ((T1_COLFLAG_SIG_ROW_0) << (T1_COLFLAG_RBS * row))) { @@ -796,9 +788,9 @@ static INLINE void opj_t1_dec_refpass_step_mqc_vsc( OPJ_INT32 poshalf, OPJ_INT32 neghalf, OPJ_INT32 vsc, - OPJ_INT32 row) + OPJ_UINT32 row) { - OPJ_INT32 v, t, flag; + OPJ_INT32 v, t; opj_mqc_t *mqc = t1->mqc; /* MQC component */ @@ -848,12 +840,10 @@ static void opj_t1_enc_refpass( static void opj_t1_dec_refpass_raw( opj_t1_t *t1, - OPJ_INT32 bpno, - OPJ_INT32 cblksty) + OPJ_INT32 bpno) { OPJ_INT32 one, poshalf, neghalf; OPJ_UINT32 i, j, k; - OPJ_INT32 vsc; opj_colflag_t *colflags1 = &t1->colflags[t1->flags_stride + 1]; one = 1 << bpno; poshalf = one >> 1; @@ -864,7 +854,6 @@ static void opj_t1_dec_refpass_raw( for (j = k; j < k + 4 && j < t1->h; ++j) { opj_t1_dec_refpass_step_raw( t1, - &t1->flags[((j+1) * t1->flags_stride) + i + 1], colflags2, &t1->data[(j * t1->w) + i], poshalf, @@ -892,16 +881,16 @@ static void opj_t1_dec_refpass_raw( opj_colflag_t *colflags2 = colflags1 + i; \ if( *colflags2 == 0 ) continue; \ flags2 += flags_stride; \ - opj_t1_dec_refpass_step_mqc(t1, flags2, colflags2, data2, poshalf, neghalf, 0); \ + opj_t1_dec_refpass_step_mqc(t1, flags2, colflags2, data2, poshalf, neghalf, 0U); \ data2 += w; \ flags2 += flags_stride; \ - opj_t1_dec_refpass_step_mqc(t1, flags2, colflags2, data2, poshalf, neghalf, 1); \ + opj_t1_dec_refpass_step_mqc(t1, flags2, colflags2, data2, poshalf, neghalf, 1U); \ data2 += w; \ flags2 += flags_stride; \ - opj_t1_dec_refpass_step_mqc(t1, flags2, colflags2, data2, poshalf, neghalf, 2); \ + opj_t1_dec_refpass_step_mqc(t1, flags2, colflags2, data2, poshalf, neghalf, 2U); \ data2 += w; \ flags2 += flags_stride; \ - opj_t1_dec_refpass_step_mqc(t1, flags2, colflags2, data2, poshalf, neghalf, 3); \ + opj_t1_dec_refpass_step_mqc(t1, flags2, colflags2, data2, poshalf, neghalf, 3U); \ data2 += w; \ } \ data1 += w << 2; \ @@ -948,22 +937,22 @@ static void opj_t1_dec_refpass_mqc_vsc( one = 1 << bpno; poshalf = one >> 1; neghalf = bpno > 0 ? -poshalf : -1; - for (k = 0; k < (t1->h & ~3); k += 4) { + for (k = 0; k < (t1->h & ~(OPJ_UINT32)3U); k += 4U) { for (i = 0; i < t1->w; ++i) { OPJ_INT32 *data2 = data1 + i; opj_flag_t *flags2 = flags1 + i; opj_colflag_t *colflags2 = colflags1 + i; flags2 += t1->flags_stride; - opj_t1_dec_refpass_step_mqc_vsc(t1, flags2, colflags2, data2, poshalf, neghalf, 0, 0); + opj_t1_dec_refpass_step_mqc_vsc(t1, flags2, colflags2, data2, poshalf, neghalf, 0, 0U); data2 += t1->w; flags2 += t1->flags_stride; - opj_t1_dec_refpass_step_mqc_vsc(t1, flags2, colflags2, data2, poshalf, neghalf, 0, 1); + opj_t1_dec_refpass_step_mqc_vsc(t1, flags2, colflags2, data2, poshalf, neghalf, 0, 1U); data2 += t1->w; flags2 += t1->flags_stride; - opj_t1_dec_refpass_step_mqc_vsc(t1, flags2, colflags2, data2, poshalf, neghalf, 0, 2); + opj_t1_dec_refpass_step_mqc_vsc(t1, flags2, colflags2, data2, poshalf, neghalf, 0, 2U); data2 += t1->w; flags2 += t1->flags_stride; - opj_t1_dec_refpass_step_mqc_vsc(t1, flags2, colflags2, data2, poshalf, neghalf, 1, 3); + opj_t1_dec_refpass_step_mqc_vsc(t1, flags2, colflags2, data2, poshalf, neghalf, 1, 3U); data2 += t1->w; } data1 += t1->w << 2; @@ -1028,7 +1017,7 @@ static void opj_t1_dec_clnpass_step_partial( opj_colflag_t *colflagsp, OPJ_INT32 *datap, OPJ_INT32 oneplushalf, - OPJ_INT32 row) + OPJ_UINT32 row) { OPJ_INT32 v, flag; opj_mqc_t *mqc = t1->mqc; /* MQC component */ @@ -1049,7 +1038,7 @@ static void opj_t1_dec_clnpass_step( opj_colflag_t *colflagsp, OPJ_INT32 *datap, OPJ_INT32 oneplushalf, - OPJ_INT32 row) + OPJ_UINT32 row) { OPJ_INT32 v, flag; @@ -1078,8 +1067,8 @@ static void opj_t1_dec_clnpass_step_only_if_flag_not_sig_visit( opj_colflag_t *colflagsp, OPJ_INT32 *datap, OPJ_INT32 oneplushalf, - OPJ_INT32 row, - OPJ_INT32 flags_stride) + OPJ_UINT32 row, + OPJ_UINT32 flags_stride) { OPJ_INT32 v; OPJ_INT32 flag; @@ -1094,7 +1083,7 @@ static void opj_t1_dec_clnpass_step_only_if_flag_not_sig_visit( opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc((OPJ_UINT32)flag)); v = opj_mqc_decode(mqc) ^ opj_t1_getspb((OPJ_UINT32)flag); *datap = v ? -oneplushalf : oneplushalf; - opj_t1_updateflagscolflags(flagsp, colflagsp, v, flags_stride, row); + opj_t1_updateflagscolflags(flagsp, colflagsp, (OPJ_UINT32)v, flags_stride, row); } } /*flagsp &= ~T1_VISIT;*/ @@ -1103,12 +1092,12 @@ static void opj_t1_dec_clnpass_step_only_if_flag_not_sig_visit( static void opj_t1_dec_clnpass_step_vsc( opj_t1_t *t1, opj_flag_t *flagsp, - opj_colflag_t *colflagsp, + opj_colflag_t *colflagsp, OPJ_INT32 *datap, OPJ_INT32 oneplushalf, OPJ_INT32 partial, OPJ_INT32 vsc, - OPJ_INT32 row) + OPJ_UINT32 row) { OPJ_INT32 v, flag; @@ -1125,7 +1114,7 @@ LABEL_PARTIAL: opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc((OPJ_UINT32)flag)); v = opj_mqc_decode(mqc) ^ opj_t1_getspb((OPJ_UINT32)flag); *datap = v ? -oneplushalf : oneplushalf; - opj_t1_updateflagscolflags(flagsp, colflagsp, v, t1->flags_stride, row); + opj_t1_updateflagscolflags(flagsp, colflagsp, (OPJ_UINT32)v, t1->flags_stride, row); } } #ifdef CONSISTENCY_CHECK @@ -1202,7 +1191,7 @@ static void opj_t1_enc_clnpass( #define opj_t1_dec_clnpass_internal(consistency_check, t1, bpno, cblksty, w, h, flags_stride) \ { \ OPJ_INT32 one, half, oneplushalf, agg, runlen, vsc; \ - OPJ_UINT32 i, j, k; \ + OPJ_UINT32 i, j, k; \ OPJ_INT32 segsym = cblksty & J2K_CCP_CBLKSTY_SEGSYM; \ \ opj_mqc_t *mqc = t1->mqc; /* MQC component */ \ @@ -1294,28 +1283,28 @@ static void opj_t1_enc_clnpass( flags2 += flags_stride; \ if( consistency_check ) { assert( (!(colflags & (T1_COLFLAG_SIG_ROW_0 | T1_COLFLAG_VISIT_ROW_0))) == (!(*flags2 & (T1_SIG | T1_VISIT))) ); } \ if (!(colflags & (T1_COLFLAG_SIG_ROW_0 | T1_COLFLAG_VISIT_ROW_0))) {\ - opj_t1_dec_clnpass_step_only_if_flag_not_sig_visit(t1, flags2, colflags2, data2, oneplushalf, 0, flags_stride); \ + opj_t1_dec_clnpass_step_only_if_flag_not_sig_visit(t1, flags2, colflags2, data2, oneplushalf, 0U, flags_stride); \ } \ if( consistency_check ) *flags2 &= ~T1_VISIT; \ data2 += w; \ flags2 += flags_stride; \ if( consistency_check ) { assert( (!(colflags & (T1_COLFLAG_SIG_ROW_1 | T1_COLFLAG_VISIT_ROW_1))) == (!(*flags2 & (T1_SIG | T1_VISIT))) ); } \ if (!(colflags & (T1_COLFLAG_SIG_ROW_1 | T1_COLFLAG_VISIT_ROW_1))) {\ - opj_t1_dec_clnpass_step_only_if_flag_not_sig_visit(t1, flags2, colflags2, data2, oneplushalf, 1, flags_stride); \ + opj_t1_dec_clnpass_step_only_if_flag_not_sig_visit(t1, flags2, colflags2, data2, oneplushalf, 1U, flags_stride); \ } \ if( consistency_check ) *flags2 &= ~T1_VISIT; \ data2 += w; \ flags2 += flags_stride; \ if( consistency_check ) { assert( (!(colflags & (T1_COLFLAG_SIG_ROW_2 | T1_COLFLAG_VISIT_ROW_2))) == (!(*flags2 & (T1_SIG | T1_VISIT))) ); } \ if (!(colflags & (T1_COLFLAG_SIG_ROW_2 | T1_COLFLAG_VISIT_ROW_2))) {\ - opj_t1_dec_clnpass_step_only_if_flag_not_sig_visit(t1, flags2, colflags2, data2, oneplushalf, 2, flags_stride); \ + opj_t1_dec_clnpass_step_only_if_flag_not_sig_visit(t1, flags2, colflags2, data2, oneplushalf, 2U, flags_stride); \ } \ if( consistency_check ) *flags2 &= ~T1_VISIT; \ data2 += w; \ flags2 += flags_stride; \ if( consistency_check ) { assert( (!(colflags & (T1_COLFLAG_SIG_ROW_3 | T1_COLFLAG_VISIT_ROW_3))) == (!(*flags2 & (T1_SIG | T1_VISIT))) ); } \ if (!(colflags & (T1_COLFLAG_SIG_ROW_3 | T1_COLFLAG_VISIT_ROW_3))) {\ - opj_t1_dec_clnpass_step_only_if_flag_not_sig_visit(t1, flags2, colflags2, data2, oneplushalf, 3, flags_stride); \ + opj_t1_dec_clnpass_step_only_if_flag_not_sig_visit(t1, flags2, colflags2, data2, oneplushalf, 3U, flags_stride); \ } \ if( consistency_check ) *flags2 &= ~T1_VISIT; \ data2 += w; \ @@ -1634,19 +1623,19 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls) OPJ_INT32* OPJ_RESTRICT tiledp = &tilec->data[(OPJ_UINT32)y * tile_w + (OPJ_UINT32)x]; for (j = 0; j < cblk_h; ++j) { i = 0; - for (; i < (cblk_w & ~3); i += 4) { - OPJ_INT32 tmp0 = datap[(j * cblk_w) + i]; - OPJ_INT32 tmp1 = datap[(j * cblk_w) + i+1]; - OPJ_INT32 tmp2 = datap[(j * cblk_w) + i+2]; - OPJ_INT32 tmp3 = datap[(j * cblk_w) + i+3]; - ((OPJ_INT32*)tiledp)[(j * tile_w) + i] = tmp0/2; - ((OPJ_INT32*)tiledp)[(j * tile_w) + i+1] = tmp1/2; - ((OPJ_INT32*)tiledp)[(j * tile_w) + i+2] = tmp2/2; - ((OPJ_INT32*)tiledp)[(j * tile_w) + i+3] = tmp3/2; + for (; i < (cblk_w & ~(OPJ_UINT32)3U); i += 4U) { + OPJ_INT32 tmp0 = datap[(j * cblk_w) + i + 0U]; + OPJ_INT32 tmp1 = datap[(j * cblk_w) + i + 1U]; + OPJ_INT32 tmp2 = datap[(j * cblk_w) + i + 2U]; + OPJ_INT32 tmp3 = datap[(j * cblk_w) + i + 3U]; + ((OPJ_INT32*)tiledp)[(j * tile_w) + i + 0U] = tmp0 / 2; + ((OPJ_INT32*)tiledp)[(j * tile_w) + i + 1U] = tmp1 / 2; + ((OPJ_INT32*)tiledp)[(j * tile_w) + i + 2U] = tmp2 / 2; + ((OPJ_INT32*)tiledp)[(j * tile_w) + i + 3U] = tmp3 / 2; } for (; i < cblk_w; ++i) { OPJ_INT32 tmp = datap[(j * cblk_w) + i]; - ((OPJ_INT32*)tiledp)[(j * tile_w) + i] = tmp/2; + ((OPJ_INT32*)tiledp)[(j * tile_w) + i] = tmp / 2; } } } else { /* if (tccp->qmfbid == 0) */ @@ -1778,7 +1767,7 @@ static OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1, break; case 1: if (type == T1_TYPE_RAW) { - opj_t1_dec_refpass_raw(t1, bpno_plus_one, (OPJ_INT32)cblksty); + opj_t1_dec_refpass_raw(t1, bpno_plus_one); } else { if (cblksty & J2K_CCP_CBLKSTY_VSC) { opj_t1_dec_refpass_mqc_vsc(t1, bpno_plus_one); @@ -1821,7 +1810,7 @@ static OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1, break; case 1: if (type == T1_TYPE_RAW) { - opj_t1_dec_refpass_raw(t1, bpno_plus_one, (OPJ_INT32)cblksty); + opj_t1_dec_refpass_raw(t1, bpno_plus_one); } else { if (cblksty & J2K_CCP_CBLKSTY_VSC) { opj_t1_dec_refpass_mqc_vsc(t1, bpno_plus_one); diff --git a/src/lib/openjp2/thread.c b/src/lib/openjp2/thread.c index fce563d0..79a9d5fb 100644 --- a/src/lib/openjp2/thread.c +++ b/src/lib/openjp2/thread.c @@ -314,11 +314,13 @@ struct opj_mutex_t opj_mutex_t* opj_mutex_create(void) { - opj_mutex_t* mutex = (opj_mutex_t*) opj_malloc(sizeof(opj_mutex_t)); - if( !mutex ) - return NULL; - pthread_mutex_t pthr_mutex = PTHREAD_MUTEX_INITIALIZER; - mutex->mutex = pthr_mutex; + opj_mutex_t* mutex = (opj_mutex_t*) opj_calloc(1U, sizeof(opj_mutex_t)); + if( mutex != NULL ) { + if ( pthread_mutex_init(&mutex->mutex, NULL) != 0) { + opj_free(mutex); + mutex = NULL; + } + } return mutex; } @@ -537,19 +539,24 @@ OPJ_BOOL opj_tls_set(opj_tls_t* tls, int key, void* value, opj_tls_free_func opj { opj_tls_key_val_t* new_key_val; int i; + + if (tls->key_val_count == INT_MAX) { + return OPJ_FALSE; + } for(i=0;ikey_val_count;i++) { if( tls->key_val[i].key == key ) { - if( tls->key_val[i].opj_free_func ) + if( tls->key_val[i].opj_free_func ) { tls->key_val[i].opj_free_func(tls->key_val[i].value); + } tls->key_val[i].value = value; tls->key_val[i].opj_free_func = opj_free_func; return OPJ_TRUE; } } new_key_val = (opj_tls_key_val_t*) opj_realloc( tls->key_val, - (tls->key_val_count + 1) * sizeof(opj_tls_key_val_t) ); + ((size_t)tls->key_val_count + 1U) * sizeof(opj_tls_key_val_t) ); if( !new_key_val ) return OPJ_FALSE; tls->key_val = new_key_val; @@ -691,7 +698,7 @@ static OPJ_BOOL opj_thread_pool_setup(opj_thread_pool_t* tp, int num_threads) if( tp->cond == NULL ) return OPJ_FALSE; - tp->worker_threads = (opj_worker_thread_t*) opj_calloc( num_threads, + tp->worker_threads = (opj_worker_thread_t*) opj_calloc( (size_t)num_threads, sizeof(opj_worker_thread_t) ); if( tp->worker_threads == NULL ) return OPJ_FALSE;