]> Creatis software - gdcm.git/commitdiff
ENH: Try to keep up with the openjpeg build changes
authormalaterre <malaterre>
Sun, 5 Feb 2006 21:59:20 +0000 (21:59 +0000)
committermalaterre <malaterre>
Sun, 5 Feb 2006 21:59:20 +0000 (21:59 +0000)
23 files changed:
src/gdcmopenjpeg/CMakeLists.txt
src/gdcmopenjpeg/DartConfig.cmake
src/gdcmopenjpeg/codec/CMakeLists.txt
src/gdcmopenjpeg/codec/convert.c
src/gdcmopenjpeg/codec/image_to_j2k.c
src/gdcmopenjpeg/codec/j2k_to_image.c
src/gdcmopenjpeg/libopenjpeg/CMakeLists.txt
src/gdcmopenjpeg/libopenjpeg/cio.c
src/gdcmopenjpeg/libopenjpeg/event.c
src/gdcmopenjpeg/libopenjpeg/fix.c [deleted file]
src/gdcmopenjpeg/libopenjpeg/fix.h
src/gdcmopenjpeg/libopenjpeg/image.c
src/gdcmopenjpeg/libopenjpeg/int.c [deleted file]
src/gdcmopenjpeg/libopenjpeg/int.h
src/gdcmopenjpeg/libopenjpeg/jp2.c
src/gdcmopenjpeg/libopenjpeg/jp2.h
src/gdcmopenjpeg/libopenjpeg/openjpeg.c
src/gdcmopenjpeg/libopenjpeg/openjpeg.h
src/gdcmopenjpeg/libopenjpeg/opj_includes.h
src/gdcmopenjpeg/libopenjpeg/pi.c
src/gdcmopenjpeg/libopenjpeg/t1.c
src/gdcmopenjpeg/libopenjpeg/t2.c
src/gdcmopenjpeg/libopenjpeg/tcd.c

index c8f6e7c2afee99744cfab49acfd547616f880ae9..a2b8d36e92fb639e753860a6984662f4795c1972 100644 (file)
@@ -1,4 +1,17 @@
+# Main CMakeLists.txt to build the OpenJPEG project using CMake (www.cmake.org)
+# Written by Mathieu Malaterre
+
+# This CMake project will by default create a library called openjpeg
+# But if you want to use this project within your own (CMake) project
+# you will eventually like to prefix the library to avoid linking confusion
+# For this purpose you can define a CMake var: OPJ_PREFIX to whatever you like
+# e.g.:
+# SET(OPJ_PREFIX "gdcm")
+# Also if you want to test (CTest driven) you need to define :
+# OPJ_STANDALONE to 1, e.g
+# OPJ_STANDALONE:BOOL=1
 PROJECT(OPENJPEG C)
+CMAKE_MINIMUM_REQUIRED(VERSION 2.0)
 
 #-----------------------------------------------------------------------------
 # OPENJPEG version number, usefull for packaging and doxygen doc:
@@ -34,6 +47,8 @@ IF(OPJ_STANDALONE)
   MARK_AS_ADVANCED(BUILD_TESTING DART_ROOT TCL_TCLSH)
   IF(BUILD_TESTING)
     ENABLE_TESTING()
+    SET(BUILDNAME "OpenJPEG-${CMAKE_SYSTEM}-${CMAKE_C_COMPILER}" CACHE STRING "Name of build on the dashboard")
+    MARK_AS_ADVANCED(BUILDNAME)
   ENDIF(BUILD_TESTING)
 ENDIF(OPJ_STANDALONE)
 
index 421763f5ca7cd3672c8d1662fabfc86b38c1f131..20e6733950db104d139a7217b10fe7002d210146 100644 (file)
@@ -9,3 +9,14 @@ SET (DROP_LOCATION "/cgi-bin/HTTPUploadDartFile.cgi")
 SET (TRIGGER_SITE 
     "http://${DROP_SITE}/cgi-bin/Submit-Public-TestingResults.cgi")
 
+# Not used right now, since on public:
+# Project Home Page
+SET (PROJECT_URL "http://www.openjpeg.org")
+
+# Dart server configuration
+#SET (ROLLUP_URL "http://${DROP_SITE}/cgi-bin/openjpeg-rollup-dashboard.sh")
+SET (CVS_WEB_URL "http://euterpe.tele.ucl.ac.be/cgi-bin/viewcvs.cgi/")
+SET (CVS_WEB_CVSROOT "OpenJPEG")
+
+SET (USE_DOXYGEN "On")
+SET (DOXYGEN_URL "http://www.openjpeg.org/libdoc/index.html")
index ee496e33a488269a56ecdc65bccc5f21d02a3697..3f3c7d5a3f5a3521dab16c111d6700e2008abc70 100644 (file)
@@ -30,10 +30,17 @@ INCLUDE_DIRECTORIES(
   ${OPENJPEG_SOURCE_DIR}/libopenjpeg
   )
 
