Compare commits

..

70 Commits

Author SHA1 Message Date
Antonin Descampe
8ddbe4dc4d [wg1n6848] added CHANGES file 2014-10-23 10:45:06 +00:00
Antonin Descampe
0ac0b3d823 [newtag] created wg1n6848 tag corresponding to submitted package for 15444-5 AMD2 additional reference software for JPEG 2000 Part-1 2014-10-23 10:40:45 +00:00
Antonin Descampe
09fb8b6989 [trunk] add Aaron Boxer as contributor 2014-10-22 23:01:04 +00:00
Antonin Descampe
9e6c62199a [trunk] re-arrange contributors alphabetically and add Matthieu Darbois 2014-10-22 22:59:35 +00:00
Antonin Descampe
d47f7a249d [trunk] workaround to make MD5 work under valgrind on MacOSX (fixes issue 410) 2014-10-22 22:52:01 +00:00
Antonin Descampe
7280263988 [trunk] Added new non-regression tests from foxit issues
Update issue 415
2014-10-22 22:38:55 +00:00
Antonin Descampe
3e1fad2da4 [trunk] resets resno_decoded for each tile (fixes issue 399) 2014-10-22 13:16:35 +00:00
Antonin Descampe
d72940c56b [trunk] resets code-blocks reused for other tiles than the first one (fixes issue 418) 2014-10-22 13:16:12 +00:00
Antonin Descampe
ad4fad0965 [trunk] add a check on mandatory headers in Main Header (fixes issue 408) 2014-10-22 10:30:35 +00:00
Antonin Descampe
aff9cb39ed [trunk] fixed invalid member values from opj_read_header or opj_decode (fixes issue 411) 2014-10-21 15:22:22 +00:00
Antonin Descampe
0a3f234df7 [trunk] verify channel definitions is complete when cdef is present (fixes issue 397) 2014-10-21 12:54:08 +00:00
Antonin Descampe
efb70af001 [trunk] add a check on the number of resolution passed to cmdline (fixes issue 352) 2014-10-21 12:47:48 +00:00
Antonin Descampe
e65303b903 [trunk] added check on JP2_IHDR box (fixes issue 364) 2014-10-21 12:35:16 +00:00
Antonin Descampe
413de4fbfa [trunk] add a check on Zppm value in PPM markers (fixes issue 393) 2014-10-21 12:27:58 +00:00
Antonin Descampe
984351f86f [trunk] Add option to call dsymutil on built binaries (fixes issue 409) 2014-10-15 10:24:49 +00:00
Antonin Descampe
f8796711e8 [trunk] add a check on progression order (fixes issue 413) 2014-10-15 10:14:54 +00:00
Antonin Descampe
0b540067b1 [trunk] add a check for illegal SCod value (fixes issue 400) 2014-10-15 08:48:19 +00:00
Antonin Descampe
3df347eded [trunk] additional checks for marker size inconsistency (fixes issue 363) 2014-10-14 15:15:09 +00:00
Antonin Descampe
eb7c6d295a [trunk] fixed potential negative size params (fixes issue 390) 2014-10-06 21:05:32 +00:00
Antonin Descampe
f126eb0d41 [trunk] added box length inconsistency check
Update issue 364

issue364-38.patch applied. Thanks Matthieu.
2014-10-06 21:05:27 +00:00
Antonin Descampe
7256e43c48 [trunk] fixed PDF crash in Chrome (fixes issue 362) 2014-10-06 21:05:21 +00:00
Antonin Descampe
a0a3af1dee [trunk] removed illegal character in comment 2014-10-03 19:52:20 +00:00
Antonin Descampe
48832d944f [trunk]fixes buffer overflow in t2.c
Update issue 390
Summary: check for negative-size params in code
Patch from Matthieu applied. Left open to apply this to other places in
code.
2014-10-03 10:15:28 +00:00
Antonin Descampe
06bd61b571 [trunk] c++-style comment removed (fixes issue 407) 2014-10-02 07:44:53 +00:00
Antonin Descampe
a1c754c737 [trunk] fixed warning from r2891 2014-10-01 12:11:43 +00:00
Antonin Descampe
fef1276901 [trunk] fixed bad use of case statement (fixes issue 381) 2014-09-30 12:19:13 +00:00
Antonin Descampe
45f33cdbd6 [trunk] check possible overflow on size in opj_t2_read_packet_data
Update issue 390
Labels: Priority-Critical
Should be rechecked with ASan and pdfium
2014-09-30 10:07:09 +00:00
Antonin Descampe
1acfa211ae [trunk] fixes heap-buffer-overflow in parse_cmdline_encoder
Fixes issue 403
Thanks Matthieu
2014-09-30 09:48:26 +00:00
Antonin Descampe
2f3fd1194e [trunk] prevent overflow in opj_t2_read_packet_header (update issue 389) 2014-09-30 09:26:44 +00:00
Antonin Descampe
f08af3ed82 [trunk] Ensure cblk->data pointer is correctly initialized (updates issue 391). Still need to check if it does not fail anymore with ASan. 2014-09-29 12:03:50 +00:00
Antonin Descampe
2720a1a405 [trunk] fixed tile numbering in output message (fixes issue 370) 2014-09-29 12:03:36 +00:00
Mathieu Malaterre
31fd8d3fe8 trunk: extend support for pdf2jp2 2014-09-19 15:48:48 +00:00
Antonin Descampe
6868ee373e added memory allocation checks (fixes issue 355) 2014-09-19 10:26:35 +00:00
Antonin Descampe
b9a247b559 fixes install name id on OSX builds (fixes issue 367) 2014-09-19 09:30:12 +00:00
Antonin Descampe
50a205d20f [trunk] improve memory management (fixes issue 359) 2014-09-16 15:48:04 +00:00
Antonin Descampe
b0072bf658 [trunk] allow compilation with MinGW32 (fixes issue 361) 2014-09-16 15:38:11 +00:00
Antonin Descampe
2c810567dd [trunk] Changed error to warning when no EOC found in codestream (fixes
issue 366)
2014-07-14 07:42:50 +00:00
Antonin Descampe
0a1a29a7fe [trunk] replaced malloc with opj_malloc. (Fixes issue 368). 2014-07-03 16:05:56 +00:00
Antonin Descampe
7d21871ed8 [trunk] fixes issue #357. MCT is automatically disabled when
subsamppling is detected.
2014-07-03 09:15:13 +00:00
Antonin Descampe
a38b97fae0 [trunk] moved comment marker setup from opj_compress to the library 2014-07-01 13:51:55 +00:00
Antonin Descampe
45313a8dfa [trunk] fixed warning in j2k.c about sign conversion 2014-04-28 09:38:44 +00:00
Mathieu Malaterre
b08135e7c1 [trunk] Finalize API for openjpeg 2.1
public header will only contains minimal information: major, minor and build version
Prefix has been changed from OPENJPEG to OPJ for consistency
SOVERSION has been removed from header (ABI vs API info)
OPJ_VERSION string has been removed, since it is accessible already (PACKAGE_VERSION)
Fixes issue 342
2014-04-28 09:17:31 +00:00
Mathieu Malaterre
4bac8488df [trunk] Properly handle failure to compress (remove file)
Fixes issue 323
2014-04-28 07:54:33 +00:00
Mathieu Malaterre
de04302c15 [trunk] Missing endianess setting
Fixes issue 337
2014-04-28 07:44:39 +00:00
Mathieu Malaterre
997758f91c [trunk] properly handle pkg-config on non-UNIX hosts
Fixes issue 340
2014-04-28 07:34:26 +00:00
Mathieu Malaterre
763214f7c0 [trunk] Provide #ifdef blockers for OpenJPEG Version
Fixes issue 342
2014-04-28 07:32:35 +00:00
Antonin Descampe
77e8dad503 [trunk] fixed typo in NEWS 2014-04-27 21:31:32 +00:00
Antonin Descampe
1758445a75 [trunk] updated NEWS for 2.1.0 2014-04-25 09:22:49 +00:00
Mathieu Malaterre
7a77a8047d [trunk] Make sure OpenJPIP compiles on WIN32 2014-04-24 11:24:56 +00:00
Antonin Descampe
d8767cbcb7 [trunk] fixed reference to opj_stream_set_user_data_v3 in jpip sources. 2014-04-24 08:51:29 +00:00
Antonin Descampe
7924d3a456 [trunk]removed '-x' option for index file as long as it's broken 2014-04-23 15:19:57 +00:00
Antonin Descampe
ec84bafcd8 [trunk]re-formatted help display in executables 2014-04-23 14:09:20 +00:00
Antonin Descampe
08c09b74cf [trunk]formatted some messages. Removed -version option to disambiguate
with -v(erbose) option, added version info in help display
2014-04-23 09:12:30 +00:00
Antonin Descampe
7aece5e8e7 [trunk]Replaced deprecated opj_stream_set_user_data function from API
with its 'v3' version, and removed all other 'v3' suffixes from API.
2014-04-23 07:46:11 +00:00
Antonin Descampe
8d93eae64a [trunk] fixed some warning and errors formatting and add a '-version'
option to opj_compress and opj_decompress binaries
2014-04-22 21:22:49 +00:00
Antonin Descampe
9a3d660d1b [trunk] fixed warning related to r2837 and move new field at the end of
parameters structure.
2014-04-17 09:54:38 +00:00
Antonin Descampe
7199d9b5d3 [trunk] refactoring of rsiz, profiles, and extensions management 2014-04-17 09:31:37 +00:00
Antonin Descampe
d19a4ab676 [trunk] updated copyright and added copyright notice required by ISO, in each file; updated AUTHORS, NEWS 2014-04-03 15:30:57 +00:00
Antonin Descampe
f105cb5471 [trunk] removed debug message in CMakeLists.txt 2014-04-02 16:37:07 +00:00
Antonin Descampe
4db4198722 [trunk] fixed a bug triggering SEGFAULT on debug mode (uninitialized
structure)
2014-04-02 16:25:40 +00:00
Mathieu Malaterre
616a3345c4 [trunk] Properly copy/paste code from the autotools
gcc correctly fails compiling this code, I needed to move the code outside the main function to get the error. This actually match the autotools (incorrect) code. We'll see how they fix this code in future release.
This make the code compatible with previous openjpeg version and remove C99 requirement.
Fixes issue 316
2014-03-27 15:07:58 +00:00
Mathieu Malaterre
1f8d84a562 [trunk] Make sure to use long long (this is not C89). However this should be ok on most compilers nowadays
Update issue 316
2014-03-26 16:20:13 +00:00
Antonin Descampe
a54d757a3e [trunk] fixed warnings triggered on linux related to r2802 2014-03-26 15:17:17 +00:00
Mathieu Malaterre
b5eb374fb9 [trunk] Run test suite on issue 316 dataset
Update issue 316
2014-03-26 15:16:24 +00:00
Antonin Descampe
f1d69068c7 [trunk] add ability in opj_compress to input subsampled images through
'-F' (aka raw option). Let the user input raw images with 444, 422, 420
(etc) subsampling. To be used in conjunction with '-mct 0' option to
compress subsampled YCC images.
2014-03-26 14:26:49 +00:00
Mathieu Malaterre
ee130e2306 [trunk] Add small utilities to extract JP2 files from PDF 2014-03-26 11:52:01 +00:00
Mathieu Malaterre
9ba6bc6042 [trunk] Make sure to test value not pointer
Update issue 302
2014-03-25 16:34:59 +00:00
Antonin Descampe
5e1a0fad08 [trunk] fixed bug related to r2791 2014-03-25 15:35:33 +00:00
Mathieu Malaterre
c05118dc49 [trunk] Add sentinel in case list empty.
I was getting a cmake error `list sub-command REMOVE_ITEM requires list to be present`
2014-03-25 15:29:19 +00:00
Mathieu Malaterre
1adf89d5d2 [trunk] Import change from 2.0 branch 2014-03-25 15:21:53 +00:00
45 changed files with 11156 additions and 999 deletions

9956
CHANGES

File diff suppressed because it is too large Load Diff

View File

@@ -29,8 +29,8 @@ include_regular_expression("^.*$")
#-----------------------------------------------------------------------------
# OPENJPEG version number, useful for packaging and doxygen doc:
set(OPENJPEG_VERSION_MAJOR 2)
set(OPENJPEG_VERSION_MINOR 0)
set(OPENJPEG_VERSION_BUILD 1)
set(OPENJPEG_VERSION_MINOR 1)
set(OPENJPEG_VERSION_BUILD 0)
set(OPENJPEG_VERSION
"${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
set(PACKAGE_VERSION
@@ -48,6 +48,7 @@ set(PACKAGE_VERSION
# 1.5.1 | 5
# 2.0 | 6
# 2.0.1 | 6
# 2.1 | 7
# above is the recommendation by the OPJ team. If you really need to override this default,
# you can specify your own OPENJPEG_SOVERSION at cmake configuration time:
# cmake -DOPENJPEG_SOVERSION:STRING=42 /path/to/openjpeg
@@ -94,6 +95,8 @@ endif()
# --------------------------------------------------------------------------
# Install directories
# Build DOCUMENTATION (not in ALL target and only if Doxygen is found)
option(BUILD_DOC "Build the HTML documentation (with doxygen if available)." OFF)
string(TOLOWER ${PROJECT_NAME} projectname)
set(OPENJPEG_INSTALL_SUBDIR "${projectname}-${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}")
@@ -118,6 +121,7 @@ if(NOT OPENJPEG_INSTALL_INCLUDE_DIR)
set(OPENJPEG_INSTALL_INCLUDE_DIR "include/${OPENJPEG_INSTALL_SUBDIR}")
endif()
if(BUILD_DOC)
if(NOT OPENJPEG_INSTALL_MAN_DIR)
set(OPENJPEG_INSTALL_MAN_DIR "share/man/")
endif()
@@ -125,6 +129,7 @@ endif()
if(NOT OPENJPEG_INSTALL_DOC_DIR)
set(OPENJPEG_INSTALL_DOC_DIR "share/doc/${OPENJPEG_INSTALL_SUBDIR}")
endif()
endif()
if(NOT OPENJPEG_INSTALL_JNI_DIR)
if(WIN32)
@@ -141,6 +146,11 @@ if(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
set(OPENJPEG_INSTALL_PACKAGE_DIR "${OPENJPEG_INSTALL_LIB_DIR}/${OPENJPEG_INSTALL_SUBDIR}")
endif()
if (APPLE)
list(APPEND OPENJPEG_LIBRARY_PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${OPENJPEG_INSTALL_LIB_DIR}")
option(OPJ_USE_DSYMUTIL "Call dsymutil on binaries after build." OFF)
endif()
#-----------------------------------------------------------------------------
# Big endian test:
include (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
@@ -264,8 +274,7 @@ configure_file(
)
#-----------------------------------------------------------------------------
# Build DOCUMENTATION (not in ALL target and only if Doxygen is found)
option(BUILD_DOC "Build the HTML documentation (with doxygen if available)." OFF)
# build documentation in doc subdir:
if(BUILD_DOC)
add_subdirectory(doc)
endif()
@@ -282,7 +291,7 @@ if(BUILD_TESTING)
# 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
PATHS $ENV{OPJ_DATA_ROOT} ${CMAKE_SOURCE_DIR}/../data
NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
)
@@ -307,16 +316,25 @@ install( FILES ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
#-----------------------------------------------------------------------------
# install CHANGES and LICENSE
if(BUILD_DOC)
if(EXISTS ${OPENJPEG_SOURCE_DIR}/CHANGES)
install(FILES CHANGES DESTINATION ${OPENJPEG_INSTALL_DOC_DIR})
endif()
install(FILES LICENSE DESTINATION ${OPENJPEG_INSTALL_DOC_DIR})
endif()
include (cmake/OpenJPEGCPack.cmake)
#-----------------------------------------------------------------------------
# pkgconfig support
# enabled by default on Unix, disabled by default on other platforms
if(UNIX)
option(BUILD_PKGCONFIG_FILES "Build and install pkg-config files" ON)
else()
option(BUILD_PKGCONFIG_FILES "Build and install pkg-config files" OFF)
endif()
if(BUILD_PKGCONFIG_FILES)
# install in lib and not share (see multi-arch note above)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/libopenjp2.pc.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc @ONLY)

53
NEWS
View File

@@ -2,23 +2,60 @@
OpenJPEG NEWS - user visible changes
====================================
Changes from OpenJPEG 2.0.0 to OpenJPEG 2.0.1
Changes from OpenJPEG 2.0.0 to OpenJPEG 2.X.X
----------------------------------------------
New Features:
* Digital Cinema profiles have been fixed and updated
* New option to disable MCT if needed
* New option to disable MCT if needed
* extended RAW support: it is now possible to input raw images
with subsampled color components (422, 420, etc)
with subsampled color components (422, 420, etc)
* New way to deal with profiles
API/ABI modifications: (see abi_compat_report in dev-utils/scripts)
API/ABI modifications: (see abi_compat_report_2.0.1.html in dev-utils/scripts)
* No changes, API/ABI fully compatible with 2.0.0
* Removed deprecated functions
- opj_stream_create_default_file_stream(FILE*,...)
- opj_stream_create_file_stream(FILE*,...)
- opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data)
* Added
- opj_stream_create_default_file_stream(char*,...)
- opj_stream_create_file_stream(char*,...)
- opj_stream_destroy(opj_stream_t*)
- opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data,
... opj_stream_free_user_data_fn p_function)
- JPEG 2000 profiles and Part-2 extensions defined through '#define'
* Changed
- 'alpha' field added to 'opj_image_comp' structure
- 'OPJ_CLRSPC_EYCC' added to enum COLOR_SPACE
- 'OPJ_CLRSPC_CMYK' added to enum COLOR_SPACE
- 'OPJ_CODEC_JPP' and 'OPJ_CODEC_JPX' added to CODEC_FORMAT
(not yet used in use)
- 'max_cs_size' and 'rsiz' fields added to opj_cparameters_t
Misc:
* OpenJPEG is now officialy conformant with JPEG 2000 Part-1
and will soon become official reference software at the
JPEG committee.
and will soon become official reference software at the
JPEG committee.
* Huge amount of bug fixes. See CHANGES for details.
Changes from OpenJPEG 1.5.x to OpenJPEG 2.0.0
----------------------------------------------
New Features:
* streaming capabilities
* merge JP3D
API modifications:
* Use a 64bits capable API
Misc:
* removed autotools build system
* folders hierarchies reorganisation
* Huge amount of bug fixes. See CHANGES for details.

50
THANKS
View File

@@ -4,30 +4,32 @@ Many people have contributed to OpenJPEG by reporting problems, suggesting vario
or submitting actual code. Here is a list of these people. Help me keep
it complete and exempt of errors.
Winfried Szukalski
Vincent Torri
Bob Friesenhahn
Callum Lerwick
Dzonatas Sol
Julien Malik
Jerôme Fimes
Herve Drolon
Yannick Verschueren
Sebastien Lugan
Kaori Hagihara
Peter Wimmer
Francois-Olivier Devaux
Antonin Descampe
David Janssens
Pr. Benoit Macq
Luis Ibanez
Giuseppe Baruffa
Ben Boeckel
Aaron Boxer
David Burken
Matthieu Darbois
Rex Dieter
Herve Drolon
Antonin Descampe
Francois-Olivier Devaux
Parvatha Elangovan
Jerôme Fimes
Bob Friesenhahn
Kaori Hagihara
Luc Hermitte
Luis Ibanez
David Janssens
Hans Johnson
Callum Lerwick
Sebastien Lugan
Benoit Macq
Arnaud Maye
Julien Malik
Vincent Nicolas
Glenn Pearson
Giuseppe Baruffa
Arnaud Maye
Rex Dieter
David Burken
Parvatha Elangovan
Hans Johnson
Luc Hermitte
Dzonatas Sol
Winfried Szukalski
Vincent Torri
Yannick Verschueren
Peter Wimmer

View File

@@ -123,8 +123,8 @@ static void sycc422_to_rgb(opj_image_t *img)
{
int *d0, *d1, *d2, *r, *g, *b;
const int *y, *cb, *cr;
int maxw, maxh, max, offset, upb;
int i, j;
int maxw, maxh, max, offset, upb;
int i, j;
i = (int)img->comps[0].prec;
offset = 1<<(i - 1); upb = (1<<i)-1;
@@ -141,18 +141,22 @@ static void sycc422_to_rgb(opj_image_t *img)
d2 = b = (int*)malloc(sizeof(int) * (size_t)max);
for(i=0; i < maxh; ++i)
{
for(j=0; j < maxw; j += 2)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
{
for(j=0; (OPJ_UINT32)j < (maxw & ~(OPJ_UINT32)1); j += 2)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b;
++y; ++r; ++g; ++b;
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b; ++cb; ++cr;
}
}
++y; ++r; ++g; ++b; ++cb; ++cr;
}
if (j < maxw) {
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b; ++cb; ++cr;
}
}
free(img->comps[0].data); img->comps[0].data = d0;
free(img->comps[1].data); img->comps[1].data = d1;
free(img->comps[2].data); img->comps[2].data = d2;
@@ -192,31 +196,59 @@ static void sycc420_to_rgb(opj_image_t *img)
d1 = g = (int*)malloc(sizeof(int) * (size_t)max);
d2 = b = (int*)malloc(sizeof(int) * (size_t)max);
for(i=0; i < maxh; i += 2)
{
ny = y + maxw;
nr = r + maxw; ng = g + maxw; nb = b + maxw;
for(i=0; (OPJ_UINT32)i < (maxh & ~(OPJ_UINT32)1); i += 2)
{
ny = y + maxw;
nr = r + maxw; ng = g + maxw; nb = b + maxw;
for(j=0; j < maxw; j += 2)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
for(j=0; (OPJ_UINT32)j < (maxw & ~(OPJ_UINT32)1); j += 2)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b;
++y; ++r; ++g; ++b;
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b;
++y; ++r; ++g; ++b;
sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
++ny; ++nr; ++ng; ++nb;
++ny; ++nr; ++ng; ++nb;
sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
++ny; ++nr; ++ng; ++nb; ++cb; ++cr;
}
if(j < maxw)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b;
sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
++ny; ++nr; ++ng; ++nb; ++cb; ++cr;
}
y += maxw; r += maxw; g += maxw; b += maxw;
}
if(i < maxh)
{
for(j=0; (OPJ_UINT32)j < (maxw & ~(OPJ_UINT32)1); j += 2)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b;
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b; ++cb; ++cr;
}
if(j < maxw)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
}
}
++ny; ++nr; ++ng; ++nb; ++cb; ++cr;
}
y += maxw; r += maxw; g += maxw; b += maxw;
}
free(img->comps[0].data); img->comps[0].data = d0;
free(img->comps[1].data); img->comps[1].data = d1;
free(img->comps[2].data); img->comps[2].data = d2;

View File

@@ -1,3 +1,5 @@
#include "opj_config_private.h"
/* create opj_apps_config.h for CMake */
#cmakedefine OPJ_HAVE_LIBPNG @HAVE_LIBPNG@

View File

