Compare commits
40 Commits
version.2.
...
wg1n6848
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ddbe4dc4d | ||
|
|
0ac0b3d823 | ||
|
|
09fb8b6989 | ||
|
|
9e6c62199a | ||
|
|
d47f7a249d | ||
|
|
7280263988 | ||
|
|
3e1fad2da4 | ||
|
|
d72940c56b | ||
|
|
ad4fad0965 | ||
|
|
aff9cb39ed | ||
|
|
0a3f234df7 | ||
|
|
efb70af001 | ||
|
|
e65303b903 | ||
|
|
413de4fbfa | ||
|
|
984351f86f | ||
|
|
f8796711e8 | ||
|
|
0b540067b1 | ||
|
|
3df347eded | ||
|
|
eb7c6d295a | ||
|
|
f126eb0d41 | ||
|
|
7256e43c48 | ||
|
|
a0a3af1dee | ||
|
|
48832d944f | ||
|
|
06bd61b571 | ||
|
|
a1c754c737 | ||
|
|
fef1276901 | ||
|
|
45f33cdbd6 | ||
|
|
1acfa211ae | ||
|
|
2f3fd1194e | ||
|
|
f08af3ed82 | ||
|
|
2720a1a405 | ||
|
|
31fd8d3fe8 | ||
|
|
6868ee373e | ||
|
|
b9a247b559 | ||
|
|
50a205d20f | ||
|
|
b0072bf658 | ||
|
|
2c810567dd | ||
|
|
0a1a29a7fe | ||
|
|
7d21871ed8 | ||
|
|
a38b97fae0 |
@@ -146,6 +146,11 @@ if(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
|
|||||||
set(OPENJPEG_INSTALL_PACKAGE_DIR "${OPENJPEG_INSTALL_LIB_DIR}/${OPENJPEG_INSTALL_SUBDIR}")
|
set(OPENJPEG_INSTALL_PACKAGE_DIR "${OPENJPEG_INSTALL_LIB_DIR}/${OPENJPEG_INSTALL_SUBDIR}")
|
||||||
endif()
|
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:
|
# Big endian test:
|
||||||
include (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
|
include (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
|
||||||
|
|||||||
4
NEWS
4
NEWS
@@ -2,7 +2,7 @@
|
|||||||
OpenJPEG NEWS - user visible changes
|
OpenJPEG NEWS - user visible changes
|
||||||
====================================
|
====================================
|
||||||
|
|
||||||
Changes from OpenJPEG 2.0.0 to OpenJPEG 2.1.0
|
Changes from OpenJPEG 2.0.0 to OpenJPEG 2.X.X
|
||||||
----------------------------------------------
|
----------------------------------------------
|
||||||
|
|
||||||
New Features:
|
New Features:
|
||||||
@@ -39,7 +39,7 @@ Misc:
|
|||||||
* OpenJPEG is now officialy conformant with JPEG 2000 Part-1
|
* OpenJPEG is now officialy conformant with JPEG 2000 Part-1
|
||||||
and will soon become official reference software at the
|
and will soon become official reference software at the
|
||||||
JPEG committee.
|
JPEG committee.
|
||||||
* Huge amount of bug fixes. See CHANGES for details.
|
* Huge amount of bug fixes. See CHANGES for details.
|
||||||
|
|
||||||
|
|
||||||
Changes from OpenJPEG 1.5.x to OpenJPEG 2.0.0
|
Changes from OpenJPEG 1.5.x to OpenJPEG 2.0.0
|
||||||
|
|||||||
50
THANKS
50
THANKS
@@ -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
|
or submitting actual code. Here is a list of these people. Help me keep
|
||||||
it complete and exempt of errors.
|
it complete and exempt of errors.
|
||||||
|
|
||||||
Winfried Szukalski
|
Giuseppe Baruffa
|
||||||
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
|
|
||||||
Ben Boeckel
|
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
|
Vincent Nicolas
|
||||||
Glenn Pearson
|
Glenn Pearson
|
||||||
Giuseppe Baruffa
|
Dzonatas Sol
|
||||||
Arnaud Maye
|
Winfried Szukalski
|
||||||
Rex Dieter
|
Vincent Torri
|
||||||
David Burken
|
Yannick Verschueren
|
||||||
Parvatha Elangovan
|
Peter Wimmer
|
||||||
Hans Johnson
|
|
||||||
Luc Hermitte
|
|
||||||
|
|||||||
@@ -123,8 +123,8 @@ static void sycc422_to_rgb(opj_image_t *img)
|
|||||||
{
|
{
|
||||||
int *d0, *d1, *d2, *r, *g, *b;
|
int *d0, *d1, *d2, *r, *g, *b;
|
||||||
const int *y, *cb, *cr;
|
const int *y, *cb, *cr;
|
||||||
int maxw, maxh, max, offset, upb;
|
int maxw, maxh, max, offset, upb;
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
i = (int)img->comps[0].prec;
|
i = (int)img->comps[0].prec;
|
||||||
offset = 1<<(i - 1); upb = (1<<i)-1;
|
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);
|
d2 = b = (int*)malloc(sizeof(int) * (size_t)max);
|
||||||
|
|
||||||
for(i=0; i < maxh; ++i)
|
for(i=0; i < maxh; ++i)
|
||||||
{
|
{
|
||||||
for(j=0; j < maxw; j += 2)
|
for(j=0; (OPJ_UINT32)j < (maxw & ~(OPJ_UINT32)1); j += 2)
|
||||||
{
|
{
|
||||||
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, *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[0].data); img->comps[0].data = d0;
|
||||||
free(img->comps[1].data); img->comps[1].data = d1;
|
free(img->comps[1].data); img->comps[1].data = d1;
|
||||||
free(img->comps[2].data); img->comps[2].data = d2;
|
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);
|
d1 = g = (int*)malloc(sizeof(int) * (size_t)max);
|
||||||
d2 = b = (int*)malloc(sizeof(int) * (size_t)max);
|
d2 = b = (int*)malloc(sizeof(int) * (size_t)max);
|
||||||
|
|
||||||
for(i=0; i < maxh; i += 2)
|
for(i=0; (OPJ_UINT32)i < (maxh & ~(OPJ_UINT32)1); i += 2)
|
||||||
{
|
{
|
||||||
ny = y + maxw;
|
ny = y + maxw;
|
||||||
nr = r + maxw; ng = g + maxw; nb = b + maxw;
|
nr = r + maxw; ng = g + maxw; nb = b + maxw;
|
||||||
|
|
||||||
for(j=0; j < maxw; j += 2)
|
for(j=0; (OPJ_UINT32)j < (maxw & ~(OPJ_UINT32)1); j += 2)
|
||||||
{
|
{
|
||||||
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, *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[0].data); img->comps[0].data = d0;
|
||||||
free(img->comps[1].data); img->comps[1].data = d1;
|
free(img->comps[1].data); img->comps[1].data = d1;
|
||||||
free(img->comps[2].data); img->comps[2].data = d2;
|
free(img->comps[2].data); img->comps[2].data = d2;
|
||||||
|
|||||||
@@ -50,6 +50,13 @@ foreach(exe opj_decompress opj_compress opj_dump)
|
|||||||
EXPORT OpenJPEGTargets
|
EXPORT OpenJPEGTargets
|
||||||
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
|
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()
|
endforeach()
|
||||||
|
|
||||||
if(BUILD_DOC)
|
if(BUILD_DOC)
|
||||||
|
|||||||
@@ -2988,10 +2988,13 @@ static opj_image_t* rawtoimage_common(const char *filename, opj_cparameters_t *p
|
|||||||
}
|
}
|
||||||
w = raw_cp->rawWidth;
|
w = raw_cp->rawWidth;
|
||||||
h = raw_cp->rawHeight;
|
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 */
|
/* initialize image components */
|
||||||
memset(&cmptparm[0], 0, (size_t)numcomps * sizeof(opj_image_cmptparm_t));
|
|
||||||
for(i = 0; i < numcomps; i++) {
|
for(i = 0; i < numcomps; i++) {
|
||||||
cmptparm[i].prec = (OPJ_UINT32)raw_cp->rawBitDepth;
|
cmptparm[i].prec = (OPJ_UINT32)raw_cp->rawBitDepth;
|
||||||
cmptparm[i].bpp = (OPJ_UINT32)raw_cp->rawBitDepth;
|
cmptparm[i].bpp = (OPJ_UINT32)raw_cp->rawBitDepth;
|
||||||
@@ -3018,7 +3021,7 @@ static opj_image_t* rawtoimage_common(const char *filename, opj_cparameters_t *p
|
|||||||
{
|
{
|
||||||
unsigned char value = 0;
|
unsigned char value = 0;
|
||||||
for(compno = 0; compno < numcomps; compno++) {
|
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++) {
|
for (i = 0; i < nloop; i++) {
|
||||||
if (!fread(&value, 1, 1, f)) {
|
if (!fread(&value, 1, 1, f)) {
|
||||||
fprintf(stderr,"Error reading raw file. End of file probably reached.\n");
|
fprintf(stderr,"Error reading raw file. End of file probably reached.\n");
|
||||||
|
|||||||
@@ -1500,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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1572,22 +1580,6 @@ int main(int argc, char **argv) {
|
|||||||
return 1;
|
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 */
|
/* Read directory if necessary */
|
||||||
if(img_fol.set_imgdir==1){
|
if(img_fol.set_imgdir==1){
|
||||||
num_images=get_num_images(img_fol.imgdirpath);
|
num_images=get_num_images(img_fol.imgdirpath);
|
||||||
@@ -1792,8 +1784,7 @@ int main(int argc, char **argv) {
|
|||||||
if( bSuccess && bUseTiles ) {
|
if( bSuccess && bUseTiles ) {
|
||||||
OPJ_BYTE *l_data;
|
OPJ_BYTE *l_data;
|
||||||
OPJ_UINT32 l_data_size = 512*512*3;
|
OPJ_UINT32 l_data_size = 512*512*3;
|
||||||
l_data = (OPJ_BYTE*) malloc( l_data_size * sizeof(OPJ_BYTE));
|
l_data = (OPJ_BYTE*) calloc( 1,l_data_size);
|
||||||
memset(l_data, 0, l_data_size );
|
|
||||||
assert( l_data );
|
assert( l_data );
|
||||||
for (i=0;i<l_nb_tiles;++i) {
|
for (i=0;i<l_nb_tiles;++i) {
|
||||||
if (! opj_write_tile(l_codec,i,l_data,l_data_size,l_stream)) {
|
if (! opj_write_tile(l_codec,i,l_data,l_data_size,l_stream)) {
|
||||||
|
|||||||
@@ -98,3 +98,13 @@ if(OPENJPEG_CPPCHECK)
|
|||||||
COMMAND ${CPPCHECK_EXECUTABLE} -DWIN32 ${f})
|
COMMAND ${CPPCHECK_EXECUTABLE} -DWIN32 ${f})
|
||||||
endforeach()
|
endforeach()
|
||||||
endif()
|
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()
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio);
|
|||||||
OPJ_BOOL opj_bio_byteout(opj_bio_t *bio) {
|
OPJ_BOOL opj_bio_byteout(opj_bio_t *bio) {
|
||||||
bio->buf = (bio->buf << 8) & 0xffff;
|
bio->buf = (bio->buf << 8) & 0xffff;
|
||||||
bio->ct = bio->buf == 0xff00 ? 7 : 8;
|
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;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
*bio->bp++ = (OPJ_BYTE)(bio->buf >> 8);
|
*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) {
|
OPJ_BOOL opj_bio_bytein(opj_bio_t *bio) {
|
||||||
bio->buf = (bio->buf << 8) & 0xffff;
|
bio->buf = (bio->buf << 8) & 0xffff;
|
||||||
bio->ct = bio->buf == 0xff00 ? 7 : 8;
|
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;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
bio->buf |= *bio->bp++;
|
bio->buf |= *bio->bp++;
|
||||||
|
|||||||
@@ -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_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size,OPJ_BOOL l_is_input)
|
||||||
{
|
{
|
||||||
opj_stream_private_t * l_stream = 00;
|
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) {
|
if (! l_stream) {
|
||||||
return 00;
|
return 00;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(l_stream,0,sizeof(opj_stream_private_t));
|
|
||||||
l_stream->m_buffer_size = p_buffer_size;
|
l_stream->m_buffer_size = p_buffer_size;
|
||||||
l_stream->m_stored_data = (OPJ_BYTE *) opj_malloc(p_buffer_size);
|
l_stream->m_stored_data = (OPJ_BYTE *) opj_malloc(p_buffer_size);
|
||||||
if (! l_stream->m_stored_data) {
|
if (! l_stream->m_stored_data) {
|
||||||
|
|||||||
@@ -571,6 +571,7 @@ OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres, DWT1D
|
|||||||
h.mem = (OPJ_INT32*)
|
h.mem = (OPJ_INT32*)
|
||||||
opj_aligned_malloc(opj_dwt_max_resolution(tr, numres) * sizeof(OPJ_INT32));
|
opj_aligned_malloc(opj_dwt_max_resolution(tr, numres) * sizeof(OPJ_INT32));
|
||||||
if (! h.mem){
|
if (! h.mem){
|
||||||
|
/* FIXME event manager error callback */
|
||||||
return OPJ_FALSE;
|
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);
|
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));
|
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;
|
v.wavelet = h.wavelet;
|
||||||
|
|
||||||
while( --numres) {
|
while( --numres) {
|
||||||
|
|||||||
@@ -39,22 +39,19 @@
|
|||||||
opj_procedure_list_t * opj_procedure_list_create()
|
opj_procedure_list_t * opj_procedure_list_create()
|
||||||
{
|
{
|
||||||
/* memory allocation */
|
/* 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)
|
if (! l_validation)
|
||||||
{
|
{
|
||||||
return 00;
|
return 00;
|
||||||
}
|
}
|
||||||
/* initialization */
|
/* initialization */
|
||||||
memset(l_validation,0,sizeof(opj_procedure_list_t));
|
|
||||||
l_validation->m_nb_max_procedures = OPJ_VALIDATION_SIZE;
|
l_validation->m_nb_max_procedures = OPJ_VALIDATION_SIZE;
|
||||||
l_validation->m_procedures = (opj_procedure*)opj_malloc(
|
l_validation->m_procedures = (opj_procedure*)opj_calloc(OPJ_VALIDATION_SIZE, sizeof(opj_procedure));
|
||||||
OPJ_VALIDATION_SIZE * sizeof(opj_procedure));
|
|
||||||
if (! l_validation->m_procedures)
|
if (! l_validation->m_procedures)
|
||||||
{
|
{
|
||||||
opj_free(l_validation);
|
opj_free(l_validation);
|
||||||
return 00;
|
return 00;
|
||||||
}
|
}
|
||||||
memset(l_validation->m_procedures,0,OPJ_VALIDATION_SIZE * sizeof(opj_procedure));
|
|
||||||
return l_validation;
|
return l_validation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -205,21 +205,19 @@ opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_c
|
|||||||
OPJ_UINT32 compno;
|
OPJ_UINT32 compno;
|
||||||
opj_image_t *image = 00;
|
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)
|
if (image)
|
||||||
{
|
{
|
||||||
memset(image,0,sizeof(opj_image_t));
|
|
||||||
|
|
||||||
image->color_space = clrspc;
|
image->color_space = clrspc;
|
||||||
image->numcomps = numcmpts;
|
image->numcomps = numcmpts;
|
||||||
|
|
||||||
/* allocate memory for the per-component information */
|
/* 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) {
|
if (!image->comps) {
|
||||||
opj_image_destroy(image);
|
opj_image_destroy(image);
|
||||||
return 00;
|
return 00;
|
||||||
}
|
}
|
||||||
memset(image->comps,0,image->numcomps * sizeof(opj_image_comp_t));
|
|
||||||
|
|
||||||
/* create the individual image components */
|
/* create the individual image components */
|
||||||
for(compno = 0; compno < numcmpts; compno++) {
|
for(compno = 0; compno < numcmpts; compno++) {
|
||||||
|
|||||||
@@ -1499,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");
|
opj_event_msg(p_manager , EVT_ERROR, "Not enough memory for checking the poc values.\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
memset(packet_array,0,step_l * p_num_layers* sizeof(OPJ_UINT32));
|
|
||||||
|
|
||||||
if (p_nb_pocs == 0) {
|
if (p_nb_pocs == 0) {
|
||||||
opj_free(packet_array);
|
opj_free(packet_array);
|
||||||
@@ -2038,7 +2037,6 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k,
|
|||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(l_image->comps,0,l_image->numcomps * sizeof(opj_image_comp_t));
|
|
||||||
l_img_comp = l_image->comps;
|
l_img_comp = l_image->comps;
|
||||||
|
|
||||||
/* Read the component information */
|
/* Read the component information */
|
||||||
@@ -2167,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");
|
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
memset(l_cp->tcps,0,l_nb_tiles*sizeof(opj_tcp_t));
|
|
||||||
|
|
||||||
#ifdef USE_JPWL
|
#ifdef USE_JPWL
|
||||||
if (l_cp->correct) {
|
if (l_cp->correct) {
|
||||||
@@ -2188,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");
|
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n");
|
||||||
return OPJ_FALSE;
|
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 =
|
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) {
|
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");
|
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n");
|
||||||
return OPJ_FALSE;
|
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_nb_max_mct_records = OPJ_J2K_MCT_DEFAULT_NB_RECORDS;
|
||||||
|
|
||||||
p_j2k->m_specific_param.m_decoder.m_default_tcp->m_mcc_records =
|
p_j2k->m_specific_param.m_decoder.m_default_tcp->m_mcc_records =
|
||||||
(opj_simple_mcc_decorrelation_data_t*)
|
(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) {
|
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");
|
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n");
|
||||||
return OPJ_FALSE;
|
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;
|
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 */
|
/* set up default dc level shift */
|
||||||
@@ -2220,12 +2214,11 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k,
|
|||||||
|
|
||||||
l_current_tile_param = l_cp->tcps;
|
l_current_tile_param = l_cp->tcps;
|
||||||
for (i = 0; i < l_nb_tiles; ++i) {
|
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) {
|
if (l_current_tile_param->tccps == 00) {
|
||||||
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n");
|
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
memset(l_current_tile_param->tccps,0,l_image->numcomps * sizeof(opj_tccp_t));
|
|
||||||
|
|
||||||
++l_current_tile_param;
|
++l_current_tile_param;
|
||||||
}
|
}
|
||||||
@@ -2422,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 */
|
opj_read_bytes(p_header_data,&l_tcp->csty,1); /* Scod */
|
||||||
++p_header_data;
|
++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) */
|
opj_read_bytes(p_header_data,&l_tmp,1); /* SGcod (A) */
|
||||||
++p_header_data;
|
++p_header_data;
|
||||||
l_tcp->prg = (OPJ_PROG_ORDER) l_tmp;
|
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) */
|
opj_read_bytes(p_header_data,&l_tcp->numlayers,2); /* SGcod (B) */
|
||||||
p_header_data+=2;
|
p_header_data+=2;
|
||||||
|
|
||||||
@@ -3551,6 +3554,14 @@ OPJ_BOOL j2k_read_ppm_v3 (
|
|||||||
|
|
||||||
/* First PPM marker */
|
/* First PPM marker */
|
||||||
if (l_Z_ppm == 0) {
|
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 */
|
/* We need now at least the Nppm^0 element */
|
||||||
if (p_header_size < 4) {
|
if (p_header_size < 4) {
|
||||||
opj_event_msg(p_manager, EVT_ERROR, "Error reading PPM marker\n");
|
opj_event_msg(p_manager, EVT_ERROR, "Error reading PPM marker\n");
|
||||||
@@ -3576,13 +3587,12 @@ OPJ_BOOL j2k_read_ppm_v3 (
|
|||||||
l_cp->ppm_len = l_N_ppm;
|
l_cp->ppm_len = l_N_ppm;
|
||||||
l_cp->ppm_data_read = 0;
|
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;
|
l_cp->ppm_buffer = l_cp->ppm_data;
|
||||||
if (l_cp->ppm_data == 00) {
|
if (l_cp->ppm_data == 00) {
|
||||||
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read ppm marker\n");
|
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read ppm marker\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
memset(l_cp->ppm_data,0,l_cp->ppm_len);
|
|
||||||
|
|
||||||
l_cp->ppm_data_current = l_cp->ppm_data;
|
l_cp->ppm_data_current = l_cp->ppm_data;
|
||||||
|
|
||||||
@@ -3649,6 +3659,15 @@ OPJ_BOOL j2k_read_ppm_v3 (
|
|||||||
|
|
||||||
if (p_header_size)
|
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 */
|
opj_read_bytes(p_header_data,&l_N_ppm,4); /* N_ppm^i */
|
||||||
p_header_data+=4;
|
p_header_data+=4;
|
||||||
p_header_size-=4;
|
p_header_size-=4;
|
||||||
@@ -4128,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) {
|
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 =
|
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));
|
(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 {
|
else {
|
||||||
opj_tp_index_t *new_tp_index = (opj_tp_index_t *) opj_realloc(
|
opj_tp_index_t *new_tp_index = (opj_tp_index_t *) opj_realloc(
|
||||||
@@ -4135,7 +4158,7 @@ OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k,
|
|||||||
if (! new_tp_index) {
|
if (! new_tp_index) {
|
||||||
opj_free(p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].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;
|
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;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = new_tp_index;
|
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = new_tp_index;
|
||||||
@@ -4149,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 =
|
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,
|
(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));
|
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 ){
|
if ( l_current_part >= p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps ){
|
||||||
@@ -4161,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);
|
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].tp_index = NULL;
|
||||||
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps = 0;
|
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;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = new_tp_index;
|
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = new_tp_index;
|
||||||
@@ -4316,6 +4344,12 @@ OPJ_BOOL opj_j2k_read_sod (opj_j2k_t *p_j2k,
|
|||||||
|
|
||||||
/* Patch to support new PHR data */
|
/* Patch to support new PHR data */
|
||||||
if (p_j2k->m_specific_param.m_decoder.m_sot_length) {
|
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) {
|
if (! *l_current_data) {
|
||||||
/* LH: oddly enough, in this path, l_tile_len!=0.
|
/* 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,...).
|
* TODO: If this was consistant, we could simplify the code to only use realloc(), as realloc(0,...) default to malloc(0,...).
|
||||||
@@ -5853,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* 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) {
|
if (!l_j2k) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(l_j2k,0,sizeof(opj_j2k_t));
|
|
||||||
|
|
||||||
l_j2k->m_is_decoder = 0;
|
l_j2k->m_is_decoder = 0;
|
||||||
l_j2k->m_cp.m_is_decoder = 0;
|
l_j2k->m_cp.m_is_decoder = 0;
|
||||||
@@ -6105,7 +6138,7 @@ OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_UINT16 rsiz, opj_ev
|
|||||||
return OPJ_TRUE;
|
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_cparameters_t *parameters,
|
||||||
opj_image_t *image,
|
opj_image_t *image,
|
||||||
opj_event_mgr_t * p_manager)
|
opj_event_mgr_t * p_manager)
|
||||||
@@ -6114,7 +6147,12 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
|
|||||||
opj_cp_t *cp = 00;
|
opj_cp_t *cp = 00;
|
||||||
|
|
||||||
if(!p_j2k || !parameters || ! image) {
|
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 */
|
/* keep a link to cp so that we can destroy it later in j2k_destroy_compress */
|
||||||
@@ -6256,6 +6294,10 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
|
|||||||
if (parameters->cp_fixed_alloc && parameters->cp_matrice) {
|
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);
|
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);
|
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);
|
memcpy(cp->m_specific_param.m_enc.m_matrice, parameters->cp_matrice, array_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6269,11 +6311,36 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
|
|||||||
|
|
||||||
/* comment string */
|
/* comment string */
|
||||||
if(parameters->cp_comment) {
|
if(parameters->cp_comment) {
|
||||||
cp->comment = (char*)opj_malloc(strlen(parameters->cp_comment) + 1);
|
cp->comment = (char*)opj_malloc(strlen(parameters->cp_comment) + 1U);
|
||||||
if(cp->comment) {
|
if(!cp->comment) {
|
||||||
strcpy(cp->comment, parameters->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
|
calculate other encoding parameters
|
||||||
@@ -6351,6 +6418,10 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
|
|||||||
/* initialize the mutiple tiles */
|
/* initialize the mutiple tiles */
|
||||||
/* ---------------------------- */
|
/* ---------------------------- */
|
||||||
cp->tcps = (opj_tcp_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_t));
|
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) {
|
if (parameters->numpocs) {
|
||||||
/* initialisation of POC */
|
/* 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);
|
opj_j2k_check_poc_val(parameters->POC,parameters->numpocs, (OPJ_UINT32)parameters->numresolution, image->numcomps, (OPJ_UINT32)parameters->tcp_numlayers, p_manager);
|
||||||
@@ -6408,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));
|
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) {
|
if (parameters->mct_data) {
|
||||||
|
|
||||||
OPJ_UINT32 lMctSize = image->numcomps * image->numcomps * (OPJ_UINT32)sizeof(OPJ_FLOAT32);
|
OPJ_UINT32 lMctSize = image->numcomps * image->numcomps * (OPJ_UINT32)sizeof(OPJ_FLOAT32);
|
||||||
OPJ_FLOAT32 * lTmpBuf = (OPJ_FLOAT32*)opj_malloc(lMctSize);
|
OPJ_FLOAT32 * lTmpBuf = (OPJ_FLOAT32*)opj_malloc(lMctSize);
|
||||||
OPJ_INT32 * l_dc_shift = (OPJ_INT32 *) ((OPJ_BYTE *) parameters->mct_data + 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->mct = 2;
|
||||||
tcp->m_mct_coding_matrix = (OPJ_FLOAT32*)opj_malloc(lMctSize);
|
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(tcp->m_mct_coding_matrix,parameters->mct_data,lMctSize);
|
||||||
memcpy(lTmpBuf,parameters->mct_data,lMctSize);
|
memcpy(lTmpBuf,parameters->mct_data,lMctSize);
|
||||||
|
|
||||||
tcp->m_mct_decoding_matrix = (OPJ_FLOAT32*)opj_malloc(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*)
|
tcp->mct_norms = (OPJ_FLOAT64*)
|
||||||
opj_malloc(image->numcomps * sizeof(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_calculate_norms(tcp->mct_norms,image->numcomps,tcp->m_mct_decoding_matrix);
|
||||||
opj_free(lTmpBuf);
|
opj_free(lTmpBuf);
|
||||||
|
|
||||||
@@ -6434,9 +6535,22 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
|
|||||||
tccp->m_dc_level_shift = l_dc_shift[i];
|
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 {
|
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++) {
|
for (i = 0; i < image->numcomps; i++) {
|
||||||
opj_tccp_t *tccp = &tcp->tccps[i];
|
opj_tccp_t *tccp = &tcp->tccps[i];
|
||||||
opj_image_comp_t * l_comp = &(image->comps[i]);
|
opj_image_comp_t * l_comp = &(image->comps[i]);
|
||||||
@@ -6523,6 +6637,7 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
|
|||||||
opj_free(parameters->mct_data);
|
opj_free(parameters->mct_data);
|
||||||
parameters->mct_data = 00;
|
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)
|
static OPJ_BOOL opj_j2k_add_mhmarker(opj_codestream_index_t *cstr_index, OPJ_UINT32 type, OPJ_OFF_T pos, OPJ_UINT32 len)
|
||||||
@@ -6915,6 +7030,15 @@ OPJ_BOOL opj_j2k_encoding_validation ( opj_j2k_t * p_j2k,
|
|||||||
/* make sure a validation list is present */
|
/* make sure a validation list is present */
|
||||||
l_is_valid &= (p_j2k->m_validation_list != 00);
|
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)) {
|
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");
|
opj_event_msg(p_manager, EVT_ERROR, "Number of resolutions is too high in comparison to the size of tiles\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
@@ -6966,6 +7090,9 @@ OPJ_BOOL opj_j2k_read_header_procedure( opj_j2k_t *p_j2k,
|
|||||||
OPJ_UINT32 l_current_marker;
|
OPJ_UINT32 l_current_marker;
|
||||||
OPJ_UINT32 l_marker_size;
|
OPJ_UINT32 l_marker_size;
|
||||||
const opj_dec_memory_marker_handler_t * l_marker_handler = 00;
|
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 */
|
/* preconditions */
|
||||||
assert(p_stream != 00);
|
assert(p_stream != 00);
|
||||||
@@ -7015,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);
|
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 */
|
/* 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) ) {
|
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");
|
opj_event_msg(p_manager, EVT_ERROR, "Marker is not compliant with its position\n");
|
||||||
@@ -7077,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);
|
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");
|
opj_event_msg(p_manager, EVT_INFO, "Main header has been correctly decoded.\n");
|
||||||
|
|
||||||
/* Position of the last element if the main header */
|
/* Position of the last element if the main header */
|
||||||
@@ -7513,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 */
|
/* 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);
|
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 */
|
/* 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) {
|
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;
|
p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_NEOC;
|
||||||
@@ -7537,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 */
|
/* 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) {
|
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) {
|
if (! new_header_data) {
|
||||||
opj_free(p_j2k->m_specific_param.m_decoder.m_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;
|
p_j2k->m_specific_param.m_decoder.m_header_data = NULL;
|
||||||
@@ -7673,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",
|
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_tile_index = p_j2k->m_current_tile_number;
|
||||||
*p_go_on = OPJ_TRUE;
|
*p_go_on = OPJ_TRUE;
|
||||||
@@ -7758,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;*/
|
p_j2k->m_specific_param.m_decoder.m_state = 0x0100;/*FIXME J2K_DEC_STATE_EOC;*/
|
||||||
}
|
}
|
||||||
else if (l_current_marker != J2K_MS_SOT)
|
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) {
|
if(opj_stream_get_number_byte_left(p_stream) == 0) {
|
||||||
p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_NEOC;
|
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;
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
opj_event_msg(p_manager, EVT_ERROR, "Stream too short, expected SOT\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8192,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* 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) {
|
if (!l_j2k) {
|
||||||
return 00;
|
return 00;
|
||||||
}
|
}
|
||||||
memset(l_j2k,0,sizeof(opj_j2k_t));
|
|
||||||
|
|
||||||
l_j2k->m_is_decoder = 1;
|
l_j2k->m_is_decoder = 1;
|
||||||
l_j2k->m_cp.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) {
|
if (!l_j2k->m_specific_param.m_decoder.m_default_tcp) {
|
||||||
opj_j2k_destroy(l_j2k);
|
opj_j2k_destroy(l_j2k);
|
||||||
return 00;
|
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) {
|
if (! l_j2k->m_specific_param.m_decoder.m_header_data) {
|
||||||
opj_j2k_destroy(l_j2k);
|
opj_j2k_destroy(l_j2k);
|
||||||
return 00;
|
return 00;
|
||||||
@@ -8222,16 +8386,11 @@ opj_j2k_t* opj_j2k_create_decompress(void)
|
|||||||
|
|
||||||
/* codestream index creation */
|
/* codestream index creation */
|
||||||
l_j2k->cstr_index = opj_j2k_create_cstr_index();
|
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){
|
if (!l_j2k->cstr_index){
|
||||||
opj_j2k_destroy(l_j2k);
|
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 */
|
/* validation list creation */
|
||||||
l_j2k->m_validation_list = opj_procedure_list_create();
|
l_j2k->m_validation_list = opj_procedure_list_create();
|
||||||
if (! l_j2k->m_validation_list) {
|
if (! l_j2k->m_validation_list) {
|
||||||
@@ -9646,6 +9805,10 @@ OPJ_BOOL opj_j2k_start_compress(opj_j2k_t *p_j2k,
|
|||||||
assert(p_manager != 00);
|
assert(p_manager != 00);
|
||||||
|
|
||||||
p_j2k->m_private_image = opj_image_create0();
|
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);
|
opj_copy_image_header(p_image, p_j2k->m_private_image);
|
||||||
|
|
||||||
/* TODO_MSD: Find a better way */
|
/* TODO_MSD: Find a better way */
|
||||||
|
|||||||
@@ -594,7 +594,7 @@ void opj_j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters);
|
|||||||
opj_j2k_t* opj_j2k_create_compress(void);
|
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_cparameters_t *parameters,
|
||||||
opj_image_t *image,
|
opj_image_t *image,
|
||||||
opj_event_mgr_t * p_manager);
|
opj_event_mgr_t * p_manager);
|
||||||
|
|||||||
@@ -537,12 +537,11 @@ OPJ_BOOL opj_jp2_read_ihdr( opj_jp2_t *jp2,
|
|||||||
p_image_header_data += 2;
|
p_image_header_data += 2;
|
||||||
|
|
||||||
/* allocate memory for components */
|
/* 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) {
|
if (jp2->comps == 0) {
|
||||||
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle image header (ihdr)\n");
|
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle image header (ihdr)\n");
|
||||||
return OPJ_FALSE;
|
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 */
|
opj_read_bytes(p_image_header_data,&(jp2->bpc),1); /* BPC */
|
||||||
++ p_image_header_data;
|
++ p_image_header_data;
|
||||||
@@ -574,11 +573,10 @@ OPJ_BYTE * opj_jp2_write_ihdr(opj_jp2_t *jp2,
|
|||||||
assert(p_nb_bytes_written != 00);
|
assert(p_nb_bytes_written != 00);
|
||||||
|
|
||||||
/* default image header is 22 bytes wide */
|
/* 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) {
|
if (l_ihdr_data == 00) {
|
||||||
return 00;
|
return 00;
|
||||||
}
|
}
|
||||||
memset(l_ihdr_data,0,22);
|
|
||||||
|
|
||||||
l_current_ihdr_ptr = l_ihdr_data;
|
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(jp2 != 00);
|
||||||
assert(p_nb_bytes_written != 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) {
|
if (l_bpcc_data == 00) {
|
||||||
return 00;
|
return 00;
|
||||||
}
|
}
|
||||||
memset(l_bpcc_data,0,l_bpcc_size);
|
|
||||||
|
|
||||||
l_current_bpcc_ptr = l_bpcc_data;
|
l_current_bpcc_ptr = l_bpcc_data;
|
||||||
|
|
||||||
@@ -709,11 +706,10 @@ OPJ_BYTE * opj_jp2_write_colr( opj_jp2_t *jp2,
|
|||||||
return 00;
|
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) {
|
if (l_colr_data == 00) {
|
||||||
return 00;
|
return 00;
|
||||||
}
|
}
|
||||||
memset(l_colr_data,0,l_colr_size);
|
|
||||||
|
|
||||||
l_current_colr_ptr = l_colr_data;
|
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) {
|
if (color->jp2_cdef) {
|
||||||
opj_jp2_cdef_info_t *info = color->jp2_cdef->info;
|
opj_jp2_cdef_info_t *info = color->jp2_cdef->info;
|
||||||
OPJ_UINT16 n = color->jp2_cdef->n;
|
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++) {
|
for (i = 0; i < n; i++) {
|
||||||
if (info[i].cn >= image->numcomps) {
|
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;
|
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
|
/* 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;
|
old_comps = image->comps;
|
||||||
new_comps = (opj_image_comp_t*)
|
new_comps = (opj_image_comp_t*)
|
||||||
opj_malloc(nr_channels * sizeof(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) {
|
for(i = 0; i < nr_channels; ++i) {
|
||||||
pcol = cmap[i].pcol; cmp = cmap[i].cmp;
|
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: */
|
/* Palette mapping: */
|
||||||
new_comps[i].data = (OPJ_INT32*)
|
new_comps[i].data = (OPJ_INT32*)
|
||||||
opj_malloc(old_comps[cmp].w * old_comps[cmp].h * sizeof(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].prec = channel_size[i];
|
||||||
new_comps[i].sgnd = channel_sign[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))
|
if (bytes_to_read > sizeof(OPJ_UINT32))
|
||||||
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;
|
return OPJ_FALSE;
|
||||||
|
|
||||||
opj_read_bytes(p_pclr_header_data, &l_value , bytes_to_read); /* Cji */
|
opj_read_bytes(p_pclr_header_data, &l_value , bytes_to_read); /* Cji */
|
||||||
@@ -1255,13 +1284,12 @@ OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2,
|
|||||||
OPJ_INT32 icc_len = (OPJ_INT32)p_colr_header_size - 3;
|
OPJ_INT32 icc_len = (OPJ_INT32)p_colr_header_size - 3;
|
||||||
|
|
||||||
jp2->color.icc_profile_len = (OPJ_UINT32)icc_len;
|
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)
|
if (!jp2->color.icc_profile_buf)
|
||||||
{
|
{
|
||||||
jp2->color.icc_profile_len = 0;
|
jp2->color.icc_profile_len = 0;
|
||||||
return OPJ_FALSE;
|
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)
|
for (it_icc_value = 0; it_icc_value < icc_len; ++it_icc_value)
|
||||||
{
|
{
|
||||||
@@ -1274,7 +1302,7 @@ OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2,
|
|||||||
}
|
}
|
||||||
else if (jp2->meth > 2)
|
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.*/
|
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), "
|
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);
|
"so we will ignore the entire Colour Specification box. \n", jp2->meth);
|
||||||
@@ -1448,15 +1476,13 @@ OPJ_BOOL opj_jp2_write_ftyp(opj_jp2_t *jp2,
|
|||||||
assert(jp2 != 00);
|
assert(jp2 != 00);
|
||||||
assert(p_manager != 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) {
|
if (l_ftyp_data == 00) {
|
||||||
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle ftyp data\n");
|
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle ftyp data\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(l_ftyp_data,0,l_ftyp_size);
|
|
||||||
|
|
||||||
l_current_data_ptr = l_ftyp_data;
|
l_current_data_ptr = l_ftyp_data;
|
||||||
|
|
||||||
opj_write_bytes(l_current_data_ptr, l_ftyp_size,4); /* box size */
|
opj_write_bytes(l_current_data_ptr, l_ftyp_size,4); /* box size */
|
||||||
@@ -1567,7 +1593,7 @@ void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters)
|
|||||||
/* JP2 encoder interface */
|
/* 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_cparameters_t *parameters,
|
||||||
opj_image_t *image,
|
opj_image_t *image,
|
||||||
opj_event_mgr_t * p_manager)
|
opj_event_mgr_t * p_manager)
|
||||||
@@ -1577,7 +1603,7 @@ void opj_jp2_setup_encoder( opj_jp2_t *jp2,
|
|||||||
OPJ_UINT32 sign;
|
OPJ_UINT32 sign;
|
||||||
|
|
||||||
if(!jp2 || !parameters || !image)
|
if(!jp2 || !parameters || !image)
|
||||||
return;
|
return OPJ_FALSE;
|
||||||
|
|
||||||
/* setup the J2K codec */
|
/* setup the J2K codec */
|
||||||
/* ------------------- */
|
/* ------------------- */
|
||||||
@@ -1585,10 +1611,12 @@ void opj_jp2_setup_encoder( opj_jp2_t *jp2,
|
|||||||
/* Check if number of components respects standard */
|
/* Check if number of components respects standard */
|
||||||
if (image->numcomps < 1 || image->numcomps > 16384) {
|
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");
|
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 */
|
/* setup the JP2 codec */
|
||||||
/* ------------------- */
|
/* ------------------- */
|
||||||
@@ -1599,22 +1627,23 @@ void opj_jp2_setup_encoder( opj_jp2_t *jp2,
|
|||||||
jp2->minversion = 0; /* MinV */
|
jp2->minversion = 0; /* MinV */
|
||||||
jp2->numcl = 1;
|
jp2->numcl = 1;
|
||||||
jp2->cl = (OPJ_UINT32*) opj_malloc(jp2->numcl * sizeof(OPJ_UINT32));
|
jp2->cl = (OPJ_UINT32*) opj_malloc(jp2->numcl * sizeof(OPJ_UINT32));
|
||||||
if (!jp2->cl){
|
if (!jp2->cl){
|
||||||
jp2->cl = NULL;
|
jp2->cl = NULL;
|
||||||
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n");
|
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n");
|
||||||
return;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
jp2->cl[0] = JP2_JP2; /* CL0 : JP2 */
|
jp2->cl[0] = JP2_JP2; /* CL0 : JP2 */
|
||||||
|
|
||||||
/* Image Header box */
|
/* Image Header box */
|
||||||
|
|
||||||
jp2->numcomps = image->numcomps; /* NC */
|
jp2->numcomps = image->numcomps; /* NC */
|
||||||
jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp2_comps_t));
|
jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp2_comps_t));
|
||||||
if (!jp2->comps) {
|
if (!jp2->comps) {
|
||||||
jp2->comps = NULL;
|
jp2->comps = NULL;
|
||||||
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n");
|
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n");
|
||||||
return;
|
/* Memory of jp2->cl will be freed by opj_jp2_destroy */
|
||||||
}
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
jp2->h = image->y1 - image->y0; /* HEIGHT */
|
jp2->h = image->y1 - image->y0; /* HEIGHT */
|
||||||
jp2->w = image->x1 - image->x0; /* WIDTH */
|
jp2->w = image->x1 - image->x0; /* WIDTH */
|
||||||
@@ -1657,6 +1686,8 @@ void opj_jp2_setup_encoder( opj_jp2_t *jp2,
|
|||||||
jp2->approx = 0; /* APPROX */
|
jp2->approx = 0; /* APPROX */
|
||||||
|
|
||||||
jp2->jpip_on = parameters->jpip_on;
|
jp2->jpip_on = parameters->jpip_on;
|
||||||
|
|
||||||
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
OPJ_BOOL opj_jp2_encode(opj_jp2_t *jp2,
|
OPJ_BOOL opj_jp2_encode(opj_jp2_t *jp2,
|
||||||
@@ -1807,13 +1838,12 @@ OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2,
|
|||||||
assert(jp2 != 00);
|
assert(jp2 != 00);
|
||||||
assert(p_manager != 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) {
|
if (l_current_data == 00) {
|
||||||
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle jpeg2000 file header\n");
|
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle jpeg2000 file header\n");
|
||||||
return OPJ_FALSE;
|
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)) {
|
while (opj_jp2_read_boxhdr(&box,&l_nb_bytes_read,stream,p_manager)) {
|
||||||
/* is it the codestream box ? */
|
/* is it the codestream box ? */
|
||||||
@@ -1835,7 +1865,7 @@ OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2,
|
|||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
/* testcase 1851.pdf.SIGSEGV.ce9.948 */
|
/* 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_event_msg(p_manager, EVT_ERROR, "invalid box size %d (%x)\n", box.length, box.type);
|
||||||
opj_free(l_current_data);
|
opj_free(l_current_data);
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
@@ -1845,6 +1875,12 @@ OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2,
|
|||||||
l_current_data_size = box.length - l_nb_bytes_read;
|
l_current_data_size = box.length - l_nb_bytes_read;
|
||||||
|
|
||||||
if (l_current_handler != 00) {
|
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) {
|
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);
|
OPJ_BYTE* new_current_data = (OPJ_BYTE*)opj_realloc(l_current_data,l_current_data_size);
|
||||||
if (!new_current_data) {
|
if (!new_current_data) {
|
||||||
@@ -2083,12 +2119,11 @@ static OPJ_BOOL opj_jp2_read_ftyp( opj_jp2_t *jp2,
|
|||||||
/* div by 4 */
|
/* div by 4 */
|
||||||
jp2->numcl = l_remaining_bytes >> 2;
|
jp2->numcl = l_remaining_bytes >> 2;
|
||||||
if (jp2->numcl) {
|
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) {
|
if (jp2->cl == 00) {
|
||||||
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory with FTYP Box\n");
|
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory with FTYP Box\n");
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
memset(jp2->cl,0,jp2->numcl * sizeof(OPJ_UINT32));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < jp2->numcl; ++i)
|
for (i = 0; i < jp2->numcl; ++i)
|
||||||
@@ -2157,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_UINT32 l_box_size=0, l_current_data_size = 0;
|
||||||
opj_jp2_box_t box;
|
opj_jp2_box_t box;
|
||||||
const opj_jp2_header_handler_t * l_current_handler;
|
const opj_jp2_header_handler_t * l_current_handler;
|
||||||
|
OPJ_BOOL l_has_ihdr = 0;
|
||||||
|
|
||||||
/* preconditions */
|
/* preconditions */
|
||||||
assert(p_header_data != 00);
|
assert(p_header_data != 00);
|
||||||
@@ -2197,10 +2233,19 @@ static OPJ_BOOL opj_jp2_read_jp2h( opj_jp2_t *jp2,
|
|||||||
jp2->jp2_img_state |= JP2_IMG_STATE_UNKNOWN;
|
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_data += l_current_data_size;
|
||||||
p_header_size -= box.length;
|
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;
|
jp2->jp2_state |= JP2_STATE_HEADER;
|
||||||
|
|
||||||
return OPJ_TRUE;
|
return OPJ_TRUE;
|
||||||
@@ -2269,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");
|
opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box of undefined sizes\n");
|
||||||
return OPJ_FALSE;
|
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;
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2531,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* 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) {
|
if (jp2) {
|
||||||
memset(jp2,0,sizeof(opj_jp2_t));
|
|
||||||
|
|
||||||
/* create the J2K codec */
|
/* create the J2K codec */
|
||||||
if (! p_is_decoder) {
|
if (! p_is_decoder) {
|
||||||
|
|||||||
@@ -278,8 +278,9 @@ OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
|
|||||||
* @param parameters compression parameters
|
* @param parameters compression parameters
|
||||||
* @param image input filled image
|
* @param image input filled image
|
||||||
* @param p_manager FIXME DOC
|
* @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_cparameters_t *parameters,
|
||||||
opj_image_t *image,
|
opj_image_t *image,
|
||||||
opj_event_mgr_t * p_manager);
|
opj_event_mgr_t * p_manager);
|
||||||
|
|||||||
@@ -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* opj_mqc_create(void) {
|
||||||
opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t));
|
opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t));
|
||||||
#ifdef MQC_PERF_OPT
|
#ifdef MQC_PERF_OPT
|
||||||
mqc->buffer = NULL;
|
if (mqc) {
|
||||||
|
mqc->buffer = NULL;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
return mqc;
|
return mqc;
|
||||||
}
|
}
|
||||||
@@ -370,7 +372,9 @@ opj_mqc_t* opj_mqc_create(void) {
|
|||||||
void opj_mqc_destroy(opj_mqc_t *mqc) {
|
void opj_mqc_destroy(opj_mqc_t *mqc) {
|
||||||
if(mqc) {
|
if(mqc) {
|
||||||
#ifdef MQC_PERF_OPT
|
#ifdef MQC_PERF_OPT
|
||||||
opj_free(mqc->buffer);
|
if (mqc->buffer) {
|
||||||
|
opj_free(mqc->buffer);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
opj_free(mqc);
|
opj_free(mqc);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ static OPJ_BOOL opj_seek_from_file (OPJ_OFF_T p_nb_bytes, FILE * p_user_data)
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#ifndef OPJ_STATIC
|
#ifndef OPJ_STATIC
|
||||||
BOOL APIENTRY
|
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(lpReserved);
|
||||||
OPJ_ARG_NOT_USED(hModule);
|
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){
|
if (!l_codec){
|
||||||
return 00;
|
return 00;
|
||||||
}
|
}
|
||||||
memset(l_codec, 0, sizeof(opj_codec_private_t));
|
|
||||||
|
|
||||||
l_codec->is_decompressor = 1;
|
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) {
|
if (!l_codec) {
|
||||||
return 00;
|
return 00;
|
||||||
}
|
}
|
||||||
memset(l_codec, 0, sizeof(opj_codec_private_t));
|
|
||||||
|
|
||||||
l_codec->is_decompressor = 0;
|
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_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 *,
|
opj_cparameters_t *,
|
||||||
struct opj_image *,
|
struct opj_image *,
|
||||||
struct opj_event_mgr * )) opj_j2k_setup_encoder;
|
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_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 *,
|
opj_cparameters_t *,
|
||||||
struct opj_image *,
|
struct opj_image *,
|
||||||
struct opj_event_mgr * )) opj_jp2_setup_encoder;
|
struct opj_event_mgr * )) opj_jp2_setup_encoder;
|
||||||
|
|||||||
@@ -142,10 +142,10 @@ typedef struct opj_codec_private
|
|||||||
|
|
||||||
void (* opj_destroy) (void * p_codec);
|
void (* opj_destroy) (void * p_codec);
|
||||||
|
|
||||||
void (* opj_setup_encoder) ( void * p_codec,
|
OPJ_BOOL (* opj_setup_encoder) ( void * p_codec,
|
||||||
opj_cparameters_t * p_param,
|
opj_cparameters_t * p_param,
|
||||||
struct opj_image * p_image,
|
struct opj_image * p_image,
|
||||||
struct opj_event_mgr * p_manager);
|
struct opj_event_mgr * p_manager);
|
||||||
} m_compression;
|
} m_compression;
|
||||||
} m_codec_data;
|
} m_codec_data;
|
||||||
/** FIXME DOC*/
|
/** FIXME DOC*/
|
||||||
|
|||||||
@@ -815,7 +815,6 @@ opj_pi_iterator_t * opj_pi_create( const opj_image_t *image,
|
|||||||
if (!l_pi) {
|
if (!l_pi) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memset(l_pi,0,l_poc_bound * sizeof(opj_pi_iterator_t));
|
|
||||||
|
|
||||||
l_current_pi = l_pi;
|
l_current_pi = l_pi;
|
||||||
for (pino = 0; pino < l_poc_bound ; ++pino) {
|
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;
|
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) {
|
for (compno = 0; compno < image->numcomps; ++compno) {
|
||||||
opj_pi_comp_t *comp = &l_current_pi->comps[compno];
|
opj_pi_comp_t *comp = &l_current_pi->comps[compno];
|
||||||
|
|
||||||
tccp = &tcp->tccps[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) {
|
if (!comp->resolutions) {
|
||||||
opj_pi_destroy(l_pi, l_poc_bound);
|
opj_pi_destroy(l_pi, l_poc_bound);
|
||||||
return 00;
|
return 00;
|
||||||
}
|
}
|
||||||
|
|
||||||
comp->numresolutions = tccp->numresolutions;
|
comp->numresolutions = tccp->numresolutions;
|
||||||
memset(comp->resolutions,0,tccp->numresolutions * sizeof(opj_pi_resolution_t));
|
|
||||||
}
|
}
|
||||||
++l_current_pi;
|
++l_current_pi;
|
||||||
}
|
}
|
||||||
@@ -1108,7 +1105,8 @@ OPJ_BOOL opj_pi_check_next_level( OPJ_INT32 pos,
|
|||||||
break;
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
switch(tcp->prg){
|
switch(tcp->prg){
|
||||||
case OPJ_LRCP||OPJ_RLCP:
|
case OPJ_LRCP: /* fall through */
|
||||||
|
case OPJ_RLCP:
|
||||||
if(tcp->prc_t == tcp->prcE){
|
if(tcp->prc_t == tcp->prcE){
|
||||||
if(opj_pi_check_next_level(i-1,cp,tileno,pino,prog)){
|
if(opj_pi_check_next_level(i-1,cp,tileno,pino,prog)){
|
||||||
return OPJ_TRUE;
|
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);
|
opj_pi_destroy(l_pi, l_bound);
|
||||||
return 00;
|
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 */
|
/* special treatment for the first packet iterator */
|
||||||
l_current_comp = l_current_pi->comps;
|
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);
|
opj_pi_destroy(l_pi, l_bound);
|
||||||
return 00;
|
return 00;
|
||||||
}
|
}
|
||||||
memset(l_current_pi->include,0,l_tcp->numlayers * l_step_l* sizeof(OPJ_INT16));
|
|
||||||
|
|
||||||
/* special treatment for the first packet iterator*/
|
/* special treatment for the first packet iterator*/
|
||||||
l_current_comp = l_current_pi->comps;
|
l_current_comp = l_current_pi->comps;
|
||||||
|
|||||||
@@ -1170,6 +1170,7 @@ OPJ_BOOL opj_t1_allocate_buffers(
|
|||||||
opj_aligned_free(t1->data);
|
opj_aligned_free(t1->data);
|
||||||
t1->data = (OPJ_INT32*) opj_aligned_malloc(datasize * sizeof(OPJ_INT32));
|
t1->data = (OPJ_INT32*) opj_aligned_malloc(datasize * sizeof(OPJ_INT32));
|
||||||
if(!t1->data){
|
if(!t1->data){
|
||||||
|
/* FIXME event manager error callback */
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
t1->datasize=datasize;
|
t1->datasize=datasize;
|
||||||
@@ -1183,6 +1184,7 @@ OPJ_BOOL opj_t1_allocate_buffers(
|
|||||||
opj_aligned_free(t1->flags);
|
opj_aligned_free(t1->flags);
|
||||||
t1->flags = (opj_flag_t*) opj_aligned_malloc(flagssize * sizeof(opj_flag_t));
|
t1->flags = (opj_flag_t*) opj_aligned_malloc(flagssize * sizeof(opj_flag_t));
|
||||||
if(!t1->flags){
|
if(!t1->flags){
|
||||||
|
/* FIXME event manager error callback */
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
t1->flagssize=flagssize;
|
t1->flagssize=flagssize;
|
||||||
@@ -1207,11 +1209,10 @@ opj_t1_t* opj_t1_create()
|
|||||||
{
|
{
|
||||||
opj_t1_t *l_t1 = 00;
|
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) {
|
if (!l_t1) {
|
||||||
return 00;
|
return 00;
|
||||||
}
|
}
|
||||||
memset(l_t1,0,sizeof(opj_t1_t));
|
|
||||||
|
|
||||||
/* create MQC and RAW handles */
|
/* create MQC and RAW handles */
|
||||||
l_t1->mqc = opj_mqc_create();
|
l_t1->mqc = opj_mqc_create();
|
||||||
|
|||||||
@@ -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) */
|
/* 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);
|
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)) {
|
while (opj_pi_next(l_current_pi)) {
|
||||||
if (l_current_pi->layno < p_maxlayers) {
|
if (l_current_pi->layno < p_maxlayers) {
|
||||||
l_nb_bytes = 0;
|
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);
|
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];
|
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)) {
|
while (opj_pi_next(l_current_pi)) {
|
||||||
if (l_current_pi->layno < p_maxlayers) {
|
if (l_current_pi->layno < p_maxlayers) {
|
||||||
l_nb_bytes=0;
|
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));
|
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)) {
|
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",
|
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 );
|
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)
|
opj_t2_t* opj_t2_create(opj_image_t *p_image, opj_cp_t *p_cp)
|
||||||
{
|
{
|
||||||
/* create the t2 structure */
|
/* 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) {
|
if (!l_t2) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memset(l_t2,0,sizeof(opj_t2_t));
|
|
||||||
|
|
||||||
l_t2->image = p_image;
|
l_t2->image = p_image;
|
||||||
l_t2->cp = p_cp;
|
l_t2->cp = p_cp;
|
||||||
@@ -599,6 +612,10 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bio = opj_bio_create();
|
bio = opj_bio_create();
|
||||||
|
if (!bio) {
|
||||||
|
/* FIXME event manager error callback */
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
opj_bio_init_enc(bio, c, length);
|
opj_bio_init_enc(bio, c, length);
|
||||||
opj_bio_write(bio, 1, 1); /* Empty header bit */
|
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_tcp->csty & J2K_CP_CSTY_SOP) {
|
||||||
if (p_max_length < 6) {
|
if (p_max_length < 6) {
|
||||||
/* TODO opj_event_msg(p_t2->cinfo->event_mgr, EVT_WARNING, "Not enough space for expected SOP marker\n"); */
|
/* 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)) {
|
} 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"); */
|
/* TODO opj_event_msg(p_t2->cinfo->event_mgr, EVT_WARNING, "Expected SOP marker\n"); */
|
||||||
printf("Expected SOP marker\n");
|
fprintf(stderr, "Warning: expected SOP marker\n");
|
||||||
fprintf(stderr, "Error : expected SOP marker\n");
|
|
||||||
} else {
|
} else {
|
||||||
l_current_data += 6;
|
l_current_data += 6;
|
||||||
}
|
}
|
||||||
@@ -917,7 +933,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
|
|||||||
|
|
||||||
/* EPH markers */
|
/* EPH markers */
|
||||||
if (p_tcp->csty & J2K_CP_CSTY_EPH) {
|
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");
|
fprintf(stderr, "Not enough space for expected EPH marker\n");
|
||||||
} else if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) {
|
} else if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) {
|
||||||
fprintf(stderr, "Error : expected EPH marker\n");
|
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 */
|
/* EPH markers */
|
||||||
if (p_tcp->csty & J2K_CP_CSTY_EPH) {
|
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");
|
fprintf(stderr, "Not enough space for expected EPH marker\n");
|
||||||
} else if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) {
|
} 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"); */
|
/* 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 {
|
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",
|
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);
|
l_seg->newlen, p_max_length, cblkno, p_pi->precno, bandno, p_pi->resno, p_pi->compno);
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
@@ -1154,11 +1171,18 @@ OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2,
|
|||||||
};
|
};
|
||||||
|
|
||||||
#endif /* USE_JPWL */
|
#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 */
|
/* Check if the cblk->data have allocated enough memory */
|
||||||
if ((l_cblk->data_current_size + l_seg->newlen) > l_cblk->data_max_size) {
|
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);
|
OPJ_BYTE* new_cblk_data = (OPJ_BYTE*) opj_realloc(l_cblk->data, l_cblk->data_current_size + l_seg->newlen);
|
||||||
if(! new_cblk_data) {
|
if(! new_cblk_data) {
|
||||||
opj_free(l_cblk->data);
|
opj_free(l_cblk->data);
|
||||||
|
l_cblk->data = NULL;
|
||||||
l_cblk->data_max_size = 0;
|
l_cblk->data_max_size = 0;
|
||||||
/* opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to realloc code block cata!\n"); */
|
/* opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to realloc code block cata!\n"); */
|
||||||
return OPJ_FALSE;
|
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);
|
*(p_data_read) = (OPJ_UINT32)(l_current_data - p_src_data);
|
||||||
|
|
||||||
|
|
||||||
return OPJ_TRUE;
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1254,7 +1279,8 @@ OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2,
|
|||||||
}
|
}
|
||||||
|
|
||||||
do {
|
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",
|
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);
|
l_seg->newlen, p_max_length, cblkno, p_pi->precno, bandno, p_pi->resno, p_pi->compno);
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
|
|||||||
@@ -175,20 +175,18 @@ opj_tcd_t* opj_tcd_create(OPJ_BOOL p_is_decoder)
|
|||||||
opj_tcd_t *l_tcd = 00;
|
opj_tcd_t *l_tcd = 00;
|
||||||
|
|
||||||
/* create the tcd structure */
|
/* 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) {
|
if (!l_tcd) {
|
||||||
return 00;
|
return 00;
|
||||||
}
|
}
|
||||||
memset(l_tcd,0,sizeof(opj_tcd_t));
|
|
||||||
|
|
||||||
l_tcd->m_is_decoder = p_is_decoder ? 1 : 0;
|
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) {
|
if (!l_tcd->tcd_image) {
|
||||||
opj_free(l_tcd);
|
opj_free(l_tcd);
|
||||||
return 00;
|
return 00;
|
||||||
}
|
}
|
||||||
memset(l_tcd->tcd_image,0,sizeof(opj_tcd_image_t));
|
|
||||||
|
|
||||||
return l_tcd;
|
return l_tcd;
|
||||||
}
|
}
|
||||||
@@ -467,6 +465,10 @@ OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd,
|
|||||||
tile_info->numpix = tcd_tile->numpix;
|
tile_info->numpix = tcd_tile->numpix;
|
||||||
tile_info->distotile = tcd_tile->distotile;
|
tile_info->distotile = tcd_tile->distotile;
|
||||||
tile_info->thresh = (OPJ_FLOAT64 *) opj_malloc(tcd_tcp->numlayers * sizeof(OPJ_FLOAT64));
|
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++) {
|
for (layno = 0; layno < tcd_tcp->numlayers; layno++) {
|
||||||
@@ -575,23 +577,18 @@ OPJ_BOOL opj_tcd_init( opj_tcd_t *p_tcd,
|
|||||||
opj_image_t * p_image,
|
opj_image_t * p_image,
|
||||||
opj_cp_t * p_cp )
|
opj_cp_t * p_cp )
|
||||||
{
|
{
|
||||||
OPJ_UINT32 l_tile_comp_size;
|
|
||||||
|
|
||||||
p_tcd->image = p_image;
|
p_tcd->image = p_image;
|
||||||
p_tcd->cp = p_cp;
|
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) {
|
if (! p_tcd->tcd_image->tiles) {
|
||||||
return OPJ_FALSE;
|
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_calloc(p_image->numcomps,sizeof(opj_tcd_tilecomp_t));
|
||||||
p_tcd->tcd_image->tiles->comps = (opj_tcd_tilecomp_t *) opj_malloc(l_tile_comp_size);
|
|
||||||
if (! p_tcd->tcd_image->tiles->comps ) {
|
if (! p_tcd->tcd_image->tiles->comps ) {
|
||||||
return OPJ_FALSE;
|
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->tcd_image->tiles->numcomps = p_image->numcomps;
|
||||||
p_tcd->tp_pos = p_cp->m_specific_param.m_enc.m_tp_pos;
|
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; */ \
|
/*tile->numcomps = image->numcomps; */ \
|
||||||
for(compno = 0; compno < l_tile->numcomps; ++compno) { \
|
for(compno = 0; compno < l_tile->numcomps; ++compno) { \
|
||||||
/*fprintf(stderr, "compno = %d/%d\n", compno, l_tile->numcomps);*/ \
|
/*fprintf(stderr, "compno = %d/%d\n", compno, l_tile->numcomps);*/ \
|
||||||
\
|
l_image_comp->resno_decoded = 0; \
|
||||||
/* border of each l_tile component (global) */ \
|
/* border of each l_tile component (global) */ \
|
||||||
l_tilec->x0 = opj_int_ceildiv(l_tile->x0, (OPJ_INT32)l_image_comp->dx); \
|
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); \
|
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 cblkxend = cblkxstart + (1 << cblkwidthexpn); \
|
||||||
OPJ_INT32 cblkyend = cblkystart + (1 << cblkheightexpn); \
|
OPJ_INT32 cblkyend = cblkystart + (1 << cblkheightexpn); \
|
||||||
\
|
\
|
||||||
|
if (! FUNCTION_ELEMENT(l_code_block)) { \
|
||||||
|
return OPJ_FALSE; \
|
||||||
|
} \
|
||||||
/* code-block size (global) */ \
|
/* code-block size (global) */ \
|
||||||
l_code_block->x0 = opj_int_max(cblkxstart, l_current_precinct->x0); \
|
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->y0 = opj_int_max(cblkystart, l_current_precinct->y0); \
|
||||||
l_code_block->x1 = opj_int_min(cblkxend, l_current_precinct->x1); \
|
l_code_block->x1 = opj_int_min(cblkxend, l_current_precinct->x1); \
|
||||||
l_code_block->y1 = opj_int_min(cblkyend, l_current_precinct->y1); \
|
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_code_block; \
|
||||||
} \
|
} \
|
||||||
++l_current_precinct; \
|
++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;
|
p_code_block->data+=1;
|
||||||
|
|
||||||
/* no memset since data */
|
/* 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) {
|
if (! p_code_block->layers) {
|
||||||
return OPJ_FALSE;
|
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) {
|
if (! p_code_block->passes) {
|
||||||
return OPJ_FALSE;
|
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;
|
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_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) {
|
if (! p_code_block->data) {
|
||||||
|
|
||||||
p_code_block->data = (OPJ_BYTE*) opj_malloc(OPJ_J2K_DEFAULT_CBLK_DATA_SIZE);
|
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;
|
p_code_block->data_max_size = OPJ_J2K_DEFAULT_CBLK_DATA_SIZE;
|
||||||
/*fprintf(stderr, "Allocate 8192 elements of code_block->data\n");*/
|
/*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_calloc(OPJ_J2K_DEFAULT_NB_SEGS,sizeof(opj_tcd_seg_t));
|
||||||
p_code_block->segs = (opj_tcd_seg_t *) opj_malloc(l_seg_size);
|
|
||||||
if (! p_code_block->segs) {
|
if (! p_code_block->segs) {
|
||||||
return OPJ_FALSE;
|
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));*/
|
/*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;
|
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);*/
|
/*fprintf(stderr, "m_current_max_segs of code_block->data = %d\n", p_code_block->m_current_max_segs);*/
|
||||||
}
|
} else {
|
||||||
/* TODO */
|
/* sanitize */
|
||||||
/*p_code_block->numsegs = 0; */
|
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;
|
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].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));
|
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 */
|
/* << INDEX */
|
||||||
|
|
||||||
|
|||||||
@@ -57,12 +57,11 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv) {
|
|||||||
OPJ_UINT32 numlvls;
|
OPJ_UINT32 numlvls;
|
||||||
OPJ_UINT32 n;
|
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) {
|
if(!tree) {
|
||||||
fprintf(stderr, "ERROR in tgt_create while allocating tree\n");
|
fprintf(stderr, "ERROR in tgt_create while allocating tree\n");
|
||||||
return 00;
|
return 00;
|
||||||
}
|
}
|
||||||
memset(tree,0,sizeof(opj_tgt_tree_t));
|
|
||||||
|
|
||||||
tree->numleafsh = numleafsh;
|
tree->numleafsh = numleafsh;
|
||||||
tree->numleafsv = numleafsv;
|
tree->numleafsv = numleafsv;
|
||||||
@@ -92,7 +91,6 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv) {
|
|||||||
opj_free(tree);
|
opj_free(tree);
|
||||||
return 00;
|
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);
|
tree->nodes_size = tree->numnodes * (OPJ_UINT32)sizeof(opj_tgt_node_t);
|
||||||
|
|
||||||
node = tree->nodes;
|
node = tree->nodes;
|
||||||
|
|||||||
@@ -57,6 +57,11 @@ set(BLACKLIST_JPEG2000
|
|||||||
gdal_fuzzer_unchecked_numresolutions.jp2
|
gdal_fuzzer_unchecked_numresolutions.jp2
|
||||||
mem-b2ace68c-1381.jp2
|
mem-b2ace68c-1381.jp2
|
||||||
1851.pdf.SIGSEGV.ce9.948.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
|
file(GLOB_RECURSE OPJ_DATA_NR_LIST
|
||||||
|
|||||||
@@ -41,22 +41,12 @@ endif()
|
|||||||
file(READ ${REFFILE} variable)
|
file(READ ${REFFILE} variable)
|
||||||
|
|
||||||
foreach(pgxfullpath ${globfiles})
|
foreach(pgxfullpath ${globfiles})
|
||||||
|
file(MD5 ${pgxfullpath} output)
|
||||||
get_filename_component(pgxfile ${pgxfullpath} NAME)
|
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}")
|
string(REGEX MATCH "[0-9a-f]+ ${pgxfile}" output_var "${variable}")
|
||||||
|
|
||||||
|
set(output "${output} ${pgxfile}")
|
||||||
|
|
||||||
if("${output_var}" STREQUAL "${output}")
|
if("${output_var}" STREQUAL "${output}")
|
||||||
message(STATUS "equal: [${output_var}] vs [${output}]")
|
message(STATUS "equal: [${output_var}] vs [${output}]")
|
||||||
|
|||||||
@@ -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.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.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
|
#!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
|
# decode with specific area
|
||||||
# prec=12; nb_c=1
|
# prec=12; nb_c=1
|
||||||
|
|||||||
@@ -37,6 +37,11 @@
|
|||||||
* only work on linux since I need memmem function
|
* 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
|
#define _GNU_SOURCE
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -98,7 +103,17 @@ int main(int argc, char *argv[])
|
|||||||
assert( r );
|
assert( r );
|
||||||
/*fprintf( stderr, "DEBUG: %s", r );*/
|
/*fprintf( stderr, "DEBUG: %s", r );*/
|
||||||
s = sscanf(r, "JPXDecode]/Length %d/Width %*d/BitsPerComponent %*d/Height %*d", &len);
|
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;
|
FILE *jp2;
|
||||||
int j;
|
int j;
|
||||||
|
|||||||
Reference in New Issue
Block a user