+# Do the proper thing when building static...if only there was configured
+# headers or def files instead
+IF(NOT BUILD_SHARED_LIBS)
+  ADD_DEFINITIONS(-DOPJ_STATIC)
+ENDIF(NOT BUILD_SHARED_LIBS)
+
 # Loop over all executables:
 FOREACH(exe j2k_to_image image_to_j2k)
   ADD_EXECUTABLE(${exe} ${exe}.c ${common_SRCS})
   TARGET_LINK_LIBRARIES(${exe} ${OPJ_PREFIX}openjpeg)
+  # On unix you need to link to the math library:
   IF(UNIX)
     TARGET_LINK_LIBRARIES(${exe} -lm)
   ENDIF(UNIX)
index 6e2ef095adbdf866d00783319ce712c7bff90fa9..fc7a17fac785b7a1ed69232f1f1e094c1b5dc068 100644 (file)
@@ -417,7 +417,6 @@ opj_image_t* bmptoimage(char *filename, opj_cparameters_t *parameters) {
               opj_image_destroy(image);
               fclose(IN);
               return NULL;
-              break;
             default:
               for (i = 0; i < v; i++) {
                 v2 = getc(IN);
@@ -597,7 +596,6 @@ int imagetobmp(opj_image_t * image, char *outfile) {
     fprintf(fdest, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff,  ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff);
     fprintf(fdest, "%c%c%c%c", (256) & 0xff, ((256) >> 8) & 0xff, ((256) >> 16) & 0xff, ((256) >> 24) & 0xff);
     fprintf(fdest, "%c%c%c%c", (256) & 0xff, ((256) >> 8) & 0xff, ((256) >> 16) & 0xff, ((256) >> 24) & 0xff);
-  }
 
   for (i = 0; i < 256; i++) {
     fprintf(fdest, "%c%c%c%c", i, i, i, 0);
@@ -615,6 +613,7 @@ int imagetobmp(opj_image_t * image, char *outfile) {
     }
   }
   fclose(fdest);
+  }
 
   return 0;
 }
index ca0503ddc55d53fdc5a3e1f702bfd1b00311f308..1df97e9c785ec941fdd0fad44ae8a6e73ad35dd6 100644 (file)
@@ -204,7 +204,7 @@ int get_file_format(char *filename) {
   static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp", "j2k", "jp2" };
   static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, J2K_CFMT, JP2_CFMT };
   char * ext = strrchr(filename, '.') + 1;
-  for(i = 0; i < sizeof(format); i++) {
+  for(i = 0; i < sizeof(format)/sizeof(*format); i++) {
     if(strnicmp(ext, extension[i], 3) == 0) {
       return format[i];
     }
@@ -221,7 +221,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
   /* parse the command line */
 
   while (1) {
-    int c = getopt(argc, argv, "i:o:r:q:f:t:n:c:b:x:p:s:d:h:P:S:E:M:R:T:C:I");
+    int c = getopt(argc, argv, "i:o:r:q:f:t:n:c:b:x:p:s:d:hP:S:E:M:R:T:C:I");
     if (c == -1)
       break;
     switch (c) {
@@ -239,7 +239,6 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
               "!! Unrecognized format for infile : %s [accept only *.pnm, *.pgm, *.ppm, *.pgx or *.bmp] !!\n\n", 
               infile);
             return 1;
-            break;
         }
         strncpy(parameters->infile, infile, MAX_PATH);
       }
@@ -258,7 +257,6 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
           default:
             fprintf(stderr, "Unknown output format image %s [only *.j2k, *.jp2]!! \n", outfile);
             return 1;
-            break;
         }
         strncpy(parameters->outfile, outfile, MAX_PATH);
       }
@@ -451,11 +449,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
         /* ----------------------------------------------------- */
       
       case 'h':      /* display an help description */
-      {
         encode_help_display();
         return 1;
-      }
-      break;
         
         /* ----------------------------------------------------- */
 
