updated XCode project file
[openjpeg.git] / libopenjpeg / cio.c
index 0b701baf4edda24f85022b122fb0d8990ba43851..2ac262a1f6b54013165218e2bd1a6e2d6d53f36b 100644 (file)
@@ -1,9 +1,10 @@
 /*
+ * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
+ * Copyright (c) 2002-2007, Professor Benoit Macq
  * Copyright (c) 2001-2003, David Janssens
  * Copyright (c) 2002-2003, Yannick Verschueren
- * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
- * Copyright (c) 2005, Herv� Drolon, FreeImage Team
- * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
+ * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
+ * Copyright (c) 2005, Herve Drolon, FreeImage Team
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -32,7 +33,7 @@
 
 /* ----------------------------------------------------------------------- */
 
-opj_cio_t* opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length) {
+opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length) {
        opj_cp_t *cp = NULL;
        opj_cio_t *cio = (opj_cio_t*)opj_malloc(sizeof(opj_cio_t));
        if(!cio) return NULL;
@@ -57,9 +58,10 @@ opj_cio_t* opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length)
                                opj_free(cio);
                                return NULL;
                }
-               cio->length = cp->tdx * cp->tdy * cp->tw * cp->th * 2;
+               cio->length = (unsigned int) (0.1625 * cp->img_size + 2000); /* 0.1625 = 1.3/8 and 2000 bytes as a minimum for headers */
                cio->buffer = (unsigned char *)opj_malloc(cio->length);
                if(!cio->buffer) {
+                       opj_event_msg(cio->cinfo, EVT_ERROR, "Error allocating memory for compressed bitstream\n");
                        opj_free(cio);
                        return NULL;
                }
@@ -77,7 +79,7 @@ opj_cio_t* opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length)
        return cio;
 }
 
-void opj_cio_close(opj_cio_t *cio) {
+void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio) {
        if(cio) {
                if(cio->openmode == OPJ_STREAM_WRITE) {
                        /* destroy the allocated buffer */
@@ -94,7 +96,7 @@ void opj_cio_close(opj_cio_t *cio) {
 /*
  * Get position in byte stream.
  */
-int cio_tell(opj_cio_t *cio) {
+int OPJ_CALLCONV cio_tell(opj_cio_t *cio) {
        return cio->bp - cio->start;
 }
 
@@ -103,7 +105,7 @@ int cio_tell(opj_cio_t *cio) {
  *
  * pos : position, in number of bytes, from the beginning of the stream
  */
-void cio_seek(opj_cio_t *cio, int pos) {
+void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos) {
        cio->bp = cio->start + pos;
 }
 
@@ -138,7 +140,7 @@ bool cio_byteout(opj_cio_t *cio, unsigned char v) {
  */
 unsigned char cio_bytein(opj_cio_t *cio) {
        if (cio->bp >= cio->end) {
-               opj_event_msg(cio->cinfo, EVT_ERROR, "read error\n");
+               opj_event_msg(cio->cinfo, EVT_ERROR, "read error: passed the end of the codestream (start = %d, current = %d, end = %d\n", cio->start, cio->bp, cio->end);
                return 0;
        }
        return *cio->bp++;