@@ -50,8 +50,16 @@ foreach(exe opj_decompress opj_compress opj_dump)
EXPORT OpenJPEGTargets
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
)
if(OPJ_USE_DSYMUTIL)
GET_TARGET_PROPERTY(EXE_LOCATION ${exe} LOCATION)
add_custom_command(TARGET ${exe} POST_BUILD
COMMAND "dsymutil" "${EXE_LOCATION}"
COMMENT "dsymutil ${EXE_LOCATION}"
DEPENDS ${exe})
endif()
endforeach()
if(BUILD_DOC)
# Install man pages
install(
FILES ${OPENJPEG_SOURCE_DIR}/doc/man/man1/opj_compress.1
@@ -59,3 +67,4 @@ install(
${OPENJPEG_SOURCE_DIR}/doc/man/man1/opj_dump.1
DESTINATION ${OPENJPEG_INSTALL_MAN_DIR}/man1)
#
endif()

View File

@@ -2597,6 +2597,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
int has_alpha = 0;
unsigned short tiBps, tiPhoto, tiSf, tiSpp, tiPC;
unsigned int tiWidth, tiHeight;
OPJ_BOOL is_cinema = OPJ_IS_CINEMA(parameters->rsiz);
tif = TIFFOpen(filename, "r");
@@ -2669,7 +2670,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
*/
memset(&cmptparm[0], 0, 4 * sizeof(opj_image_cmptparm_t));
if ((tiPhoto == PHOTOMETRIC_RGB) && (parameters->cp_cinema)) {
if ((tiPhoto == PHOTOMETRIC_RGB) && (is_cinema)) {
fprintf(stdout,"WARNING:\n"
"Input image bitdepth is %d bits\n"
"TIF conversion has automatically rescaled to 12-bits\n"
@@ -2685,7 +2686,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
/*#define USETILEMODE*/
for(j = 0; j < numcomps; j++)
{
if(parameters->cp_cinema)
if(is_cinema)
{
cmptparm[j].prec = 12;
cmptparm[j].bpp = 12;
@@ -2754,7 +2755,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
if(has_alpha)
image->comps[3].data[index] = ( dat8[i+7] << 8 ) | dat8[i+6];
if(parameters->cp_cinema)
if(is_cinema)
{
/* Rounding 16 to 12 bits
*/
@@ -2791,7 +2792,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
image->comps[3].data[index] = dat8[i+3];
#endif
if(parameters->cp_cinema)
if(is_cinema)
{
/* Rounding 8 to 12 bits
*/
@@ -2987,10 +2988,13 @@ static opj_image_t* rawtoimage_common(const char *filename, opj_cparameters_t *p
}
w = raw_cp->rawWidth;
h = raw_cp->rawHeight;
cmptparm = (opj_image_cmptparm_t*) malloc((size_t)numcomps * sizeof(opj_image_cmptparm_t));
cmptparm = (opj_image_cmptparm_t*) calloc(numcomps,sizeof(opj_image_cmptparm_t));
if (!cmptparm) {
fprintf(stderr, "Failed to allocate image components parameters !!\n");
fprintf(stderr,"Aborting\n");
return NULL;
}
/* initialize image components */
memset(&cmptparm[0], 0, (size_t)numcomps * sizeof(opj_image_cmptparm_t));
for(i = 0; i < numcomps; i++) {
cmptparm[i].prec = (OPJ_UINT32)raw_cp->rawBitDepth;
cmptparm[i].bpp = (OPJ_UINT32)raw_cp->rawBitDepth;
@@ -3017,7 +3021,7 @@ static opj_image_t* rawtoimage_common(const char *filename, opj_cparameters_t *p
{
unsigned char value = 0;
for(compno = 0; compno < numcomps; compno++) {
int nloop = (w*h)/(raw_cp->rawComps[compno].dx*raw_cp->rawComps[compno].dx);
int nloop = (w*h)/(raw_cp->rawComps[compno].dx*raw_cp->rawComps[compno].dy);
for (i = 0; i < nloop; i++) {
if (!fread(&value, 1, 1, f)) {
fprintf(stderr,"Error reading raw file. End of file probably reached.\n");

View File

@@ -86,25 +86,12 @@ typedef struct img_folder{
}img_fol_t;
static void encode_help_display(void) {
fprintf(stdout,"HELP for opj_compress\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n");
fprintf(stdout,"\nThis is the opj_compress utility from the OpenJPEG project.\n"
"It compresses various image formats with the JPEG 2000 algorithm.\n"
"It has been compiled against openjp2 library v%s.\n\n",opj_version());
/* UniPG>> */
fprintf(stdout,"List of parameters for the JPEG 2000 "
#ifdef USE_JPWL
"+ JPWL "
#endif /* USE_JPWL */
"encoder:\n");
/* <<UniPG */
fprintf(stdout,"\n");
fprintf(stdout,"REMARKS:\n");
fprintf(stdout,"---------\n");
fprintf(stdout,"\n");
fprintf(stdout,"The markers written to the main_header are : SOC SIZ COD QCD COM.\n");
fprintf(stdout,"COD and QCD never appear in the tile_header.\n");
fprintf(stdout,"\n");
fprintf(stdout,"By default:\n");
fprintf(stdout,"------------\n");
fprintf(stdout,"Default encoding options:\n");
fprintf(stdout,"-------------------------\n");
fprintf(stdout,"\n");
fprintf(stdout," * Lossless\n");
fprintf(stdout," * 1 tile\n");
@@ -117,7 +104,9 @@ static void encode_help_display(void) {
fprintf(stdout," * No sub-sampling in x or y direction\n");
fprintf(stdout," * No mode switch activated\n");
fprintf(stdout," * Progression order: LRCP\n");
#ifdef FIXME_INDEX
fprintf(stdout," * No index file\n");
#endif /* FIXME_INDEX */
fprintf(stdout," * No ROI upshifted\n");
fprintf(stdout," * No offset of the origin of the image\n");
fprintf(stdout," * No offset of the origin of the tiles\n");
@@ -128,176 +117,204 @@ static void encode_help_display(void) {
#endif /* USE_JPWL */
/* <<UniPG */
fprintf(stdout,"\n");
fprintf(stdout,"Note:\n");
fprintf(stdout,"-----\n");
fprintf(stdout,"\n");
fprintf(stdout,"The markers written to the main_header are : SOC SIZ COD QCD COM.\n");
fprintf(stdout,"COD and QCD never appear in the tile_header.\n");
fprintf(stdout,"\n");
fprintf(stdout,"Parameters:\n");
fprintf(stdout,"------------\n");
fprintf(stdout,"-----------\n");
fprintf(stdout,"\n");
fprintf(stdout,"Required Parameters (except with -h):\n");
fprintf(stdout,"One of the two options -ImgDir or -i must be used\n");
fprintf(stdout,"\n");
fprintf(stdout,"-ImgDir : Image file Directory path (example ../Images) \n");
fprintf(stdout,"-i <file>\n");
fprintf(stdout," Input file\n");
fprintf(stdout," Known extensions are <PBM|PGM|PPM|PNM|PAM|PGX|PNG|BMP|TIF|RAW|RAWL|TGA>\n");
fprintf(stdout," If used, '-o <file>' must be provided\n");
fprintf(stdout,"-o <compressed file>\n");
fprintf(stdout," Output file (accepted extensions are j2k or jp2).\n");
fprintf(stdout,"-ImgDir <dir>\n");
fprintf(stdout," Image file Directory path (example ../Images) \n");
fprintf(stdout," When using this option -OutFor must be used\n");
fprintf(stdout,"\n");
fprintf(stdout,"-OutFor \n");
fprintf(stdout," REQUIRED only if -ImgDir is used\n");
fprintf(stdout," Need to specify only format without filename <BMP> \n");
fprintf(stdout," Currently accepts PBM, PGM, PPM, PNM, PAM, PGX, PNG, BMP, TIF, RAW (MSB), RAWL (LSB) and TGA formats\n");
fprintf(stdout,"\n");
fprintf(stdout,"-i : source file (-i source.pnm also *pbm, *.pgm, *.ppm, *.pam, *.pgx, *png, *.bmp, *.tif, *.raw, *.tga) \n");
fprintf(stdout," When using this option -o must be used\n");
fprintf(stdout,"\n");
fprintf(stdout,"-o : destination file (-o dest.j2k or .jp2) \n");
fprintf(stdout,"-OutFor <J2K|J2C|JP2>\n");
fprintf(stdout," Output format for compressed files.\n");
fprintf(stdout," Required only if -ImgDir is used\n");
fprintf(stdout,"-F <width>,<height>,<ncomp>,<bitdepth>,{s,u}@<dx1>x<dy1>:...:<dxn>x<dyn>\n");
fprintf(stdout," Characteristics of the raw input image\n");
fprintf(stdout," If subsampling is omitted, 1x1 is assumed for all components\n");
fprintf(stdout," Example: -F 512,512,3,8,u@1x1:2x2:2x2\n");
fprintf(stdout," for raw 512x512 image with 4:2:0 subsampling\n");
fprintf(stdout," Required only if RAW or RAWL input file is provided.\n");
fprintf(stdout,"\n");
fprintf(stdout,"Optional Parameters:\n");
fprintf(stdout,"\n");
fprintf(stdout,"-h : display the help information \n ");
fprintf(stdout,"\n");
fprintf(stdout,"-cinema2K : Digital Cinema 2K profile compliant codestream for 2K resolution.(-CINEMA2K 24 or 48) \n");
fprintf(stdout," Need to specify the frames per second for a 2K resolution. Only 24 or 48 fps is allowed\n");
fprintf(stdout,"\n");
fprintf(stdout,"-cinema4K : Digital Cinema 4K profile compliant codestream for 4K resolution \n");
fprintf(stdout," Frames per second not required. Default value is 24fps\n");
fprintf(stdout,"\n");
fprintf(stdout,"-r : different compression ratios for successive layers (-r 20,10,5)\n ");
fprintf(stdout," - The rate specified for each quality level is the desired \n");
fprintf(stdout," compression factor.\n");
fprintf(stdout," Example: -r 20,10,1 means quality 1: compress 20x, \n");
fprintf(stdout," quality 2: compress 10x and quality 3: compress lossless\n");
fprintf(stdout,"\n");
fprintf(stdout," (options -r and -q cannot be used together)\n ");
fprintf(stdout,"\n");
fprintf(stdout,"-q : different psnr for successive layers (-q 30,40,50) \n ");
fprintf(stdout," (options -r and -q cannot be used together)\n ");
fprintf(stdout,"\n");
fprintf(stdout,"-n : number of resolutions (-n 3) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-b : size of code block (-b 32,32) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-c : size of precinct (-c 128,128) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-t : size of tile (-t 512,512) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-p : progression order (-p LRCP) [LRCP, RLCP, RPCL, PCRL, CPRL] \n");
fprintf(stdout,"\n");
fprintf(stdout,"-s : subsampling factor (-s 2,2) [-s X,Y] \n");
fprintf(stdout," Remark: subsampling bigger than 2 can produce error\n");
fprintf(stdout,"\n");
fprintf(stdout,"-POC : Progression order change (-POC T1=0,0,1,5,3,CPRL/T1=5,0,1,6,3,CPRL) \n");
fprintf(stdout," Example: T1=0,0,1,5,3,CPRL \n");
fprintf(stdout," : Ttilenumber=Resolution num start,Component num start,Layer num end,Resolution num end,Component num end,Progression order\n");
fprintf(stdout,"\n");
fprintf(stdout,"-SOP : write SOP marker before each packet \n");
fprintf(stdout,"\n");
fprintf(stdout,"-EPH : write EPH marker after each header packet \n");
fprintf(stdout,"\n");
fprintf(stdout,"-M : mode switch (-M 3) [1=BYPASS(LAZY) 2=RESET 4=RESTART(TERMALL)\n");
fprintf(stdout," 8=VSC 16=ERTERM(SEGTERM) 32=SEGMARK(SEGSYM)] \n");
fprintf(stdout," Indicate multiple modes by adding their values. \n");
fprintf(stdout," ex: RESTART(4) + RESET(2) + SEGMARK(32) = -M 38\n");
fprintf(stdout,"\n");
fprintf(stdout,"-TP : divide packets of every tile into tile-parts (-TP R) [R, L, C]\n");
fprintf(stdout,"\n");
fprintf(stdout,"-x : create an index file *.Idx (-x index_name.Idx) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-ROI : c=%%d,U=%%d : quantization indices upshifted \n");
fprintf(stdout," for component c=%%d [%%d = 0,1,2]\n");
fprintf(stdout," with a value of U=%%d [0 <= %%d <= 37] (i.e. -ROI c=0,U=25) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-d : offset of the origin of the image (-d 150,300) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-T : offset of the origin of the tiles (-T 100,75) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-I : use the irreversible DWT 9-7 (-I) \n");
fprintf(stdout,"\n");
fprintf(stdout,"-F : characteristics of the raw input image\n");
fprintf(stdout," -F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n");
fprintf(stdout," Example: -i lena.raw -o lena.j2k -F 512,512,3,8,u\n");
fprintf(stdout,"\n");
fprintf(stdout,"-mct {0,1,2} : explicitely specifies if a Multiple Component Transform has to be used.\n");
fprintf(stdout," 0: no MCT ; 1: RGB->YCC conversion ; 2: custom MCT.\n");
fprintf(stdout," If custom MCT, \"-m\" option has to be used (see hereunder).\n");
fprintf(stdout," By default, RGB->YCC conversion is used if there are 3 components or more,\n");
fprintf(stdout," no conversion otherwise.\n");
fprintf(stdout,"-m <file> : use array-based MCT, values are coma separated, line by line\n");
fprintf(stdout," no specific separators between lines, no space allowed between values\n");
fprintf(stdout," If this option is used, it automatically sets \"-mct\" option to 2.\n");
fprintf(stdout,"-jpip : write jpip codestream index box in JP2 output file\n");
fprintf(stdout," NOTICE: currently supports only RPCL order\n");
fprintf(stdout,"\n");
fprintf(stdout,"-h\n");
fprintf(stdout," Display the help information.\n");
fprintf(stdout,"-r <compression ratio>,<compression ratio>,...\n");
fprintf(stdout," Different compression ratios for successive layers.\n");
fprintf(stdout," The rate specified for each quality level is the desired\n");
fprintf(stdout," compression factor.\n");
fprintf(stdout," Decreasing ratios required.\n");
fprintf(stdout," Example: -r 20,10,1 means \n");
fprintf(stdout," quality layer 1: compress 20x, \n");
fprintf(stdout," quality layer 2: compress 10x \n");
fprintf(stdout," quality layer 3: compress lossless\n");
fprintf(stdout," Options -r and -q cannot be used together.\n");
fprintf(stdout,"-q <psnr value>,<psnr value>,<psnr value>,...\n");
fprintf(stdout," Different psnr for successive layers (-q 30,40,50).\n");
fprintf(stdout," Increasing PSNR values required.\n");
fprintf(stdout," Options -r and -q cannot be used together.\n");
fprintf(stdout,"-n <number of resolutions>\n");
fprintf(stdout," Number of resolutions.\n");
fprintf(stdout," It corresponds to the number of DWT decompositions +1. \n");
fprintf(stdout," Default: 6.\n");
fprintf(stdout,"-b <cblk width>,<cblk height>\n");
fprintf(stdout," Code-block size. The dimension must respect the constraint \n");
fprintf(stdout," defined in the JPEG-2000 standard (no dimension smaller than 4 \n");
fprintf(stdout," or greater than 1024, no code-block with more than 4096 coefficients).\n");
fprintf(stdout," The maximum value authorized is 64x64. \n");
fprintf(stdout," Default: 64x64.\n");
fprintf(stdout,"-c [<prec width>,<prec height>],[<prec width>,<prec height>],...\n");
fprintf(stdout," Precinct size. Values specified must be power of 2. \n");
fprintf(stdout," Multiple records may be supplied, in which case the first record refers\n");
fprintf(stdout," to the highest resolution level and subsequent records to lower \n");
fprintf(stdout," resolution levels. The last specified record is right-shifted for each \n");
fprintf(stdout," remaining lower resolution levels.\n");
fprintf(stdout," Default: 215x215 at each resolution.\n");
fprintf(stdout,"-t <tile width>,<tile height>\n");
fprintf(stdout," Tile size.\n");
fprintf(stdout," Default: the dimension of the whole image, thus only one tile.\n");
fprintf(stdout,"-p <LRCP|RLCP|RPCL|PCRL|CPRL>\n");
fprintf(stdout," Progression order.\n");
fprintf(stdout," Default: LRCP.\n");
fprintf(stdout,"-s <subX,subY>\n");
fprintf(stdout," Subsampling factor.\n");
fprintf(stdout," Subsampling bigger than 2 can produce error\n");
fprintf(stdout," Default: no subsampling.\n");
fprintf(stdout,"-POC <progression order change>/<progression order change>/...\n");
fprintf(stdout," Progression order change.\n");
fprintf(stdout," The syntax of a progression order change is the following:\n");
fprintf(stdout," T<tile>=<resStart>,<compStart>,<layerEnd>,<resEnd>,<compEnd>,<progOrder>\n");
fprintf(stdout," Example: -POC T1=0,0,1,5,3,CPRL/T1=5,0,1,6,3,CPRL\n");
fprintf(stdout,"-SOP\n");
fprintf(stdout," Write SOP marker before each packet.\n");
fprintf(stdout,"-EPH\n");
fprintf(stdout," Write EPH marker after each header packet.\n");
fprintf(stdout,"-M <key value>\n");
fprintf(stdout," Mode switch.\n");
fprintf(stdout," [1=BYPASS(LAZY) 2=RESET 4=RESTART(TERMALL)\n");
fprintf(stdout," 8=VSC 16=ERTERM(SEGTERM) 32=SEGMARK(SEGSYM)]\n");
fprintf(stdout," Indicate multiple modes by adding their values.\n");
fprintf(stdout," Example: RESTART(4) + RESET(2) + SEGMARK(32) => -M 38\n");
fprintf(stdout,"-TP <R|L|C>\n");
fprintf(stdout," Divide packets of every tile into tile-parts.\n");
fprintf(stdout," Division is made by grouping Resolutions (R), Layers (L)\n");
fprintf(stdout," or Components (C).\n");
#ifdef FIXME_INDEX
fprintf(stdout,"-x <index file>\n");
fprintf(stdout," Create an index file.\n");
#endif /*FIXME_INDEX*/
fprintf(stdout,"-ROI c=<component index>,U=<upshifting value>\n");
fprintf(stdout," Quantization indices upshifted for a component. \n");
fprintf(stdout," Warning: This option does not implement the usual ROI (Region of Interest).\n");
fprintf(stdout," It should be understood as a 'Component of Interest'. It offers the \n");
fprintf(stdout," possibility to upshift the value of a component during quantization step.\n");
fprintf(stdout," The value after c= is the component number [0, 1, 2, ...] and the value \n");
fprintf(stdout," after U= is the value of upshifting. U must be in the range [0, 37].\n");
fprintf(stdout,"-d <image offset X,image offset Y>\n");
fprintf(stdout," Offset of the origin of the image.\n");
fprintf(stdout,"-T <tile offset X,tile offset Y>\n");
fprintf(stdout," Offset of the origin of the tiles.\n");
fprintf(stdout,"-I\n");
fprintf(stdout," Use the irreversible DWT 9-7.\n");
fprintf(stdout,"-mct <0|1|2>\n");
fprintf(stdout," Explicitely specifies if a Multiple Component Transform has to be used.\n");
fprintf(stdout," 0: no MCT ; 1: RGB->YCC conversion ; 2: custom MCT.\n");
fprintf(stdout," If custom MCT, \"-m\" option has to be used (see hereunder).\n");
fprintf(stdout," By default, RGB->YCC conversion is used if there are 3 components or more,\n");
fprintf(stdout," no conversion otherwise.\n");
fprintf(stdout,"-m <file>\n");
fprintf(stdout," Use array-based MCT, values are coma separated, line by line\n");
fprintf(stdout," No specific separators between lines, no space allowed between values.\n");
fprintf(stdout," If this option is used, it automatically sets \"-mct\" option to 2.\n");
fprintf(stdout,"-cinema2K <24|48>\n");
fprintf(stdout," Digital Cinema 2K profile compliant codestream.\n");
fprintf(stdout," Need to specify the frames per second for a 2K resolution.\n");
fprintf(stdout," Only 24 or 48 fps are currently allowed.\n");
fprintf(stdout,"-cinema4K\n");
fprintf(stdout," Digital Cinema 4K profile compliant codestream.\n");
fprintf(stdout," Frames per second not required. Default value is 24fps.\n");
fprintf(stdout,"-jpip\n");
fprintf(stdout," Write jpip codestream index box in JP2 output file.\n");
fprintf(stdout," Currently supports only RPCL order.\n");
fprintf(stdout,"-C <comment>\n");
fprintf(stdout," Add <comment> in the comment marker segment.\n");
/* UniPG>> */
#ifdef USE_JPWL
fprintf(stdout,"-W : adoption of JPWL (Part 11) capabilities (-W params)\n");
fprintf(stdout," The parameters can be written and repeated in any order:\n");
fprintf(stdout," [h<tilepart><=type>,s<tilepart><=method>,a=<addr>,...\n");
fprintf(stdout," ...,z=<size>,g=<range>,p<tilepart:pack><=type>]\n");
fprintf(stdout,"\n");
fprintf(stdout," h selects the header error protection (EPB): 'type' can be\n");
fprintf(stdout," [0=none 1,absent=predefined 16=CRC-16 32=CRC-32 37-128=RS]\n");
fprintf(stdout," if 'tilepart' is absent, it is for main and tile headers\n");
fprintf(stdout," if 'tilepart' is present, it applies from that tile\n");
fprintf(stdout," onwards, up to the next h<> spec, or to the last tilepart\n");
fprintf(stdout," in the codestream (max. %d specs)\n", JPWL_MAX_NO_TILESPECS);
fprintf(stdout,"\n");
fprintf(stdout," p selects the packet error protection (EEP/UEP with EPBs)\n");
fprintf(stdout," to be applied to raw data: 'type' can be\n");
fprintf(stdout," [0=none 1,absent=predefined 16=CRC-16 32=CRC-32 37-128=RS]\n");
fprintf(stdout," if 'tilepart:pack' is absent, it is from tile 0, packet 0\n");
fprintf(stdout," if 'tilepart:pack' is present, it applies from that tile\n");
fprintf(stdout," and that packet onwards, up to the next packet spec\n");
fprintf(stdout," or to the last packet in the last tilepart in the stream\n");
fprintf(stdout," (max. %d specs)\n", JPWL_MAX_NO_PACKSPECS);
fprintf(stdout,"\n");
fprintf(stdout," s enables sensitivity data insertion (ESD): 'method' can be\n");
fprintf(stdout," [-1=NO ESD 0=RELATIVE ERROR 1=MSE 2=MSE REDUCTION 3=PSNR\n");
fprintf(stdout," 4=PSNR INCREMENT 5=MAXERR 6=TSE 7=RESERVED]\n");
fprintf(stdout," if 'tilepart' is absent, it is for main header only\n");
fprintf(stdout," if 'tilepart' is present, it applies from that tile\n");
fprintf(stdout," onwards, up to the next s<> spec, or to the last tilepart\n");
fprintf(stdout," in the codestream (max. %d specs)\n", JPWL_MAX_NO_TILESPECS);
fprintf(stdout,"\n");
fprintf(stdout," g determines the addressing mode: <range> can be\n");
fprintf(stdout," [0=PACKET 1=BYTE RANGE 2=PACKET RANGE]\n");
fprintf(stdout,"\n");
fprintf(stdout," a determines the size of data addressing: <addr> can be\n");
fprintf(stdout," 2/4 bytes (small/large codestreams). If not set, auto-mode\n");
fprintf(stdout,"\n");
fprintf(stdout," z determines the size of sensitivity values: <size> can be\n");
fprintf(stdout," 1/2 bytes, for the transformed pseudo-floating point value\n");
fprintf(stdout,"\n");
fprintf(stdout," ex.:\n");
fprintf(stdout," h,h0=64,h3=16,h5=32,p0=78,p0:24=56,p1,p3:0=0,p3:20=32,s=0,\n");
fprintf(stdout," s0=6,s3=-1,a=0,g=1,z=1\n");
fprintf(stdout," means\n");
fprintf(stdout," predefined EPB in MH, rs(64,32) from TPH 0 to TPH 2,\n");
fprintf(stdout," CRC-16 in TPH 3 and TPH 4, CRC-32 in remaining TPHs,\n");
fprintf(stdout," UEP rs(78,32) for packets 0 to 23 of tile 0,\n");
fprintf(stdout," UEP rs(56,32) for packs. 24 to the last of tilepart 0,\n");
fprintf(stdout," UEP rs default for packets of tilepart 1,\n");
fprintf(stdout," no UEP for packets 0 to 19 of tilepart 3,\n");
fprintf(stdout," UEP CRC-32 for packs. 20 of tilepart 3 to last tilepart,\n");
fprintf(stdout," relative sensitivity ESD for MH,\n");
fprintf(stdout," TSE ESD from TPH 0 to TPH 2, byte range with automatic\n");
fprintf(stdout," size of addresses and 1 byte for each sensitivity value\n");
fprintf(stdout,"\n");
fprintf(stdout," ex.:\n");
fprintf(stdout," h,s,p\n");
fprintf(stdout," means\n");
fprintf(stdout," default protection to headers (MH and TPHs) as well as\n");
fprintf(stdout," data packets, one ESD in MH\n");
fprintf(stdout,"\n");
fprintf(stdout," N.B.: use the following recommendations when specifying\n");
fprintf(stdout," the JPWL parameters list\n");
fprintf(stdout," - when you use UEP, always pair the 'p' option with 'h'\n");
fprintf(stdout," \n");
fprintf(stdout,"-W <params>\n");
fprintf(stdout," Adoption of JPWL (Part 11) capabilities (-W params)\n");
fprintf(stdout," The <params> field can be written and repeated in any order:\n");
fprintf(stdout," [h<tilepart><=type>,s<tilepart><=method>,a=<addr>,...\n");
fprintf(stdout," ...,z=<size>,g=<range>,p<tilepart:pack><=type>]\n");
fprintf(stdout," h selects the header error protection (EPB): 'type' can be\n");
fprintf(stdout," [0=none 1,absent=predefined 16=CRC-16 32=CRC-32 37-128=RS]\n");
fprintf(stdout," if 'tilepart' is absent, it is for main and tile headers\n");
fprintf(stdout," if 'tilepart' is present, it applies from that tile\n");
fprintf(stdout," onwards, up to the next h<> spec, or to the last tilepart\n");
fprintf(stdout," in the codestream (max. %d specs)\n", JPWL_MAX_NO_TILESPECS);
fprintf(stdout," p selects the packet error protection (EEP/UEP with EPBs)\n");
fprintf(stdout," to be applied to raw data: 'type' can be\n");
fprintf(stdout," [0=none 1,absent=predefined 16=CRC-16 32=CRC-32 37-128=RS]\n");
fprintf(stdout," if 'tilepart:pack' is absent, it is from tile 0, packet 0\n");
fprintf(stdout," if 'tilepart:pack' is present, it applies from that tile\n");
fprintf(stdout," and that packet onwards, up to the next packet spec\n");
fprintf(stdout," or to the last packet in the last tilepart in the stream\n");
fprintf(stdout," (max. %d specs)\n", JPWL_MAX_NO_PACKSPECS);
fprintf(stdout," s enables sensitivity data insertion (ESD): 'method' can be\n");
fprintf(stdout," [-1=NO ESD 0=RELATIVE ERROR 1=MSE 2=MSE REDUCTION 3=PSNR\n");
fprintf(stdout," 4=PSNR INCREMENT 5=MAXERR 6=TSE 7=RESERVED]\n");
fprintf(stdout," if 'tilepart' is absent, it is for main header only\n");
fprintf(stdout," if 'tilepart' is present, it applies from that tile\n");
fprintf(stdout," onwards, up to the next s<> spec, or to the last tilepart\n");
fprintf(stdout," in the codestream (max. %d specs)\n", JPWL_MAX_NO_TILESPECS);
fprintf(stdout," g determines the addressing mode: <range> can be\n");
fprintf(stdout," [0=PACKET 1=BYTE RANGE 2=PACKET RANGE]\n");
fprintf(stdout," a determines the size of data addressing: <addr> can be\n");
fprintf(stdout," 2/4 bytes (small/large codestreams). If not set, auto-mode\n");
fprintf(stdout," z determines the size of sensitivity values: <size> can be\n");
fprintf(stdout," 1/2 bytes, for the transformed pseudo-floating point value\n");
fprintf(stdout," ex.:\n");
fprintf(stdout," h,h0=64,h3=16,h5=32,p0=78,p0:24=56,p1,p3:0=0,p3:20=32,s=0,\n");
fprintf(stdout," s0=6,s3=-1,a=0,g=1,z=1\n");
fprintf(stdout," means\n");
fprintf(stdout," predefined EPB in MH, rs(64,32) from TPH 0 to TPH 2,\n");
fprintf(stdout," CRC-16 in TPH 3 and TPH 4, CRC-32 in remaining TPHs,\n");
fprintf(stdout," UEP rs(78,32) for packets 0 to 23 of tile 0,\n");
fprintf(stdout," UEP rs(56,32) for packs. 24 to the last of tilepart 0,\n");
fprintf(stdout," UEP rs default for packets of tilepart 1,\n");
fprintf(stdout," no UEP for packets 0 to 19 of tilepart 3,\n");
fprintf(stdout," UEP CRC-32 for packs. 20 of tilepart 3 to last tilepart,\n");
fprintf(stdout," relative sensitivity ESD for MH,\n");
fprintf(stdout," TSE ESD from TPH 0 to TPH 2, byte range with automatic\n");
fprintf(stdout," size of addresses and 1 byte for each sensitivity value\n");
fprintf(stdout," ex.:\n");
fprintf(stdout," h,s,p\n");
fprintf(stdout," means\n");
fprintf(stdout," default protection to headers (MH and TPHs) as well as\n");
fprintf(stdout," data packets, one ESD in MH\n");
fprintf(stdout," N.B.: use the following recommendations when specifying\n");
fprintf(stdout," the JPWL parameters list\n");
fprintf(stdout," - when you use UEP, always pair the 'p' option with 'h'\n");
#endif /* USE_JPWL */
/* <<UniPG */
fprintf(stdout,"IMPORTANT:\n");
fprintf(stdout,"-----------\n");
fprintf(stdout,"\n");
fprintf(stdout,"The index file has the structure below:\n");
fprintf(stdout,"---------------------------------------\n");
#ifdef FIXME_INDEX
fprintf(stdout,"Index structure:\n");
fprintf(stdout,"----------------\n");
fprintf(stdout,"\n");
fprintf(stdout,"Image_height Image_width\n");
fprintf(stdout,"progression order\n");
@@ -327,10 +344,9 @@ static void encode_help_display(void) {
fprintf(stdout,"Tpacket_0 Tile layer res. comp. prec. start_pos end_pos disto\n");
fprintf(stdout,"...\n");
fprintf(stdout,"Tpacket_Np '' '' '' '' '' '' '' ''\n");
fprintf(stdout,"MaxDisto\n");
fprintf(stdout,"TotalDisto\n\n");
#endif /*FIXME_INDEX*/
}
static OPJ_PROG_ORDER give_progression(const char progression[4]) {
@@ -502,8 +518,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
break;
default:
fprintf(stderr,
"!! Unrecognized format for infile : %s "
"[accept only *.pnm, *.pgm, *.ppm, *.pgx, *png, *.bmp, *.tif, *.raw or *.tga] !!\n\n",
"[ERROR] Unknown input file format: %s \n"
" Known file formats are *.pnm, *.pgm, *.ppm, *.pgx, *png, *.bmp, *.tif, *.raw or *.tga\n",
infile);
return 1;
}
@@ -790,6 +806,11 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
{
char *index = opj_optarg;
strncpy(indexfilename, index, OPJ_PATH_LEN);
/* FIXME ADE INDEX >> */
fprintf(stderr,
"[WARNING] Index file generation is currently broken.\n"
" '-x' option ignored.\n");
/* << FIXME ADE INDEX */
}
break;
@@ -968,9 +989,13 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
int fps=0;
sscanf(opj_optarg,"%d",&fps);
if(fps == 24){
parameters->cp_cinema = OPJ_CINEMA2K_24;
parameters->rsiz = OPJ_PROFILE_CINEMA_2K;
parameters->max_comp_size = OPJ_CINEMA_24_COMP;
parameters->max_cs_size = OPJ_CINEMA_24_CS;
}else if(fps == 48 ){
parameters->cp_cinema = OPJ_CINEMA2K_48;
parameters->rsiz = OPJ_PROFILE_CINEMA_2K;
parameters->max_comp_size = OPJ_CINEMA_48_COMP;
parameters->max_cs_size = OPJ_CINEMA_48_CS;
}else {
fprintf(stderr,"Incorrect value!! must be 24 or 48\n");
return 1;
@@ -985,7 +1010,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
case 'y': /* Digital Cinema 4K profile compliance*/
{
parameters->cp_cinema = OPJ_CINEMA4K_24;
parameters->rsiz = OPJ_PROFILE_CINEMA_4K;
fprintf(stdout,"CINEMA 4K profile activated\n"
"Other options specified could be overriden\n");
}
@@ -1408,37 +1433,38 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
default:
fprintf(stderr, "ERROR -> Command line not valid\n");
return 1;
fprintf(stderr, "[WARNING] An invalid option has been ignored\n");
break;
}
}while(c != -1);
if(img_fol->set_imgdir == 1){
if(!(parameters->infile[0] == 0)){
fprintf(stderr, "Error: options -ImgDir and -i cannot be used together !!\n");
fprintf(stderr, "[ERROR] options -ImgDir and -i cannot be used together !!\n");
return 1;
}
if(img_fol->set_out_format == 0){
fprintf(stderr, "Error: When -ImgDir is used, -OutFor <FORMAT> must be used !!\n");
fprintf(stderr, "[ERROR] When -ImgDir is used, -OutFor <FORMAT> must be used !!\n");
fprintf(stderr, "Only one format allowed! Valid formats are j2k and jp2!!\n");
return 1;
}
if(!((parameters->outfile[0] == 0))){
fprintf(stderr, "Error: options -ImgDir and -o cannot be used together !!\n");
fprintf(stderr, "[ERROR] options -ImgDir and -o cannot be used together !!\n");
fprintf(stderr, "Specify OutputFormat using -OutFor<FORMAT> !!\n");
return 1;
}
}else{
if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) {
fprintf(stderr, "Example: %s -i image.ppm -o image.j2k\n",argv[0]);
fprintf(stderr, " Try: %s -h\n",argv[0]);
fprintf(stderr, "[ERROR] Required parameters are missing\n"
"Example: %s -i image.j2k -o image.pgm\n",argv[0]);
fprintf(stderr, " Help: %s -h\n",argv[0]);
return 1;
}
}
if ( (parameters->decod_format == RAW_DFMT && raw_cp->rawWidth == 0)
|| (parameters->decod_format == RAWL_DFMT && raw_cp->rawWidth == 0)) {
fprintf(stderr,"\nError: invalid raw image parameters\n");
fprintf(stderr,"[ERROR] invalid raw image parameters\n");
fprintf(stderr,"Please use the Format option -F:\n");
fprintf(stderr,"-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n");
fprintf(stderr,"Example: -i lena.raw -o lena.j2k -F 512,512,3,8,u\n");
@@ -1448,7 +1474,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
if ((parameters->cp_disto_alloc || parameters->cp_fixed_alloc || parameters->cp_fixed_quality)
&& (!(parameters->cp_disto_alloc ^ parameters->cp_fixed_alloc ^ parameters->cp_fixed_quality))) {
fprintf(stderr, "Error: options -r -q and -f cannot be used together !!\n");
fprintf(stderr, "[ERROR] options -r -q and -f cannot be used together !!\n");
return 1;
} /* mod fixed_quality */
@@ -1461,7 +1487,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
if((parameters->cp_tx0 > parameters->image_offset_x0) || (parameters->cp_ty0 > parameters->image_offset_y0)) {
fprintf(stderr,
"Error: Tile offset dimension is unnappropriate --> TX0(%d)<=IMG_X0(%d) TYO(%d)<=IMG_Y0(%d) \n",
"[ERROR] Tile offset dimension is unnappropriate --> TX0(%d)<=IMG_X0(%d) TYO(%d)<=IMG_Y0(%d) \n",
parameters->cp_tx0, parameters->image_offset_x0, parameters->cp_ty0, parameters->image_offset_y0);
return 1;
}
@@ -1474,6 +1500,14 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
}
}
/* If subsampled image is provided, automatically disable MCT */
if ( ((parameters->decod_format == RAW_DFMT) || (parameters->decod_format == RAWL_DFMT))
&& ( ((raw_cp->rawComp > 1 ) && ((raw_cp->rawComps[1].dx > 1) || (raw_cp->rawComps[1].dy > 1)))
|| ((raw_cp->rawComp > 2 ) && ((raw_cp->rawComps[2].dx > 1) || (raw_cp->rawComps[2].dy > 1)))
)) {
parameters->tcp_mct = 0;
}
return 0;
}
@@ -1507,7 +1541,6 @@ static void info_callback(const char *msg, void *client_data) {
*/
/* -------------------------------------------------------------------------- */
int main(int argc, char **argv) {
FILE *fout = NULL;
opj_cparameters_t parameters; /* compression parameters */
@@ -1547,22 +1580,6 @@ int main(int argc, char **argv) {
return 1;
}
/* Create comment for codestream */
if(parameters.cp_comment == NULL) {
const char comment[] = "Created by OpenJPEG version ";
const size_t clen = strlen(comment);
const char *version = opj_version();
/* UniPG>> */
#ifdef USE_JPWL
parameters.cp_comment = (char*)malloc(clen+strlen(version)+11);
sprintf(parameters.cp_comment,"%s%s with JPWL", comment, version);
#else
parameters.cp_comment = (char*)malloc(clen+strlen(version)+1);
sprintf(parameters.cp_comment,"%s%s", comment, version);
#endif
/* <<UniPG */
}
/* Read directory if necessary */
if(img_fol.set_imgdir==1){
num_images=get_num_images(img_fol.imgdirpath);
@@ -1753,16 +1770,8 @@ int main(int argc, char **argv) {
}
opj_setup_encoder(l_codec, &parameters, image);
/* Open the output file*/
fout = fopen(parameters.outfile, "wb");
if (! fout) {
fprintf(stderr, "Not enable to create output file!\n");
opj_stream_destroy(l_stream);
return 1;
}
/* open a byte stream for writing and allocate memory for all tiles */
l_stream = opj_stream_create_default_file_stream(fout,OPJ_FALSE);
l_stream = opj_stream_create_default_file_stream(parameters.outfile,OPJ_FALSE);
if (! l_stream){
return 1;
}
@@ -1772,17 +1781,15 @@ int main(int argc, char **argv) {
if (!bSuccess) {
fprintf(stderr, "failed to encode image: opj_start_compress\n");
}
if( bUseTiles ) {
if( bSuccess && bUseTiles ) {
OPJ_BYTE *l_data;
OPJ_UINT32 l_data_size = 512*512*3;
l_data = (OPJ_BYTE*) malloc( l_data_size * sizeof(OPJ_BYTE));
memset(l_data, 0, l_data_size );
l_data = (OPJ_BYTE*) calloc( 1,l_data_size);
assert( l_data );
for (i=0;i<l_nb_tiles;++i) {
if (! opj_write_tile(l_codec,i,l_data,l_data_size,l_stream)) {
fprintf(stderr, "ERROR -> test_tile_encoder: failed to write the tile %d!\n",i);
opj_stream_destroy(l_stream);
fclose(fout);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
return 1;
@@ -1803,17 +1810,16 @@ int main(int argc, char **argv) {
if (!bSuccess) {
opj_stream_destroy(l_stream);
fclose(fout);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
fprintf(stderr, "failed to encode image\n");
remove(parameters.outfile);
return 1;
}
fprintf(stderr,"Generated outfile %s\n",parameters.outfile);
fprintf(stdout,"[INFO] Generated outfile %s\n",parameters.outfile);
/* close and free the byte stream */
opj_stream_destroy(l_stream);
fclose(fout);
/* free remaining compression structures */
opj_destroy_codec(l_codec);

View File

@@ -106,31 +106,25 @@ int parse_DA_values( char* inArg, unsigned int *DA_x0, unsigned int *DA_y0, unsi
/* -------------------------------------------------------------------------- */
static void decode_help_display(void) {
fprintf(stdout,"HELP for opj_decompress\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n");
fprintf(stdout,"\nThis is the opj_decompress utility from the OpenJPEG project.\n"
"It decompresses JPEG 2000 codestreams to various image formats.\n"
"It has been compiled against openjp2 library v%s.\n\n",opj_version());
/* UniPG>> */
fprintf(stdout,"List of parameters for the JPEG 2000 "
#ifdef USE_JPWL
"+ JPWL "
#endif /* USE_JPWL */
"decoder:\n");
/* <<UniPG */
fprintf(stdout,"Parameters:\n");
fprintf(stdout,"-----------\n");
fprintf(stdout,"\n");
fprintf(stdout,"\n");
fprintf(stdout," -ImgDir \n");
fprintf(stdout," -ImgDir <directory> \n");
fprintf(stdout," Image file Directory path \n");
fprintf(stdout," -OutFor \n");
fprintf(stdout," -OutFor <PBM|PGM|PPM|PNM|PAM|PGX|PNG|BMP|TIF|RAW|RAWL|TGA>\n");
fprintf(stdout," REQUIRED only if -ImgDir is used\n");
fprintf(stdout," Need to specify only format without filename <BMP> \n");
fprintf(stdout," Currently accepts PGM, PPM, PNM, PGX, PNG, BMP, TIF, RAW and TGA formats\n");
fprintf(stdout," Output format for decompressed images.\n");
fprintf(stdout," -i <compressed file>\n");
fprintf(stdout," REQUIRED only if an Input image directory not specified\n");
fprintf(stdout," REQUIRED only if an Input image directory is 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 <decompressed file>\n");
fprintf(stdout," REQUIRED\n");
fprintf(stdout," Currently accepts PGM, PPM, PNM, PGX, PNG, BMP, TIF, RAW and TGA files\n");
fprintf(stdout," Currently accepts formats specified above (see OutFor option)\n");
fprintf(stdout," Binary data is written to the file (not ascii). If a PGX\n");
fprintf(stdout," filename is given, there will be as many output files as there are\n");
fprintf(stdout," components: an indice starting from 0 will then be appended to the\n");
@@ -331,7 +325,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
int totlen, c;
opj_option_t long_option[]={
{"ImgDir",REQ_ARG, NULL ,'y'},
{"OutFor",REQ_ARG, NULL ,'O'},
{"OutFor",REQ_ARG, NULL ,'O'}
};
const char optlist[] = "i:o:r:l:x:d:t:"
@@ -341,7 +335,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
"W:"
#endif /* USE_JPWL */
/* <<UniPG */
"h" ;
"h" ;
totlen=sizeof(long_option);
img_fol->set_out_format = 0;
do {
@@ -367,7 +361,8 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
return 1;
default:
fprintf(stderr,
"!! Unrecognized format for infile: %s [accept only *.j2k, *.jp2, *.jpc or *.jpt] !!\n\n",
"[ERROR] Unknown input file format: %s \n"
" Known file formats are *.j2k, *.jp2, *.jpc or *.jpt\n",
infile);
return 1;
}
@@ -472,10 +467,10 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
decode_help_display();
return 1;
/* ------------------------------------------------------ */
/* ----------------------------------------------------- */
case 'y': /* Image Directory path */
{
{
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1;
@@ -589,31 +584,33 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
/* ----------------------------------------------------- */
default:
fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, opj_optarg);
break;
default:
fprintf(stderr, "[WARNING] An invalid option has been ignored.\n");
break;
}
}while(c != -1);
/* check for possible errors */
if(img_fol->set_imgdir==1){
if(!(parameters->infile[0]==0)){
fprintf(stderr, "Error: options -ImgDir and -i cannot be used together !!\n");
fprintf(stderr, "[ERROR] options -ImgDir and -i cannot be used together.\n");
return 1;
}
if(img_fol->set_out_format == 0){
fprintf(stderr, "Error: When -ImgDir is used, -OutFor <FORMAT> must be used !!\n");
fprintf(stderr, "Only one format allowed! Valid format PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA!!\n");
fprintf(stderr, "[ERROR] When -ImgDir is used, -OutFor <FORMAT> must be used.\n");
fprintf(stderr, "Only one format allowed.\n"
"Valid format are PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA.\n");
return 1;
}
if(!((parameters->outfile[0] == 0))){
fprintf(stderr, "Error: options -ImgDir and -o cannot be used together !!\n");
fprintf(stderr, "[ERROR] options -ImgDir and -o cannot be used together.\n");
return 1;
}
}else{
if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) {
fprintf(stderr, "Example: %s -i image.j2k -o image.pgm\n",argv[0]);
fprintf(stderr, " Try: %s -h\n",argv[0]);
fprintf(stderr, "[ERROR] Required parameters are missing\n"
"Example: %s -i image.j2k -o image.pgm\n",argv[0]);
fprintf(stderr, " Help: %s -h\n",argv[0]);
return 1;
}
}
@@ -682,8 +679,6 @@ static void info_callback(const char *msg, void *client_data) {
/* -------------------------------------------------------------------------- */
int main(int argc, char **argv)
{
FILE *fsrc = NULL;
opj_dparameters_t parameters; /* decompression parameters */
opj_image_t* image = NULL;
opj_stream_t *l_stream = NULL; /* Stream */
@@ -753,16 +748,10 @@ int main(int argc, char **argv)
/* read the input file and put it in memory */
/* ---------------------------------------- */
fsrc = fopen(parameters.infile, "rb");
if (!fsrc) {
fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile);
return EXIT_FAILURE;
}
l_stream = opj_stream_create_default_file_stream(fsrc,1);
l_stream = opj_stream_create_default_file_stream(parameters.infile,1);
if (!l_stream){
fclose(fsrc);
fprintf(stderr, "ERROR -> failed to create the stream from the file\n");
fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n", parameters.infile);
return EXIT_FAILURE;
}
@@ -803,7 +792,6 @@ int main(int argc, char **argv)
if ( !opj_setup_decoder(l_codec, &parameters) ){
fprintf(stderr, "ERROR -> opj_compress: failed to setup the decoder\n");
opj_stream_destroy(l_stream);
fclose(fsrc);
opj_destroy_codec(l_codec);
return EXIT_FAILURE;
}
@@ -813,7 +801,6 @@ int main(int argc, char **argv)
if(! opj_read_header(l_stream, l_codec, &image)){
fprintf(stderr, "ERROR -> opj_decompress: failed to read the header\n");
opj_stream_destroy(l_stream);
fclose(fsrc);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
return EXIT_FAILURE;
@@ -827,7 +814,6 @@ int main(int argc, char **argv)
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
fclose(fsrc);
return EXIT_FAILURE;
}
@@ -837,7 +823,6 @@ int main(int argc, char **argv)
opj_destroy_codec(l_codec);
opj_stream_destroy(l_stream);
opj_image_destroy(image);
fclose(fsrc);
return EXIT_FAILURE;
}
}
@@ -849,7 +834,6 @@ int main(int argc, char **argv)
opj_destroy_codec(l_codec);
opj_stream_destroy(l_stream);
opj_image_destroy(image);
fclose(fsrc);
return EXIT_FAILURE;
}*/
@@ -858,7 +842,6 @@ int main(int argc, char **argv)
opj_destroy_codec(l_codec);
opj_stream_destroy(l_stream);
opj_image_destroy(image);
fclose(fsrc);
return EXIT_FAILURE;
}
fprintf(stdout, "tile %d is decoded!\n\n", parameters.tile_index);
@@ -866,7 +849,6 @@ int main(int argc, char **argv)
/* Close the byte stream */
opj_stream_destroy(l_stream);
fclose(fsrc);
if(image->color_space == OPJ_CLRSPC_SYCC){
color_sycc_to_rgb(image); /* FIXME */
@@ -892,81 +874,81 @@ int main(int argc, char **argv)
switch (parameters.cod_format) {
case PXM_DFMT: /* PNM PGM PPM */
if (imagetopnm(image, parameters.outfile)) {
fprintf(stderr,"Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
}
break;
case PGX_DFMT: /* PGX */
if(imagetopgx(image, parameters.outfile)){
fprintf(stderr,"Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
}
break;
case BMP_DFMT: /* BMP */
if(imagetobmp(image, parameters.outfile)){
fprintf(stderr,"Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
}
break;
#ifdef OPJ_HAVE_LIBTIFF
case TIF_DFMT: /* TIFF */
if(imagetotif(image, parameters.outfile)){
fprintf(stderr,"Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
}
break;
#endif /* OPJ_HAVE_LIBTIFF */
case RAW_DFMT: /* RAW */
if(imagetoraw(image, parameters.outfile)){
fprintf(stderr,"Error generating raw file. Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"[ERROR] Error generating raw file. Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
}
break;
case RAWL_DFMT: /* RAWL */
if(imagetorawl(image, parameters.outfile)){
fprintf(stderr,"Error generating rawl file. Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"[ERROR] Error generating rawl file. Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
}
break;
case TGA_DFMT: /* TGA */
if(imagetotga(image, parameters.outfile)){
fprintf(stderr,"Error generating tga file. Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"[ERROR] Error generating tga file. Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
}
break;
#ifdef OPJ_HAVE_LIBPNG
case PNG_DFMT: /* PNG */
if(imagetopng(image, parameters.outfile)){
fprintf(stderr,"Error generating png file. Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"[ERROR] Error generating png file. Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
}
break;
#endif /* OPJ_HAVE_LIBPNG */
@@ -974,7 +956,7 @@ int main(int argc, char **argv)
* and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined
*/
default:
fprintf(stderr,"Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
@@ -990,6 +972,7 @@ int main(int argc, char **argv)
/* destroy the codestream index */
opj_destroy_cstr_index(&cstr_index);
if(failed) remove(parameters.outfile);
}
return failed ? EXIT_FAILURE : EXIT_SUCCESS;
}

View File

@@ -91,19 +91,14 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
/* -------------------------------------------------------------------------- */
static void decode_help_display(void) {
fprintf(stdout,"HELP for opj_dump\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n");
fprintf(stdout,"\nThis is the opj_dump utility from the OpenJPEG project.\n"
"It dumps JPEG 2000 codestream info to stdout or a given file.\n"
"It has been compiled against openjp2 library v%s.\n\n",opj_version());
/* UniPG>> */
fprintf(stdout,"List of parameters for the JPEG 2000 "
#ifdef USE_JPWL
"+ JPWL "
#endif /* USE_JPWL */
"decoder:\n");
/* <<UniPG */
fprintf(stdout,"\n");
fprintf(stdout,"\n");
fprintf(stdout," -ImgDir \n");
fprintf(stdout,"Parameters:\n");
fprintf(stdout,"-----------\n");
fprintf(stdout,"\n");
fprintf(stdout," -ImgDir <directory>\n");
fprintf(stdout," Image file Directory path \n");
fprintf(stdout," -i <compressed file>\n");
fprintf(stdout," REQUIRED only if an Input image directory not specified\n");
@@ -113,10 +108,10 @@ static void decode_help_display(void) {
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," -v "); /* FIXME WIP_MSD */
fprintf(stdout," -v "); /* FIXME WIP_MSD */
fprintf(stdout," OPTIONAL\n");
fprintf(stdout," Activate or not the verbose mode (display info and warning message)\n");
fprintf(stdout," By default verbose mode is off.\n");
fprintf(stdout," Enable informative messages\n");
fprintf(stdout," By default verbose mode is off.\n");
fprintf(stdout,"\n");
}
@@ -277,9 +272,9 @@ static int infile_format(const char *fname)
static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol) {
int totlen, c;
opj_option_t long_option[]={
{"ImgDir",REQ_ARG, NULL ,'y'},
{"ImgDir",REQ_ARG, NULL ,'y'}
};
const char optlist[] = "i:o:f:hv";
const char optlist[] = "i:o:f:hv";
totlen=sizeof(long_option);
img_fol->set_out_format = 0;
@@ -298,12 +293,13 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
case JP2_CFMT:
break;
case JPT_CFMT:
break;
default:
fprintf(stderr,
"!! Unrecognized format for infile : %s [accept only *.j2k, *.jp2, *.jpc or *.jpt] !!\n\n",
infile);
return 1;
break;
default:
fprintf(stderr,
"[ERROR] Unknown input file format: %s \n"
" Known file formats are *.j2k, *.jp2, *.jpc or *.jpt\n",
infile);
return 1;
}
strncpy(parameters->infile, infile, sizeof(parameters->infile)-1);
}
@@ -340,38 +336,40 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
/* ----------------------------------------------------- */
case 'v': /* Verbose mode */
case 'v': /* Verbose mode */
{
parameters->m_verbose = 1;
parameters->m_verbose = 1;
}
break;
/* ----------------------------------------------------- */
default:
fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, opj_optarg);
break;
}
default:
fprintf(stderr, "[WARNING] An invalid option has been ignored.\n");
break;
}
}while(c != -1);
/* check for possible errors */
if(img_fol->set_imgdir==1){
if(!(parameters->infile[0]==0)){
fprintf(stderr, "Error: options -ImgDir and -i cannot be used together !!\n");
fprintf(stderr, "[ERROR] options -ImgDir and -i cannot be used together.\n");
return 1;
}
if(img_fol->set_out_format == 0){
fprintf(stderr, "Error: When -ImgDir is used, -OutFor <FORMAT> must be used !!\n");
fprintf(stderr, "Only one format allowed! Valid format PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA!!\n");
fprintf(stderr, "[ERROR] When -ImgDir is used, -OutFor <FORMAT> must be used.\n");
fprintf(stderr, "Only one format allowed.\n"
"Valid format are PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA.\n");
return 1;
}
if(!(parameters->outfile[0] == 0)){
fprintf(stderr, "Error: options -ImgDir and -o cannot be used together !!\n");
fprintf(stderr, "[ERROR] options -ImgDir and -o cannot be used together\n");
return 1;
}
}else{
if(parameters->infile[0] == 0) {
fprintf(stderr, "[ERROR] Required parameter is missing\n");
fprintf(stderr, "Example: %s -i image.j2k\n",argv[0]);
fprintf(stderr, " Try: %s -h\n",argv[0]);
fprintf(stderr, " Help: %s -h\n",argv[0]);
return 1;
}
}
@@ -410,7 +408,7 @@ static void info_callback(const char *msg, void *client_data) {
/* -------------------------------------------------------------------------- */
int main(int argc, char *argv[])
{
FILE *fsrc = NULL, *fout = NULL;
FILE *fout = NULL;
opj_dparameters_t parameters; /* Decompression parameters */
opj_image_t* image = NULL; /* Image structure */
@@ -496,16 +494,10 @@ int main(int argc, char *argv[])
/* Read the input file and put it in memory */
/* ---------------------------------------- */
fsrc = fopen(parameters.infile, "rb");
if (!fsrc) {
fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile);
return EXIT_FAILURE;
}
l_stream = opj_stream_create_default_file_stream(fsrc,1);
l_stream = opj_stream_create_default_file_stream(parameters.infile,1);
if (!l_stream){
fclose(fsrc);
fprintf(stderr, "ERROR -> failed to create the stream from the file\n");
fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n",parameters.infile);
return EXIT_FAILURE;
}
@@ -546,7 +538,6 @@ int main(int argc, char *argv[])
if ( !opj_setup_decoder(l_codec, &parameters) ){
fprintf(stderr, "ERROR -> opj_dump: failed to setup the decoder\n");
opj_stream_destroy(l_stream);
fclose(fsrc);
opj_destroy_codec(l_codec);
fclose(fout);
return EXIT_FAILURE;
@@ -556,7 +547,6 @@ int main(int argc, char *argv[])
if(! opj_read_header(l_stream, l_codec, &image)){
fprintf(stderr, "ERROR -> opj_dump: failed to read the header\n");
opj_stream_destroy(l_stream);
fclose(fsrc);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
fclose(fout);
@@ -571,7 +561,6 @@ int main(int argc, char *argv[])
/* close the byte stream */
opj_stream_destroy(l_stream);
fclose(fsrc);
/* free remaining structures */
if (l_codec) {

View File

@@ -68,10 +68,12 @@ install(FILES openjpeg.h opj_stdint.h
DESTINATION ${OPENJPEG_INSTALL_INCLUDE_DIR} COMPONENT Headers
)
if(BUILD_DOC)
# install man page of the library
install(
FILES ${OPENJPEG_SOURCE_DIR}/doc/man/man3/libopenjp2.3
DESTINATION ${OPENJPEG_INSTALL_MAN_DIR}/man3)
endif()
# internal utilities to generate t1_luts.h (part of the jp2 lib)
# no need to install:
@@ -96,3 +98,13 @@ if(OPENJPEG_CPPCHECK)
COMMAND ${CPPCHECK_EXECUTABLE} -DWIN32 ${f})
endforeach()
endif()
if(OPJ_USE_DSYMUTIL)
if(BUILD_SHARED_LIBS)
GET_TARGET_PROPERTY(OPENJPEG_LIBRARY_LOCATION ${OPENJPEG_LIBRARY_NAME} LOCATION)
add_custom_command(TARGET ${OPENJPEG_LIBRARY_NAME} POST_BUILD
COMMAND "dsymutil" "${OPENJPEG_LIBRARY_LOCATION}"
COMMENT "dsymutil ${OPENJPEG_LIBRARY_LOCATION}"
DEPENDS ${OPENJPEG_LIBRARY_NAME})
endif()
endif()

View File

@@ -81,7 +81,7 @@ static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio);
OPJ_BOOL opj_bio_byteout(opj_bio_t *bio) {
bio->buf = (bio->buf << 8) & 0xffff;
bio->ct = bio->buf == 0xff00 ? 7 : 8;
if (bio->bp >= bio->end) {
if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) {
return OPJ_FALSE;
}
*bio->bp++ = (OPJ_BYTE)(bio->buf >> 8);
@@ -91,7 +91,7 @@ OPJ_BOOL opj_bio_byteout(opj_bio_t *bio) {
OPJ_BOOL opj_bio_bytein(opj_bio_t *bio) {
bio->buf = (bio->buf << 8) & 0xffff;
bio->ct = bio->buf == 0xff00 ? 7 : 8;
if (bio->bp >= bio->end) {
if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) {
return OPJ_FALSE;
}
bio->buf |= *bio->bp++;

View File

@@ -151,12 +151,11 @@ void opj_read_float_LE(const OPJ_BYTE * p_buffer, OPJ_FLOAT32 * p_value)
opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size,OPJ_BOOL l_is_input)
{
opj_stream_private_t * l_stream = 00;
l_stream = (opj_stream_private_t*) opj_malloc(sizeof(opj_stream_private_t));
l_stream = (opj_stream_private_t*) opj_calloc(1,sizeof(opj_stream_private_t));
if (! l_stream) {
return 00;
}
memset(l_stream,0,sizeof(opj_stream_private_t));
l_stream->m_buffer_size = p_buffer_size;
l_stream->m_stored_data = (OPJ_BYTE *) opj_malloc(p_buffer_size);
if (! l_stream->m_stored_data) {
@@ -195,6 +194,9 @@ void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream)
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
if (l_stream) {
if (l_stream->m_free_user_data_fn) {
l_stream->m_free_user_data_fn(l_stream->m_user_data);
}
opj_free(l_stream->m_stored_data);
l_stream->m_stored_data = 00;
opj_free(l_stream);
@@ -244,12 +246,13 @@ void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_strea
l_stream->m_skip_fn = p_function;
}
void OPJ_CALLCONV opj_stream_set_user_data(opj_stream_t* p_stream, void * p_data)
void OPJ_CALLCONV opj_stream_set_user_data(opj_stream_t* p_stream, void * p_data, opj_stream_free_user_data_fn p_function)
{
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
if (!l_stream)
return;
l_stream->m_user_data = p_data;
l_stream->m_free_user_data_fn = p_function;
}
void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream, OPJ_UINT64 data_length)

View File

@@ -49,7 +49,7 @@ The functions in CIO.C have for goal to realize a byte input / output process.
/** @defgroup CIO CIO - byte input-output stream */
/*@{*/
#include "opj_config.h"
#include "opj_config_private.h"
/* ----------------------------------------------------------------------- */
@@ -91,6 +91,13 @@ typedef struct opj_stream_private
*/
void * m_user_data;
/**
* Pointer to function to free m_user_data (NULL at initialization)
* when destroying the stream. If pointer is NULL the function is not
* called and the m_user_data is not freed (even if non-NULL).
*/
opj_stream_free_user_data_fn m_free_user_data_fn;
/**
* User data length
*/

View File

@@ -571,6 +571,7 @@ OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres, DWT1D
h.mem = (OPJ_INT32*)
opj_aligned_malloc(opj_dwt_max_resolution(tr, numres) * sizeof(OPJ_INT32));
if (! h.mem){
/* FIXME event manager error callback */
return OPJ_FALSE;
}
@@ -842,6 +843,10 @@ OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numr
OPJ_UINT32 w = (OPJ_UINT32)(tilec->x1 - tilec->x0);
h.wavelet = (opj_v4_t*) opj_aligned_malloc((opj_dwt_max_resolution(res, numres)+5) * sizeof(opj_v4_t));
if (!h.wavelet) {
/* FIXME event manager error callback */
return OPJ_FALSE;
}
v.wavelet = h.wavelet;
while( --numres) {

View File

@@ -39,22 +39,19 @@
opj_procedure_list_t * opj_procedure_list_create()
{
/* memory allocation */
opj_procedure_list_t * l_validation = (opj_procedure_list_t *) opj_malloc(sizeof(opj_procedure_list_t));
opj_procedure_list_t * l_validation = (opj_procedure_list_t *) opj_calloc(1,sizeof(opj_procedure_list_t));
if (! l_validation)
{
return 00;
}
/* initialization */
memset(l_validation,0,sizeof(opj_procedure_list_t));
l_validation->m_nb_max_procedures = OPJ_VALIDATION_SIZE;
l_validation->m_procedures = (opj_procedure*)opj_malloc(
OPJ_VALIDATION_SIZE * sizeof(opj_procedure));
l_validation->m_procedures = (opj_procedure*)opj_calloc(OPJ_VALIDATION_SIZE, sizeof(opj_procedure));
if (! l_validation->m_procedures)
{
opj_free(l_validation);
return 00;
}
memset(l_validation->m_procedures,0,OPJ_VALIDATION_SIZE * sizeof(opj_procedure));
return l_validation;
}

View File

@@ -205,21 +205,19 @@ opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_c
OPJ_UINT32 compno;
opj_image_t *image = 00;
image = (opj_image_t*) opj_malloc(sizeof(opj_image_t));
image = (opj_image_t*) opj_calloc(1,sizeof(opj_image_t));
if (image)
{
memset(image,0,sizeof(opj_image_t));
image->color_space = clrspc;
image->numcomps = numcmpts;
/* allocate memory for the per-component information */
image->comps = (opj_image_comp_t*)opj_malloc(image->numcomps * sizeof(opj_image_comp_t));
image->comps = (opj_image_comp_t*)opj_calloc(image->numcomps, sizeof(opj_image_comp_t));
if (!image->comps) {
opj_image_destroy(image);
return 00;
}
memset(image->comps,0,image->numcomps * sizeof(opj_image_comp_t));
/* create the individual image components */
for(compno = 0; compno < numcmpts; compno++) {

View File

@@ -42,11 +42,6 @@
#include "opj_includes.h"
#define CINEMA_24_CS 1302083 /*Codestream length for 24fps*/
#define CINEMA_48_CS 651041 /*Codestream length for 48fps*/
#define COMP_24_CS 1041666 /*Maximum size per color component for 2K & 4K @ 24fps*/
#define COMP_48_CS 520833 /*Maximum size per color component for 2K @ 48fps*/
/** @defgroup J2K J2K - JPEG-2000 codestream reader/writer */
/*@{*/
@@ -1172,7 +1167,7 @@ static int opj_j2k_initialise_4K_poc(opj_poc_t *POC, int numres);
static void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *image, opj_event_mgr_t *p_manager);
static OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_CINEMA_MODE cinema_mode, opj_event_mgr_t *p_manager);
static OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_UINT16 rsiz, opj_event_mgr_t *p_manager);
/*@}*/
@@ -1504,7 +1499,6 @@ OPJ_BOOL opj_j2k_check_poc_val( const opj_poc_t *p_pocs,
opj_event_msg(p_manager , EVT_ERROR, "Not enough memory for checking the poc values.\n");
return OPJ_FALSE;
}
memset(packet_array,0,step_l * p_num_layers* sizeof(OPJ_UINT32));
if (p_nb_pocs == 0) {
opj_free(packet_array);
@@ -1945,7 +1939,7 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k,
opj_read_bytes(p_header_data,&l_tmp ,2); /* Rsiz (capabilities) */
p_header_data+=2;
l_cp->rsiz = (OPJ_RSIZ_CAPABILITIES) l_tmp;
l_cp->rsiz = (OPJ_UINT16) l_tmp;
opj_read_bytes(p_header_data, (OPJ_UINT32*) &l_image->x1, 4); /* Xsiz */
p_header_data+=4;
opj_read_bytes(p_header_data, (OPJ_UINT32*) &l_image->y1, 4); /* Ysiz */
@@ -2043,7 +2037,6 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k,
return OPJ_FALSE;
}
memset(l_image->comps,0,l_image->numcomps * sizeof(opj_image_comp_t));
l_img_comp = l_image->comps;
/* Read the component information */
@@ -2066,13 +2059,6 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k,
i, l_img_comp->dx, l_img_comp->dy);
return OPJ_FALSE;
}
if( l_img_comp->dx < 1 || l_img_comp->dx > 255 ||
l_img_comp->dy < 1 || l_img_comp->dy > 255 ) {
opj_event_msg(p_manager, EVT_ERROR,
"Invalid values for comp = %d : dx=%u dy=%u\n (should be between 1 and 255 according the JPEG2000 norm)",
i, l_img_comp->dx, l_img_comp->dy);
return OPJ_FALSE;
}
#ifdef USE_JPWL
if (l_cp->correct) {
@@ -2110,14 +2096,6 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k,
l_cp->tw = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)(l_image->x1 - l_cp->tx0), (OPJ_INT32)l_cp->tdx);
l_cp->th = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)(l_image->y1 - l_cp->ty0), (OPJ_INT32)l_cp->tdy);
/* Check that the number of tiles is valid */
if (l_cp->tw == 0 || l_cp->th == 0 || l_cp->tw > 65535 / l_cp->th) {
opj_event_msg( p_manager, EVT_ERROR,
"Invalid number of tiles : %u x %u (maximum fixed by jpeg2000 norm is 65535 tiles)\n",
l_cp->tw, l_cp->th);
return OPJ_FALSE;
}
/* Check that the number of tiles is valid */
if (l_cp->tw == 0 || l_cp->th == 0 || l_cp->tw > 65535 / l_cp->th) {
opj_event_msg( p_manager, EVT_ERROR,
@@ -2187,7 +2165,6 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k,
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n");
return OPJ_FALSE;
}
memset(l_cp->tcps,0,l_nb_tiles*sizeof(opj_tcp_t));
#ifdef USE_JPWL
if (l_cp->correct) {
@@ -2208,27 +2185,24 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k,
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n");
return OPJ_FALSE;
}
memset(p_j2k->m_specific_param.m_decoder.m_default_tcp->tccps ,0,l_image->numcomps*sizeof(opj_tccp_t));
p_j2k->m_specific_param.m_decoder.m_default_tcp->m_mct_records =
(opj_mct_data_t*)opj_malloc(OPJ_J2K_MCT_DEFAULT_NB_RECORDS * sizeof(opj_mct_data_t));
(opj_mct_data_t*)opj_calloc(OPJ_J2K_MCT_DEFAULT_NB_RECORDS ,sizeof(opj_mct_data_t));
if (! p_j2k->m_specific_param.m_decoder.m_default_tcp->m_mct_records) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n");
return OPJ_FALSE;
}
memset(p_j2k->m_specific_param.m_decoder.m_default_tcp->m_mct_records,0,OPJ_J2K_MCT_DEFAULT_NB_RECORDS * sizeof(opj_mct_data_t));
p_j2k->m_specific_param.m_decoder.m_default_tcp->m_nb_max_mct_records = OPJ_J2K_MCT_DEFAULT_NB_RECORDS;
p_j2k->m_specific_param.m_decoder.m_default_tcp->m_mcc_records =
(opj_simple_mcc_decorrelation_data_t*)
opj_malloc(OPJ_J2K_MCC_DEFAULT_NB_RECORDS * sizeof(opj_simple_mcc_decorrelation_data_t));
opj_calloc(OPJ_J2K_MCC_DEFAULT_NB_RECORDS, sizeof(opj_simple_mcc_decorrelation_data_t));
if (! p_j2k->m_specific_param.m_decoder.m_default_tcp->m_mcc_records) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n");
return OPJ_FALSE;
}
memset(p_j2k->m_specific_param.m_decoder.m_default_tcp->m_mcc_records,0,OPJ_J2K_MCC_DEFAULT_NB_RECORDS * sizeof(opj_simple_mcc_decorrelation_data_t));
p_j2k->m_specific_param.m_decoder.m_default_tcp->m_nb_max_mcc_records = OPJ_J2K_MCC_DEFAULT_NB_RECORDS;
/* set up default dc level shift */
@@ -2240,12 +2214,11 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k,
l_current_tile_param = l_cp->tcps;
for (i = 0; i < l_nb_tiles; ++i) {
l_current_tile_param->tccps = (opj_tccp_t*) opj_malloc(l_image->numcomps * sizeof(opj_tccp_t));
l_current_tile_param->tccps = (opj_tccp_t*) opj_calloc(l_image->numcomps, sizeof(opj_tccp_t));
if (l_current_tile_param->tccps == 00) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n");
return OPJ_FALSE;
}
memset(l_current_tile_param->tccps,0,l_image->numcomps * sizeof(opj_tccp_t));
++l_current_tile_param;
}
@@ -2442,9 +2415,19 @@ static OPJ_BOOL opj_j2k_read_cod ( opj_j2k_t *p_j2k,
opj_read_bytes(p_header_data,&l_tcp->csty,1); /* Scod */
++p_header_data;
/* Make sure we know how to decode this */
if ((l_tcp->csty & ~(OPJ_UINT32)(J2K_CP_CSTY_PRT | J2K_CP_CSTY_SOP | J2K_CP_CSTY_EPH)) != 0U) {
opj_event_msg(p_manager, EVT_ERROR, "Unknown Scod value in COD marker\n");
return OPJ_FALSE;
}
opj_read_bytes(p_header_data,&l_tmp,1); /* SGcod (A) */
++p_header_data;
l_tcp->prg = (OPJ_PROG_ORDER) l_tmp;
/* Make sure progression order is valid */
if (l_tcp->prg > OPJ_CPRL ) {
opj_event_msg(p_manager, EVT_ERROR, "Unknown progression order in COD marker\n");
l_tcp->prg = OPJ_PROG_UNKNOWN;
}
opj_read_bytes(p_header_data,&l_tcp->numlayers,2); /* SGcod (B) */
p_header_data+=2;
@@ -3117,7 +3100,7 @@ OPJ_UINT32 opj_j2k_get_specific_header_sizes(opj_j2k_t *p_j2k)
l_nb_comps = p_j2k->m_private_image->numcomps - 1;
l_nb_bytes += opj_j2k_get_max_toc_size(p_j2k);
if (p_j2k->m_cp.m_specific_param.m_enc.m_cinema == 0) {
if (!(OPJ_IS_CINEMA(p_j2k->m_cp.rsiz))) {
l_coc_bytes = opj_j2k_get_max_coc_size(p_j2k);
l_nb_bytes += l_nb_comps * l_coc_bytes;
@@ -3571,6 +3554,14 @@ OPJ_BOOL j2k_read_ppm_v3 (
/* First PPM marker */
if (l_Z_ppm == 0) {
if (l_cp->ppm_data != NULL) {
opj_event_msg(p_manager, EVT_ERROR, "Zppm O already processed. Found twice.\n");
opj_free(l_cp->ppm_data);
l_cp->ppm_data = NULL;
l_cp->ppm_buffer = NULL;
l_cp->ppm = 0; /* do not use PPM */
return OPJ_FALSE;
}
/* We need now at least the Nppm^0 element */
if (p_header_size < 4) {
opj_event_msg(p_manager, EVT_ERROR, "Error reading PPM marker\n");
@@ -3596,13 +3587,12 @@ OPJ_BOOL j2k_read_ppm_v3 (
l_cp->ppm_len = l_N_ppm;
l_cp->ppm_data_read = 0;
l_cp->ppm_data = (OPJ_BYTE *) opj_malloc(l_cp->ppm_len);
l_cp->ppm_data = (OPJ_BYTE *) opj_calloc(1,l_cp->ppm_len);
l_cp->ppm_buffer = l_cp->ppm_data;
if (l_cp->ppm_data == 00) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read ppm marker\n");
return OPJ_FALSE;
}
memset(l_cp->ppm_data,0,l_cp->ppm_len);
l_cp->ppm_data_current = l_cp->ppm_data;
@@ -3669,6 +3659,15 @@ OPJ_BOOL j2k_read_ppm_v3 (
if (p_header_size)
{
if (p_header_size < 4) {
opj_free(l_cp->ppm_data);
l_cp->ppm_data = NULL;
l_cp->ppm_buffer = NULL; /* TODO: no need for a new local variable: ppm_buffer and ppm_data are enough */
l_cp->ppm_len = 0;
l_cp->ppm = 0;
opj_event_msg(p_manager, EVT_ERROR, "Error reading PPM marker\n");
return OPJ_FALSE;
}
opj_read_bytes(p_header_data,&l_N_ppm,4); /* N_ppm^i */
p_header_data+=4;
p_header_size-=4;
@@ -4148,6 +4147,10 @@ OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k,
if (!p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index) {
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index =
(opj_tp_index_t*)opj_calloc(l_num_parts, sizeof(opj_tp_index_t));
if (!p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read SOT marker. Tile index allocation failed\n");
return OPJ_FALSE;
}
}
else {
opj_tp_index_t *new_tp_index = (opj_tp_index_t *) opj_realloc(
@@ -4155,7 +4158,7 @@ OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k,
if (! new_tp_index) {
opj_free(p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index);
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read PPT marker\n");
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read SOT marker. Tile index allocation failed\n");
return OPJ_FALSE;
}
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = new_tp_index;
@@ -4169,6 +4172,11 @@ OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k,
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index =
(opj_tp_index_t*)opj_calloc( p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps,
sizeof(opj_tp_index_t));
if (!p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index) {
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps = 0;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read SOT marker. Tile index allocation failed\n");
return OPJ_FALSE;
}
}
if ( l_current_part >= p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps ){
@@ -4181,7 +4189,7 @@ OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k,
opj_free(p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index);
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = NULL;
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps = 0;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read PPT marker\n");
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read SOT marker. Tile index allocation failed\n");
return OPJ_FALSE;
}
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = new_tp_index;
@@ -4336,6 +4344,12 @@ OPJ_BOOL opj_j2k_read_sod (opj_j2k_t *p_j2k,
/* Patch to support new PHR data */
if (p_j2k->m_specific_param.m_decoder.m_sot_length) {
/* If we are here, we'll try to read the data after allocation */
/* Check enough bytes left in stream before allocation */
if ((OPJ_OFF_T)p_j2k->m_specific_param.m_decoder.m_sot_length > opj_stream_get_number_byte_left(p_stream)) {
opj_event_msg(p_manager, EVT_ERROR, "Tile part length size inconsistent with stream length\n");
return OPJ_FALSE;
}
if (! *l_current_data) {
/* LH: oddly enough, in this path, l_tile_len!=0.
* TODO: If this was consistant, we could simplify the code to only use realloc(), as realloc(0,...) default to malloc(0,...).
@@ -4737,7 +4751,7 @@ OPJ_BOOL opj_j2k_update_rates( opj_j2k_t *p_j2k,
return OPJ_FALSE;
}
if (l_cp->m_specific_param.m_enc.m_cinema) {
if (OPJ_IS_CINEMA(l_cp->rsiz)) {
p_j2k->m_specific_param.m_encoder.m_tlm_sot_offsets_buffer =
(OPJ_BYTE *) opj_malloc(5*p_j2k->m_specific_param.m_encoder.m_total_tile_parts);
if (! p_j2k->m_specific_param.m_encoder.m_tlm_sot_offsets_buffer) {
@@ -5873,12 +5887,11 @@ void opj_j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters)
opj_j2k_t* opj_j2k_create_compress(void)
{
opj_j2k_t *l_j2k = (opj_j2k_t*) opj_malloc(sizeof(opj_j2k_t));
opj_j2k_t *l_j2k = (opj_j2k_t*) opj_calloc(1,sizeof(opj_j2k_t));
if (!l_j2k) {
return NULL;
}
memset(l_j2k,0,sizeof(opj_j2k_t));
l_j2k->m_is_decoder = 0;
l_j2k->m_cp.m_is_decoder = 0;
@@ -5929,24 +5942,8 @@ int opj_j2k_initialise_4K_poc(opj_poc_t *POC, int numres){
void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *image, opj_event_mgr_t *p_manager)
{
/* Configure cinema parameters */
OPJ_FLOAT32 max_rate = 0;
OPJ_FLOAT32 temp_rate = 0;
int i;
/* profile (Rsiz) */
switch (parameters->cp_cinema){
case OPJ_CINEMA2K_24:
case OPJ_CINEMA2K_48:
parameters->cp_rsiz = OPJ_CINEMA2K;
break;
case OPJ_CINEMA4K_24:
parameters->cp_rsiz = OPJ_CINEMA4K;
break;
case OPJ_OFF:
assert(0);
break;
}
/* No tiling */
parameters->tile_size_on = OPJ_FALSE;
parameters->cp_tdx=1;
@@ -5984,15 +5981,16 @@ void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *i
opj_event_msg(p_manager, EVT_WARNING,
"JPEG 2000 Profile-3 and 4 (2k/4k dc profile) requires:\n"
"1 single quality layer"
"-> Number of layers forced to 1 (rather than %d)\n",
parameters->tcp_numlayers);
"-> Number of layers forced to 1 (rather than %d)\n"
"-> Rate of the last layer (%3.1f) will be used",
parameters->tcp_numlayers, parameters->tcp_rates[parameters->tcp_numlayers-1]);
parameters->tcp_rates[0] = parameters->tcp_rates[parameters->tcp_numlayers-1];
parameters->tcp_numlayers = 1;
}
/* Resolution levels */
switch (parameters->cp_cinema){
case OPJ_CINEMA2K_24:
case OPJ_CINEMA2K_48:
switch (parameters->rsiz){
case OPJ_PROFILE_CINEMA_2K:
if(parameters->numresolution > 6){
opj_event_msg(p_manager, EVT_WARNING,
"JPEG 2000 Profile-3 (2k dc profile) requires:\n"
@@ -6002,7 +6000,7 @@ void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *i
parameters->numresolution = 6;
}
break;
case OPJ_CINEMA4K_24:
case OPJ_PROFILE_CINEMA_4K:
if(parameters->numresolution < 2){
opj_event_msg(p_manager, EVT_WARNING,
"JPEG 2000 Profile-4 (4k dc profile) requires:\n"
@@ -6035,7 +6033,7 @@ void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *i
parameters->prog_order = OPJ_CPRL;
/* Progression order changes for 4K, disallowed for 2K */
if (parameters->cp_cinema == OPJ_CINEMA4K_24) {
if (parameters->rsiz == OPJ_PROFILE_CINEMA_4K) {
parameters->numpocs = (OPJ_UINT32)opj_j2k_initialise_4K_poc(parameters->POC,parameters->numresolution);
} else {
parameters->numpocs = 0;
@@ -6043,62 +6041,42 @@ void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *i
/* Limited bit-rate */
parameters->cp_disto_alloc = 1;
switch (parameters->cp_cinema){
case OPJ_CINEMA2K_24:
case OPJ_CINEMA4K_24:
max_rate = (OPJ_FLOAT32) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)/
(OPJ_FLOAT32)(CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy);
if (parameters->tcp_rates[0] == 0){
parameters->tcp_rates[0] = max_rate;
}else{
temp_rate =(OPJ_FLOAT32)(image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)/
(parameters->tcp_rates[0] * 8 * (OPJ_FLOAT32)image->comps[0].dx * (OPJ_FLOAT32)image->comps[0].dy);
if (temp_rate > CINEMA_24_CS ){
opj_event_msg(p_manager, EVT_WARNING,
"JPEG 2000 Profile-3 and 4 (2k/4k dc profile) requires:\n"
"Maximum 1302083 compressed bytes @ 24fps\n"
"-> Specified rate (%3.1f) exceeds this limit. Rate will be forced to %3.1f.\n",
parameters->tcp_rates[0], max_rate);
parameters->tcp_rates[0]= max_rate;
}else{
opj_event_msg(p_manager, EVT_WARNING,
"JPEG 2000 Profile-3 and 4 (2k/4k dc profile):\n"
"INFO : Specified rate (%3.1f) is below the 2k/4k limit @ 24fps.\n",
parameters->tcp_rates[0]);
}
}
parameters->max_comp_size = COMP_24_CS;
break;
case OPJ_CINEMA2K_48:
max_rate = ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
(float)(CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy);
if (parameters->tcp_rates[0] == 0){
parameters->tcp_rates[0] = max_rate;
}else{
temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
(parameters->tcp_rates[0] * 8 * (float)image->comps[0].dx * (float)image->comps[0].dy);
if (temp_rate > CINEMA_48_CS ){
opj_event_msg(p_manager, EVT_WARNING,
"JPEG 2000 Profile-3 (2k dc profile) requires:\n"
"Maximum 651041 compressed bytes @ 48fps\n"
"-> Specified rate (%3.1f) exceeds this limit. Rate will be forced to %3.1f.\n",
parameters->tcp_rates[0], max_rate);
parameters->tcp_rates[0]= max_rate;
}else{
opj_event_msg(p_manager, EVT_WARNING,
"JPEG 2000 Profile-3 (2k dc profile):\n"
"INFO : Specified rate (%3.1f) is below the 2k limit @ 48 fps.\n",
parameters->tcp_rates[0]);
}
}
parameters->max_comp_size = COMP_48_CS;
break;
default:
break;
if (parameters->max_cs_size <= 0) {
/* No rate has been introduced, 24 fps is assumed */
parameters->max_cs_size = OPJ_CINEMA_24_CS;
opj_event_msg(p_manager, EVT_WARNING,
"JPEG 2000 Profile-3 and 4 (2k/4k dc profile) requires:\n"
"Maximum 1302083 compressed bytes @ 24fps\n"
"As no rate has been given, this limit will be used.\n");
} else if (parameters->max_cs_size > OPJ_CINEMA_24_CS) {
opj_event_msg(p_manager, EVT_WARNING,
"JPEG 2000 Profile-3 and 4 (2k/4k dc profile) requires:\n"
"Maximum 1302083 compressed bytes @ 24fps\n"
"-> Specified rate exceeds this limit. Rate will be forced to 1302083 bytes.\n");
parameters->max_cs_size = OPJ_CINEMA_24_CS;
}
if (parameters->max_comp_size <= 0) {
/* No rate has been introduced, 24 fps is assumed */
parameters->max_comp_size = OPJ_CINEMA_24_COMP;
opj_event_msg(p_manager, EVT_WARNING,
"JPEG 2000 Profile-3 and 4 (2k/4k dc profile) requires:\n"
"Maximum 1041666 compressed bytes @ 24fps\n"
"As no rate has been given, this limit will be used.\n");
} else if (parameters->max_comp_size > OPJ_CINEMA_24_COMP) {
opj_event_msg(p_manager, EVT_WARNING,
"JPEG 2000 Profile-3 and 4 (2k/4k dc profile) requires:\n"
"Maximum 1041666 compressed bytes @ 24fps\n"
"-> Specified rate exceeds this limit. Rate will be forced to 1041666 bytes.\n");
parameters->max_comp_size = OPJ_CINEMA_24_COMP;
}
parameters->tcp_rates[0] = (OPJ_FLOAT32) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)/
(OPJ_FLOAT32)(((OPJ_UINT32)parameters->max_cs_size) * 8 * image->comps[0].dx * image->comps[0].dy);
}
OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_CINEMA_MODE cinema_mode, opj_event_mgr_t *p_manager)
OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_UINT16 rsiz, opj_event_mgr_t *p_manager)
{
OPJ_UINT32 i;
@@ -6130,9 +6108,8 @@ OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_CINEMA_MODE cinema_
}
/* Image size */
switch (cinema_mode){
case OPJ_CINEMA2K_24:
case OPJ_CINEMA2K_48:
switch (rsiz){
case OPJ_PROFILE_CINEMA_2K:
if (((image->comps[0].w > 2048) | (image->comps[0].h > 1080))){
opj_event_msg(p_manager, EVT_WARNING,
"JPEG 2000 Profile-3 (2k dc profile) requires:\n"
@@ -6143,7 +6120,7 @@ OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_CINEMA_MODE cinema_
return OPJ_FALSE;
}
break;
case OPJ_CINEMA4K_24:
case OPJ_PROFILE_CINEMA_4K:
if (((image->comps[0].w > 4096) | (image->comps[0].h > 2160))){
opj_event_msg(p_manager, EVT_WARNING,
"JPEG 2000 Profile-4 (4k dc profile) requires:\n"
@@ -6161,7 +6138,7 @@ OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_CINEMA_MODE cinema_
return OPJ_TRUE;
}
void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
OPJ_BOOL opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
opj_cparameters_t *parameters,
opj_image_t *image,
opj_event_mgr_t * p_manager)
@@ -6170,7 +6147,12 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
opj_cp_t *cp = 00;
if(!p_j2k || !parameters || ! image) {
return;
return OPJ_FALSE;
}
if ((parameters->numresolution <= 0) || (parameters->numresolution > OPJ_J2K_MAXRLVLS)) {
opj_event_msg(p_manager, EVT_ERROR, "Invalid number of resolutions : %d not in range [1,%d]\n", parameters->numresolution, OPJ_J2K_MAXRLVLS);
return OPJ_FALSE;
}
/* keep a link to cp so that we can destroy it later in j2k_destroy_compress */
@@ -6180,20 +6162,130 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
cp->tw = 1;
cp->th = 1;
/* FIXME ADE: to be removed once deprecated cp_cinema and cp_rsiz have been removed */
if (parameters->rsiz == OPJ_PROFILE_NONE) { /* consider deprecated fields only if RSIZ has not been set */
OPJ_BOOL deprecated_used = OPJ_FALSE;
switch (parameters->cp_cinema){
case OPJ_CINEMA2K_24:
parameters->rsiz = OPJ_PROFILE_CINEMA_2K;
parameters->max_cs_size = OPJ_CINEMA_24_CS;
parameters->max_comp_size = OPJ_CINEMA_24_COMP;
deprecated_used = OPJ_TRUE;
break;
case OPJ_CINEMA2K_48:
parameters->rsiz = OPJ_PROFILE_CINEMA_2K;
parameters->max_cs_size = OPJ_CINEMA_48_CS;
parameters->max_comp_size = OPJ_CINEMA_48_COMP;
deprecated_used = OPJ_TRUE;
break;
case OPJ_CINEMA4K_24:
parameters->rsiz = OPJ_PROFILE_CINEMA_4K;
parameters->max_cs_size = OPJ_CINEMA_24_CS;
parameters->max_comp_size = OPJ_CINEMA_24_COMP;
deprecated_used = OPJ_TRUE;
break;
case OPJ_OFF:
default:
break;
}
switch (parameters->cp_rsiz){
case OPJ_CINEMA2K:
parameters->rsiz = OPJ_PROFILE_CINEMA_2K;
deprecated_used = OPJ_TRUE;
break;
case OPJ_CINEMA4K:
parameters->rsiz = OPJ_PROFILE_CINEMA_4K;
deprecated_used = OPJ_TRUE;
break;
case OPJ_MCT:
parameters->rsiz = OPJ_PROFILE_PART2 | OPJ_EXTENSION_MCT;
deprecated_used = OPJ_TRUE;
case OPJ_STD_RSIZ:
default:
break;
}
if (deprecated_used) {
opj_event_msg(p_manager, EVT_WARNING,
"Deprecated fields cp_cinema or cp_rsiz are used\n"
"Please consider using only the rsiz field\n"
"See openjpeg.h documentation for more details\n");
}
}
/* see if max_codestream_size does limit input rate */
if (parameters->max_cs_size <= 0) {
if (parameters->tcp_rates[parameters->tcp_numlayers-1] > 0) {
OPJ_FLOAT32 temp_size;
temp_size =(OPJ_FLOAT32)(image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)/
(parameters->tcp_rates[parameters->tcp_numlayers-1] * 8 * (OPJ_FLOAT32)image->comps[0].dx * (OPJ_FLOAT32)image->comps[0].dy);
parameters->max_cs_size = (int) floor(temp_size);
} else {
parameters->max_cs_size = 0;
}
} else {
OPJ_FLOAT32 temp_rate;
OPJ_BOOL cap = OPJ_FALSE;
temp_rate = (OPJ_FLOAT32) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)/
(OPJ_FLOAT32)(((OPJ_UINT32)parameters->max_cs_size) * 8 * image->comps[0].dx * image->comps[0].dy);
for (i = 0; i < (OPJ_UINT32) parameters->tcp_numlayers; i++) {
if (parameters->tcp_rates[i] < temp_rate) {
parameters->tcp_rates[i] = temp_rate;
cap = OPJ_TRUE;
}
}
if (cap) {
opj_event_msg(p_manager, EVT_WARNING,
"The desired maximum codestream size has limited\n"
"at least one of the desired quality layers\n");
}
}
/* Manage profiles and applications and set RSIZ */
/* set cinema parameters if required */
if (parameters->cp_cinema){
opj_j2k_set_cinema_parameters(parameters,image,p_manager);
if (!opj_j2k_is_cinema_compliant(image,parameters->cp_cinema,p_manager)) {
parameters->cp_rsiz = OPJ_STD_RSIZ;
if (OPJ_IS_CINEMA(parameters->rsiz)){
if ((parameters->rsiz == OPJ_PROFILE_CINEMA_S2K)
|| (parameters->rsiz == OPJ_PROFILE_CINEMA_S4K)){
opj_event_msg(p_manager, EVT_WARNING,
"JPEG 2000 Scalable Digital Cinema profiles not yet supported\n");
parameters->rsiz = OPJ_PROFILE_NONE;
} else {
opj_j2k_set_cinema_parameters(parameters,image,p_manager);
if (!opj_j2k_is_cinema_compliant(image,parameters->rsiz,p_manager)) {
parameters->rsiz = OPJ_PROFILE_NONE;
}
}
} else if (OPJ_IS_STORAGE(parameters->rsiz)) {
opj_event_msg(p_manager, EVT_WARNING,
"JPEG 2000 Long Term Storage profile not yet supported\n");
parameters->rsiz = OPJ_PROFILE_NONE;
} else if (OPJ_IS_BROADCAST(parameters->rsiz)) {
opj_event_msg(p_manager, EVT_WARNING,
"JPEG 2000 Broadcast profiles not yet supported\n");
parameters->rsiz = OPJ_PROFILE_NONE;
} else if (OPJ_IS_IMF(parameters->rsiz)) {
opj_event_msg(p_manager, EVT_WARNING,
"JPEG 2000 IMF profiles not yet supported\n");
parameters->rsiz = OPJ_PROFILE_NONE;
} else if (OPJ_IS_PART2(parameters->rsiz)) {
if (parameters->rsiz == ((OPJ_PROFILE_PART2) | (OPJ_EXTENSION_NONE))) {
opj_event_msg(p_manager, EVT_WARNING,
"JPEG 2000 Part-2 profile defined\n"
"but no Part-2 extension enabled.\n"
"Profile set to NONE.\n");
parameters->rsiz = OPJ_PROFILE_NONE;
} else if (parameters->rsiz != ((OPJ_PROFILE_PART2) | (OPJ_EXTENSION_MCT))) {
opj_event_msg(p_manager, EVT_WARNING,
"Unsupported Part-2 extension enabled\n"
"Profile set to NONE.\n");
parameters->rsiz = OPJ_PROFILE_NONE;
}
}
/*
copy user encoding parameters
*/
cp->m_specific_param.m_enc.m_cinema = parameters->cp_cinema;
cp->m_specific_param.m_enc.m_max_comp_size = (OPJ_UINT32)parameters->max_comp_size;
cp->rsiz = parameters->cp_rsiz;
cp->rsiz = parameters->rsiz;
cp->m_specific_param.m_enc.m_disto_alloc = (OPJ_UINT32)parameters->cp_disto_alloc & 1u;
cp->m_specific_param.m_enc.m_fixed_alloc = (OPJ_UINT32)parameters->cp_fixed_alloc & 1u;
cp->m_specific_param.m_enc.m_fixed_quality = (OPJ_UINT32)parameters->cp_fixed_quality & 1u;
@@ -6202,6 +6294,10 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
if (parameters->cp_fixed_alloc && parameters->cp_matrice) {
size_t array_size = (size_t)parameters->tcp_numlayers * (size_t)parameters->numresolution * 3 * sizeof(OPJ_INT32);
cp->m_specific_param.m_enc.m_matrice = (OPJ_INT32 *) opj_malloc(array_size);
if (!cp->m_specific_param.m_enc.m_matrice) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate copy of user encoding parameters matrix \n");
return OPJ_FALSE;
}
memcpy(cp->m_specific_param.m_enc.m_matrice, parameters->cp_matrice, array_size);
}
@@ -6215,11 +6311,36 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
/* comment string */
if(parameters->cp_comment) {
cp->comment = (char*)opj_malloc(strlen(parameters->cp_comment) + 1);
if(cp->comment) {
strcpy(cp->comment, parameters->cp_comment);
}
}
cp->comment = (char*)opj_malloc(strlen(parameters->cp_comment) + 1U);
if(!cp->comment) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate copy of comment string\n");
return OPJ_FALSE;
}
strcpy(cp->comment, parameters->cp_comment);
} else {
/* Create default comment for codestream */
const char comment[] = "Created by OpenJPEG version ";
const size_t clen = strlen(comment);
const char *version = opj_version();
/* UniPG>> */
#ifdef USE_JPWL
cp->comment = (char*)opj_malloc(clen+strlen(version)+11);
if(!cp->comment) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate comment string\n");
return OPJ_FALSE;
}
sprintf(cp->comment,"%s%s with JPWL", comment, version);
#else
cp->comment = (char*)opj_malloc(clen+strlen(version)+1);
if(!cp->comment) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate comment string\n");
return OPJ_FALSE;
}
sprintf(cp->comment,"%s%s", comment, version);
#endif
/* <<UniPG */
}
/*
calculate other encoding parameters
@@ -6297,6 +6418,10 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
/* initialize the mutiple tiles */
/* ---------------------------- */
cp->tcps = (opj_tcp_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_t));
if (!cp->tcps) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate tile coding parameters\n");
return OPJ_FALSE;
}
if (parameters->numpocs) {
/* initialisation of POC */
opj_j2k_check_poc_val(parameters->POC,parameters->numpocs, (OPJ_UINT32)parameters->numresolution, image->numcomps, (OPJ_UINT32)parameters->tcp_numlayers, p_manager);
@@ -6308,7 +6433,7 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
tcp->numlayers = (OPJ_UINT32)parameters->tcp_numlayers;
for (j = 0; j < tcp->numlayers; j++) {
if(cp->m_specific_param.m_enc.m_cinema){
if(OPJ_IS_CINEMA(cp->rsiz)){
if (cp->m_specific_param.m_enc.m_fixed_quality) {
tcp->distoratio[j] = parameters->tcp_distoratio[j];
}
@@ -6354,24 +6479,54 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
}
tcp->tccps = (opj_tccp_t*) opj_calloc(image->numcomps, sizeof(opj_tccp_t));
if (!tcp->tccps) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate tile component coding parameters\n");
return OPJ_FALSE;
}
if (parameters->mct_data) {
OPJ_UINT32 lMctSize = image->numcomps * image->numcomps * (OPJ_UINT32)sizeof(OPJ_FLOAT32);
OPJ_FLOAT32 * lTmpBuf = (OPJ_FLOAT32*)opj_malloc(lMctSize);
OPJ_INT32 * l_dc_shift = (OPJ_INT32 *) ((OPJ_BYTE *) parameters->mct_data + lMctSize);
if (!lTmpBuf) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate temp buffer\n");
return OPJ_FALSE;
}
tcp->mct = 2;
tcp->m_mct_coding_matrix = (OPJ_FLOAT32*)opj_malloc(lMctSize);
if (! tcp->m_mct_coding_matrix) {
opj_free(lTmpBuf);
lTmpBuf = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate encoder MCT coding matrix \n");
return OPJ_FALSE;
}
memcpy(tcp->m_mct_coding_matrix,parameters->mct_data,lMctSize);
memcpy(lTmpBuf,parameters->mct_data,lMctSize);
tcp->m_mct_decoding_matrix = (OPJ_FLOAT32*)opj_malloc(lMctSize);
assert(opj_matrix_inversion_f(lTmpBuf,(tcp->m_mct_decoding_matrix),image->numcomps));
if (! tcp->m_mct_decoding_matrix) {
opj_free(lTmpBuf);
lTmpBuf = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate encoder MCT decoding matrix \n");
return OPJ_FALSE;
}
if(opj_matrix_inversion_f(lTmpBuf,(tcp->m_mct_decoding_matrix),image->numcomps) == OPJ_FALSE) {
opj_free(lTmpBuf);
lTmpBuf = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Failed to inverse encoder MCT decoding matrix \n");
return OPJ_FALSE;
}
tcp->mct_norms = (OPJ_FLOAT64*)
opj_malloc(image->numcomps * sizeof(OPJ_FLOAT64));
if (! tcp->mct_norms) {
opj_free(lTmpBuf);
lTmpBuf = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate encoder MCT norms \n");
return OPJ_FALSE;
}
opj_calculate_norms(tcp->mct_norms,image->numcomps,tcp->m_mct_decoding_matrix);
opj_free(lTmpBuf);
@@ -6380,9 +6535,22 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
tccp->m_dc_level_shift = l_dc_shift[i];
}
opj_j2k_setup_mct_encoding(tcp,image);
if (opj_j2k_setup_mct_encoding(tcp,image) == OPJ_FALSE) {
/* free will be handled by opj_j2k_destroy */
opj_event_msg(p_manager, EVT_ERROR, "Failed to setup j2k mct encoding\n");
return OPJ_FALSE;
}
}
else {
if(tcp->mct==1 && image->numcomps == 3) { /* RGB->YCC MCT is enabled */
if ((image->comps[0].dx != image->comps[1].dx) ||
(image->comps[0].dx != image->comps[2].dx) ||
(image->comps[0].dy != image->comps[1].dy) ||
(image->comps[0].dy != image->comps[2].dy)) {
opj_event_msg(p_manager, EVT_WARNING, "Cannot perform MCT on components with different sizes. Disabling MCT.\n");
tcp->mct = 0;
}
}
for (i = 0; i < image->numcomps; i++) {
opj_tccp_t *tccp = &tcp->tccps[i];
opj_image_comp_t * l_comp = &(image->comps[i]);
@@ -6469,6 +6637,7 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
opj_free(parameters->mct_data);
parameters->mct_data = 00;
}
return OPJ_TRUE;
}
static OPJ_BOOL opj_j2k_add_mhmarker(opj_codestream_index_t *cstr_index, OPJ_UINT32 type, OPJ_OFF_T pos, OPJ_UINT32 len)
@@ -6861,6 +7030,15 @@ OPJ_BOOL opj_j2k_encoding_validation ( opj_j2k_t * p_j2k,
/* make sure a validation list is present */
l_is_valid &= (p_j2k->m_validation_list != 00);
/* ISO 15444-1:2004 states between 1 & 33 (0 -> 32) */
/* 33 (32) would always fail the 2 checks below (if a cast to 64bits was done) */
/* 32 (31) would always fail the 2 checks below (if a cast to 64bits was done) */
/* FIXME Shall we change OPJ_J2K_MAXRLVLS to 31 ? */
if ((p_j2k->m_cp.tcps->tccps->numresolutions <= 0) || (p_j2k->m_cp.tcps->tccps->numresolutions > 31)) {
opj_event_msg(p_manager, EVT_ERROR, "Number of resolutions is too high in comparison to the size of tiles\n");
return OPJ_FALSE;
}
if ((p_j2k->m_cp.tdx) < (OPJ_UINT32) (1 << p_j2k->m_cp.tcps->tccps->numresolutions)) {
opj_event_msg(p_manager, EVT_ERROR, "Number of resolutions is too high in comparison to the size of tiles\n");
return OPJ_FALSE;
@@ -6912,6 +7090,9 @@ OPJ_BOOL opj_j2k_read_header_procedure( opj_j2k_t *p_j2k,
OPJ_UINT32 l_current_marker;
OPJ_UINT32 l_marker_size;
const opj_dec_memory_marker_handler_t * l_marker_handler = 00;
OPJ_BOOL l_has_siz = 0;
OPJ_BOOL l_has_cod = 0;
OPJ_BOOL l_has_qcd = 0;
/* preconditions */
assert(p_stream != 00);
@@ -6961,6 +7142,19 @@ OPJ_BOOL opj_j2k_read_header_procedure( opj_j2k_t *p_j2k,
l_marker_handler = opj_j2k_get_marker_handler(l_current_marker);
}
if (l_marker_handler->id == J2K_MS_SIZ) {
/* Mark required SIZ marker as found */
l_has_siz = 1;
}
if (l_marker_handler->id == J2K_MS_COD) {
/* Mark required COD marker as found */
l_has_cod = 1;
}
if (l_marker_handler->id == J2K_MS_QCD) {
/* Mark required QCD marker as found */
l_has_qcd = 1;
}
/* Check if the marker is known and if it is the right place to find it */
if (! (p_j2k->m_specific_param.m_decoder.m_state & l_marker_handler->states) ) {
opj_event_msg(p_manager, EVT_ERROR, "Marker is not compliant with its position\n");
@@ -7023,6 +7217,19 @@ OPJ_BOOL opj_j2k_read_header_procedure( opj_j2k_t *p_j2k,
opj_read_bytes(p_j2k->m_specific_param.m_decoder.m_header_data,&l_current_marker,2);
}
if (l_has_siz == 0) {
opj_event_msg(p_manager, EVT_ERROR, "required SIZ marker not found in main header\n");
return OPJ_FALSE;
}
if (l_has_cod == 0) {
opj_event_msg(p_manager, EVT_ERROR, "required COD marker not found in main header\n");
return OPJ_FALSE;
}
if (l_has_qcd == 0) {
opj_event_msg(p_manager, EVT_ERROR, "required QCD marker not found in main header\n");
return OPJ_FALSE;
}
opj_event_msg(p_manager, EVT_INFO, "Main header has been correctly decoded.\n");
/* Position of the last element if the main header */
@@ -7459,6 +7666,12 @@ OPJ_BOOL opj_j2k_read_tile_header( opj_j2k_t * p_j2k,
/* Read 2 bytes from the buffer as the marker size */
opj_read_bytes(p_j2k->m_specific_param.m_decoder.m_header_data,&l_marker_size,2);
/* Check marker size (does not include marker ID but includes marker size) */
if (l_marker_size < 2) {
opj_event_msg(p_manager, EVT_ERROR, "Inconsistent marker size\n");
return OPJ_FALSE;
}
/* cf. https://code.google.com/p/openjpeg/issues/detail?id=226 */
if (l_current_marker == 0x8080 && opj_stream_get_number_byte_left(p_stream) == 0) {
p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_NEOC;
@@ -7483,7 +7696,14 @@ OPJ_BOOL opj_j2k_read_tile_header( opj_j2k_t * p_j2k,
/* Check if the marker size is compatible with the header data size */
if (l_marker_size > p_j2k->m_specific_param.m_decoder.m_header_data_size) {
OPJ_BYTE *new_header_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_decoder.m_header_data, l_marker_size);
OPJ_BYTE *new_header_data = NULL;
/* If we are here, this means we consider this marker as known & we will read it */
/* Check enough bytes left in stream before allocation */
if ((OPJ_OFF_T)l_marker_size > opj_stream_get_number_byte_left(p_stream)) {
opj_event_msg(p_manager, EVT_ERROR, "Marker size inconsistent with stream length\n");
return OPJ_FALSE;
}
new_header_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_decoder.m_header_data, l_marker_size);
if (! new_header_data) {
opj_free(p_j2k->m_specific_param.m_decoder.m_header_data);
p_j2k->m_specific_param.m_decoder.m_header_data = NULL;
@@ -7619,7 +7839,7 @@ OPJ_BOOL opj_j2k_read_tile_header( opj_j2k_t * p_j2k,
}
opj_event_msg(p_manager, EVT_INFO, "Header of tile %d / %d has been read.\n",
p_j2k->m_current_tile_number, (p_j2k->m_cp.th * p_j2k->m_cp.tw) - 1);
p_j2k->m_current_tile_number+1, (p_j2k->m_cp.th * p_j2k->m_cp.tw));
*p_tile_index = p_j2k->m_current_tile_number;
*p_go_on = OPJ_TRUE;
@@ -7704,13 +7924,13 @@ OPJ_BOOL opj_j2k_decode_tile ( opj_j2k_t * p_j2k,
p_j2k->m_specific_param.m_decoder.m_state = 0x0100;/*FIXME J2K_DEC_STATE_EOC;*/
}
else if (l_current_marker != J2K_MS_SOT)
{
opj_event_msg(p_manager, EVT_ERROR, "Stream too short, expected SOT\n");
{
if(opj_stream_get_number_byte_left(p_stream) == 0) {
p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_NEOC;
opj_event_msg(p_manager, EVT_WARNING, "Stream does not end with EOC\n");
return OPJ_TRUE;
}
opj_event_msg(p_manager, EVT_ERROR, "Stream too short, expected SOT\n");
return OPJ_FALSE;
}
}
@@ -8138,23 +8358,21 @@ OPJ_BOOL opj_j2k_set_decode_area( opj_j2k_t *p_j2k,
opj_j2k_t* opj_j2k_create_decompress(void)
{
opj_j2k_t *l_j2k = (opj_j2k_t*) opj_malloc(sizeof(opj_j2k_t));
opj_j2k_t *l_j2k = (opj_j2k_t*) opj_calloc(1,sizeof(opj_j2k_t));
if (!l_j2k) {
return 00;
}
memset(l_j2k,0,sizeof(opj_j2k_t));
l_j2k->m_is_decoder = 1;
l_j2k->m_cp.m_is_decoder = 1;
l_j2k->m_specific_param.m_decoder.m_default_tcp = (opj_tcp_t*) opj_malloc(sizeof(opj_tcp_t));
l_j2k->m_specific_param.m_decoder.m_default_tcp = (opj_tcp_t*) opj_calloc(1,sizeof(opj_tcp_t));
if (!l_j2k->m_specific_param.m_decoder.m_default_tcp) {
opj_j2k_destroy(l_j2k);
return 00;
}
memset(l_j2k->m_specific_param.m_decoder.m_default_tcp,0,sizeof(opj_tcp_t));
l_j2k->m_specific_param.m_decoder.m_header_data = (OPJ_BYTE *) opj_malloc(OPJ_J2K_DEFAULT_HEADER_SIZE);
l_j2k->m_specific_param.m_decoder.m_header_data = (OPJ_BYTE *) opj_calloc(1,OPJ_J2K_DEFAULT_HEADER_SIZE);
if (! l_j2k->m_specific_param.m_decoder.m_header_data) {
opj_j2k_destroy(l_j2k);
return 00;
@@ -8168,16 +8386,11 @@ opj_j2k_t* opj_j2k_create_decompress(void)
/* codestream index creation */
l_j2k->cstr_index = opj_j2k_create_cstr_index();
/*(opj_codestream_index_t*) opj_malloc(sizeof(opj_codestream_index_t));
if (!l_j2k->cstr_index){
opj_j2k_destroy(l_j2k);
return NULL;
return 00;
}
l_j2k->cstr_index->marker = (opj_marker_info_t*) opj_malloc(100 * sizeof(opj_marker_info_t));
*/
/* validation list creation */
l_j2k->m_validation_list = opj_procedure_list_create();
if (! l_j2k->m_validation_list) {
@@ -9592,6 +9805,10 @@ OPJ_BOOL opj_j2k_start_compress(opj_j2k_t *p_j2k,
assert(p_manager != 00);
p_j2k->m_private_image = opj_image_create0();
if (! p_j2k->m_private_image) {
opj_event_msg(p_manager, EVT_ERROR, "Failed to allocate image header." );
return OPJ_FALSE;
}
opj_copy_image_header(p_image, p_j2k->m_private_image);
/* TODO_MSD: Find a better way */
@@ -9813,7 +10030,7 @@ void opj_j2k_setup_end_compress (opj_j2k_t *p_j2k)
/* DEVELOPER CORNER, insert your custom procedures */
opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)opj_j2k_write_eoc );
if (p_j2k->m_cp.m_specific_param.m_enc.m_cinema) {
if (OPJ_IS_CINEMA(p_j2k->m_cp.rsiz)) {
opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)opj_j2k_write_updated_tlm);
}
@@ -9845,14 +10062,14 @@ void opj_j2k_setup_header_writing (opj_j2k_t *p_j2k)
opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)opj_j2k_write_cod );
opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)opj_j2k_write_qcd );
if (p_j2k->m_cp.m_specific_param.m_enc.m_cinema) {
if (OPJ_IS_CINEMA(p_j2k->m_cp.rsiz)) {
/* No need for COC or QCC, QCD and COD are used
opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)opj_j2k_write_all_coc );
opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)opj_j2k_write_all_qcc );
*/
opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)opj_j2k_write_tlm );
if (p_j2k->m_cp.m_specific_param.m_enc.m_cinema == OPJ_CINEMA4K_24) {
if (p_j2k->m_cp.rsiz == OPJ_PROFILE_CINEMA_4K) {
opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)opj_j2k_write_poc );
}
}
@@ -9864,7 +10081,7 @@ void opj_j2k_setup_header_writing (opj_j2k_t *p_j2k)
}
/* DEVELOPER CORNER, insert your custom procedures */
if (p_j2k->m_cp.rsiz & OPJ_MCT) {
if (p_j2k->m_cp.rsiz & OPJ_EXTENSION_MCT) {
opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)opj_j2k_write_mct_data_group );
}
/* End of Developer Corner */
@@ -9913,7 +10130,7 @@ OPJ_BOOL opj_j2k_write_first_tile_part (opj_j2k_t *p_j2k,
p_data += l_current_nb_bytes_written;
p_total_data_size -= l_current_nb_bytes_written;
if (l_cp->m_specific_param.m_enc.m_cinema == 0) {
if (!OPJ_IS_CINEMA(l_cp->rsiz)) {
#if 0
for (compno = 1; compno < p_j2k->m_private_image->numcomps; compno++) {
l_current_nb_bytes_written = 0;
@@ -9950,7 +10167,7 @@ OPJ_BOOL opj_j2k_write_first_tile_part (opj_j2k_t *p_j2k,
/* Writing Psot in SOT marker */
opj_write_bytes(l_begin_data + 6,l_nb_bytes_written,4); /* PSOT */
if (l_cp->m_specific_param.m_enc.m_cinema){
if (OPJ_IS_CINEMA(l_cp->rsiz)){
opj_j2k_update_tlm(p_j2k,l_nb_bytes_written);
}
@@ -10014,7 +10231,7 @@ OPJ_BOOL opj_j2k_write_all_tile_parts( opj_j2k_t *p_j2k,
/* Writing Psot in SOT marker */
opj_write_bytes(l_begin_data + 6,l_part_tile_size,4); /* PSOT */
if (l_cp->m_specific_param.m_enc.m_cinema) {
if (OPJ_IS_CINEMA(l_cp->rsiz)) {
opj_j2k_update_tlm(p_j2k,l_part_tile_size);
}
@@ -10055,7 +10272,7 @@ OPJ_BOOL opj_j2k_write_all_tile_parts( opj_j2k_t *p_j2k,
/* Writing Psot in SOT marker */
opj_write_bytes(l_begin_data + 6,l_part_tile_size,4); /* PSOT */
if (l_cp->m_specific_param.m_enc.m_cinema) {
if (OPJ_IS_CINEMA(l_cp->rsiz)) {
opj_j2k_update_tlm(p_j2k,l_part_tile_size);
}

View File

@@ -304,8 +304,6 @@ typedef struct opj_tcp
typedef struct opj_encoding_param
{
/** Digital cinema profile*/
OPJ_CINEMA_MODE m_cinema;
/** Maximum rate for each component. If == 0, component size limitation is not considered */
OPJ_UINT32 m_max_comp_size;
/** Position of tile part flag in progression order*/
@@ -343,7 +341,7 @@ typedef struct opj_cp
/** Size of the image in bits*/
/*int img_size;*/
/** Rsiz*/
OPJ_RSIZ_CAPABILITIES rsiz;
OPJ_UINT16 rsiz;
/** XTOsiz */
OPJ_UINT32 tx0; /* MSD see norm */
/** YTOsiz */
@@ -596,7 +594,7 @@ void opj_j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters);
opj_j2k_t* opj_j2k_create_compress(void);
void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
OPJ_BOOL opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
opj_cparameters_t *parameters,
opj_image_t *image,
opj_event_mgr_t * p_manager);

View File

@@ -537,12 +537,11 @@ OPJ_BOOL opj_jp2_read_ihdr( opj_jp2_t *jp2,
p_image_header_data += 2;
/* allocate memory for components */
jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp2_comps_t));
jp2->comps = (opj_jp2_comps_t*) opj_calloc(jp2->numcomps, sizeof(opj_jp2_comps_t));
if (jp2->comps == 0) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle image header (ihdr)\n");
return OPJ_FALSE;
}
memset(jp2->comps,0,jp2->numcomps * sizeof(opj_jp2_comps_t));
opj_read_bytes(p_image_header_data,&(jp2->bpc),1); /* BPC */
++ p_image_header_data;
@@ -574,11 +573,10 @@ OPJ_BYTE * opj_jp2_write_ihdr(opj_jp2_t *jp2,
assert(p_nb_bytes_written != 00);
/* default image header is 22 bytes wide */
l_ihdr_data = (OPJ_BYTE *) opj_malloc(22);
l_ihdr_data = (OPJ_BYTE *) opj_calloc(1,22);
if (l_ihdr_data == 00) {
return 00;
}
memset(l_ihdr_data,0,22);
l_current_ihdr_ptr = l_ihdr_data;
@@ -627,11 +625,10 @@ OPJ_BYTE * opj_jp2_write_bpcc( opj_jp2_t *jp2,
assert(jp2 != 00);
assert(p_nb_bytes_written != 00);
l_bpcc_data = (OPJ_BYTE *) opj_malloc(l_bpcc_size);
l_bpcc_data = (OPJ_BYTE *) opj_calloc(1,l_bpcc_size);
if (l_bpcc_data == 00) {
return 00;
}
memset(l_bpcc_data,0,l_bpcc_size);
l_current_bpcc_ptr = l_bpcc_data;
@@ -709,11 +706,10 @@ OPJ_BYTE * opj_jp2_write_colr( opj_jp2_t *jp2,
return 00;
}
l_colr_data = (OPJ_BYTE *) opj_malloc(l_colr_size);
l_colr_data = (OPJ_BYTE *) opj_calloc(1,l_colr_size);
if (l_colr_data == 00) {
return 00;
}
memset(l_colr_data,0,l_colr_size);
l_current_colr_ptr = l_colr_data;
@@ -768,6 +764,12 @@ static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color,
if (color->jp2_cdef) {
opj_jp2_cdef_info_t *info = color->jp2_cdef->info;
OPJ_UINT16 n = color->jp2_cdef->n;
OPJ_UINT32 nr_channels = image->numcomps; /* FIXME image->numcomps == jp2->numcomps before color is applied ??? */
/* cdef applies to cmap channels if any */
if (color->jp2_pclr && color->jp2_pclr->cmap) {
nr_channels = (OPJ_UINT32)color->jp2_pclr->nr_channels;
}
for (i = 0; i < n; i++) {
if (info[i].cn >= image->numcomps) {
@@ -779,6 +781,22 @@ static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color,
return OPJ_FALSE;
}
}
/* issue 397 */
/* ISO 15444-1 states that if cdef is present, it shall contain a complete list of channel definitions. */
while (nr_channels > 0)
{
for(i = 0; i < n; ++i) {
if ((OPJ_UINT32)info[i].cn == (nr_channels - 1U)) {
break;
}
}
if (i == n) {
opj_event_msg(p_manager, EVT_ERROR, "Incomplete channel definitions.\n");
return OPJ_FALSE;
}
--nr_channels;
}
}
/* testcases 451.pdf.SIGSEGV.f4c.3723, 451.pdf.SIGSEGV.5b5.3723 and
@@ -859,7 +877,11 @@ void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color)
old_comps = image->comps;
new_comps = (opj_image_comp_t*)
opj_malloc(nr_channels * sizeof(opj_image_comp_t));
if (!new_comps) {
/* FIXME no error code for opj_jp2_apply_pclr */
/* FIXME event manager error callback */
return;
}
for(i = 0; i < nr_channels; ++i) {
pcol = cmap[i].pcol; cmp = cmap[i].cmp;
@@ -875,6 +897,13 @@ void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color)
/* Palette mapping: */
new_comps[i].data = (OPJ_INT32*)
opj_malloc(old_comps[cmp].w * old_comps[cmp].h * sizeof(OPJ_INT32));
if (!new_comps[i].data) {
opj_free(new_comps);
new_comps = NULL;
/* FIXME no error code for opj_jp2_apply_pclr */
/* FIXME event manager error callback */
return;
}
new_comps[i].prec = channel_size[i];
new_comps[i].sgnd = channel_sign[i];
}
@@ -1010,7 +1039,7 @@ OPJ_BOOL opj_jp2_read_pclr( opj_jp2_t *jp2,
if (bytes_to_read > sizeof(OPJ_UINT32))
bytes_to_read = sizeof(OPJ_UINT32);
if ((ptrdiff_t)p_pclr_header_size < p_pclr_header_data - orig_header_data + (ptrdiff_t)bytes_to_read)
if ((ptrdiff_t)p_pclr_header_size < (ptrdiff_t)(p_pclr_header_data - orig_header_data) + (ptrdiff_t)bytes_to_read)
return OPJ_FALSE;
opj_read_bytes(p_pclr_header_data, &l_value , bytes_to_read); /* Cji */
@@ -1097,6 +1126,8 @@ void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color)
asoc = info[i].asoc;
if(asoc == 0 || asoc == 65535)
{
if (i < image->numcomps)
image->comps[i].alpha = info[i].typ;
continue;
}
@@ -1120,6 +1151,7 @@ void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color)
info[acn].asoc = (OPJ_UINT16)(info[acn].cn + 1);
}
image->comps[cn].alpha = info[i].typ;
}
if(color->jp2_cdef->info) opj_free(color->jp2_cdef->info);
@@ -1252,13 +1284,12 @@ OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2,
OPJ_INT32 icc_len = (OPJ_INT32)p_colr_header_size - 3;
jp2->color.icc_profile_len = (OPJ_UINT32)icc_len;
jp2->color.icc_profile_buf = (OPJ_BYTE*) opj_malloc((size_t)icc_len);
jp2->color.icc_profile_buf = (OPJ_BYTE*) opj_calloc(1,(size_t)icc_len);
if (!jp2->color.icc_profile_buf)
{
jp2->color.icc_profile_len = 0;
return OPJ_FALSE;
}
memset(jp2->color.icc_profile_buf, 0, (size_t)icc_len * sizeof(OPJ_BYTE));
for (it_icc_value = 0; it_icc_value < icc_len; ++it_icc_value)
{
@@ -1271,7 +1302,7 @@ OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2,
}
else if (jp2->meth > 2)
{
/* ISO/IEC 15444-1:2004 (E), Table I.9 <20> Legal METH values:
/* ISO/IEC 15444-1:2004 (E), Table I.9 Legal METH values:
conforming JP2 reader shall ignore the entire Colour Specification box.*/
opj_event_msg(p_manager, EVT_INFO, "COLR BOX meth value is not a regular value (%d), "
"so we will ignore the entire Colour Specification box. \n", jp2->meth);
@@ -1305,6 +1336,8 @@ OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
p_image->color_space = OPJ_CLRSPC_GRAY;
else if (jp2->enumcs == 18)
p_image->color_space = OPJ_CLRSPC_SYCC;
else if (jp2->enumcs == 24)
p_image->color_space = OPJ_CLRSPC_EYCC;
else
p_image->color_space = OPJ_CLRSPC_UNKNOWN;
@@ -1443,15 +1476,13 @@ OPJ_BOOL opj_jp2_write_ftyp(opj_jp2_t *jp2,
assert(jp2 != 00);
assert(p_manager != 00);
l_ftyp_data = (OPJ_BYTE *) opj_malloc(l_ftyp_size);
l_ftyp_data = (OPJ_BYTE *) opj_calloc(1,l_ftyp_size);
if (l_ftyp_data == 00) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle ftyp data\n");
return OPJ_FALSE;
}
memset(l_ftyp_data,0,l_ftyp_size);
l_current_data_ptr = l_ftyp_data;
opj_write_bytes(l_current_data_ptr, l_ftyp_size,4); /* box size */
@@ -1562,7 +1593,7 @@ void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters)
/* JP2 encoder interface */
/* ----------------------------------------------------------------------- */
void opj_jp2_setup_encoder( opj_jp2_t *jp2,
OPJ_BOOL opj_jp2_setup_encoder( opj_jp2_t *jp2,
opj_cparameters_t *parameters,
opj_image_t *image,
opj_event_mgr_t * p_manager)
@@ -1572,7 +1603,7 @@ void opj_jp2_setup_encoder( opj_jp2_t *jp2,
OPJ_UINT32 sign;
if(!jp2 || !parameters || !image)
return;
return OPJ_FALSE;
/* setup the J2K codec */
/* ------------------- */
@@ -1580,10 +1611,12 @@ void opj_jp2_setup_encoder( opj_jp2_t *jp2,
/* Check if number of components respects standard */
if (image->numcomps < 1 || image->numcomps > 16384) {
opj_event_msg(p_manager, EVT_ERROR, "Invalid number of components specified while setting up JP2 encoder\n");
return;
return OPJ_FALSE;
}
opj_j2k_setup_encoder(jp2->j2k, parameters, image, p_manager );
if (opj_j2k_setup_encoder(jp2->j2k, parameters, image, p_manager ) == OPJ_FALSE) {
return OPJ_FALSE;
}
/* setup the JP2 codec */
/* ------------------- */
@@ -1594,22 +1627,23 @@ void opj_jp2_setup_encoder( opj_jp2_t *jp2,
jp2->minversion = 0; /* MinV */
jp2->numcl = 1;
jp2->cl = (OPJ_UINT32*) opj_malloc(jp2->numcl * sizeof(OPJ_UINT32));
if (!jp2->cl){
jp2->cl = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n");
return;
}
if (!jp2->cl){
jp2->cl = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n");
return OPJ_FALSE;
}
jp2->cl[0] = JP2_JP2; /* CL0 : JP2 */
/* Image Header box */
jp2->numcomps = image->numcomps; /* NC */
jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp2_comps_t));
if (!jp2->comps) {
jp2->comps = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n");
return;
}
if (!jp2->comps) {
jp2->comps = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n");
/* Memory of jp2->cl will be freed by opj_jp2_destroy */
return OPJ_FALSE;
}
jp2->h = image->y1 - image->y0; /* HEIGHT */
jp2->w = image->x1 - image->x0; /* WIDTH */
@@ -1652,6 +1686,8 @@ void opj_jp2_setup_encoder( opj_jp2_t *jp2,
jp2->approx = 0; /* APPROX */
jp2->jpip_on = parameters->jpip_on;
return OPJ_TRUE;
}
OPJ_BOOL opj_jp2_encode(opj_jp2_t *jp2,
@@ -1802,13 +1838,12 @@ OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2,
assert(jp2 != 00);
assert(p_manager != 00);
l_current_data = (OPJ_BYTE*)opj_malloc(l_last_data_size);
l_current_data = (OPJ_BYTE*)opj_calloc(1,l_last_data_size);
if (l_current_data == 00) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle jpeg2000 file header\n");
return OPJ_FALSE;
}
memset(l_current_data, 0 , l_last_data_size);
while (opj_jp2_read_boxhdr(&box,&l_nb_bytes_read,stream,p_manager)) {
/* is it the codestream box ? */
@@ -1830,7 +1865,7 @@ OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2,
return OPJ_FALSE;
}
/* testcase 1851.pdf.SIGSEGV.ce9.948 */
else if (box.length < l_nb_bytes_read) {
else if (box.length < l_nb_bytes_read) {
opj_event_msg(p_manager, EVT_ERROR, "invalid box size %d (%x)\n", box.length, box.type);
opj_free(l_current_data);
return OPJ_FALSE;
@@ -1840,6 +1875,12 @@ OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2,
l_current_data_size = box.length - l_nb_bytes_read;
if (l_current_handler != 00) {
if ((OPJ_OFF_T)l_current_data_size > opj_stream_get_number_byte_left(stream)) {
/* do not even try to malloc if we can't read */
opj_event_msg(p_manager, EVT_ERROR, "Invalid box size %d for box '%c%c%c%c'. Need %d bytes, %d bytes remaining \n", box.length, (OPJ_BYTE)(box.type>>24), (OPJ_BYTE)(box.type>>16), (OPJ_BYTE)(box.type>>8), (OPJ_BYTE)(box.type>>0), l_current_data_size, (OPJ_UINT32)opj_stream_get_number_byte_left(stream));
opj_free(l_current_data);
return OPJ_FALSE;
}
if (l_current_data_size > l_last_data_size) {
OPJ_BYTE* new_current_data = (OPJ_BYTE*)opj_realloc(l_current_data,l_current_data_size);
if (!new_current_data) {
@@ -2078,12 +2119,11 @@ static OPJ_BOOL opj_jp2_read_ftyp( opj_jp2_t *jp2,
/* div by 4 */
jp2->numcl = l_remaining_bytes >> 2;
if (jp2->numcl) {
jp2->cl = (OPJ_UINT32 *) opj_malloc(jp2->numcl * sizeof(OPJ_UINT32));
jp2->cl = (OPJ_UINT32 *) opj_calloc(jp2->numcl, sizeof(OPJ_UINT32));
if (jp2->cl == 00) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory with FTYP Box\n");
return OPJ_FALSE;
}
memset(jp2->cl,0,jp2->numcl * sizeof(OPJ_UINT32));
}
for (i = 0; i < jp2->numcl; ++i)
@@ -2152,6 +2192,7 @@ static OPJ_BOOL opj_jp2_read_jp2h( opj_jp2_t *jp2,
OPJ_UINT32 l_box_size=0, l_current_data_size = 0;
opj_jp2_box_t box;
const opj_jp2_header_handler_t * l_current_handler;
OPJ_BOOL l_has_ihdr = 0;
/* preconditions */
assert(p_header_data != 00);
@@ -2192,10 +2233,19 @@ static OPJ_BOOL opj_jp2_read_jp2h( opj_jp2_t *jp2,
jp2->jp2_img_state |= JP2_IMG_STATE_UNKNOWN;
}
if (box.type == JP2_IHDR) {
l_has_ihdr = 1;
}
p_header_data += l_current_data_size;
p_header_size -= box.length;
}
if (l_has_ihdr == 0) {
opj_event_msg(p_manager, EVT_ERROR, "Stream error while reading JP2 Header box: no 'ihdr' box.\n");
return OPJ_FALSE;
}
jp2->jp2_state |= JP2_STATE_HEADER;
return OPJ_TRUE;
@@ -2264,7 +2314,10 @@ OPJ_BOOL opj_jp2_read_boxhdr_char( opj_jp2_box_t *box,
opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box of undefined sizes\n");
return OPJ_FALSE;
}
if (box->length < *p_number_bytes_read) {
opj_event_msg(p_manager, EVT_ERROR, "Box length is inconsistent.\n");
return OPJ_FALSE;
}
return OPJ_TRUE;
}
@@ -2526,9 +2579,8 @@ OPJ_BOOL opj_jp2_get_tile( opj_jp2_t *p_jp2,
opj_jp2_t* opj_jp2_create(OPJ_BOOL p_is_decoder)
{
opj_jp2_t *jp2 = (opj_jp2_t*)opj_malloc(sizeof(opj_jp2_t));
opj_jp2_t *jp2 = (opj_jp2_t*)opj_calloc(1,sizeof(opj_jp2_t));
if (jp2) {
memset(jp2,0,sizeof(opj_jp2_t));
/* create the J2K codec */
if (! p_is_decoder) {

View File

@@ -278,8 +278,9 @@ OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
* @param parameters compression parameters
* @param image input filled image
* @param p_manager FIXME DOC
* @return OPJ_TRUE if successful, OPJ_FALSE otherwise
*/
void opj_jp2_setup_encoder( opj_jp2_t *jp2,
OPJ_BOOL opj_jp2_setup_encoder( opj_jp2_t *jp2,
opj_cparameters_t *parameters,
opj_image_t *image,
opj_event_mgr_t * p_manager);

View File

@@ -362,7 +362,9 @@ static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc) {
opj_mqc_t* opj_mqc_create(void) {
opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t));
#ifdef MQC_PERF_OPT
mqc->buffer = NULL;
if (mqc) {
mqc->buffer = NULL;
}
#endif
return mqc;
}
@@ -370,7 +372,9 @@ opj_mqc_t* opj_mqc_create(void) {
void opj_mqc_destroy(opj_mqc_t *mqc) {
if(mqc) {
#ifdef MQC_PERF_OPT
opj_free(mqc->buffer);
if (mqc->buffer) {
opj_free(mqc->buffer);
}
#endif
opj_free(mqc);
}

View File

@@ -132,7 +132,7 @@ static OPJ_BOOL opj_seek_from_file (OPJ_OFF_T p_nb_bytes, FILE * p_user_data)
#ifdef _WIN32
#ifndef OPJ_STATIC
BOOL APIENTRY
DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
OPJ_ARG_NOT_USED(lpReserved);
OPJ_ARG_NOT_USED(hModule);
@@ -169,7 +169,6 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format)
if (!l_codec){
return 00;
}
memset(l_codec, 0, sizeof(opj_codec_private_t));
l_codec->is_decompressor = 1;
@@ -546,7 +545,6 @@ opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format)
if (!l_codec) {
return 00;
}
memset(l_codec, 0, sizeof(opj_codec_private_t));
l_codec->is_decompressor = 0;
@@ -574,7 +572,7 @@ opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format)
l_codec->m_codec_data.m_compression.opj_destroy = (void (*) (void *)) opj_j2k_destroy;
l_codec->m_codec_data.m_compression.opj_setup_encoder = (void (*) ( void *,
l_codec->m_codec_data.m_compression.opj_setup_encoder = (OPJ_BOOL (*) ( void *,
opj_cparameters_t *,
struct opj_image *,
struct opj_event_mgr * )) opj_j2k_setup_encoder;
@@ -611,7 +609,7 @@ opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format)
l_codec->m_codec_data.m_compression.opj_destroy = (void (*) (void *)) opj_jp2_destroy;
l_codec->m_codec_data.m_compression.opj_setup_encoder = (void (*) ( void *,
l_codec->m_codec_data.m_compression.opj_setup_encoder = (OPJ_BOOL (*) ( void *,
opj_cparameters_t *,
struct opj_image *,
struct opj_event_mgr * )) opj_jp2_setup_encoder;
@@ -639,10 +637,11 @@ void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *paramete
if(parameters) {
memset(parameters, 0, sizeof(opj_cparameters_t));
/* default coding parameters */
parameters->cp_cinema = OPJ_OFF;
parameters->cp_cinema = OPJ_OFF; /* DEPRECATED */
parameters->rsiz = OPJ_PROFILE_NONE;
parameters->max_comp_size = 0;
parameters->numresolution = 6;
parameters->cp_rsiz = OPJ_STD_RSIZ;
parameters->cp_rsiz = OPJ_STD_RSIZ; /* DEPRECATED */
parameters->cblockw_init = 64;
parameters->cblockh_init = 64;
parameters->prog_order = OPJ_LRCP;
@@ -793,8 +792,11 @@ OPJ_BOOL OPJ_CALLCONV opj_set_MCT(opj_cparameters_t *parameters,
OPJ_UINT32 l_mct_total_size = l_matrix_size + l_dc_shift_size;
/* add MCT capability */
OPJ_INT32 rsiz = (OPJ_INT32)parameters->cp_rsiz | (OPJ_INT32)OPJ_MCT;
parameters->cp_rsiz = (OPJ_RSIZ_CAPABILITIES)rsiz;
if (OPJ_IS_PART2(parameters->rsiz)) {
parameters->rsiz |= OPJ_EXTENSION_MCT;
} else {
parameters->rsiz = ((OPJ_PROFILE_PART2) | (OPJ_EXTENSION_MCT));
}
parameters->irreversible = 1;
/* use array based MCT */
@@ -917,33 +919,44 @@ void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index)
}
}
/* ---------------------------------------------------------------------- */
opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file, OPJ_BOOL p_is_read_stream)
opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (const char *fname, OPJ_BOOL p_is_read_stream)
{
return opj_stream_create_file_stream(p_file,OPJ_J2K_STREAM_CHUNK_SIZE,p_is_read_stream);
return opj_stream_create_file_stream(fname, OPJ_J2K_STREAM_CHUNK_SIZE, p_is_read_stream);
}
opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream ( FILE * p_file,
OPJ_SIZE_T p_size,
OPJ_BOOL p_is_read_stream)
opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (
const char *fname,
OPJ_SIZE_T p_size,
OPJ_BOOL p_is_read_stream)
{
opj_stream_t* l_stream = 00;
opj_stream_t* l_stream = 00;
FILE *p_file;
const char *mode;
if (! p_file) {
return NULL;
}
if (! fname) {
return NULL;
}
if(p_is_read_stream) mode = "rb"; else mode = "wb";
l_stream = opj_stream_create(p_size,p_is_read_stream);
if (! l_stream) {
return NULL;
}
p_file = fopen(fname, mode);
opj_stream_set_user_data(l_stream, p_file);
opj_stream_set_user_data_length(l_stream, opj_get_data_length_from_file(p_file));
opj_stream_set_read_function(l_stream, (opj_stream_read_fn) opj_read_from_file);
opj_stream_set_write_function(l_stream, (opj_stream_write_fn) opj_write_from_file);
opj_stream_set_skip_function(l_stream, (opj_stream_skip_fn) opj_skip_from_file);
opj_stream_set_seek_function(l_stream, (opj_stream_seek_fn) opj_seek_from_file);
if (! p_file) {
return NULL;
}
return l_stream;
l_stream = opj_stream_create(p_size,p_is_read_stream);
if (! l_stream) {
fclose(p_file);
return NULL;
}
opj_stream_set_user_data(l_stream, p_file, (opj_stream_free_user_data_fn) fclose);
opj_stream_set_user_data_length(l_stream, opj_get_data_length_from_file(p_file));
opj_stream_set_read_function(l_stream, (opj_stream_read_fn) opj_read_from_file);
opj_stream_set_write_function(l_stream, (opj_stream_write_fn) opj_write_from_file);
opj_stream_set_skip_function(l_stream, (opj_stream_skip_fn) opj_skip_from_file);
opj_stream_set_seek_function(l_stream, (opj_stream_seek_fn) opj_seek_from_file);
return l_stream;
}

View File

@@ -173,30 +173,88 @@ typedef size_t OPJ_SIZE_T;
#define OPJ_JP2_INFO 128 /**< JP2 file information */
#define OPJ_JP2_IND 256 /**< JP2 file index */
/**
* JPEG 2000 Profiles, see Table A.10 from 15444-1 (updated in various AMD)
* These values help chosing the RSIZ value for the J2K codestream.
* The RSIZ value triggers various encoding options, as detailed in Table A.10.
* If OPJ_PROFILE_PART2 is chosen, it has to be combined with one or more extensions
* described hereunder.
* Example: rsiz = OPJ_PROFILE_PART2 | OPJ_EXTENSION_MCT;
* For broadcast profiles, the OPJ_PROFILE value has to be combined with the targeted
* mainlevel (3-0 LSB, value between 0 and 11):
* Example: rsiz = OPJ_PROFILE_BC_MULTI | 0x0005; (here mainlevel 5)
* For IMF profiles, the OPJ_PROFILE value has to be combined with the targeted mainlevel
* (3-0 LSB, value between 0 and 11) and sublevel (7-4 LSB, value between 0 and 9):
* Example: rsiz = OPJ_PROFILE_IMF_2K | 0x0040 | 0x0005; (here main 5 and sublevel 4)
* */
#define OPJ_PROFILE_NONE 0x0000 /** no profile, conform to 15444-1 */
#define OPJ_PROFILE_0 0x0001 /** Profile 0 as described in 15444-1,Table A.45 */
#define OPJ_PROFILE_1 0x0002 /** Profile 1 as described in 15444-1,Table A.45 */
#define OPJ_PROFILE_PART2 0x8000 /** At least 1 extension defined in 15444-2 (Part-2) */
#define OPJ_PROFILE_CINEMA_2K 0x0003 /** 2K cinema profile defined in 15444-1 AMD1 */
#define OPJ_PROFILE_CINEMA_4K 0x0004 /** 4K cinema profile defined in 15444-1 AMD1 */
#define OPJ_PROFILE_CINEMA_S2K 0x0005 /** Scalable 2K cinema profile defined in 15444-1 AMD2 */
#define OPJ_PROFILE_CINEMA_S4K 0x0006 /** Scalable 4K cinema profile defined in 15444-1 AMD2 */
#define OPJ_PROFILE_CINEMA_LTS 0x0007 /** Long term storage cinema profile defined in 15444-1 AMD2 */
#define OPJ_PROFILE_BC_SINGLE 0x0100 /** Single Tile Broadcast profile defined in 15444-1 AMD3 */
#define OPJ_PROFILE_BC_MULTI 0x0200 /** Multi Tile Broadcast profile defined in 15444-1 AMD3 */
#define OPJ_PROFILE_BC_MULTI_R 0x0300 /** Multi Tile Reversible Broadcast profile defined in 15444-1 AMD3 */
#define OPJ_PROFILE_IMF_2K 0x0400 /** 2K Single Tile Lossy IMF profile defined in 15444-1 AMD 8 */
#define OPJ_PROFILE_IMF_4K 0x0401 /** 4K Single Tile Lossy IMF profile defined in 15444-1 AMD 8 */
#define OPJ_PROFILE_IMF_8K 0x0402 /** 8K Single Tile Lossy IMF profile defined in 15444-1 AMD 8 */
#define OPJ_PROFILE_IMF_2K_R 0x0403 /** 2K Single/Multi Tile Reversible IMF profile defined in 15444-1 AMD 8 */
#define OPJ_PROFILE_IMF_4K_R 0x0800 /** 4K Single/Multi Tile Reversible IMF profile defined in 15444-1 AMD 8 */
#define OPJ_PROFILE_IMF_8K_R 0x0801 /** 8K Single/Multi Tile Reversible IMF profile defined in 15444-1 AMD 8 */
/**
* JPEG 2000 Part-2 extensions
* */
#define OPJ_EXTENSION_NONE 0x0000 /** No Part-2 extension */
#define OPJ_EXTENSION_MCT 0x0100 /** Custom MCT support */
/**
* JPEG 2000 profile macros
* */
#define OPJ_IS_CINEMA(v) (((v) >= OPJ_PROFILE_CINEMA_2K)&&((v) <= OPJ_PROFILE_CINEMA_S4K))
#define OPJ_IS_STORAGE(v) ((v) == OPJ_PROFILE_CINEMA_LTS)
#define OPJ_IS_BROADCAST(v) (((v) >= OPJ_PROFILE_BC_SINGLE)&&((v) <= ((OPJ_PROFILE_BC_MULTI_R) | (0x000b))))
#define OPJ_IS_IMF(v) (((v) >= OPJ_PROFILE_IMF_2K)&&((v) <= ((OPJ_PROFILE_IMF_8K_R) | (0x009b))))
#define OPJ_IS_PART2(v) ((v) & OPJ_PROFILE_PART2)
/**
* JPEG 2000 codestream and component size limits in cinema profiles
* */
#define OPJ_CINEMA_24_CS 1302083 /** Maximum codestream length for 24fps */
#define OPJ_CINEMA_48_CS 651041 /** Maximum codestream length for 48fps */
#define OPJ_CINEMA_24_COMP 1041666 /** Maximum size per color component for 2K & 4K @ 24fps */
#define OPJ_CINEMA_48_COMP 520833 /** Maximum size per color component for 2K @ 48fps */
/*
==========================================================
enum definitions
==========================================================
*/
/**
/**
* DEPRECATED: use RSIZ, OPJ_PROFILE_* and OPJ_EXTENSION_* instead
* Rsiz Capabilities
* */
typedef enum RSIZ_CAPABILITIES {
OPJ_STD_RSIZ = 0, /** Standard JPEG2000 profile*/
OPJ_CINEMA2K = 3, /** Profile name for a 2K image*/
OPJ_CINEMA4K = 4, /** Profile name for a 4K image*/
OPJ_MCT = 0x8100
OPJ_STD_RSIZ = 0, /** Standard JPEG2000 profile*/
OPJ_CINEMA2K = 3, /** Profile name for a 2K image*/
OPJ_CINEMA4K = 4, /** Profile name for a 4K image*/
OPJ_MCT = 0x8100
} OPJ_RSIZ_CAPABILITIES;
/**
/**
* DEPRECATED: use RSIZ, OPJ_PROFILE_* and OPJ_EXTENSION_* instead
* Digital cinema operation mode
* */
typedef enum CINEMA_MODE {
OPJ_OFF = 0, /** Not Digital Cinema*/
OPJ_CINEMA2K_24 = 1, /** 2K Digital Cinema at 24 fps*/
OPJ_CINEMA2K_48 = 2, /** 2K Digital Cinema at 48 fps*/
OPJ_CINEMA4K_24 = 3 /** 4K Digital Cinema at 24 fps*/
OPJ_OFF = 0, /** Not Digital Cinema*/
OPJ_CINEMA2K_24 = 1, /** 2K Digital Cinema at 24 fps*/
OPJ_CINEMA2K_48 = 2, /** 2K Digital Cinema at 48 fps*/
OPJ_CINEMA4K_24 = 3 /** 4K Digital Cinema at 24 fps*/
}OPJ_CINEMA_MODE;
/**
@@ -215,11 +273,13 @@ typedef enum PROG_ORDER {
* Supported image color spaces
*/
typedef enum COLOR_SPACE {
OPJ_CLRSPC_UNKNOWN = -1, /**< not supported by the library */
OPJ_CLRSPC_UNSPECIFIED = 0, /**< not specified in the codestream */
OPJ_CLRSPC_SRGB = 1, /**< sRGB */
OPJ_CLRSPC_GRAY = 2, /**< grayscale */
OPJ_CLRSPC_SYCC = 3 /**< YUV */
OPJ_CLRSPC_UNKNOWN = -1, /**< not supported by the library */
OPJ_CLRSPC_UNSPECIFIED = 0, /**< not specified in the codestream */
OPJ_CLRSPC_SRGB = 1, /**< sRGB */
OPJ_CLRSPC_GRAY = 2, /**< grayscale */
OPJ_CLRSPC_SYCC = 3, /**< YUV */
OPJ_CLRSPC_EYCC = 4, /**< e-YCC */
OPJ_CLRSPC_CMYK = 5 /**< CMYK */
} OPJ_COLOR_SPACE;
/**
@@ -229,7 +289,9 @@ typedef enum CODEC_FORMAT {
OPJ_CODEC_UNKNOWN = -1, /**< place-holder */
OPJ_CODEC_J2K = 0, /**< JPEG-2000 codestream : read/write */
OPJ_CODEC_JPT = 1, /**< JPT-stream (JPEG 2000, JPIP) : read only */
OPJ_CODEC_JP2 = 2 /**< JPEG-2000 file format : read/write */
OPJ_CODEC_JP2 = 2, /**< JP2 file format : read/write */
OPJ_CODEC_JPP = 3, /**< JPP-stream (JPEG 2000, JPIP) : to be coded */
OPJ_CODEC_JPX = 4 /**< JPX file format (JPEG 2000 Part-2) : to be coded */
} OPJ_CODEC_FORMAT;
@@ -315,7 +377,7 @@ typedef struct opj_cparameters {
OPJ_UINT32 numpocs;
/** number of layers */
int tcp_numlayers;
/** rates of layers */
/** rates of layers - might be subsequently limited by the max_cs_size field */
float tcp_rates[100];
/** different psnr for successive layers */
float tcp_distoratio[100];
@@ -396,12 +458,21 @@ typedef struct opj_cparameters {
/*@}*/
/* <<UniPG */
/** Digital Cinema compliance 0-not compliant, 1-compliant*/
OPJ_CINEMA_MODE cp_cinema;
/** Maximum rate for each component. If == 0, component size limitation is not considered */
/**
* DEPRECATED: use RSIZ, OPJ_PROFILE_* and MAX_COMP_SIZE instead
* Digital Cinema compliance 0-not compliant, 1-compliant
* */
OPJ_CINEMA_MODE cp_cinema;
/**
* Maximum size (in bytes) for each component.
* If == 0, component size limitation is not considered
* */
int max_comp_size;
/** Profile name*/
OPJ_RSIZ_CAPABILITIES cp_rsiz;
/**
* DEPRECATED: use RSIZ, OPJ_PROFILE_* and OPJ_EXTENSION_* instead
* Profile name
* */
OPJ_RSIZ_CAPABILITIES cp_rsiz;
/** Tile part generation*/
char tp_on;
/** Flag for Tile part generation*/
@@ -413,6 +484,16 @@ typedef struct opj_cparameters {
/** Naive implementation of MCT restricted to a single reversible array based
encoding without offset concerning all the components. */
void * mct_data;
/**
* Maximum size (in bytes) for the whole codestream.
* If == 0, codestream size limitation is not considered
* If it does not comply with tcp_rates, max_cs_size prevails
* and a warning is issued.
* */
int max_cs_size;
/** RSIZ value
To be used to combine OPJ_PROFILE_*, OPJ_EXTENSION_* and (sub)levels values. */
OPJ_UINT16 rsiz;
} opj_cparameters_t;
#define OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG 0x0001
@@ -522,6 +603,11 @@ typedef OPJ_OFF_T (* opj_stream_skip_fn) (OPJ_OFF_T p_nb_bytes, void * p_user_da
*/
typedef OPJ_BOOL (* opj_stream_seek_fn) (OPJ_OFF_T p_nb_bytes, void * p_user_data) ;
/*
* Callback function prototype for free user data function
*/
typedef void (* opj_stream_free_user_data_fn) (void * p_user_data) ;
/*
* JPEG2000 Stream.
*/
@@ -561,6 +647,8 @@ typedef struct opj_image_comp {
OPJ_UINT32 factor;
/** image component data */
OPJ_INT32 *data;
/** alpha channel */
OPJ_UINT16 alpha;
} opj_image_comp_t;
/**
@@ -1028,7 +1116,7 @@ OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size, O
* @param p_stream the stream to destroy.
*/
OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream);
/**
* Sets the given function to be used as a read function.
* @param p_stream the stream to modify
@@ -1061,8 +1149,9 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, o
* Sets the given data to be used as a user data for the stream.
* @param p_stream the stream to modify
* @param p_data the data to set.
* @param p_function the function to free p_data when opj_stream_destroy() is called.
*/
OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data);
OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data, opj_stream_free_user_data_fn p_function);
/**
* Sets the length of the user data for the stream.
@@ -1073,21 +1162,21 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void
OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream, OPJ_UINT64 data_length);
/**
* Helper function.
* Sets the stream to be a file stream. The FILE must have been open previously.
* @param p_file the file stream to operate on
* Create a stream from a file identified with its filename with default parameters (helper function)
* @param fname the filename of the file to stream
* @param p_is_read_stream whether the stream is a read stream (true) or not (false)
*/
OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file, OPJ_BOOL p_is_read_stream);
/**
* FIXME DOC
* @param p_file the file stream to operate on
OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (const char *fname, OPJ_BOOL p_is_read_stream);
/** Create a stream from a file identified with its filename with a specific buffer size
* @param fname the filename of the file to stream
* @param p_buffer_size size of the chunk used to stream
* @param p_is_read_stream whether the stream is a read stream (true) or not (false)
*/
OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (FILE * p_file, OPJ_SIZE_T p_buffer_size, OPJ_BOOL p_is_read_stream);
OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (const char *fname,
OPJ_SIZE_T p_buffer_size,
OPJ_BOOL p_is_read_stream);
/*
==========================================================
event manager functions definitions

View File

@@ -142,10 +142,10 @@ typedef struct opj_codec_private
void (* opj_destroy) (void * p_codec);
void (* opj_setup_encoder) ( void * p_codec,
opj_cparameters_t * p_param,
struct opj_image * p_image,
struct opj_event_mgr * p_manager);
OPJ_BOOL (* opj_setup_encoder) ( void * p_codec,
opj_cparameters_t * p_param,
struct opj_image * p_image,
struct opj_event_mgr * p_manager);
} m_compression;
} m_codec_data;
/** FIXME DOC*/

View File

@@ -1,2 +1,10 @@
/* create opj_config.h for CMake */
#cmakedefine OPJ_HAVE_STDINT_H @OPJ_HAVE_STDINT_H@
/*--------------------------------------------------------------------------*/
/* OpenJPEG Versioning */
/* Version number. */
#define OPJ_VERSION_MAJOR @OPENJPEG_VERSION_MAJOR@
#define OPJ_VERSION_MINOR @OPENJPEG_VERSION_MINOR@
#define OPJ_VERSION_BUILD @OPENJPEG_VERSION_BUILD@

View File

@@ -815,7 +815,6 @@ opj_pi_iterator_t * opj_pi_create( const opj_image_t *image,
if (!l_pi) {
return NULL;
}
memset(l_pi,0,l_poc_bound * sizeof(opj_pi_iterator_t));
l_current_pi = l_pi;
for (pino = 0; pino < l_poc_bound ; ++pino) {
@@ -827,21 +826,19 @@ opj_pi_iterator_t * opj_pi_create( const opj_image_t *image,
}
l_current_pi->numcomps = image->numcomps;
memset(l_current_pi->comps,0,image->numcomps * sizeof(opj_pi_comp_t));
for (compno = 0; compno < image->numcomps; ++compno) {
opj_pi_comp_t *comp = &l_current_pi->comps[compno];
tccp = &tcp->tccps[compno];
comp->resolutions = (opj_pi_resolution_t*) opj_malloc(tccp->numresolutions * sizeof(opj_pi_resolution_t));
comp->resolutions = (opj_pi_resolution_t*) opj_calloc(tccp->numresolutions, sizeof(opj_pi_resolution_t));
if (!comp->resolutions) {
opj_pi_destroy(l_pi, l_poc_bound);
return 00;
}
comp->numresolutions = tccp->numresolutions;
memset(comp->resolutions,0,tccp->numresolutions * sizeof(opj_pi_resolution_t));
}
++l_current_pi;
}
@@ -1108,7 +1105,8 @@ OPJ_BOOL opj_pi_check_next_level( OPJ_INT32 pos,
break;
case 'P':
switch(tcp->prg){
case OPJ_LRCP||OPJ_RLCP:
case OPJ_LRCP: /* fall through */
case OPJ_RLCP:
if(tcp->prc_t == tcp->prcE){
if(opj_pi_check_next_level(i-1,cp,tileno,pino,prog)){
return OPJ_TRUE;
@@ -1242,7 +1240,6 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
opj_pi_destroy(l_pi, l_bound);
return 00;
}
memset(l_current_pi->include,0, (l_tcp->numlayers + 1) * l_step_l* sizeof(OPJ_INT16));
/* special treatment for the first packet iterator */
l_current_comp = l_current_pi->comps;
@@ -1439,7 +1436,6 @@ opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image,
opj_pi_destroy(l_pi, l_bound);
return 00;
}
memset(l_current_pi->include,0,l_tcp->numlayers * l_step_l* sizeof(OPJ_INT16));
/* special treatment for the first packet iterator*/
l_current_comp = l_current_pi->comps;
@@ -1525,7 +1521,7 @@ opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image,
opj_free(l_tmp_ptr);
l_tmp_ptr = 00;
if (l_tcp->POC && ( p_cp->m_specific_param.m_enc.m_cinema || p_t2_mode == FINAL_PASS)) {
if (l_tcp->POC && (OPJ_IS_CINEMA(p_cp->rsiz) || p_t2_mode == FINAL_PASS)) {
opj_pi_update_encode_poc_and_final(p_cp,p_tile_no,l_tx0,l_tx1,l_ty0,l_ty1,l_max_prec,l_max_res,l_dx_min,l_dy_min);
}
else {
@@ -1554,7 +1550,7 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi,
pi[pino].first = 1;
pi[pino].poc.prg = tcp->prg;
if(!(cp->m_specific_param.m_enc.m_tp_on && ((!cp->m_specific_param.m_enc.m_cinema && (t2_mode == FINAL_PASS)) || cp->m_specific_param.m_enc.m_cinema))){
if(!(cp->m_specific_param.m_enc.m_tp_on && ((!OPJ_IS_CINEMA(cp->rsiz) && (t2_mode == FINAL_PASS)) || OPJ_IS_CINEMA(cp->rsiz)))){
pi[pino].poc.resno0 = tcp->resS;
pi[pino].poc.resno1 = tcp->resE;
pi[pino].poc.compno0 = tcp->compS;

View File

@@ -1170,6 +1170,7 @@ OPJ_BOOL opj_t1_allocate_buffers(
opj_aligned_free(t1->data);
t1->data = (OPJ_INT32*) opj_aligned_malloc(datasize * sizeof(OPJ_INT32));
if(!t1->data){
/* FIXME event manager error callback */
return OPJ_FALSE;
}
t1->datasize=datasize;
@@ -1183,6 +1184,7 @@ OPJ_BOOL opj_t1_allocate_buffers(
opj_aligned_free(t1->flags);
t1->flags = (opj_flag_t*) opj_aligned_malloc(flagssize * sizeof(opj_flag_t));
if(!t1->flags){
/* FIXME event manager error callback */
return OPJ_FALSE;
}
t1->flagssize=flagssize;
@@ -1207,11 +1209,10 @@ opj_t1_t* opj_t1_create()
{
opj_t1_t *l_t1 = 00;
l_t1 = (opj_t1_t*) opj_malloc(sizeof(opj_t1_t));
l_t1 = (opj_t1_t*) opj_calloc(1,sizeof(opj_t1_t));
if (!l_t1) {
return 00;
}
memset(l_t1,0,sizeof(opj_t1_t));
/* create MQC and RAW handles */
l_t1->mqc = opj_mqc_create();

View File

@@ -218,7 +218,7 @@ OPJ_BOOL opj_t2_encode_packets( opj_t2_t* p_t2,
opj_image_t *l_image = p_t2->image;
opj_cp_t *l_cp = p_t2->cp;
opj_tcp_t *l_tcp = &l_cp->tcps[p_tile_no];
OPJ_UINT32 pocno = l_cp->m_specific_param.m_enc.m_cinema == OPJ_CINEMA4K_24? 2: 1;
OPJ_UINT32 pocno = (l_cp->rsiz == OPJ_PROFILE_CINEMA_4K)? 2: 1;
OPJ_UINT32 l_max_comp = l_cp->m_specific_param.m_enc.m_max_comp_size > 0 ? l_image->numcomps : 1;
OPJ_UINT32 l_nb_pocs = l_tcp->numpocs + 1;
@@ -242,6 +242,11 @@ OPJ_BOOL opj_t2_encode_packets( opj_t2_t* p_t2,
/* TODO MSD : check why this function cannot fail (cf. v1) */
opj_pi_create_encode(l_pi, l_cp,p_tile_no,poc,l_tp_num,p_tp_pos,p_t2_mode);
if (l_current_pi->poc.prg == OPJ_PROG_UNKNOWN) {
/* TODO ADE : add an error */
opj_pi_destroy(l_pi, l_nb_pocs);
return OPJ_FALSE;
}
while (opj_pi_next(l_current_pi)) {
if (l_current_pi->layno < p_maxlayers) {
l_nb_bytes = 0;
@@ -274,7 +279,11 @@ OPJ_BOOL opj_t2_encode_packets( opj_t2_t* p_t2,
opj_pi_create_encode(l_pi, l_cp,p_tile_no,p_pino,p_tp_num,p_tp_pos,p_t2_mode);
l_current_pi = &l_pi[p_pino];
if (l_current_pi->poc.prg == OPJ_PROG_UNKNOWN) {
/* TODO ADE : add an error */
opj_pi_destroy(l_pi, l_nb_pocs);
return OPJ_FALSE;
}
while (opj_pi_next(l_current_pi)) {
if (l_current_pi->layno < p_maxlayers) {
l_nb_bytes=0;
@@ -386,6 +395,11 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
}
memset(first_pass_failed, OPJ_TRUE, l_image->numcomps * sizeof(OPJ_BOOL));
if (l_current_pi->poc.prg == OPJ_PROG_UNKNOWN) {
/* TODO ADE : add an error */
opj_pi_destroy(l_pi, l_nb_pocs);
return OPJ_FALSE;
}
while (opj_pi_next(l_current_pi)) {
JAS_FPRINTF( stderr, "packet offset=00000166 prg=%d cmptno=%02d rlvlno=%02d prcno=%03d lyrno=%02d\n\n",
l_current_pi->poc.prg1, l_current_pi->compno, l_current_pi->resno, l_current_pi->precno, l_current_pi->layno );
@@ -477,11 +491,10 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
opj_t2_t* opj_t2_create(opj_image_t *p_image, opj_cp_t *p_cp)
{
/* create the t2 structure */
opj_t2_t *l_t2 = (opj_t2_t*)opj_malloc(sizeof(opj_t2_t));
opj_t2_t *l_t2 = (opj_t2_t*)opj_calloc(1,sizeof(opj_t2_t));
if (!l_t2) {
return NULL;
}
memset(l_t2,0,sizeof(opj_t2_t));
l_t2->image = p_image;
l_t2->cp = p_cp;
@@ -599,6 +612,10 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno,
}
bio = opj_bio_create();
if (!bio) {
/* FIXME event manager error callback */
return OPJ_FALSE;
}
opj_bio_init_enc(bio, c, length);
opj_bio_write(bio, 1, 1); /* Empty header bit */
@@ -863,11 +880,10 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
if (p_tcp->csty & J2K_CP_CSTY_SOP) {
if (p_max_length < 6) {
/* TODO opj_event_msg(p_t2->cinfo->event_mgr, EVT_WARNING, "Not enough space for expected SOP marker\n"); */
printf("Not enough space for expected SOP marker\n");
fprintf(stderr, "Not enough space for expected SOP marker\n");
} else if ((*l_current_data) != 0xff || (*(l_current_data + 1) != 0x91)) {
/* TODO opj_event_msg(p_t2->cinfo->event_mgr, EVT_WARNING, "Expected SOP marker\n"); */
printf("Expected SOP marker\n");
fprintf(stderr, "Error : expected SOP marker\n");
fprintf(stderr, "Warning: expected SOP marker\n");
} else {
l_current_data += 6;
}
@@ -917,7 +933,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
/* EPH markers */
if (p_tcp->csty & J2K_CP_CSTY_EPH) {
if (p_max_length < 2) {
if ((*l_modified_length_ptr - (OPJ_UINT32)(l_header_data - *l_header_data_start)) < 2U) {
fprintf(stderr, "Not enough space for expected EPH marker\n");
} else if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) {
fprintf(stderr, "Error : expected EPH marker\n");
@@ -1045,7 +1061,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
/* EPH markers */
if (p_tcp->csty & J2K_CP_CSTY_EPH) {
if (p_max_length < 2) {
if ((*l_modified_length_ptr - (OPJ_UINT32)(l_header_data - *l_header_data_start)) < 2U) {
fprintf(stderr, "Not enough space for expected EPH marker\n");
} else if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) {
/* TODO opj_event_msg(t2->cinfo->event_mgr, EVT_ERROR, "Expected EPH marker\n"); */
@@ -1129,7 +1145,8 @@ OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2,
}
do {
if (l_current_data + l_seg->newlen > p_src_data + p_max_length) {
/* Check possible overflow (on l_current_data only, assumes input args already checked) then size */
if ((((OPJ_SIZE_T)l_current_data + (OPJ_SIZE_T)l_seg->newlen) < (OPJ_SIZE_T)l_current_data) || (l_current_data + l_seg->newlen > p_src_data + p_max_length)) {
fprintf(stderr, "read: segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
l_seg->newlen, p_max_length, cblkno, p_pi->precno, bandno, p_pi->resno, p_pi->compno);
return OPJ_FALSE;
@@ -1154,11 +1171,18 @@ OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2,
};
#endif /* USE_JPWL */
/* Check possible overflow on size */
if ((l_cblk->data_current_size + l_seg->newlen) < l_cblk->data_current_size) {
fprintf(stderr, "read: segment too long (%d) with current size (%d > %d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
l_seg->newlen, l_cblk->data_current_size, 0xFFFFFFFF - l_seg->newlen, cblkno, p_pi->precno, bandno, p_pi->resno, p_pi->compno);
return OPJ_FALSE;
}
/* Check if the cblk->data have allocated enough memory */
if ((l_cblk->data_current_size + l_seg->newlen) > l_cblk->data_max_size) {
OPJ_BYTE* new_cblk_data = (OPJ_BYTE*) opj_realloc(l_cblk->data, l_cblk->data_current_size + l_seg->newlen);
if(! new_cblk_data) {
opj_free(l_cblk->data);
l_cblk->data = NULL;
l_cblk->data_max_size = 0;
/* opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to realloc code block cata!\n"); */
return OPJ_FALSE;
@@ -1197,6 +1221,7 @@ OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2,
*(p_data_read) = (OPJ_UINT32)(l_current_data - p_src_data);
return OPJ_TRUE;
}
@@ -1254,7 +1279,8 @@ OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2,
}
do {
if (* p_data_read + l_seg->newlen > p_max_length) {
/* Check possible overflow then size */
if (((*p_data_read + l_seg->newlen) < (*p_data_read)) || ((*p_data_read + l_seg->newlen) > p_max_length)) {
fprintf(stderr, "skip: segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
l_seg->newlen, p_max_length, cblkno, p_pi->precno, bandno, p_pi->resno, p_pi->compno);
return OPJ_FALSE;

View File

@@ -175,20 +175,18 @@ opj_tcd_t* opj_tcd_create(OPJ_BOOL p_is_decoder)
opj_tcd_t *l_tcd = 00;
/* create the tcd structure */
l_tcd = (opj_tcd_t*) opj_malloc(sizeof(opj_tcd_t));
l_tcd = (opj_tcd_t*) opj_calloc(1,sizeof(opj_tcd_t));
if (!l_tcd) {
return 00;
}
memset(l_tcd,0,sizeof(opj_tcd_t));
l_tcd->m_is_decoder = p_is_decoder ? 1 : 0;
l_tcd->tcd_image = (opj_tcd_image_t*)opj_malloc(sizeof(opj_tcd_image_t));
l_tcd->tcd_image = (opj_tcd_image_t*)opj_calloc(1,sizeof(opj_tcd_image_t));
if (!l_tcd->tcd_image) {
opj_free(l_tcd);
return 00;
}
memset(l_tcd->tcd_image,0,sizeof(opj_tcd_image_t));
return l_tcd;
}
@@ -467,6 +465,10 @@ OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd,
tile_info->numpix = tcd_tile->numpix;
tile_info->distotile = tcd_tile->distotile;
tile_info->thresh = (OPJ_FLOAT64 *) opj_malloc(tcd_tcp->numlayers * sizeof(OPJ_FLOAT64));
if (!tile_info->thresh) {
/* FIXME event manager error callback */
return OPJ_FALSE;
}
}
for (layno = 0; layno < tcd_tcp->numlayers; layno++) {
@@ -502,7 +504,7 @@ OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd,
opj_tcd_makelayer(tcd, layno, thresh, 0);
if (cp->m_specific_param.m_enc.m_fixed_quality) { /* fixed_quality */
if(cp->m_specific_param.m_enc.m_cinema){
if(OPJ_IS_CINEMA(cp->rsiz)){
if (! opj_t2_encode_packets(t2,tcd->tcd_tileno, tcd_tile, layno + 1, dest, p_data_written, maxlen, cstr_info,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,THRESH_CALC)) {
lo = thresh;
@@ -575,23 +577,18 @@ OPJ_BOOL opj_tcd_init( opj_tcd_t *p_tcd,
opj_image_t * p_image,
opj_cp_t * p_cp )
{
OPJ_UINT32 l_tile_comp_size;
p_tcd->image = p_image;
p_tcd->cp = p_cp;
p_tcd->tcd_image->tiles = (opj_tcd_tile_t *) opj_malloc(sizeof(opj_tcd_tile_t));
p_tcd->tcd_image->tiles = (opj_tcd_tile_t *) opj_calloc(1,sizeof(opj_tcd_tile_t));
if (! p_tcd->tcd_image->tiles) {
return OPJ_FALSE;
}
memset(p_tcd->tcd_image->tiles,0, sizeof(opj_tcd_tile_t));
l_tile_comp_size = p_image->numcomps * (OPJ_UINT32)sizeof(opj_tcd_tilecomp_t);
p_tcd->tcd_image->tiles->comps = (opj_tcd_tilecomp_t *) opj_malloc(l_tile_comp_size);
p_tcd->tcd_image->tiles->comps = (opj_tcd_tilecomp_t *) opj_calloc(p_image->numcomps,sizeof(opj_tcd_tilecomp_t));
if (! p_tcd->tcd_image->tiles->comps ) {
return OPJ_FALSE;
}
memset( p_tcd->tcd_image->tiles->comps , 0 , l_tile_comp_size);
p_tcd->tcd_image->tiles->numcomps = p_image->numcomps;
p_tcd->tp_pos = p_cp->m_specific_param.m_enc.m_tp_pos;
@@ -679,7 +676,7 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \
/*tile->numcomps = image->numcomps; */ \
for(compno = 0; compno < l_tile->numcomps; ++compno) { \
/*fprintf(stderr, "compno = %d/%d\n", compno, l_tile->numcomps);*/ \
\
l_image_comp->resno_decoded = 0; \
/* border of each l_tile component (global) */ \
l_tilec->x0 = opj_int_ceildiv(l_tile->x0, (OPJ_INT32)l_image_comp->dx); \
l_tilec->y0 = opj_int_ceildiv(l_tile->y0, (OPJ_INT32)l_image_comp->dy); \
@@ -973,15 +970,14 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \
OPJ_INT32 cblkxend = cblkxstart + (1 << cblkwidthexpn); \
OPJ_INT32 cblkyend = cblkystart + (1 << cblkheightexpn); \
\
if (! FUNCTION_ELEMENT(l_code_block)) { \
return OPJ_FALSE; \
} \
/* code-block size (global) */ \
l_code_block->x0 = opj_int_max(cblkxstart, l_current_precinct->x0); \
l_code_block->y0 = opj_int_max(cblkystart, l_current_precinct->y0); \
l_code_block->x1 = opj_int_min(cblkxend, l_current_precinct->x1); \
l_code_block->y1 = opj_int_min(cblkyend, l_current_precinct->y1); \
\
if (! FUNCTION_ELEMENT(l_code_block)) { \
return OPJ_FALSE; \
} \
++l_code_block; \
} \
++l_current_precinct; \
@@ -1021,20 +1017,17 @@ OPJ_BOOL opj_tcd_code_block_enc_allocate (opj_tcd_cblk_enc_t * p_code_block)
p_code_block->data+=1;
/* no memset since data */
p_code_block->layers = (opj_tcd_layer_t*) opj_malloc(100 * sizeof(opj_tcd_layer_t));
p_code_block->layers = (opj_tcd_layer_t*) opj_calloc(100, sizeof(opj_tcd_layer_t));
if (! p_code_block->layers) {
return OPJ_FALSE;
}
p_code_block->passes = (opj_tcd_pass_t*) opj_malloc(100 * sizeof(opj_tcd_pass_t));
p_code_block->passes = (opj_tcd_pass_t*) opj_calloc(100, sizeof(opj_tcd_pass_t));
if (! p_code_block->passes) {
return OPJ_FALSE;
}
}
memset(p_code_block->layers,0,100 * sizeof(opj_tcd_layer_t));
memset(p_code_block->passes,0,100 * sizeof(opj_tcd_pass_t));
return OPJ_TRUE;
}
@@ -1043,8 +1036,6 @@ OPJ_BOOL opj_tcd_code_block_enc_allocate (opj_tcd_cblk_enc_t * p_code_block)
*/
OPJ_BOOL opj_tcd_code_block_dec_allocate (opj_tcd_cblk_dec_t * p_code_block)
{
OPJ_UINT32 l_seg_size;
if (! p_code_block->data) {
p_code_block->data = (OPJ_BYTE*) opj_malloc(OPJ_J2K_DEFAULT_CBLK_DATA_SIZE);
@@ -1054,19 +1045,27 @@ OPJ_BOOL opj_tcd_code_block_dec_allocate (opj_tcd_cblk_dec_t * p_code_block)
p_code_block->data_max_size = OPJ_J2K_DEFAULT_CBLK_DATA_SIZE;
/*fprintf(stderr, "Allocate 8192 elements of code_block->data\n");*/
l_seg_size = OPJ_J2K_DEFAULT_NB_SEGS * sizeof(opj_tcd_seg_t);
p_code_block->segs = (opj_tcd_seg_t *) opj_malloc(l_seg_size);
p_code_block->segs = (opj_tcd_seg_t *) opj_calloc(OPJ_J2K_DEFAULT_NB_SEGS,sizeof(opj_tcd_seg_t));
if (! p_code_block->segs) {
return OPJ_FALSE;
}
memset(p_code_block->segs,0,l_seg_size);
/*fprintf(stderr, "Allocate %d elements of code_block->data\n", OPJ_J2K_DEFAULT_NB_SEGS * sizeof(opj_tcd_seg_t));*/
p_code_block->m_current_max_segs = OPJ_J2K_DEFAULT_NB_SEGS;
/*fprintf(stderr, "m_current_max_segs of code_block->data = %d\n", p_code_block->m_current_max_segs);*/
}
/* TODO */
/*p_code_block->numsegs = 0; */
} else {
/* sanitize */
OPJ_BYTE* l_data = p_code_block->data;
OPJ_UINT32 l_data_max_size = p_code_block->data_max_size;
opj_tcd_seg_t * l_segs = p_code_block->segs;
OPJ_UINT32 l_current_max_segs = p_code_block->m_current_max_segs;
memset(p_code_block, 0, sizeof(opj_tcd_cblk_dec_t));
p_code_block->data = l_data;
p_code_block->data_max_size = l_data_max_size;
p_code_block->segs = l_segs;
p_code_block->m_current_max_segs = l_current_max_segs;
}
return OPJ_TRUE;
}
@@ -1135,6 +1134,10 @@ OPJ_BOOL opj_tcd_encode_tile( opj_tcd_t *p_tcd,
p_cstr_info->tile[p_tile_no].pdy[i] = (int)l_tccp->prch[i];
}
p_cstr_info->tile[p_tile_no].packet = (opj_packet_info_t*) opj_calloc((size_t)p_cstr_info->numcomps * (size_t)p_cstr_info->numlayers * l_num_packs, sizeof(opj_packet_info_t));
if (!p_cstr_info->tile[p_tile_no].packet) {
/* FIXME event manager error callback */
return OPJ_FALSE;
}
}
/* << INDEX */

View File

@@ -57,12 +57,11 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv) {
OPJ_UINT32 numlvls;
OPJ_UINT32 n;
tree = (opj_tgt_tree_t *) opj_malloc(sizeof(opj_tgt_tree_t));
tree = (opj_tgt_tree_t *) opj_calloc(1,sizeof(opj_tgt_tree_t));
if(!tree) {
fprintf(stderr, "ERROR in tgt_create while allocating tree\n");
return 00;
}
memset(tree,0,sizeof(opj_tgt_tree_t));
tree->numleafsh = numleafsh;
tree->numleafsv = numleafsv;
@@ -92,7 +91,6 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv) {
opj_free(tree);
return 00;
}
memset(tree->nodes,0,tree->numnodes * sizeof(opj_tgt_node_t));
tree->nodes_size = tree->numnodes * (OPJ_UINT32)sizeof(opj_tgt_node_t);
node = tree->nodes;

View File

@@ -43,7 +43,7 @@ static void info_callback(const char *msg, void *client_data);
static Byte_t * imagetopnm(opj_image_t *image, ihdrbox_param_t **ihdrbox);
Byte_t * j2k_to_pnm( FILE *fp, ihdrbox_param_t **ihdrbox)
Byte_t * j2k_to_pnm( const char *fn, ihdrbox_param_t **ihdrbox)
{
Byte_t *pnmstream = NULL;
opj_dparameters_t parameters; /* decompression parameters */
@@ -55,7 +55,7 @@ Byte_t * j2k_to_pnm( FILE *fp, ihdrbox_param_t **ihdrbox)
opj_set_default_decoder_parameters(&parameters);
/* set a byte stream */
l_stream = opj_stream_create_default_file_stream( fp, 1);
l_stream = opj_stream_create_default_file_stream( fn, OPJ_TRUE);
if (!l_stream){
fprintf(stderr, "ERROR -> failed to create the stream from the file\n");
return NULL;

View File

@@ -34,6 +34,6 @@
#include "byte_manager.h"
#include "ihdrbox_manager.h"
Byte_t * j2k_to_pnm( FILE *fp, ihdrbox_param_t **ihdrbox);
Byte_t * j2k_to_pnm( const char *fn, ihdrbox_param_t **ihdrbox);
#endif /* !JP2K_DECODER_H_ */

View File

@@ -76,19 +76,34 @@ Byte_t * jpipstream_to_pnm( Byte_t *jpipstream, msgqueue_param_t *msgqueue, Byte
Byte_t *pnmstream;
Byte_t *j2kstream; /* j2k or jp2 codestream */
Byte8_t j2klen;
size_t retlen;
FILE *fp;
const char j2kfname[] = "tmp.j2k";
j2kstream = recons_j2k( msgqueue, jpipstream, csn, fw, fh, &j2klen);
fp = fopen( j2kfname, "w+b");
fwrite( j2kstream, j2klen, 1, fp);
if( !fp )
{
return NULL;
}
j2kstream = recons_j2k( msgqueue, jpipstream, csn, fw, fh, &j2klen);
if( !j2kstream )
{
fclose(fp);
remove( j2kfname);
return NULL;
}
retlen = fwrite( j2kstream, 1, j2klen, fp);
opj_free( j2kstream);
fseek( fp, 0, SEEK_SET);
fclose(fp);
if( retlen != j2klen )
{
remove( j2kfname);
return NULL;
}
pnmstream = j2k_to_pnm( fp, ihdrbox);
pnmstream = j2k_to_pnm( j2kfname, ihdrbox);
fclose( fp);
remove( j2kfname);
return pnmstream;

View File

@@ -30,6 +30,7 @@
#ifdef _WIN32
#include <windows.h>
typedef SSIZE_T ssize_t;
#else
#include <sys/types.h>
#include <sys/socket.h>

View File

@@ -150,9 +150,7 @@ static int infile_format(const char *fname)
/* -------------------------------------------------------------------------- */
int main(int argc, char **argv)
{
FILE *fsrc = NULL;
OPJ_UINT32 index;
OPJ_UINT32 index;
opj_dparameters_t parameters; /* decompression parameters */
opj_image_t* image = NULL;
opj_stream_t *l_stream = NULL; /* Stream */
@@ -175,13 +173,6 @@ int main(int argc, char **argv)
strncpy(parameters.infile, argv[1], OPJ_PATH_LEN - 1);
/* read the input file */
/* ------------------- */
fsrc = fopen(parameters.infile, "rb");
if (!fsrc) {
fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile);
return EXIT_FAILURE;
}
/* decode the JPEG2000 stream */
/* -------------------------- */
@@ -218,10 +209,9 @@ int main(int argc, char **argv)
opj_set_warning_handler(l_codec, warning_callback,00);
opj_set_error_handler(l_codec, error_callback,00);
l_stream = opj_stream_create_default_file_stream(fsrc,1);
l_stream = opj_stream_create_default_file_stream(parameters.infile,1);
if (!l_stream){
fclose(fsrc);
fprintf(stderr, "ERROR -> failed to create the stream from the file\n");
fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n", parameters.infile);
return EXIT_FAILURE;
}
@@ -229,7 +219,6 @@ int main(int argc, char **argv)
if ( !opj_setup_decoder(l_codec, &parameters) ){
fprintf(stderr, "ERROR -> j2k_dump: failed to setup the decoder\n");
opj_stream_destroy(l_stream);
fclose(fsrc);
opj_destroy_codec(l_codec);
return EXIT_FAILURE;
}
@@ -238,7 +227,6 @@ int main(int argc, char **argv)
if(! opj_read_header(l_stream, l_codec, &image)){
fprintf(stderr, "ERROR -> j2k_to_image: failed to read the header\n");
opj_stream_destroy(l_stream);
fclose(fsrc);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
return EXIT_FAILURE;
@@ -262,7 +250,6 @@ int main(int argc, char **argv)
opj_destroy_cstr_info(&cstr_info); \
opj_destroy_codec(l_codec); \
opj_image_destroy(image); \
fclose(fsrc); \
return EXIT_FAILURE; \
} \
for(index = 0; index < image->numcomps; ++index) { \
@@ -272,7 +259,6 @@ int main(int argc, char **argv)
opj_destroy_cstr_info(&cstr_info); \
opj_destroy_codec(l_codec); \
opj_image_destroy(image); \
fclose(fsrc); \
return EXIT_FAILURE; \
} \
} \
@@ -297,9 +283,6 @@ int main(int argc, char **argv)
/* Free image data structure */
opj_image_destroy(image);
/* Close the input file */
fclose(fsrc);
return EXIT_SUCCESS;
}
/*end main*/

View File

@@ -57,6 +57,11 @@ set(BLACKLIST_JPEG2000
gdal_fuzzer_unchecked_numresolutions.jp2
mem-b2ace68c-1381.jp2
1851.pdf.SIGSEGV.ce9.948.jp2
1888.pdf.asan.35.988.jp2
issue362-2863.jp2 #kdu_jp2info ok
issue362-2866.jp2
issue362-2894.jp2
issue400.jp2 #kdu_jp2info ok
)
file(GLOB_RECURSE OPJ_DATA_NR_LIST

View File

@@ -41,22 +41,12 @@ endif()
file(READ ${REFFILE} variable)
foreach(pgxfullpath ${globfiles})
file(MD5 ${pgxfullpath} output)
get_filename_component(pgxfile ${pgxfullpath} NAME)
execute_process(
COMMAND ${CMAKE_COMMAND} -E md5sum ${pgxfile}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Temporary
RESULT_VARIABLE res
OUTPUT_VARIABLE output
ERROR_VARIABLE error_output
OUTPUT_STRIP_TRAILING_WHITESPACE # important
)
# Pass the output back to ctest
if(res)
message(SEND_ERROR "md5 could not be computed, it failed with value ${res}. Output was: ${error_output}")
endif()
string(REGEX MATCH "[0-9a-f]+ ${pgxfile}" output_var "${variable}")
set(output "${output} ${pgxfile}")
if("${output_var}" STREQUAL "${output}")
message(STATUS "equal: [${output_var}] vs [${output}]")

View File

@@ -174,6 +174,26 @@ opj_decompress -i @INPUT_NR_PATH@/issue226.j2k -o @TEMP_PATH@/
#!opj_decompress -i @INPUT_NR_PATH@/3459.pdf.asan.6c.2734.0.jp2 -o @TEMP_PATH@/3459.pdf.asan.6c.2734.0.jp2.pgx
#!opj_decompress -i @INPUT_NR_PATH@/3459.pdf.asan.6c.2734.1.jp2 -o @TEMP_PATH@/3459.pdf.asan.6c.2734.1.jp2.pgx
#!opj_decompress -i @INPUT_NR_PATH@/3459.pdf.asan.6c.2734.2.jp2 -o @TEMP_PATH@/3459.pdf.asan.6c.2734.2.jp2.pgx
# issue 362 (from pdfium fuzz engine)
# Invalid PPM Marker
!opj_decompress -i @INPUT_NR_PATH@/issue362-2863.jp2 -o @TEMP_PATH@/issue362-2863.jp2.pgx
# Invalid ftyp box size
!opj_decompress -i @INPUT_NR_PATH@/issue362-2866.jp2 -o @TEMP_PATH@/issue362-2866.jp2.pgx
!opj_decompress -i @INPUT_NR_PATH@/issue362-2894.jp2 -o @TEMP_PATH@/issue362-2894.jp2.pgx
# issue 363 (from pdfium fuzz engine)
# Invalid Tile part length
!opj_decompress -i @INPUT_NR_PATH@/issue363-4723.jp2 -o @TEMP_PATH@/issue363-4723.jp2.pgx
# Invalid Marker length
!opj_decompress -i @INPUT_NR_PATH@/issue363-4740.jp2 -o @TEMP_PATH@/issue363-4740.jp2.pgx
!opj_decompress -i @INPUT_NR_PATH@/issue363-4792.jp2 -o @TEMP_PATH@/issue363-4792.jp2.pgx
# issue 390 (from pdfium fuzz engine) Invalid segment size
!opj_decompress -i @INPUT_NR_PATH@/issue390.jp2 -o @TEMP_PATH@/issue390.jp2.pgx
# issue 391 (from pdfium fuzz engine) Invalid segment size
!opj_decompress -i @INPUT_NR_PATH@/issue391.jp2 -o @TEMP_PATH@/issue391.jp2.pgx
# issue 400 (from pdfium fuzz engine) Unknown Scod value in COD marker
!opj_decompress -i @INPUT_NR_PATH@/issue400.jp2 -o @TEMP_PATH@/issue400.jp2.pgx
# issue 413 (from pdfium fuzz engine) Unknown progression order in COD marker
!opj_decompress -i @INPUT_NR_PATH@/issue413.jp2 -o @TEMP_PATH@/issue413.jp2.pgx
# decode with specific area
# prec=12; nb_c=1

View File

@@ -37,6 +37,11 @@
* only work on linux since I need memmem function
*/
/*
* Add support for other signatures:
*
* obj<</Subtype/Image/Length 110494/Filter/JPXDecode/BitsPerComponent 8/ColorSpace/DeviceRGB/Width 712/Height 1052>>stream
*/
#define _GNU_SOURCE
#include <string.h>
#include <stdio.h>
@@ -98,7 +103,17 @@ int main(int argc, char *argv[])
assert( r );
/*fprintf( stderr, "DEBUG: %s", r );*/
s = sscanf(r, "JPXDecode]/Length %d/Width %*d/BitsPerComponent %*d/Height %*d", &len);
assert( s == 1 );
if( s == 0 )
{ // try again harder
const int ret = fseek(f, offets[i] - 40, SEEK_SET); // 40 is magic number
assert( ret == 0 );
r = fgets(buffer, sizeof(buffer), f);
assert( r );
const char needle2[] = "/Length";
char * s2 = strstr(buffer, needle2);
s = sscanf(s2, "/Length %d/", &len);
}
if( s == 1 )
{
FILE *jp2;
int j;

View File

@@ -165,7 +165,6 @@ int main (int argc, char *argv[])
opj_dparameters_t l_param;
opj_codec_t * l_codec;
opj_image_t * l_image;
FILE * l_file;
opj_stream_t * l_stream;
OPJ_UINT32 l_data_size;
OPJ_UINT32 l_max_data_size = 1000;
@@ -204,17 +203,8 @@ int main (int argc, char *argv[])
return EXIT_FAILURE;
}
l_file = fopen(input_file,"rb");
if (! l_file)
{
fprintf(stdout, "ERROR while opening input file\n");
free(l_data);
return EXIT_FAILURE;
}
l_stream = opj_stream_create_default_file_stream(l_file,OPJ_TRUE);
l_stream = opj_stream_create_default_file_stream(input_file,OPJ_TRUE);
if (!l_stream){
fclose(l_file);
free(l_data);
fprintf(stderr, "ERROR -> failed to create the stream from the file\n");
return EXIT_FAILURE;
@@ -253,7 +243,6 @@ int main (int argc, char *argv[])
default:
{
fprintf(stderr, "ERROR -> Not a valid JPEG2000 file!\n");
fclose(l_file);
free(l_data);
opj_stream_destroy(l_stream);
return EXIT_FAILURE;
@@ -269,7 +258,6 @@ int main (int argc, char *argv[])
if (! opj_setup_decoder(l_codec, &l_param))
{
fprintf(stderr, "ERROR -> j2k_dump: failed to setup the decoder\n");
fclose(l_file);
free(l_data);
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
@@ -280,7 +268,6 @@ int main (int argc, char *argv[])
if (! opj_read_header(l_stream, l_codec, &l_image))
{
fprintf(stderr, "ERROR -> j2k_to_image: failed to read the header\n");
fclose(l_file);
free(l_data);
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
@@ -289,7 +276,6 @@ int main (int argc, char *argv[])
if (!opj_set_decode_area(l_codec, l_image, da_x0, da_y0,da_x1, da_y1)){
fprintf(stderr, "ERROR -> j2k_to_image: failed to set the decoded area\n");
fclose(l_file);
free(l_data);
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
@@ -311,7 +297,6 @@ int main (int argc, char *argv[])
&l_nb_comps,
&l_go_on))
{
fclose(l_file);
free(l_data);
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
@@ -326,7 +311,6 @@ int main (int argc, char *argv[])
OPJ_BYTE *l_new_data = (OPJ_BYTE *) realloc(l_data, l_data_size);
if (! l_new_data)
{
fclose(l_file);
free(l_new_data);
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
@@ -339,7 +323,6 @@ int main (int argc, char *argv[])
if (! opj_decode_tile_data(l_codec,l_tile_index,l_data,l_data_size,l_stream))
{
fclose(l_file);
free(l_data);
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
@@ -352,7 +335,6 @@ int main (int argc, char *argv[])
if (! opj_end_decompress(l_codec,l_stream))
{
fclose(l_file);
free(l_data);
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
@@ -361,7 +343,6 @@ int main (int argc, char *argv[])
}
/* Free memory */
fclose(l_file);
free(l_data);
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);

View File

@@ -66,7 +66,6 @@ int main (int argc, char *argv[])
opj_codec_t * l_codec;
opj_image_t * l_image;
opj_image_cmptparm_t l_params [NUM_COMPS_MAX];
FILE * l_file;
opj_stream_t * l_stream;
OPJ_UINT32 l_nb_tiles;
OPJ_UINT32 l_data_size;
@@ -264,18 +263,9 @@ int main (int argc, char *argv[])
return 1;
}
l_file = fopen(output_file,"wb");
if (! l_file) {
fprintf(stderr, "ERROR -> test_tile_encoder: failed to create the output file!\n");
opj_destroy_codec(l_codec);
opj_image_destroy(l_image);
return 1;
}
l_stream = opj_stream_create_default_file_stream(l_file, OPJ_FALSE);
l_stream = opj_stream_create_default_file_stream(output_file, OPJ_FALSE);
if (! l_stream) {
fprintf(stderr, "ERROR -> test_tile_encoder: failed to create the stream from the output file %s !\n",output_file );
fclose(l_file);
opj_destroy_codec(l_codec);
opj_image_destroy(l_image);
return 1;
@@ -283,8 +273,7 @@ int main (int argc, char *argv[])
if (! opj_start_compress(l_codec,l_image,l_stream)) {
fprintf(stderr, "ERROR -> test_tile_encoder: failed to start compress!\n");
opj_stream_destroy(l_stream);
fclose(l_file);
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
opj_image_destroy(l_image);
return 1;
@@ -293,8 +282,7 @@ int main (int argc, char *argv[])
for (i=0;i<l_nb_tiles;++i) {
if (! opj_write_tile(l_codec,i,l_data,l_data_size,l_stream)) {
fprintf(stderr, "ERROR -> test_tile_encoder: failed to write the tile %d!\n",i);
opj_stream_destroy(l_stream);
fclose(l_file);
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
opj_image_destroy(l_image);
return 1;
@@ -303,15 +291,13 @@ int main (int argc, char *argv[])
if (! opj_end_compress(l_codec,l_stream)) {
fprintf(stderr, "ERROR -> test_tile_encoder: failed to end compress!\n");
opj_stream_destroy(l_stream);
fclose(l_file);
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
opj_image_destroy(l_image);
return 1;
}
opj_stream_destroy(l_stream);
fclose(l_file);
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
opj_image_destroy(l_image);

View File

@@ -71,7 +71,6 @@ int main(int argc, char *argv[])
opj_image_t *image;
opj_codec_t* l_codec = 00;
OPJ_BOOL bSuccess;
FILE *f;
opj_stream_t *l_stream = 00;
(void)argc;
(void)argv;
@@ -111,11 +110,7 @@ int main(int argc, char *argv[])
opj_setup_encoder(l_codec, &parameters, image);
strcpy(parameters.outfile, "testempty1.j2k");
f = fopen(parameters.outfile, "wb");
assert( f );
l_stream = opj_stream_create_default_file_stream(f,OPJ_FALSE);
l_stream = opj_stream_create_default_file_stream("testempty1.j2k",OPJ_FALSE);
assert(l_stream);
bSuccess = opj_start_compress(l_codec,image,l_stream);
if( !bSuccess )
@@ -133,7 +128,6 @@ int main(int argc, char *argv[])
assert( bSuccess );
opj_stream_destroy(l_stream);
fclose(f);
opj_destroy_codec(l_codec);
opj_image_destroy(image);

View File

@@ -73,7 +73,6 @@ int main(int argc, char *argv[])
opj_image_t *image;
opj_codec_t* l_codec = 00;
OPJ_BOOL bSuccess;
FILE *f;
opj_stream_t *l_stream = 00;
(void)argc;
(void)argv;
@@ -90,6 +89,7 @@ int main(int argc, char *argv[])
cmptparm.dy = subsampling_dy;
cmptparm.w = image_width;
cmptparm.h = image_height;
strncpy(parameters.outfile, outputfile, sizeof(parameters.outfile)-1);
image = opj_image_create(numcomps, &cmptparm, color_space);
assert( image );
@@ -115,15 +115,10 @@ int main(int argc, char *argv[])
opj_setup_encoder(l_codec, &parameters, image);
strcpy(parameters.outfile, outputfile);
f = fopen(parameters.outfile, "wb");
assert( f );
l_stream = opj_stream_create_default_file_stream(f,OPJ_FALSE);
l_stream = opj_stream_create_default_file_stream(parameters.outfile,OPJ_FALSE);
if( !l_stream )
{
fprintf( stderr, "Something went wrong during creation of stream\n" );
fclose(f);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
opj_stream_destroy(l_stream);
@@ -133,7 +128,6 @@ int main(int argc, char *argv[])
bSuccess = opj_start_compress(l_codec,image,l_stream);
if( !bSuccess )
{
fclose(f);
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
@@ -147,7 +141,6 @@ int main(int argc, char *argv[])
assert( bSuccess );
opj_stream_destroy(l_stream);
fclose(f);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
@@ -155,10 +148,8 @@ int main(int argc, char *argv[])
/* read back the generated file */
{
FILE *fsrc = fopen(outputfile, "rb");
opj_codec_t* d_codec = 00;
opj_dparameters_t dparameters;
assert( fsrc );
d_codec = opj_create_decompress(OPJ_CODEC_J2K);
opj_set_info_handler(d_codec, info_callback,00);
@@ -168,7 +159,7 @@ int main(int argc, char *argv[])
bSuccess = opj_setup_decoder(d_codec, &dparameters);
assert( bSuccess );
l_stream = opj_stream_create_default_file_stream(fsrc,1);
l_stream = opj_stream_create_default_file_stream(outputfile,1);
assert( l_stream );
bSuccess = opj_read_header(l_stream, d_codec, &image);
@@ -181,7 +172,7 @@ int main(int argc, char *argv[])
assert( bSuccess );
opj_stream_destroy(l_stream);
fclose(fsrc);
opj_destroy_codec(d_codec);
opj_image_destroy(image);