index 56d89ef789f0c550b67e4a3b4b2c66930e49c487..86324fd1895ddc41a3d366b8d887a20918841ef3 100644 (file)
@@ -92,7 +92,7 @@ int get_file_format(char *filename) {
   static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT };
   char * ext = strrchr(filename, '.') + 1;
   if(ext) {
-    for(i = 0; i < sizeof(format); i++) {
+    for(i = 0; i < sizeof(format)/sizeof(*format); i++) {
       if(strnicmp(ext, extension[i], 3) == 0) {
         return format[i];
       }
@@ -108,7 +108,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
   /* parse the command line */
 
   while (1) {
-    int c = getopt(argc, argv, "i:o:r:q:f:t:n:c:b:x:p:s:d:h:P:S:E:M:R:T:C:I");
+    int c = getopt(argc, argv, "i:o:r:q:f:t:n:c:b:x:p:s:d:hP:S:E:M:R:T:C:I");
     if (c == -1)
       break;
     switch (c) {
@@ -126,7 +126,6 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
               "!! Unrecognized format for infile : %s [accept only *.j2k, *.jp2, *.jpc or *.jpt] !!\n\n", 
               infile);
             return 1;
-            break;
         }
         strncpy(parameters->infile, infile, MAX_PATH);
       }
@@ -146,7 +145,6 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
           default:
             fprintf(stderr, "Unknown output format image %s [only *.pnm, *.pgm, *.ppm, *.pgx or *.bmp]!! \n", outfile);
             return 1;
-            break;
         }
         strncpy(parameters->outfile, outfile, MAX_PATH);
       }
@@ -173,11 +171,8 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
         /* ----------------------------------------------------- */
       
       case 'h':       /* display an help description */
-      {
         decode_help_display();
         return 1;
-      }
-      break;
             
         /* ----------------------------------------------------- */
       
@@ -360,7 +355,6 @@ int main(int argc, char **argv) {
     default:
       fprintf(stderr, "ERROR -> j2k_to_image : Unknown input image format\n");
       return 1;
-      break;
   }
   
   /* free the memory containing the code-stream */
index 08a072edfaa98edbedeac0a22bd270f97092db46..62a5e52e143fb3f1f7e872c6291dd565cc763d9b 100644 (file)
@@ -1,13 +1,11 @@
 INCLUDE_REGULAR_EXPRESSION("^.*$")
