summaryrefslogtreecommitdiff
path: root/libopenjpeg
diff options
context:
space:
mode:
authorFrancois-Olivier Devaux <fodevaux@users.noreply.github.com>2007-10-18 12:26:11 +0000
committerFrancois-Olivier Devaux <fodevaux@users.noreply.github.com>2007-10-18 12:26:11 +0000
commit9e114bcaa47194a9f6af8eadf6d7cb9bb1ec277f (patch)
tree8ddf614d9b481254e15a4ea9088f83d6f1534734 /libopenjpeg
parent5fdc05d18d4831ead22948950ba279fadfc6b71d (diff)
Patch from Callum Lewick. Memset patch. See ChangeLog for more details. Thanks Callum !
Diffstat (limited to 'libopenjpeg')
-rw-r--r--libopenjpeg/image.c4
-rw-r--r--libopenjpeg/j2k.c68
-rw-r--r--libopenjpeg/j2k_lib.c17
-rw-r--r--libopenjpeg/j2k_lib.h85
-rw-r--r--libopenjpeg/jp2.c2
-rw-r--r--libopenjpeg/opj_includes.h6
-rw-r--r--libopenjpeg/opj_malloc.h140
-rw-r--r--libopenjpeg/pi.c34
-rw-r--r--libopenjpeg/t1.c18
-rw-r--r--libopenjpeg/tcd.c9
-rw-r--r--libopenjpeg/tgt.c2
11 files changed, 212 insertions, 173 deletions
diff --git a/libopenjpeg/image.c b/libopenjpeg/image.c
index 6698f459..ea8e59ea 100644
--- a/libopenjpeg/image.c
+++ b/libopenjpeg/image.c
@@ -35,7 +35,7 @@ opj_image_t* OPJ_CALLCONV opj_image_create(int numcmpts, opj_image_cmptparm_t *c
int compno;
opj_image_t *image = NULL;
- image = (opj_image_t*)opj_malloc(sizeof(opj_image_t));
+ image = (opj_image_t*) opj_calloc(1, sizeof(opj_image_t));
if(image) {
image->color_space = clrspc;
image->numcomps = numcmpts;
@@ -58,7 +58,7 @@ opj_image_t* OPJ_CALLCONV opj_image_create(int numcmpts, opj_image_cmptparm_t *c
comp->prec = cmptparms[compno].prec;
comp->bpp = cmptparms[compno].bpp;
comp->sgnd = cmptparms[compno].sgnd;
- comp->data = (int*)opj_malloc(comp->w * comp->h * sizeof(int));
+ comp->data = (int*) opj_calloc(comp->w * comp->h, sizeof(int));
if(!comp->data) {
fprintf(stderr,"Unable to allocate memory for image.\n");
opj_image_destroy(image);
diff --git a/libopenjpeg/j2k.c b/libopenjpeg/j2k.c
index 042b8643..114ee9ec 100644
--- a/libopenjpeg/j2k.c
+++ b/libopenjpeg/j2k.c
@@ -259,13 +259,13 @@ char *j2k_convert_progression_order(OPJ_PROG_ORDER prg_order){
}
static void j2k_check_poc_val(opj_cparameters_t *parameters, int numcomps, int numlayers){
+ int* packet_array;
int index, resno, compno, layno, i;
- char loss = 0;
int step_c = 1;
int step_r = numcomps * step_c;
int step_l = parameters->numresolution * step_r;
- int array_size = step_l * numlayers * sizeof(int);
- int *packet_array = (int *) opj_malloc(array_size);
+ bool loss = false;
+ packet_array = (int*) opj_calloc(step_l * numlayers, sizeof(int));
for (i = 0; i < parameters->numpocs ; i++) {
int layno0 = 0;
@@ -285,12 +285,12 @@ static void j2k_check_poc_val(opj_cparameters_t *parameters, int numcomps, int n
for (layno = 0; layno < numlayers ; layno++) {
index = step_r * resno + step_c * compno + step_l * layno;
if(!( packet_array[index]== 1)){
- loss = 1;
+ loss = true;
}
}
}
}
- if(loss == 1)
+ if(loss)
fprintf(stdout,"Missing packets possible loss of data\n");
opj_free(packet_array);
}
@@ -536,7 +536,7 @@ static void j2k_read_siz(opj_j2k_t *j2k) {
}
#endif /* USE_JPWL */
- image->comps = (opj_image_comp_t *) opj_malloc(image->numcomps * sizeof(opj_image_comp_t));
+ image->comps = (opj_image_comp_t*) opj_calloc(image->numcomps, sizeof(opj_image_comp_t));
for (i = 0; i < image->numcomps; i++) {
int tmp, w, h;
tmp = cio_read(cio, 1); /* Ssiz_i */
@@ -625,8 +625,8 @@ static void j2k_read_siz(opj_j2k_t *j2k) {
}
#endif /* USE_JPWL */
- cp->tcps = (opj_tcp_t *) opj_malloc(cp->tw * cp->th * sizeof(opj_tcp_t));
- cp->tileno = (int *) opj_malloc(cp->tw * cp->th * sizeof(int));
+ cp->tcps = (opj_tcp_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_t));
+ cp->tileno = (int*) opj_malloc(cp->tw * cp->th * sizeof(int));
cp->tileno_size = 0;
#ifdef USE_JPWL
@@ -654,13 +654,13 @@ static void j2k_read_siz(opj_j2k_t *j2k) {
cp->ppm_data_first = NULL;
cp->ppm_previous = 0;
cp->ppm_store = 0;
-
- j2k->default_tcp->tccps = (opj_tccp_t *) opj_malloc(sizeof(opj_tccp_t) * image->numcomps);
+
+ j2k->default_tcp->tccps = (opj_tccp_t*) opj_calloc(image->numcomps, sizeof(opj_tccp_t));
for (i = 0; i < cp->tw * cp->th; i++) {
- cp->tcps[i].tccps = (opj_tccp_t *) opj_malloc(sizeof(opj_tccp_t) * image->numcomps);
+ cp->tcps[i].tccps = (opj_tccp_t*) opj_malloc(image->numcomps * sizeof(opj_tccp_t));
}
- j2k->tile_data = (unsigned char **) opj_malloc(cp->tw * cp->th * sizeof(unsigned char *));
- j2k->tile_len = (int *) opj_malloc(cp->tw * cp->th * sizeof(int));
+ j2k->tile_data = (unsigned char**) opj_calloc(cp->tw * cp->th, sizeof(unsigned char*));
+ j2k->tile_len = (int*) opj_calloc(cp->tw * cp->th, sizeof(int));
j2k->state = J2K_STATE_MH;
/* Index */
@@ -675,7 +675,7 @@ static void j2k_read_siz(opj_j2k_t *j2k) {
cstr_info->tile_y = cp->tdy;
cstr_info->tile_Ox = cp->tx0;
cstr_info->tile_Oy = cp->ty0;
- cstr_info->tile = (opj_tile_info_t*) opj_malloc(cp->tw * cp->th * sizeof(opj_tile_info_t));
+ cstr_info->tile = (opj_tile_info_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tile_info_t));
}
}
@@ -824,7 +824,7 @@ static void j2k_read_cod(opj_j2k_t *j2k) {
opj_codestream_info_t *cstr_info = j2k->cstr_info;
cstr_info->prog = tcp->prg;
cstr_info->numlayers = tcp->numlayers;
- cstr_info->numdecompos = (int*) malloc (image->numcomps * sizeof(int));
+ cstr_info->numdecompos = (int*) opj_malloc(image->numcomps * sizeof(int));
for (i = 0; i < image->numcomps; i++) {
cstr_info->numdecompos[i] = tcp->tccps[i].numresolutions - 1;
}
@@ -1713,15 +1713,19 @@ static opj_dec_mstabent_t *j2k_dec_mstab_lookup(int id) {
/* ----------------------------------------------------------------------- */
opj_j2k_t* j2k_create_decompress(opj_common_ptr cinfo) {
- opj_j2k_t *j2k = (opj_j2k_t*)opj_malloc(sizeof(opj_j2k_t));
- if(j2k) {
- j2k->cinfo = cinfo;
- j2k->default_tcp = (opj_tcp_t*)opj_malloc(sizeof(opj_tcp_t));
- if(!j2k->default_tcp) {
- opj_free(j2k);
- return NULL;
- }
+ opj_j2k_t *j2k = (opj_j2k_t*) opj_calloc(1, sizeof(opj_j2k_t));
+ if(!j2k)
+ return NULL;
+
+ j2k->default_tcp = (opj_tcp_t*) opj_calloc(1, sizeof(opj_tcp_t));
+ if(!j2k->default_tcp) {
+ opj_free(j2k);
+ return NULL;
}
+
+ j2k->cinfo = cinfo;
+ j2k->tile_data = NULL;
+
return j2k;
}
@@ -1775,7 +1779,7 @@ void j2k_destroy_decompress(opj_j2k_t *j2k) {
void j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters) {
if(j2k && parameters) {
/* create and initialize the coding parameters structure */
- opj_cp_t *cp = (opj_cp_t*)opj_malloc(sizeof(opj_cp_t));
+ opj_cp_t *cp = (opj_cp_t*) opj_calloc(1, sizeof(opj_cp_t));
cp->reduce = parameters->cp_reduce;
cp->layer = parameters->cp_layer;
cp->limit_decoding = parameters->cp_limit_decoding;
@@ -1977,7 +1981,7 @@ opj_image_t* j2k_decode_jpt_stream(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestre
/* ----------------------------------------------------------------------- */
opj_j2k_t* j2k_create_compress(opj_common_ptr cinfo) {
- opj_j2k_t *j2k = (opj_j2k_t*)opj_malloc(sizeof(opj_j2k_t));
+ opj_j2k_t *j2k = (opj_j2k_t*) opj_calloc(1, sizeof(opj_j2k_t));
if(j2k) {
j2k->cinfo = cinfo;
}
@@ -2016,7 +2020,7 @@ void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_
}
/* create and initialize the coding parameters structure */
- cp = (opj_cp_t*)opj_malloc(sizeof(opj_cp_t));
+ cp = (opj_cp_t*) opj_calloc(1, sizeof(opj_cp_t));
/* keep a link to cp so that we can destroy it later in j2k_destroy_compress */
j2k->cp = cp;
@@ -2140,7 +2144,7 @@ void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_
/* initialize the mutiple tiles */
/* ---------------------------- */
- cp->tcps = (opj_tcp_t *) opj_malloc(cp->tw * cp->th * sizeof(opj_tcp_t));
+ cp->tcps = (opj_tcp_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_t));
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
opj_tcp_t *tcp = &cp->tcps[tileno];
@@ -2187,8 +2191,8 @@ void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_
tcp->numpocs = 0;
}
- tcp->tccps = (opj_tccp_t *) opj_malloc(image->numcomps * sizeof(opj_tccp_t));
-
+ tcp->tccps = (opj_tccp_t*) opj_calloc(image->numcomps, sizeof(opj_tccp_t));
+
for (i = 0; i < image->numcomps; i++) {
opj_tccp_t *tccp = &tcp->tccps[i];
tccp->csty = parameters->csty & 0x01; /* 0 => one precinct || 1 => custom precinct */
@@ -2299,11 +2303,11 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestre
cstr_info->tile_Oy = cp->ty0; /* new version parser */
cstr_info->numcomps = image->numcomps;
cstr_info->numlayers = (&cp->tcps[0])->numlayers;
- cstr_info->numdecompos = (int*) malloc (image->numcomps * sizeof(int));
+ cstr_info->numdecompos = (int*) opj_malloc(image->numcomps * sizeof(int));
for (compno=0; compno < image->numcomps; compno++) {
cstr_info->numdecompos[compno] = (&cp->tcps[0])->tccps->numresolutions - 1;
}
- cstr_info->D_max = 0; /* ADD Marcela */
+ cstr_info->D_max = 0.0; /* ADD Marcela */
cstr_info->main_head_start = cio_tell(cio); /* position of SOC */
}
/* << INDEX */
@@ -2450,7 +2454,7 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestre
tcd_free_encode(tcd);
tcd_destroy(tcd);
- free(j2k->cur_totnum_tp);
+ opj_free(j2k->cur_totnum_tp);
j2k_write_eoc(j2k);
diff --git a/libopenjpeg/j2k_lib.c b/libopenjpeg/j2k_lib.c
index 62774320..91aee007 100644
--- a/libopenjpeg/j2k_lib.c
+++ b/libopenjpeg/j2k_lib.c
@@ -57,20 +57,3 @@ double opj_clock(void) {
#endif
}
-void* opj_malloc( size_t size ) {
- void *memblock = malloc(size);
- if(memblock) {
- memset(memblock, 0, size);
- }
- return memblock;
-}
-
-void* opj_realloc( void *memblock, size_t size ) {
- return realloc(memblock, size);
-}
-
-void opj_free( void *memblock ) {
- free(memblock);
-}
-
-
diff --git a/libopenjpeg/j2k_lib.h b/libopenjpeg/j2k_lib.h
index 99f06196..7df4d367 100644
--- a/libopenjpeg/j2k_lib.h
+++ b/libopenjpeg/j2k_lib.h
@@ -29,13 +29,9 @@
@file j2k_lib.h
@brief Internal functions
-The functions in J2K_LIB.C are internal utilities mainly used for memory management.
+The functions in J2K_LIB.C are internal utilities mainly used for timing.
*/
-#ifndef __GNUC__
-#define __attribute__(x) /* */
-#endif
-
/** @defgroup MISC MISC - Miscellaneous internal functions */
/*@{*/
@@ -49,85 +45,6 @@ Difference in successive opj_clock() calls tells you the elapsed time
*/
double opj_clock(void);
-/**
-Allocate a memory block with elements initialized to 0
-@param size Bytes to allocate
-@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
-*/
-void* __attribute__ ((malloc)) opj_malloc( size_t size );
-
-/**
-Allocate memory aligned to a 16 byte boundry
-@param size Bytes to allocate
-@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
-*/
-/* FIXME: These should be set with cmake tests, but we're currently not requiring use of cmake */
-#ifdef WIN32
- /* Someone should tell the mingw people that their malloc.h ought to provide _mm_malloc() */
- #ifdef __GNUC__
- #include <mm_malloc.h>
- #define HAVE_MM_MALLOC
- #else /* MSVC, Intel C++ */
- #include <malloc.h>
- #ifdef _mm_malloc
- #define HAVE_MM_MALLOC
- #endif
- #endif
-#else /* Not WIN32 */
- #if defined(__sun)
- #define HAVE_MEMALIGN
- /* Linux x86_64 and OSX always align allocations to 16 bytes */
- #elif !defined(__amd64__) && !defined(__APPLE__)
- /* FIXME: Yes, this is a big assumption */
- #define HAVE_POSIX_MEMALIGN
- #endif
-#endif
-
-#define opj_aligned_malloc(size) malloc(size)
-#define opj_aligned_free(m) free(m)
-
-#ifdef HAVE_MM_MALLOC
- #undef opj_aligned_malloc
- #define opj_aligned_malloc(size) _mm_malloc(size, 16)
- #undef opj_aligned_free
- #define opj_aligned_free(m) _mm_free(m)
-#endif
-
-#ifdef HAVE_MEMALIGN
- extern void* memalign(size_t, size_t);
- #undef opj_aligned_malloc
- #define opj_aligned_malloc(size) memalign(16, (size))
- #undef opj_aligned_free
- #define opj_aligned_free(m) free(m)
-#endif
-
-#ifdef HAVE_POSIX_MEMALIGN
- #undef opj_aligned_malloc
- extern int posix_memalign(void**, size_t, size_t);
-
- static INLINE void* __attribute__ ((malloc)) opj_aligned_malloc(size_t size){
- void* mem = NULL;
- posix_memalign(&mem, 16, size);
- return mem;
- }
- #undef opj_aligned_free
- #define opj_aligned_free(m) free(m)
-#endif
-
-/**
-Reallocate memory blocks.
-@param memblock Pointer to previously allocated memory block
-@param size New size in bytes
-@return Returns a void pointer to the reallocated (and possibly moved) memory block
-*/
-void* __attribute__ ((malloc)) opj_realloc( void *memblock, size_t size );
-
-/**
-Deallocates or frees a memory block.
-@param memblock Previously allocated memory block to be freed
-*/
-void opj_free( void *memblock );
-
/* ----------------------------------------------------------------------- */
/*@}*/
diff --git a/libopenjpeg/jp2.c b/libopenjpeg/jp2.c
index 92abf2e1..14f9493c 100644
--- a/libopenjpeg/jp2.c
+++ b/libopenjpeg/jp2.c
@@ -507,7 +507,7 @@ static bool jp2_read_struct(opj_jp2_t *jp2, opj_cio_t *cio) {
/* ----------------------------------------------------------------------- */
opj_jp2_t* jp2_create_decompress(opj_common_ptr cinfo) {
- opj_jp2_t *jp2 = (opj_jp2_t*)opj_malloc(sizeof(opj_jp2_t));
+ opj_jp2_t *jp2 = (opj_jp2_t*) opj_calloc(1, sizeof(opj_jp2_t));
if(jp2) {
jp2->cinfo = cinfo;
/* create the J2K codec */
diff --git a/libopenjpeg/opj_includes.h b/libopenjpeg/opj_includes.h
index 72152a5e..7599a71f 100644
--- a/libopenjpeg/opj_includes.h
+++ b/libopenjpeg/opj_includes.h
@@ -54,6 +54,11 @@
==========================================================
*/
+/* Ignore GCC attributes if this is not GCC */
+#ifndef __GNUC__
+ #define __attribute__(x) /* __attribute__(x) */
+#endif
+
/*
The inline keyword is supported by C99 but not by C90.
Most compilers implement their own version of this keyword ...
@@ -72,6 +77,7 @@ Most compilers implement their own version of this keyword ...
#endif /* INLINE */
#include "j2k_lib.h"
+#include "opj_malloc.h"
#include "event.h"
#include "cio.h"
diff --git a/libopenjpeg/opj_malloc.h b/libopenjpeg/opj_malloc.h
new file mode 100644
index 00000000..9b7c8956
--- /dev/null
+++ b/libopenjpeg/opj_malloc.h
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2005, Hervé Drolon, FreeImage Team
+ * Copyright (c) 2007, Callum Lerwick <seg@haxxed.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef __OPJ_MALLOC_H
+#define __OPJ_MALLOC_H
+/**
+@file opj_malloc.h
+@brief Internal functions
+
+The functions in opj_malloc.h are internal utilities used for memory management.
+*/
+
+/** @defgroup MISC MISC - Miscellaneous internal functions */
+/*@{*/
+
+/** @name Exported functions */
+/*@{*/
+/* ----------------------------------------------------------------------- */
+
+/**
+Allocate an uninitialized memory block
+@param size Bytes to allocate
+@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
+*/
+#define opj_malloc(size) malloc(size)
+
+/**
+Allocate a memory block with elements initialized to 0
+@param num Blocks to allocate
+@param size Bytes per block to allocate
+@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
+*/
+#define opj_calloc(num, size) calloc(num, size)
+
+/**
+Allocate memory aligned to a 16 byte boundry
+@param size Bytes to allocate
+@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
+*/
+/* FIXME: These should be set with cmake tests, but we're currently not requiring use of cmake */
+#ifdef WIN32
+ /* Someone should tell the mingw people that their malloc.h ought to provide _mm_malloc() */
+ #ifdef __GNUC__
+ #include <mm_malloc.h>
+ #define HAVE_MM_MALLOC
+ #else /* MSVC, Intel C++ */
+ #include <malloc.h>
+ #ifdef _mm_malloc
+ #define HAVE_MM_MALLOC
+ #endif
+ #endif
+#else /* Not WIN32 */
+ #if defined(__sun)
+ #define HAVE_MEMALIGN
+ /* Linux x86_64 and OSX always align allocations to 16 bytes */
+ #elif !defined(__amd64__) && !defined(__APPLE__)
+ /* FIXME: Yes, this is a big assumption */
+ #define HAVE_POSIX_MEMALIGN
+ #endif
+#endif
+
+#define opj_aligned_malloc(size) malloc(size)
+#define opj_aligned_free(m) free(m)
+
+#ifdef HAVE_MM_MALLOC
+ #undef opj_aligned_malloc
+ #define opj_aligned_malloc(size) _mm_malloc(size, 16)
+ #undef opj_aligned_free
+ #define opj_aligned_free(m) _mm_free(m)
+#endif
+
+#ifdef HAVE_MEMALIGN
+ extern void* memalign(size_t, size_t);
+ #undef opj_aligned_malloc
+ #define opj_aligned_malloc(size) memalign(16, (size))
+ #undef opj_aligned_free
+ #define opj_aligned_free(m) free(m)
+#endif
+
+#ifdef HAVE_POSIX_MEMALIGN
+ #undef opj_aligned_malloc
+ extern int posix_memalign(void**, size_t, size_t);
+
+ static INLINE void* __attribute__ ((malloc)) opj_aligned_malloc(size_t size){
+ void* mem = NULL;
+ posix_memalign(&mem, 16, size);
+ return mem;
+ }
+ #undef opj_aligned_free
+ #define opj_aligned_free(m) free(m)
+#endif
+
+/**
+Reallocate memory blocks.
+@param memblock Pointer to previously allocated memory block
+@param size New size in bytes
+@return Returns a void pointer to the reallocated (and possibly moved) memory block
+*/
+#define opj_realloc(m, s) realloc(m, s)
+
+/**
+Deallocates or frees a memory block.
+@param memblock Previously allocated memory block to be freed
+*/
+#define opj_free(m) free(m)
+
+#ifdef __GNUC__
+#pragma GCC poison malloc calloc realloc free
+#endif
+
+/* ----------------------------------------------------------------------- */
+/*@}*/
+
+/*@}*/
+
+#endif /* __OPJ_MALLOC_H */
+
diff --git a/libopenjpeg/pi.c b/libopenjpeg/pi.c
index e43be817..b5e8656d 100644
--- a/libopenjpeg/pi.c
+++ b/libopenjpeg/pi.c
@@ -413,17 +413,15 @@ opj_pi_iterator_t *pi_create_decode(opj_image_t *image, opj_cp_t *cp, int tileno
opj_pi_iterator_t *pi = NULL;
opj_tcp_t *tcp = NULL;
opj_tccp_t *tccp = NULL;
- size_t array_size;
-
+
tcp = &cp->tcps[tileno];
- array_size = (tcp->numpocs + 1) * sizeof(opj_pi_iterator_t);
- pi = (opj_pi_iterator_t *) opj_malloc(array_size);
+ pi = (opj_pi_iterator_t*) opj_calloc((tcp->numpocs + 1), sizeof(opj_pi_iterator_t));
if(!pi) {
/* TODO: throw an error */
return NULL;
}
-
+
for (pino = 0; pino < tcp->numpocs + 1; pino++) { /* change */
int maxres = 0;
int maxprec = 0;
@@ -436,14 +434,12 @@ opj_pi_iterator_t *pi_create_decode(opj_image_t *image, opj_cp_t *cp, int tileno
pi[pino].ty1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1);
pi[pino].numcomps = image->numcomps;
- array_size = image->numcomps * sizeof(opj_pi_comp_t);
- pi[pino].comps = (opj_pi_comp_t *) opj_malloc(array_size);
+ pi[pino].comps = (opj_pi_comp_t*) opj_calloc(image->numcomps, sizeof(opj_pi_comp_t));
if(!pi[pino].comps) {
/* TODO: throw an error */
pi_destroy(pi, cp, tileno);
return NULL;
}
- memset(pi[pino].comps, 0, array_size);
for (compno = 0; compno < pi->numcomps; compno++) {
int tcx0, tcy0, tcx1, tcy1;
@@ -453,8 +449,7 @@ opj_pi_iterator_t *pi_create_decode(opj_image_t *image, opj_cp_t *cp, int tileno
comp->dy = image->comps[compno].dy;
comp->numresolutions = tccp->numresolutions;
- array_size = comp->numresolutions * sizeof(opj_pi_resolution_t);
- comp->resolutions = (opj_pi_resolution_t *) opj_malloc(array_size);
+ comp->resolutions = (opj_pi_resolution_t*) opj_calloc(comp->numresolutions, sizeof(opj_pi_resolution_t));
if(!comp->resolutions) {
/* TODO: throw an error */
pi_destroy(pi, cp, tileno);
@@ -507,8 +502,7 @@ opj_pi_iterator_t *pi_create_decode(opj_image_t *image, opj_cp_t *cp, int tileno
pi[pino].step_l = maxres * pi[pino].step_r;
if (pino == 0) {
- array_size = image->numcomps * maxres * tcp->numlayers * maxprec * sizeof(short int);
- pi[pino].include = (short int *) opj_malloc(array_size);
+ pi[pino].include = (short int*) opj_calloc(image->numcomps * maxres * tcp->numlayers * maxprec, sizeof(short int));
if(!pi[pino].include) {
/* TODO: throw an error */
pi_destroy(pi, cp, tileno);
@@ -554,15 +548,13 @@ opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int ti
opj_pi_iterator_t *pi = NULL;
opj_tcp_t *tcp = NULL;
opj_tccp_t *tccp = NULL;
- size_t array_size;
tcp = &cp->tcps[tileno];
- array_size = (tcp->numpocs + 1) * sizeof(opj_pi_iterator_t);
- pi = (opj_pi_iterator_t *) opj_malloc(array_size);
+ pi = (opj_pi_iterator_t*) opj_calloc((tcp->numpocs + 1), sizeof(opj_pi_iterator_t));
if(!pi) { return NULL;}
pi->tp_on = cp->tp_on;
-
+
for(pino = 0;pino < tcp->numpocs+1 ; pino ++){
p = tileno % cp->tw;
q = tileno / cp->tw;
@@ -573,13 +565,11 @@ opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int ti
pi[pino].ty1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1);
pi[pino].numcomps = image->numcomps;
- array_size = image->numcomps * sizeof(opj_pi_comp_t);
- pi[pino].comps = (opj_pi_comp_t *) opj_malloc(array_size);
+ pi[pino].comps = (opj_pi_comp_t*) opj_calloc(image->numcomps, sizeof(opj_pi_comp_t));
if(!pi[pino].comps) {
pi_destroy(pi, cp, tileno);
return NULL;
}
- memset(pi[pino].comps, 0, array_size);
for (compno = 0; compno < pi[pino].numcomps; compno++) {
int tcx0, tcy0, tcx1, tcy1;
@@ -589,8 +579,7 @@ opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int ti
comp->dy = image->comps[compno].dy;
comp->numresolutions = tccp->numresolutions;
- array_size = comp->numresolutions * sizeof(opj_pi_resolution_t);
- comp->resolutions = (opj_pi_resolution_t *) opj_malloc(array_size);
+ comp->resolutions = (opj_pi_resolution_t*) opj_malloc(comp->numresolutions * sizeof(opj_pi_resolution_t));
if(!comp->resolutions) {
pi_destroy(pi, cp, tileno);
return NULL;
@@ -653,8 +642,7 @@ opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int ti
}
if (pino == 0) {
- array_size = tcp->numlayers * pi[pino].step_l * sizeof(short int);
- pi[pino].include = (short int *) opj_malloc(array_size);
+ pi[pino].include = (short int*) opj_calloc(tcp->numlayers * pi[pino].step_l, sizeof(short int));
if(!pi[pino].include) {
pi_destroy(pi, cp, tileno);
return NULL;
diff --git a/libopenjpeg/t1.c b/libopenjpeg/t1.c
index c05d05c0..d359b093 100644
--- a/libopenjpeg/t1.c
+++ b/libopenjpeg/t1.c
@@ -762,7 +762,7 @@ static bool allocate_buffers(
if(datasize > t1->datasize){
opj_aligned_free(t1->data);
- t1->data=opj_aligned_malloc(datasize * sizeof(int));
+ t1->data = (int*) opj_aligned_malloc(datasize * sizeof(int));
if(!t1->data){
return false;
}
@@ -775,7 +775,7 @@ static bool allocate_buffers(
if(flagssize > t1->flagssize){
opj_aligned_free(t1->flags);
- t1->flags=opj_aligned_malloc(flagssize * sizeof(flag_t));
+ t1->flags = (flag_t*) opj_aligned_malloc(flagssize * sizeof(flag_t));
if(!t1->flags){
return false;
}
@@ -998,15 +998,15 @@ opj_t1_t* t1_create(opj_common_ptr cinfo) {
if(!t1)
return NULL;
- t1->cinfo = cinfo;
- /* create MQC and RAW handles */
- t1->mqc = mqc_create();
- t1->raw = raw_create();
+ t1->cinfo = cinfo;
+ /* create MQC and RAW handles */
+ t1->mqc = mqc_create();
+ t1->raw = raw_create();
- t1->datasize=0;
t1->data=NULL;
- t1->flagssize=0;
t1->flags=NULL;
+ t1->datasize=0;
+ t1->flagssize=0;
return t1;
}
@@ -1018,7 +1018,7 @@ void t1_destroy(opj_t1_t *t1) {
raw_destroy(t1->raw);
opj_aligned_free(t1->data);
opj_aligned_free(t1->flags);
- free(t1);
+ opj_free(t1);
}
}
diff --git a/libopenjpeg/tcd.c b/libopenjpeg/tcd.c
index 8d91b851..2a8a6223 100644
--- a/libopenjpeg/tcd.c
+++ b/libopenjpeg/tcd.c
@@ -313,7 +313,7 @@ void tcd_malloc_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int c
prc->cw = (brcblkxend - tlcblkxstart) >> cblkwidthexpn;
prc->ch = (brcblkyend - tlcblkystart) >> cblkheightexpn;
- prc->cblks = (opj_tcd_cblk_t *) opj_malloc((prc->cw * prc->ch) * sizeof(opj_tcd_cblk_t));
+ prc->cblks = (opj_tcd_cblk_t*) opj_calloc((prc->cw * prc->ch), sizeof(opj_tcd_cblk_t));
prc->incltree = tgt_create(prc->cw, prc->ch);
prc->imsbtree = tgt_create(prc->cw, prc->ch);
@@ -548,7 +548,7 @@ void tcd_init_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int cur
prc->ch = (brcblkyend - tlcblkystart) >> cblkheightexpn;
opj_free(prc->cblks);
- prc->cblks = (opj_tcd_cblk_t *) opj_malloc(prc->cw * prc->ch * sizeof(opj_tcd_cblk_t));
+ prc->cblks = (opj_tcd_cblk_t*) opj_calloc(prc->cw * prc->ch, sizeof(opj_tcd_cblk_t));
if (prc->incltree != NULL) {
tgt_destroy(prc->incltree);
@@ -603,7 +603,7 @@ void tcd_malloc_decode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp) {
tileno = cp->tileno[j];
tile = &(tcd->tcd_image->tiles[cp->tileno[tileno]]);
tile->numcomps = image->numcomps;
- tile->comps = (opj_tcd_tilecomp_t *) opj_malloc(image->numcomps * sizeof(opj_tcd_tilecomp_t));
+ tile->comps = (opj_tcd_tilecomp_t*) opj_calloc(image->numcomps, sizeof(opj_tcd_tilecomp_t));
}
for (i = 0; i < image->numcomps; i++) {
@@ -799,6 +799,7 @@ void tcd_malloc_decode_tile(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp,
cblk->y0 = int_max(cblkystart, prc->y0);
cblk->x1 = int_min(cblkxend, prc->x1);
cblk->y1 = int_min(cblkyend, prc->y1);
+ cblk->numsegs = 0;
}
} /* precno */
} /* bandno */
@@ -1178,7 +1179,7 @@ int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, op
cstr_info->tile[tileno].pdx[i] = tccp->prcw[i];
cstr_info->tile[tileno].pdy[i] = tccp->prch[i];
}
- cstr_info->tile[tileno].packet = (opj_packet_info_t *) opj_malloc(cstr_info->numcomps * cstr_info->numlayers * numpacks * sizeof(opj_packet_info_t));
+ cstr_info->tile[tileno].packet = (opj_packet_info_t*) opj_calloc(cstr_info->numcomps * cstr_info->numlayers * numpacks, sizeof(opj_packet_info_t));
}
/* << INDEX */
diff --git a/libopenjpeg/tgt.c b/libopenjpeg/tgt.c
index 30b0aee4..a5dbcd3c 100644
--- a/libopenjpeg/tgt.c
+++ b/libopenjpeg/tgt.c
@@ -71,7 +71,7 @@ opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv) {
return NULL;
}
- tree->nodes = (opj_tgt_node_t *) opj_malloc(tree->numnodes * sizeof(opj_tgt_node_t));
+ tree->nodes = (opj_tgt_node_t*) opj_calloc(tree->numnodes, sizeof(opj_tgt_node_t));
if(!tree->nodes) {
opj_free(tree);
return NULL;