! : changed
+ : added
+September 1st, 2011
+! [antonin] renamed getopt.{c/h} to opj_getopt.{c/h} and forced the use of these files rather than the system ones. This fixed issue 78. Credit to Winfried.
+
+August 31, 2011
+* [mickael] fixed a segfault with fgets return value for some cases inside test function compare_dump_file()
++ [mickael] enhance the encoding test suite and remove unsued CONFIGURE_FILE into a CMakeList
+
+August 30, 2011
++ [mickael] added first version of the encoding tests suite
+
August 16, 2011
+ [antonin] added NEWS, AUTHORS and THANKS files. Cosmetic changes in autotools files.
- [antonin] removed obsolete testing directory and *.nix files
#
#----------------------------------------------------------------------
+SET(CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE 1000000)
SET (CTEST_CUSTOM_MAXIMUM_NUMBER_OF_ERRORS 50)
SET (CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS 2000)
# Exclude files from the Testing directories
".*/tests/.*"
- ".*/Testing/.*"
+
+ # Exclude files from the ThirdParty Utilities directories
+ ".*/thirdparty/.*"
)
SET(CTEST_CUSTOM_WARNING_EXCEPTION
+++ /dev/null
-# Check if getopt is present:
-INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
-SET(DONT_HAVE_GETOPT 1)
-IF(UNIX) #I am pretty sure only *nix sys have this anyway
- CHECK_INCLUDE_FILE("getopt.h" CMAKE_HAVE_GETOPT_H)
- # Seems like we need the contrary:
- IF(CMAKE_HAVE_GETOPT_H)
- SET(DONT_HAVE_GETOPT 0)
- ENDIF(CMAKE_HAVE_GETOPT_H)
-ENDIF(UNIX)
-
-IF(DONT_HAVE_GETOPT)
- ADD_DEFINITIONS(-DDONT_HAVE_GETOPT)
-ENDIF(DONT_HAVE_GETOPT)
-
# Test for some required system information.
INCLUDE (${CMAKE_ROOT}/Modules/CMakeBackwardCompatibilityC.cmake)
-#-----------------------------------------------------------------------------
-# Test for getopt being available in this system
-INCLUDE (${OPENJPEG_SOURCE_DIR}/CMake/CheckHaveGetopt.cmake )
-
#-----------------------------------------------------------------------------
# Setup file for setting custom ctest vars
CONFIGURE_FILE(
ENABLE_TESTING()
INCLUDE(CTest)
- # Add repository where to find tests
- ADD_SUBDIRECTORY(tests)
-
# 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}/../data)
-
- SET (REF_DECODER_BIN_PATH "NOT-FOUND" CACHE PATH "Single directory where find the reference encoder binaries to enable encoding test suite.")
+
+ # For encoding tests we need the path to the ref decoder exe/lib (kakadu)
+ SET (REF_DECODER_BIN_PATH "NOTFOUND" CACHE PATH "Single directory where find the reference decoder binaries to enable encoding test suite.")
MARK_AS_ADVANCED(REF_DECODER_BIN_PATH)
-
+
+ # Add repository where to find tests
+ ADD_SUBDIRECTORY(tests)
+
ELSE(BUILD_CODEC)
message(FATAL_ERROR "You need build codec to run the tests")
ENDIF(BUILD_CODEC)
SET(common_SRCS
../codec/convert.c
../codec/index.c
+ ../common/opj_getopt.c
)
-# If not getopt was found then add it to the lib:
-IF(DONT_HAVE_GETOPT)
- SET(common_SRCS
- ${common_SRCS}
- ../common/getopt.c
- )
-ENDIF(DONT_HAVE_GETOPT)
-
# Headers file are located here:
INCLUDE_DIRECTORIES(
#include <math.h>\r
\r
#include "openjpeg.h"\r
-#include "getopt.h"\r
+#include "opj_getopt.h"\r
#include "convert.h"\r
#include "index.h"\r
#include "dirent.h"\r
int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,\r
img_fol_t *img_fol, char *indexfilename) {\r
int i, j,totlen;\r
- option_t long_option[]={\r
+ opj_option_t long_option[]={\r
{"cinema2K",REQ_ARG, NULL ,'w'},\r
{"cinema4K",NO_ARG, NULL ,'y'},\r
{"ImgDir",REQ_ARG, NULL ,'z'},\r
reset_options_reading();\r
\r
while (1) {\r
- int c = getopt_long(argc, argv, optlist,long_option,totlen);\r
+ int c = opj_getopt_long(argc, argv, optlist,long_option,totlen);\r
if (c == -1)\r
break;\r
switch (c) {\r
\r
case 'o': /* output file */\r
{\r
- char *outfile = optarg;\r
+ char *outfile = opj_optarg;\r
parameters->cod_format = get_file_format(outfile);\r
switch(parameters->cod_format) {\r
case J2K_CFMT:\r
case 'O': /* output format */\r
{\r
char outformat[50];\r
- char *of = optarg;\r
+ char *of = opj_optarg;\r
sprintf(outformat,".%s",of);\r
img_fol->set_out_format = 1;\r
parameters->cod_format = get_file_format(outformat);\r
switch(parameters->cod_format) {\r
case J2K_CFMT:\r
case JP2_CFMT:\r
- img_fol->out_format = optarg;\r
+ img_fol->out_format = opj_optarg;\r
break;\r
default:\r
fprintf(stderr, "Unknown output format image [only j2k, j2c, jp2]!! \n");\r
\r
case 'r': /* rates rates/distorsion */\r
{\r
- char *s = optarg;\r
+ char *s = opj_optarg;\r
while (sscanf(s, "%f", ¶meters->tcp_rates[parameters->tcp_numlayers]) == 1) {\r
parameters->tcp_numlayers++;\r
while (*s && *s != ',') {\r
\r
case 'q': /* add fixed_quality */\r
{\r
- char *s = optarg;\r
+ char *s = opj_optarg;\r
while (sscanf(s, "%f", ¶meters->tcp_distoratio[parameters->tcp_numlayers]) == 1) {\r
parameters->tcp_numlayers++;\r
while (*s && *s != ',') {\r
int *row = NULL, *col = NULL;\r
int numlayers = 0, numresolution = 0, matrix_width = 0;\r
\r
- char *s = optarg;\r
+ char *s = opj_optarg;\r
sscanf(s, "%d", &numlayers);\r
s++;\r
if (numlayers > 9)\r
\r
case 't': /* tiles */\r
{\r
- sscanf(optarg, "%d,%d", ¶meters->cp_tdx, ¶meters->cp_tdy);\r
+ sscanf(opj_optarg, "%d,%d", ¶meters->cp_tdx, ¶meters->cp_tdy);\r
parameters->tile_size_on = true;\r
}\r
break;\r
\r
case 'n': /* resolution */\r
{\r
- sscanf(optarg, "%d", ¶meters->numresolution);\r
+ sscanf(opj_optarg, "%d", ¶meters->numresolution);\r
}\r
break;\r
\r
char sep;\r
int res_spec = 0;\r
\r
- char *s = optarg;\r
+ char *s = opj_optarg;\r
do {\r
sep = 0;\r
sscanf(s, "[%d,%d]%c", ¶meters->prcw_init[res_spec],\r
case 'b': /* code-block dimension */\r
{\r
int cblockw_init = 0, cblockh_init = 0;\r
- sscanf(optarg, "%d,%d", &cblockw_init, &cblockh_init);\r
+ sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init);\r
if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024\r
|| cblockw_init < 4 || cblockh_init > 1024 || cblockh_init < 4) {\r
fprintf(stderr,\r
\r
case 'x': /* creation of index file */\r
{\r
- char *index = optarg;\r
+ char *index = opj_optarg;\r
strncpy(indexfilename, index, OPJ_PATH_LEN);\r
}\r
break;\r
{\r
char progression[4];\r
\r
- strncpy(progression, optarg, 4);\r
+ strncpy(progression, opj_optarg, 4);\r
parameters->prog_order = give_progression(progression);\r
if (parameters->prog_order == -1) {\r
fprintf(stderr, "Unrecognized progression order "\r
\r
case 's': /* subsampling factor */\r
{\r
- if (sscanf(optarg, "%d,%d", ¶meters->subsampling_dx,\r
+ if (sscanf(opj_optarg, "%d,%d", ¶meters->subsampling_dx,\r
¶meters->subsampling_dy) != 2) {\r
fprintf(stderr, "'-s' sub-sampling argument error ! [-s dx,dy]\n");\r
return 1;\r
\r
case 'd': /* coordonnate of the reference grid */\r
{\r
- if (sscanf(optarg, "%d,%d", ¶meters->image_offset_x0,\r
+ if (sscanf(opj_optarg, "%d,%d", ¶meters->image_offset_x0,\r
¶meters->image_offset_y0) != 2) {\r
fprintf(stderr, "-d 'coordonnate of the reference grid' argument "\r
"error !! [-d x0,y0]\n");\r
int numpocs = 0; /* number of progression order change (POC) default 0 */\r
opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */\r
\r
- char *s = optarg;\r
+ char *s = opj_optarg;\r
POC = parameters->POC;\r
\r
while (sscanf(s, "T%d=%d,%d,%d,%d,%d,%4s", &POC[numpocs].tile,\r
case 'M': /* Mode switch pas tous au point !! */\r
{\r
int value = 0;\r
- if (sscanf(optarg, "%d", &value) == 1) {\r
+ if (sscanf(opj_optarg, "%d", &value) == 1) {\r
for (i = 0; i <= 5; i++) {\r
int cache = value & (1 << i);\r
if (cache)\r
\r
case 'R': /* ROI */\r
{\r
- if (sscanf(optarg, "c=%d,U=%d", ¶meters->roi_compno,\r
+ if (sscanf(opj_optarg, "c=%d,U=%d", ¶meters->roi_compno,\r
¶meters->roi_shift) != 2) {\r
fprintf(stderr, "ROI error !! [-ROI c='compno',U='shift']\n");\r
return 1;\r
\r
case 'T': /* Tile offset */\r
{\r
- if (sscanf(optarg, "%d,%d", ¶meters->cp_tx0, ¶meters->cp_ty0) != 2) {\r
+ if (sscanf(opj_optarg, "%d,%d", ¶meters->cp_tx0, ¶meters->cp_ty0) != 2) {\r
fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]");\r
return 1;\r
}\r
\r
case 'C': /* add a comment */\r
{\r
- parameters->cp_comment = (char*)malloc(strlen(optarg) + 1);\r
+ parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1);\r
if(parameters->cp_comment) {\r
- strcpy(parameters->cp_comment, optarg);\r
+ strcpy(parameters->cp_comment, opj_optarg);\r
}\r
}\r
break;\r
\r
case 'v': /* Tile part generation*/\r
{\r
- parameters->tp_flag = optarg[0];\r
+ parameters->tp_flag = opj_optarg[0];\r
parameters->tp_on = 1;\r
}\r
break; \r
\r
case 'z': /* Image Directory path */\r
{\r
- img_fol->imgdirpath = (char*)malloc(strlen(optarg) + 1);\r
- strcpy(img_fol->imgdirpath,optarg);\r
+ img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);\r
+ strcpy(img_fol->imgdirpath,opj_optarg);\r
img_fol->set_imgdir=1;\r
}\r
break;\r
case 'w': /* Digital Cinema 2K profile compliance*/\r
{\r
int fps=0;\r
- sscanf(optarg,"%d",&fps);\r
+ sscanf(opj_optarg,"%d",&fps);\r
if(fps == 24){\r
parameters->cp_cinema = CINEMA2K_24;\r
}else if(fps == 48 ){\r
/* search for different protection methods */\r
\r
/* break the option in comma points and parse the result */\r
- token = strtok(optarg, ",");\r
+ token = strtok(opj_optarg, ",");\r
while(token != NULL) {\r
\r
/* search header error protection method */\r
#include <math.h>\r
\r
#include "openjpeg.h"\r
-#include "getopt.h"\r
+#include "opj_getopt.h"\r
#include "convert.h"\r
#include "dirent.h"\r
#include "org_openJpeg_OpenJPEGJavaDecoder.h"\r
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol) {\r
/* parse the command line */\r
int totlen;\r
- option_t long_option[]={\r
+ opj_option_t long_option[]={\r
{"ImgDir",REQ_ARG, NULL ,'y'},\r
{"OutFor",REQ_ARG, NULL ,'O'},\r
};\r
reset_options_reading();\r
\r
while (1) {\r
- int c = getopt_long(argc, argv,optlist,long_option,totlen);\r
+ int c = opj_getopt_long(argc, argv,optlist,long_option,totlen);\r
if (c == -1)\r
break;\r
switch (c) {\r
case 'i': /* input file */\r
{\r
- char *infile = optarg;\r
+ char *infile = opj_optarg;\r
parameters->decod_format = get_file_format(infile);\r
switch(parameters->decod_format) {\r
case J2K_CFMT:\r
\r
case 'o': /* output file */\r
{\r
- char *outfile = optarg;\r
+ char *outfile = opj_optarg;\r
parameters->cod_format = get_file_format(outfile);\r
switch(parameters->cod_format) {\r
case PGX_DFMT:\r
case 'O': /* output format */\r
{\r
char outformat[50];\r
- char *of = optarg;\r
+ char *of = opj_optarg;\r
sprintf(outformat,".%s",of);\r
img_fol->set_out_format = 1;\r
parameters->cod_format = get_file_format(outformat);\r
\r
case 'r': /* reduce option */\r
{\r
- sscanf(optarg, "%d", ¶meters->cp_reduce);\r
+ sscanf(opj_optarg, "%d", ¶meters->cp_reduce);\r
}\r
break;\r
\r
\r
case 'l': /* layering option */\r
{\r
- sscanf(optarg, "%d", ¶meters->cp_layer);\r
+ sscanf(opj_optarg, "%d", ¶meters->cp_layer);\r
}\r
break;\r
\r
\r
case 'y': /* Image Directory path */\r
{\r
- img_fol->imgdirpath = (char*)malloc(strlen(optarg) + 1);\r
- strcpy(img_fol->imgdirpath,optarg);\r
+ img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);\r
+ strcpy(img_fol->imgdirpath,opj_optarg);\r
img_fol->set_imgdir=1;\r
}\r
break;\r
{\r
char *token = NULL;\r
\r
- token = strtok(optarg, ",");\r
+ token = strtok(opj_optarg, ",");\r
while(token != NULL) {\r
\r
/* search expected number of components */\r
/* ----------------------------------------------------- */\r
\r
default:\r
- fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, optarg);\r
+ fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, opj_optarg);\r
break;\r
}\r
}\r
all: j2k_to_image image_to_j2k
j2k_to_image: j2k_to_image.c ../libopenjpeg.a
- gcc $(CFLAGS) ../common/getopt.c convert.c j2k_to_image.c -o j2k_to_image -L.. -lopenjpeg -I ../libopenjpeg/ -lm -ltiff
+ gcc $(CFLAGS) ../common/opj_getopt.c convert.c j2k_to_image.c -o j2k_to_image -L.. -lopenjpeg -I ../libopenjpeg/ -lm -ltiff
image_to_j2k: image_to_j2k.c ../libopenjpeg.a
- gcc $(CFLAGS) ../common/getopt.c convert.c image_to_j2k.c -o image_to_j2k -L.. -lopenjpeg -I ../libopenjpeg/ -lm -ltiff
+ gcc $(CFLAGS) ../common/opj_getopt.c convert.c image_to_j2k.c -o image_to_j2k -L.. -lopenjpeg -I ../libopenjpeg/ -lm -ltiff
clean:
rm -f j2k_to_image image_to_j2k
common/color.c \
common/color.h \
common/format_defs.h \
-common/getopt.c \
-common/getopt.h
+common/opj_getopt.c \
+common/opj_getopt.h
convert.c
index.c
${OPENJPEG_SOURCE_DIR}/applications/common/color.c
-)
-
-# If not getopt was found then add it to the lib:
-IF(DONT_HAVE_GETOPT)
- SET(common_SRCS
- ${common_SRCS}
- ${OPENJPEG_SOURCE_DIR}/applications/common/getopt.c
+ ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c
)
-ENDIF(DONT_HAVE_GETOPT)
# Headers file are located here:
INCLUDE_DIRECTORIES(
j2k_to_image_LDADD = $(top_builddir)/libopenjpeg/libopenjpeg.la @LCMS1_LIBS@ @LCMS2_LIBS@ @TIFF_LIBS@ @PNG_LIBS@ -lm
j2k_to_image_SOURCES = \
../common/color.c \
-../common/getopt.c \
+../common/opj_getopt.c \
convert.c \
index.c \
j2k_to_image.c \
image_to_j2k_CFLAGS =
image_to_j2k_LDADD = $(top_builddir)/libopenjpeg/libopenjpeg.la @TIFF_LIBS@ @PNG_LIBS@ -lm
image_to_j2k_SOURCES = \
-../common/getopt.c \
+../common/opj_getopt.c \
convert.c \
index.c \
image_to_j2k.c \
j2k_dump_CFLAGS =
j2k_dump_LDADD = $(top_builddir)/libopenjpeg/libopenjpeg.la -lm
j2k_dump_SOURCES = \
-../common/getopt.c \
+../common/opj_getopt.c \
index.c \
j2k_dump.c \
-../common/getopt.h \
+../common/opj_getopt.h \
index.h
JPWL_j2k_to_image_CPPFLAGS = \
JPWL_j2k_to_image_LDADD = $(top_builddir)/libopenjpeg/jpwl/libopenjpeg_JPWL.la @LCMS1_LIBS@ @LCMS2_LIBS@ @TIFF_LIBS@ @PNG_LIBS@
JPWL_j2k_to_image_SOURCES = \
../common/color.c \
-../common/getopt.c \
+../common/opj_getopt.c \
index.c \
convert.c \
j2k_to_image.c
JPWL_image_to_j2k_LDADD = $(top_builddir)/libopenjpeg/jpwl/libopenjpeg_JPWL.la @TIFF_LIBS@ @PNG_LIBS@
JPWL_image_to_j2k_SOURCES = \
-../common/getopt.c \
+../common/opj_getopt.c \
index.c \
convert.c \
image_to_j2k.c
<<-- <<-- <<-- <<-- */
+#ifdef INFORMATION_ONLY
// TGA header definition.
-#pragma pack(push,1) // Pack structure byte aligned
-typedef struct tga_header
+struct tga_header
{
unsigned char id_length; /* Image id field length */
unsigned char colour_map_type; /* Colour map type */
unsigned short image_height; /* Image height */
unsigned char pixel_depth; /* Pixel depth */
unsigned char image_desc; /* Image descriptor */
-} tga_header;
-#pragma pack(pop) // Return to normal structure packing alignment.
+};
+#endif /* INFORMATION_ONLY */
+
+static unsigned short get_ushort(unsigned short val) {
+
+#ifdef ORDER_BIGENDIAN
+ return( ((val & 0xff) << 8) + (val >> 8) );
+#else
+ return( val );
+#endif
+
+}
+
+#define TGA_HEADER_SIZE 18
int tga_readheader(FILE *fp, unsigned int *bits_per_pixel,
unsigned int *width, unsigned int *height, int *flip_image)
{
int palette_size;
- tga_header tga ;
+ unsigned char *tga ;
+ unsigned char id_len, cmap_type, image_type;
+ unsigned char pixel_depth, image_desc;
+ unsigned short cmap_index, cmap_len, cmap_entry_size;
+ unsigned short x_origin, y_origin, image_w, image_h;
if (!bits_per_pixel || !width || !height || !flip_image)
return 0;
-
- // Read TGA header
- if ( fread((unsigned char*)&tga, sizeof(tga_header), 1, fp) != 1 )
+ tga = (unsigned char*)malloc(18);
+
+ if ( fread(tga, TGA_HEADER_SIZE, 1, fp) != 1 )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return 0 ;
}
+ id_len = (unsigned char)tga[0];
+ cmap_type = (unsigned char)tga[1];
+ image_type = (unsigned char)tga[2];
+ cmap_index = get_ushort(*(unsigned short*)(&tga[3]));
+ cmap_len = get_ushort(*(unsigned short*)(&tga[5]));
+ cmap_entry_size = (unsigned char)tga[7];
- *bits_per_pixel = tga.pixel_depth;
-
- *width = tga.image_width;
- *height = tga.image_height ;
+
+ x_origin = get_ushort(*(unsigned short*)(&tga[8]));
+ y_origin = get_ushort(*(unsigned short*)(&tga[10]));
+ image_w = get_ushort(*(unsigned short*)(&tga[12]));
+ image_h = get_ushort(*(unsigned short*)(&tga[14]));
+ pixel_depth = (unsigned char)tga[16];
+ image_desc = (unsigned char)tga[17];
+
+ free(tga);
+
+ *bits_per_pixel = (unsigned int)pixel_depth;
+ *width = (unsigned int)image_w;
+ *height = (unsigned int)image_h;
// Ignore tga identifier, if present ...
- if (tga.id_length)
+ if (id_len)
{
- unsigned char *id = (unsigned char *) malloc(tga.id_length);
- if ( !fread(id, tga.id_length, 1, fp) )
+ unsigned char *id = (unsigned char *) malloc(id_len);
+ if ( !fread(id, id_len, 1, fp) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
free(id);
// Test for compressed formats ... not yet supported ...
// Note :- 9 - RLE encoded palettized.
// 10 - RLE encoded RGB.
- if (tga.image_type > 8)
+ if (image_type > 8)
{
fprintf(stderr, "Sorry, compressed tga files are not currently supported.\n");
return 0 ;
}
- *flip_image = !(tga.image_desc & 32);
+ *flip_image = !(image_desc & 32);
// Palettized formats are not yet supported, skip over the palette, if present ...
- palette_size = tga.colour_map_length * (tga.colour_map_entry_size/8);
+ palette_size = cmap_len * (cmap_entry_size/8);
if (palette_size>0)
{
int tga_writeheader(FILE *fp, int bits_per_pixel, int width, int height,
opj_bool flip_image)
{
- tga_header tga;
+ unsigned short image_w, image_h, us0;
+ unsigned char uc0, image_type;
+ unsigned char pixel_depth, image_desc;
if (!bits_per_pixel || !width || !height)
return 0;
- memset(&tga, 0, sizeof(tga_header));
+ pixel_depth = 0;
if ( bits_per_pixel < 256 )
- tga.pixel_depth = (unsigned char)bits_per_pixel;
+ pixel_depth = (unsigned char)bits_per_pixel;
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_desc = 8; // 8 bits per component.
+ uc0 = 0;
- if (flip_image)
- tga.image_desc |= 32;
+ if(fwrite(&uc0, 1, 1, fp) != 1) goto fails; // id_length
+ if(fwrite(&uc0, 1, 1, fp) != 1) goto fails; // colour_map_type
+
+ image_type = 2; // Uncompressed.
+ if(fwrite(&image_type, 1, 1, fp) != 1) goto fails;
+
+ us0 = 0;
+ if(fwrite(&us0, 2, 1, fp) != 1) goto fails; // colour_map_index
+ if(fwrite(&us0, 2, 1, fp) != 1) goto fails; // colour_map_length
+ if(fwrite(&uc0, 1, 1, fp) != 1) goto fails; // colour_map_entry_size
+
+ if(fwrite(&us0, 2, 1, fp) != 1) goto fails; // x_origin
+ if(fwrite(&us0, 2, 1, fp) != 1) goto fails; // y_origin
+
+ image_w = (unsigned short)width;
+ image_h = (unsigned short) height;
+
+ if(fwrite(&image_w, 2, 1, fp) != 1) goto fails;
+ if(fwrite(&image_h, 2, 1, fp) != 1) goto fails;
- // Write TGA header
- fwrite((unsigned char*)&tga, sizeof(tga_header), 1, fp);
+ if(fwrite(&pixel_depth, 1, 1, fp) != 1) goto fails;
+
+ image_desc = 8; // 8 bits per component.
+
+ if (flip_image)
+ image_desc |= 32;
+ if(fwrite(&image_desc, 1, 1, fp) != 1) goto fails;
return 1;
+
+fails:
+ fputs("\nwrite_tgaheader: write ERROR\n", stderr);
+ return 0;
}
opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) {
#include "opj_config.h"
#include "openjpeg.h"
-#include "getopt.h"
+#include "opj_getopt.h"
#include "convert.h"
#include "index.h"
int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename) {
int i, j, totlen, c;
- option_t long_option[]={
+ opj_option_t long_option[]={
{"cinema2K",REQ_ARG, NULL ,'w'},
{"cinema4K",NO_ARG, NULL ,'y'},
{"ImgDir",REQ_ARG, NULL ,'z'},
raw_cp->rawWidth = 0;
do{
- c = getopt_long(argc, argv, optlist,long_option,totlen);
+ c = opj_getopt_long(argc, argv, optlist,long_option,totlen);
if (c == -1)
break;
switch (c) {
case 'i': /* input file */
{
- char *infile = optarg;
+ char *infile = opj_optarg;
parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) {
case PGX_DFMT:
case 'o': /* output file */
{
- char *outfile = optarg;
+ char *outfile = opj_optarg;
parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) {
case J2K_CFMT:
case 'O': /* output format */
{
char outformat[50];
- char *of = optarg;
+ char *of = opj_optarg;
sprintf(outformat,".%s",of);
img_fol->set_out_format = 1;
parameters->cod_format = get_file_format(outformat);
switch(parameters->cod_format) {
case J2K_CFMT:
case JP2_CFMT:
- img_fol->out_format = optarg;
+ img_fol->out_format = opj_optarg;
break;
default:
fprintf(stderr, "Unknown output format image [only j2k, j2c, jp2]!! \n");
case 'r': /* rates rates/distorsion */
{
- char *s = optarg;
+ char *s = opj_optarg;
parameters->tcp_numlayers = 0;
while (sscanf(s, "%f", ¶meters->tcp_rates[parameters->tcp_numlayers]) == 1) {
parameters->tcp_numlayers++;
case 'F': /* Raw image format parameters */
{
char signo;
- char *s = optarg;
+ char *s = opj_optarg;
if (sscanf(s, "%d,%d,%d,%d,%c", &raw_cp->rawWidth, &raw_cp->rawHeight, &raw_cp->rawComp, &raw_cp->rawBitDepth, &signo) == 5) {
if (signo == 's') {
raw_cp->rawSigned = OPJ_TRUE;
case 'q': /* add fixed_quality */
{
- char *s = optarg;
+ char *s = opj_optarg;
while (sscanf(s, "%f", ¶meters->tcp_distoratio[parameters->tcp_numlayers]) == 1) {
parameters->tcp_numlayers++;
while (*s && *s != ',') {
int *row = NULL, *col = NULL;
int numlayers = 0, numresolution = 0, matrix_width = 0;
- char *s = optarg;
+ char *s = opj_optarg;
sscanf(s, "%d", &numlayers);
s++;
if (numlayers > 9)
case 't': /* tiles */
{
- sscanf(optarg, "%d,%d", ¶meters->cp_tdx, ¶meters->cp_tdy);
+ sscanf(opj_optarg, "%d,%d", ¶meters->cp_tdx, ¶meters->cp_tdy);
parameters->tile_size_on = OPJ_TRUE;
}
break;
case 'n': /* resolution */
{
- sscanf(optarg, "%d", ¶meters->numresolution);
+ sscanf(opj_optarg, "%d", ¶meters->numresolution);
}
break;
char sep;
int res_spec = 0;
- char *s = optarg;
+ char *s = opj_optarg;
do {
sep = 0;
sscanf(s, "[%d,%d]%c", ¶meters->prcw_init[res_spec],
case 'b': /* code-block dimension */
{
int cblockw_init = 0, cblockh_init = 0;
- sscanf(optarg, "%d,%d", &cblockw_init, &cblockh_init);
+ sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init);
if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024
|| cblockw_init < 4 || cblockh_init > 1024 || cblockh_init < 4) {
fprintf(stderr,
case 'x': /* creation of index file */
{
- char *index = optarg;
+ char *index = opj_optarg;
strncpy(indexfilename, index, OPJ_PATH_LEN);
}
break;
{
char progression[4];
- strncpy(progression, optarg, 4);
+ strncpy(progression, opj_optarg, 4);
parameters->prog_order = give_progression(progression);
if (parameters->prog_order == -1) {
fprintf(stderr, "Unrecognized progression order "
case 's': /* subsampling factor */
{
- if (sscanf(optarg, "%d,%d", ¶meters->subsampling_dx,
+ if (sscanf(opj_optarg, "%d,%d", ¶meters->subsampling_dx,
¶meters->subsampling_dy) != 2) {
fprintf(stderr, "'-s' sub-sampling argument error ! [-s dx,dy]\n");
return 1;
case 'd': /* coordonnate of the reference grid */
{
- if (sscanf(optarg, "%d,%d", ¶meters->image_offset_x0,
+ if (sscanf(opj_optarg, "%d,%d", ¶meters->image_offset_x0,
¶meters->image_offset_y0) != 2) {
fprintf(stderr, "-d 'coordonnate of the reference grid' argument "
"error !! [-d x0,y0]\n");
int numpocs = 0; /* number of progression order change (POC) default 0 */
opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */
- char *s = optarg;
+ char *s = opj_optarg;
POC = parameters->POC;
while (sscanf(s, "T%d=%d,%d,%d,%d,%d,%4s", &POC[numpocs].tile,
case 'M': /* Mode switch pas tous au point !! */
{
int value = 0;
- if (sscanf(optarg, "%d", &value) == 1) {
+ if (sscanf(opj_optarg, "%d", &value) == 1) {
for (i = 0; i <= 5; i++) {
int cache = value & (1 << i);
if (cache)
case 'R': /* ROI */
{
- if (sscanf(optarg, "c=%d,U=%d", ¶meters->roi_compno,
+ if (sscanf(opj_optarg, "c=%d,U=%d", ¶meters->roi_compno,
¶meters->roi_shift) != 2) {
fprintf(stderr, "ROI error !! [-ROI c='compno',U='shift']\n");
return 1;
case 'T': /* Tile offset */
{
- if (sscanf(optarg, "%d,%d", ¶meters->cp_tx0, ¶meters->cp_ty0) != 2) {
+ if (sscanf(opj_optarg, "%d,%d", ¶meters->cp_tx0, ¶meters->cp_ty0) != 2) {
fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]");
return 1;
}
case 'C': /* add a comment */
{
- parameters->cp_comment = (char*)malloc(strlen(optarg) + 1);
+ parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1);
if(parameters->cp_comment) {
- strcpy(parameters->cp_comment, optarg);
+ strcpy(parameters->cp_comment, opj_optarg);
}
}
break;
case 'v': /* Tile part generation*/
{
- parameters->tp_flag = optarg[0];
+ parameters->tp_flag = opj_optarg[0];
parameters->tp_on = 1;
}
break;
case 'z': /* Image Directory path */
{
- img_fol->imgdirpath = (char*)malloc(strlen(optarg) + 1);
- strcpy(img_fol->imgdirpath,optarg);
+ img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
+ strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1;
}
break;
case 'w': /* Digital Cinema 2K profile compliance*/
{
int fps=0;
- sscanf(optarg,"%d",&fps);
+ sscanf(opj_optarg,"%d",&fps);
if(fps == 24){
parameters->cp_cinema = CINEMA2K_24;
}else if(fps == 48 ){
/* search for different protection methods */
/* break the option in comma points and parse the result */
- token = strtok(optarg, ",");
+ token = strtok(opj_optarg, ",");
while(token != NULL) {
/* search header error protection method */
#include "openjpeg.h"
#include "j2k.h"
#include "jp2.h"
-#include "getopt.h"
+#include "opj_getopt.h"
#include "convert.h"
#include "index.h"
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol, char *indexfilename) {
/* parse the command line */
int totlen, c;
- option_t long_option[]={
+ opj_option_t long_option[]={
{"ImgDir",REQ_ARG, NULL ,'y'},
};
const char optlist[] = "i:o:h";
totlen=sizeof(long_option);
img_fol->set_out_format = 0;
do {
- c = getopt_long(argc, argv,optlist,long_option,totlen);
+ c = opj_getopt_long(argc, argv,optlist,long_option,totlen);
if (c == -1)
break;
switch (c) {
case 'i': /* input file */
{
- char *infile = optarg;
+ char *infile = opj_optarg;
parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) {
case J2K_CFMT:
case 'o': /* output file */
{
- char *outfile = optarg;
+ char *outfile = opj_optarg;
strncpy(parameters->outfile, outfile, sizeof(parameters->outfile)-1);
}
break;
case 'y': /* Image Directory path */
{
- img_fol->imgdirpath = (char*)malloc(strlen(optarg) + 1);
- strcpy(img_fol->imgdirpath,optarg);
+ img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
+ strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1;
}
break;
/* ----------------------------------------------------- */
default:
- 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, opj_optarg);
break;
}
}while(c != -1);
#include "opj_config.h"
#include "openjpeg.h"
-#include "getopt.h"
+#include "opj_getopt.h"
#include "convert.h"
#include "index.h"
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol, char *indexfilename) {
/* parse the command line */
int totlen, c;
- option_t long_option[]={
+ opj_option_t long_option[]={
{"ImgDir",REQ_ARG, NULL ,'y'},
{"OutFor",REQ_ARG, NULL ,'O'},
};
totlen=sizeof(long_option);
img_fol->set_out_format = 0;
do {
- c = getopt_long(argc, argv,optlist,long_option,totlen);
+ c = opj_getopt_long(argc, argv,optlist,long_option,totlen);
if (c == -1)
break;
switch (c) {
case 'i': /* input file */
{
- char *infile = optarg;
+ char *infile = opj_optarg;
parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) {
case J2K_CFMT:
case 'o': /* output file */
{
- char *outfile = optarg;
+ char *outfile = opj_optarg;
parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) {
case PGX_DFMT:
case 'O': /* output format */
{
char outformat[50];
- char *of = optarg;
+ char *of = opj_optarg;
sprintf(outformat,".%s",of);
img_fol->set_out_format = 1;
parameters->cod_format = get_file_format(outformat);
case 'r': /* reduce option */
{
- sscanf(optarg, "%d", ¶meters->cp_reduce);
+ sscanf(opj_optarg, "%d", ¶meters->cp_reduce);
}
break;
case 'l': /* layering option */
{
- sscanf(optarg, "%d", ¶meters->cp_layer);
+ sscanf(opj_optarg, "%d", ¶meters->cp_layer);
}
break;
case 'y': /* Image Directory path */
{
- img_fol->imgdirpath = (char*)malloc(strlen(optarg) + 1);
- strcpy(img_fol->imgdirpath,optarg);
+ img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
+ strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1;
}
break;
/* ----------------------------------------------------- */
case 'x': /* Creation of index file */
{
- char *index = optarg;
+ char *index = opj_optarg;
strncpy(indexfilename, index, OPJ_PATH_LEN);
}
break;
{
char *token = NULL;
- token = strtok(optarg, ",");
+ token = strtok(opj_optarg, ",");
while(token != NULL) {
/* search expected number of components */
/* ----------------------------------------------------- */
default:
- 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, opj_optarg);
break;
}
}while(c != -1);
# error "not implemented"\r
# elif defined(__sgi) /* Silicon Graphics */\r
# define HAVE_DIRENT_H\r
-# elif defined(sun) || defined(_sun) /* Sun Solaris */\r
+# elif defined(sun) || defined(__sun) /* Sun Solaris */\r
# define HAVE_DIRENT_H\r
# elif defined(__FreeBSD__) /* FreeBSD */\r
# define HAVE_DIRENT_H\r
+++ /dev/null
-/* last review : october 29th, 2002 */
-
-#ifndef _GETOPT_H_
-#define _GETOPT_H_
-
-typedef struct option
-{
- const char *name;
- int has_arg;
- int *flag;
- int val;
-}option_t;
-
-#define NO_ARG 0
-#define REQ_ARG 1
-#define OPT_ARG 2
-
-extern int opterr;
-extern int optind;
-extern int optopt;
-extern int optreset;
-extern char *optarg;
-
-extern int getopt(int nargc, char *const *nargv, const char *ostr);
-extern int getopt_long(int argc, char * const argv[], const char *optstring,
- const struct option *longopts, int totlen);
-extern void reset_options_reading(void);
-
-#endif /* _GETOPT_H_ */
/* last review : october 29th, 2002 */
#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95";
+static char sccsid[] = "@(#)opj_getopt.c 8.3 (Berkeley) 4/27/95";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "opj_getopt.h"
-int opterr = 1, /* if error message should be printed */
- optind = 1, /* index into parent argv vector */
- optopt, /* character checked for validity */
- optreset; /* reset getopt */
-const char *optarg; /* argument associated with option */
-
-typedef struct option
-{
- const char *name;
- int has_arg;
- int *flag;
- int val;
-}option_t;
+int opj_opterr = 1, /* if error message should be printed */
+ opj_optind = 1, /* index into parent argv vector */
+ opj_optopt, /* character checked for validity */
+ opj_optreset; /* reset getopt */
+ char *opj_optarg; /* argument associated with option */
#define BADCH (int)'?'
#define BADARG (int)':'
-#define EMSG ""
+static char EMSG[]={""};
/* As this class remembers its values from one Java call to the other, reset the values before each use */
void reset_options_reading(void) {
- opterr = 1;
- optind = 1;
+ opj_opterr = 1;
+ opj_optind = 1;
}
/*
* getopt --
* Parse argc/argv argument vector.
*/
-int getopt(int nargc, char *const *nargv, const char *ostr) {
+int opj_getopt(int nargc, char *const *nargv, const char *ostr) {
# define __progname nargv[0]
- static const char *place = EMSG; /* option letter processing */
+ static char *place = EMSG; /* option letter processing */
char *oli; /* option letter list index */
- if (optreset || !*place) { /* update scanning pointer */
- optreset = 0;
- if (optind >= nargc || *(place = nargv[optind]) != '-') {
+ if (opj_optreset || !*place) { /* update scanning pointer */
+ opj_optreset = 0;
+ if (opj_optind >= nargc || *(place = nargv[opj_optind]) != '-') {
place = EMSG;
return (-1);
}
if (place[1] && *++place == '-') { /* found "--" */
- ++optind;
+ ++opj_optind;
place = EMSG;
return (-1);
}
} /* option letter okay? */
- if ((optopt = (int) *place++) == (int) ':' ||
- !(oli = strchr(ostr, optopt))) {
+ if ((opj_optopt = (int) *place++) == (int) ':' ||
+ !(oli = strchr(ostr, opj_optopt))) {
/*
* if the user didn't specify '-' as an option,
* assume it means -1.
*/
- if (optopt == (int) '-')
+ if (opj_optopt == (int) '-')
return (-1);
if (!*place)
- ++optind;
- if (opterr && *ostr != ':') {
+ ++opj_optind;
+ if (opj_opterr && *ostr != ':') {
fprintf(stderr,
- "%s: illegal option -- %c\n", __progname, optopt);
+ "%s: illegal option -- %c\n", __progname, opj_optopt);
return (BADCH);
}
}
if (*++oli != ':') { /* don't need argument */
- optarg = NULL;
+ opj_optarg = NULL;
if (!*place)
- ++optind;
+ ++opj_optind;
} else { /* need an argument */
if (*place) /* no white space */
- optarg = place;
- else if (nargc <= ++optind) { /* no arg */
+ opj_optarg = place;
+ else if (nargc <= ++opj_optind) { /* no arg */
place = EMSG;
if (*ostr == ':')
return (BADARG);
- if (opterr) {
+ if (opj_opterr) {
fprintf(stderr,
"%s: option requires an argument -- %c\n",
- __progname, optopt);
+ __progname, opj_optopt);
return (BADCH);
}
} else /* white space */
- optarg = nargv[optind];
+ opj_optarg = nargv[opj_optind];
place = EMSG;
- ++optind;
+ ++opj_optind;
}
- return (optopt); /* dump back option letter */
+ return (opj_optopt); /* dump back option letter */
}
-int getopt_long(int argc, char * const argv[], const char *optstring,
-const struct option *longopts, int totlen) {
+int opj_getopt_long(int argc, char * const argv[], const char *optstring,
+const opj_option_t *longopts, int totlen) {
static int lastidx,lastofs;
char *tmp;
int i,len;
char param = 1;
again:
- if (optind >= argc || !argv[optind] || *argv[optind]!='-')
+ if (opj_optind >= argc || !argv[opj_optind] || *argv[opj_optind]!='-')
return -1;
- if (argv[optind][0]=='-' && argv[optind][1]==0) {
- if(optind >= (argc - 1)){ /* no more input parameters */
+ if (argv[opj_optind][0]=='-' && argv[opj_optind][1]==0) {
+ if(opj_optind >= (argc - 1)){ /* no more input parameters */
param = 0;
}
else{ /* more input parameters */
- if(argv[optind + 1][0] == '-'){
+ if(argv[opj_optind + 1][0] == '-'){
param = 0; /* Missing parameter after '-' */
}
else{
}
if (param == 0) {
- ++optind;
+ ++opj_optind;
return (BADCH);
}
- if (argv[optind][0]=='-') { /* long option */
- char* arg=argv[optind]+1;
- const struct option* o;
+ if (argv[opj_optind][0]=='-') { /* long option */
+ char* arg=argv[opj_optind]+1;
+ const opj_option_t* o;
o=longopts;
len=sizeof(longopts[0]);
if (param > 1){
- arg = argv[optind+1];
- optind++;
+ arg = argv[opj_optind+1];
+ opj_optind++;
}
else
- arg = argv[optind]+1;
+ arg = argv[opj_optind]+1;
if(strlen(arg)>1){
for (i=0;i<totlen;i=i+len,o++) {
if (!strcmp(o->name,arg)) { /* match */
if (o->has_arg == 0) {
- if ((argv[optind+1])&&(!(argv[optind+1][0]=='-'))){
- fprintf(stderr,"%s: option does not require an argument. Ignoring %s\n",arg,argv[optind+1]);
- ++optind;
+ if ((argv[opj_optind+1])&&(!(argv[opj_optind+1][0]=='-'))){
+ fprintf(stderr,"%s: option does not require an argument. Ignoring %s\n",arg,argv[opj_optind+1]);
+ ++opj_optind;
}
}else{
- optarg=argv[optind+1];
- if(optarg){
- if (optarg[0] == '-'){ /* Has read next input parameter: No arg for current parameter */
- if (opterr) {
+ opj_optarg=argv[opj_optind+1];
+ if(opj_optarg){
+ if (opj_optarg[0] == '-'){ /* Has read next input parameter: No arg for current parameter */
+ if (opj_opterr) {
fprintf(stderr,"%s: option requires an argument\n",arg);
return (BADCH);
}
}
}
- if (!optarg && o->has_arg==1) { /* no argument there */
- if (opterr) {
+ if (!opj_optarg && o->has_arg==1) { /* no argument there */
+ if (opj_opterr) {
fprintf(stderr,"%s: option requires an argument \n",arg);
return (BADCH);
}
}
- ++optind;
+ ++opj_optind;
}
- ++optind;
+ ++opj_optind;
if (o->flag)
*(o->flag)=o->val;
else
}
}//(end for)String not found in the list
fprintf(stderr,"Invalid option %s\n",arg);
- ++optind;
+ ++opj_optind;
return (BADCH);
}else{ /*Single character input parameter*/
if (*optstring==':') return ':';
- if (lastidx!=optind) {
- lastidx=optind; lastofs=0;
+ if (lastidx!=opj_optind) {
+ lastidx=opj_optind; lastofs=0;
}
- optopt=argv[optind][lastofs+1];
- if ((tmp=strchr(optstring,optopt))) {/*Found input parameter in list*/
+ opj_optopt=argv[opj_optind][lastofs+1];
+ if ((tmp=strchr(optstring,opj_optopt))) {/*Found input parameter in list*/
if (*tmp==0) { /* apparently, we looked for \0, i.e. end of argument */
- ++optind;
+ ++opj_optind;
goto again;
}
if (tmp[1]==':') { /* argument expected */
- if (tmp[2]==':' || argv[optind][lastofs+2]) { /* "-foo", return "oo" as optarg */
- if (!*(optarg=argv[optind]+lastofs+2)) optarg=0;
+ if (tmp[2]==':' || argv[opj_optind][lastofs+2]) { /* "-foo", return "oo" as opj_optarg */
+ if (!*(opj_optarg=argv[opj_optind]+lastofs+2)) opj_optarg=0;
goto found;
}
- optarg=argv[optind+1];
- if(optarg){
- if (optarg[0] == '-'){ /* Has read next input parameter: No arg for current parameter */
- if (opterr) {
+ opj_optarg=argv[opj_optind+1];
+ if(opj_optarg){
+ if (opj_optarg[0] == '-'){ /* Has read next input parameter: No arg for current parameter */
+ if (opj_opterr) {
fprintf(stderr,"%s: option requires an argument\n",arg);
return (BADCH);
}
}
}
- if (!optarg) { /* missing argument */
- if (opterr) {
+ if (!opj_optarg) { /* missing argument */
+ if (opj_opterr) {
fprintf(stderr,"%s: option requires an argument\n",arg);
return (BADCH);
}
}
- ++optind;
+ ++opj_optind;
}else {/*Argument not expected*/
++lastofs;
- return optopt;
+ return opj_optopt;
}
found:
- ++optind;
- return optopt;
+ ++opj_optind;
+ return opj_optopt;
} else { /* not found */
fprintf(stderr,"Invalid option %s\n",arg);
- ++optind;
+ ++opj_optind;
return (BADCH);
}//end of not found
}// end of single character
}//end '-'
fprintf(stderr,"Invalid option\n");
- ++optind;
+ ++opj_optind;
return (BADCH);;
}//end function
--- /dev/null
+/* last review : october 29th, 2002 */
+
+#ifndef _GETOPT_H_
+#define _GETOPT_H_
+
+typedef struct opj_option
+{
+ const char *name;
+ int has_arg;
+ int *flag;
+ int val;
+}opj_option_t;
+
+#define NO_ARG 0
+#define REQ_ARG 1
+#define OPT_ARG 2
+
+extern int opj_opterr;
+extern int opj_optind;
+extern int opj_optopt;
+extern int opj_optreset;
+extern char *opj_optarg;
+
+extern int opj_getopt(int nargc, char *const *nargv, const char *ostr);
+extern int opj_getopt_long(int argc, char * const argv[], const char *optstring,
+ const opj_option_t *longopts, int totlen);
+extern void reset_options_reading(void);
+
+#endif /* _GETOPT_H_ */
# Makefile for the MJ2 codecs of the OpenJPEG library: frames_to_mj2, mj2_to_frames, extract_j2k_from_mj2 and wrap_j2k_in_mj2
-SET(common_SRCS "")
-IF(DONT_HAVE_GETOPT)
- SET(common_SRCS ${OPENJPEG_SOURCE_DIR}/applications/common/getopt.c)
-ENDIF(DONT_HAVE_GETOPT)
+SET(common_SRCS ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c)
# While mj2 executables do not use the API correctly, we do not link with the library but rather compile the sources files.
SET(OPJ_SRCS
frames_to_mj2_LDADD = -lm
frames_to_mj2_SOURCES = \
$(OPJ_SRC) \
-../common/getopt.c \
+../common/opj_getopt.c \
mj2_convert.c \
mj2.c \
frames_to_mj2.c \
mj2_to_frames_SOURCES = \
$(OPJ_SRC) \
../common/color.c \
-../common/getopt.c \
+../common/opj_getopt.c \
mj2_convert.c \
mj2.c \
mj2_to_frames.c \
#include "cio.h"
#include "mj2.h"
#include "mj2_convert.h"
-#include "getopt.h"
+#include "opj_getopt.h"
/**
Size of memory first allocated for MOOV box
}
while (1) {
- int c = getopt(argc, argv,
+ int c = opj_getopt(argc, argv,
"i:o:r:q:f:t:n:c:b:p:s:d:P:S:E:M:R:T:C:I:W:F:D:h");
if (c == -1)
break;
switch (c) {
case 'i': /* IN fill */
{
- char *infile = optarg;
- s = optarg;
+ char *infile = opj_optarg;
+ s = opj_optarg;
while (*s) {
s++;
}
/* ----------------------------------------------------- */
case 'o': /* OUT fill */
{
- char *outfile = optarg;
+ char *outfile = opj_optarg;
while (*outfile) {
outfile++;
}
outfile--;
S1 = *outfile;
- outfile = optarg;
+ outfile = opj_optarg;
if ((S1 == 'm' && S2 == 'j' && S3 == '2')
|| (S1 == 'M' && S2 == 'J' && S3 == '2'))
case 'r': /* rates rates/distorsion */
{
float rate;
- s = optarg;
+ s = opj_optarg;
while (sscanf(s, "%f", &rate) == 1) {
j2k_parameters->tcp_rates[j2k_parameters->tcp_numlayers] = rate * 2;
j2k_parameters->tcp_numlayers++;
break;
/* ----------------------------------------------------- */
case 'q': /* add fixed_quality */
- s = optarg;
+ s = opj_optarg;
while (sscanf(s, "%f", &j2k_parameters->tcp_distoratio[j2k_parameters->tcp_numlayers]) == 1) {
j2k_parameters->tcp_numlayers++;
while (*s && *s != ',') {
int *row = NULL, *col = NULL;
int numlayers = 0, numresolution = 0, matrix_width = 0;
- s = optarg;
+ s = opj_optarg;
sscanf(s, "%d", &numlayers);
s++;
if (numlayers > 9)
break;
/* ----------------------------------------------------- */
case 't': /* tiles */
- sscanf(optarg, "%d,%d", &j2k_parameters->cp_tdx, &j2k_parameters->cp_tdy);
+ sscanf(opj_optarg, "%d,%d", &j2k_parameters->cp_tdx, &j2k_parameters->cp_tdy);
j2k_parameters->tile_size_on = OPJ_TRUE;
break;
/* ----------------------------------------------------- */
case 'n': /* resolution */
- sscanf(optarg, "%d", &j2k_parameters->numresolution);
+ sscanf(opj_optarg, "%d", &j2k_parameters->numresolution);
break;
/* ----------------------------------------------------- */
case 'c': /* precinct dimension */
char sep;
int res_spec = 0;
- char *s = optarg;
+ char *s = opj_optarg;
do {
sep = 0;
sscanf(s, "[%d,%d]%c", &j2k_parameters->prcw_init[res_spec],
case 'b': /* code-block dimension */
{
int cblockw_init = 0, cblockh_init = 0;
- sscanf(optarg, "%d,%d", &cblockw_init, &cblockh_init);
+ sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init);
if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024
|| cblockw_init < 4 || cblockh_init > 1024 || cblockh_init < 4) {
fprintf(stderr,
{
char progression[5];
- strncpy(progression, optarg, 5);
+ strncpy(progression, opj_optarg, 5);
j2k_parameters->prog_order = give_progression(progression);
if (j2k_parameters->prog_order == -1) {
fprintf(stderr, "Unrecognized progression order "
/* ----------------------------------------------------- */
case 's': /* subsampling factor */
{
- if (sscanf(optarg, "%d,%d", &j2k_parameters->subsampling_dx,
+ if (sscanf(opj_optarg, "%d,%d", &j2k_parameters->subsampling_dx,
&j2k_parameters->subsampling_dy) != 2) {
fprintf(stderr, "'-s' sub-sampling argument error ! [-s dx,dy]\n");
return 1;
/* ----------------------------------------------------- */
case 'd': /* coordonnate of the reference grid */
{
- if (sscanf(optarg, "%d,%d", &j2k_parameters->image_offset_x0,
+ if (sscanf(opj_optarg, "%d,%d", &j2k_parameters->image_offset_x0,
&j2k_parameters->image_offset_y0) != 2) {
fprintf(stderr, "-d 'coordonnate of the reference grid' argument "
"error !! [-d x0,y0]\n");
int numpocs = 0; /* number of progression order change (POC) default 0 */
opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */
- char *s = optarg;
+ char *s = opj_optarg;
POC = j2k_parameters->POC;
while (sscanf(s, "T%d=%d,%d,%d,%d,%d,%4s", &POC[numpocs].tile,
break;
/* ------------------------------------------------------ */
case 'M': /* Mode switch pas tous au point !! */
- if (sscanf(optarg, "%d", &value) == 1) {
+ if (sscanf(opj_optarg, "%d", &value) == 1) {
for (i = 0; i <= 5; i++) {
int cache = value & (1 << i);
if (cache)
/* ------------------------------------------------------ */
case 'R': /* ROI */
{
- if (sscanf(optarg, "OI:c=%d,U=%d", &j2k_parameters->roi_compno,
+ if (sscanf(opj_optarg, "OI:c=%d,U=%d", &j2k_parameters->roi_compno,
&j2k_parameters->roi_shift) != 2) {
fprintf(stderr, "ROI error !! [-ROI:c='compno',U='shift']\n");
return 1;
/* ------------------------------------------------------ */
case 'T': /* Tile offset */
{
- if (sscanf(optarg, "%d,%d", &j2k_parameters->cp_tx0, &j2k_parameters->cp_ty0) != 2) {
+ if (sscanf(opj_optarg, "%d,%d", &j2k_parameters->cp_tx0, &j2k_parameters->cp_ty0) != 2) {
fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]");
return 1;
}
/* ------------------------------------------------------ */
case 'C': /* Add a comment */
{
- j2k_parameters->cp_comment = (char*)malloc(strlen(optarg) + 1);
+ j2k_parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1);
if(j2k_parameters->cp_comment) {
- strcpy(j2k_parameters->cp_comment, optarg);
+ strcpy(j2k_parameters->cp_comment, opj_optarg);
}
}
break;
/* ------------------------------------------------------ */
case 'W': /* Width and Height and Cb and Cr subsampling in case of YUV format files */
if (sscanf
- (optarg, "%d,%d,%d,%d", &mj2_parameters.w, &mj2_parameters.h, &mj2_parameters.CbCr_subsampling_dx,
+ (opj_optarg, "%d,%d,%d,%d", &mj2_parameters.w, &mj2_parameters.h, &mj2_parameters.CbCr_subsampling_dx,
&mj2_parameters.CbCr_subsampling_dy) != 4) {
fprintf(stderr, "-W argument error");
return 1;
break;
/* ------------------------------------------------------ */
case 'F': /* Video frame rate */
- if (sscanf(optarg, "%d", &mj2_parameters.frame_rate) != 1) {
+ if (sscanf(opj_optarg, "%d", &mj2_parameters.frame_rate) != 1) {
fprintf(stderr, "-F argument error");
return 1;
}
break;
/* ------------------------------------------------------ */
case 'D': /* Depth: the precision */
- if(sscanf(optarg, "%d", &prec) != 1) prec = 0;
+ if(sscanf(opj_optarg, "%d", &prec) != 1) prec = 0;
break;
default:
#include "mj2_to_metadata.h"
#include <string.h>
-#include "getopt.h"
+#include "opj_getopt.h"
/* -------------------------------------------------------------------------- */
Name="MJ2 Header Files"\r
>\r
<File\r
- RelativePath="compat\getopt.h"\r
+ RelativePath="compat\opj_getopt.h"\r
>\r
</File>\r
<File\r
Name="MJ2 Source Files"\r
>\r
<File\r
- RelativePath="compat\getopt.c"\r
+ RelativePath="compat\opj_getopt.c"\r
>\r
<FileConfiguration\r
Name="Debug|Win32"\r
)
# 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)
+SET(comparePGXimages_SRCS comparePGXimages.c ${OPENJPEG_SOURCE_DIR}/applications/codec/convert.c ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c)
+
+SET(compare_dump_files_SRCS compare_dump_files.c ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c)
+
+SET(compareRAWimages_SRCS compareRAWimages.c ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c)
ADD_EXECUTABLE(comparePGXimages ${comparePGXimages_SRCS})
TARGET_LINK_LIBRARIES(comparePGXimages ${OPENJPEG_LIBRARY_NAME}
ADD_EXECUTABLE(compare_dump_files ${compare_dump_files_SRCS})
+ADD_EXECUTABLE(compareRAWimages ${compareRAWimages_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)
\ No newline at end of file
+ADD_SUBDIRECTORY(nonregression)
#include <ctype.h>
#include "opj_config.h"
-#include "getopt.h"
+#include "opj_getopt.h"
#include "openjpeg.h"
#include "format_defs.h"
param->tabPEAKvalues = NULL;
param->nr_flag = 0;
- opterr = 0;
+ opj_opterr = 0;
- while ((c = getopt(argc, argv, optlist)) != -1)
+ while ((c = opj_getopt(argc, argv, optlist)) != -1)
switch (c)
{
case 'b':
- sizemembasefile = (int)strlen(optarg)+1;
+ sizemembasefile = (int)strlen(opj_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';
+ strncpy(param->base_filename, opj_optarg, strlen(opj_optarg));
+ param->base_filename[strlen(opj_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;
+ sizememtestfile = (int) strlen(opj_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';
+ strncpy(param->test_filename, opj_optarg, strlen(opj_optarg));
+ param->test_filename[strlen(opj_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);
+ param->nbcomp = atoi(opj_optarg);
break;
case 'm':
- MSElistvalues = optarg;
+ MSElistvalues = opj_optarg;
flagM = 1;
break;
case 'p':
- PEAKlistvalues = optarg;
+ PEAKlistvalues = opj_optarg;
flagP = 1;
break;
case 'd':
param->nr_flag = 1;
break;
case 's':
- separatorList = optarg;
+ separatorList = opj_optarg;
break;
case '?':
- if ((optopt == 'b') || (optopt == 't') || (optopt == 'n') || (optopt == 'p') || (optopt == 'm') || (optopt
+ if ((opj_optopt == 'b') || (opj_optopt == 't') || (opj_optopt == 'n') || (opj_optopt == 'p') || (opj_optopt == 'm') || (opj_optopt
== 's'))
- fprintf(stderr, "Option -%c requires an argument.\n", optopt);
+ fprintf(stderr, "Option -%c requires an argument.\n", opj_optopt);
else
- if (isprint(optopt)) fprintf(stderr, "Unknown option `-%c'.\n", optopt);
- else fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
+ if (isprint(opj_optopt)) fprintf(stderr, "Unknown option `-%c'.\n", opj_optopt);
+ else fprintf(stderr, "Unknown option character `\\x%x'.\n", opj_optopt);
return 1;
default:
- 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, opj_optarg);
break;
}
- if (optind != argc)
+ if (opj_optind != argc)
{
- for (index = optind; index < argc; index++)
+ for (index = opj_optind; index < argc; index++)
fprintf(stderr,"Non-option argument %s\n", argv[index]);
return EXIT_FAILURE;
}
--- /dev/null
+/*
+ * 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.
+ */
+
+/*
+ * compareRAWimages.c
+ *
+ * Created on: 31 August 2011
+ * Author: mickael
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "opj_getopt.h"
+
+void compareRAWimages_help_display(void);
+
+typedef struct test_cmp_parameters
+{
+ /** */
+ char* base_filename;
+ /** */
+ char* test_filename;
+} test_cmp_parameters;
+
+/*******************************************************************************
+ * Command line help function
+ *******************************************************************************/
+void compareRAWimages_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 RAW image \n");
+ fprintf(stdout," -t \t REQUIRED \t filename to the test RAW 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;
+
+ opj_opterr = 0;
+ while ((c = getopt(argc, argv, optlist)) != -1)
+ switch (c)
+ {
+ case 'b':
+ sizemembasefile = (int)strlen(opj_optarg)+1;
+ param->base_filename = (char*) malloc(sizemembasefile);
+ param->base_filename[0] = '\0';
+ strncpy(param->base_filename, opj_optarg, strlen(opj_optarg));
+ param->base_filename[strlen(opj_optarg)] = '\0';
+ //printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );
+ break;
+ case 't':
+ sizememtestfile = (int) strlen(opj_optarg) + 1;
+ param->test_filename = (char*) malloc(sizememtestfile);
+ param->test_filename[0] = '\0';
+ strncpy(param->test_filename, opj_optarg, strlen(opj_optarg));
+ param->test_filename[strlen(opj_optarg)] = '\0';
+ //printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);
+ break;
+ case '?':
+ if ((opj_optopt == 'b') || (opj_optopt == 't'))
+ fprintf(stderr, "Option -%c requires an argument.\n", opj_optopt);
+ else
+ if (isprint(opj_optopt)) fprintf(stderr, "Unknown option `-%c'.\n", opj_optopt);
+ else fprintf(stderr, "Unknown option character `\\x%x'.\n", opj_optopt);
+ return 1;
+ default:
+ fprintf(stderr, "WARNING -> this option is not valid \"-%c %s\"\n", c, opj_optarg);
+ break;
+ }
+
+ if (opj_optind != argc) {
+ for (index = opj_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 *file_test=NULL, *file_base=NULL;
+ unsigned char equal = 1;
+
+ // Get parameters from command line
+ if (parse_cmdline_cmp(argc, argv, &inParam) == EXIT_FAILURE)
+ {
+ compareRAWimages_help_display();
+ return EXIT_FAILURE;
+ }
+
+ file_test = fopen(inParam.test_filename, "rb");
+ if (!file_test) {
+ fprintf(stderr, "Failed to open %s for reading !!\n", inParam.test_filename);
+ return EXIT_FAILURE;
+ }
+
+ file_base = fopen(inParam.base_filename, "rb");
+ if (!file_base) {
+ fprintf(stderr, "Failed to open %s for reading !!\n", inParam.base_filename);
+ return EXIT_FAILURE;
+ }
+
+ // Read simultaneously the two files
+ while (equal)
+ {
+ unsigned char value_test = 0;
+ unsigned char eof_test = 0;
+ unsigned char value_base = 0;
+ unsigned char eof_base = 0;
+
+ // Read one byte
+ if (!fread(&value_test, 1, 1, file_test)) {
+ eof_test = 1;
+ }
+
+ // Read one byte
+ if (!fread(&value_base, 1, 1, file_base)) {
+ eof_base = 1;;
+ }
+
+ // End of file reached by the two files?
+ if (eof_test && eof_base)
+ break;
+
+ // End of file reached only by one file?
+ if (eof_test || eof_base)
+ {
+ fprintf(stdout,"Files have different sizes.\n");
+ equal = 0;
+ }
+
+ // Binary values are equal?
+ if (value_test != value_base)
+ {
+ fprintf(stdout,"Binary values read in the file are different.\n");
+ equal = 0;
+ }
+ }
+
+ fclose(file_test);
+ fclose(file_base);
+
+ if (equal)
+ {
+ fprintf(stdout,"---- TEST SUCCEED: Files are equal ----\n");
+ return EXIT_SUCCESS;
+ }
+ else
+ return EXIT_FAILURE;
+}
#include <string.h>
#include <ctype.h>
-#include "getopt.h"
+#include "opj_getopt.h"
typedef struct test_cmp_parameters
{
param->base_filename = NULL;
param->test_filename = NULL;
- opterr = 0;
+ opj_opterr = 0;
- while ((c = getopt(argc, argv, optlist)) != -1)
+ while ((c = opj_getopt(argc, argv, optlist)) != -1)
switch (c)
{
case 'b':
- sizemembasefile = (int)strlen(optarg)+1;
+ sizemembasefile = (int)strlen(opj_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';
+ strncpy(param->base_filename, opj_optarg, strlen(opj_optarg));
+ param->base_filename[strlen(opj_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;
+ sizememtestfile = (int) strlen(opj_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';
+ strncpy(param->test_filename, opj_optarg, strlen(opj_optarg));
+ param->test_filename[strlen(opj_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);
+ if ( (opj_optopt == 'b') || (opj_optopt == 't') )
+ fprintf(stderr, "Option -%c requires an argument.\n", opj_optopt);
else
- if (isprint(optopt)) fprintf(stderr, "Unknown option `-%c'.\n", optopt);
- else fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
+ if (isprint(opj_optopt)) fprintf(stderr, "Unknown option `-%c'.\n", opj_optopt);
+ else fprintf(stderr, "Unknown option character `\\x%x'.\n", opj_optopt);
return 1;
default:
- 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, opj_optarg);
break;
}
- if (optind != argc)
+ if (opj_optind != argc)
{
- for (index = optind; index < argc; index++)
+ for (index = opj_optind; index < argc; index++)
fprintf(stderr,"Non-option argument %s\n", argv[index]);
return EXIT_FAILURE;
}
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);
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);
+ if (fgets(strbase, nbytes, fbase) == NULL)
+ fprintf(stderr,"\nWARNING: fgets return a NULL value");
+ else
+ {
+ if (fgets(strtest, nbytes, ftest) == NULL)
+ fprintf(stderr,"\nWARNING: fgets return a NULL value");
+ else
+ {
+ 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_d);free(strtest_d);
+ }
+ }
- 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);
+ free(strbase);free(strtest);
+
+ same = 0;
- 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
# PROPERTIES DEPENDS
# NR-${filename}-decode)
-ENDFOREACH(filepath)
\ No newline at end of file
+<<<<<<< .working
+ENDFOREACH(filepath)=======
+ENDFOREACH(filepath)
+
+
+# TEST ENCODER SUITE
+# Read a input file to know which files processed and with which options.
+
+IF (NOT WIN32)
+CONFIGURE_FILE("opj_ref_decode_cmd.sh.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/opj_ref_decode_cmd.sh"
+ @ONLY)
+ENDIF (NOT WIN32)
+
+string(COMPARE EQUAL ${REF_DECODER_BIN_PATH} "NOTFOUND" REF_DECODER_NOTFOUND)
+IF (REF_DECODER_NOTFOUND)
+ MESSAGE(STATUS "REF_DECODER_BIN_PATH not found, if you want all the encoding tests suite please provide a regular path")
+ENDIF (REF_DECODER_NOTFOUND)
+
+
+# Read the file into a list
+FILE(STRINGS encoder_test_suite.txt OPJ_TEST_ENC_CMD_LINE_LIST)
+
+SET(it_test 0)
+
+FOREACH(OPJ_TEST_ENC_CMD_LINE ${OPJ_TEST_ENC_CMD_LINE_LIST})
+ math(EXPR it_test "${it_test}+1" )
+
+ #message(STATUS ${OPJ_TEST_ENC_CMD_LINE})
+
+ string(REPLACE " " ";" CMD_ARG_LIST ${OPJ_TEST_ENC_CMD_LINE})
+
+ #message(STATUS "list = ${CMD_ARG_LIST}")
+
+ list(GET CMD_ARG_LIST 0 EXE_NAME)
+ string(COMPARE EQUAL ${EXE_NAME} "image_to_j2k" EXE_NAME_FOUND)
+ IF(EXE_NAME_FOUND)
+ list(REMOVE_AT CMD_ARG_LIST 0)
+ ELSE(EXE_NAME_FOUND)
+ string(COMPARE EQUAL ${EXE_NAME} "#" IGNORE_LINE_FOUND)
+ IF(IGNORE_LINE_FOUND)
+ message( STATUS "Current line is ignored: ${OPJ_TEST_ENC_CMD_LINE}")
+ ELSE(IGNORE_LINE_FOUND)
+ message( FATAL_ERROR "${EXE_ARG} is not the right executable name to encode file (try to use image_to_j2k)")
+ ENDIF(IGNORE_LINE_FOUND)
+ ENDIF(EXE_NAME_FOUND)
+
+ IF(NOT IGNORE_LINE_FOUND)
+ SET(CMD_ARG_LIST_2 "")
+ SET(ARG_POS 0)
+ SET(INPUT_ARG_POS 0)
+ SET(OUTPUT_ARG_POS 0)
+
+ FOREACH(CMD_ARG_ELT ${CMD_ARG_LIST})
+ math(EXPR ARG_POS "${ARG_POS}+1" )
+
+ # Will work only with cmake version > 2.8.4
+ #message(STATUS "${CMD_ARG_ELT}")
+ #string(FIND "${CMD_ARG_ELT}" "-i input/" INPUT_ARG_FOUND)
+ #message(STATUS "pos = ${INPUT_ARG_FOUND}")
+ #IF(INPUT_ARG_FOUND)
+ # string(SUBSTRING ${CMD_ARG_ELT} INPUT_ARG_FOUND -1 filename_input)
+ # message(STATUS "filename = ${filename_input}")
+ #ELSE(INPUT_ARG_FOUND)
+ # message( FATAL_ERROR "Not found a input image into the list of arguments")
+ #ENDIF(INPUT_ARG_FOUND)
+
+
+ string(COMPARE EQUAL ${CMD_ARG_ELT} "-i" INPUT_ARG_FOUND)
+ IF(INPUT_ARG_FOUND)
+ SET(INPUT_ARG_POS ${ARG_POS})
+ SET(INPUT_ARG_FOUND 0)
+ ENDIF(INPUT_ARG_FOUND)
+
+ string(COMPARE EQUAL ${CMD_ARG_ELT} "-o" OUTPUT_ARG_FOUND)
+ IF(OUTPUT_ARG_FOUND)
+ SET(OUTPUT_ARG_POS ${ARG_POS})
+ SET(OUTPUT_ARG_FOUND 0)
+ ENDIF(OUTPUT_ARG_FOUND)
+
+ string(REPLACE "input/" "${INPUT_NR}/" CMD_ARG_ELT ${CMD_ARG_ELT})
+ string(REPLACE "temp/" "${TEMP}/" CMD_ARG_ELT ${CMD_ARG_ELT})
+
+ list (APPEND CMD_ARG_LIST_2 ${CMD_ARG_ELT})
+
+ ENDFOREACH(CMD_ARG_ELT)
+
+ list(GET CMD_ARG_LIST_2 ${INPUT_ARG_POS} INPUT_FILENAME)
+ get_filename_component(INPUT_FILENAME_NAME ${INPUT_FILENAME} NAME)
+ list(GET CMD_ARG_LIST_2 ${OUTPUT_ARG_POS} OUTPUT_FILENAME)
+ get_filename_component(OUTPUT_FILENAME_NAME_WE ${OUTPUT_FILENAME} NAME_WE)
+
+
+ # Encode an image into the jpeg2000 format
+ ADD_TEST(NR-ENC-${INPUT_FILENAME_NAME}-${it_test}-encode
+ ${EXECUTABLE_OUTPUT_PATH}/${EXE_NAME}
+ ${CMD_ARG_LIST_2}
+ )
+
+ # Dump the encoding file
+ ADD_TEST(NR-ENC-${INPUT_FILENAME_NAME}-${it_test}-dump
+ ${EXECUTABLE_OUTPUT_PATH}/j2k_dump
+ -i ${OUTPUT_FILENAME}
+ -o ${OUTPUT_FILENAME}-ENC-${it_test}.txt
+ )
+ SET_TESTS_PROPERTIES(NR-ENC-${INPUT_FILENAME_NAME}-${it_test}-dump
+ PROPERTIES DEPENDS
+ NR-ENC-${INPUT_FILENAME_NAME}-${it_test}-encode)
+
+ # Compare the dump file with the baseline
+ ADD_TEST(NR-ENC-${INPUT_FILENAME_NAME}-${it_test}-compare_dump2base
+ ${EXECUTABLE_OUTPUT_PATH}/compare_dump_files
+ -b ${BASELINE_NR}/opj_${OUTPUT_FILENAME_NAME_WE}-ENC-${it_test}.txt
+ -t ${OUTPUT_FILENAME}-ENC-${it_test}.txt
+ )
+
+ SET_TESTS_PROPERTIES(NR-ENC-${INPUT_FILENAME_NAME}-${it_test}-compare_dump2base
+ PROPERTIES DEPENDS
+ NR-ENC-${INPUT_FILENAME_NAME}-${it_test}-dump)
+
+ # Decode the encoding file with kakadu expand command
+ IF (NOT REF_DECODER_NOTFOUND)
+ IF (NOT WIN32)
+ # Need a bash script to export the path of the kakadu library into PATH
+ ADD_TEST( NR-ENC-${INPUT_FILENAME_NAME}-${it_test}-decode-ref
+ bash ${CMAKE_CURRENT_BINARY_DIR}/opj_ref_decode_cmd.sh
+ -i ${OUTPUT_FILENAME}
+ -o ${OUTPUT_FILENAME}.raw
+ )
+ ELSE (NOT WIN32)
+ ADD_TEST(NR-ENC-${INPUT_FILENAME_NAME}-${it_test}-decode-ref
+ ${REF_DECODER_BIN_PATH}/kdu_expand
+ -i ${OUTPUT_FILENAME}
+ -o ${OUTPUT_FILENAME}.raw
+ )
+ ENDIF (NOT WIN32)
+
+ SET_TESTS_PROPERTIES(NR-ENC-${INPUT_FILENAME_NAME}-${it_test}-decode-ref
+ PROPERTIES DEPENDS
+ NR-ENC-${INPUT_FILENAME_NAME}-${it_test}-encode)
+
+ # Compare the decoding file with baseline generated from the kdu_expand and baseline.j2k
+ ADD_TEST(NR-ENC-${INPUT_FILENAME_NAME}-${it_test}-compare_dec-ref-out2base
+ ${EXECUTABLE_OUTPUT_PATH}/compareRAWimages
+ #-b ${BASELINE_NR}/opj_${OUTPUT_FILENAME_NAME_WE}-ENC-${it_test}.raw
+ -b ${BASELINE_NR}/opj_${OUTPUT_FILENAME_NAME_WE}-ENC-${it_test}.raw
+ -t ${OUTPUT_FILENAME}.raw
+ )
+
+ SET_TESTS_PROPERTIES(NR-ENC-${INPUT_FILENAME_NAME}-${it_test}-compare_dec-ref-out2base
+ PROPERTIES DEPENDS
+ NR-ENC-${INPUT_FILENAME_NAME}-${it_test}-decode-ref)
+
+ ENDIF (NOT REF_DECODER_NOTFOUND)
+
+ ENDIF(NOT IGNORE_LINE_FOUND)
+
+ENDFOREACH(OPJ_TEST_ENC_CMD_LINE)
+
+
+
+
+>>>>>>> .merge-right.r907
--- /dev/null
+image_to_j2k -i input/Bretagne1.ppm -o temp/Bretagne1_0.j2k -r 200,50,10\r
+image_to_j2k -i input/Bretagne1.ppm -o temp/Bretagne1_1.j2k -q 30,35,40 -n 2\r
+image_to_j2k -i input/Bretagne1.ppm -o temp/Bretagne1_2.j2k -q 30,35,40 -b 16,16 -c [64,64]\r
+image_to_j2k -i input/Bretagne2.ppm -o temp/Bretagne2_0.j2k -c [128,128],[128,128],[128,128] -r 100,20,2 -t 640,480 -b 32,32\r
+image_to_j2k -i input/Bretagne2.ppm -o temp/Bretagne2_1.j2k -t 127,127 -p PCRL\r
+image_to_j2k -i input/Bretagne2.ppm -o temp/Bretagne2_2.j2k -s 2,2 -SOP\r
+image_to_j2k -i input/Bretagne2.ppm -o temp/Bretagne2_3.j2k -EPH -M 38\r
+image_to_j2k -i input/Bretagne2.ppm -o temp/Bretagne2_4.j2k -d 150,300 -r 800\r
+image_to_j2k -i input/Cevennes1.bmp -o temp/Cevennes1.j2k -r 10\r
+image_to_j2k -i input/Cevennes2.ppm -o temp/Cevennes2.jp2 -r 50\r
+image_to_j2k -i input/Rome.bmp -o temp/Rome.jp2 -q 30,35,50 -p LRCP -n 3\r
+# image_to_j2k -i input/X_4_2K_24_185_CBR_WB_000.tif -o temp/X_4_2K_24_185_CBR_WB_000.j2k -cinema2K 24\r
+# image_to_j2k -i input/X_5_2K_24_235_CBR_STEM24_000.tif -o temp/X_5_2K_24_235_CBR_STEM24_000.j2k -cinema2K 24\r
+# image_to_j2k -i input/X_6_2K_24_FULL_CBR_CIRCLE_000.tif -o temp/X_6_2K_24_FULL_CBR_CIRCLE_000.j2k -cinema2K 24\r
--- /dev/null
+#!/bin/bash
+export LD_LIBRARY_PATH="@REF_DECODER_BIN_PATH@"
+echo run following command: @REF_DECODER_BIN_PATH@/kdu_expand $@
+@REF_DECODER_BIN_PATH@/kdu_expand $@
\ No newline at end of file