-# Create the lib
-SET(openjpeg_SRCS
+# Defines the source code for the library
+SET(OpenJPEG_SRCS
   bio.c
   cio.c
   dwt.c
   event.c
-  fix.c
   image.c
-  int.c
   j2k.c
   j2k_lib.c
   jp2.c
@@ -23,13 +21,18 @@ SET(openjpeg_SRCS
   tgt.c
 )
 
+# Pass proper definition to preprocessor to generate shared lib
 IF (WIN32)
   IF (BUILD_SHARED_LIBS)
-    ADD_DEFINITIONS(-DOPJ_SHARED)
+    ADD_DEFINITIONS(-DOPJ_EXPORTS)
   ELSE (BUILD_SHARED_LIBS)
     ADD_DEFINITIONS(-DOPJ_STATIC)
   ENDIF (BUILD_SHARED_LIBS)
 ENDIF (WIN32)
 
-ADD_LIBRARY(${OPJ_PREFIX}openjpeg ${openjpeg_SRCS})
+# Create the library
+ADD_LIBRARY(${OPJ_PREFIX}openjpeg ${OpenJPEG_SRCS})
+
+# Install library
+INSTALL_TARGETS(/lib/ ${OPJ_PREFIX}openjpeg)
 
index 4264fccee9603f7b05e20085e7fa78024bee8856..146c5d3d460bdcd2ccb5393ff5efb6ae20227195 100644 (file)
@@ -32,7 +32,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;
@@ -77,7 +77,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 +94,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 +103,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;
 }
 
index 7e7c52f2589fe589008235e13679a7485299233c..57e1e3b6c1e8725abc5550083a2168f62041401c 100644 (file)
@@ -61,7 +61,7 @@ _itoa(int i, char *a, int r) {
 
 /* ----------------------------------------------------------------------- */
 
-opj_event_mgr_t* opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context) {
+opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context) {
   if(cinfo) {
     opj_event_mgr_t *previous = cinfo->event_mgr;
     cinfo->event_mgr = event_mgr;
diff --git a/src/gdcmopenjpeg/libopenjpeg/fix.c b/src/gdcmopenjpeg/libopenjpeg/fix.c
deleted file mode 100644 (file)
index e9ba82b..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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
- * 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.
- */
-
-#include "fix.h"
-
-#if defined(_MSC_VER) || defined(__BORLANDC__)
-#define int64 __int64
-#else
-#define int64 long long
-#endif
-
-int fix_mul(int a, int b) {
-    int64 temp = (int64) a * (int64) b >> 12;
-    return (int) ((temp >> 1) + (temp & 1)) ;
-}
-
-
-
index b5b62e67bef224f3084f277b50a91c57a341f3c9..85575cbcee9f2caff698e434c3d13253229253d5 100644 (file)
  */
 #ifndef __FIX_H
 #define __FIX_H
+
+#if defined(_MSC_VER) || defined(__BORLANDC__)
+#define int64 __int64
+#else
+#define int64 long long
+#endif
+
 /**
 @file fix.h
 @brief Implementation of operations of specific multiplication (FIX)
 
-The functions in FIX.C have for goal to realize specific multiplication.
+The functions in FIX.H have for goal to realize specific multiplication.
 */
 
 /** @defgroup FIX FIX - Implementation of operations of specific multiplication */
@@ -45,7 +52,10 @@ Multiply two fixed-precision rational numbers.
 @param b
 @return Returns a * b
 */
-int fix_mul(int a, int b);
+static INLINE int fix_mul(int a, int b) {
+    int64 temp = (int64) a * (int64) b >> 12;
+    return (int) ((temp >> 1) + (temp & 1)) ;
+}
 
 /*@}*/
 
index 576701b25dc9612b2aa61f41d8ccdcb9f32e37ee..69267eed3cbdbd1d18b45b840a3ac6ace12bdf22 100644 (file)
@@ -31,7 +31,7 @@ opj_image_t* opj_image_create0() {
   return image;
 }
 
-opj_image_t *opj_image_create(int numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) {
+opj_image_t* OPJ_CALLCONV opj_image_create(int numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) {
   int compno;
   opj_image_t *image = NULL;
 
@@ -68,7 +68,7 @@ opj_image_t *opj_image_create(int numcmpts, opj_image_cmptparm_t *cmptparms, OPJ
   return image;
 }
 
-void opj_image_destroy(opj_image_t *image) {
+void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) {
   int i;
   if(image) {
     if(image->comps) {
diff --git a/src/gdcmopenjpeg/libopenjpeg/int.c b/src/gdcmopenjpeg/libopenjpeg/int.c
deleted file mode 100644 (file)
index f27726f..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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
- * 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.
- */
-
-#include "opj_includes.h"
-
-int int_min(int a, int b) {
-  return a < b ? a : b;
-}
-
-int int_max(int a, int b) {
-  return (a > b) ? a : b;
-}
-
-int int_clamp(int a, int min, int max) {
-  if (a < min)
-    return min;
-  if (a > max)
-    return max;
-  return a;
-}
-
-int int_abs(int a) {
-  return a < 0 ? -a : a;
-}
-
-int int_ceildiv(int a, int b) {
-  return (a + b - 1) / b;
-}
-
-int int_ceildivpow2(int a, int b) {
-  return (a + (1 << b) - 1) >> b;
-}
-
-int int_floordivpow2(int a, int b) {
-  return a >> b;
-}
-
-int int_floorlog2(int a) {
-  int l;
-  for (l = 0; a > 1; l++) {
-    a >>= 1;
-  }
-  return l;
-}
-
index aff0905fb0bd4694e1aaff9440e9dadd1ac6a225..3195cccc4499747bd631112a70298ad63f514566 100644 (file)
@@ -33,7 +33,7 @@
 @file int.h
 @brief Implementation of operations on integers (INT)
 
-The functions in INT.C have for goal to realize operations on integers.
+The functions in INT.H have for goal to realize operations on integers.
 */
 
 /** @defgroup INT INT - Implementation of operations on integers */
@@ -46,12 +46,16 @@ The functions in INT.C have for goal to realize operations on integers.
 Get the minimum of two integers
 @return Returns a if a < b else b
 */
-int int_min(int a, int b);
+static INLINE int int_min(int a, int b) {
+  return a < b ? a : b;
+}
 /**
 Get the maximum of two integers
 @return Returns a if a > b else b
 */
-int int_max(int a, int b);
+static INLINE int int_max(int a, int b) {
+  return (a > b) ? a : b;
+}
 /**
 Clamp an integer inside an interval
 @return
@@ -61,32 +65,51 @@ Clamp an integer inside an interval
 <li>Returns min if (a < min) 
 </ul>
 */
-int int_clamp(int a, int min, int max);
+static INLINE int int_clamp(int a, int min, int max) {
+  if (a < min)
+    return min;
+  if (a > max)
+    return max;
+  return a;
+}
 /**
 @return Get absolute value of integer
 */
-int int_abs(int a);
+static INLINE int int_abs(int a) {
+  return a < 0 ? -a : a;
+}
 /**
 Divide an integer and round upwards
 @return Returns a divided by b
 */
-int int_ceildiv(int a, int b);
+static INLINE int int_ceildiv(int a, int b) {
+  return (a + b - 1) / b;
+}
 /**
 Divide an integer by a power of 2 and round upwards
 @return Returns a divided by 2^b
 */
-int int_ceildivpow2(int a, int b);
+static INLINE int int_ceildivpow2(int a, int b) {
+  return (a + (1 << b) - 1) >> b;
+}
 /**
 Divide an integer by a power of 2 and round downwards
 @return Returns a divided by 2^b
 */
-int int_floordivpow2(int a, int b);
+static INLINE int int_floordivpow2(int a, int b) {
+  return a >> b;
+}
 /**
 Get logarithm of an integer and round downwards
 @return Returns log2(a)
 */
-int int_floorlog2(int a);
-
+static INLINE int int_floorlog2(int a) {
+  int l;
+  for (l = 0; a > 1; l++) {
+    a >>= 1;
+  }
+  return l;
+}
 /* ----------------------------------------------------------------------- */
 /*@}*/
 
index 29aa311e687c8efd9c8ddae1535b152309c2b08a..7f6988d33a1ad8e3933e0d57c848f32a3aefe968 100644 (file)
@@ -81,7 +81,7 @@ Read the FTYP box - File type box
 @return Returns true if successful, returns false otherwise
 */
 static bool jp2_read_ftyp(opj_jp2_t *jp2, opj_cio_t *cio);
-static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, char *index);
+static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, char *index);
 static bool jp2_read_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, unsigned int *j2k_codestream_length, unsigned int *j2k_codestream_offset);
 static void jp2_write_jp(opj_cio_t *cio);
 /**
@@ -414,12 +414,11 @@ static bool jp2_read_ftyp(opj_jp2_t *jp2, opj_cio_t *cio) {
   return true;
 }
 
-static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, char *index) {
+static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, char *index) {
   unsigned int j2k_codestream_offset, j2k_codestream_length;
   opj_jp2_box_t box;
 
   opj_j2k_t *j2k = jp2->j2k;
-  opj_image_t *image = jp2->image;
 
   box.init_pos = cio_tell(cio);
   cio_skip(cio, 4);
@@ -635,8 +634,6 @@ void jp2_setup_encoder(opj_jp2_t *jp2, opj_cparameters_t *parameters, opj_image_
 
   /* Image Header box */
 
-  jp2->image = image;
-
   jp2->numcomps = image->numcomps;  /* NC */
   jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp2_comps_t));
   jp2->h = image->y1 - image->y0;    /* HEIGHT */
@@ -684,7 +681,6 @@ void jp2_setup_encoder(opj_jp2_t *jp2, opj_cparameters_t *parameters, opj_image_
 }
 
 bool jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, char *index) {
-  (void)image;
 
   /* JP2 encoding */
 
@@ -697,7 +693,7 @@ bool jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, char *index)
 
   /* J2K encoding */
 
-  if(!jp2_write_jp2c(jp2, cio, index)) {
+  if(!jp2_write_jp2c(jp2, cio, image, index)) {
     opj_event_msg(jp2->cinfo, EVT_ERROR, "Failed to encode image\n");
     return false;
   }
index 133caee475cffee4ff2148cfbab3637b6c30a01b..12ac455f961f2ca4d6ccc354f26fdbd972d7055b 100644 (file)
@@ -84,7 +84,6 @@ typedef struct opj_jp2 {
   unsigned int numcl;
   unsigned int *cl;
   opj_jp2_comps_t *comps;
-  opj_image_t *image;
   unsigned int j2k_codestream_offset;
   unsigned int j2k_codestream_length;
 } opj_jp2_t;
index 9f872e4752ca3d040635c7b785b17143e0eb2984..6097cdbafdbb708a2b8441799325b44eed9dccc0 100644 (file)
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifdef WIN32
+#include <windows.h>
+#endif /* WIN32 */
+
 #include "opj_includes.h"
 
-const char * opj_version() {
+/* ---------------------------------------------------------------------- */
+#ifdef WIN32
+#ifndef OPJ_STATIC
+BOOL APIENTRY
+DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
+  switch (ul_reason_for_call) {
+    case DLL_PROCESS_ATTACH :
+      break;
+    case DLL_PROCESS_DETACH :
+      break;
+    case DLL_THREAD_ATTACH :
+    case DLL_THREAD_DETACH :
+      break;
+    }
+
+    return TRUE;
+}
+#endif /* OPJ_STATIC */
+#endif /* WIN32 */
+
+/* ---------------------------------------------------------------------- */
+
+
+const char* OPJ_CALLCONV opj_version() {
     return OPENJPEG_VERSION;
 }
 
-opj_dinfo_t* opj_create_decompress(OPJ_CODEC_FORMAT format) {
+opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) {
   opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_malloc(sizeof(opj_dinfo_t));
   if(!dinfo) return NULL;
   dinfo->is_decompressor = true;
@@ -52,6 +79,7 @@ opj_dinfo_t* opj_create_decompress(OPJ_CODEC_FORMAT format) {
         return NULL;
       }
       break;
+    case CODEC_UNKNOWN:
     default:
       opj_free(dinfo);
       return NULL;
@@ -62,7 +90,7 @@ opj_dinfo_t* opj_create_decompress(OPJ_CODEC_FORMAT format) {
   return dinfo;
 }
 
-void opj_destroy_decompress(opj_dinfo_t *dinfo) {
+void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo) {
   if(dinfo) {
     /* destroy the codec */
     switch(dinfo->codec_format) {
@@ -73,13 +101,16 @@ void opj_destroy_decompress(opj_dinfo_t *dinfo) {
       case CODEC_JP2:
         jp2_destroy_decompress((opj_jp2_t*)dinfo->jp2_handle);
         break;
+      case CODEC_UNKNOWN:
+      default:
+        break;
     }
     /* destroy the decompressor */
     opj_free(dinfo);
   }
 }
 
-void opj_set_default_decoder_parameters(opj_dparameters_t *parameters) {
+void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters) {
   if(parameters) {
     memset(parameters, 0, sizeof(opj_dparameters_t));
     /* default decoding parameters */
@@ -91,7 +122,7 @@ void opj_set_default_decoder_parameters(opj_dparameters_t *parameters) {
   }
 }
 
-void opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters) {
+void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters) {
   if(dinfo && parameters) {
     switch(dinfo->codec_format) {
       case CODEC_J2K:
@@ -101,11 +132,14 @@ void opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters) {
       case CODEC_JP2:
         jp2_setup_decoder((opj_jp2_t*)dinfo->jp2_handle, parameters);
         break;
+      case CODEC_UNKNOWN:
+      default:
+        break;
     }
   }
 }
 
-opj_image_t* opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) {
+opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) {
   if(dinfo && cio) {
     switch(dinfo->codec_format) {
       case CODEC_J2K:
@@ -114,13 +148,16 @@ opj_image_t* opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) {
         return j2k_decode_jpt_stream((opj_j2k_t*)dinfo->j2k_handle, cio);
       case CODEC_JP2:
         return jp2_decode((opj_jp2_t*)dinfo->jp2_handle, cio);
+      case CODEC_UNKNOWN:
+      default:
+        break;
     }
   }
 
   return NULL;
 }
 
-opj_cinfo_t* opj_create_compress(OPJ_CODEC_FORMAT format) {
+opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format) {
   opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_malloc(sizeof(opj_cinfo_t));
   if(!cinfo) return NULL;
   cinfo->is_decompressor = false;
@@ -141,6 +178,8 @@ opj_cinfo_t* opj_create_compress(OPJ_CODEC_FORMAT format) {
         return NULL;
       }
       break;
+    case CODEC_JPT:
+    case CODEC_UNKNOWN:
     default:
       opj_free(cinfo);
       return NULL;
@@ -151,7 +190,7 @@ opj_cinfo_t* opj_create_compress(OPJ_CODEC_FORMAT format) {
   return cinfo;
 }
 
-void opj_destroy_compress(opj_cinfo_t *cinfo) {
+void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo) {
   if(cinfo) {
     /* destroy the codec */
     switch(cinfo->codec_format) {
@@ -161,13 +200,17 @@ void opj_destroy_compress(opj_cinfo_t *cinfo) {
       case CODEC_JP2:
         jp2_destroy_decompress((opj_jp2_t*)cinfo->jp2_handle);
         break;
+      case CODEC_JPT:
+      case CODEC_UNKNOWN:
+      default:
+        break;
     }
     /* destroy the decompressor */
     opj_free(cinfo);
   }
 }
 
-void opj_set_default_encoder_parameters(opj_cparameters_t *parameters) {
+void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters) {
   if(parameters) {
     memset(parameters, 0, sizeof(opj_cparameters_t));
     /* default coding parameters */
@@ -184,7 +227,7 @@ void opj_set_default_encoder_parameters(opj_cparameters_t *parameters) {
   }
 }
 
-void opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image) {
+void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image) {
   if(cinfo && parameters && image) {
     switch(cinfo->codec_format) {
       case CODEC_J2K:
@@ -193,17 +236,25 @@ void opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_im
       case CODEC_JP2:
         jp2_setup_encoder((opj_jp2_t*)cinfo->jp2_handle, parameters, image);
         break;
+      case CODEC_JPT:
+      case CODEC_UNKNOWN:
+      default:
+        break;
     }
   }
 }
 
-bool opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index) {
+bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index) {
   if(cinfo && cio && image) {
     switch(cinfo->codec_format) {
       case CODEC_J2K:
         return j2k_encode((opj_j2k_t*)cinfo->j2k_handle, cio, image, index);
       case CODEC_JP2:
         return jp2_encode((opj_jp2_t*)cinfo->jp2_handle, cio, image, index);
+      case CODEC_JPT:
+      case CODEC_UNKNOWN:
+      default:
+        break;
     }
   }
 
index d7f7413294dfdbc69366e629b6d1f8bda5d052b5..641b3d6f334d10a3e7141e286f81827647df84d4 100644 (file)
 
 #define OPENJPEG_VERSION "1.0.0"
 
-#if defined(_WIN32) && !defined (OPJ_STATIC)
-#ifdef OPJ_SHARED
-#define OPJ_EXPORT __declspec(dllexport)
-#else
-#define OPJ_EXPORT __declspec(dllimport)
-#endif
-#else
-#ifdef OPJ_STATIC
-#define OPJ_EXPORT extern
-#else
-#define OPJ_EXPORT
-#endif
-#endif
-
 /* 
 ==========================================================
    Compiler directives
 ==========================================================
 */
+
+#if defined(OPJ_STATIC) || !(defined(WIN32) || defined(__WIN32__))
+#define OPJ_API
+#define OPJ_CALLCONV
+#else
+#define OPJ_CALLCONV __stdcall
+/*
+The following ifdef block is the standard way of creating macros which make exporting 
+from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS
+symbol defined on the command line. this symbol should not be defined on any project
+that uses this DLL. This way any other project whose source files include this file see 
+OPJ_API functions as being imported from a DLL, wheras this DLL sees symbols
+defined with this macro as being exported.
+*/
+#ifdef OPJ_EXPORTS
+#define OPJ_API __declspec(dllexport)
+#else
+#define OPJ_API __declspec(dllimport)
+#endif /* OPJ_EXPORTS */
+#endif /* !OPJ_STATIC || !WIN32 */
+
 #ifndef __cplusplus
 #if defined(HAVE_STDBOOL_H)
 /*
@@ -460,7 +467,7 @@ extern "C" {
 ==========================================================
 */
 
-const char * opj_version();
+OPJ_API const char * OPJ_CALLCONV opj_version();
 
 /* 
 ==========================================================
@@ -475,13 +482,13 @@ Create an image
 @param clrspc image color space
 @return returns a new image structure if successful, returns NULL otherwise
 */
-OPJ_EXPORT opj_image_t *opj_image_create(int numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
+OPJ_API opj_image_t* OPJ_CALLCONV opj_image_create(int numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
 
 /**
 Deallocate any resources associated with an image
 @param image image to be destroyed
 */
-OPJ_EXPORT void opj_image_destroy(opj_image_t *image);
+OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image);
 
 /* 
 ==========================================================
@@ -500,26 +507,26 @@ to contain encoded data.
 @param length Reading: buffer length. Writing: 0
 @return Returns a CIO handle if successful, returns NULL otherwise
 */
-OPJ_EXPORT opj_cio_t* opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length);
+OPJ_API opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length);
 
 /**
 Close and free a CIO handle
 @param cio CIO handle to free
 */
-OPJ_EXPORT void opj_cio_close(opj_cio_t *cio);
+OPJ_API void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio);
 
 /**
 Get position in byte stream
 @param cio CIO handle
 @return Returns the position in bytes
 */
-OPJ_EXPORT int cio_tell(opj_cio_t *cio);
+OPJ_API int OPJ_CALLCONV cio_tell(opj_cio_t *cio);
 /**
 Set position in byte stream
 @param cio CIO handle
 @param pos Position, in number of bytes, from the beginning of the stream
 */
-void cio_seek(opj_cio_t *cio, int pos);
+OPJ_API void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos);
 
 /* 
 ==========================================================
@@ -527,7 +534,7 @@ void cio_seek(opj_cio_t *cio, int pos);
 ==========================================================
 */
 
-OPJ_EXPORT opj_event_mgr_t* opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context);
+OPJ_API opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context);
 
 /* 
 ==========================================================
@@ -539,42 +546,42 @@ Creates a J2K/JPT/JP2 decompression structure
 @param format Decoder to select
 @return Returns a handle to a decompressor if successful, returns NULL otherwise
 */
-OPJ_EXPORT opj_dinfo_t* opj_create_decompress(OPJ_CODEC_FORMAT format);
+OPJ_API opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format);
 /**
 Destroy a decompressor handle
 @param dinfo decompressor handle to destroy
 */
