From: malaterre Date: Sun, 5 Feb 2006 21:59:20 +0000 (+0000) Subject: ENH: Try to keep up with the openjpeg build changes X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=bba4d4f75b6c5e373de1a555b7eaadfba961eaaa;p=gdcm.git ENH: Try to keep up with the openjpeg build changes --- diff --git a/src/gdcmopenjpeg/CMakeLists.txt b/src/gdcmopenjpeg/CMakeLists.txt index c8f6e7c2..a2b8d36e 100644 --- a/src/gdcmopenjpeg/CMakeLists.txt +++ b/src/gdcmopenjpeg/CMakeLists.txt @@ -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) diff --git a/src/gdcmopenjpeg/DartConfig.cmake b/src/gdcmopenjpeg/DartConfig.cmake index 421763f5..20e67339 100644 --- a/src/gdcmopenjpeg/DartConfig.cmake +++ b/src/gdcmopenjpeg/DartConfig.cmake @@ -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") diff --git a/src/gdcmopenjpeg/codec/CMakeLists.txt b/src/gdcmopenjpeg/codec/CMakeLists.txt index ee496e33..3f3c7d5a 100644 --- a/src/gdcmopenjpeg/codec/CMakeLists.txt +++ b/src/gdcmopenjpeg/codec/CMakeLists.txt @@ -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) diff --git a/src/gdcmopenjpeg/codec/convert.c b/src/gdcmopenjpeg/codec/convert.c index 6e2ef095..fc7a17fa 100644 --- a/src/gdcmopenjpeg/codec/convert.c +++ b/src/gdcmopenjpeg/codec/convert.c @@ -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; } diff --git a/src/gdcmopenjpeg/codec/image_to_j2k.c b/src/gdcmopenjpeg/codec/image_to_j2k.c index ca0503dd..1df97e9c 100644 --- a/src/gdcmopenjpeg/codec/image_to_j2k.c +++ b/src/gdcmopenjpeg/codec/image_to_j2k.c @@ -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; /* ----------------------------------------------------- */ diff --git a/src/gdcmopenjpeg/codec/j2k_to_image.c b/src/gdcmopenjpeg/codec/j2k_to_image.c index 56d89ef7..86324fd1 100644 --- a/src/gdcmopenjpeg/codec/j2k_to_image.c +++ b/src/gdcmopenjpeg/codec/j2k_to_image.c @@ -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 */ diff --git a/src/gdcmopenjpeg/libopenjpeg/CMakeLists.txt b/src/gdcmopenjpeg/libopenjpeg/CMakeLists.txt index 08a072ed..62a5e52e 100644 --- a/src/gdcmopenjpeg/libopenjpeg/CMakeLists.txt +++ b/src/gdcmopenjpeg/libopenjpeg/CMakeLists.txt @@ -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) diff --git a/src/gdcmopenjpeg/libopenjpeg/cio.c b/src/gdcmopenjpeg/libopenjpeg/cio.c index 4264fcce..146c5d3d 100644 --- a/src/gdcmopenjpeg/libopenjpeg/cio.c +++ b/src/gdcmopenjpeg/libopenjpeg/cio.c @@ -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; } diff --git a/src/gdcmopenjpeg/libopenjpeg/event.c b/src/gdcmopenjpeg/libopenjpeg/event.c index 7e7c52f2..57e1e3b6 100644 --- a/src/gdcmopenjpeg/libopenjpeg/event.c +++ b/src/gdcmopenjpeg/libopenjpeg/event.c @@ -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 index e9ba82be..00000000 --- a/src/gdcmopenjpeg/libopenjpeg/fix.c +++ /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)) ; -} - - - diff --git a/src/gdcmopenjpeg/libopenjpeg/fix.h b/src/gdcmopenjpeg/libopenjpeg/fix.h index b5b62e67..85575cbc 100644 --- a/src/gdcmopenjpeg/libopenjpeg/fix.h +++ b/src/gdcmopenjpeg/libopenjpeg/fix.h @@ -29,11 +29,18 @@ */ #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)) ; +} /*@}*/ diff --git a/src/gdcmopenjpeg/libopenjpeg/image.c b/src/gdcmopenjpeg/libopenjpeg/image.c index 576701b2..69267eed 100644 --- a/src/gdcmopenjpeg/libopenjpeg/image.c +++ b/src/gdcmopenjpeg/libopenjpeg/image.c @@ -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 index f27726f9..00000000 --- a/src/gdcmopenjpeg/libopenjpeg/int.c +++ /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; -} - diff --git a/src/gdcmopenjpeg/libopenjpeg/int.h b/src/gdcmopenjpeg/libopenjpeg/int.h index aff0905f..3195cccc 100644 --- a/src/gdcmopenjpeg/libopenjpeg/int.h +++ b/src/gdcmopenjpeg/libopenjpeg/int.h @@ -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
  • Returns min if (a < min) */ -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; +} /* ----------------------------------------------------------------------- */ /*@}*/ diff --git a/src/gdcmopenjpeg/libopenjpeg/jp2.c b/src/gdcmopenjpeg/libopenjpeg/jp2.c index 29aa311e..7f6988d3 100644 --- a/src/gdcmopenjpeg/libopenjpeg/jp2.c +++ b/src/gdcmopenjpeg/libopenjpeg/jp2.c @@ -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; } diff --git a/src/gdcmopenjpeg/libopenjpeg/jp2.h b/src/gdcmopenjpeg/libopenjpeg/jp2.h index 133caee4..12ac455f 100644 --- a/src/gdcmopenjpeg/libopenjpeg/jp2.h +++ b/src/gdcmopenjpeg/libopenjpeg/jp2.h @@ -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; diff --git a/src/gdcmopenjpeg/libopenjpeg/openjpeg.c b/src/gdcmopenjpeg/libopenjpeg/openjpeg.c index 9f872e47..6097cdba 100644 --- a/src/gdcmopenjpeg/libopenjpeg/openjpeg.c +++ b/src/gdcmopenjpeg/libopenjpeg/openjpeg.c @@ -24,13 +24,40 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#ifdef WIN32 +#include +#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; } } diff --git a/src/gdcmopenjpeg/libopenjpeg/openjpeg.h b/src/gdcmopenjpeg/libopenjpeg/openjpeg.h index d7f74132..641b3d6f 100644 --- a/src/gdcmopenjpeg/libopenjpeg/openjpeg.h +++ b/src/gdcmopenjpeg/libopenjpeg/openjpeg.h @@ -32,25 +32,32 @@ #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 :
      @@ -596,14 +603,14 @@ Set encoding parameters to default values, that means :
    @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 } diff --git a/src/gdcmopenjpeg/libopenjpeg/opj_includes.h b/src/gdcmopenjpeg/libopenjpeg/opj_includes.h index 565131ee..13240323 100644 --- a/src/gdcmopenjpeg/libopenjpeg/opj_includes.h +++ b/src/gdcmopenjpeg/libopenjpeg/opj_includes.h @@ -54,6 +54,23 @@ ========================================================== */ +/* +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() */ +#endif /* INLINE */ + #include "j2k_lib.h" #include "event.h" #include "cio.h" diff --git a/src/gdcmopenjpeg/libopenjpeg/pi.c b/src/gdcmopenjpeg/libopenjpeg/pi.c index f5d170a0..58912447 100644 --- a/src/gdcmopenjpeg/libopenjpeg/pi.c +++ b/src/gdcmopenjpeg/libopenjpeg/pi.c @@ -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; diff --git a/src/gdcmopenjpeg/libopenjpeg/t1.c b/src/gdcmopenjpeg/libopenjpeg/t1.c index 1f153a18..49651fe9 100644 --- a/src/gdcmopenjpeg/libopenjpeg/t1.c +++ b/src/gdcmopenjpeg/libopenjpeg/t1.c @@ -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; diff --git a/src/gdcmopenjpeg/libopenjpeg/t2.c b/src/gdcmopenjpeg/libopenjpeg/t2.c index 5d61ed31..fc30aa8f 100644 --- a/src/gdcmopenjpeg/libopenjpeg/t2.c +++ b/src/gdcmopenjpeg/libopenjpeg/t2.c @@ -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; diff --git a/src/gdcmopenjpeg/libopenjpeg/tcd.c b/src/gdcmopenjpeg/libopenjpeg/tcd.c index 763ab67e..abd0d620 100644 --- a/src/gdcmopenjpeg/libopenjpeg/tcd.c +++ b/src/gdcmopenjpeg/libopenjpeg/tcd.c @@ -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 */