backport rev[824-834] and rev[837-859] into the openjpeg-1.5 branch

This commit is contained in:
Mickael Savinaud 2011-08-11 10:18:02 +00:00
commit 2724f85cad
39 changed files with 2372 additions and 537 deletions

View File

@ -5,6 +5,9 @@ What's New for OpenJPEG
! : changed ! : changed
+ : added + : added
August 11, 2011
! [mickael] backport rev[824-834] and rev[837-859] into the openjpeg-1.5 branch
August 9, 2011 August 9, 2011
- [antonin] removed xcode project files (cmake and autotools are now the only supported build methods) - [antonin] removed xcode project files (cmake and autotools are now the only supported build methods)

View File

@ -1,15 +1,30 @@
# #
# For further details regarding this file, # Note that the ITK/CMakeLists.txt file configures this file
# see http://www.vtk.org/Wiki/CMake_Testing_With_CTest#Customizing_CTest
# #
# CMake/CTestCustom.cmake.in
#
# to this file
#
# ${ITK_BINARY_DIR}/CTestCustom.cmake
#
#----------------------------------------------------------------------
#
# For further details regarding this file,
# see http://www.cmake.org/Wiki/CMake_Testing_With_CTest#Customizing_CTest
#
# and
# http://www.kitware.com/blog/home/post/27
#
#----------------------------------------------------------------------
SET (CTEST_CUSTOM_MAXIMUM_NUMBER_OF_ERRORS 50) SET (CTEST_CUSTOM_MAXIMUM_NUMBER_OF_ERRORS 50)
SET (CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS 50) SET (CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS 2000)
SET(CTEST_CUSTOM_COVERAGE_EXCLUDE SET(CTEST_CUSTOM_COVERAGE_EXCLUDE
${CTEST_CUSTOM_COVERAGE_EXCLUDE} ${CTEST_CUSTOM_COVERAGE_EXCLUDE}
# Exclude files from the Testing directories # Exclude files from the Testing directories
".*/tests/.*"
".*/Testing/.*" ".*/Testing/.*"
) )

View File

@ -1,24 +1,31 @@
# - Find LCMS library # - Find LCMS library
# Find the native LCMS includes and library # Find the native LCMS includes and library
# This module defines # Once done this will define
# LCMS_INCLUDE_DIR, where to find tiff.h, etc. #
# LCMS_LIBRARIES, libraries to link against to use LCMS. # LCMS_INCLUDE_DIR - Where to find lcms.h, etc.
# LCMS_FOUND, If false, do not try to use LCMS. # LCMS_LIBRARIES - Libraries to link against to use LCMS.
# LCMS_FOUND - If false, do not try to use LCMS.
#
# also defined, but not for general use are # also defined, but not for general use are
# LCMS_LIBRARY, where to find the LCMS library. # LCMS_LIBRARY, where to find the LCMS library.
#
#=============================================================================
#=============================================================================
FIND_PATH(LCMS_INCLUDE_DIR lcms.h PATHS /usr/include /usr/local/include /opt/include /opt/local/include) FIND_PATH(LCMS_INCLUDE_DIR lcms.h PATHS /usr/include /usr/local/include /opt/include /opt/local/include)
#
SET(LCMS_NAMES ${LCMS_NAMES} lcms liblcms liblcms_static) SET(LCMS_NAMES ${LCMS_NAMES} lcms liblcms liblcms_static)
FIND_LIBRARY(LCMS_LIBRARY NAMES ${LCMS_NAMES} ) FIND_LIBRARY(LCMS_LIBRARY NAMES ${LCMS_NAMES} )
#
MARK_AS_ADVANCED(LCMS_INCLUDE_DIR LCMS_LIBRARY)
# handle the QUIETLY and REQUIRED arguments and set LCMS_FOUND to TRUE if # handle the QUIETLY and REQUIRED arguments and set LCMS_FOUND to TRUE if
# all listed variables are TRUE # all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs) INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LCMS DEFAULT_MSG LCMS_LIBRARY LCMS_INCLUDE_DIR) FIND_PACKAGE_HANDLE_STANDARD_ARGS(LCMS DEFAULT_MSG LCMS_LIBRARY LCMS_INCLUDE_DIR)
#
IF(LCMS_FOUND) IF(LCMS_FOUND)
SET( LCMS_INCLUDE_DIRS ${LCMS_INCLUDE_DIR})
SET( LCMS_LIBRARIES ${LCMS_LIBRARY} ) SET( LCMS_LIBRARIES ${LCMS_LIBRARY} )
ENDIF(LCMS_FOUND) ENDIF(LCMS_FOUND)
MARK_AS_ADVANCED(LCMS_INCLUDE_DIR LCMS_LIBRARY)

View File

@ -1,23 +1,31 @@
# - Find LCMS2 library # - Find LCMS2 library
# Find the native LCMS2 includes and library # Find the native LCMS2 includes and library
# This module defines # Once done this will define
# LCMS2_INCLUDE_DIR, where to find tiff.h, etc.
# LCMS2_LIBRARIES, libraries to link against to use LCMS2.
# LCMS2_FOUND, If false, do not try to use LCMS2.
# also defined, but not for general use are
# LCMS2_LIBRARY, where to find the LCMS2 library.
# #
# LCMS2_INCLUDE_DIR - Where to find lcms2.h, etc.
# LCMS2_LIBRARIES - Libraries to link against to use LCMS2.
# LCMS2_FOUND - If false, do not try to use LCMS2.
#
# also defined, but not for general use are
# LCMS2_LIBRARY - Where to find the LCMS2 library.
#=============================================================================
#=============================================================================
FIND_PATH(LCMS2_INCLUDE_DIR lcms2.h PATHS /usr/include /usr/local/include /opt/include /opt/local/include) FIND_PATH(LCMS2_INCLUDE_DIR lcms2.h PATHS /usr/include /usr/local/include /opt/include /opt/local/include)
SET(LCMS2_NAMES ${LCMS2_NAMES} lcms2 liblcms2 liblcms2_static) SET(LCMS2_NAMES ${LCMS2_NAMES} lcms2 liblcms2 liblcms2_static)
FIND_LIBRARY(LCMS2_LIBRARY NAMES ${LCMS2_NAMES} ) FIND_LIBRARY(LCMS2_LIBRARY NAMES ${LCMS2_NAMES} )
MARK_AS_ADVANCED(LCMS2_INCLUDE_DIR LCMS2_LIBRARY)
# handle the QUIETLY and REQUIRED arguments and set LCMS2_FOUND to TRUE if # handle the QUIETLY and REQUIRED arguments and set LCMS2_FOUND to TRUE if
# all listed variables are TRUE # all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs) INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LCMS2 DEFAULT_MSG LCMS2_LIBRARY LCMS2_INCLUDE_DIR) FIND_PACKAGE_HANDLE_STANDARD_ARGS(LCMS2 DEFAULT_MSG LCMS2_LIBRARY LCMS2_INCLUDE_DIR)
#
IF(LCMS2_FOUND) IF(LCMS2_FOUND)
SET( LCMS2_INCLUDE_DIRS ${LCMS2_INCLUDE_DIR})
SET( LCMS2_LIBRARIES ${LCMS2_LIBRARY} ) SET( LCMS2_LIBRARIES ${LCMS2_LIBRARY} )
ENDIF(LCMS2_FOUND) ENDIF(LCMS2_FOUND)
#
MARK_AS_ADVANCED(LCMS2_INCLUDE_DIR LCMS2_LIBRARY)

View File

@ -39,6 +39,12 @@ SET(OPENJPEG_LIBRARY_PROPERTIES
SOVERSION "${OPENJPEG_VERSION_MAJOR}" SOVERSION "${OPENJPEG_VERSION_MAJOR}"
) )
# Path to additional CMake modules
SET(CMAKE_MODULE_PATH
${CMAKE_SOURCE_DIR}/CMake
${CMAKE_MODULE_PATH})
# On Visual Studio 8 MS deprecated C. This removes all 1.276E1265 security # On Visual Studio 8 MS deprecated C. This removes all 1.276E1265 security
# warnings # warnings
IF(WIN32) IF(WIN32)
@ -150,7 +156,7 @@ IF(CMAKE_COMPILER_IS_GNUCC)
ENDIF(CMAKE_COMPILER_IS_GNUCC) ENDIF(CMAKE_COMPILER_IS_GNUCC)
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# opj_config.h generation # opj_config.h generation (1/2)
FIND_FILE(HAVE_STRINGS_H_FOUND strings.h) FIND_FILE(HAVE_STRINGS_H_FOUND strings.h)
IF(NOT HAVE_STRINGS_H_FOUND STREQUAL "HAVE_STRINGS_H_FOUND-NOTFOUND") IF(NOT HAVE_STRINGS_H_FOUND STREQUAL "HAVE_STRINGS_H_FOUND-NOTFOUND")
FIND_FILE(HAVE_STRINGS_H strings.h) FIND_FILE(HAVE_STRINGS_H strings.h)
@ -196,18 +202,6 @@ IF(NOT HAVE_UNISTD_H_FOUND STREQUAL "HAVE_UNISTD_H_FOUND-NOTFOUND")
FIND_FILE(HAVE_UNISTD_H unistd.h) FIND_FILE(HAVE_UNISTD_H unistd.h)
SET(HAS_UNISTD_H 1) SET(HAS_UNISTD_H 1)
ENDIF() ENDIF()
CONFIGURE_FILE("${OPENJPEG_SOURCE_DIR}/opj_configh.cmake.in"
"${OPENJPEG_BINARY_DIR}/opj_config.h"
@ONLY
)
#-----------------------------------------------------------------------------
# CDash+CMake : to be updated
OPTION(BUILD_TESTING "Build the tests." OFF)
IF(BUILD_TESTING)
ENABLE_TESTING()
INCLUDE(CTest)
ENDIF(BUILD_TESTING)
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# Build Library # Build Library
@ -218,7 +212,19 @@ ADD_SUBDIRECTORY(libopenjpeg)
# Build Applications # Build Applications
OPTION(BUILD_CODEC "Build the CODEC executables" ON) OPTION(BUILD_CODEC "Build the CODEC executables" ON)
OPTION(BUILD_MJ2 "Build the MJ2 executables." OFF) OPTION(BUILD_MJ2 "Build the MJ2 executables." OFF)
ADD_SUBDIRECTORY(applications)
IF(BUILD_CODEC OR BUILD_MJ2)
OPTION(BUILD_THIRDPARTY "Build the thirdparty executables if it is needed" OFF)
ADD_SUBDIRECTORY(thirdparty)
ADD_SUBDIRECTORY(applications)
ENDIF (BUILD_CODEC OR BUILD_MJ2)
#-----------------------------------------------------------------------------
# opj_config.h generation (2/2)
CONFIGURE_FILE("${OPENJPEG_SOURCE_DIR}/opj_configh.cmake.in"
"${OPENJPEG_BINARY_DIR}/opj_config.h"
@ONLY
)
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# Build JPWL-flavoured library and executables # Build JPWL-flavoured library and executables
@ -229,17 +235,28 @@ OPTION(BUILD_JPWL "Build the JPWL library and executables" OFF)
ADD_SUBDIRECTORY(doc) ADD_SUBDIRECTORY(doc)
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# Tests data # Buld Testing
OPTION(BUILD_TESTING "Build the tests." OFF)
IF(BUILD_TESTING) IF(BUILD_TESTING)
# Adding test with dataset from: IF(BUILD_CODEC)
# http://www.openjpeg.org/conformance/j2kp4files_v1_5.zip ENABLE_TESTING()
# -> wget http://www.openjpeg.org/conformance/j2kp4files_v1_5.zip INCLUDE(CTest)
# http://www.jpeg.org/jpeg2000guide/testimages/testimages.html
# Adding JPEG2000_CONFORMANCE_DATA_ROOT # Add repository where to find tests
FIND_PATH(JPEG2000_CONFORMANCE_DATA_ROOT testimages.html ADD_SUBDIRECTORY(tests)
${OPENJPEG_SOURCE_DIR}/../jpeg2000testimages
$ENV{JPEG2000_CONFORMANCE_DATA_ROOT} # Search openjpeg data needed for the tests
) # They could be found via svn on the OpenJPEG google code project
# svn checkout http://openjpeg.googlecode.com/svn/data (about 70 Mo)
FIND_PATH(OPJ_DATA_ROOT README-OPJ-Data
PATHS $ENV{OPJ_DATA_ROOT} ${CMAKE_SOURCE_DIR}/../opj-data)
SET (REF_DECODER_BIN_PATH "NOT-FOUND" CACHE PATH "Single directory where find the reference encoder binaries to enable encoding test suite.")
MARK_AS_ADVANCED(REF_DECODER_BIN_PATH)
ELSE(BUILD_CODEC)
message(FATAL_ERROR "You need build codec to run the tests")
ENDIF(BUILD_CODEC)
ENDIF(BUILD_TESTING) ENDIF(BUILD_TESTING)
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------

View File

@ -1,130 +1,9 @@
IF(BUILD_CODEC OR BUILD_MJ2) # Build the each application if it needed
#
#
IF(UNIX OR CYGWIN)
SET(CMAKE_INCLUDE_PATH /usr/include /usr/local/include /opt/include
/opt/local/include /usr/include/libpng /usr/include/libpng14
/usr/include/libpng12 /usr/local/include/libpng
/usr/local/include/libpng14 /usr/local/include/libpng12
/opt/include/libpng /opt/include/libpng14 /opt/include/libpng12
/opt/local/include/libpng /opt/local/include/libpng14)
SET(CMAKE_LIBRARY_PATH /usr/lib /usr/local/lib /opt/lib /opt/local/lib)
ENDIF()
#
FIND_PACKAGE(ZLIB)
#
IF(ZLIB_LIBRARY STREQUAL "ZLIB_LIBRARY-NOTFOUND")
SET(ZLIB_FOUND 0)
ENDIF(ZLIB_LIBRARY STREQUAL "ZLIB_LIBRARY-NOTFOUND")
#
IF(ZLIB_FOUND)
SET(HAVE_ZLIB_H 1)
SET(HABE_LIBZ 1)
SET(Z_LIBNAME ${ZLIB_LIBRARIES})
SET(Z_INCLUDE_DIRNAME ${ZLIB_INCLUDE_DIR})
ENDIF(ZLIB_FOUND)
#
FIND_PACKAGE(PNG)
#
IF(PNG_LIBRARY STREQUAL "PNG_LIBRARY-NOTFOUND")
SET(PNG_FOUND 0)
ENDIF(PNG_LIBRARY STREQUAL "PNG_LIBRARY-NOTFOUND")
#
IF(PNG_FOUND)
SET(HAVE_PNG_H 1)
SET(HAVE_LIBPNG 1)
SET(PNG_LIBNAME ${PNG_LIBRARIES})
SET(PNG_INCLUDE_DIRNAME ${PNG_INCLUDE_DIR})
ENDIF(PNG_FOUND)
#
FIND_PACKAGE(TIFF)
#
IF(TIFF_LIBRARY STREQUAL "TIFF_LIBRARY-NOTFOUND")
SET(TIFF_FOUND 0)
ENDIF(TIFF_LIBRARY STREQUAL "TIFF_LIBRARY-NOTFOUND")
#
IF(TIFF_FOUND)
SET(HAVE_TIFF_H 1)
SET(HAVE_LIBTIFF 1)
SET(TIFF_LIBNAME ${TIFF_LIBRARIES})
SET(TIFF_INCLUDE_DIRNAME ${TIFF_INCLUDE_DIR})
ENDIF(TIFF_FOUND)
#
SET(LCMS12_MISSING 1)
INCLUDE(${OPENJPEG_SOURCE_DIR}/thirdparty/FindLCMS2.cmake OPTIONAL)
#
IF(LCMS2_FOUND)
SET(LCMS12_MISSING 0)
SET(HAVE_LCMS2_H 1)
SET(HAVE_LIBLCMS2 1)
SET(LCMS_LIBNAME ${LCMS2_LIBRARY})
SET(LCMS_INCLUDE_DIRNAME ${LCMS2_INCLUDE_DIR})
ENDIF(LCMS2_FOUND)
#
IF(NOT LCMS2_FOUND)
INCLUDE(${OPENJPEG_SOURCE_DIR}/thirdparty/FindLCMS.cmake OPTIONAL)
#
IF(LCMS_FOUND)
SET(LCMS12_MISSING 0)
SET(HAVE_LCMS1_H 1)
SET(HAVE_LIBLCMS1 1)
SET(LCMS_LIBNAME ${LCMS_LIBRARY} )
SET(LCMS_INCLUDE_DIRNAME ${LCMS_INCLUDE_DIR})
ENDIF(LCMS_FOUND)
ENDIF(NOT LCMS2_FOUND)
#-------------------------------------------------------------
OPTION(BUILD_THIRDPARTY "Build the thirdparty executables" ON)
#
IF(NOT ZLIB_FOUND OR NOT PNG_FOUND OR NOT TIFF_FOUND OR LCMS12_MISSING)
IF(BUILD_THIRDPARTY)
SET(HAVE_ZLIB_H 1)
SET(HAVE_LIBZ 1)
SET(HAVE_PNG_H 1)
SET(HAVE_LIBPNG 1)
SET(HAVE_TIFF_H 1)
SET(HAVE_LIBTIFF 1)
SET(HAVE_LCMS2_H 1)
SET(HAVE_LIBLCMS2 1)
#
#ADD_SUBDIRECTORY(${OPENJPEG_SOURCE_DIR}/thirdparty)
#
LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/thirdparty/lib)
#
IF(NOT ZLIB_FOUND)
INCLUDE_DIRECTORIES(${OPENJPEG_SOURCE_DIR}/thirdparty/include)
SET(ZLIB_INCLUDE_DIRNAME ${OPENJPEG_SOURCE_DIR}/thirdparty/include)
SET(Z_LIBNAME z)
SET(ZLIB_FOUND 1)
ENDIF(NOT ZLIB_FOUND)
#
IF(NOT PNG_FOUND)
SET(PNG_INCLUDE_DIRNAME ${OPENJPEG_SOURCE_DIR}/thirdparty/libpng)
SET(PNG_LIBNAME png)
SET(PNG_FOUND 1)
ENDIF(NOT PNG_FOUND)
#
IF(NOT LCMS_FOUND AND NOT LCMS2_FOUND)
SET(LCMS_INCLUDE_DIRNAME ${OPENJPEG_SOURCE_DIR}/thirdparty/liblcms2/include)
SET(LCMS_LIBNAME lcms2)
SET(LCMS2_FOUND 1)
ENDIF(NOT LCMS_FOUND AND NOT LCMS2_FOUND)
#
IF(NOT TIFF_FOUND)
SET(TIFF_INCLUDE_DIRNAME ${OPENJPEG_SOURCE_DIR}/thirdparty/libtiff)
SET(TIFF_LIBNAME tiff)
SET(TIFF_FOUND 1)
ENDIF(NOT TIFF_FOUND)
#
ENDIF(BUILD_THIRDPARTY)
ENDIF(NOT ZLIB_FOUND OR NOT PNG_FOUND OR NOT TIFF_FOUND OR LCMS12_MISSING)
#
ENDIF(BUILD_CODEC OR BUILD_MJ2)
#
IF(BUILD_CODEC) IF(BUILD_CODEC)
ADD_SUBDIRECTORY(codec) ADD_SUBDIRECTORY(codec)
ENDIF(BUILD_CODEC) ENDIF(BUILD_CODEC)
#
IF(BUILD_MJ2) IF(BUILD_MJ2)
ADD_SUBDIRECTORY(mj2) ADD_SUBDIRECTORY(mj2)
ENDIF(BUILD_MJ2) ENDIF(BUILD_MJ2)
#