-OPJ_EXPORT void opj_destroy_decompress(opj_dinfo_t *dinfo);
+OPJ_API void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo);
 /**
 Set decoding parameters to default values
 @param parameters Decompression parameters
 */
-OPJ_EXPORT void opj_set_default_decoder_parameters(opj_dparameters_t *parameters);
+OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters);
 /**
 Setup the decoder decoding parameters using user parameters.
 Decoding parameters are returned in j2k->cp. 
 @param dinfo decompressor handle
 @param parameters decompression parameters
 */
-OPJ_EXPORT void opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters);
+OPJ_API void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters);
 /**
 Decode an image from a JPEG-2000 codestream
 @param dinfo decompressor handle
 @param cio Input buffer stream
 @return Returns a decoded image if successful, returns NULL otherwise
 */
-OPJ_EXPORT opj_image_t* opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio);
+OPJ_API opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio);
 /**
 Creates a J2K/JP2 compression structure
 @param format Coder to select
 @return Returns a handle to a compressor if successful, returns NULL otherwise
 */
-OPJ_EXPORT opj_cinfo_t* opj_create_compress(OPJ_CODEC_FORMAT format);
+OPJ_API opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
 /**
 Destroy a compressor handle
 @param cinfo compressor handle to destroy
 */
-OPJ_EXPORT void opj_destroy_compress(opj_cinfo_t *cinfo);
+OPJ_API void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo);
 /**
 Set encoding parameters to default values, that means : 
 <ul>
@@ -596,14 +603,14 @@ Set encoding parameters to default values, that means :
 </ul>
 @param parameters Compression parameters
 */
