Skip to content

Commit

Permalink
Merge branch 'master' into bit-fields-type
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Mühlstrasser committed Sep 7, 2016
2 parents 5487419 + c16bc05 commit 6c83f14
Show file tree
Hide file tree
Showing 57 changed files with 1,834 additions and 1,215 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Ignore files and directories made by `cmake .`.
CMakeFiles/
Makefile
cmake_install.cmake
/CMakeCache.txt
/CPackConfig.cmake
/CPackSourceConfig.cmake
/CTestCustom.cmake
/LICENSE.txt
/OpenJPEGConfig.cmake
/libopenjp2.pc
/src/bin/common/opj_apps_config.h
/src/lib/openjp2/opj_config.h
/src/lib/openjp2/opj_config_private.h

# Ignore directories made by `make`.
/bin/
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ matrix:
- os: linux
compiler: clang
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Debug OPJ_CI_ASAN=1
- os: linux
compiler: clang-3.8
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release
addons:
apt:
sources:
- llvm-toolchain-precise-3.8
- ubuntu-toolchain-r-test
packages:
- clang-3.8
- os: linux
compiler: x86_64-w64-mingw32-gcc
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release
Expand Down
34 changes: 17 additions & 17 deletions src/lib/openjp2/dwt.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,16 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 i, DWT
static OPJ_BOOL opj_dwt_encode_procedure( opj_tcd_tilecomp_t * tilec,
void (*p_function)(OPJ_INT32 *, OPJ_INT32,OPJ_INT32,OPJ_INT32) );

static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_UINT32 i);
static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* OPJ_RESTRICT r, OPJ_UINT32 i);

/* <summary> */
/* Inverse 9-7 wavelet transform in 1-D. */
/* </summary> */
static void opj_v4dwt_decode(opj_v4dwt_t* restrict dwt);
static void opj_v4dwt_decode(opj_v4dwt_t* OPJ_RESTRICT dwt);

static void opj_v4dwt_interleave_h(opj_v4dwt_t* restrict w, OPJ_FLOAT32* 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);

static void opj_v4dwt_interleave_v(opj_v4dwt_t* restrict v , OPJ_FLOAT32* restrict a , OPJ_INT32 x, OPJ_INT32 nb_elts_read);
static void opj_v4dwt_interleave_v(opj_v4dwt_t* OPJ_RESTRICT v , OPJ_FLOAT32* OPJ_RESTRICT a , OPJ_INT32 x, OPJ_INT32 nb_elts_read);

