+# 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:
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)
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")
${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)
opj_image_destroy(image);
fclose(IN);
return NULL;
- break;
default:
for (i = 0; i < v; i++) {
v2 = getc(IN);
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);
}
}
fclose(fdest);
+ }
return 0;
}
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];
}
/* 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) {
"!! 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);
}
default:
fprintf(stderr, "Unknown output format image %s [only *.j2k, *.jp2]!! \n", outfile);
return 1;
- break;
}
strncpy(parameters->outfile, outfile, MAX_PATH);
}
/* ----------------------------------------------------- */
case 'h': /* display an help description */
- {
encode_help_display();
return 1;
- }
- break;
/* ----------------------------------------------------- */
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];
}
/* 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) {
"!! Unrecognized format for infile : %s [accept only *.j2k, *.jp2, *.jpc or *.jpt] !!\n\n",
infile);
return 1;
- break;
}
strncpy(parameters->infile, infile, MAX_PATH);
}
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);
}
/* ----------------------------------------------------- */
case 'h': /* display an help description */
- {
decode_help_display();
return 1;
- }
- break;
/* ----------------------------------------------------- */
default:
fprintf(stderr, "ERROR -> j2k_to_image : Unknown input image format\n");
return 1;
- break;
}
/* free the memory containing the code-stream */
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
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)
/* ----------------------------------------------------------------------- */
-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;
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 */
/*
* 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;
}
*
* 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;
}
/* ----------------------------------------------------------------------- */
-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;
+++ /dev/null
-/*
- * 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)) ;
-}
-
-
-
*/
#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 */
@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)) ;
+}
/*@}*/
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;
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) {
+++ /dev/null
-/*
- * 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;
-}
-
@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 */
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
<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;
+}
/* ----------------------------------------------------------------------- */
/*@}*/
@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);
/**
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);
/* 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 */
}
bool jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, char *index) {
- (void)image;
/* JP2 encoding */
/* 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;
}
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;
* 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;
return NULL;
}
break;
+ case CODEC_UNKNOWN:
default:
opj_free(dinfo);
return NULL;
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) {
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 */
}
}
-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:
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:
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;
return NULL;
}
break;
+ case CODEC_JPT:
+ case CODEC_UNKNOWN:
default:
opj_free(cinfo);
return NULL;
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) {
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 */
}
}
-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:
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;
}
}
#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)
/*
==========================================================
*/
-const char * opj_version();
+OPJ_API const char * OPJ_CALLCONV opj_version();
/*
==========================================================
@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);
/*
==========================================================
@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);
/*
==========================================================
==========================================================
*/
-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);
/*
==========================================================
@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>
</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
@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
}
==========================================================
*/
+/*
+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"
return pi_next_pcrl(pi);
case CPRL:
return pi_next_cprl(pi);
+ case PROG_UNKNOWN:
+ return false;
}
return false;
int passno;
int bpno, passtype;
int max;
- int nmsedec;
+ int nmsedec = 0;
double cumwmsedec = 0;
char type = T1_TYPE_MQ;
@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);
/*@}*/
}
}
-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;
dd = pass->distortiondec - cblk->passes[n - 1].distortiondec;
}
if (!dr) {
- if (dd)
+ if (dd != 0)
n = passno + 1;
continue;
}
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 */