-OPJ_EXPORT void opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
+OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
 /**
 Setup the encoder parameters using the current image and using user parameters. 
 @param cinfo compressor handle
 @param parameters compression parameters
 @param image input filled image
 */
-OPJ_EXPORT void opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image);
+OPJ_API void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image);
 /**
 Encode an image into a JPEG-2000 codestream
 @param cinfo compressor handle
@@ -612,7 +619,7 @@ Encode an image into a JPEG-2000 codestream
 @param index Name of the index file if required, NULL otherwise
 @return Returns true if successful, returns false otherwise
 */
-OPJ_EXPORT bool opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index);
+OPJ_API bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index);
 
 #ifdef __cplusplus
 }
index 565131eebaa48476a29ad1c9940940d7010b31b0..13240323cc9f30901c5005acf3d5fcba9f0ef2fd 100644 (file)
  ==========================================================
 */
 
+/*
+The inline keyword is supported by C99 but not by C90. 
+Most compilers implement their own version of this keyword ... 
+*/
+#ifndef INLINE
+  #if defined(_MSC_VER)
+    #define INLINE __inline
+  #elif defined(__GNUC__)
+    #define INLINE __inline__
+  #elif defined(__MWERKS__)
+    #define INLINE inline
+  #else 
+    /* add other compilers here ... */
+    #define INLINE 
+  #endif /* defined(<Compiler>) */
+#endif /* INLINE */
+
 #include "j2k_lib.h"
 #include "event.h"
 #include "cio.h"
