summaryrefslogtreecommitdiff
path: root/applications
diff options
context:
space:
mode:
authorMickael Savinaud <savmickael@users.noreply.github.com>2011-08-11 10:18:02 +0000
committerMickael Savinaud <savmickael@users.noreply.github.com>2011-08-11 10:18:02 +0000
commit2724f85cadd8c24dfb235d790989edd19629a2cb (patch)
tree01ab33fe728b35e7029781ae9848d04e9d1ecd95 /applications
parent40b989ce0066a4a15e8891209eeb3df510a158ff (diff)
parente3e2dc1f6e5045ba7b180a7917b5b91a3a9b9e31 (diff)
backport rev[824-834] and rev[837-859] into the openjpeg-1.5 branch
Diffstat (limited to 'applications')
-rw-r--r--applications/CMakeLists.txt127
-rw-r--r--applications/codec/CMakeLists.txt49
-rw-r--r--applications/codec/convert.c462
-rw-r--r--applications/codec/image_to_j2k.c12
-rw-r--r--applications/codec/j2k_dump.c66
-rw-r--r--applications/codec/j2k_to_image.c26
-rw-r--r--applications/common/getopt.c4
-rw-r--r--applications/common/getopt.h2
-rw-r--r--applications/jpip/opj_client/opj_dec_server/opj_dec_server.c2
-rw-r--r--applications/mj2/CMakeLists.txt20
-rw-r--r--applications/mj2/frames_to_mj2.c20
-rw-r--r--applications/mj2/mj2.c14
-rw-r--r--applications/mj2/mj2.h8
-rw-r--r--applications/mj2/mj2_convert.c18
-rw-r--r--applications/mj2/mj2_convert.h2
15 files changed, 404 insertions, 428 deletions
diff --git a/applications/CMakeLists.txt b/applications/CMakeLists.txt
index 5f413169..3b65ade1 100644
--- a/applications/CMakeLists.txt
+++ b/applications/CMakeLists.txt
@@ -1,130 +1,9 @@
-IF(BUILD_CODEC OR BUILD_MJ2)
-#
-#
-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)
-#
+# Build the each application if it needed
+
IF(BUILD_CODEC)
ADD_SUBDIRECTORY(codec)
ENDIF(BUILD_CODEC)
-#
+
IF(BUILD_MJ2)
ADD_SUBDIRECTORY(mj2)
ENDIF(BUILD_MJ2)
-#
diff --git a/applications/codec/CMakeLists.txt b/applications/codec/CMakeLists.txt
index 1a25d310..8c1d3c25 100644
--- a/applications/codec/CMakeLists.txt
+++ b/applications/codec/CMakeLists.txt
@@ -1,4 +1,4 @@
- # Build the demo app, small examples
+# Build the demo app, small examples
# First thing define the common source:
SET(common_SRCS
@@ -37,15 +37,8 @@ ENDIF(WIN32)
FOREACH(exe j2k_to_image image_to_j2k j2k_dump)
ADD_EXECUTABLE(${exe} ${exe}.c ${common_SRCS})
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:
IF(UNIX)
TARGET_LINK_LIBRARIES(${exe} m)
@@ -103,40 +96,4 @@ IF(BUILD_JPWL)
INSTALL(TARGETS JPWL_image_to_j2k JPWL_j2k_to_image
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
)
-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)
+ENDIF(BUILD_JPWL) \ No newline at end of file
diff --git a/applications/codec/convert.c b/applications/codec/convert.c
index f1a5edb7..c7afc074 100644
--- a/applications/codec/convert.c
+++ b/applications/codec/convert.c
@@ -102,7 +102,11 @@ int tga_readheader(FILE *fp, unsigned int *bits_per_pixel,
return 0;
// 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;
@@ -113,7 +117,12 @@ int tga_readheader(FILE *fp, unsigned int *bits_per_pixel,
if (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);
}
@@ -149,9 +158,14 @@ int tga_writeheader(FILE *fp, int bits_per_pixel, int width, int height,
memset(&tga, 0, sizeof(tga_header));
- tga.pixel_depth = bits_per_pixel;
- tga.image_width = width;
- tga.image_height = height;
+ if ( bits_per_pixel < 256 )
+ tga.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.
@@ -246,9 +260,25 @@ opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) {
for (x=0;x<image_width;x++)
{
unsigned char r,g,b;
- fread(&b, 1, 1, f);
- fread(&g, 1, 1, f);
- fread(&r, 1, 1, f);
+
+ if( !fread(&b, 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[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++)
{
unsigned char r,g,b,a;
- fread(&b, 1, 1, f);
- fread(&g, 1, 1, f);
- fread(&r, 1, 1, f);
- fread(&a, 1, 1, f);
+ if ( !fread(&b, 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;
+ }
+ 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[1].data[index]=g;
@@ -408,10 +458,8 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
unsigned int j, PAD = 0;
int x, y, index;
- int gray_scale = 1, not_end_file = 1;
+ int gray_scale = 1;
int has_color;
- unsigned int line = 0, col = 0;
- unsigned char v, v2;
DWORD W, H;
IN = fopen(filename, "rb");
@@ -558,7 +606,13 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
RGB = (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;
@@ -590,9 +644,9 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
has_color = 0;
for (j = 0; j < Info_h.biClrUsed; j++)
{
- table_B[j] = getc(IN);
- table_G[j] = getc(IN);
- table_R[j] = getc(IN);
+ table_B[j] = (unsigned char)getc(IN);
+ table_G[j] = (unsigned char)getc(IN);
+ table_R[j] = (unsigned char)getc(IN);
getc(IN);
has_color +=
!(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));
- 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)
{
index = 0;
@@ -680,156 +743,163 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
}/* RGB8 */
else
if (Info_h.biBitCount == 8 && Info_h.biCompression == 1)//RLE8
- {
- unsigned char *pix, *beyond;
- unsigned int *gray, *red, *green, *blue;
- unsigned int x, y, max;
- int i, c, c1;
- unsigned char uc;
-
- if(Info_h.biClrUsed == 0) Info_h.biClrUsed = 256;
- else
- if(Info_h.biClrUsed > 256) Info_h.biClrUsed = 256;
-
- table_R = (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));
-
- has_color = 0;
- for (j = 0; j < Info_h.biClrUsed; j++)
- {
- table_B[j] = getc(IN);
- table_G[j] = getc(IN);
- table_R[j] = getc(IN);
- getc(IN);
- has_color +=
- !(table_R[j] == table_G[j] && table_R[j] == table_B[j]);
+ {
+ unsigned char *pix, *beyond;
+ int *gray, *red, *green, *blue;
+ unsigned int x, y, max;
+ int i, c, c1;
+ unsigned char uc;
+
+ if (Info_h.biClrUsed == 0)
+ Info_h.biClrUsed = 256;
+ else if (Info_h.biClrUsed > 256)
+ Info_h.biClrUsed = 256;
+
+ table_R = (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));
+
+ has_color = 0;
+ for (j = 0; j < Info_h.biClrUsed; j++)
+ {
+ table_B[j] = (unsigned char)getc(IN);
+ table_G[j] = (unsigned char)getc(IN);
+ table_R[j] = (unsigned char)getc(IN);
+ getc(IN);
+ has_color += !(table_R[j] == table_G[j] && table_R[j] == table_B[j]);
+ }
- }
- if(has_color) gray_scale = 0;
+ if (has_color)
+ gray_scale = 0;
- numcomps = gray_scale ? 1 : 3;
- color_space = gray_scale ? CLRSPC_GRAY : CLRSPC_SRGB;
- /* initialize image components */
- memset(&cmptparm[0], 0, 3 * sizeof(opj_image_cmptparm_t));
- for(i = 0; i < numcomps; i++)
- {
- cmptparm[i].prec = 8;
- cmptparm[i].bpp = 8;
- cmptparm[i].sgnd = 0;
- cmptparm[i].dx = subsampling_dx;
- cmptparm[i].dy = subsampling_dy;
- cmptparm[i].w = w;
- cmptparm[i].h = h;
- }
- /* create the image */
- image = opj_image_create(numcomps, &cmptparm[0], color_space);
- if(!image)
- {
- fclose(IN);
- free(table_R); free(table_G); free(table_B);
- return NULL;
- }
+ numcomps = gray_scale ? 1 : 3;
+ color_space = gray_scale ? CLRSPC_GRAY : CLRSPC_SRGB;
+ /* initialize image components */
+ memset(&cmptparm[0], 0, 3 * sizeof(opj_image_cmptparm_t));
+ for (i = 0; i < numcomps; i++)
+ {
+ cmptparm[i].prec = 8;
+ cmptparm[i].bpp = 8;
+ cmptparm[i].sgnd = 0;
+ cmptparm[i].dx = subsampling_dx;
+ cmptparm[i].dy = subsampling_dy;
+ cmptparm[i].w = w;
+ cmptparm[i].h = h;
+ }
+ /* create the image */
+ image = opj_image_create(numcomps, &cmptparm[0], color_space);
+ if (!image)
+ {
+ fclose(IN);
+ free(table_R);
+ free(table_G);
+ free(table_B);
+ return NULL;
+ }
- /* set image offset and reference grid */
- image->x0 = parameters->image_offset_x0;
- image->y0 = parameters->image_offset_y0;
- image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : image->x0 + (w - 1) * subsampling_dx + 1;
- image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : image->y0 + (h - 1) * subsampling_dy + 1;
+ /* set image offset and reference grid */
+ image->x0 = parameters->image_offset_x0;
+ image->y0 = parameters->image_offset_y0;
+ image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : image->x0 + (w
+ - 1) * subsampling_dx + 1;
+ image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : image->y0 + (h
+ - 1) * subsampling_dy + 1;
- /* 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);
+ /* set image data */
- W = Info_h.biWidth;
- H = Info_h.biHeight;
- RGB = (unsigned char *)calloc(1, W * H * sizeof(unsigned char));
- beyond = RGB + W * H;
- pix = beyond - W;
- x = y = 0;
+ /* Place the cursor at the beginning of the image information */
+ fseek(IN, 0, SEEK_SET);
+ fseek(IN, File_h.bfOffBits, SEEK_SET);
- while(y < H)
- {
- c = getc(IN);
+ W = Info_h.biWidth;
+ H = Info_h.biHeight;
+ RGB = (unsigned char *) calloc(1, W * H * sizeof(unsigned char));
+ beyond = RGB + W * H;
+ pix = beyond - W;
+ x = y = 0;
- if (c)
- {
- c1 = getc(IN);
+ while (y < H)
+ {
+ c = getc(IN);
- for (i = 0; i < c && x < W && pix < beyond; i++, x++, pix++)
- *pix = c1;
- }
- else
- {
- c = getc(IN);
+ if (c)
+ {
+ c1 = 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 = c1;
- }
- if(c & 1) /* skip padding byte */
- getc(IN);
- }
- }
- }/* while() */
+ for (i = 0; i < c && x < W && pix < beyond; i++, x++, pix++)
+ *pix = (unsigned char)c1;
+ }
+ else
+ {
+ c = getc(IN);
- if (gray_scale)
- {
- int *gray;
+ 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() */
- gray = image->comps[0].data;
- pix = RGB;
- max = W * H;
+ if (gray_scale)
+ {
+ gray = image->comps[0].data;
+ pix = RGB;
+ max = W * H;
- while(max--)
- {
- uc = *pix++;
+ while (max--)
+ {
+ uc = *pix++;
- *gray++ = table_R[uc];
- }
- }
- else
- {
- int *red, *green, *blue;
+ *gray++ = table_R[uc];
+ }
+ }
+ else
+ {
+ //int *red, *green, *blue;
- red = image->comps[0].data;
- green = image->comps[1].data;
- blue = image->comps[2].data;
- pix = RGB;
- max = W * H;
+ red = image->comps[0].data;
+ green = image->comps[1].data;
+ blue = image->comps[2].data;
+ pix = RGB;
+ max = W * H;
- while(max--)
- {
- uc = *pix++;
+ 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 */
+ *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
{
fprintf(stderr,
@@ -1007,7 +1077,6 @@ int imagetobmp(opj_image_t * image, const char *outfile) {
}
for (i = 0; i < w * h; i++) {
- unsigned char rc;
int r;
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 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;
}
unsigned short readushort(FILE * f, int bigendian)
{
unsigned char c1, c2;
- fread(&c1, 1, 1, f);
- fread(&c2, 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;
+ }
+ if ( !fread(&c2, 1, 1, f) )
+ {
+ fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
+ return 0;
+ }
if (bigendian)
return (c1 << 8) + c2;
else
@@ -1056,10 +1137,26 @@ unsigned short readushort(FILE * f, int bigendian)
unsigned int readuint(FILE * f, int bigendian)
{
unsigned char c1, c2, c3, c4;
- fread(&c1, 1, 1, f);
- fread(&c2, 1, 1, f);
- fread(&c3, 1, 1, f);
- fread(&c4, 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;
+ }
+ 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)
return (c1 << 24) + (c2 << 16) + (c3 << 8) + c4;
else
@@ -1095,8 +1192,11 @@ opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters) {
}
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;
sign='+';
while (signtmp[i]!='\0') {
@@ -1200,11 +1300,11 @@ int imagetopgx(opj_image_t * image, const char *outfile) {
name = (char*)malloc(total+1);
}
strncpy(name, outfile, dotpos);
- if (image->numcomps > 1) {
- sprintf(name+dotpos, "-%d.pgx", compno);
- } else {
+ //if (image->numcomps > 1) {
+ sprintf(name+dotpos, "_%d.pgx", compno);
+ /*} else {
strcpy(name+dotpos, ".pgx");
- }
+ }*/
fdest = fopen(name, "wb");
if (!fdest) {
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 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')
{
@@ -1563,7 +1667,8 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters) {
for(compno = 0; compno < numcomps; compno++)
{
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;
}
@@ -1584,14 +1689,16 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters) {
{
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)
{
image->comps[compno].data[i] = c0;
}
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: */
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;
- 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);
}
@@ -1640,7 +1748,8 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters) {
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;
}
}
@@ -1863,7 +1972,6 @@ int imagetotif(opj_image_t * image, const char *outfile)
int width, height, imgsize;
int bps,index,adjust, sgnd;
int ushift, dshift, has_alpha, force16;
- unsigned int last_i=0;
TIFF *tif;
tdata_t buf;
tstrip_t strip;
@@ -1924,10 +2032,10 @@ int imagetotif(opj_image_t * image, const char *outfile)
for(strip = 0; strip < TIFFNumberOfStrips(tif); strip++)
{
unsigned char *dat8;
- tsize_t i, ssize;
+ tsize_t i, ssize, last_i = 0;
+ int step, restx;
ssize = TIFFStripSize(tif);
dat8 = (unsigned char*)buf;
- int step, restx;
if(bps == 8)
{
diff --git a/applications/codec/image_to_j2k.c b/applications/codec/image_to_j2k.c
index 1e1cfbf4..92353970 100644
--- a/applications/codec/image_to_j2k.c
+++ b/applications/codec/image_to_j2k.c
@@ -82,7 +82,7 @@ typedef struct img_folder{
float *rates;
}img_fol_t;
-void encode_help_display() {
+void encode_help_display(void) {
fprintf(stdout,"HELP for image_to_j2k\n----\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,
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[]={
{"cinema2K",REQ_ARG, NULL ,'w'},
{"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;
raw_cp->rawWidth = 0;
- while (1) {
- int c = getopt_long(argc, argv, optlist,long_option,totlen);
+ do{
+ c = getopt_long(argc, argv, optlist,long_option,totlen);
if (c == -1)
break;
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");
return 1;
}
- }
+ }while(c != -1);
/* check for possible errors */
if (parameters->cp_cinema){
@@ -1482,7 +1482,7 @@ int main(int argc, char **argv) {
opj_image_t *image = NULL;
int i,num_images;
int imageno;
- dircnt_t *dirptr;
+ dircnt_t *dirptr = NULL;
raw_cparameters_t raw_cp;
opj_codestream_info_t cstr_info; /* Codestream information structure */
char indexfilename[OPJ_PATH_LEN]; /* index file name */
diff --git a/applications/codec/j2k_dump.c b/applications/codec/j2k_dump.c
index 543a7d79..02f8316c 100644
--- a/applications/codec/j2k_dump.c
+++ b/applications/codec/j2k_dump.c
@@ -73,7 +73,7 @@ typedef struct img_folder{
}img_fol_t;
-void decode_help_display() {
+void decode_help_display(void) {
fprintf(stdout,"HELP for j2k_dump\n----\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," Currently accepts J2K-files, JP2-files and JPT-files. The file type\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");
}
@@ -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) {
/* parse the command line */
- int totlen;
+ int totlen, c;
option_t long_option[]={
{"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);
img_fol->set_out_format = 0;
- while (1) {
- int c = getopt_long(argc, argv,optlist,long_option,totlen);
+ do {
+ c = getopt_long(argc, argv,optlist,long_option,totlen);
if (c == -1)
break;
switch (c) {
@@ -223,6 +229,15 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
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;
/* ----------------------------------------------------- */
@@ -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);
break;
}
- }
+ }while(c != -1);
/* check for possible errors */
if(img_fol->set_imgdir==1){
@@ -306,7 +321,7 @@ int main(int argc, char *argv[])
img_fol_t img_fol;
opj_event_mgr_t event_mgr; /* event manager */
opj_image_t *image = NULL;
- FILE *fsrc = NULL;
+ FILE *fsrc = NULL, *fout = NULL;
unsigned char *src = NULL;
int file_length;
int num_images;
@@ -362,6 +377,19 @@ int main(int argc, char *argv[])
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*/
for(imageno = 0; imageno < num_images ; imageno++)
{
@@ -386,7 +414,13 @@ int main(int argc, char *argv[])
file_length = ftell(fsrc);
fseek(fsrc, 0, SEEK_SET);
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);
/* decode the code-stream */
@@ -421,17 +455,17 @@ int main(int argc, char *argv[])
return 1;
}
/* dump image */
- j2k_dump_image(stdout, image);
+ j2k_dump_image(fout, image);
/* 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 */
opj_cio_close(cio);
/* Write the index to disk */
if (*indexfilename) {
- char bSuccess;
+ opj_bool bSuccess;
bSuccess = write_index_file(&cstr_info, indexfilename);
if (bSuccess) {
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;
}
- j2k_dump_image(stdout, image);
+ j2k_dump_image(fout, image);
/* 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 */
opj_cio_close(cio);
/* Write the index to disk */
if (*indexfilename) {
- char bSuccess;
+ opj_bool bSuccess;
bSuccess = write_index_file(&cstr_info, indexfilename);
if (bSuccess) {
fprintf(stderr, "Failed to output index file\n");
@@ -524,7 +558,7 @@ int main(int argc, char *argv[])
/* Write the index to disk */
if (*indexfilename) {
- char bSuccess;
+ opj_bool bSuccess;
bSuccess = write_index_file(&cstr_info, indexfilename);
if (bSuccess) {
fprintf(stderr, "Failed to output index file\n");
@@ -554,6 +588,8 @@ int main(int argc, char *argv[])
}
+ fclose(fout);
+
return EXIT_SUCCESS;
}
diff --git a/applications/codec/j2k_to_image.c b/applications/codec/j2k_to_image.c
index bc9ef7dd..2b421369 100644
--- a/applications/codec/j2k_to_image.c
+++ b/applications/codec/j2k_to_image.c
@@ -85,7 +85,7 @@ typedef struct img_folder{
}img_fol_t;
-void decode_help_display() {
+void decode_help_display(void) {
fprintf(stdout,"HELP for j2k_to_image\n----\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) {
/* parse the command line */
- int totlen;
+ int totlen, c;
option_t long_option[]={
{"ImgDir",REQ_ARG, NULL ,'y'},
{"OutFor",REQ_ARG, NULL ,'O'},
@@ -253,8 +253,8 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
"h" ;
totlen=sizeof(long_option);
img_fol->set_out_format = 0;
- while (1) {
- int c = getopt_long(argc, argv,optlist,long_option,totlen);
+ do {
+ c = getopt_long(argc, argv,optlist,long_option,totlen);
if (c == -1)
break;
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);
break;
}
- }
+ }while(c != -1);
/* check for possible errors */
if(img_fol->set_imgdir==1){
@@ -521,7 +521,7 @@ int main(int argc, char **argv) {
int file_length;
int num_images;
int i,imageno;
- dircnt_t *dirptr;
+ dircnt_t *dirptr = NULL;
opj_dinfo_t* dinfo = NULL; /* handle to a decompressor */
opj_cio_t *cio = NULL;
opj_codestream_info_t cstr_info; /* Codestream information structure */
@@ -595,7 +595,13 @@ int main(int argc, char **argv) {
file_length = ftell(fsrc);
fseek(fsrc, 0, SEEK_SET);
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);
/* decode the code-stream */
@@ -635,7 +641,7 @@ int main(int argc, char **argv) {
/* Write the index to disk */
if (*indexfilename) {
- char bSuccess;
+ opj_bool bSuccess;
bSuccess = write_index_file(&cstr_info, indexfilename);
if (bSuccess) {
fprintf(stderr, "Failed to output index file\n");
@@ -677,7 +683,7 @@ int main(int argc, char **argv) {
/* Write the index to disk */
if (*indexfilename) {
- char bSuccess;
+ opj_bool bSuccess;
bSuccess = write_index_file(&cstr_info, indexfilename);
if (bSuccess) {
fprintf(stderr, "Failed to output index file\n");
@@ -719,7 +725,7 @@ int main(int argc, char **argv) {
/* Write the index to disk */
if (*indexfilename) {
- char bSuccess;
+ opj_bool bSuccess;
bSuccess = write_index_file(&cstr_info, indexfilename);
if (bSuccess) {
fprintf(stderr, "Failed to output index file\n");
diff --git a/applications/common/getopt.c b/applications/common/getopt.c
index 5e444d39..3edd969d 100644
--- a/applications/common/getopt.c
+++ b/applications/common/getopt.c
@@ -60,7 +60,7 @@ typedef struct option
#define 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 reset_options_reading(void) {
opterr = 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,
-struct option *longopts, int totlen) {
+const struct option *longopts, int totlen) {
static int lastidx,lastofs;
char *tmp;
int i,len;
diff --git a/applications/common/getopt.h b/applications/common/getopt.h
index 779fe470..1b32d2b6 100644
--- a/applications/common/getopt.h
+++ b/applications/common/getopt.h
@@ -24,6 +24,6 @@ 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();
+extern void reset_options_reading(void);
#endif /* _GETOPT_H_ */
diff --git a/applications/jpip/opj_client/opj_dec_server/opj_dec_server.c b/applications/jpip/opj_client/opj_dec_server/opj_dec_server.c
index e2709797..895ade5c 100644
--- a/applications/jpip/opj_client/opj_dec_server/opj_dec_server.c
+++ b/applications/jpip/opj_client/opj_dec_server/opj_dec_server.c
@@ -144,7 +144,7 @@ int main(int argc, char *argv[]){
int listening_socket = open_listeningsocket();
- int addrlen = sizeof(peer_sin);
+ unsigned int addrlen = sizeof(peer_sin);
cachelist_param_t *cachelist = gene_cachelist();
diff --git a/applications/mj2/CMakeLists.txt b/applications/mj2/CMakeLists.txt
index 7b365678..4a43886f 100644
--- a/applications/mj2/CMakeLists.txt
+++ b/applications/mj2/CMakeLists.txt
@@ -46,9 +46,8 @@ ADD_EXECUTABLE(frames_to_mj2
${OPJ_SRCS}
${MJ2_SRCS}
)
-IF(LCMS_FOUND OR LCMS2_FOUND)
- TARGET_LINK_LIBRARIES(frames_to_mj2 ${LCMS_LIBNAME})
-ENDIF(LCMS_FOUND OR LCMS2_FOUND)
+TARGET_LINK_LIBRARIES(frames_to_mj2 ${LCMS_LIBNAME})
+
IF(UNIX)
TARGET_LINK_LIBRARIES(frames_to_mj2 m)
ENDIF(UNIX)
@@ -60,9 +59,8 @@ ADD_EXECUTABLE(mj2_to_frames
${MJ2_SRCS}
${OPENJPEG_SOURCE_DIR}/applications/common/color.c
)
-IF(LCMS_FOUND OR LCMS2_FOUND)
- TARGET_LINK_LIBRARIES(mj2_to_frames ${LCMS_LIBNAME})
-ENDIF(LCMS_FOUND OR LCMS2_FOUND)
+TARGET_LINK_LIBRARIES(mj2_to_frames ${LCMS_LIBNAME})
+
IF(UNIX)
TARGET_LINK_LIBRARIES(mj2_to_frames m)
ENDIF(UNIX)
@@ -72,9 +70,8 @@ ADD_EXECUTABLE(extract_j2k_from_mj2
${OPJ_SRCS}
${MJ2_SRCS}
)
-IF(LCMS_FOUND OR LCMS2_FOUND)
- TARGET_LINK_LIBRARIES(extract_j2k_from_mj2 ${LCMS_LIBNAME})
-ENDIF(LCMS_FOUND OR LCMS2_FOUND)
+TARGET_LINK_LIBRARIES(extract_j2k_from_mj2 ${LCMS_LIBNAME})
+
IF(UNIX)
TARGET_LINK_LIBRARIES(extract_j2k_from_mj2 m)
ENDIF(UNIX)
@@ -84,9 +81,8 @@ ADD_EXECUTABLE(wrap_j2k_in_mj2
${OPJ_SRCS}
${MJ2_SRCS}
)
-IF(LCMS_FOUND OR LCMS2_FOUND)
- TARGET_LINK_LIBRARIES(wrap_j2k_in_mj2 ${LCMS_LIBNAME})
-ENDIF(LCMS_FOUND OR LCMS2_FOUND)
+TARGET_LINK_LIBRARIES(wrap_j2k_in_mj2 ${LCMS_LIBNAME})
+
IF(UNIX)
TARGET_LINK_LIBRARIES(wrap_j2k_in_mj2 m)
ENDIF(UNIX)
diff --git a/applications/mj2/frames_to_mj2.c b/applications/mj2/frames_to_mj2.c
index 4e89956f..1e0d29a9 100644
--- a/applications/mj2/frames_to_mj2.c
+++ b/applications/mj2/frames_to_mj2.c
@@ -199,29 +199,29 @@ void help_display()
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'
&& progression[2] == 'C' && progression[3] == 'P') {
- return 0;
+ return LRCP;
} else {
if (progression[0] == 'R' && progression[1] == 'L'
&& progression[2] == 'C' && progression[3] == 'P') {
- return 1;
+ return RLCP;
} else {
if (progression[0] == 'R' && progression[1] == 'P'
&& progression[2] == 'C' && progression[3] == 'L') {
- return 2;
+ return RPCL;
} else {
if (progression[0] == 'P' && progression[1] == 'C'
&& progression[2] == 'R' && progression[3] == 'L') {
- return 3;
+ return PCRL;
} else {
if (progression[0] == 'C' && progression[1] == 'P'
&& progression[2] == 'R' && progression[3] == 'L') {
- return 4;
+ return CPRL;
} else {
- return -1;
+ return PROG_UNKNOWN;
}
}
}
@@ -475,9 +475,9 @@ int main(int argc, char **argv)
/* ----------------------------------------------------- */
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);
if (j2k_parameters->prog_order == -1) {
fprintf(stderr, "Unrecognized progression order "
@@ -696,7 +696,7 @@ int main(int argc, char **argv)
movie->tk[0].num_samples =
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;
}
diff --git a/applications/mj2/mj2.c b/applications/mj2/mj2.c
index dfab1917..fe48415b 100644
--- a/applications/mj2/mj2.c
+++ b/applications/mj2/mj2.c
@@ -240,9 +240,7 @@ void mj2_tts_decompact(mj2_tk_t * tk)
*/
void mj2_stsc_decompact(mj2_tk_t * tk)
{
- int j, i;
- unsigned int k;
- int sampleno=0;
+ unsigned int i, j, k, sampleno = 0;
if (tk->num_samplestochunk == 1) {
tk->num_chunks =
@@ -283,10 +281,8 @@ void mj2_stsc_decompact(mj2_tk_t * tk)
*/
void mj2_stco_decompact(mj2_tk_t * tk)
{
- int j;
- unsigned int i;
- int k = 0;
- int intra_chunk_offset;
+ unsigned int i, j, k = 0;
+ unsigned int intra_chunk_offset;
for (i = 0; i < tk->num_chunks; i++) {
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)
{
- int i;
+ unsigned int i;
mj2_box_t box;
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 i;
+ unsigned int i;
mj2_box_t box;
mj2_read_boxhdr(&box, cio); /* Box Size */
diff --git a/applications/mj2/mj2.h b/applications/mj2/mj2.h
index d4f27451..2e3d0b15 100644
--- a/applications/mj2/mj2.h
+++ b/applications/mj2/mj2.h
@@ -103,7 +103,7 @@ typedef struct mj2_tts {
Chunk
*/
typedef struct mj2_chunk {
- int num_samples;
+ unsigned int num_samples;
int sample_descr_idx;
int offset;
} mj2_chunk_t;
@@ -112,8 +112,8 @@ typedef struct mj2_chunk {
Sample to chunk
*/
typedef struct mj2_sampletochunk {
- int first_chunk;
- int samples_per_chunk;
+ unsigned int first_chunk;
+ unsigned int samples_per_chunk;
int sample_descr_idx;
} mj2_sampletochunk_t;
@@ -205,7 +205,7 @@ typedef struct mj2_tk {
mj2_tts_t *tts;
unsigned int num_chunks;
mj2_chunk_t *chunk;
- int num_samplestochunk;
+ unsigned int num_samplestochunk;
mj2_sampletochunk_t *sampletochunk;
char *name;
opj_jp2_t jp2_struct;
diff --git a/applications/mj2/mj2_convert.c b/applications/mj2/mj2_convert.c
index 0f2d975d..3d842883 100644
--- a/applications/mj2/mj2_convert.c
+++ b/applications/mj2/mj2_convert.c
@@ -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;
- long end_of_f;
+ unsigned int prec_size;
+ long end_of_f, frame_size;
FILE *f;
f = fopen(infile,"rb");
if (!f) {
fprintf(stderr, "failed to open %s for reading\n",infile);
- return -1;
+ return 0;
}
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;
fseek(f, 0, SEEK_END);
@@ -60,13 +60,11 @@ int yuv_num_frames(mj2_tk_t * tk, char *infile)
fprintf(stderr,
"YUV does not contains any frame of %d x %d size\n", tk->w,
tk->h);
- return -1;
+ return 0;
}
+ fclose(f);
- numimages = end_of_f / frame_size; /* Calculate number of images */
- fclose(f);
-
- return numimages;
+ return (unsigned int)(end_of_f / frame_size);
}
// -----------------------
diff --git a/applications/mj2/mj2_convert.h b/applications/mj2/mj2_convert.h
index 78e6c470..19ba99f7 100644
--- a/applications/mj2/mj2_convert.h
+++ b/applications/mj2/mj2_convert.h
@@ -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);
-int yuv_num_frames(mj2_tk_t * tk, char *infile);
+unsigned int yuv_num_frames(mj2_tk_t * tk, char *infile);
#endif