#ifdef __SSE__
static void opj_v4dwt_decode_step1_sse(opj_v4_t* w, OPJ_INT32 count, const __m128 c);
Expand Down Expand Up @@ -543,7 +543,7 @@ void opj_dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, OPJ_UINT32 prec) {
/* <summary> */
/* Determine maximum computed resolution level for inverse wavelet transform */
/* </summary> */
static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_UINT32 i) {
static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* OPJ_RESTRICT r, OPJ_UINT32 i) {
OPJ_UINT32 mr = 0;
OPJ_UINT32 w;
while( --i ) {
Expand Down Expand Up @@ -582,7 +582,7 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres
v.mem = h.mem;

while( --numres) {
OPJ_INT32 * restrict tiledp = tilec->data;
OPJ_INT32 * OPJ_RESTRICT tiledp = tilec->data;
OPJ_UINT32 j;

++tr;
Expand Down Expand Up @@ -617,8 +617,8 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres
return OPJ_TRUE;
}

static void opj_v4dwt_interleave_h(opj_v4dwt_t* restrict w, OPJ_FLOAT32* restrict a, OPJ_INT32 x, OPJ_INT32 size){
OPJ_FLOAT32* restrict bi = (OPJ_FLOAT32*) (w->wavelet + w->cas);
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_INT32 count = w->sn;
OPJ_INT32 i, k;

Expand Down Expand Up @@ -660,8 +660,8 @@ static void opj_v4dwt_interleave_h(opj_v4dwt_t* restrict w, OPJ_FLOAT32* restric
}
}

static void opj_v4dwt_interleave_v(opj_v4dwt_t* restrict v , OPJ_FLOAT32* restrict a , OPJ_INT32 x, OPJ_INT32 nb_elts_read){
opj_v4_t* restrict bi = v->wavelet + v->cas;
static void opj_v4dwt_interleave_v(opj_v4dwt_t* OPJ_RESTRICT v , OPJ_FLOAT32* OPJ_RESTRICT a , OPJ_INT32 x, OPJ_INT32 nb_elts_read){
opj_v4_t* OPJ_RESTRICT bi = v->wavelet + v->cas;
OPJ_INT32 i;

for(i = 0; i < v->sn; ++i){
Expand All @@ -679,7 +679,7 @@ static void opj_v4dwt_interleave_v(opj_v4dwt_t* restrict v , OPJ_FLOAT32* restri
#ifdef __SSE__

static void opj_v4dwt_decode_step1_sse(opj_v4_t* w, OPJ_INT32 count, const __m128 c){
__m128* restrict vw = (__m128*) w;
__m128* OPJ_RESTRICT vw = (__m128*) w;
OPJ_INT32 i;
/* 4x unrolled loop */
for(i = 0; i < count >> 2; ++i){
Expand All @@ -700,8 +700,8 @@ static void opj_v4dwt_decode_step1_sse(opj_v4_t* w, OPJ_INT32 count, const __m12
}

void opj_v4dwt_decode_step2_sse(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_INT32 m, __m128 c){
__m128* restrict vl = (__m128*) l;
__m128* restrict vw = (__m128*) w;
__m128* OPJ_RESTRICT vl = (__m128*) l;
__m128* OPJ_RESTRICT vw = (__m128*) w;
OPJ_INT32 i;
__m128 tmp1, tmp2, tmp3;
tmp1 = vl[0];
Expand Down Expand Up @@ -729,7 +729,7 @@ void opj_v4dwt_decode_step2_sse(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_INT32

static void opj_v4dwt_decode_step1(opj_v4_t* w, OPJ_INT32 count, const OPJ_FLOAT32 c)
{
OPJ_FLOAT32* restrict fw = (OPJ_FLOAT32*) w;
OPJ_FLOAT32* OPJ_RESTRICT fw = (OPJ_FLOAT32*) w;
OPJ_INT32 i;
for(i = 0; i < count; ++i){
OPJ_FLOAT32 tmp1 = fw[i*8 ];
Expand Down Expand Up @@ -797,7 +797,7 @@ static void opj_v4dwt_decode_step2(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_IN
/* <summary> */
/* Inverse 9-7 wavelet transform in 1-D. */
/* </summary> */
static void opj_v4dwt_decode(opj_v4dwt_t* restrict dwt)
static void opj_v4dwt_decode(opj_v4dwt_t* OPJ_RESTRICT dwt)
{
OPJ_INT32 a, b;
if(dwt->cas == 0) {
Expand Down Expand Up @@ -834,7 +834,7 @@ static void opj_v4dwt_decode(opj_v4dwt_t* restrict dwt)
/* <summary> */
/* Inverse 9-7 wavelet transform in 2-D. */
/* </summary> */
OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numres)
OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, OPJ_UINT32 numres)
{
opj_v4dwt_t h;
opj_v4dwt_t v;
Expand All @@ -854,7 +854,7 @@ OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numr
v.wavelet = h.wavelet;

while( --numres) {
OPJ_FLOAT32 * restrict aj = (OPJ_FLOAT32*) tilec->data;
OPJ_FLOAT32 * OPJ_RESTRICT aj = (OPJ_FLOAT32*) tilec->data;
OPJ_UINT32 bufsize = (OPJ_UINT32)((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0));
OPJ_INT32 j;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/openjp2/dwt.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Apply an irreversible inverse DWT transform to a component of an image.
@param tilec Tile component information (current tile)
@param numres Number of resolution levels to decode
*/
OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numres);
OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, OPJ_UINT32 numres);

/**
Get the gain of a subband for the irreversible 9-7 DWT.
Expand Down
8 changes: 7 additions & 1 deletion src/lib/openjp2/j2k.c
Original file line number Diff line number Diff line change
Expand Up @@ -8217,8 +8217,14 @@ static OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data,

/* Allocate output component buffer if necessary */
if (!l_img_comp_dest->data) {
OPJ_SIZE_T l_width = l_img_comp_dest->w;
OPJ_SIZE_T l_height = l_img_comp_dest->h;

l_img_comp_dest->data = (OPJ_INT32*) opj_calloc((OPJ_SIZE_T)l_img_comp_dest->w * (OPJ_SIZE_T)l_img_comp_dest->h, sizeof(OPJ_INT32));
if ((l_height == 0U) || (l_width > (SIZE_MAX / l_height))) {
/* would overflow */
return OPJ_FALSE;
}
l_img_comp_dest->data = (OPJ_INT32*) opj_calloc(l_width * l_height, sizeof(OPJ_INT32));
if (! l_img_comp_dest->data) {
return OPJ_FALSE;
}
Expand Down
14 changes: 11 additions & 3 deletions src/lib/openjp2/jp2.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,11 @@ static OPJ_BOOL opj_jp2_read_ihdr( opj_jp2_t *jp2,
assert(jp2 != 00);
assert(p_manager != 00);

if (jp2->comps != NULL) {
opj_event_msg(p_manager, EVT_WARNING, "Ignoring ihdr box. First ihdr box already read\n");
return OPJ_TRUE;
}

if (p_image_header_size != 14) {
opj_event_msg(p_manager, EVT_ERROR, "Bad image header box (bad size)\n");
return OPJ_FALSE;
Expand All @@ -563,6 +568,11 @@ static OPJ_BOOL opj_jp2_read_ihdr( opj_jp2_t *jp2,
p_image_header_data += 4;
opj_read_bytes(p_image_header_data,&(jp2->numcomps),2); /* NC */
p_image_header_data += 2;

if ((jp2->numcomps - 1U) >= 16384U) { /* unsigned underflow is well defined: 1U <= jp2->numcomps <= 16384U */
opj_event_msg(p_manager, EVT_ERROR, "Invalid number of components (ihdr)\n");
return OPJ_FALSE;
}

/* allocate memory for components */
jp2->comps = (opj_jp2_comps_t*) opj_calloc(jp2->numcomps, sizeof(opj_jp2_comps_t));
Expand Down Expand Up @@ -1764,7 +1774,7 @@ void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters)

/* further JP2 initializations go here */
jp2->color.jp2_has_colr = 0;
jp2->ignore_pclr_cmap_cdef = parameters->flags & OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG;
jp2->ignore_pclr_cmap_cdef = parameters->flags & OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG;
}

/* ----------------------------------------------------------------------- */
Expand Down Expand Up @@ -1810,7 +1820,6 @@ OPJ_BOOL opj_jp2_setup_encoder( opj_jp2_t *jp2,
jp2->numcl = 1;
jp2->cl = (OPJ_UINT32*) opj_malloc(jp2->numcl * sizeof(OPJ_UINT32));
if (!jp2->cl){
jp2->cl = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n");
return OPJ_FALSE;
}
Expand All @@ -1821,7 +1830,6 @@ OPJ_BOOL opj_jp2_setup_encoder( opj_jp2_t *jp2,
jp2->numcomps = image->numcomps; /* NC */
jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp2_comps_t));
if (!jp2->comps) {
jp2->comps = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n");
/* Memory of jp2->cl will be freed by opj_jp2_destroy */
return OPJ_FALSE;
Expand Down
42 changes: 21 additions & 21 deletions src/lib/openjp2/mct.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ const OPJ_FLOAT64 * opj_mct_get_mct_norms_real ()
/* </summary> */
#ifdef __SSE2__
void opj_mct_encode(
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_INT32* OPJ_RESTRICT c0,
OPJ_INT32* OPJ_RESTRICT c1,
OPJ_INT32* OPJ_RESTRICT c2,
OPJ_UINT32 n)
{
OPJ_SIZE_T i;
Expand Down Expand Up @@ -116,9 +116,9 @@ void opj_mct_encode(
}
#else
void opj_mct_encode(
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_INT32* OPJ_RESTRICT c0,
OPJ_INT32* OPJ_RESTRICT c1,
OPJ_INT32* OPJ_RESTRICT c2,
OPJ_UINT32 n)
{
OPJ_SIZE_T i;
Expand All @@ -143,9 +143,9 @@ void opj_mct_encode(
/* </summary> */
#ifdef __SSE2__
void opj_mct_decode(
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_INT32* OPJ_RESTRICT c0,
OPJ_INT32* OPJ_RESTRICT c1,
OPJ_INT32* OPJ_RESTRICT c2,
OPJ_UINT32 n)
{
OPJ_SIZE_T i;
Expand Down Expand Up @@ -178,9 +178,9 @@ void opj_mct_decode(
}
#else
void opj_mct_decode(
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_INT32* OPJ_RESTRICT c0,
OPJ_INT32* OPJ_RESTRICT c1,
OPJ_INT32* OPJ_RESTRICT c2,
OPJ_UINT32 n)
{
OPJ_UINT32 i;
Expand Down Expand Up @@ -210,9 +210,9 @@ OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno) {
/* </summary> */
#ifdef __SSE4_1__
void opj_mct_encode_real(
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_INT32* OPJ_RESTRICT c0,
OPJ_INT32* OPJ_RESTRICT c1,
OPJ_INT32* OPJ_RESTRICT c2,
OPJ_UINT32 n)
{
OPJ_SIZE_T i;
Expand Down Expand Up @@ -351,9 +351,9 @@ void opj_mct_encode_real(
}
#else
void opj_mct_encode_real(
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_INT32* OPJ_RESTRICT c0,
OPJ_INT32* OPJ_RESTRICT c1,
OPJ_INT32* OPJ_RESTRICT c2,
OPJ_UINT32 n)
{
OPJ_UINT32 i;
Expand All @@ -375,9 +375,9 @@ void opj_mct_encode_real(
/* Inverse irreversible MCT. */
/* </summary> */
void opj_mct_decode_real(
OPJ_FLOAT32* restrict c0,
OPJ_FLOAT32* restrict c1,
OPJ_FLOAT32* restrict c2,
OPJ_FLOAT32* OPJ_RESTRICT c0,
OPJ_FLOAT32* OPJ_RESTRICT c1,
OPJ_FLOAT32* OPJ_RESTRICT c2,
OPJ_UINT32 n)
{
OPJ_UINT32 i;
Expand Down
8 changes: 4 additions & 4 deletions src/lib/openjp2/mct.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ Apply a reversible multi-component transform to an image
@param c2 Samples blue component
@param n Number of samples for each component
*/
void opj_mct_encode(OPJ_INT32 *c0, OPJ_INT32 *c1, OPJ_INT32 *c2, OPJ_UINT32 n);
void opj_mct_encode(OPJ_INT32* OPJ_RESTRICT c0, OPJ_INT32* OPJ_RESTRICT c1, OPJ_INT32* OPJ_RESTRICT c2, OPJ_UINT32 n);
/**
Apply a reversible multi-component inverse transform to an image
@param c0 Samples for luminance component
@param c1 Samples for red chrominance component
@param c2 Samples for blue chrominance component
@param n Number of samples for each component
*/
void opj_mct_decode(OPJ_INT32 *c0, OPJ_INT32 *c1, OPJ_INT32 *c2, OPJ_UINT32 n);
void opj_mct_decode(OPJ_INT32* OPJ_RESTRICT c0, OPJ_INT32* OPJ_RESTRICT c1, OPJ_INT32* OPJ_RESTRICT c2, OPJ_UINT32 n);
/**
Get norm of the basis function used for the reversible multi-component transform
@param compno Number of the component (0->Y, 1->U, 2->V)
Expand All @@ -83,15 +83,15 @@ Apply an irreversible multi-component transform to an image
@param c2 Samples blue component
@param n Number of samples for each component
*/
void opj_mct_encode_real(OPJ_INT32 *c0, OPJ_INT32 *c1, OPJ_INT32 *c2, OPJ_UINT32 n);
void opj_mct_encode_real(OPJ_INT32* OPJ_RESTRICT c0, OPJ_INT32* OPJ_RESTRICT c1, OPJ_INT32* OPJ_RESTRICT c2, OPJ_UINT32 n);
/**
Apply an irreversible multi-component inverse transform to an image
@param c0 Samples for luminance component
@param c1 Samples for red chrominance component
@param c2 Samples for blue chrominance component
@param n Number of samples for each component
*/
void opj_mct_decode_real(OPJ_FLOAT32* c0, OPJ_FLOAT32* c1, OPJ_FLOAT32* c2, OPJ_UINT32 n);
void opj_mct_decode_real(OPJ_FLOAT32* OPJ_RESTRICT c0, OPJ_FLOAT32* OPJ_RESTRICT c1, OPJ_FLOAT32* OPJ_RESTRICT c2, OPJ_UINT32 n);
/**
Get norm of the basis function used for the irreversible multi-component transform
@param compno Number of the component (0->Y, 1->U, 2->V)
Expand Down
17 changes: 13 additions & 4 deletions src/lib/openjp2/opj_includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,21 @@
*/

/* Are restricted pointers available? (C99) */
#if (__STDC_VERSION__ != 199901L)
#if (__STDC_VERSION__ >= 199901L)
#define OPJ_RESTRICT restrict
#else
/* Not a C99 compiler */
#ifdef __GNUC__
#define restrict __restrict__
#if defined(__GNUC__)
#define OPJ_RESTRICT __restrict__

/*
vc14 (2015) outputs wrong results.
Need to check OPJ_RESTRICT usage (or a bug in vc14)
#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
#define OPJ_RESTRICT __restrict
*/
#else
#define restrict /* restrict */
#define OPJ_RESTRICT /* restrict */
#endif
#endif

Expand Down
8 changes: 7 additions & 1 deletion src/lib/openjp2/pi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,13 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
l_current_pi = l_pi;

/* memory allocation for include */
l_current_pi->include = (OPJ_INT16*) opj_calloc((l_tcp->numlayers +1) * l_step_l, sizeof(OPJ_INT16));
/* prevent an integer overflow issue */
l_current_pi->include = 00;
if (l_step_l <= (SIZE_MAX / (l_tcp->numlayers + 1U)))
{
l_current_pi->include = (OPJ_INT16*) opj_calloc((l_tcp->numlayers +1) * l_step_l, sizeof(OPJ_INT16));
}

if
(!l_current_pi->include)
{
Expand Down
Loading

0 comments on commit 6c83f14

Please sign in to comment.