index f5d170a0ce0f213ed43054529e7d679f9c57001d..589124474d285f2bcf27c652bafb241b1e3cf377 100644 (file)
@@ -545,6 +545,8 @@ bool pi_next(opj_pi_iterator_t * pi) {
       return pi_next_pcrl(pi);
     case CPRL:
       return pi_next_cprl(pi);
+    case PROG_UNKNOWN:
+      return false;
   }
   
   return false;
index 1f153a18ff3a8c0e449cefd846f4665d9c4ec05c..49651fe9bfbc0857dc0c0b99af7f3229063fdb6e 100644 (file)
@@ -524,7 +524,7 @@ static void t1_encode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int
   int passno;
   int bpno, passtype;
   int max;
-  int nmsedec;
+  int nmsedec = 0;
   double cumwmsedec = 0;
   char type = T1_TYPE_MQ;
   
index 5d61ed31d51411cf0bd301494a0b297ee4ba1a62..fc30aa8f66ac8247e950b68dda45b6af9ef8ce13 100644 (file)
@@ -73,7 +73,7 @@ Decode a packet of a tile from a source buffer
 @param pi Packet identity
 @return 
 */
-int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi);
+static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi);
 
 /*@}*/
 
@@ -308,7 +308,7 @@ static void t2_init_seg(opj_tcd_seg_t * seg, int cblksty, int first) {
   }
 }
 
-int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi) {
+static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi) {
   int bandno, cblkno;
   unsigned char *c = src;
 
index 763ab67eb26953a6317a847468979cd32c7ea01b..abd0d620d89a7442a3ba14bd61a6aa88a585d29c 100644 (file)
@@ -945,7 +945,7 @@ void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final) {
                 dd = pass->distortiondec - cblk->passes[n - 1].distortiondec;
               }
               if (!dr) {
-                if (dd)
+                if (dd != 0)
                   n = passno + 1;
                 continue;
               }
@@ -1056,7 +1056,7 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_in
     double hi = max;
     int success = 0;
     int maxlen = tcd_tcp->rates[layno] ? int_min(tcd_tcp->rates[layno], len) : len;
-    double goodthresh;
+    double goodthresh = 0;
     int i;
     double distotarget;    /* fixed_quality */