fixed opj_malloc.h for macosx (bugfix provided by janpeder, thanks)
[openjpeg.git] / libopenjpeg / image.c
index 84664e9a86f03ce9dd700c56fa38d47e99df5051..ea8e59ea547ab91d12b538d1ff8bf889e3ce241d 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "opj_includes.h"
 
-opj_image_t* opj_image_create0() {
+opj_image_t* opj_image_create0(void) {
        opj_image_t *image = (opj_image_t*)opj_malloc(sizeof(opj_image_t));
        return image;
 }
@@ -35,13 +35,14 @@ 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;
                /* allocate memory for the per-component information */
                image->comps = (opj_image_comp_t*)opj_malloc(image->numcomps * sizeof(opj_image_comp_t));
                if(!image->comps) {
+                       fprintf(stderr,"Unable to allocate memory for image.\n");
                        opj_image_destroy(image);
                        return NULL;
                }
@@ -57,8 +58,9 @@ 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);
                                return NULL;
                        }