added a validation procedure before launching actual decoding, fixed testempty tests
This commit is contained in:
parent
c91e2099b1
commit
d3c0915992
|
@ -44,6 +44,8 @@ The functions in INT.H have for goal to realize operations on integers.
|
|||
/*@{*/
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#else
|
||||
|
@ -102,8 +104,10 @@ Divide an integer and round upwards
|
|||
@return Returns a divided by b
|
||||
*/
|
||||
static INLINE int int_ceildiv(int a, int b) {
|
||||
return (a + b - 1) / b;
|
||||
assert(b);
|
||||
return (a + b - 1) / b;
|
||||
}
|
||||
|
||||
/**
|
||||
Divide an integer by a power of 2 and round upwards
|
||||
@return Returns a divided by 2^b
|
||||
|
|
|
@ -247,6 +247,12 @@ Add tile header marker information
|
|||
@param len length of marker segment
|
||||
*/
|
||||
static void j2k_add_tlmarker( int tileno, opj_codestream_info_t *cstr_info, unsigned short int type, int pos, int len);
|
||||
/**
|
||||
Validate encoding parameters and image before actual encoding
|
||||
@param j2k J2K handle
|
||||
@param image IMAGE handle
|
||||
*/
|
||||
static opj_bool j2k_validate_encode( opj_j2k_t *j2k, opj_image_t *image);
|
||||
|
||||
/*@}*/
|
||||
|
||||
|
@ -2450,6 +2456,9 @@ opj_bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_code
|
|||
|
||||
cp = j2k->cp;
|
||||
|
||||
/* Parameters validation */
|
||||
if (!j2k_validate_encode(j2k, image)) return OPJ_FALSE;
|
||||
|
||||
/* INDEX >> */
|
||||
j2k->cstr_info = cstr_info;
|
||||
if (cstr_info) {
|
||||
|
@ -2698,3 +2707,21 @@ static void j2k_add_tlmarker( int tileno, opj_codestream_info_t *cstr_info, unsi
|
|||
marker->len = len;
|
||||
cstr_info->tile[tileno].marknum++;
|
||||
}
|
||||
|
||||
static opj_bool j2k_validate_encode(opj_j2k_t *j2k, opj_image_t *image) {
|
||||
|
||||
int compno;
|
||||
opj_bool is_valid = OPJ_TRUE;
|
||||
|
||||
/* preconditions */
|
||||
assert(j2k != 00);
|
||||
assert(image != 00);
|
||||
|
||||
/* PARAMETERS checking */
|
||||
for (compno=0; compno < image->numcomps; compno++) {
|
||||
is_valid &= (image->comps[compno].dx > 1 && j2k->image->comps[compno].dx < 255);
|
||||
is_valid &= (image->comps[compno].dy > 1 && j2k->image->comps[compno].dy < 255);
|
||||
}
|
||||
|
||||
return is_valid;
|
||||
}
|
||||
|
|
|
@ -111,6 +111,15 @@ int main(int argc, char *argv[])
|
|||
cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0);
|
||||
assert( cio );
|
||||
bSuccess = opj_encode(cinfo, cio, image, NULL);
|
||||
|
||||
if( !bSuccess )
|
||||
{
|
||||
opj_cio_close(cio);
|
||||
opj_destroy_compress(cinfo);
|
||||
opj_image_destroy(image);
|
||||
return 0;
|
||||
}
|
||||
|
||||
assert( bSuccess );
|
||||
|
||||
codestream_length = (size_t)cio_tell(cio);
|
||||
|
|
|
@ -115,6 +115,15 @@ int main(int argc, char *argv[])
|
|||
cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0);
|
||||
assert( cio );
|
||||
bSuccess = opj_encode(cinfo, cio, image, NULL);
|
||||
|
||||
if( !bSuccess )
|
||||
{
|
||||
opj_cio_close(cio);
|
||||
opj_destroy_compress(cinfo);
|
||||
opj_image_destroy(image);
|
||||
return 0;
|
||||
}
|
||||
|
||||
assert( bSuccess );
|
||||
|
||||
codestream_length = (size_t)cio_tell(cio);
|
||||
|
|
Loading…
Reference in New Issue