View File

@ -1,4 +1,4 @@
# Build the demo app, small examples # Build the demo app, small examples
# First thing define the common source: # First thing define the common source:
SET(common_SRCS SET(common_SRCS
@ -37,15 +37,8 @@ ENDIF(WIN32)
FOREACH(exe j2k_to_image image_to_j2k j2k_dump) FOREACH(exe j2k_to_image image_to_j2k j2k_dump)
ADD_EXECUTABLE(${exe} ${exe}.c ${common_SRCS}) ADD_EXECUTABLE(${exe} ${exe}.c ${common_SRCS})
TARGET_LINK_LIBRARIES(${exe} ${OPENJPEG_LIBRARY_NAME} TARGET_LINK_LIBRARIES(${exe} ${OPENJPEG_LIBRARY_NAME}
${Z_LIBNAME} ${PNG_LIBNAME} ${TIFF_LIBNAME}) ${Z_LIBNAME} ${PNG_LIBNAME} ${TIFF_LIBNAME} ${LCMS_LIBNAME} )
IF(LCMS_FOUND OR LCMS2_FOUND)
TARGET_LINK_LIBRARIES(${exe} ${LCMS_LIBNAME})
ENDIF(LCMS_FOUND OR LCMS2_FOUND)
ADD_TEST(${exe} ${EXECUTABLE_OUTPUT_PATH}/${exe})
# calling those exe without option will make them fail always:
SET_TESTS_PROPERTIES(${exe} PROPERTIES WILL_FAIL TRUE)
# On unix you need to link to the math library: # On unix you need to link to the math library:
IF(UNIX) IF(UNIX)
TARGET_LINK_LIBRARIES(${exe} m) TARGET_LINK_LIBRARIES(${exe} m)
@ -103,40 +96,4 @@ IF(BUILD_JPWL)
INSTALL(TARGETS JPWL_image_to_j2k JPWL_j2k_to_image INSTALL(TARGETS JPWL_image_to_j2k JPWL_j2k_to_image
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
) )
ENDIF(BUILD_JPWL) ENDIF(BUILD_JPWL)
if(BUILD_TESTING)
# Do testing here, once we know the examples are being built:
FILE(GLOB_RECURSE OPENJPEG_DATA_IMAGES_GLOB
"${JPEG2000_CONFORMANCE_DATA_ROOT}/*.j2k"
"${JPEG2000_CONFORMANCE_DATA_ROOT}/*.j2c"
"${JPEG2000_CONFORMANCE_DATA_ROOT}/*.jp2"
)
foreach(filename ${OPENJPEG_DATA_IMAGES_GLOB})
get_filename_component(filename_temp ${filename} NAME)
get_filename_component(filename_ext ${filename} EXT)
execute_process(COMMAND ${EXECUTABLE_OUTPUT_PATH}/j2k_dump -i ${filename}
OUTPUT_VARIABLE dump_success
OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/${filename_temp}.dump
ERROR_QUIET
)
if(dump_success)
file(READ ${CMAKE_CURRENT_BINARY_DIR}/${filename_temp}.dump numcomp_file)
string(REGEX REPLACE ".*numcomps=([0-9]+).*" "\\1"
numcomps "${numcomp_file}")
#message( "found:${output_variable} for ${filename_temp}" )
endif()
ADD_TEST(dump-${filename_temp} ${EXECUTABLE_OUTPUT_PATH}/j2k_dump -i ${filename})
foreach(codec_type ppm pgx bmp tif raw tga png)
ADD_TEST(j2i-${filename_temp}-${codec_type} ${EXECUTABLE_OUTPUT_PATH}/j2k_to_image -i ${filename} -o ${filename_temp}.${codec_type})
endforeach(codec_type)
foreach(codec_type ppm bmp tif tga png)
ADD_TEST(i2j-${filename_temp}-${codec_type} ${EXECUTABLE_OUTPUT_PATH}/image_to_j2k -i ${filename_temp}.${codec_type} -o ${filename_temp}.${codec_type}${filename_ext})
SET_TESTS_PROPERTIES(i2j-${filename_temp}-${codec_type} PROPERTIES DEPENDS j2i-${filename_temp}-${codec_type})
#if(UNIX)
# ADD_TEST(cmp-${filename_temp}-${codec_type} cmp ${filename} ${filename_temp}.${codec_type}${filename_ext})
#endif(UNIX)
endforeach(codec_type)
endforeach(filename)
endif(BUILD_TESTING)

View File

@ -102,7 +102,11 @@ int tga_readheader(FILE *fp, unsigned int *bits_per_pixel,
return 0; return 0;
// Read TGA header // Read TGA header
fread((unsigned char*)&tga, sizeof(tga_header), 1, fp); if ( fread((unsigned char*)&tga, sizeof(tga_header), 1, fp) != 1 )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return 0 ;
}
*bits_per_pixel = tga.pixel_depth; *bits_per_pixel = tga.pixel_depth;
@ -113,7 +117,12 @@ int tga_readheader(FILE *fp, unsigned int *bits_per_pixel,
if (tga.id_length) if (tga.id_length)
{ {
unsigned char *id = (unsigned char *) malloc(tga.id_length); unsigned char *id = (unsigned char *) malloc(tga.id_length);
fread(id, tga.id_length, 1, fp); if ( !fread(id, tga.id_length, 1, fp) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
free(id);
return 0 ;
}
free(id); free(id);
} }
@ -149,9 +158,14 @@ int tga_writeheader(FILE *fp, int bits_per_pixel, int width, int height,
memset(&tga, 0, sizeof(tga_header)); memset(&tga, 0, sizeof(tga_header));
tga.pixel_depth = bits_per_pixel; if ( bits_per_pixel < 256 )
tga.image_width = width; tga.pixel_depth = (unsigned char)bits_per_pixel;
tga.image_height = height; else{
fprintf(stderr,"ERROR: Wrong bits per pixel inside tga_header");
return 0;
}
tga.image_width = (unsigned short)width;
tga.image_height = (unsigned short)height;
tga.image_type = 2; // Uncompressed. tga.image_type = 2; // Uncompressed.
tga.image_desc = 8; // 8 bits per component. tga.image_desc = 8; // 8 bits per component.
@ -246,9 +260,25 @@ opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) {
for (x=0;x<image_width;x++) for (x=0;x<image_width;x++)
{ {
unsigned char r,g,b; unsigned char r,g,b;
fread(&b, 1, 1, f);
fread(&g, 1, 1, f); if( !fread(&b, 1, 1, f) )
fread(&r, 1, 1, f); {
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
return NULL;
}
if ( !fread(&g, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
return NULL;
}
if ( !fread(&r, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
return NULL;
}
image->comps[0].data[index]=r; image->comps[0].data[index]=r;
image->comps[1].data[index]=g; image->comps[1].data[index]=g;
@ -261,10 +291,30 @@ opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) {
for (x=0;x<image_width;x++) for (x=0;x<image_width;x++)
{ {
unsigned char r,g,b,a; unsigned char r,g,b,a;
fread(&b, 1, 1, f); if ( !fread(&b, 1, 1, f) )
fread(&g, 1, 1, f); {
fread(&r, 1, 1, f); fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
fread(&a, 1, 1, f); opj_image_destroy(image);
return NULL;
}
if ( !fread(&g, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
return NULL;
}
if ( !fread(&r, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
return NULL;
}
if ( !fread(&a, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
return NULL;
}
image->comps[0].data[index]=r; image->comps[0].data[index]=r;
image->comps[1].data[index]=g; image->comps[1].data[index]=g;
@ -408,10 +458,8 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
unsigned int j, PAD = 0; unsigned int j, PAD = 0;
int x, y, index; int x, y, index;
int gray_scale = 1, not_end_file = 1; int gray_scale = 1;
int has_color; int has_color;
unsigned int line = 0, col = 0;
unsigned char v, v2;
DWORD W, H; DWORD W, H;
IN = fopen(filename, "rb"); IN = fopen(filename, "rb");
@ -558,7 +606,13 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
RGB = (unsigned char *) RGB = (unsigned char *)
malloc((3 * W + PAD) * H * sizeof(unsigned char)); malloc((3 * W + PAD) * H * sizeof(unsigned char));
fread(RGB, sizeof(unsigned char), (3 * W + PAD) * H, IN); if ( fread(RGB, sizeof(unsigned char), (3 * W + PAD) * H, IN) != (3 * W + PAD) * H )
{
free(RGB);
opj_image_destroy(image);
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return NULL;
}
index = 0; index = 0;
@ -590,9 +644,9 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
has_color = 0; has_color = 0;
for (j = 0; j < Info_h.biClrUsed; j++) for (j = 0; j < Info_h.biClrUsed; j++)
{ {
table_B[j] = getc(IN); table_B[j] = (unsigned char)getc(IN);
table_G[j] = getc(IN); table_G[j] = (unsigned char)getc(IN);
table_R[j] = getc(IN); table_R[j] = (unsigned char)getc(IN);
getc(IN); getc(IN);
has_color += has_color +=
!(table_R[j] == table_G[j] && table_R[j] == table_B[j]); !(table_R[j] == table_G[j] && table_R[j] == table_B[j]);
@ -641,7 +695,16 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
RGB = (unsigned char *) malloc(W * H * sizeof(unsigned char)); RGB = (unsigned char *) malloc(W * H * sizeof(unsigned char));
fread(RGB, sizeof(unsigned char), W * H, IN); if ( fread(RGB, sizeof(unsigned char), W * H, IN) != W * H )
{
free(table_R);
free(table_G);
free(table_B);
free(RGB);
opj_image_destroy(image);
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return NULL;
}
if (gray_scale) if (gray_scale)
{ {
index = 0; index = 0;
@ -680,156 +743,163 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
}/* RGB8 */ }/* RGB8 */
else else
if (Info_h.biBitCount == 8 && Info_h.biCompression == 1)//RLE8 if (Info_h.biBitCount == 8 && Info_h.biCompression == 1)//RLE8
{ {
unsigned char *pix, *beyond; unsigned char *pix, *beyond;
unsigned int *gray, *red, *green, *blue; int *gray, *red, *green, *blue;
unsigned int x, y, max; unsigned int x, y, max;
int i, c, c1; int i, c, c1;
unsigned char uc; unsigned char uc;
if(Info_h.biClrUsed == 0) Info_h.biClrUsed = 256; if (Info_h.biClrUsed == 0)
else Info_h.biClrUsed = 256;
if(Info_h.biClrUsed > 256) Info_h.biClrUsed = 256; else if (Info_h.biClrUsed > 256)
Info_h.biClrUsed = 256;
table_R = (unsigned char *) malloc(256 * sizeof(unsigned char)); table_R = (unsigned char *) malloc(256 * sizeof(unsigned char));
table_G = (unsigned char *) malloc(256 * sizeof(unsigned char)); table_G = (unsigned char *) malloc(256 * sizeof(unsigned char));
table_B = (unsigned char *) malloc(256 * sizeof(unsigned char)); table_B = (unsigned char *) malloc(256 * sizeof(unsigned char));
has_color = 0; has_color = 0;
for (j = 0; j < Info_h.biClrUsed; j++) for (j = 0; j < Info_h.biClrUsed; j++)
{ {
table_B[j] = getc(IN); table_B[j] = (unsigned char)getc(IN);
table_G[j] = getc(IN); table_G[j] = (unsigned char)getc(IN);
table_R[j] = getc(IN); table_R[j] = (unsigned char)getc(IN);
getc(IN); getc(IN);
has_color += has_color += !(table_R[j] == table_G[j] && table_R[j] == table_B[j]);
!(table_R[j] == table_G[j] && table_R[j] == table_B[j]); }
} if (has_color)
if(has_color) gray_scale = 0; gray_scale = 0;
numcomps = gray_scale ? 1 : 3; numcomps = gray_scale ? 1 : 3;
color_space = gray_scale ? CLRSPC_GRAY : CLRSPC_SRGB; color_space = gray_scale ? CLRSPC_GRAY : CLRSPC_SRGB;
/* initialize image components */ /* initialize image components */
memset(&cmptparm[0], 0, 3 * sizeof(opj_image_cmptparm_t)); memset(&cmptparm[0], 0, 3 * sizeof(opj_image_cmptparm_t));
for(i = 0; i < numcomps; i++) for (i = 0; i < numcomps; i++)
{ {
cmptparm[i].prec = 8; cmptparm[i].prec = 8;
cmptparm[i].bpp = 8; cmptparm[i].bpp = 8;
cmptparm[i].sgnd = 0; cmptparm[i].sgnd = 0;
cmptparm[i].dx = subsampling_dx; cmptparm[i].dx = subsampling_dx;
cmptparm[i].dy = subsampling_dy; cmptparm[i].dy = subsampling_dy;
cmptparm[i].w = w; cmptparm[i].w = w;
cmptparm[i].h = h; cmptparm[i].h = h;
} }
/* create the image */ /* create the image */
image = opj_image_create(numcomps, &cmptparm[0], color_space); image = opj_image_create(numcomps, &cmptparm[0], color_space);
if(!image) if (!image)
{ {
fclose(IN); fclose(IN);
free(table_R); free(table_G); free(table_B); free(table_R);
return NULL; free(table_G);
} free(table_B);
return NULL;
}
/* set image offset and reference grid */ /* set image offset and reference grid */
image->x0 = parameters->image_offset_x0; image->x0 = parameters->image_offset_x0;
image->y0 = parameters->image_offset_y0; image->y0 = parameters->image_offset_y0;
image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : image->x0 + (w - 1) * subsampling_dx + 1; image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : image->x0 + (w
image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : image->y0 + (h - 1) * subsampling_dy + 1; - 1) * subsampling_dx + 1;
image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : image->y0 + (h
- 1) * subsampling_dy + 1;
/* set image data */ /* set image data */
/* Place the cursor at the beginning of the image information */
fseek(IN, 0, SEEK_SET);
fseek(IN, File_h.bfOffBits, SEEK_SET);
W = Info_h.biWidth; /* Place the cursor at the beginning of the image information */
H = Info_h.biHeight; fseek(IN, 0, SEEK_SET);
RGB = (unsigned char *)calloc(1, W * H * sizeof(unsigned char)); fseek(IN, File_h.bfOffBits, SEEK_SET);
beyond = RGB + W * H;
pix = beyond - W;
x = y = 0;
while(y < H) W = Info_h.biWidth;
{ H = Info_h.biHeight;
c = getc(IN); RGB = (unsigned char *) calloc(1, W * H * sizeof(unsigned char));
beyond = RGB + W * H;
pix = beyond - W;
x = y = 0;
if (c) while (y < H)
{ {
c1 = getc(IN); c = getc(IN);
for (i = 0; i < c && x < W && pix < beyond; i++, x++, pix++) if (c)
*pix = c1; {
} c1 = getc(IN);
else
{
c = getc(IN);
if(c == 0x00) /* EOL */ for (i = 0; i < c && x < W && pix < beyond; i++, x++, pix++)
{ *pix = (unsigned char)c1;
x = 0; ++y; pix = RGB + x + (H - y - 1) * W; }
} else
{
c = getc(IN);
if (c == 0x00) /* EOL */
{
x = 0;
++y;
pix = RGB + x + (H - y - 1) * W;
}
else if (c == 0x01) /* EOP */
break;
else if (c == 0x02) /* MOVE by dxdy */
{
c = getc(IN);
x += c;
c = getc(IN);
y += c;
pix = RGB + (H - y - 1) * W + x;
}
else /* 03 .. 255 */
{
i = 0;
for (; i < c && x < W && pix < beyond; i++, x++, pix++)
{
c1 = getc(IN);
*pix = (unsigned char)c1;
}
if (c & 1) /* skip padding byte */
getc(IN);
}
}
}/* while() */
if (gray_scale)
{
gray = image->comps[0].data;
pix = RGB;
max = W * H;
while (max--)
{
uc = *pix++;
*gray++ = table_R[uc];
}
}
else else
if(c == 0x01) /* EOP */ {
break; //int *red, *green, *blue;
else
if(c == 0x02) /* MOVE by dxdy */
{
c = getc(IN); x += c;
c = getc(IN); y += c;
pix = RGB + (H - y - 1) * W + x;
}
else /* 03 .. 255 */
{
i = 0;
for(; i < c && x < W && pix < beyond; i++, x++, pix++)
{
c1 = getc(IN);
*pix = c1;
}
if(c & 1) /* skip padding byte */
getc(IN);
}
}
}/* while() */
if (gray_scale) red = image->comps[0].data;
{ green = image->comps[1].data;
int *gray; blue = image->comps[2].data;
pix = RGB;
max = W * H;
gray = image->comps[0].data; while (max--)
pix = RGB; {
max = W * H; uc = *pix++;
while(max--) *red++ = table_R[uc];
{ *green++ = table_G[uc];
uc = *pix++; *blue++ = table_B[uc];
}
*gray++ = table_R[uc]; }
} free(RGB);
} free(table_R);
else free(table_G);
{ free(table_B);
int *red, *green, *blue; }/* RLE8 */
red = image->comps[0].data;
green = image->comps[1].data;
blue = image->comps[2].data;
pix = RGB;
max = W * H;
while(max--)
{
uc = *pix++;
*red++ = table_R[uc];
*green++ = table_G[uc];
*blue++ = table_B[uc];
}
}
free(RGB);
free(table_R); free(table_G); free(table_B);
}/* RLE8 */
else else
{ {
fprintf(stderr, fprintf(stderr,
@ -1007,7 +1077,6 @@ int imagetobmp(opj_image_t * image, const char *outfile) {
} }
for (i = 0; i < w * h; i++) { for (i = 0; i < w * h; i++) {
unsigned char rc;
int r; int r;
r = image->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; r = image->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
@ -1038,15 +1107,27 @@ PGX IMAGE FORMAT
unsigned char readuchar(FILE * f) unsigned char readuchar(FILE * f)
{ {
unsigned char c1; unsigned char c1;
fread(&c1, 1, 1, f); if ( !fread(&c1, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return 0;
}
return c1; return c1;
} }
unsigned short readushort(FILE * f, int bigendian) unsigned short readushort(FILE * f, int bigendian)
{ {
unsigned char c1, c2; unsigned char c1, c2;
fread(&c1, 1, 1, f); if ( !fread(&c1, 1, 1, f) )
fread(&c2, 1, 1, f); {
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return 0;
}
if ( !fread(&c2, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return 0;
}
if (bigendian) if (bigendian)
return (c1 << 8) + c2; return (c1 << 8) + c2;
else else
@ -1056,10 +1137,26 @@ unsigned short readushort(FILE * f, int bigendian)
unsigned int readuint(FILE * f, int bigendian) unsigned int readuint(FILE * f, int bigendian)
{ {
unsigned char c1, c2, c3, c4; unsigned char c1, c2, c3, c4;
fread(&c1, 1, 1, f); if ( !fread(&c1, 1, 1, f) )
fread(&c2, 1, 1, f); {
fread(&c3, 1, 1, f); fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
fread(&c4, 1, 1, f); return 0;
}
if ( !fread(&c2, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return 0;
}
if ( !fread(&c3, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return 0;
}
if ( !fread(&c4, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return 0;
}
if (bigendian) if (bigendian)
return (c1 << 24) + (c2 << 16) + (c3 << 8) + c4; return (c1 << 24) + (c2 << 16) + (c3 << 8) + c4;
else else
@ -1095,8 +1192,11 @@ opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters) {
} }
fseek(f, 0, SEEK_SET); fseek(f, 0, SEEK_SET);
fscanf(f, "PG%[ \t]%c%c%[ \t+-]%d%[ \t]%d%[ \t]%d",temp,&endian1,&endian2,signtmp,&prec,temp,&w,temp,&h); if( fscanf(f, "PG%[ \t]%c%c%[ \t+-]%d%[ \t]%d%[ \t]%d",temp,&endian1,&endian2,signtmp,&prec,temp,&w,temp,&h) != 9){
fprintf(stderr, "ERROR: Failed to read the right number of element from the fscanf() function!\n");
return NULL;
}
i=0; i=0;
sign='+'; sign='+';
while (signtmp[i]!='\0') { while (signtmp[i]!='\0') {
@ -1200,11 +1300,11 @@ int imagetopgx(opj_image_t * image, const char *outfile) {
name = (char*)malloc(total+1); name = (char*)malloc(total+1);
} }
strncpy(name, outfile, dotpos); strncpy(name, outfile, dotpos);
if (image->numcomps > 1) { //if (image->numcomps > 1) {
sprintf(name+dotpos, "-%d.pgx", compno); sprintf(name+dotpos, "_%d.pgx", compno);
} else { /*} else {
strcpy(name+dotpos, ".pgx"); strcpy(name+dotpos, ".pgx");
} }*/
fdest = fopen(name, "wb"); fdest = fopen(name, "wb");
if (!fdest) { if (!fdest) {
fprintf(stderr, "ERROR -> failed to open %s for writing\n", name); fprintf(stderr, "ERROR -> failed to open %s for writing\n", name);
@ -1308,7 +1408,11 @@ static void read_pnm_header(FILE *reader, struct pnm_header *ph)
char idf[256], type[256]; char idf[256], type[256];
char line[256]; char line[256];
fgets(line, 250, reader); if (fgets(line, 250, reader) == NULL)
{
fprintf(stderr,"\nWARNING: fgets return a NULL value");
return;
}
if(line[0] != 'P') if(line[0] != 'P')
{ {
@ -1563,7 +1667,8 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters) {
for(compno = 0; compno < numcomps; compno++) for(compno = 0; compno < numcomps; compno++)
{ {
index = 0; index = 0;
fscanf(fp, "%u", &index); if (fscanf(fp, "%u", &index) != 1)
fprintf(stderr, "\nWARNING: fscanf return a number of element different from the expected.\n");
image->comps[compno].data[i] = (index * 255)/header_info.maxval; image->comps[compno].data[i] = (index * 255)/header_info.maxval;
} }
@ -1584,14 +1689,16 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters) {
{ {
for(compno = 0; compno < numcomps; compno++) for(compno = 0; compno < numcomps; compno++)
{ {
fread(&c0, 1, 1, fp); if ( !fread(&c0, 1, 1, fp) )
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
if(one) if(one)
{ {
image->comps[compno].data[i] = c0; image->comps[compno].data[i] = c0;
} }
else else
{ {
fread(&c1, 1, 1, fp); if ( !fread(&c1, 1, 1, fp) )
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
/* netpbm: */ /* netpbm: */
image->comps[compno].data[i] = ((c0<<8) | c1); image->comps[compno].data[i] = ((c0<<8) | c1);
} }
@ -1605,7 +1712,8 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters) {
{ {
unsigned int index; unsigned int index;
fscanf(fp, "%u", &index); if ( fscanf(fp, "%u", &index) != 1)
fprintf(stderr, "\nWARNING: fscanf return a number of element different from the expected.\n");
image->comps[0].data[i] = (index?0:255); image->comps[0].data[i] = (index?0:255);
} }
@ -1640,7 +1748,8 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters) {
for(i = 0; i < w * h; ++i) for(i = 0; i < w * h; ++i)
{ {
fread(&uc, 1, 1, fp); if ( !fread(&uc, 1, 1, fp) )
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
image->comps[0].data[i] = (uc & 1)?0:255; image->comps[0].data[i] = (uc & 1)?0:255;
} }
} }
@ -1863,7 +1972,6 @@ int imagetotif(opj_image_t * image, const char *outfile)
int width, height, imgsize; int width, height, imgsize;
int bps,index,adjust, sgnd; int bps,index,adjust, sgnd;
int ushift, dshift, has_alpha, force16; int ushift, dshift, has_alpha, force16;
unsigned int last_i=0;
TIFF *tif; TIFF *tif;
tdata_t buf; tdata_t buf;
tstrip_t strip; tstrip_t strip;
@ -1924,10 +2032,10 @@ int imagetotif(opj_image_t * image, const char *outfile)
for(strip = 0; strip < TIFFNumberOfStrips(tif); strip++) for(strip = 0; strip < TIFFNumberOfStrips(tif); strip++)
{ {
unsigned char *dat8; unsigned char *dat8;
tsize_t i, ssize; tsize_t i, ssize, last_i = 0;
int step, restx;
ssize = TIFFStripSize(tif); ssize = TIFFStripSize(tif);
dat8 = (unsigned char*)buf; dat8 = (unsigned char*)buf;
int step, restx;
if(bps == 8) if(bps == 8)
{ {

View File

@ -82,7 +82,7 @@ typedef struct img_folder{
float *rates; float *rates;
}img_fol_t; }img_fol_t;
void encode_help_display() { void encode_help_display(void) {
fprintf(stdout,"HELP for image_to_j2k\n----\n\n"); fprintf(stdout,"HELP for image_to_j2k\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n"); fprintf(stdout,"- the -h option displays this help information on screen\n\n");
@ -573,7 +573,7 @@ void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image, img_
int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters, int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename) { img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename) {
int i, j,totlen; int i, j, totlen, c;
option_t long_option[]={ option_t long_option[]={
{"cinema2K",REQ_ARG, NULL ,'w'}, {"cinema2K",REQ_ARG, NULL ,'w'},
{"cinema4K",NO_ARG, NULL ,'y'}, {"cinema4K",NO_ARG, NULL ,'y'},
@ -597,8 +597,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
img_fol->set_out_format=0; img_fol->set_out_format=0;
raw_cp->rawWidth = 0; raw_cp->rawWidth = 0;
while (1) { do{
int c = getopt_long(argc, argv, optlist,long_option,totlen); c = getopt_long(argc, argv, optlist,long_option,totlen);
if (c == -1) if (c == -1)
break; break;
switch (c) { switch (c) {
@ -1376,7 +1376,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
fprintf(stderr, "ERROR -> Command line not valid\n"); fprintf(stderr, "ERROR -> Command line not valid\n");
return 1; return 1;
} }
} }while(c != -1);
/* check for possible errors */ /* check for possible errors */
if (parameters->cp_cinema){ if (parameters->cp_cinema){
@ -1482,7 +1482,7 @@ int main(int argc, char **argv) {
opj_image_t *image = NULL; opj_image_t *image = NULL;
int i,num_images; int i,num_images;
int imageno; int imageno;
dircnt_t *dirptr; dircnt_t *dirptr = NULL;
raw_cparameters_t raw_cp; raw_cparameters_t raw_cp;
opj_codestream_info_t cstr_info; /* Codestream information structure */ opj_codestream_info_t cstr_info; /* Codestream information structure */
char indexfilename[OPJ_PATH_LEN]; /* index file name */ char indexfilename[OPJ_PATH_LEN]; /* index file name */

View File

@ -73,7 +73,7 @@ typedef struct img_folder{
}img_fol_t; }img_fol_t;
void decode_help_display() { void decode_help_display(void) {
fprintf(stdout,"HELP for j2k_dump\n----\n\n"); fprintf(stdout,"HELP for j2k_dump\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n"); fprintf(stdout,"- the -h option displays this help information on screen\n\n");
@ -92,6 +92,10 @@ void decode_help_display() {
fprintf(stdout," REQUIRED only if an Input image directory not specified\n"); fprintf(stdout," REQUIRED only if an Input image directory not specified\n");
fprintf(stdout," Currently accepts J2K-files, JP2-files and JPT-files. The file type\n"); fprintf(stdout," Currently accepts J2K-files, JP2-files and JPT-files. The file type\n");
fprintf(stdout," is identified based on its suffix.\n"); fprintf(stdout," is identified based on its suffix.\n");
fprintf(stdout," -o <output file>\n");
fprintf(stdout," OPTIONAL\n");
fprintf(stdout," Output file where file info will be dump.\n");
fprintf(stdout," By default it will be in the stdout.\n");
fprintf(stdout,"\n"); fprintf(stdout,"\n");
} }
@ -192,16 +196,18 @@ char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparamet
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol, char *indexfilename) { int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol, char *indexfilename) {
/* parse the command line */ /* parse the command line */
int totlen; int totlen, c;
option_t long_option[]={ option_t long_option[]={
{"ImgDir",REQ_ARG, NULL ,'y'}, {"ImgDir",REQ_ARG, NULL ,'y'},
}; };
const char optlist[] = "i:o:h";
OPJ_ARG_NOT_USED(indexfilename);
const char optlist[] = "i:h";
totlen=sizeof(long_option); totlen=sizeof(long_option);
img_fol->set_out_format = 0; img_fol->set_out_format = 0;
while (1) { do {
int c = getopt_long(argc, argv,optlist,long_option,totlen); c = getopt_long(argc, argv,optlist,long_option,totlen);
if (c == -1) if (c == -1)
break; break;
switch (c) { switch (c) {
@ -222,6 +228,15 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
} }
strncpy(parameters->infile, infile, sizeof(parameters->infile)-1); strncpy(parameters->infile, infile, sizeof(parameters->infile)-1);
} }
break;
/* ------------------------------------------------------ */
case 'o': /* output file */
{
char *outfile = optarg;
strncpy(parameters->outfile, outfile, sizeof(parameters->outfile)-1);
}
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
@ -246,7 +261,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, optarg); fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, optarg);
break; break;
} }
} }while(c != -1);
/* check for possible errors */ /* check for possible errors */
if(img_fol->set_imgdir==1){ if(img_fol->set_imgdir==1){
@ -306,7 +321,7 @@ int main(int argc, char *argv[])
img_fol_t img_fol; img_fol_t img_fol;
opj_event_mgr_t event_mgr; /* event manager */ opj_event_mgr_t event_mgr; /* event manager */
opj_image_t *image = NULL; opj_image_t *image = NULL;
FILE *fsrc = NULL; FILE *fsrc = NULL, *fout = NULL;
unsigned char *src = NULL; unsigned char *src = NULL;
int file_length; int file_length;
int num_images; int num_images;
@ -362,6 +377,19 @@ int main(int argc, char *argv[])
num_images=1; num_images=1;
} }
//
if (parameters.outfile[0] != 0)
{
fout = fopen(parameters.outfile,"w");
if (!fout)
{
fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.outfile);
return 1;
}
}
else
fout = stdout;
/*Encoding image one by one*/ /*Encoding image one by one*/
for(imageno = 0; imageno < num_images ; imageno++) for(imageno = 0; imageno < num_images ; imageno++)
{ {
@ -386,7 +414,13 @@ int main(int argc, char *argv[])
file_length = ftell(fsrc); file_length = ftell(fsrc);
fseek(fsrc, 0, SEEK_SET); fseek(fsrc, 0, SEEK_SET);
src = (unsigned char *) malloc(file_length); src = (unsigned char *) malloc(file_length);
fread(src, 1, file_length, fsrc); if (fread(src, 1, file_length, fsrc) != (size_t)file_length)
{
free(src);
fclose(fsrc);
fprintf(stderr, "\nERROR: fread return a number of element different from the expected.\n");
return 1;
}
fclose(fsrc); fclose(fsrc);
/* decode the code-stream */ /* decode the code-stream */
@ -421,17 +455,17 @@ int main(int argc, char *argv[])
return 1; return 1;
} }
/* dump image */ /* dump image */
j2k_dump_image(stdout, image); j2k_dump_image(fout, image);
/* dump cp */ /* dump cp */
j2k_dump_cp(stdout, image, ((opj_j2k_t*)dinfo->j2k_handle)->cp); j2k_dump_cp(fout, image, ((opj_j2k_t*)dinfo->j2k_handle)->cp);
/* close the byte stream */ /* close the byte stream */
opj_cio_close(cio); opj_cio_close(cio);
/* Write the index to disk */ /* Write the index to disk */
if (*indexfilename) { if (*indexfilename) {
char bSuccess; opj_bool bSuccess;
bSuccess = write_index_file(&cstr_info, indexfilename); bSuccess = write_index_file(&cstr_info, indexfilename);
if (bSuccess) { if (bSuccess) {
fprintf(stderr, "Failed to output index file\n"); fprintf(stderr, "Failed to output index file\n");
@ -472,17 +506,17 @@ int main(int argc, char *argv[])
{ {
free(image->icc_profile_buf); image->icc_profile_buf = NULL; free(image->icc_profile_buf); image->icc_profile_buf = NULL;
} }
j2k_dump_image(stdout, image); j2k_dump_image(fout, image);
/* dump cp */ /* dump cp */
j2k_dump_cp(stdout, image, ((opj_jp2_t*)dinfo->jp2_handle)->j2k->cp); j2k_dump_cp(fout, image, ((opj_jp2_t*)dinfo->jp2_handle)->j2k->cp);
/* close the byte stream */ /* close the byte stream */
opj_cio_close(cio); opj_cio_close(cio);
/* Write the index to disk */ /* Write the index to disk */
if (*indexfilename) { if (*indexfilename) {
char bSuccess; opj_bool bSuccess;
bSuccess = write_index_file(&cstr_info, indexfilename); bSuccess = write_index_file(&cstr_info, indexfilename);
if (bSuccess) { if (bSuccess) {
fprintf(stderr, "Failed to output index file\n"); fprintf(stderr, "Failed to output index file\n");
@ -524,7 +558,7 @@ int main(int argc, char *argv[])
/* Write the index to disk */ /* Write the index to disk */
if (*indexfilename) { if (*indexfilename) {
char bSuccess; opj_bool bSuccess;
bSuccess = write_index_file(&cstr_info, indexfilename); bSuccess = write_index_file(&cstr_info, indexfilename);
if (bSuccess) { if (bSuccess) {
fprintf(stderr, "Failed to output index file\n"); fprintf(stderr, "Failed to output index file\n");
@ -554,6 +588,8 @@ int main(int argc, char *argv[])
} }
fclose(fout);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -85,7 +85,7 @@ typedef struct img_folder{
}img_fol_t; }img_fol_t;
void decode_help_display() { void decode_help_display(void) {
fprintf(stdout,"HELP for j2k_to_image\n----\n\n"); fprintf(stdout,"HELP for j2k_to_image\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n"); fprintf(stdout,"- the -h option displays this help information on screen\n\n");
@ -237,7 +237,7 @@ char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparamet
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol, char *indexfilename) { int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol, char *indexfilename) {
/* parse the command line */ /* parse the command line */
int totlen; int totlen, c;
option_t long_option[]={ option_t long_option[]={
{"ImgDir",REQ_ARG, NULL ,'y'}, {"ImgDir",REQ_ARG, NULL ,'y'},
{"OutFor",REQ_ARG, NULL ,'O'}, {"OutFor",REQ_ARG, NULL ,'O'},
@ -253,8 +253,8 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
"h" ; "h" ;
totlen=sizeof(long_option); totlen=sizeof(long_option);
img_fol->set_out_format = 0; img_fol->set_out_format = 0;
while (1) { do {
int c = getopt_long(argc, argv,optlist,long_option,totlen); c = getopt_long(argc, argv,optlist,long_option,totlen);
if (c == -1) if (c == -1)
break; break;
switch (c) { switch (c) {
@ -457,7 +457,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, optarg); fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, optarg);
break; break;
} }
} }while(c != -1);
/* check for possible errors */ /* check for possible errors */
if(img_fol->set_imgdir==1){ if(img_fol->set_imgdir==1){
@ -521,7 +521,7 @@ int main(int argc, char **argv) {
int file_length; int file_length;
int num_images; int num_images;
int i,imageno; int i,imageno;
dircnt_t *dirptr; dircnt_t *dirptr = NULL;
opj_dinfo_t* dinfo = NULL; /* handle to a decompressor */ opj_dinfo_t* dinfo = NULL; /* handle to a decompressor */
opj_cio_t *cio = NULL; opj_cio_t *cio = NULL;
opj_codestream_info_t cstr_info; /* Codestream information structure */ opj_codestream_info_t cstr_info; /* Codestream information structure */
@ -595,7 +595,13 @@ int main(int argc, char **argv) {
file_length = ftell(fsrc); file_length = ftell(fsrc);
fseek(fsrc, 0, SEEK_SET); fseek(fsrc, 0, SEEK_SET);
src = (unsigned char *) malloc(file_length); src = (unsigned char *) malloc(file_length);
fread(src, 1, file_length, fsrc); if (fread(src, 1, file_length, fsrc) != (size_t)file_length)
{
free(src);
fclose(fsrc);
fprintf(stderr, "\nERROR: fread return a number of element different from the expected.\n");
return 1;
}
fclose(fsrc); fclose(fsrc);
/* decode the code-stream */ /* decode the code-stream */
@ -635,7 +641,7 @@ int main(int argc, char **argv) {
/* Write the index to disk */ /* Write the index to disk */
if (*indexfilename) { if (*indexfilename) {
char bSuccess; opj_bool bSuccess;
bSuccess = write_index_file(&cstr_info, indexfilename); bSuccess = write_index_file(&cstr_info, indexfilename);
if (bSuccess) { if (bSuccess) {
fprintf(stderr, "Failed to output index file\n"); fprintf(stderr, "Failed to output index file\n");
@ -677,7 +683,7 @@ int main(int argc, char **argv) {
/* Write the index to disk */ /* Write the index to disk */
if (*indexfilename) { if (*indexfilename) {
char bSuccess; opj_bool bSuccess;
bSuccess = write_index_file(&cstr_info, indexfilename); bSuccess = write_index_file(&cstr_info, indexfilename);
if (bSuccess) { if (bSuccess) {
fprintf(stderr, "Failed to output index file\n"); fprintf(stderr, "Failed to output index file\n");
@ -719,7 +725,7 @@ int main(int argc, char **argv) {
/* Write the index to disk */ /* Write the index to disk */
if (*indexfilename) { if (*indexfilename) {
char bSuccess; opj_bool bSuccess;
bSuccess = write_index_file(&cstr_info, indexfilename); bSuccess = write_index_file(&cstr_info, indexfilename);
if (bSuccess) { if (bSuccess) {
fprintf(stderr, "Failed to output index file\n"); fprintf(stderr, "Failed to output index file\n");

View File

@ -60,7 +60,7 @@ typedef struct option
#define EMSG "" #define EMSG ""
/* As this class remembers its values from one Java call to the other, reset the values before each use */ /* As this class remembers its values from one Java call to the other, reset the values before each use */
void reset_options_reading() { void reset_options_reading(void) {
opterr = 1; opterr = 1;
optind = 1; optind = 1;
} }
@ -129,7 +129,7 @@ int getopt(int nargc, char *const *nargv, const char *ostr) {
int getopt_long(int argc, char * const argv[], const char *optstring, int getopt_long(int argc, char * const argv[], const char *optstring,
struct option *longopts, int totlen) { const struct option *longopts, int totlen) {
static int lastidx,lastofs; static int lastidx,lastofs;
char *tmp; char *tmp;
int i,len; int i,len;

View File

@ -24,6 +24,6 @@ extern char *optarg;
extern int getopt(int nargc, char *const *nargv, const char *ostr); extern int getopt(int nargc, char *const *nargv, const char *ostr);
extern int getopt_long(int argc, char * const argv[], const char *optstring, extern int getopt_long(int argc, char * const argv[], const char *optstring,
const struct option *longopts, int totlen); const struct option *longopts, int totlen);
extern void reset_options_reading(); extern void reset_options_reading(void);
#endif /* _GETOPT_H_ */ #endif /* _GETOPT_H_ */

View File

@ -144,7 +144,7 @@ int main(int argc, char *argv[]){
int listening_socket = open_listeningsocket(); int listening_socket = open_listeningsocket();
int addrlen = sizeof(peer_sin); unsigned int addrlen = sizeof(peer_sin);
cachelist_param_t *cachelist = gene_cachelist(); cachelist_param_t *cachelist = gene_cachelist();

View File

@ -46,9 +46,8 @@ ADD_EXECUTABLE(frames_to_mj2
${OPJ_SRCS} ${OPJ_SRCS}
${MJ2_SRCS} ${MJ2_SRCS}
) )
IF(LCMS_FOUND OR LCMS2_FOUND) TARGET_LINK_LIBRARIES(frames_to_mj2 ${LCMS_LIBNAME})
TARGET_LINK_LIBRARIES(frames_to_mj2 ${LCMS_LIBNAME})
ENDIF(LCMS_FOUND OR LCMS2_FOUND)
IF(UNIX) IF(UNIX)
TARGET_LINK_LIBRARIES(frames_to_mj2 m) TARGET_LINK_LIBRARIES(frames_to_mj2 m)
ENDIF(UNIX) ENDIF(UNIX)
@ -60,9 +59,8 @@ ADD_EXECUTABLE(mj2_to_frames
${MJ2_SRCS} ${MJ2_SRCS}
${OPENJPEG_SOURCE_DIR}/applications/common/color.c ${OPENJPEG_SOURCE_DIR}/applications/common/color.c
) )
IF(LCMS_FOUND OR LCMS2_FOUND) TARGET_LINK_LIBRARIES(mj2_to_frames ${LCMS_LIBNAME})
TARGET_LINK_LIBRARIES(mj2_to_frames ${LCMS_LIBNAME})
ENDIF(LCMS_FOUND OR LCMS2_FOUND)
IF(UNIX) IF(UNIX)
TARGET_LINK_LIBRARIES(mj2_to_frames m) TARGET_LINK_LIBRARIES(mj2_to_frames m)
ENDIF(UNIX) ENDIF(UNIX)
@ -72,9 +70,8 @@ ADD_EXECUTABLE(extract_j2k_from_mj2
${OPJ_SRCS} ${OPJ_SRCS}
${MJ2_SRCS} ${MJ2_SRCS}
) )
IF(LCMS_FOUND OR LCMS2_FOUND) TARGET_LINK_LIBRARIES(extract_j2k_from_mj2 ${LCMS_LIBNAME})
TARGET_LINK_LIBRARIES(extract_j2k_from_mj2 ${LCMS_LIBNAME})
ENDIF(LCMS_FOUND OR LCMS2_FOUND)
IF(UNIX) IF(UNIX)
TARGET_LINK_LIBRARIES(extract_j2k_from_mj2 m) TARGET_LINK_LIBRARIES(extract_j2k_from_mj2 m)
ENDIF(UNIX) ENDIF(UNIX)
@ -84,9 +81,8 @@ ADD_EXECUTABLE(wrap_j2k_in_mj2
${OPJ_SRCS} ${OPJ_SRCS}
${MJ2_SRCS} ${MJ2_SRCS}
) )
IF(LCMS_FOUND OR LCMS2_FOUND) TARGET_LINK_LIBRARIES(wrap_j2k_in_mj2 ${LCMS_LIBNAME})
TARGET_LINK_LIBRARIES(wrap_j2k_in_mj2 ${LCMS_LIBNAME})
ENDIF(LCMS_FOUND OR LCMS2_FOUND)
IF(UNIX) IF(UNIX)
TARGET_LINK_LIBRARIES(wrap_j2k_in_mj2 m) TARGET_LINK_LIBRARIES(wrap_j2k_in_mj2 m)
ENDIF(UNIX) ENDIF(UNIX)

View File

@ -199,29 +199,29 @@ void help_display()
fprintf(stdout,"TotalDisto\n\n"); fprintf(stdout,"TotalDisto\n\n");
} }
int give_progression(char progression[4]) OPJ_PROG_ORDER give_progression(char progression[5])
{ {
if (progression[0] == 'L' && progression[1] == 'R' if (progression[0] == 'L' && progression[1] == 'R'
&& progression[2] == 'C' && progression[3] == 'P') { && progression[2] == 'C' && progression[3] == 'P') {
return 0; return LRCP;
} else { } else {
if (progression[0] == 'R' && progression[1] == 'L' if (progression[0] == 'R' && progression[1] == 'L'
&& progression[2] == 'C' && progression[3] == 'P') { && progression[2] == 'C' && progression[3] == 'P') {
return 1; return RLCP;
} else { } else {
if (progression[0] == 'R' && progression[1] == 'P' if (progression[0] == 'R' && progression[1] == 'P'
&& progression[2] == 'C' && progression[3] == 'L') { && progression[2] == 'C' && progression[3] == 'L') {
return 2; return RPCL;
} else { } else {
if (progression[0] == 'P' && progression[1] == 'C' if (progression[0] == 'P' && progression[1] == 'C'
&& progression[2] == 'R' && progression[3] == 'L') { && progression[2] == 'R' && progression[3] == 'L') {
return 3; return PCRL;
} else { } else {
if (progression[0] == 'C' && progression[1] == 'P' if (progression[0] == 'C' && progression[1] == 'P'
&& progression[2] == 'R' && progression[3] == 'L') { && progression[2] == 'R' && progression[3] == 'L') {
return 4; return CPRL;
} else { } else {
return -1; return PROG_UNKNOWN;
} }
} }
} }
@ -475,9 +475,9 @@ int main(int argc, char **argv)
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'p': /* progression order */ case 'p': /* progression order */
{ {
char progression[4]; char progression[5];
strncpy(progression, optarg, 4); strncpy(progression, optarg, 5);
j2k_parameters->prog_order = give_progression(progression); j2k_parameters->prog_order = give_progression(progression);
if (j2k_parameters->prog_order == -1) { if (j2k_parameters->prog_order == -1) {
fprintf(stderr, "Unrecognized progression order " fprintf(stderr, "Unrecognized progression order "
@ -696,7 +696,7 @@ int main(int argc, char **argv)
movie->tk[0].num_samples = movie->tk[0].num_samples =
yuv_num_frames(&movie->tk[0],mj2_parameters.infile); yuv_num_frames(&movie->tk[0],mj2_parameters.infile);
if (movie->tk[0].num_samples == -1) { if (movie->tk[0].num_samples == 0) {
return 1; return 1;
} }

View File

@ -240,9 +240,7 @@ void mj2_tts_decompact(mj2_tk_t * tk)
*/ */
void mj2_stsc_decompact(mj2_tk_t * tk) void mj2_stsc_decompact(mj2_tk_t * tk)
{ {
int j, i; unsigned int i, j, k, sampleno = 0;
unsigned int k;
int sampleno=0;
if (tk->num_samplestochunk == 1) { if (tk->num_samplestochunk == 1) {
tk->num_chunks = tk->num_chunks =
@ -283,10 +281,8 @@ void mj2_stsc_decompact(mj2_tk_t * tk)
*/ */
void mj2_stco_decompact(mj2_tk_t * tk) void mj2_stco_decompact(mj2_tk_t * tk)
{ {
int j; unsigned int i, j, k = 0;
unsigned int i; unsigned int intra_chunk_offset;
int k = 0;
int intra_chunk_offset;
for (i = 0; i < tk->num_chunks; i++) { for (i = 0; i < tk->num_chunks; i++) {
intra_chunk_offset = 0; intra_chunk_offset = 0;
@ -585,7 +581,7 @@ int mj2_read_stsz(mj2_tk_t * tk, opj_cio_t *cio)
*/ */
void mj2_write_stsc(mj2_tk_t * tk, opj_cio_t *cio) void mj2_write_stsc(mj2_tk_t * tk, opj_cio_t *cio)
{ {
int i; unsigned int i;
mj2_box_t box; mj2_box_t box;
box.init_pos = cio_tell(cio); box.init_pos = cio_tell(cio);
@ -617,7 +613,7 @@ void mj2_write_stsc(mj2_tk_t * tk, opj_cio_t *cio)
*/ */
int mj2_read_stsc(mj2_tk_t * tk, opj_cio_t *cio) int mj2_read_stsc(mj2_tk_t * tk, opj_cio_t *cio)
{ {
int i; unsigned int i;
mj2_box_t box; mj2_box_t box;
mj2_read_boxhdr(&box, cio); /* Box Size */ mj2_read_boxhdr(&box, cio); /* Box Size */

View File

@ -103,7 +103,7 @@ typedef struct mj2_tts {
Chunk Chunk
*/ */
typedef struct mj2_chunk { typedef struct mj2_chunk {
int num_samples; unsigned int num_samples;
int sample_descr_idx; int sample_descr_idx;
int offset; int offset;
} mj2_chunk_t; } mj2_chunk_t;
@ -112,8 +112,8 @@ typedef struct mj2_chunk {
Sample to chunk Sample to chunk
*/ */
typedef struct mj2_sampletochunk { typedef struct mj2_sampletochunk {
int first_chunk; unsigned int first_chunk;
int samples_per_chunk; unsigned int samples_per_chunk;
int sample_descr_idx; int sample_descr_idx;
} mj2_sampletochunk_t; } mj2_sampletochunk_t;
@ -205,7 +205,7 @@ typedef struct mj2_tk {
mj2_tts_t *tts; mj2_tts_t *tts;
unsigned int num_chunks; unsigned int num_chunks;
mj2_chunk_t *chunk; mj2_chunk_t *chunk;
int num_samplestochunk; unsigned int num_samplestochunk;
mj2_sampletochunk_t *sampletochunk; mj2_sampletochunk_t *sampletochunk;
char *name; char *name;
opj_jp2_t jp2_struct; opj_jp2_t jp2_struct;

View File

@ -37,20 +37,20 @@
/* */ /* */
/* ----------------------- */ /* ----------------------- */
int yuv_num_frames(mj2_tk_t * tk, char *infile) unsigned int yuv_num_frames(mj2_tk_t * tk, char *infile)
{ {
int numimages, frame_size, prec_size; unsigned int prec_size;
long end_of_f; long end_of_f, frame_size;
FILE *f; FILE *f;
f = fopen(infile,"rb"); f = fopen(infile,"rb");
if (!f) { if (!f) {
fprintf(stderr, "failed to open %s for reading\n",infile); fprintf(stderr, "failed to open %s for reading\n",infile);
return -1; return 0;
} }
prec_size = (tk->depth + 7)/8;/* bytes of precision */ prec_size = (tk->depth + 7)/8;/* bytes of precision */
frame_size = (int) (tk->w * tk->h * (1.0 + (double) 2 / (double) (tk->CbCr_subsampling_dx * tk->CbCr_subsampling_dy))); /* Calculate frame size */ frame_size = (long) (tk->w * tk->h * (1.0 + (double) 2 / (double) (tk->CbCr_subsampling_dx * tk->CbCr_subsampling_dy))); /* Calculate frame size */
frame_size *= prec_size; frame_size *= prec_size;
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
@ -60,13 +60,11 @@ int yuv_num_frames(mj2_tk_t * tk, char *infile)
fprintf(stderr, fprintf(stderr,
"YUV does not contains any frame of %d x %d size\n", tk->w, "YUV does not contains any frame of %d x %d size\n", tk->w,
tk->h); tk->h);
return -1; return 0;
} }
fclose(f);
numimages = end_of_f / frame_size; /* Calculate number of images */ return (unsigned int)(end_of_f / frame_size);
fclose(f);
return numimages;
} }
// ----------------------- // -----------------------

View File

@ -39,7 +39,7 @@ opj_image_t *mj2_image_create(mj2_tk_t * tk, opj_cparameters_t *parameters);
char yuvtoimage(mj2_tk_t * tk, opj_image_t * img, int frame_num, opj_cparameters_t *parameters, char* infile); char yuvtoimage(mj2_tk_t * tk, opj_image_t * img, int frame_num, opj_cparameters_t *parameters, char* infile);
int yuv_num_frames(mj2_tk_t * tk, char *infile); unsigned int yuv_num_frames(mj2_tk_t * tk, char *infile);
#endif #endif

View File

@ -527,7 +527,7 @@ static void dwt_decode_tile(opj_tcd_tilecomp_t* tilec, int numres, DWT1DFN dwt_1
int w = tilec->x1 - tilec->x0; int w = tilec->x1 - tilec->x0;
h.mem = opj_aligned_malloc(dwt_decode_max_resolution(tr, numres) * sizeof(int)); h.mem = (int*)opj_aligned_malloc(dwt_decode_max_resolution(tr, numres) * sizeof(int));
v.mem = h.mem; v.mem = h.mem;
while( --numres) { while( --numres) {

View File

@ -30,6 +30,7 @@
Utility functions Utility functions
==========================================================*/ ==========================================================*/
#ifdef OPJ_CODE_NOT_USED
#ifndef _WIN32 #ifndef _WIN32
static char* static char*
i2a(unsigned i, char *a, unsigned r) { i2a(unsigned i, char *a, unsigned r) {
@ -58,7 +59,7 @@ _itoa(int i, char *a, int r) {
} }
#endif /* !_WIN32 */ #endif /* !_WIN32 */
#endif
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
opj_event_mgr_t* OPJ_CALLCONV 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) {

View File

@ -236,7 +236,7 @@ static void j2k_read_unk(opj_j2k_t *j2k);
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
typedef struct j2k_prog_order{ typedef struct j2k_prog_order{
OPJ_PROG_ORDER enum_prog; OPJ_PROG_ORDER enum_prog;
char str_prog[4]; char str_prog[5];
}j2k_prog_order_t; }j2k_prog_order_t;
j2k_prog_order_t j2k_prog_order_list[] = { j2k_prog_order_t j2k_prog_order_list[] = {
@ -297,6 +297,9 @@ static int j2k_get_num_tp(opj_cp_t *cp,int pino,int tileno){
/** mem allocation for TLM marker*/ /** mem allocation for TLM marker*/
int j2k_calculate_tp(opj_cp_t *cp,int img_numcomp,opj_image_t *image,opj_j2k_t *j2k ){ int j2k_calculate_tp(opj_cp_t *cp,int img_numcomp,opj_image_t *image,opj_j2k_t *j2k ){
int pino,tileno,totnum_tp=0; int pino,tileno,totnum_tp=0;
OPJ_ARG_NOT_USED(img_numcomp);
j2k->cur_totnum_tp = (int *) opj_malloc(cp->tw * cp->th * sizeof(int)); j2k->cur_totnum_tp = (int *) opj_malloc(cp->tw * cp->th * sizeof(int));
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) { for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
int cur_totnum_tp = 0; int cur_totnum_tp = 0;
@ -835,6 +838,15 @@ static void j2k_read_qcx(opj_j2k_t *j2k, int compno, int len) {
}; };
}; };
#else
/* We check whether there are too many subbands */
if ((numbands < 0) || (numbands >= J2K_MAXBANDS)) {
opj_event_msg(j2k->cinfo, EVT_WARNING ,
"bad number of subbands in Sqcx (%d) regarding to J2K_MAXBANDS (%d) \n"
"- limiting number of bands to J2K_MAXBANDS and try to move to the next markers\n", numbands, J2K_MAXBANDS);
}
#endif /* USE_JPWL */ #endif /* USE_JPWL */
for (bandno = 0; bandno < numbands; bandno++) { for (bandno = 0; bandno < numbands; bandno++) {
@ -847,8 +859,10 @@ static void j2k_read_qcx(opj_j2k_t *j2k, int compno, int len) {
expn = tmp >> 11; expn = tmp >> 11;
mant = tmp & 0x7ff; mant = tmp & 0x7ff;
} }
tccp->stepsizes[bandno].expn = expn; if (bandno < J2K_MAXBANDS){
tccp->stepsizes[bandno].mant = mant; tccp->stepsizes[bandno].expn = expn;
tccp->stepsizes[bandno].mant = mant;
}
} }
/* Add Antonin : if scalar_derived -> compute other stepsizes */ /* Add Antonin : if scalar_derived -> compute other stepsizes */
@ -912,7 +926,7 @@ static void j2k_read_qcc(opj_j2k_t *j2k) {
int len, compno; int len, compno;
int numcomp = j2k->image->numcomps; int numcomp = j2k->image->numcomps;
opj_cio_t *cio = j2k->cio; opj_cio_t *cio = j2k->cio;
len = cio_read(cio, 2); /* Lqcc */ len = cio_read(cio, 2); /* Lqcc */
compno = cio_read(cio, numcomp <= 256 ? 1 : 2); /* Cqcc */ compno = cio_read(cio, numcomp <= 256 ? 1 : 2); /* Cqcc */
@ -1847,9 +1861,10 @@ opj_image_t* j2k_decode_jpt_stream(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestre
opj_image_t *image = NULL; opj_image_t *image = NULL;
opj_jpt_msg_header_t header; opj_jpt_msg_header_t header;
int position; int position;
opj_common_ptr cinfo = j2k->cinfo; opj_common_ptr cinfo = j2k->cinfo;
OPJ_ARG_NOT_USED(cstr_info);
j2k->cio = cio; j2k->cio = cio;
/* create an empty image */ /* create an empty image */

View File

@ -398,13 +398,16 @@ static opj_bool jp2_read_pclr(opj_jp2_t *jp2, opj_cio_t *cio,
unsigned short i, j; unsigned short i, j;
unsigned char uc; unsigned char uc;
OPJ_ARG_NOT_USED(box);
OPJ_ARG_NOT_USED(jp2);
/* Part 1, I.5.3.4: 'There shall be at most one Palette box inside /* Part 1, I.5.3.4: 'There shall be at most one Palette box inside
* a JP2 Header box' : * a JP2 Header box' :
*/ */
if(color->jp2_pclr) return OPJ_FALSE; if(color->jp2_pclr) return OPJ_FALSE;
nr_entries = cio_read(cio, 2); /* NE */ nr_entries = (unsigned short)cio_read(cio, 2); /* NE */
nr_channels = cio_read(cio, 1);/* NPC */ nr_channels = (unsigned short)cio_read(cio, 1);/* NPC */
entries = (unsigned int*) entries = (unsigned int*)
opj_malloc(nr_channels * nr_entries * sizeof(unsigned int)); opj_malloc(nr_channels * nr_entries * sizeof(unsigned int));
@ -446,6 +449,9 @@ static opj_bool jp2_read_cmap(opj_jp2_t *jp2, opj_cio_t *cio,
opj_jp2_cmap_comp_t *cmap; opj_jp2_cmap_comp_t *cmap;
unsigned short i, nr_channels; unsigned short i, nr_channels;
OPJ_ARG_NOT_USED(box);
OPJ_ARG_NOT_USED(jp2);
/* Need nr_channels: */ /* Need nr_channels: */
if(color->jp2_pclr == NULL) return OPJ_FALSE; if(color->jp2_pclr == NULL) return OPJ_FALSE;
@ -460,7 +466,7 @@ static opj_bool jp2_read_cmap(opj_jp2_t *jp2, opj_cio_t *cio,
for(i = 0; i < nr_channels; ++i) for(i = 0; i < nr_channels; ++i)
{ {
cmap[i].cmp = cio_read(cio, 2); cmap[i].cmp = (unsigned short)cio_read(cio, 2);
cmap[i].mtyp = cio_read(cio, 1); cmap[i].mtyp = cio_read(cio, 1);
cmap[i].pcol = cio_read(cio, 1); cmap[i].pcol = cio_read(cio, 1);
@ -511,12 +517,15 @@ static opj_bool jp2_read_cdef(opj_jp2_t *jp2, opj_cio_t *cio,
opj_jp2_cdef_info_t *info; opj_jp2_cdef_info_t *info;
unsigned short i, n; unsigned short i, n;
OPJ_ARG_NOT_USED(box);
OPJ_ARG_NOT_USED(jp2);
/* Part 1, I.5.3.6: 'The shall be at most one Channel Definition box /* Part 1, I.5.3.6: 'The shall be at most one Channel Definition box
* inside a JP2 Header box.' * inside a JP2 Header box.'
*/ */
if(color->jp2_cdef) return OPJ_FALSE; if(color->jp2_cdef) return OPJ_FALSE;
if((n = cio_read(cio, 2)) == 0) return OPJ_FALSE; /* szukw000: FIXME */ if((n = (unsigned short)cio_read(cio, 2)) == 0) return OPJ_FALSE; /* szukw000: FIXME */
info = (opj_jp2_cdef_info_t*) info = (opj_jp2_cdef_info_t*)
opj_malloc(n * sizeof(opj_jp2_cdef_info_t)); opj_malloc(n * sizeof(opj_jp2_cdef_info_t));
@ -527,9 +536,9 @@ static opj_bool jp2_read_cdef(opj_jp2_t *jp2, opj_cio_t *cio,
for(i = 0; i < n; ++i) for(i = 0; i < n; ++i)
{ {
info[i].cn = cio_read(cio, 2); info[i].cn = (unsigned short)cio_read(cio, 2);
info[i].typ = cio_read(cio, 2); info[i].typ = (unsigned short)cio_read(cio, 2);
info[i].asoc = cio_read(cio, 2); info[i].asoc = (unsigned short)cio_read(cio, 2);
} }
return OPJ_TRUE; return OPJ_TRUE;

View File

@ -75,9 +75,10 @@ jpwl_epc_ms_t *jpwl_epc_create(opj_j2k_t *j2k, opj_bool esd_on, opj_bool red_on,
@param sensval pointer to an array of sensitivity values (if NULL, they will be automatically filled) @param sensval pointer to an array of sensitivity values (if NULL, they will be automatically filled)
@return returns the freshly created ESD @return returns the freshly created ESD
*/ */
jpwl_esd_ms_t *jpwl_esd_create(opj_j2k_t *j2k, int comps, unsigned char addrm, unsigned char ad_size, jpwl_esd_ms_t *jpwl_esd_create(opj_j2k_t *j2k, int comps,
unsigned char senst, int se_size, int tileno, unsigned char addrm, unsigned char ad_size,
unsigned long int svalnum, void *sensval); unsigned char senst, int se_size, int tileno,
unsigned long int svalnum, void *sensval);
/** this function is used to compare two JPWL markers based on /** this function is used to compare two JPWL markers based on
their relevant wishlist position their relevant wishlist position
@ -168,7 +169,7 @@ void j2k_add_marker(opj_codestream_info_t *cstr_info, unsigned short int type, i
/* expand the list? */ /* expand the list? */
if ((cstr_info->marknum + 1) > cstr_info->maxmarknum) { if ((cstr_info->marknum + 1) > cstr_info->maxmarknum) {
cstr_info->maxmarknum = 100 + (int) ((float) cstr_info->maxmarknum * 1.0F); cstr_info->maxmarknum = 100 + (int) ((float) cstr_info->maxmarknum * 1.0F);
cstr_info->marker = opj_realloc(cstr_info->marker, cstr_info->maxmarknum); cstr_info->marker = (opj_marker_info_t*)opj_realloc(cstr_info->marker, cstr_info->maxmarknum);
} }
/* add the marker */ /* add the marker */
@ -906,7 +907,7 @@ void j2k_read_epc(opj_j2k_t *j2k) {
unsigned short int Lepc, Pcrc = 0x0000; unsigned short int Lepc, Pcrc = 0x0000;
unsigned char Pepc; unsigned char Pepc;
opj_cio_t *cio = j2k->cio; opj_cio_t *cio = j2k->cio;
char *ans1; const char *ans1;
/* Simply read the EPC parameters */ /* Simply read the EPC parameters */
Lepcp = cio_tell(cio); Lepcp = cio_tell(cio);

View File

@ -1200,9 +1200,10 @@ int jpwl_esds_add(opj_j2k_t *j2k, jpwl_marker_t *jwmarker, int *jwmarker_num,
return 0; return 0;
} }
jpwl_esd_ms_t *jpwl_esd_create(opj_j2k_t *j2k, int comp, unsigned char addrm, unsigned char ad_size, jpwl_esd_ms_t *jpwl_esd_create(opj_j2k_t *j2k, int comp,
unsigned char senst, unsigned char se_size, int tileno, unsigned char addrm, unsigned char ad_size,
unsigned long int svalnum, void *sensval) { unsigned char senst, int se_size, int tileno,
unsigned long int svalnum, void *sensval) {
jpwl_esd_ms_t *esd = NULL; jpwl_esd_ms_t *esd = NULL;
@ -1232,7 +1233,7 @@ jpwl_esd_ms_t *jpwl_esd_create(opj_j2k_t *j2k, int comp, unsigned char addrm, un
/* packet mode */ /* packet mode */
case (0): case (0):
ad_size = 0; /* as per the standard */ ad_size = 0; /* as per the standard */
esd->sensval_size = se_size; esd->sensval_size = (unsigned int)se_size;
break; break;
/* byte range */ /* byte range */

View File

@ -36,6 +36,10 @@
#ifndef OPJ_STATIC #ifndef OPJ_STATIC
BOOL APIENTRY BOOL APIENTRY
DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
OPJ_ARG_NOT_USED(lpReserved);
OPJ_ARG_NOT_USED(hModule);
switch (ul_reason_for_call) { switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH : case DLL_PROCESS_ATTACH :
break; break;

View File

@ -63,6 +63,8 @@ typedef int opj_bool;
#define OPJ_TRUE 1 #define OPJ_TRUE 1
#define OPJ_FALSE 0 #define OPJ_FALSE 0
// Avoid compile-time warning because parameter is not used
#define OPJ_ARG_NOT_USED(x) (void)(x)
/* /*
========================================================== ==========================================================
Useful constant definitions Useful constant definitions

View File

@ -382,9 +382,10 @@ static INLINE void t1_dec_sigpass_step_raw(
int vsc) int vsc)
{ {
int v, flag; int v, flag;
opj_raw_t *raw = t1->raw; /* RAW component */ opj_raw_t *raw = t1->raw; /* RAW component */
OPJ_ARG_NOT_USED(orient);
flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp);
if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) { if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) {
if (raw_decode(raw)) { if (raw_decode(raw)) {
@ -823,9 +824,10 @@ static void t1_dec_clnpass_step_partial(
int oneplushalf) int oneplushalf)
{ {
int v, flag; int v, flag;
opj_mqc_t *mqc = t1->mqc; /* MQC component */ opj_mqc_t *mqc = t1->mqc; /* MQC component */
OPJ_ARG_NOT_USED(orient);
flag = *flagsp; flag = *flagsp;
mqc_setcurctx(mqc, t1_getctxno_sc(flag)); mqc_setcurctx(mqc, t1_getctxno_sc(flag));
v = mqc_decode(mqc) ^ t1_getspb(flag); v = mqc_decode(mqc) ^ t1_getspb(flag);

View File

@ -149,8 +149,8 @@ static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_itera
c[1] = 145; c[1] = 145;
c[2] = 0; c[2] = 0;
c[3] = 4; c[3] = 4;
c[4] = (tile->packno % 65536) / 256; c[4] = (unsigned char)((tile->packno % 65536) / 256);
c[5] = (tile->packno % 65536) % 256; c[5] = (unsigned char)((tile->packno % 65536) % 256);
c += 6; c += 6;
} }
/* </SOP> */ /* </SOP> */

View File

@ -676,6 +676,8 @@ void tcd_malloc_decode_tile(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp,
opj_tcp_t *tcp; opj_tcp_t *tcp;
opj_tcd_tile_t *tile; opj_tcd_tile_t *tile;
OPJ_ARG_NOT_USED(cstr_info);
tcd->cp = cp; tcd->cp = cp;
tcp = &(cp->tcps[cp->tileno[tileno]]); tcp = &(cp->tcps[cp->tileno[tileno]]);
@ -1416,18 +1418,23 @@ opj_bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno
if (tcd->tcp->mct) { if (tcd->tcp->mct) {
int n = (tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0); int n = (tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0);
if (tcd->tcp->tccps[0].qmfbid == 1) {
mct_decode( if (tile->numcomps >= 3 ){
tile->comps[0].data, if (tcd->tcp->tccps[0].qmfbid == 1) {
tile->comps[1].data, mct_decode(
tile->comps[2].data, tile->comps[0].data,
n); tile->comps[1].data,
} else { tile->comps[2].data,
mct_decode_real( n);
(float*)tile->comps[0].data, } else {
(float*)tile->comps[1].data, mct_decode_real(
(float*)tile->comps[2].data, (float*)tile->comps[0].data,
n); (float*)tile->comps[1].data,
(float*)tile->comps[2].data,
n);
}
} else{
opj_event_msg(tcd->cinfo, EVT_WARNING,"Number of components (%d) is inconsistent with a MCT. Skip the MCT step.\n",tile->numcomps);
} }
} }

View File

@ -1,6 +1,6 @@
/* create config.h for CMake */ /* create config.h for CMake */
#define PACKAGE_VERSION "@PACKAGE_VERSION@" #define PACKAGE_VERSION "@PACKAGE_VERSION@"
#
#cmakedefine HAVE_INTTYPES_H @HAS_INTTYPES_H@ #cmakedefine HAVE_INTTYPES_H @HAS_INTTYPES_H@
#cmakedefine HAVE_MEMORY_H @HAS_MEMORY_H@ #cmakedefine HAVE_MEMORY_H @HAS_MEMORY_H@
#cmakedefine HAVE_STDINT_H @HAS_STDINT_H@ #cmakedefine HAVE_STDINT_H @HAS_STDINT_H@
@ -14,9 +14,9 @@
#cmakedefine HAVE_PNG_H @HAVE_PNG_H@ #cmakedefine HAVE_PNG_H @HAVE_PNG_H@
#cmakedefine HAVE_LIBTIFF @HAVE_LIBTIFF@ #cmakedefine HAVE_LIBTIFF @HAVE_LIBTIFF@
#cmakedefine HAVE_TIFF_H @HAVE_TIFF_H@ #cmakedefine HAVE_TIFF_H @HAVE_TIFF_H@
#
#cmakedefine HAVE_LIBLCMS1 @HAVE_LIBLCMS1@ #cmakedefine HAVE_LIBLCMS1 @HAVE_LIBLCMS1@
#cmakedefine HAVE_LIBLCMS2 @HAVE_LIBLCMS2@ #cmakedefine HAVE_LIBLCMS2 @HAVE_LIBLCMS2@
#cmakedefine HAVE_LCMS1_H @HAVE_LCMS1_H@ #cmakedefine HAVE_LCMS1_H @HAVE_LCMS1_H@
#cmakedefine HAVE_LCMS2_H @HAVE_LCMS2_H@ #cmakedefine HAVE_LCMS2_H @HAVE_LCMS2_H@
#

45
tests/CMakeLists.txt Normal file
View File

@ -0,0 +1,45 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
INCLUDE_DIRECTORIES(${OPENJPEG_SOURCE_DIR}/libopenjpeg
${OPENJPEG_SOURCE_DIR}/applications/codec
${OPENJPEG_SOURCE_DIR}/applications/common
${Z_INCLUDE_DIRNAME}
${PNG_INCLUDE_DIRNAME}
${TIFF_INCLUDE_DIRNAME}
)
# First thing define the common source:
SET(comparePGXimages_SRCS comparePGXimages.c ${OPENJPEG_SOURCE_DIR}/applications/codec/convert.c)
SET(compare_dump_files_SRCS compare_dump_files.c)
# If not getopt was found then add it to the exe:
IF(DONT_HAVE_GETOPT)
message("dont have getopt, we will add it")
SET(comparePGXimages_SRCS
${comparePGXimages_SRCS}
${OPENJPEG_SOURCE_DIR}/applications/common/getopt.c
)
SET(compare_dump_files_SRCS
${compare_dump_files_SRCS}
${OPENJPEG_SOURCE_DIR}/applications/common/getopt.c
)
ENDIF(DONT_HAVE_GETOPT)
ADD_EXECUTABLE(comparePGXimages ${comparePGXimages_SRCS})
TARGET_LINK_LIBRARIES(comparePGXimages ${OPENJPEG_LIBRARY_NAME}
${Z_LIBNAME}
${PNG_LIBNAME}
${TIFF_LIBNAME}
)
ADD_EXECUTABLE(compare_dump_files ${compare_dump_files_SRCS})
# No image send to the dashboard if lib PNG is not available.
IF(NOT HAVE_LIBPNG)
MESSAGE(WARNING "Lib PNG seems to be not available: if you want run the non-regression tests with images reported to the dashboard, you need it (try BUILD_THIRDPARTY)")
ENDIF(NOT HAVE_LIBPNG)
ADD_SUBDIRECTORY(conformance)
ADD_SUBDIRECTORY(nonregression)

802
tests/comparePGXimages.c Normal file
View File

@ -0,0 +1,802 @@
/*
* Copyright (c) 2011, Mickael Savinaud, Communications & Systemes <mickael.savinaud@c-s.fr>
* 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.
*/
/*
* comparePGXimages.c
*
* Created on: 8 juil. 2011
* Author: mickael
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include "opj_config.h"
#include "getopt.h"
#include "openjpeg.h"
#include "format_defs.h"
#include "convert.h"
double* parseToleranceValues( char* inArg, const int nbcomp);
void comparePGXimages_help_display(void);
opj_image_t* readImageFromFilePGX(char* filename, int nbFilenamePGX, char *separator);
#ifdef HAVE_LIBPNG
int imageToPNG(const opj_image_t* image, const char* filename, int num_comp_select);
#endif
typedef struct test_cmp_parameters
{
/** */
char* base_filename;
/** */
char* test_filename;
/** Number of components */
int nbcomp;
/** */
double* tabMSEvalues;
/** */
double* tabPEAKvalues;
/** */
int nr_flag;
/** */
char separator_base[2];
/** */
char separator_test[2];
} test_cmp_parameters;
/*******************************************************************************
* Command line help function
*******************************************************************************/
void comparePGXimages_help_display(void) {
fprintf(stdout,"\nList of parameters for the comparePGX function \n");
fprintf(stdout,"\n");
fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline PGX image \n");
fprintf(stdout," -t \t REQUIRED \t filename to the test PGX image\n");
fprintf(stdout," -n \t REQUIRED \t number of component of the image (used to generate correct filename)\n");
fprintf(stdout," -m \t OPTIONAL \t list of MSE tolerances, separated by : (size must correspond to the number of component) of \n");
fprintf(stdout," -p \t OPTIONAL \t list of PEAK tolerances, separated by : (size must correspond to the number of component) \n");
fprintf(stdout," -s \t OPTIONAL \t 1 or 2 filename separator to take into account PGX image with different components, "
"please indicate b or t before separator to indicate respectively the separator "
"for ref/base file and for test file. \n");
fprintf(stdout," -r \t OPTIONAL \t indicate if you want to run this function as conformance test or as non regression test\n");
fprintf(stdout,"\n");
}
/*******************************************************************************
* Parse command line
*******************************************************************************/
int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param)
{
char *MSElistvalues = NULL; char *PEAKlistvalues= NULL;
char *separatorList = NULL;
int sizemembasefile, sizememtestfile;
int index, flagM=0, flagP=0;
const char optlist[] = "b:t:n:m:p:s:d";
int c;
// Init parameters
param->base_filename = NULL;
param->test_filename = NULL;
param->nbcomp = 0;
param->tabMSEvalues = NULL;
param->tabPEAKvalues = NULL;
param->nr_flag = 0;
opterr = 0;
while ((c = getopt(argc, argv, optlist)) != -1)
switch (c)
{
case 'b':
sizemembasefile = (int)strlen(optarg)+1;
param->base_filename = (char*) malloc(sizemembasefile);
param->base_filename[0] = '\0';
strncpy(param->base_filename, optarg, strlen(optarg));
param->base_filename[strlen(optarg)] = '\0';
//printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );
break;
case 't':
sizememtestfile = (int) strlen(optarg) + 1;
param->test_filename = (char*) malloc(sizememtestfile);
param->test_filename[0] = '\0';
strncpy(param->test_filename, optarg, strlen(optarg));
param->test_filename[strlen(optarg)] = '\0';
//printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);
break;
case 'n':
param->nbcomp = atoi(optarg);
break;
case 'm':
MSElistvalues = optarg;
flagM = 1;
break;
case 'p':
PEAKlistvalues = optarg;
flagP = 1;
break;
case 'd':
param->nr_flag = 1;
break;
case 's':
separatorList = optarg;
break;
case '?':
if ((optopt == 'b') || (optopt == 't') || (optopt == 'n') || (optopt == 'p') || (optopt == 'm') || (optopt
== 's'))
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
else
if (isprint(optopt)) fprintf(stderr, "Unknown option `-%c'.\n", optopt);
else fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
return 1;
default:
fprintf(stderr, "WARNING -> this option is not valid \"-%c %s\"\n", c, optarg);
break;
}
if (optind != argc)
{
for (index = optind; index < argc; index++)
fprintf(stderr,"Non-option argument %s\n", argv[index]);
return EXIT_FAILURE;
}
if (param->nbcomp == 0)
{
fprintf(stderr,"Need to indicate the number of components !\n");
return EXIT_FAILURE;
}
else
{
if ( flagM && flagP )
{
param->tabMSEvalues = parseToleranceValues( MSElistvalues, param->nbcomp);
param->tabPEAKvalues = parseToleranceValues( PEAKlistvalues, param->nbcomp);
if ( (param->tabMSEvalues == NULL) || (param->tabPEAKvalues == NULL))
{
fprintf(stderr,"MSE and PEAK values are not correct (respectively need %d values)\n",param->nbcomp);
return EXIT_FAILURE;
}
}
/*else
{
}*/
}
// Get separators after corresponding letter (b or t)
if (separatorList != NULL)
{
if( (strlen(separatorList) ==2) || (strlen(separatorList) ==4) )
{
// keep original string
int sizeseplist = (int)strlen(separatorList)+1;
char* separatorList2 = (char*)malloc( sizeseplist );
separatorList2[0] = '\0';
strncpy(separatorList2, separatorList, strlen(separatorList));
separatorList2[strlen(separatorList)] = '\0';
//printf("separatorList2 = %s [%d / %d]\n", separatorList2, strlen(separatorList2), sizeseplist);
if (strlen(separatorList) == 2) // one separator behind b or t
{
char *resultT = NULL;
resultT = strtok(separatorList2, "t");
if (strlen(resultT) == strlen(separatorList)) // didn't find t character, try to find b
{
char *resultB = NULL;
resultB = strtok(resultT, "b");
if (strlen(resultB) == 1)
{
param->separator_base[0] = separatorList[1];param->separator_base[1] = '\0';
param->separator_test[0] ='\0';
}
else // not found b
{
free(separatorList2);
return EXIT_FAILURE;
}
}
else // found t
{
param->separator_base[0] ='\0';
param->separator_test[0] = separatorList[1];param->separator_test[1] = '\0';
}
//printf("sep b = %s [%d] and sep t = %s [%d]\n",param->separator_base, strlen(param->separator_base), param->separator_test, strlen(param->separator_test) );
}
else // == 4 characters we must found t and b
{
char *resultT = NULL;
resultT = strtok(separatorList2, "t");
if (strlen(resultT) == 3) // found t in first place
{
char *resultB = NULL;
resultB = strtok(resultT, "b");
if (strlen(resultB) == 1) // found b after t
{
param->separator_test[0] = separatorList[1];param->separator_test[1] = '\0';
param->separator_base[0] = separatorList[3];param->separator_base[1] = '\0';
}
else // didn't find b after t
{
free(separatorList2);
return EXIT_FAILURE;
}
}
else // == 2, didn't find t in first place
{
char *resultB = NULL;
resultB = strtok(resultT, "b");
if (strlen(resultB) == 1) // found b in first place
{
param->separator_base[0] = separatorList[1]; param->separator_base[1] = '\0';
param->separator_test[0] = separatorList[3]; param->separator_test[1] = '\0';
}
else // didn't found b in first place => problem
{
free(separatorList2);
return EXIT_FAILURE;
}
}
}
free(separatorList2);
}
else // wrong number of argument after -s
{
return EXIT_FAILURE;
}
}
else
{
if (param->nbcomp == 1)
{
param->separator_base[0] = '\0';
param->separator_test[0] = '\0';
}
else
{
fprintf(stderr,"If number of component is > 1, we need separator\n");
return EXIT_FAILURE;
}
}
if ( (param->nr_flag) && (flagP || flagM) )
{
fprintf(stderr,"Wrong input parameters list: it is non-regression test or tolerance comparison\n");
return EXIT_FAILURE;
}
if ( (!param->nr_flag) && (!flagP || !flagM) )
{
fprintf(stderr,"Wrong input parameters list: it is non-regression test or tolerance comparison\n");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
/*******************************************************************************
* Parse MSE and PEAK input values (
* separator = ":"
*******************************************************************************/
double* parseToleranceValues( char* inArg, const int nbcomp)
{
double* outArgs= malloc(nbcomp * sizeof(double));
int it_comp = 0;
char delims[] = ":";
char *result = NULL;
result = strtok( inArg, delims );
while( (result != NULL) && (it_comp < nbcomp ))
{
outArgs[it_comp] = atof(result);
result = strtok( NULL, delims );
it_comp++;
}
if (it_comp != nbcomp)
return NULL;
else
return outArgs;
}
/*******************************************************************************
* Create filenames from a filename by used separator and nb components
* (begin to 0)
*******************************************************************************/
char* createMultiComponentsFilename(const char* inFilename, const int indexF, const char* separator)
{
char s[255];
char *outFilename, *ptr;
char token = '.';
int posToken = 0;
//printf("inFilename = %s\n", inFilename);
if ((ptr = strrchr(inFilename, token)) != NULL)
{
posToken = (int) (strlen(inFilename) - strlen(ptr));
//printf("Position of %c character inside inFilename = %d\n", token, posToken);
}
else
{
//printf("Token %c not found\n", token);
outFilename = (char*)malloc(1);
outFilename[0] = '\0';
return outFilename;
}
outFilename = (char*)malloc((posToken + 7) * sizeof(char)); //6
strncpy(outFilename, inFilename, posToken);
outFilename[posToken] = '\0';
strcat(outFilename, separator);
sprintf(s, "%i", indexF);
strcat(outFilename, s);
strcat(outFilename, ".pgx");
//printf("outfilename: %s\n", outFilename);
return outFilename;
}
/*******************************************************************************
*
*******************************************************************************/
opj_image_t* readImageFromFilePGX(char* filename, int nbFilenamePGX, char *separator)
{
int it_file;
opj_image_t* image_read = NULL;
opj_image_t* image = NULL;
opj_cparameters_t parameters;
opj_image_cmptparm_t* param_image_read;
int** data;
// If separator is empty => nb file to read is equal to one
if ( strlen(separator) == 0 )
nbFilenamePGX = 1;
/* set encoding parameters to default values */
opj_set_default_encoder_parameters(&parameters);
parameters.decod_format = PGX_DFMT;
strncpy(parameters.infile, filename, sizeof(parameters.infile)-1);
// Allocate memory
param_image_read = malloc(nbFilenamePGX * sizeof(opj_image_cmptparm_t));
data = malloc(nbFilenamePGX * sizeof(*data));
it_file = 0;
for (it_file = 0; it_file < nbFilenamePGX; it_file++)
{
// Create the right filename
char *filenameComponentPGX;
if (strlen(separator) == 0)
{
filenameComponentPGX = malloc((strlen(filename) + 1) * sizeof(*filenameComponentPGX));
strcpy(filenameComponentPGX, filename);
}
else
filenameComponentPGX = createMultiComponentsFilename(filename, it_file, separator);
// Read the pgx file corresponding to the component
image_read = pgxtoimage(filenameComponentPGX, &parameters);
if (!image_read)
{
fprintf(stderr, "Unable to load pgx file\n");
return NULL;
}
// Set the image_read parameters
param_image_read[it_file].x0 = 0;
param_image_read[it_file].y0 = 0;
param_image_read[it_file].dx = 0;
param_image_read[it_file].dy = 0;
param_image_read[it_file].h = image_read->comps->h;
param_image_read[it_file].w = image_read->comps->w;
param_image_read[it_file].bpp = image_read->comps->bpp;
param_image_read[it_file].prec = image_read->comps->prec;
param_image_read[it_file].sgnd = image_read->comps->sgnd;
// Copy data
data[it_file] = malloc(param_image_read[it_file].h * param_image_read[it_file].w * sizeof(int));
memcpy(data[it_file], image_read->comps->data, image_read->comps->h * image_read->comps->w * sizeof(int));
// Free memory
opj_image_destroy(image_read);
free(filenameComponentPGX);
}
image = opj_image_create(nbFilenamePGX, param_image_read, CLRSPC_UNSPECIFIED);
for (it_file = 0; it_file < nbFilenamePGX; it_file++)
{
// Copy data into output image and free memory
memcpy(image->comps[it_file].data, data[it_file], image->comps[it_file].h * image->comps[it_file].w * sizeof(int));
free(data[it_file]);
}
// Free memory
free(param_image_read);
free(data);
return image;
}
/*******************************************************************************
*
*******************************************************************************/
#ifdef HAVE_LIBPNG
int imageToPNG(const opj_image_t* image, const char* filename, int num_comp_select)
{
opj_image_cmptparm_t param_image_write;
opj_image_t* image_write = NULL;
param_image_write.x0 = 0;
param_image_write.y0 = 0;
param_image_write.dx = 0;
param_image_write.dy = 0;
param_image_write.h = image->comps[num_comp_select].h;
param_image_write.w = image->comps[num_comp_select].w;
param_image_write.bpp = image->comps[num_comp_select].bpp;
param_image_write.prec = image->comps[num_comp_select].prec;
param_image_write.sgnd = image->comps[num_comp_select].sgnd;
image_write = opj_image_create(1, &param_image_write, CLRSPC_GRAY);
memcpy(image_write->comps->data, image->comps[num_comp_select].data, param_image_write.h * param_image_write.w * sizeof(int));
imagetopng(image_write, filename);
opj_image_destroy(image_write);
return EXIT_SUCCESS;
}
#endif
/*******************************************************************************
* MAIN
*******************************************************************************/
int main(int argc, char **argv)
{
test_cmp_parameters inParam;
int it_comp, itpxl;
int failed = 0;
int nbFilenamePGXbase, nbFilenamePGXtest;
char *filenamePNGtest= NULL, *filenamePNGbase = NULL, *filenamePNGdiff = NULL;
int memsizebasefilename, memsizetestfilename, memsizedifffilename;
int valueDiff = 0, nbPixelDiff = 0;
double sumDiff = 0.0;
// Structures to store image parameters and data
opj_image_t *imageBase = NULL, *imageTest = NULL, *imageDiff = NULL;
opj_image_cmptparm_t* param_image_diff;
// Get parameters from command line
if( parse_cmdline_cmp(argc, argv, &inParam) == EXIT_FAILURE )
{
comparePGXimages_help_display();
if (!inParam.tabMSEvalues) free(inParam.tabMSEvalues);
if (!inParam.tabPEAKvalues) free(inParam.tabPEAKvalues);
if (!inParam.base_filename) free(inParam.base_filename);
if (!inParam.test_filename) free(inParam.test_filename);
return EXIT_FAILURE;
}
// Display Parameters
printf("******Parameters********* \n");
printf(" base_filename = %s\n"
" test_filename = %s\n"
" nb of Components = %d\n"
" Non regression test = %d\n"
" separator Base = %s\n"
" separator Test = %s\n",
inParam.base_filename, inParam.test_filename, inParam.nbcomp,
inParam.nr_flag, inParam.separator_base, inParam.separator_test);
if ( (inParam.tabMSEvalues != NULL) && (inParam.tabPEAKvalues != NULL))
{
printf(" MSE values = [");
for (it_comp = 0; it_comp < inParam.nbcomp; it_comp++)
printf(" %f ", inParam.tabMSEvalues[it_comp]);
printf("]\n");
printf(" PEAK values = [");
for (it_comp = 0; it_comp < inParam.nbcomp; it_comp++)
printf(" %f ", inParam.tabPEAKvalues[it_comp]);
printf("]\n");
printf(" Non-regression test = %d\n", inParam.nr_flag);
}
if (strlen(inParam.separator_base) == 0)
nbFilenamePGXbase = 0;
else
nbFilenamePGXbase = inParam.nbcomp;
if (strlen(inParam.separator_test) == 0)
nbFilenamePGXtest = 0;
else
nbFilenamePGXtest = inParam.nbcomp;
printf(" NbFilename to generate from base filename = %d\n", nbFilenamePGXbase);
printf(" NbFilename to generate from test filename = %d\n", nbFilenamePGXtest);
printf("************************* \n");
//----------BASELINE IMAGE--------
//
memsizebasefilename = (int)strlen(inParam.test_filename) + 1 + 5 + 2 + 4;
memsizetestfilename = (int)strlen(inParam.test_filename) + 1 + 5 + 2 + 4;
imageBase = readImageFromFilePGX( inParam.base_filename, nbFilenamePGXbase, inParam.separator_base);
if ( imageBase != NULL)
{
filenamePNGbase = (char*) malloc(memsizebasefilename);
filenamePNGbase[0] = '\0';
strncpy(filenamePNGbase, inParam.test_filename, strlen(inParam.test_filename));
filenamePNGbase[strlen(inParam.test_filename)] = '\0';
strcat(filenamePNGbase, ".base");
//printf("filenamePNGbase = %s [%d / %d octets]\n",filenamePNGbase, strlen(filenamePNGbase),memsizebasefilename );
}
else
{
if (!inParam.tabMSEvalues) free(inParam.tabMSEvalues);
if (!inParam.tabPEAKvalues) free(inParam.tabPEAKvalues);
if (!inParam.base_filename) free(inParam.base_filename);
if (!inParam.test_filename) free(inParam.test_filename);
return EXIT_FAILURE;
}
//----------TEST IMAGE--------
//
imageTest = readImageFromFilePGX(inParam.test_filename, nbFilenamePGXtest, inParam.separator_test);
if ( imageTest != NULL)
{
filenamePNGtest = (char*) malloc(memsizetestfilename);
filenamePNGtest[0] = '\0';
strncpy(filenamePNGtest, inParam.test_filename, strlen(inParam.test_filename));
filenamePNGtest[strlen(inParam.test_filename)] = '\0';
strcat(filenamePNGtest, ".test");
//printf("filenamePNGtest = %s [%d / %d octets]\n",filenamePNGtest, strlen(filenamePNGtest),memsizetestfilename );
}
else
{
if (!inParam.tabMSEvalues) free(inParam.tabMSEvalues);
if (!inParam.tabPEAKvalues) free(inParam.tabPEAKvalues);
if (!inParam.base_filename) free(inParam.base_filename);
if (!inParam.test_filename) free(inParam.test_filename);
free(filenamePNGbase);
return EXIT_FAILURE;
}
//----------DIFF IMAGE--------
//
// Allocate memory
param_image_diff = malloc( imageBase->numcomps * sizeof(opj_image_cmptparm_t));
// Comparison of header parameters
printf("Step 1 -> Header comparison\n");
for (it_comp = 0; it_comp < imageBase->numcomps; it_comp++)
{
param_image_diff[it_comp].x0 = 0;
param_image_diff[it_comp].y0 = 0;
param_image_diff[it_comp].dx = 0;
param_image_diff[it_comp].dy = 0;
if (imageBase->comps[it_comp].sgnd != imageTest->comps[it_comp].sgnd)
{
printf("ERROR: sign mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).sgnd, ((imageTest->comps)[it_comp]).sgnd);
failed = 1;
}
else
param_image_diff[it_comp].sgnd = 0 ;
if (((imageBase->comps)[it_comp]).prec != ((imageTest->comps)[it_comp]).prec)
{
printf("ERROR: prec mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).prec, ((imageTest->comps)[it_comp]).prec);
failed = 1;
}
else
param_image_diff[it_comp].prec = 8 ;
if (((imageBase->comps)[it_comp]).bpp != ((imageTest->comps)[it_comp]).bpp)
{
printf("ERROR: byte per pixel mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).bpp, ((imageTest->comps)[it_comp]).bpp);
failed = 1;
}
else
param_image_diff[it_comp].bpp = 1 ;
if (((imageBase->comps)[it_comp]).h != ((imageTest->comps)[it_comp]).h)
{
printf("ERROR: height mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).h, ((imageTest->comps)[it_comp]).h);
failed = 1;
}
else
param_image_diff[it_comp].h = imageBase->comps[it_comp].h ;
if (((imageBase->comps)[it_comp]).w != ((imageTest->comps)[it_comp]).w)
{
printf("ERROR: width mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).w, ((imageTest->comps)[it_comp]).w);
failed = 1;
}
else
param_image_diff[it_comp].w = imageBase->comps[it_comp].w ;
}
// If only one parameter is different, we stop the test
if (failed)
{
free(inParam.tabMSEvalues);
free(inParam.tabPEAKvalues);
free(inParam.base_filename);
free(inParam.test_filename);
free(filenamePNGbase);
free(filenamePNGtest);
opj_image_destroy(imageBase);
opj_image_destroy(imageTest);
free(param_image_diff);
return EXIT_FAILURE;
}
imageDiff = opj_image_create(imageBase->numcomps, param_image_diff, CLRSPC_UNSPECIFIED);
// Free memory
free(param_image_diff);
// Measurement computation
printf("Step 2 -> measurement comparison\n");
memsizedifffilename = strlen(inParam.test_filename) + 1 + 5 + 2 + 4;
filenamePNGdiff = (char*) malloc(memsizedifffilename);
filenamePNGdiff[0] = '\0';
strncpy(filenamePNGdiff, inParam.test_filename, strlen(inParam.test_filename));
filenamePNGdiff[strlen(inParam.test_filename)] = '\0';
strcat(filenamePNGdiff, ".diff");
//printf("filenamePNGdiff = %s [%d / %d octets]\n",filenamePNGdiff, strlen(filenamePNGdiff),memsizedifffilename );
// Compute pixel diff
for (it_comp = 0; it_comp < imageDiff->numcomps; it_comp++)
{
double SE=0,PEAK=0;
double MSE=0;
char *filenamePNGbase_it_comp, *filenamePNGtest_it_comp, *filenamePNGdiff_it_comp;
filenamePNGbase_it_comp = (char*) malloc(memsizebasefilename);
filenamePNGbase_it_comp[0] = '\0';
strncpy(filenamePNGbase_it_comp,filenamePNGbase,strlen(filenamePNGbase));
filenamePNGbase_it_comp[strlen(filenamePNGbase)] = '\0';
filenamePNGtest_it_comp = (char*) malloc(memsizetestfilename);
filenamePNGtest_it_comp[0] = '\0';
strncpy(filenamePNGtest_it_comp,filenamePNGtest,strlen(filenamePNGtest));
filenamePNGtest_it_comp[strlen(filenamePNGtest)] = '\0';
filenamePNGdiff_it_comp = (char*) malloc(memsizedifffilename);
filenamePNGdiff_it_comp[0] = '\0';
strncpy(filenamePNGdiff_it_comp,filenamePNGdiff,strlen(filenamePNGdiff));
filenamePNGdiff_it_comp[strlen(filenamePNGdiff)] = '\0';
for (itpxl = 0; itpxl < ((imageDiff->comps)[it_comp]).w * ((imageDiff->comps)[it_comp]).h; itpxl++)
{
if (abs( ((imageBase->comps)[it_comp]).data[itpxl] - ((imageTest->comps)[it_comp]).data[itpxl] ) > 0)
{
valueDiff = ((imageBase->comps)[it_comp]).data[itpxl] - ((imageTest->comps)[it_comp]).data[itpxl];
((imageDiff->comps)[it_comp]).data[itpxl] = abs(valueDiff);
sumDiff += (double)valueDiff;
nbPixelDiff++;
SE += (double)(valueDiff * valueDiff);
PEAK = (PEAK > abs(valueDiff)) ? PEAK : abs(valueDiff);
}
else
((imageDiff->comps)[it_comp]).data[itpxl] = 0;
}// h*w loop
MSE = SE / ( ((imageDiff->comps)[it_comp]).w * ((imageDiff->comps)[it_comp]).h );
if (!inParam.nr_flag && (inParam.tabMSEvalues != NULL) && (inParam.tabPEAKvalues != NULL))
{ // Conformance test
printf("<DartMeasurement name=\"PEAK_%d\" type=\"numeric/double\"> %f </DartMeasurement> \n", it_comp, PEAK);
printf("<DartMeasurement name=\"MSE_%d\" type=\"numeric/double\"> %f </DartMeasurement> \n", it_comp, MSE);
if ( (MSE > inParam.tabMSEvalues[it_comp]) || (PEAK > inParam.tabPEAKvalues[it_comp]) )
{
printf("ERROR: MSE (%f) or PEAK (%f) values produced by the decoded file are greater "
"than the allowable error (respectively %f and %f) \n",
MSE, PEAK, inParam.tabMSEvalues[it_comp], inParam.tabPEAKvalues[it_comp]);
failed = 1;
}
}
else // Non regression-test
{
if ( nbPixelDiff > 0)
{
char it_compc[255];
it_compc[0] = '\0';
printf("<DartMeasurement name=\"NumberOfPixelsWithDifferences_%d\" type=\"numeric/int\"> %d </DartMeasurement> \n", it_comp, nbPixelDiff);
printf("<DartMeasurement name=\"ComponentError_%d\" type=\"numeric/double\"> %f </DartMeasurement> \n", it_comp, sumDiff);
#ifdef HAVE_LIBPNG
sprintf(it_compc, "_%i", it_comp);
strcat(it_compc,".png");
strcat(filenamePNGbase_it_comp, it_compc);
//printf("filenamePNGbase_it = %s [%d / %d octets]\n",filenamePNGbase_it_comp, strlen(filenamePNGbase_it_comp),memsizebasefilename );
strcat(filenamePNGtest_it_comp, it_compc);
//printf("filenamePNGtest_it = %s [%d / %d octets]\n",filenamePNGtest_it_comp, strlen(filenamePNGtest_it_comp),memsizetestfilename );
strcat(filenamePNGdiff_it_comp, it_compc);
//printf("filenamePNGdiff_it = %s [%d / %d octets]\n",filenamePNGdiff_it_comp, strlen(filenamePNGdiff_it_comp),memsizedifffilename );
if ( imageToPNG(imageBase, filenamePNGbase_it_comp, it_comp) == EXIT_SUCCESS )
{
printf("<DartMeasurementFile name=\"BaselineImage_%d\" type=\"image/png\"> %s </DartMeasurementFile> \n", it_comp, filenamePNGbase_it_comp);
}
if ( imageToPNG(imageTest, filenamePNGtest_it_comp, it_comp) == EXIT_SUCCESS )
{
printf("<DartMeasurementFile name=\"TestImage_%d\" type=\"image/png\"> %s </DartMeasurementFile> \n", it_comp, filenamePNGtest_it_comp);
}
if ( imageToPNG(imageDiff, filenamePNGdiff_it_comp, it_comp) == EXIT_SUCCESS )
{
printf("<DartMeasurementFile name=\"DiffferenceImage_%d\" type=\"image/png\"> %s </DartMeasurementFile> \n", it_comp, filenamePNGdiff_it_comp);
}
#endif
failed = 1;
}
}
free(filenamePNGbase_it_comp);
free(filenamePNGtest_it_comp);
free(filenamePNGdiff_it_comp);
} // it_comp loop
//-----------------------------
// Free memory
opj_image_destroy(imageBase);
opj_image_destroy(imageTest);
opj_image_destroy(imageDiff);
free(filenamePNGbase);
free(filenamePNGtest);
free(filenamePNGdiff);
free(inParam.tabMSEvalues);
free(inParam.tabPEAKvalues);
free(inParam.base_filename);
free(inParam.test_filename);
if (failed)
return EXIT_FAILURE;
else
{
printf("---- TEST SUCCEED ----\n");
return EXIT_SUCCESS;
}
}

257
tests/compare_dump_files.c Normal file
View File

@ -0,0 +1,257 @@
/*
* Copyright (c) 2011, Mickael Savinaud, Communications & Systemes <mickael.savinaud@c-s.fr>
* 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.
*/
/*
* compare_dump_files.c
*
* Created on: 25 juil. 2011
* Author: mickael
* BASELINE MUST BE GENERATED BY UNIX PLATFORM REGARDING TO THE CRLF PROBLEM
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "getopt.h"
typedef struct test_cmp_parameters
{
/** */
char* base_filename;
/** */
char* test_filename;
} test_cmp_parameters;
/*******************************************************************************
* Command line help function
*******************************************************************************/
void compare_dump_files_help_display(void) {
fprintf(stdout,"\nList of parameters for the compare_dump_files function \n");
fprintf(stdout,"\n");
fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline dump file \n");
fprintf(stdout," -t \t REQUIRED \t filename to the test dump file image\n");
fprintf(stdout,"\n");
}
/*******************************************************************************
* Parse command line
*******************************************************************************/
int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param)
{
int sizemembasefile, sizememtestfile;
int index;
const char optlist[] = "b:t:";
int c;
// Init parameters
param->base_filename = NULL;
param->test_filename = NULL;
opterr = 0;
while ((c = getopt(argc, argv, optlist)) != -1)
switch (c)
{
case 'b':
sizemembasefile = (int)strlen(optarg)+1;
param->base_filename = (char*) malloc(sizemembasefile);
param->base_filename[0] = '\0';
strncpy(param->base_filename, optarg, strlen(optarg));
param->base_filename[strlen(optarg)] = '\0';
//printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );
break;
case 't':
sizememtestfile = (int) strlen(optarg) + 1;
param->test_filename = (char*) malloc(sizememtestfile);
param->test_filename[0] = '\0';
strncpy(param->test_filename, optarg, strlen(optarg));
param->test_filename[strlen(optarg)] = '\0';
//printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);
break;
case '?':
if ( (optopt == 'b') || (optopt == 't') )
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
else
if (isprint(optopt)) fprintf(stderr, "Unknown option `-%c'.\n", optopt);
else fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
return 1;
default:
fprintf(stderr, "WARNING -> this option is not valid \"-%c %s\"\n", c, optarg);
break;
}
if (optind != argc)
{
for (index = optind; index < argc; index++)
fprintf(stderr,"Non-option argument %s\n", argv[index]);
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
/*******************************************************************************
* MAIN
*******************************************************************************/
int main(int argc, char **argv)
{
test_cmp_parameters inParam;
FILE *fbase=NULL, *ftest=NULL;
int chbase, chtest;
int same = 1;
unsigned long l=1, pos;
if( parse_cmdline_cmp(argc, argv, &inParam) == EXIT_FAILURE )
{
compare_dump_files_help_display();
if (!inParam.base_filename) free(inParam.base_filename);
if (!inParam.test_filename) free(inParam.test_filename);
return EXIT_FAILURE;
}
// Display Parameters
printf("******Parameters********* \n");
printf(" base_filename = %s\n"
" test_filename = %s\n",
inParam.base_filename, inParam.test_filename);
printf("************************* \n");
/* open base file */
printf("Try to open: %s for reading ... ", inParam.base_filename);
if((fbase = fopen(inParam.base_filename, "rb"))==NULL)
{
printf("Failed.\n");
free(inParam.base_filename);
free(inParam.test_filename);
return EXIT_FAILURE;
}
printf("Ok.\n");
/* open test file */
printf("Try to open: %s for reading ... ", inParam.test_filename);
if((ftest = fopen(inParam.test_filename, "rb"))==NULL)
{
printf("Failed.\n");
fclose(fbase);
free(inParam.base_filename);
free(inParam.test_filename);
return EXIT_FAILURE;
}
printf("Ok.\n");
pos=ftell(fbase);
while(!feof(fbase))
{
chbase = fgetc(fbase);
if(ferror(fbase))
{
printf("Error reading base file.\n");
return EXIT_FAILURE;
}
chtest = fgetc(ftest);
if(ferror(ftest))
{
printf("Error reading test file.\n");
return EXIT_FAILURE;
}
// CRLF problem (Baseline must be always generated by unix platform)
if (chbase == '\n' && chtest == '\r')
if (fgetc(ftest) == '\n')
chtest = '\n';
if(chbase != chtest)
{
size_t nbytes = 2048;
int CRLF_shift=1;
char *strbase, *strtest, *strbase_d, *strtest_d;
char *return_value_fgets;
printf("Files differ at line %lu:\n", l);
fseek(fbase,pos,SEEK_SET);
// Take into account CRLF characters when we write \n into
// dump file when we used WIN platform
#ifdef _WIN32
CRLF_shift = 2;
fseek(ftest,pos + l - 1,SEEK_SET);
#else
fseek(ftest,pos,SEEK_SET);
#endif
strbase = (char *) malloc(nbytes + 1);
strtest = (char *) malloc(nbytes + 1);
return_value_fgets = fgets(strbase, nbytes, fbase);
if (!strcmp(return_value_fgets,strbase))
fprintf(stderr,"\nWARNING: fgets return a value different that the first argument");
free(return_value_fgets);
return_value_fgets = fgets(strtest, nbytes, ftest);
if (!strcmp(return_value_fgets,strtest))
fprintf(stderr,"\nWARNING: fgets return a value different that the first argument");
free(return_value_fgets);
strbase_d = (char *) malloc(strlen(strbase)+1);
strtest_d = (char *) malloc(strlen(strtest)+1);
strncpy(strbase_d, strbase, strlen(strbase)-1);
strncpy(strtest_d, strtest, strlen(strtest)-CRLF_shift);
strbase_d[strlen(strbase)-1] = '\0';
strtest_d[strlen(strtest)-CRLF_shift] = '\0';
printf("<%s> vs. <%s>\n", strbase_d, strtest_d);
free(strbase);free(strtest);
free(strbase_d);free(strtest_d);
same = 0;
break;
}
else
{
if (chbase == '\n')
{
l++;
pos = ftell(fbase);
}
}
}
//Close File
fclose(fbase);
fclose(ftest);
// Free memory
free(inParam.base_filename);
free(inParam.test_filename);
if(same)
{
printf("\n***** TEST SUCCEED: Files are the same. *****\n");
return EXIT_SUCCESS;
}
else return EXIT_FAILURE;
}

View File

@ -0,0 +1,484 @@
# CONFORMANCE TESTS AND NON-REGRESSION ON THIS DATASET
FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Temporary)
SET(TEMP ${CMAKE_CURRENT_BINARY_DIR}/Temporary)
SET(BASELINE_CONF ${OPJ_DATA_ROOT}/baseline/conformance)
SET(BASELINE_NR ${OPJ_DATA_ROOT}/baseline/nonregression)
SET(INPUT_CONF ${OPJ_DATA_ROOT}/input/conformance)
# List of components by file (normaly p0_13.j2k have 257 components but for this
#set of test we consider only 4)
SET( CP0_nbC_list "not_used;1;1;1;3;4;4;3;3;1;3;1;1;4;3;1;1")
SET( CP1_nbC_list "not_used;1;3;4;1;3;3;2")
SET(COMMENTCODEVAR FALSE)
#--------------------------------------------------------------------------
# Tests about class 0 profile 0
# try to decode
# compare to ref file provided by the Executable Test Suite
# non regression comparison
# Parameters and tolerances given by Table C.1
SET( C0P0_ResFactor_list "not_used;0;0;0;3;3;3;0;5;2;0;0;0;0;2;0;0")
SET( C0P0_PEAK_list "not_used;0;0;0;33;54;109;10;7;4;10;0;0;0;0;0;0")
SET( C0P0_MSE_list "not_used;0;0;0;55.8;68;743;0.34;6.72;1.47;2.84;0;0;0;0;0;0")
FOREACH(numFileC0P0 RANGE 1 16)
# Build filenames
IF(${numFileC0P0} LESS 10)
SET( filenameInput p0_0${numFileC0P0}.j2k )
SET( filenameRef c0p0_0${numFileC0P0}.pgx )
ELSE(${numFileC0P0} LESS 10)
SET( filenameInput p0_${numFileC0P0}.j2k )
SET( filenameRef c0p0_${numFileC0P0}.pgx )
ENDIF(${numFileC0P0} LESS 10)
# Get corresponding tests parameters
list(GET C0P0_ResFactor_list ${numFileC0P0} ResFactor)
list(GET CP0_nbC_list ${numFileC0P0} nbComponents)
list(GET C0P0_PEAK_list ${numFileC0P0} PEAK_limit)
list(GET C0P0_MSE_list ${numFileC0P0} MSE_limit)
# Manage cases which need to try different resolution reduction
IF (numFileC0P0 EQUAL 3 OR numFileC0P0 EQUAL 15)
get_filename_component(filenameRefSub ${filenameRef} NAME_WE)
#r = 0
ADD_TEST(ETS-C0P0-${filenameInput}-r0-decode
${EXECUTABLE_OUTPUT_PATH}/j2k_to_image
-i ${INPUT_CONF}/${filenameInput}
-o ${TEMP}/c0${filenameInput}-r0.pgx
-r 0
)
ADD_TEST(ETS-C0P0-${filenameInput}-r0-compare2ref
${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
-b ${BASELINE_CONF}/${filenameRefSub}r0.pgx
-t ${TEMP}/c0${filenameInput}-r0.pgx
-n ${nbComponents}
-p ${PEAK_limit}
-m ${MSE_limit}
-s t_
)
SET_TESTS_PROPERTIES(ETS-C0P0-${filenameInput}-r0-compare2ref
PROPERTIES DEPENDS
ETS-C0P0-${filenameInput}-r0-decode)
ADD_TEST(NR-C0P0-${filenameInput}-r0-compare2base
${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
-b ${BASELINE_NR}/opj_${filenameRefSub}-r0.pgx
-t ${TEMP}/c0${filenameInput}-r0.pgx
-n ${nbComponents}
-d
-s b_t_
)
SET_TESTS_PROPERTIES(NR-C0P0-${filenameInput}-r0-compare2base
PROPERTIES DEPENDS
ETS-C0P0-${filenameInput}-r0-decode)
#r = 1
ADD_TEST(ETS-C0P0-${filenameInput}-r1-decode
${EXECUTABLE_OUTPUT_PATH}/j2k_to_image
-i ${INPUT_CONF}/${filenameInput}
-o ${TEMP}/c0${filenameInput}-r1.pgx
-r 1
)
ADD_TEST(ETS-C0P0-${filenameInput}-r1-compare2ref
${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
-b ${BASELINE_CONF}/${filenameRefSub}r1.pgx
-t ${TEMP}/c0${filenameInput}-r1.pgx
-n ${nbComponents}
-p ${PEAK_limit}
-m ${MSE_limit}
-s t_
)
SET_TESTS_PROPERTIES(ETS-C0P0-${filenameInput}-r1-compare2ref
PROPERTIES DEPENDS
ETS-C0P0-${filenameInput}-r1-decode)
ADD_TEST(NR-C0P0-${filenameInput}-r1-compare2base
${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
-b ${BASELINE_NR}/opj_${filenameRefSub}-r1.pgx
-t ${TEMP}/c0${filenameInput}-r1.pgx
-n ${nbComponents}
-d
-s b_t_
)
SET_TESTS_PROPERTIES(NR-C0P0-${filenameInput}-r1-compare2base
PROPERTIES DEPENDS
ETS-C0P0-${filenameInput}-r1-decode)
ELSE(numFileC0P0 EQUAL 3 OR numFileC0P0 EQUAL 15)
ADD_TEST(ETS-C0P0-${filenameInput}-decode
${EXECUTABLE_OUTPUT_PATH}/j2k_to_image
-i ${INPUT_CONF}/${filenameInput}
-o ${TEMP}/c0${filenameInput}.pgx
-r ${ResFactor}
)
ADD_TEST(ETS-C0P0-${filenameInput}-compare2ref
${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
-b ${BASELINE_CONF}/${filenameRef}
-t ${TEMP}/c0${filenameInput}.pgx
-n ${nbComponents}
-p ${PEAK_limit}
-m ${MSE_limit}
-s t_
)
SET_TESTS_PROPERTIES(ETS-C0P0-${filenameInput}-compare2ref
PROPERTIES DEPENDS
ETS-C0P0-${filenameInput}-decode)
ADD_TEST(NR-C0P0-${filenameInput}-compare2base
${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
-b ${BASELINE_NR}/opj_${filenameRef}
-t ${TEMP}/c0${filenameInput}.pgx
-n ${nbComponents}
-d
-s b_t_
)
SET_TESTS_PROPERTIES(NR-C0P0-${filenameInput}-compare2base
PROPERTIES DEPENDS
ETS-C0P0-${filenameInput}-decode)
ENDIF(numFileC0P0 EQUAL 3 OR numFileC0P0 EQUAL 15)
ENDFOREACH(numFileC0P0)
#--------------------------------------------------------------------------
# Tests about class 0 profile 1
# try to decode
# compare to ref file
# non regression comparison
# Parameters and tolerances given by Table C.4
SET( C0P1_ResFactor_list "not_used;0;3;3;0;4;1;0")
SET( C0P1_PEAK_list "not_used;0;35;28;2;128;128;0")
SET( C0P1_MSE_list "not_used;0;74;18.8;0.550;16384;16384;0")
FOREACH(numFileC0P1 RANGE 1 7)
# Build filenames
SET( filenameInput p1_0${numFileC0P1}.j2k )
SET( filenameRef c0p1_0${numFileC0P1}.pgx )
# Get corresponding tests parameters
list(GET C0P1_ResFactor_list ${numFileC0P1} ResFactor)
list(GET CP1_nbC_list ${numFileC0P1} nbComponents)
list(GET C0P1_PEAK_list ${numFileC0P1} PEAK_limit)
list(GET C0P1_MSE_list ${numFileC0P1} MSE_limit)
# Manage cases which need to try different resolution reduction
IF (numFileC0P1 EQUAL 4 )
get_filename_component(filenameRefSub ${filenameRef} NAME_WE)
#r = 0
ADD_TEST(ETS-C0P1-${filenameInput}-r0-decode
${EXECUTABLE_OUTPUT_PATH}/j2k_to_image
-i ${INPUT_CONF}/${filenameInput}
-o ${TEMP}/c0${filenameInput}-r0.pgx
-r 0
)
ADD_TEST(ETS-C0P1-${filenameInput}-r0-compare2ref
${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
-b ${BASELINE_CONF}/${filenameRefSub}r0.pgx
-t ${TEMP}/c0${filenameInput}-r0.pgx
-n ${nbComponents}
-p ${PEAK_limit}
-m ${MSE_limit}
-s t_
)
SET_TESTS_PROPERTIES(ETS-C0P1-${filenameInput}-r0-compare2ref
PROPERTIES DEPENDS
ETS-C0P1-${filenameInput}-r0-decode)
ADD_TEST(NR-C0P1-${filenameInput}-r0-compare2base
${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
-b ${BASELINE_NR}/opj_${filenameRefSub}-r0.pgx
-t ${TEMP}/c0${filenameInput}-r0.pgx
-n ${nbComponents}
-d
-s b_t_
)
SET_TESTS_PROPERTIES(NR-C0P1-${filenameInput}-r0-compare2base
PROPERTIES DEPENDS
ETS-C0P1-${filenameInput}-r0-decode)
#r = 3
ADD_TEST(ETS-C0P1-${filenameInput}-r3-decode
${EXECUTABLE_OUTPUT_PATH}/j2k_to_image
-i ${INPUT_CONF}/${filenameInput}
-o ${TEMP}/c0${filenameInput}-r3.pgx
-r 3
)
ADD_TEST(ETS-C0P1-${filenameInput}-r3-compare2ref
${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
-b ${BASELINE_CONF}/${filenameRefSub}r3.pgx
-t ${TEMP}/c0${filenameInput}-r3.pgx
-n ${nbComponents}
-p ${PEAK_limit}
-m ${MSE_limit}
-s t_
)
SET_TESTS_PROPERTIES(ETS-C0P1-${filenameInput}-r3-compare2ref
PROPERTIES DEPENDS
ETS-C0P1-${filenameInput}-r3-decode)
ADD_TEST(NR-C0P1-${filenameInput}-r3-compare2base
${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
-b ${BASELINE_NR}/opj_${filenameRefSub}-r3.pgx
-t ${TEMP}/c0${filenameInput}-r3.pgx
-n ${nbComponents}
-d
-s b_t_
)
SET_TESTS_PROPERTIES(NR-C0P1-${filenameInput}-r3-compare2base
PROPERTIES DEPENDS
ETS-C0P1-${filenameInput}-r3-decode)
ELSE(numFileC0P1 EQUAL 4)
ADD_TEST(ETS-C0P1-${filenameInput}-decode
${EXECUTABLE_OUTPUT_PATH}/j2k_to_image
-i ${INPUT_CONF}/${filenameInput}
-o ${TEMP}/c0${filenameInput}.pgx
-r ${ResFactor}
)
ADD_TEST(ETS-C0P1-${filenameInput}-compare2ref
${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
-b ${BASELINE_CONF}/${filenameRef}
-t ${TEMP}/c0${filenameInput}.pgx
-n ${nbComponents}
-p ${PEAK_limit}
-m ${MSE_limit}
-s t_
)
SET_TESTS_PROPERTIES(ETS-C0P1-${filenameInput}-compare2ref
PROPERTIES DEPENDS
ETS-C0P1-${filenameInput}-decode)
ADD_TEST(NR-C0P1-${filenameInput}-compare2base
${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
-b ${BASELINE_NR}/opj_${filenameRef}
-t ${TEMP}/c0${filenameInput}.pgx
-n ${nbComponents}
-d
-s b_t_
)
SET_TESTS_PROPERTIES(NR-C0P1-${filenameInput}-compare2base
PROPERTIES DEPENDS
ETS-C0P1-${filenameInput}-decode)
ENDIF(numFileC0P1 EQUAL 4)
ENDFOREACH(numFileC0P1)
#--------------------------------------------------------------------------
# Tests about class 1 profile 0
# try to decode
# compare to ref file
# non regression comparison
# Parameters and tolerances given by Table C.6
SET( C1P0_ResFactor_list "not_used;0;0;0;0;0;0;0;1;0;0;0;0;0;0;0;0")
SET( C1P0_PEAK_list "not_used;0;0;0;5:4:6;2:2:2:0;635:403:378:0;0:0:0;0:0:0;0;0:0:0;0;0;0:0:0:0;0:0:0;0;0")
SET( C1P0_MSE_list "not_used;0;0;0;0.776:0.626:1.070;0.302:0.307:0.269:0;11287:6124:3968:0;0:0:0;0:0:0;0;0:0:0;0;0;0:0:0:0;0:0:0;0;0")
FOREACH(numFileC1P0 RANGE 1 16)
# Build filenames
IF(${numFileC1P0} LESS 10)
SET( filenameInput p0_0${numFileC1P0}.j2k )
SET( filenameRef c1p0_0${numFileC1P0}.pgx )
ELSE(${numFileC1P0} LESS 10)
SET( filenameInput p0_${numFileC1P0}.j2k )
SET( filenameRef c1p0_${numFileC1P0}.pgx )
ENDIF(${numFileC1P0} LESS 10)
# Get corresponding tests parameters
list(GET CP0_nbC_list ${numFileC1P0} nbComponents)
list(GET C1P0_ResFactor_list ${numFileC1P0} ResFactor)
list(GET C1P0_PEAK_list ${numFileC1P0} PEAK_limit)
list(GET C1P0_MSE_list ${numFileC1P0} MSE_limit)
ADD_TEST(ETS-C1P0-${filenameInput}-decode
${EXECUTABLE_OUTPUT_PATH}/j2k_to_image
-i ${INPUT_CONF}/${filenameInput}
-o ${TEMP}/c1${filenameInput}.pgx
-r ${ResFactor}
)
ADD_TEST(ETS-C1P0-${filenameInput}-compare2ref
${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
-b ${BASELINE_CONF}/${filenameRef}
-t ${TEMP}/c1${filenameInput}.pgx
-n ${nbComponents}
-p ${PEAK_limit}
-m ${MSE_limit}
-s b_t_
)
SET_TESTS_PROPERTIES(ETS-C1P0-${filenameInput}-compare2ref
PROPERTIES DEPENDS
ETS-C1P0-${filenameInput}-decode)
ADD_TEST(NR-C1P0-${filenameInput}-compare2base
${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
-b ${BASELINE_NR}/opj_${filenameRef}
-t ${TEMP}/c1${filenameInput}.pgx
-n ${nbComponents}
-d
-s b_t_
)
SET_TESTS_PROPERTIES(NR-C1P0-${filenameInput}-compare2base
PROPERTIES DEPENDS
ETS-C1P0-${filenameInput}-decode)
ENDFOREACH(numFileC1P0)
#--------------------------------------------------------------------------
# Tests about class 1 profile 1
# try to decode
# compare to ref file
# non regression comparison
# Parameters and tolerances given by Table C.7
SET( C1P1_PEAK_list "not_used;0;5:4:6;2:2:1:0;624;40:40:40;2:2:2;0:0")
SET( C1P1_MSE_list "not_used;0;0.765:0.616:1.051;0.3:0.210:0.200:0;3080;8.458:9.816:10.154;0.6:0.6:0.6;0:0")
FOREACH(numFileC1P1 RANGE 1 7)
# Build filenames
SET( filenameInput p1_0${numFileC1P1}.j2k )
SET( filenameRef c1p1_0${numFileC1P1}.pgx )
# Get corresponding tests parameters
list(GET CP1_nbC_list ${numFileC1P1} nbComponents)
list(GET C1P1_PEAK_list ${numFileC1P1} PEAK_limit)
list(GET C1P1_MSE_list ${numFileC1P1} MSE_limit)
ADD_TEST(ETS-C1P1-${filenameInput}-decode
${EXECUTABLE_OUTPUT_PATH}/j2k_to_image
-i ${INPUT_CONF}/${filenameInput}
-o ${TEMP}/c1${filenameInput}.pgx
-r 0
)
ADD_TEST(ETS-C1P1-${filenameInput}-compare2ref
${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
-b ${BASELINE_CONF}/${filenameRef}
-t ${TEMP}/c1${filenameInput}.pgx
-n ${nbComponents}
-p ${PEAK_limit}
-m ${MSE_limit}
-s b_t_
)
SET_TESTS_PROPERTIES(ETS-C1P1-${filenameInput}-compare2ref
PROPERTIES DEPENDS
ETS-C1P1-${filenameInput}-decode)
ADD_TEST(NR-C1P1-${filenameInput}-compare2base
${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
-b ${BASELINE_NR}/opj_${filenameRef}
-t ${TEMP}/c1${filenameInput}.pgx
-n ${nbComponents}
-d
-s b_t_
)
SET_TESTS_PROPERTIES(NR-C1P1-${filenameInput}-compare2base
PROPERTIES DEPENDS
ETS-C1P1-${filenameInput}-decode)
ENDFOREACH(numFileC1P1)
#--------------------------------------------------------------------------#
#--------------------------------------------------------------------------#
#--------------------------------------------------------------------------#
#--------------------------------------------------------------------------
# Tests about dump of profile 0 file
# try to dump image and codestream informations into a file
# non regression comparison this file to the baseline
FOREACH(numFileP0 RANGE 1 16)
# Build filenames
IF(${numFileP0} LESS 10)
SET( filenameInput p0_0${numFileP0}.j2k )
ELSE(${numFileP0} LESS 10)
SET( filenameInput p0_${numFileP0}.j2k )
ENDIF(${numFileP0} LESS 10)
get_filename_component(filenameRefSub ${filenameInput} NAME_WE)
ADD_TEST(NR-${filenameInput}-dump
${EXECUTABLE_OUTPUT_PATH}/j2k_dump
-i ${INPUT_CONF}/${filenameInput}
-o ${TEMP}/${filenameInput}.txt
)
ADD_TEST(NR-${filenameInput}-compare_dump2base
${EXECUTABLE_OUTPUT_PATH}/compare_dump_files
-b ${BASELINE_NR}/opj_${filenameRefSub}.txt
-t ${TEMP}/${filenameInput}.txt
)
SET_TESTS_PROPERTIES(NR-${filenameInput}-compare_dump2base
PROPERTIES DEPENDS
NR-${filenameInput}-dump)
ENDFOREACH(numFileP0 RANGE 1 16)
#--------------------------------------------------------------------------
# Tests about dump of profile 1 file
# try to dump image and codestream informations into a file
# non regression comparison this file to the baseline
FOREACH(numFileP1 RANGE 1 7)
# Build filenames
SET( filenameInput p1_0${numFileP1}.j2k )
get_filename_component(filenameInputSub ${filenameInput} NAME_WE)
ADD_TEST(NR-${filenameInput}-dump
${EXECUTABLE_OUTPUT_PATH}/j2k_dump
-i ${INPUT_CONF}/${filenameInput}
-o ${TEMP}/${filenameInput}.txt
)
ADD_TEST(NR-${filenameInput}-compare_dump2base
${EXECUTABLE_OUTPUT_PATH}/compare_dump_files
-b ${BASELINE_NR}/opj_${filenameInputSub}.txt
-t ${TEMP}/${filenameInput}.txt
)
SET_TESTS_PROPERTIES(NR-${filenameInput}-compare_dump2base
PROPERTIES DEPENDS
NR-${filenameInput}-dump)
ENDFOREACH(numFileP1 RANGE 1 7)

View File

@ -0,0 +1,54 @@
# NON-REGRESSION TESTS ON THIS DATASET LOCATED ${OPJ_DATA_ROOT}/input/nonregression
FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Temporary)
SET(TEMP ${CMAKE_CURRENT_BINARY_DIR}/Temporary)
SET(BASELINE_NR ${OPJ_DATA_ROOT}/baseline/nonregression)
SET(INPUT_NR ${OPJ_DATA_ROOT}/input/nonregression)
FILE(GLOB_RECURSE OPJ_DATA_NR_LIST
"${INPUT_NR}/*.j2k"
"${INPUT_NR}/*.j2c"
"${INPUT_NR}/*.jp2"
)
FOREACH(filepath ${OPJ_DATA_NR_LIST})
GET_FILENAME_COMPONENT(filename ${filepath} NAME)
GET_FILENAME_COMPONENT(filenameSub ${filename} NAME_WE)
ADD_TEST(NR-${filename}-dump
${EXECUTABLE_OUTPUT_PATH}/j2k_dump
-i ${filepath}
-o ${TEMP}/${filename}.txt
)
ADD_TEST(NR-${filename}-compare_dump2base
${EXECUTABLE_OUTPUT_PATH}/compare_dump_files
-b ${BASELINE_NR}/opj_${filenameSub}.txt
-t ${TEMP}/${filename}.txt
)
SET_TESTS_PROPERTIES(NR-${filename}-compare_dump2base
PROPERTIES DEPENDS
NR-${filename}-dump)
ADD_TEST(NR-${filename}-decode
${EXECUTABLE_OUTPUT_PATH}/j2k_to_image
-i ${filepath}
-o ${TEMP}/${filename}.pgx
)
# ADD_TEST(NR-${filename}-compare2base
# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages
# -b ${BASELINE_NR}/opj_${filenameRef}
# -t ${TEMP}/${filename}.pgx
# -n ${nbComponents}
# -d
# -s b_t_
# )
#
# SET_TESTS_PROPERTIES(NR-${filename}-compare2base
# PROPERTIES DEPENDS
# NR-${filename}-decode)
ENDFOREACH(filepath)

View File

@ -1,20 +1,146 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.6) CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
IF(BUILD_THIRDPARTY)
# IF(UNIX OR CYGWIN)
IF(NOT ZLIB_FOUND) SET(CMAKE_INCLUDE_PATH /usr/include /usr/local/include /opt/include
ADD_SUBDIRECTORY(libz) /opt/local/include /usr/include/libpng /usr/include/libpng14
ENDIF(NOT ZLIB_FOUND) /usr/include/libpng12 /usr/local/include/libpng
# /usr/local/include/libpng14 /usr/local/include/libpng12
IF(NOT PNG_FOUND) /opt/include/libpng /opt/include/libpng14 /opt/include/libpng12
ADD_SUBDIRECTORY(libpng) /opt/local/include/libpng /opt/local/include/libpng14)
ENDIF(NOT PNG_FOUND) SET(CMAKE_LIBRARY_PATH /usr/lib /usr/local/lib /opt/lib /opt/local/lib)
# ENDIF(UNIX OR CYGWIN)
IF(NOT LCMS2_FOUND)
ADD_SUBDIRECTORY(liblcms2) #------------
ENDIF(NOT LCMS2_FOUND) # Try to find lib Z
# FIND_PACKAGE(ZLIB)
IF(NOT TIFF_FOUND)
ADD_SUBDIRECTORY(libtiff) IF(ZLIB_FOUND)
ENDIF(NOT TIFF_FOUND)
# SET(Z_LIBNAME ${ZLIB_LIBRARIES} PARENT_SCOPE)
ENDIF(BUILD_THIRDPARTY) SET(Z_INCLUDE_DIRNAME ${ZLIB_INCLUDE_DIRS} PARENT_SCOPE)
message("Your system seems to have a Z lib available, we will used it to generate PNG lib")
ELSE (ZLIB_FOUND) # not found
IF(BUILD_THIRDPARTY)
# Try to build it
message("We will build Z lib from thirdparty")
ADD_SUBDIRECTORY(libz)
SET(Z_LIBNAME z PARENT_SCOPE)
SET(Z_INCLUDE_DIRNAME ${OPENJPEG_SOURCE_DIR}/thirdparty/include PARENT_SCOPE)
SET(ZLIB_FOUND 1)
ELSE (BUILD_THIRDPARTY)
message("Z lib not found, activate BUILD_THIRDPARTY if you want build it (necessary to build libPNG)")
ENDIF(BUILD_THIRDPARTY)
ENDIF(ZLIB_FOUND)
#------------
# Try to find lib PNG (which depends to zlib)
IF (ZLIB_FOUND)
FIND_PACKAGE(PNG)
IF(PNG_FOUND)
message("Your system seems to have a PNG lib available, we will used it")
SET(HAVE_PNG_H 1 PARENT_SCOPE)
SET(HAVE_LIBPNG 1 PARENT_SCOPE)
SET(PNG_LIBNAME ${PNG_LIBRARIES} PARENT_SCOPE)
SET(PNG_INCLUDE_DIRNAME ${PNG_PNG_INCLUDE_DIR} PARENT_SCOPE)
ELSE(PNG_FOUND) # not found
IF(BUILD_THIRDPARTY)
# Try to build it
message("We will build PNG lib from thirdparty")
ADD_SUBDIRECTORY(libpng)
SET(HAVE_PNG_H 1 PARENT_SCOPE)
SET(HAVE_LIBPNG 1 PARENT_SCOPE)
SET(PNG_LIBNAME png PARENT_SCOPE)
SET(PNG_INCLUDE_DIRNAME ${OPENJPEG_SOURCE_DIR}/thirdparty/libpng PARENT_SCOPE)
ELSE (BUILD_THIRDPARTY)
SET(HAVE_PNG_H 0 PARENT_SCOPE)
SET(HAVE_LIBPNG 0 PARENT_SCOPE)
message("PNG lib not found, activate BUILD_THIRDPARTY if you want build it")
ENDIF(BUILD_THIRDPARTY)
ENDIF(PNG_FOUND)
ENDIF (ZLIB_FOUND)
#------------
# Try to find lib TIFF
FIND_PACKAGE(TIFF)
IF(TIFF_FOUND)
message("Your system seems to have a TIFF lib available, we will used it")
SET(HAVE_TIFF_H 1 PARENT_SCOPE)
SET(HAVE_LIBTIFF 1 PARENT_SCOPE)
SET(TIFF_LIBNAME ${TIFF_LIBRARIES} PARENT_SCOPE)
SET(TIFF_INCLUDE_DIRNAME ${TIFF_INCLUDE_DIR} PARENT_SCOPE)
ELSE (TIFF_FOUND) # not found
IF(BUILD_THIRDPARTY)
# Try to build it
message("We will build TIFF lib from thirdparty")
ADD_SUBDIRECTORY(libtiff)
SET(TIFF_LIBNAME tiff PARENT_SCOPE)
SET(TIFF_INCLUDE_DIRNAME ${OPENJPEG_SOURCE_DIR}/thirdparty/libtiff PARENT_SCOPE)
SET(HAVE_TIFF_H 1 PARENT_SCOPE)
SET(HAVE_LIBTIFF 1 PARENT_SCOPE)
ELSE (BUILD_THIRDPARTY)
SET(HAVE_TIFF_H 0 PARENT_SCOPE)
SET(HAVE_LIBTIFF 0 PARENT_SCOPE)
message("TIFF lib not found, activate BUILD_THIRDPARTY if you want build it")
ENDIF(BUILD_THIRDPARTY)
ENDIF(TIFF_FOUND)
#------------
# Try to find lib LCMS2 (or by default LCMS)
FIND_PACKAGE(LCMS2)
IF(LCMS2_FOUND)
message("Your system seems to have a LCMS2 lib available, we will used it")
SET(HAVE_LCMS2_H 1 PARENT_SCOPE)
SET(HAVE_LIBLCMS2 1 PARENT_SCOPE)
SET(LCMS_LIBNAME ${LCMS2_LIBRARIES} PARENT_SCOPE)
SET(LCMS_INCLUDE_DIRNAME ${LCMS2_INCLUDE_DIRS} PARENT_SCOPE)
ELSE (LCMS2_FOUND) # not found lcms2
# try to find LCMS
FIND_PACKAGE(LCMS)
IF(LCMS_FOUND)
message("Your system seems to have a LCMS lib available, we will used it")
SET(HAVE_LCMS_H 1 PARENT_SCOPE)
SET(HAVE_LIBLCMS 1 PARENT_SCOPE)
SET(LCMS_LIBNAME ${LCMS_LIBRARIES} PARENT_SCOPE)
SET(LCMS_INCLUDE_DIRNAME ${LCMS_INCLUDE_DIRS} PARENT_SCOPE)
ELSE (LCMS_FOUND) # not found lcms
SET(HAVE_LCMS_H 0 PARENT_SCOPE)
SET(HAVE_LIBLCMS 0 PARENT_SCOPE)
IF( BUILD_THIRDPARTY)
# Try to build lcms2
message("We will build LCMS2 lib from thirdparty")
ADD_SUBDIRECTORY(liblcms2)
SET(LCMS_LIBNAME lcms2 PARENT_SCOPE)
SET(LCMS_INCLUDE_DIRNAME ${OPENJPEG_SOURCE_DIR}/thirdparty/liblcms2/include PARENT_SCOPE) #
SET(HAVE_LCMS2_H 1 PARENT_SCOPE)
SET(HAVE_LIBLCMS2 1 PARENT_SCOPE)
ELSE (BUILD_THIRDPARTY)
SET(HAVE_LCMS2_H 0 PARENT_SCOPE)
SET(HAVE_LIBLCMS2 0 PARENT_SCOPE)
message("LCMS2 or LCMS lib not found, activate BUILD_THIRDPARTY if you want build it")
ENDIF(BUILD_THIRDPARTY)
ENDIF (LCMS_FOUND)
ENDIF(LCMS2_FOUND)

View File

@ -39,7 +39,6 @@ SET(TARGET_FILES
tif_predict.h tif_predict.h
tif_print.c tif_print.c
tif_read.c tif_read.c
tif_stream.cxx
tif_strip.c tif_strip.c
tif_swab.c tif_swab.c
tif_thunder.c tif_thunder.c