Initial commit of source code using HEAD at commit 940100c28a
and patched with issue356-r2997.patch. A number of the hunks failed and had to be manually merged in. NOTE : This commit compiles but has not been fully tested.
This commit is contained in:
parent
940100c28a
commit
e7b5723810
|
@ -88,6 +88,94 @@ typedef struct img_folder{
|
|||
char set_out_format;
|
||||
}img_fol_t;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Custom allocation functions */
|
||||
//#define OPJ_USE_MEMORY_MANAGER
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
static void* opj_custom_malloc(OPJ_SIZE_T size, void *client_data)
|
||||
{
|
||||
OPJ_ARG_NOT_USED(client_data);
|
||||
|
||||
if ((size + 32U) < size) {
|
||||
return NULL;
|
||||
}
|
||||
size += 32U;
|
||||
|
||||
return (void*)(((OPJ_UINT8*)malloc(size)) + 32);
|
||||
}
|
||||
static void* opj_custom_calloc(OPJ_SIZE_T num, OPJ_SIZE_T size, void *client_data)
|
||||
{
|
||||
OPJ_ARG_NOT_USED(client_data);
|
||||
|
||||
if ((size + 32U) < size) {
|
||||
return NULL;
|
||||
}
|
||||
size += 32U;
|
||||
|
||||
return (void*)(((OPJ_UINT8*)calloc(num, size)) + 32);
|
||||
}
|
||||
static void* opj_custom_realloc(void* ptr, OPJ_SIZE_T size, void *client_data)
|
||||
{
|
||||
OPJ_ARG_NOT_USED(client_data);
|
||||
|
||||
if ((size + 32U) < size) {
|
||||
return NULL;
|
||||
}
|
||||
size += 32U;
|
||||
|
||||
if (ptr != NULL) {
|
||||
ptr = ((OPJ_UINT8*)ptr) - 32;
|
||||
}
|
||||
|
||||
return (void*)(((OPJ_UINT8*)realloc(ptr, size)) + 32);
|
||||
}
|
||||
static void opj_custom_free(void* ptr, void *client_data)
|
||||
{
|
||||
OPJ_ARG_NOT_USED(client_data);
|
||||
if (ptr != NULL) {
|
||||
free(((OPJ_UINT8*)ptr) - 32);
|
||||
}
|
||||
}
|
||||
static void* opj_custom_aligned_malloc(OPJ_SIZE_T size, OPJ_SIZE_T alignment, void *client_data)
|
||||
{
|
||||
void** l_result = NULL;
|
||||
void** l_original = NULL;
|
||||
|
||||
OPJ_ARG_NOT_USED(client_data);
|
||||
|
||||
if ((alignment == 0) || (alignment & (alignment - 1))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((size + alignment) < size) {
|
||||
return NULL;
|
||||
}
|
||||
size += alignment;
|
||||
if ((size + 32U * sizeof(void*)) < size) {
|
||||
return NULL;
|
||||
}
|
||||
size += 32U * sizeof(void*);
|
||||
|
||||
l_original = (void**)malloc(size);
|
||||
|
||||
l_result = l_original + 30U;
|
||||
|
||||
if (alignment > sizeof(void*)) {
|
||||
l_result = (void**)(((OPJ_SIZE_T)l_result + (alignment - 1)) & -alignment );
|
||||
}
|
||||
l_result[-1] = l_original;
|
||||
|
||||
return (void*)l_result;
|
||||
}
|
||||
static void opj_custom_aligned_free(void* ptr, void *client_data)
|
||||
{
|
||||
OPJ_ARG_NOT_USED(client_data);
|
||||
if (ptr != NULL) {
|
||||
free(((void**)ptr)[-1]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void encode_help_display(void) {
|
||||
fprintf(stdout,"\nThis is the opj_compress utility from the OpenJPEG project.\n"
|
||||
"It compresses various image formats with the JPEG 2000 algorithm.\n"
|
||||
|
@ -1569,7 +1657,9 @@ OPJ_FLOAT64 opj_clock(void) {
|
|||
*/
|
||||
/* -------------------------------------------------------------------------- */
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_t l_manager = NULL;
|
||||
#endif
|
||||
opj_cparameters_t parameters; /* compression parameters */
|
||||
|
||||
opj_stream_t *l_stream = 00;
|
||||
|
@ -1634,6 +1724,13 @@ int main(int argc, char **argv) {
|
|||
}else{
|
||||
num_images=1;
|
||||
}
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
l_manager = opj_manager_create(NULL, opj_custom_malloc, opj_custom_calloc, opj_custom_realloc, opj_custom_free, opj_custom_aligned_malloc, opj_custom_aligned_free);
|
||||
if (!l_manager){
|
||||
fprintf(stderr, "ERROR -> failed to create memory manager\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
#endif
|
||||
/*Encoding image one by one*/
|
||||
for(imageno=0;imageno<num_images;imageno++) {
|
||||
image = NULL;
|
||||
|
@ -1675,6 +1772,9 @@ int main(int argc, char **argv) {
|
|||
image = pgxtoimage(parameters.infile, ¶meters);
|
||||
if (!image) {
|
||||
fprintf(stderr, "Unable to load pgx file\n");
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_destroy(l_manager);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
@ -1683,6 +1783,9 @@ int main(int argc, char **argv) {
|
|||
image = pnmtoimage(parameters.infile, ¶meters);
|
||||
if (!image) {
|
||||
fprintf(stderr, "Unable to load pnm file\n");
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_destroy(l_manager);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
@ -1691,6 +1794,9 @@ int main(int argc, char **argv) {
|
|||
image = bmptoimage(parameters.infile, ¶meters);
|
||||
if (!image) {
|
||||
fprintf(stderr, "Unable to load bmp file\n");
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_destroy(l_manager);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
@ -1700,6 +1806,9 @@ int main(int argc, char **argv) {
|
|||
image = tiftoimage(parameters.infile, ¶meters);
|
||||
if (!image) {
|
||||
fprintf(stderr, "Unable to load tiff file\n");
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_destroy(l_manager);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
@ -1709,6 +1818,9 @@ int main(int argc, char **argv) {
|
|||
image = rawtoimage(parameters.infile, ¶meters, &raw_cp);
|
||||
if (!image) {
|
||||
fprintf(stderr, "Unable to load raw file\n");
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_destroy(l_manager);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
@ -1717,6 +1829,9 @@ int main(int argc, char **argv) {
|
|||
image = rawltoimage(parameters.infile, ¶meters, &raw_cp);
|
||||
if (!image) {
|
||||
fprintf(stderr, "Unable to load raw file\n");
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_destroy(l_manager);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
@ -1725,6 +1840,9 @@ int main(int argc, char **argv) {
|
|||
image = tgatoimage(parameters.infile, ¶meters);
|
||||
if (!image) {
|
||||
fprintf(stderr, "Unable to load tga file\n");
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_destroy(l_manager);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
@ -1734,6 +1852,9 @@ int main(int argc, char **argv) {
|
|||
image = pngtoimage(parameters.infile, ¶meters);
|
||||
if (!image) {
|
||||
fprintf(stderr, "Unable to load png file\n");
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_destroy(l_manager);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
@ -1745,6 +1866,9 @@ int main(int argc, char **argv) {
|
|||
*/
|
||||
if( !image) {
|
||||
fprintf(stderr, "Unable to load file: got no image\n");
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_destroy(l_manager);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1755,11 +1879,17 @@ int main(int argc, char **argv) {
|
|||
if ((parameters.tcp_mct == 1) && (image->numcomps < 3)){
|
||||
fprintf(stderr, "RGB->YCC conversion cannot be used:\n");
|
||||
fprintf(stderr, "Input image has less than 3 components\n");
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_destroy(l_manager);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
if ((parameters.tcp_mct == 2) && (!parameters.mct_data)){
|
||||
fprintf(stderr, "Custom MCT has been set but no array-based MCT\n");
|
||||
fprintf(stderr, "has been provided. Aborting.\n");
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_destroy(l_manager);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -1771,13 +1901,21 @@ int main(int argc, char **argv) {
|
|||
case J2K_CFMT: /* JPEG-2000 codestream */
|
||||
{
|
||||
/* Get a decoder handle */
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
l_codec = opj_manager_create_compress(l_manager, OPJ_CODEC_J2K);
|
||||
#else
|
||||
l_codec = opj_create_compress(OPJ_CODEC_J2K);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case JP2_CFMT: /* JPEG 2000 compressed image data */
|
||||
{
|
||||
/* Get a decoder handle */
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
l_codec = opj_manager_create_compress(l_manager, OPJ_CODEC_JP2);
|
||||
#else
|
||||
l_codec = opj_create_compress(OPJ_CODEC_JP2);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1787,9 +1925,15 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
/* catch events using our callbacks and give a local context */
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_set_info_handler(l_manager, info_callback,00);
|
||||
opj_manager_set_warning_handler(l_manager, warning_callback,00);
|
||||
opj_manager_set_error_handler(l_manager, error_callback,00);
|
||||
#else
|
||||
opj_set_info_handler(l_codec, info_callback,00);
|
||||
opj_set_warning_handler(l_codec, warning_callback,00);
|
||||
opj_set_error_handler(l_codec, error_callback,00);
|
||||
#endif
|
||||
|
||||
if( bUseTiles ) {
|
||||
parameters.cp_tx0 = 0;
|
||||
|
@ -1806,8 +1950,15 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
/* open a byte stream for writing and allocate memory for all tiles */
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
l_stream = opj_manager_stream_create_default_file_stream(l_manager, parameters.outfile,OPJ_FALSE);
|
||||
#else
|
||||
l_stream = opj_stream_create_default_file_stream(parameters.outfile,OPJ_FALSE);
|
||||
#endif
|
||||
if (! l_stream){
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_destroy(l_manager);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1827,6 +1978,9 @@ int main(int argc, char **argv) {
|
|||
opj_stream_destroy(l_stream);
|
||||
opj_destroy_codec(l_codec);
|
||||
opj_image_destroy(image);
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_destroy(l_manager);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -1847,8 +2001,11 @@ int main(int argc, char **argv) {
|
|||
opj_stream_destroy(l_stream);
|
||||
opj_destroy_codec(l_codec);
|
||||
opj_image_destroy(image);
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_destroy(l_manager);
|
||||
#endif
|
||||
fprintf(stderr, "failed to encode image\n");
|
||||
remove(parameters.outfile);
|
||||
remove(parameters.outfile);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1869,7 +2026,10 @@ int main(int argc, char **argv) {
|
|||
if(parameters.cp_comment) free(parameters.cp_comment);
|
||||
if(parameters.cp_matrice) free(parameters.cp_matrice);
|
||||
if(raw_cp.rawComps) free(raw_cp.rawComps);
|
||||
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_destroy(l_manager);
|
||||
#endif
|
||||
|
||||
t = opj_clock() - t;
|
||||
if (num_compressed_files) {
|
||||
fprintf(stdout, "encode time: %d ms \n", (int)((t * 1000.0)/(OPJ_FLOAT64)num_compressed_files));
|
||||
|
|
|
@ -162,6 +162,94 @@ int parse_DA_values( char* inArg, unsigned int *DA_x0, unsigned int *DA_y0, unsi
|
|||
|
||||
static opj_image_t* convert_gray_to_rgb(opj_image_t* original);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Custom allocation functions */
|
||||
//#define OPJ_USE_MEMORY_MANAGER
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
static void* opj_custom_malloc(OPJ_SIZE_T size, void *client_data)
|
||||
{
|
||||
OPJ_ARG_NOT_USED(client_data);
|
||||
|
||||
if ((size + 32U) < size) {
|
||||
return NULL;
|
||||
}
|
||||
size += 32U;
|
||||
|
||||
return (void*)(((OPJ_UINT8*)malloc(size)) + 32);
|
||||
}
|
||||
static void* opj_custom_calloc(OPJ_SIZE_T num, OPJ_SIZE_T size, void *client_data)
|
||||
{
|
||||
OPJ_ARG_NOT_USED(client_data);
|
||||
|
||||
if ((size + 32U) < size) {
|
||||
return NULL;
|
||||
}
|
||||
size += 32U;
|
||||
|
||||
return (void*)(((OPJ_UINT8*)calloc(num, size)) + 32);
|
||||
}
|
||||
static void* opj_custom_realloc(void* ptr, OPJ_SIZE_T size, void *client_data)
|
||||
{
|
||||
OPJ_ARG_NOT_USED(client_data);
|
||||
|
||||
if ((size + 32U) < size) {
|
||||
return NULL;
|
||||
}
|
||||
size += 32U;
|
||||
|
||||
if (ptr != NULL) {
|
||||
ptr = ((OPJ_UINT8*)ptr) - 32;
|
||||
}
|
||||
|
||||
return (void*)(((OPJ_UINT8*)realloc(ptr, size)) + 32);
|
||||
}
|
||||
static void opj_custom_free(void* ptr, void *client_data)
|
||||
{
|
||||
OPJ_ARG_NOT_USED(client_data);
|
||||
if (ptr != NULL) {
|
||||
free(((OPJ_UINT8*)ptr) - 32);
|
||||
}
|
||||
}
|
||||
static void* opj_custom_aligned_malloc(OPJ_SIZE_T size, OPJ_SIZE_T alignment, void *client_data)
|
||||
{
|
||||
void** l_result = NULL;
|
||||
void** l_original = NULL;
|
||||
|
||||
OPJ_ARG_NOT_USED(client_data);
|
||||
|
||||
if ((alignment == 0) || (alignment & (alignment - 1))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((size + alignment) < size) {
|
||||
return NULL;
|
||||
}
|
||||
size += alignment;
|
||||
if ((size + 32U * sizeof(void*)) < size) {
|
||||
return NULL;
|
||||
}
|
||||
size += 32U * sizeof(void*);
|
||||
|
||||
l_original = (void**)malloc(size);
|
||||
|
||||
l_result = l_original + 30U;
|
||||
|
||||
if (alignment > sizeof(void*)) {
|
||||
l_result = (void**)(((OPJ_SIZE_T)l_result + (alignment - 1)) & -alignment );
|
||||
}
|
||||
l_result[-1] = l_original;
|
||||
|
||||
return (void*)l_result;
|
||||
}
|
||||
static void opj_custom_aligned_free(void* ptr, void *client_data)
|
||||
{
|
||||
OPJ_ARG_NOT_USED(client_data);
|
||||
if (ptr != NULL) {
|
||||
free(((void**)ptr)[-1]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
static void decode_help_display(void) {
|
||||
fprintf(stdout,"\nThis is the opj_decompress utility from the OpenJPEG project.\n"
|
||||
|
@ -822,36 +910,6 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Parse decoding area input values
|
||||
* separator = ","
|
||||
*/
|
||||
/* -------------------------------------------------------------------------- */
|
||||
int parse_DA_values( char* inArg, unsigned int *DA_x0, unsigned int *DA_y0, unsigned int *DA_x1, unsigned int *DA_y1)
|
||||
{
|
||||
int it = 0;
|
||||
int values[4];
|
||||
char delims[] = ",";
|
||||
char *result = NULL;
|
||||
result = strtok( inArg, delims );
|
||||
|
||||
while( (result != NULL) && (it < 4 ) ) {
|
||||
values[it] = atoi(result);
|
||||
result = strtok( NULL, delims );
|
||||
it++;
|
||||
}
|
||||
|
||||
if (it != 4) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else{
|
||||
*DA_x0 = (OPJ_UINT32)values[0]; *DA_y0 = (OPJ_UINT32)values[1];
|
||||
*DA_x1 = (OPJ_UINT32)values[2]; *DA_y1 = (OPJ_UINT32)values[3];
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
OPJ_FLOAT64 opj_clock(void) {
|
||||
#ifdef _WIN32
|
||||
/* _WIN32: use QueryPerformance (very accurate) */
|
||||
|
@ -876,69 +934,19 @@ OPJ_FLOAT64 opj_clock(void) {
|
|||
#endif
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
sample error callback expecting a FILE* client object
|
||||
*/
|
||||
static void error_callback(const char *msg, void *client_data) {
|
||||
(void)client_data;
|
||||
fprintf(stdout, "[ERROR] %s", msg);
|
||||
}
|
||||
/**
|
||||
sample warning callback expecting a FILE* client object
|
||||
*/
|
||||
static void warning_callback(const char *msg, void *client_data) {
|
||||
(void)client_data;
|
||||
fprintf(stdout, "[WARNING] %s", msg);
|
||||
}
|
||||
/**
|
||||
sample debug callback expecting no client object
|
||||
*/
|
||||
static void info_callback(const char *msg, void *client_data) {
|
||||
(void)client_data;
|
||||
fprintf(stdout, "[INFO] %s", msg);
|
||||
}
|
||||
|
||||
static void set_default_parameters(opj_decompress_parameters* parameters)
|
||||
{
|
||||
if (parameters) {
|
||||
memset(parameters, 0, sizeof(opj_decompress_parameters));
|
||||
|
||||
/* default decoding parameters (command line specific) */
|
||||
parameters->decod_format = -1;
|
||||
parameters->cod_format = -1;
|
||||
|
||||
/* default decoding parameters (core) */
|
||||
opj_set_default_decoder_parameters(&(parameters->core));
|
||||
}
|
||||
}
|
||||
|
||||
static void destroy_parameters(opj_decompress_parameters* parameters)
|
||||
{
|
||||
if (parameters) {
|
||||
if (parameters->precision) {
|
||||
free(parameters->precision);
|
||||
parameters->precision = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
static opj_image_t* convert_gray_to_rgb(opj_image_t* original)
|
||||
{
|
||||
OPJ_UINT32 compno;
|
||||
opj_image_t* l_new_image = NULL;
|
||||
opj_image_cmptparm_t* l_new_components = NULL;
|
||||
|
||||
|
||||
l_new_components = (opj_image_cmptparm_t*)malloc((original->numcomps + 2U) * sizeof(opj_image_cmptparm_t));
|
||||
if (l_new_components == NULL) {
|
||||
fprintf(stderr, "ERROR -> opj_decompress: failed to allocate memory for RGB image!\n");
|
||||
opj_image_destroy(original);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
l_new_components[0].bpp = l_new_components[1].bpp = l_new_components[2].bpp = original->comps[0].bpp;
|
||||
l_new_components[0].dx = l_new_components[1].dx = l_new_components[2].dx = original->comps[0].dx;
|
||||
l_new_components[0].dy = l_new_components[1].dy = l_new_components[2].dy = original->comps[0].dy;
|
||||
|
@ -948,7 +956,7 @@ static opj_image_t* convert_gray_to_rgb(opj_image_t* original)
|
|||
l_new_components[0].sgnd = l_new_components[1].sgnd = l_new_components[2].sgnd = original->comps[0].sgnd;
|
||||
l_new_components[0].x0 = l_new_components[1].x0 = l_new_components[2].x0 = original->comps[0].x0;
|
||||
l_new_components[0].y0 = l_new_components[1].y0 = l_new_components[2].y0 = original->comps[0].y0;
|
||||
|
||||
|
||||
for(compno = 1U; compno < original->numcomps; ++compno) {
|
||||
l_new_components[compno+2U].bpp = original->comps[compno].bpp;
|
||||
l_new_components[compno+2U].dx = original->comps[compno].dx;
|
||||
|
@ -960,7 +968,7 @@ static opj_image_t* convert_gray_to_rgb(opj_image_t* original)
|
|||
l_new_components[compno+2U].x0 = original->comps[compno].x0;
|
||||
l_new_components[compno+2U].y0 = original->comps[compno].y0;
|
||||
}
|
||||
|
||||
|
||||
l_new_image = opj_image_create(original->numcomps + 2U, l_new_components, OPJ_CLRSPC_SRGB);
|
||||
free(l_new_components);
|
||||
if (l_new_image == NULL) {
|
||||
|
@ -968,20 +976,20 @@ static opj_image_t* convert_gray_to_rgb(opj_image_t* original)
|
|||
opj_image_destroy(original);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
l_new_image->x0 = original->x0;
|
||||
l_new_image->x1 = original->x1;
|
||||
l_new_image->y0 = original->y0;
|
||||
l_new_image->y1 = original->y1;
|
||||
|
||||
|
||||
l_new_image->comps[0].factor = l_new_image->comps[1].factor = l_new_image->comps[2].factor = original->comps[0].factor;
|
||||
l_new_image->comps[0].alpha = l_new_image->comps[1].alpha = l_new_image->comps[2].alpha = original->comps[0].alpha;
|
||||
l_new_image->comps[0].resno_decoded = l_new_image->comps[1].resno_decoded = l_new_image->comps[2].resno_decoded = original->comps[0].resno_decoded;
|
||||
|
||||
|
||||
memcpy(l_new_image->comps[0].data, original->comps[0].data, original->comps[0].w * original->comps[0].h * sizeof(OPJ_INT32));
|
||||
memcpy(l_new_image->comps[1].data, original->comps[0].data, original->comps[0].w * original->comps[0].h * sizeof(OPJ_INT32));
|
||||
memcpy(l_new_image->comps[2].data, original->comps[0].data, original->comps[0].w * original->comps[0].h * sizeof(OPJ_INT32));
|
||||
|
||||
|
||||
for(compno = 1U; compno < original->numcomps; ++compno) {
|
||||
l_new_image->comps[compno+2U].factor = original->comps[compno].factor;
|
||||
l_new_image->comps[compno+2U].alpha = original->comps[compno].alpha;
|
||||
|
@ -1022,11 +1030,11 @@ static opj_image_t* upsample_image_components(opj_image_t* original)
|
|||
opj_image_destroy(original);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
for (compno = 0U; compno < original->numcomps; ++compno) {
|
||||
opj_image_cmptparm_t* l_new_cmp = &(l_new_components[compno]);
|
||||
opj_image_comp_t* l_org_cmp = &(original->comps[compno]);
|
||||
|
||||
|
||||
l_new_cmp->bpp = l_org_cmp->bpp;
|
||||
l_new_cmp->prec = l_org_cmp->prec;
|
||||
l_new_cmp->sgnd = l_org_cmp->sgnd;
|
||||
|
@ -1035,17 +1043,17 @@ static opj_image_t* upsample_image_components(opj_image_t* original)
|
|||
l_new_cmp->dx = 1;
|
||||
l_new_cmp->dy = 1;
|
||||
l_new_cmp->w = l_org_cmp->w; /* should be original->x1 - original->x0 for dx==1 */
|
||||
l_new_cmp->h = l_org_cmp->h; /* should be original->y1 - original->y0 for dy==0 */
|
||||
|
||||
l_new_cmp->h = l_org_cmp->h; /* should be original->y1 - original->y0 for dy==1 */
|
||||
|
||||
if (l_org_cmp->dx > 1U) {
|
||||
l_new_cmp->w = original->x1 - original->x0;
|
||||
}
|
||||
|
||||
|
||||
if (l_org_cmp->dy > 1U) {
|
||||
l_new_cmp->h = original->y1 - original->y0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
l_new_image = opj_image_create(original->numcomps, l_new_components, original->color_space);
|
||||
free(l_new_components);
|
||||
if (l_new_image == NULL) {
|
||||
|
@ -1053,26 +1061,26 @@ static opj_image_t* upsample_image_components(opj_image_t* original)
|
|||
opj_image_destroy(original);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
l_new_image->x0 = original->x0;
|
||||
l_new_image->x1 = original->x1;
|
||||
l_new_image->y0 = original->y0;
|
||||
l_new_image->y1 = original->y1;
|
||||
|
||||
|
||||
for (compno = 0U; compno < original->numcomps; ++compno) {
|
||||
opj_image_comp_t* l_new_cmp = &(l_new_image->comps[compno]);
|
||||
opj_image_comp_t* l_org_cmp = &(original->comps[compno]);
|
||||
|
||||
|
||||
l_new_cmp->factor = l_org_cmp->factor;
|
||||
l_new_cmp->alpha = l_org_cmp->alpha;
|
||||
l_new_cmp->resno_decoded = l_org_cmp->resno_decoded;
|
||||
|
||||
|
||||
if ((l_org_cmp->dx > 1U) || (l_org_cmp->dy > 1U)) {
|
||||
const OPJ_INT32* l_src = l_org_cmp->data;
|
||||
OPJ_INT32* l_dst = l_new_cmp->data;
|
||||
OPJ_UINT32 y;
|
||||
OPJ_UINT32 xoff, yoff;
|
||||
|
||||
|
||||
/* need to take into account dx & dy */
|
||||
xoff = l_org_cmp->dx * l_org_cmp->x0 - original->x0;
|
||||
yoff = l_org_cmp->dy * l_org_cmp->y0 - original->y0;
|
||||
|
@ -1082,17 +1090,17 @@ static opj_image_t* upsample_image_components(opj_image_t* original)
|
|||
opj_image_destroy(l_new_image);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
for (y = 0U; y < yoff; ++y) {
|
||||
memset(l_dst, 0U, l_new_cmp->w * sizeof(OPJ_INT32));
|
||||
l_dst += l_new_cmp->w;
|
||||
}
|
||||
|
||||
|
||||
if(l_new_cmp->h > (l_org_cmp->dy - 1U)) { /* check substraction overflow for really small images */
|
||||
for (; y < l_new_cmp->h - (l_org_cmp->dy - 1U); y += l_org_cmp->dy) {
|
||||
OPJ_UINT32 x, dy;
|
||||
OPJ_UINT32 xorg;
|
||||
|
||||
|
||||
xorg = 0U;
|
||||
for (x = 0U; x < xoff; ++x) {
|
||||
l_dst[x] = 0;
|
||||
|
@ -1109,7 +1117,7 @@ static opj_image_t* upsample_image_components(opj_image_t* original)
|
|||
l_dst[x] = l_src[xorg];
|
||||
}
|
||||
l_dst += l_new_cmp->w;
|
||||
|
||||
|
||||
for (dy = 1U; dy < l_org_cmp->dy; ++dy) {
|
||||
memcpy(l_dst, l_dst - l_new_cmp->w, l_new_cmp->w * sizeof(OPJ_INT32));
|
||||
l_dst += l_new_cmp->w;
|
||||
|
@ -1120,7 +1128,7 @@ static opj_image_t* upsample_image_components(opj_image_t* original)
|
|||
if (y < l_new_cmp->h) {
|
||||
OPJ_UINT32 x;
|
||||
OPJ_UINT32 xorg;
|
||||
|
||||
|
||||
xorg = 0U;
|
||||
for (x = 0U; x < xoff; ++x) {
|
||||
l_dst[x] = 0;
|
||||
|
@ -1152,6 +1160,84 @@ static opj_image_t* upsample_image_components(opj_image_t* original)
|
|||
return l_new_image;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Parse decoding area input values
|
||||
* separator = ","
|
||||
*/
|
||||
/* -------------------------------------------------------------------------- */
|
||||
int parse_DA_values( char* inArg, unsigned int *DA_x0, unsigned int *DA_y0, unsigned int *DA_x1, unsigned int *DA_y1)
|
||||
{
|
||||
int it = 0;
|
||||
int values[4];
|
||||
char delims[] = ",";
|
||||
char *result = NULL;
|
||||
result = strtok( inArg, delims );
|
||||
|
||||
while( (result != NULL) && (it < 4 ) ) {
|
||||
values[it] = atoi(result);
|
||||
result = strtok( NULL, delims );
|
||||
it++;
|
||||
}
|
||||
|
||||
if (it != 4) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else{
|
||||
*DA_x0 = (OPJ_UINT32)values[0]; *DA_y0 = (OPJ_UINT32)values[1];
|
||||
*DA_x1 = (OPJ_UINT32)values[2]; *DA_y1 = (OPJ_UINT32)values[3];
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
sample error callback expecting a FILE* client object
|
||||
*/
|
||||
static void error_callback(const char *msg, void *client_data) {
|
||||
(void)client_data;
|
||||
fprintf(stdout, "[ERROR] %s", msg);
|
||||
}
|
||||
/**
|
||||
sample warning callback expecting a FILE* client object
|
||||
*/
|
||||
static void warning_callback(const char *msg, void *client_data) {
|
||||
(void)client_data;
|
||||
fprintf(stdout, "[WARNING] %s", msg);
|
||||
}
|
||||
/**
|
||||
sample debug callback expecting no client object
|
||||
*/
|
||||
static void info_callback(const char *msg, void *client_data) {
|
||||
(void)client_data;
|
||||
fprintf(stdout, "[INFO] %s", msg);
|
||||
}
|
||||
|
||||
static void set_default_parameters(opj_decompress_parameters* parameters)
|
||||
{
|
||||
if (parameters) {
|
||||
memset(parameters, 0, sizeof(opj_decompress_parameters));
|
||||
|
||||
/* default decoding parameters (command line specific) */
|
||||
parameters->decod_format = -1;
|
||||
parameters->cod_format = -1;
|
||||
|
||||
/* default decoding parameters (core) */
|
||||
opj_set_default_decoder_parameters(&(parameters->core));
|
||||
}
|
||||
}
|
||||
|
||||
static void destroy_parameters(opj_decompress_parameters* parameters)
|
||||
{
|
||||
if (parameters) {
|
||||
if (parameters->precision) {
|
||||
free(parameters->precision);
|
||||
parameters->precision = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/**
|
||||
* OPJ_DECOMPRESS MAIN
|
||||
|
@ -1159,6 +1245,9 @@ static opj_image_t* upsample_image_components(opj_image_t* original)
|
|||
/* -------------------------------------------------------------------------- */
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_t l_manager = NULL;
|
||||
#endif
|
||||
opj_decompress_parameters parameters; /* decompression parameters */
|
||||
opj_image_t* image = NULL;
|
||||
opj_stream_t *l_stream = NULL; /* Stream */
|
||||
|
@ -1220,6 +1309,15 @@ int main(int argc, char **argv)
|
|||
num_images=1;
|
||||
}
|
||||
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
l_manager = opj_manager_create(NULL, opj_custom_malloc, opj_custom_calloc, opj_custom_realloc, opj_custom_free, opj_custom_aligned_malloc, opj_custom_aligned_free);
|
||||
if (!l_manager){
|
||||
fprintf(stderr, "ERROR -> failed to create memory manager\n");
|
||||
destroy_parameters(¶meters);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*Decoding image one by one*/
|
||||
for(imageno = 0; imageno < num_images ; imageno++) {
|
||||
|
||||
|
@ -1235,10 +1333,16 @@ int main(int argc, char **argv)
|
|||
|
||||
/* read the input file and put it in memory */
|
||||
/* ---------------------------------------- */
|
||||
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
l_stream = opj_manager_stream_create_default_file_stream(l_manager, parameters.infile,1);
|
||||
#else
|
||||
l_stream = opj_stream_create_default_file_stream(parameters.infile,1);
|
||||
#endif
|
||||
if (!l_stream){
|
||||
fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n", parameters.infile);
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_destroy(l_manager);
|
||||
#endif
|
||||
destroy_parameters(¶meters);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
@ -1250,19 +1354,31 @@ int main(int argc, char **argv)
|
|||
case J2K_CFMT: /* JPEG-2000 codestream */
|
||||
{
|
||||
/* Get a decoder handle */
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
l_codec = opj_manager_create_decompress(l_manager, OPJ_CODEC_J2K);
|
||||
#else
|
||||
l_codec = opj_create_decompress(OPJ_CODEC_J2K);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case JP2_CFMT: /* JPEG 2000 compressed image data */
|
||||
{
|
||||
/* Get a decoder handle */
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
l_codec = opj_manager_create_decompress(l_manager, OPJ_CODEC_JP2);
|
||||
#else
|
||||
l_codec = opj_create_decompress(OPJ_CODEC_JP2);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case JPT_CFMT: /* JPEG 2000, JPIP */
|
||||
{
|
||||
/* Get a decoder handle */
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
l_codec = opj_manager_create_decompress(l_manager, OPJ_CODEC_JPT);
|
||||
#else
|
||||
l_codec = opj_create_decompress(OPJ_CODEC_JPT);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1272,10 +1388,16 @@ int main(int argc, char **argv)
|
|||
continue;
|
||||
}
|
||||
|
||||
/* catch events using our callbacks and give a local context */
|
||||
/* catch events using our callbacks and give a local context */
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_set_info_handler(l_manager, info_callback,00);
|
||||
opj_manager_set_warning_handler(l_manager, warning_callback,00);
|
||||
opj_manager_set_error_handler(l_manager, error_callback,00);
|
||||
#else
|
||||
opj_set_info_handler(l_codec, info_callback,00);
|
||||
opj_set_warning_handler(l_codec, warning_callback,00);
|
||||
opj_set_error_handler(l_codec, error_callback,00);
|
||||
#endif
|
||||
|
||||
t = opj_clock();
|
||||
|
||||
|
@ -1285,6 +1407,9 @@ int main(int argc, char **argv)
|
|||
destroy_parameters(¶meters);
|
||||
opj_stream_destroy(l_stream);
|
||||
opj_destroy_codec(l_codec);
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_destroy(l_manager);
|
||||
#endif
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -1295,7 +1420,13 @@ int main(int argc, char **argv)
|
|||
destroy_parameters(¶meters);
|
||||
opj_stream_destroy(l_stream);
|
||||
opj_destroy_codec(l_codec);
|
||||
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_image_destroy(l_manager, image);
|
||||
opj_manager_destroy(l_manager);
|
||||
#else
|
||||
opj_image_destroy(image);
|
||||
#endif
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -1307,7 +1438,12 @@ int main(int argc, char **argv)
|
|||
destroy_parameters(¶meters);
|
||||
opj_stream_destroy(l_stream);
|
||||
opj_destroy_codec(l_codec);
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_image_destroy(l_manager, image);
|
||||
opj_manager_destroy(l_manager);
|
||||
#else
|
||||
opj_image_destroy(image);
|
||||
#endif
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -1317,7 +1453,12 @@ int main(int argc, char **argv)
|
|||
destroy_parameters(¶meters);
|
||||
opj_destroy_codec(l_codec);
|
||||
opj_stream_destroy(l_stream);
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_image_destroy(l_manager, image);
|
||||
opj_manager_destroy(l_manager);
|
||||
#else
|
||||
opj_image_destroy(image);
|
||||
#endif
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
@ -1337,7 +1478,12 @@ int main(int argc, char **argv)
|
|||
destroy_parameters(¶meters);
|
||||
opj_destroy_codec(l_codec);
|
||||
opj_stream_destroy(l_stream);
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_image_destroy(l_manager, image);
|
||||
opj_manager_destroy(l_manager);
|
||||
#else
|
||||
opj_image_destroy(image);
|
||||
#endif
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
fprintf(stdout, "tile %d is decoded!\n\n", parameters.tile_index);
|
||||
|
@ -1373,7 +1519,11 @@ int main(int argc, char **argv)
|
|||
else
|
||||
color_apply_conversion(image);
|
||||
#endif
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_custom_free(image->icc_profile_buf, NULL);
|
||||
#else
|
||||
free(image->icc_profile_buf);
|
||||
#endif
|
||||
image->icc_profile_buf = NULL; image->icc_profile_len = 0;
|
||||
}
|
||||
|
||||
|
@ -1419,6 +1569,9 @@ int main(int argc, char **argv)
|
|||
fprintf(stderr, "ERROR -> opj_decompress: failed to upsample image components!\n");
|
||||
destroy_parameters(¶meters);
|
||||
opj_destroy_codec(l_codec);
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_destroy(l_manager);
|
||||
#endif
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
@ -1443,6 +1596,9 @@ int main(int argc, char **argv)
|
|||
fprintf(stderr, "ERROR -> opj_decompress: failed to convert to RGB image!\n");
|
||||
destroy_parameters(¶meters);
|
||||
opj_destroy_codec(l_codec);
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_destroy(l_manager);
|
||||
#endif
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
@ -1545,13 +1701,25 @@ int main(int argc, char **argv)
|
|||
|
||||
|
||||
/* free image data structure */
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_image_destroy(l_manager, image);
|
||||
#else
|
||||
opj_image_destroy(image);
|
||||
#endif
|
||||
|
||||
/* destroy the codestream index */
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_destroy_cstr_index(l_manager, &cstr_index);
|
||||
#else
|
||||
opj_destroy_cstr_index(&cstr_index);
|
||||
#endif
|
||||
|
||||
|
||||
if(failed) remove(parameters.outfile);
|
||||
}
|
||||
#ifdef OPJ_USE_MEMORY_MANAGER
|
||||
opj_manager_destroy(l_manager);
|
||||
#endif
|
||||
destroy_parameters(¶meters);
|
||||
if (numDecompressedImages) {
|
||||
fprintf(stdout, "decode time: %d ms\n", (int)( (tCumulative * 1000.0) / (OPJ_FLOAT64)numDecompressedImages));
|
||||
|
|
|
@ -33,6 +33,7 @@ set(OPENJPEG_SRCS
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/openjpeg.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/opj_clock.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/opj_clock.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/opj_manager.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/pi.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/pi.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/raw.c
|
||||
|
|
|
@ -120,14 +120,14 @@ static OPJ_UINT32 opj_bio_getbit(opj_bio_t *bio) {
|
|||
==========================================================
|
||||
*/
|
||||
|
||||
opj_bio_t* opj_bio_create(void) {
|
||||
opj_bio_t *bio = (opj_bio_t*)opj_malloc(sizeof(opj_bio_t));
|
||||
opj_bio_t* opj_bio_create(opj_manager_t manager) {
|
||||
opj_bio_t *bio = (opj_bio_t*)opj_manager_malloc(manager, sizeof(opj_bio_t));
|
||||
return bio;
|
||||
}
|
||||
|
||||
void opj_bio_destroy(opj_bio_t *bio) {
|
||||
void opj_bio_destroy(opj_manager_t manager, opj_bio_t *bio) {
|
||||
if(bio) {
|
||||
opj_free(bio);
|
||||
opj_manager_free(manager, bio);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,12 +73,12 @@ typedef struct opj_bio {
|
|||
Create a new BIO handle
|
||||
@return Returns a new BIO handle if successful, returns NULL otherwise
|
||||
*/
|
||||
opj_bio_t* opj_bio_create(void);
|
||||
opj_bio_t* opj_bio_create(opj_manager_t manager);
|
||||
/**
|
||||
Destroy a previously created BIO handle
|
||||
@param bio BIO handle to destroy
|
||||
*/
|
||||
void opj_bio_destroy(opj_bio_t *bio);
|
||||
void opj_bio_destroy(opj_manager_t manager, opj_bio_t *bio);
|
||||
/**
|
||||
Number of bytes written.
|
||||
@param bio BIO handle
|
||||
|
|
|
@ -150,17 +150,32 @@ void opj_read_float_LE(const OPJ_BYTE * p_buffer, OPJ_FLOAT32 * p_value)
|
|||
|
||||
opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size,OPJ_BOOL l_is_input)
|
||||
{
|
||||
opj_stream_private_t * l_stream = 00;
|
||||
l_stream = (opj_stream_private_t*) opj_calloc(1,sizeof(opj_stream_private_t));
|
||||
if (! l_stream) {
|
||||
return 00;
|
||||
opj_manager_t l_manager = opj_manager_get_global_manager();
|
||||
|
||||
return opj_manager_stream_create(l_manager, p_buffer_size, l_is_input);
|
||||
}
|
||||
|
||||
OPJ_API opj_stream_t* OPJ_CALLCONV opj_manager_stream_create(opj_manager_t manager, OPJ_SIZE_T p_buffer_size, OPJ_BOOL l_is_input)
|
||||
{
|
||||
opj_stream_private_t * l_stream = NULL;
|
||||
|
||||
if (manager == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
l_stream = (opj_stream_private_t*) opj_manager_calloc(manager, 1, sizeof(opj_stream_private_t));
|
||||
if (! l_stream) {
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Unable to allocate memory for stream.");
|
||||
return NULL;
|
||||
}
|
||||
l_stream->m_manager = manager;
|
||||
|
||||
l_stream->m_buffer_size = p_buffer_size;
|
||||
l_stream->m_stored_data = (OPJ_BYTE *) opj_malloc(p_buffer_size);
|
||||
if (! l_stream->m_stored_data) {
|
||||
opj_free(l_stream);
|
||||
return 00;
|
||||
l_stream->m_stored_data = (OPJ_BYTE *) opj_manager_malloc(manager, p_buffer_size);
|
||||
if (l_stream->m_stored_data == NULL) {
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Unable to allocate memory for stream.");
|
||||
opj_manager_free(manager, l_stream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
l_stream->m_current_data = l_stream->m_stored_data;
|
||||
|
@ -186,20 +201,28 @@ opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size,OPJ_BOOL l
|
|||
|
||||
opj_stream_t* OPJ_CALLCONV opj_stream_default_create(OPJ_BOOL l_is_input)
|
||||
{
|
||||
return opj_stream_create(OPJ_J2K_STREAM_CHUNK_SIZE,l_is_input);
|
||||
opj_manager_t l_manager = opj_manager_get_global_manager();
|
||||
|
||||
return opj_manager_stream_default_create(l_manager, l_is_input);
|
||||
}
|
||||
OPJ_API opj_stream_t* OPJ_CALLCONV opj_manager_stream_default_create(opj_manager_t manager, OPJ_BOOL l_is_input)
|
||||
{
|
||||
return opj_manager_stream_create(manager, OPJ_J2K_STREAM_CHUNK_SIZE,l_is_input);
|
||||
}
|
||||
|
||||
void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream)
|
||||
{
|
||||
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
|
||||
|
||||
|
||||
if (l_stream) {
|
||||
opj_manager_t l_manager = l_stream->m_manager;
|
||||
|
||||
if (l_stream->m_free_user_data_fn) {
|
||||
l_stream->m_free_user_data_fn(l_stream->m_user_data);
|
||||
}
|
||||
opj_free(l_stream->m_stored_data);
|
||||
opj_manager_free(l_manager, l_stream->m_stored_data);
|
||||
l_stream->m_stored_data = 00;
|
||||
opj_free(l_stream);
|
||||
opj_manager_free(l_manager, l_stream);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -165,6 +165,10 @@ typedef struct opj_stream_private
|
|||
*/
|
||||
opj_stream_flag m_status;
|
||||
|
||||
/**
|
||||
* OpenJpeg Manager (memory/event)
|
||||
*/
|
||||
opj_manager_t m_manager;
|
||||
}
|
||||
opj_stream_private_t;
|
||||
|
||||
|
|
|
@ -124,9 +124,9 @@ static void opj_dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_INT32 numbps, opj_st
|
|||
/**
|
||||
Inverse wavelet transform in 2-D.
|
||||
*/
|
||||
static OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 i, DWT1DFN fn);
|
||||
static OPJ_BOOL opj_dwt_decode_tile(opj_manager_t manager, opj_tcd_tilecomp_t* tilec, OPJ_UINT32 i, DWT1DFN fn);
|
||||
|
||||
static OPJ_BOOL opj_dwt_encode_procedure( opj_tcd_tilecomp_t * tilec,
|
||||
static OPJ_BOOL opj_dwt_encode_procedure( opj_manager_t manager, opj_tcd_tilecomp_t * tilec,
|
||||
void (*p_function)(OPJ_INT32 *, OPJ_INT32,OPJ_INT32,OPJ_INT32) );
|
||||
|
||||
static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_UINT32 i);
|
||||
|
@ -385,7 +385,7 @@ static void opj_dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_INT32 numbps, opj_st
|
|||
/* <summary> */
|
||||
/* Forward 5-3 wavelet transform in 2-D. */
|
||||
/* </summary> */
|
||||
static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tilecomp_t * tilec,void (*p_function)(OPJ_INT32 *, OPJ_INT32,OPJ_INT32,OPJ_INT32) )
|
||||
static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_manager_t manager, opj_tcd_tilecomp_t * tilec,void (*p_function)(OPJ_INT32 *, OPJ_INT32,OPJ_INT32,OPJ_INT32) )
|
||||
{
|
||||
OPJ_INT32 i, j, k;
|
||||
OPJ_INT32 *a = 00;
|
||||
|
@ -408,7 +408,7 @@ static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tilecomp_t * tilec,void
|
|||
l_last_res = l_cur_res - 1;
|
||||
|
||||
l_data_size = opj_dwt_max_resolution( tilec->resolutions,tilec->numresolutions) * (OPJ_UINT32)sizeof(OPJ_INT32);
|
||||
bj = (OPJ_INT32*)opj_malloc((size_t)l_data_size);
|
||||
bj = (OPJ_INT32*)opj_manager_malloc(manager, (size_t)l_data_size);
|
||||
if (! bj) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
@ -457,22 +457,22 @@ static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tilecomp_t * tilec,void
|
|||
--l_last_res;
|
||||
}
|
||||
|
||||
opj_free(bj);
|
||||
opj_manager_free(manager, bj);
|
||||
return OPJ_TRUE;
|
||||
}
|
||||
|
||||
/* Forward 5-3 wavelet transform in 2-D. */
|
||||
/* </summary> */
|
||||
OPJ_BOOL opj_dwt_encode(opj_tcd_tilecomp_t * tilec)
|
||||
OPJ_BOOL opj_dwt_encode(opj_manager_t manager, opj_tcd_tilecomp_t * tilec)
|
||||
{
|
||||
return opj_dwt_encode_procedure(tilec,opj_dwt_encode_1);
|
||||
return opj_dwt_encode_procedure(manager, tilec,opj_dwt_encode_1);
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
/* Inverse 5-3 wavelet transform in 2-D. */
|
||||
/* </summary> */
|
||||
OPJ_BOOL opj_dwt_decode(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres) {
|
||||
return opj_dwt_decode_tile(tilec, numres, &opj_dwt_decode_1);
|
||||
OPJ_BOOL opj_dwt_decode(opj_manager_t manager, opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres) {
|
||||
return opj_dwt_decode_tile(manager, tilec, numres, &opj_dwt_decode_1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -497,9 +497,9 @@ OPJ_FLOAT64 opj_dwt_getnorm(OPJ_UINT32 level, OPJ_UINT32 orient) {
|
|||
/* <summary> */
|
||||
/* Forward 9-7 wavelet transform in 2-D. */
|
||||
/* </summary> */
|
||||
OPJ_BOOL opj_dwt_encode_real(opj_tcd_tilecomp_t * tilec)
|
||||
OPJ_BOOL opj_dwt_encode_real(opj_manager_t manager, opj_tcd_tilecomp_t * tilec)
|
||||
{
|
||||
return opj_dwt_encode_procedure(tilec,opj_dwt_encode_1_real);
|
||||
return opj_dwt_encode_procedure(manager, tilec,opj_dwt_encode_1_real);
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -557,7 +557,7 @@ static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_U
|
|||
/* <summary> */
|
||||
/* Inverse wavelet transform in 2-D. */
|
||||
/* </summary> */
|
||||
static OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres, DWT1DFN dwt_1D) {
|
||||
static OPJ_BOOL opj_dwt_decode_tile(opj_manager_t manager, opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres, DWT1DFN dwt_1D) {
|
||||
opj_dwt_t h;
|
||||
opj_dwt_t v;
|
||||
|
||||
|
@ -569,7 +569,7 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres
|
|||
OPJ_UINT32 w = (OPJ_UINT32)(tilec->x1 - tilec->x0);
|
||||
|
||||
h.mem = (OPJ_INT32*)
|
||||
opj_aligned_malloc(opj_dwt_max_resolution(tr, numres) * sizeof(OPJ_INT32));
|
||||
opj_manager_aligned_malloc(manager, opj_dwt_max_resolution(tr, numres) * sizeof(OPJ_INT32), 16);
|
||||
if (! h.mem){
|
||||
/* FIXME event manager error callback */
|
||||
return OPJ_FALSE;
|
||||
|
@ -609,7 +609,7 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres
|
|||
}
|
||||
}
|
||||
}
|
||||
opj_aligned_free(h.mem);
|
||||
opj_manager_aligned_free(manager, h.mem);
|
||||
return OPJ_TRUE;
|
||||
}
|
||||
|
||||
|
@ -830,7 +830,7 @@ void opj_v4dwt_decode(opj_v4dwt_t* restrict dwt)
|
|||
/* <summary> */
|
||||
/* Inverse 9-7 wavelet transform in 2-D. */
|
||||
/* </summary> */
|
||||
OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numres)
|
||||
OPJ_BOOL opj_dwt_decode_real(opj_manager_t manager, opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numres)
|
||||
{
|
||||
opj_v4dwt_t h;
|
||||
opj_v4dwt_t v;
|
||||
|
@ -842,7 +842,7 @@ OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numr
|
|||
|
||||
OPJ_UINT32 w = (OPJ_UINT32)(tilec->x1 - tilec->x0);
|
||||
|
||||
h.wavelet = (opj_v4_t*) opj_aligned_malloc((opj_dwt_max_resolution(res, numres)+5) * sizeof(opj_v4_t));
|
||||
h.wavelet = (opj_v4_t*) opj_manager_aligned_malloc(manager, (opj_dwt_max_resolution(res, numres)+5) * sizeof(opj_v4_t), 16);
|
||||
if (!h.wavelet) {
|
||||
/* FIXME event manager error callback */
|
||||
return OPJ_FALSE;
|
||||
|
@ -925,6 +925,6 @@ OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numr
|
|||
}
|
||||
}
|
||||
|
||||
opj_aligned_free(h.wavelet);
|
||||
opj_manager_aligned_free(manager, h.wavelet);
|
||||
return OPJ_TRUE;
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ Forward 5-3 wavelet tranform in 2-D.
|
|||
Apply a reversible DWT transform to a component of an image.
|
||||
@param tilec Tile component information (current tile)
|
||||
*/
|
||||
OPJ_BOOL opj_dwt_encode(opj_tcd_tilecomp_t * tilec);
|
||||
OPJ_BOOL opj_dwt_encode(opj_manager_t manager, opj_tcd_tilecomp_t * tilec);
|
||||
|
||||
/**
|
||||
Inverse 5-3 wavelet tranform in 2-D.
|
||||
|
@ -66,7 +66,7 @@ Apply a reversible inverse DWT transform to a component of an image.
|
|||
@param tilec Tile component information (current tile)
|
||||
@param numres Number of resolution levels to decode
|
||||
*/
|
||||
OPJ_BOOL opj_dwt_decode(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres);
|
||||
OPJ_BOOL opj_dwt_decode(opj_manager_t manager, opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres);
|
||||
|
||||
/**
|
||||
Get the gain of a subband for the reversible 5-3 DWT.
|
||||
|
@ -86,14 +86,14 @@ Forward 9-7 wavelet transform in 2-D.
|
|||
Apply an irreversible DWT transform to a component of an image.
|
||||
@param tilec Tile component information (current tile)
|
||||
*/
|
||||
OPJ_BOOL opj_dwt_encode_real(opj_tcd_tilecomp_t * tilec);
|
||||
OPJ_BOOL opj_dwt_encode_real(opj_manager_t manager, opj_tcd_tilecomp_t * tilec);
|
||||
/**
|
||||
Inverse 9-7 wavelet transform in 2-D.
|
||||
Apply an irreversible inverse DWT transform to a component of an image.
|
||||
@param tilec Tile component information (current tile)
|
||||
@param numres Number of resolution levels to decode
|
||||
*/
|
||||
OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numres);
|
||||
OPJ_BOOL opj_dwt_decode_real(opj_manager_t manager, opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numres);
|
||||
|
||||
/**
|
||||
Get the gain of a subband for the irreversible 9-7 DWT.
|
||||
|
|
|
@ -36,82 +36,95 @@
|
|||
*/
|
||||
#define OPJ_VALIDATION_SIZE 10
|
||||
|
||||
opj_procedure_list_t * opj_procedure_list_create()
|
||||
opj_procedure_list_t * opj_procedure_list_create(opj_manager_t manager)
|
||||
{
|
||||
/* memory allocation */
|
||||
opj_procedure_list_t * l_validation = (opj_procedure_list_t *) opj_calloc(1,sizeof(opj_procedure_list_t));
|
||||
if (! l_validation)
|
||||
{
|
||||
return 00;
|
||||
}
|
||||
/* initialization */
|
||||
l_validation->m_nb_max_procedures = OPJ_VALIDATION_SIZE;
|
||||
l_validation->m_procedures = (opj_procedure*)opj_calloc(OPJ_VALIDATION_SIZE, sizeof(opj_procedure));
|
||||
if (! l_validation->m_procedures)
|
||||
{
|
||||
opj_free(l_validation);
|
||||
return 00;
|
||||
}
|
||||
return l_validation;
|
||||
opj_procedure_list_t * l_validation = NULL;
|
||||
|
||||
/* preconditions */
|
||||
assert(manager != NULL);
|
||||
|
||||
/* memory allocation */
|
||||
l_validation = (opj_procedure_list_t *) opj_manager_calloc(manager, 1, sizeof(opj_procedure_list_t));
|
||||
if (l_validation == NULL)
|
||||
{
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Unable to allocate memory for procedure list.");
|
||||
return NULL;
|
||||
}
|
||||
/* initialization */
|
||||
l_validation->m_manager = manager;
|
||||
l_validation->m_nb_max_procedures = OPJ_VALIDATION_SIZE;
|
||||
l_validation->m_procedures = (opj_procedure*)opj_manager_calloc(manager, OPJ_VALIDATION_SIZE, sizeof(opj_procedure));
|
||||
if (l_validation->m_procedures == NULL)
|
||||
{
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Unable to allocate memory for procedure list.");
|
||||
opj_manager_free(manager, l_validation);
|
||||
return NULL;
|
||||
}
|
||||
return l_validation;
|
||||
}
|
||||
|
||||
void opj_procedure_list_destroy(opj_procedure_list_t * p_list)
|
||||
{
|
||||
if (! p_list)
|
||||
{
|
||||
return;
|
||||
}
|
||||
/* initialization */
|
||||
if (p_list->m_procedures)
|
||||
{
|
||||
opj_free(p_list->m_procedures);
|
||||
}
|
||||
opj_free(p_list);
|
||||
opj_manager_t l_manager = NULL;
|
||||
if (p_list == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* preconditions */
|
||||
assert(p_list->m_manager != NULL);
|
||||
|
||||
/* initialization */
|
||||
l_manager = p_list->m_manager;
|
||||
if (p_list->m_procedures)
|
||||
{
|
||||
opj_manager_free(l_manager, p_list->m_procedures);
|
||||
}
|
||||
opj_manager_free(l_manager, p_list);
|
||||
}
|
||||
|
||||
OPJ_BOOL opj_procedure_list_add_procedure (opj_procedure_list_t * p_validation_list, opj_procedure p_procedure, opj_event_mgr_t* p_manager )
|
||||
{
|
||||
/* preconditions */
|
||||
assert(p_validation_list != NULL);
|
||||
assert(p_validation_list->m_manager != NULL);
|
||||
|
||||
assert(p_manager != NULL);
|
||||
|
||||
if (p_validation_list->m_nb_max_procedures == p_validation_list->m_nb_procedures)
|
||||
{
|
||||
opj_procedure * new_procedures;
|
||||
if (p_validation_list->m_nb_max_procedures == p_validation_list->m_nb_procedures)
|
||||
{
|
||||
opj_procedure * new_procedures;
|
||||
|
||||
p_validation_list->m_nb_max_procedures += OPJ_VALIDATION_SIZE;
|
||||
new_procedures = (opj_procedure*)opj_realloc(
|
||||
p_validation_list->m_procedures,
|
||||
p_validation_list->m_nb_max_procedures * sizeof(opj_procedure));
|
||||
if (! new_procedures)
|
||||
{
|
||||
opj_free(p_validation_list->m_procedures);
|
||||
p_validation_list->m_nb_max_procedures = 0;
|
||||
p_validation_list->m_nb_procedures = 0;
|
||||
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to add a new validation procedure\n");
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
p_validation_list->m_procedures = new_procedures;
|
||||
}
|
||||
}
|
||||
p_validation_list->m_procedures[p_validation_list->m_nb_procedures] = p_procedure;
|
||||
++p_validation_list->m_nb_procedures;
|
||||
p_validation_list->m_nb_max_procedures += OPJ_VALIDATION_SIZE;
|
||||
new_procedures = (opj_procedure*)opj_manager_realloc(p_validation_list->m_manager,
|
||||
p_validation_list->m_procedures,
|
||||
p_validation_list->m_nb_max_procedures * sizeof(opj_procedure));
|
||||
if (new_procedures == NULL)
|
||||
{
|
||||
opj_manager_free(p_validation_list->m_manager, p_validation_list->m_procedures);
|
||||
p_validation_list->m_nb_max_procedures = 0;
|
||||
p_validation_list->m_nb_procedures = 0;
|
||||
opj_event_msg(&(p_validation_list->m_manager->event_mgr), EVT_ERROR, "Not enough memory to add a new validation procedure\n");
|
||||
return OPJ_FALSE;
|
||||
} else {
|
||||
p_validation_list->m_procedures = new_procedures;
|
||||
}
|
||||
}
|
||||
p_validation_list->m_procedures[p_validation_list->m_nb_procedures] = p_procedure;
|
||||
++p_validation_list->m_nb_procedures;
|
||||
|
||||
return OPJ_TRUE;
|
||||
return OPJ_TRUE;
|
||||
}
|
||||
|
||||
OPJ_UINT32 opj_procedure_list_get_nb_procedures (opj_procedure_list_t * p_validation_list)
|
||||
{
|
||||
return p_validation_list->m_nb_procedures;
|
||||
return p_validation_list->m_nb_procedures;
|
||||
}
|
||||
|
||||
opj_procedure* opj_procedure_list_get_first_procedure (opj_procedure_list_t * p_validation_list)
|
||||
{
|
||||
return p_validation_list->m_procedures;
|
||||
return p_validation_list->m_procedures;
|
||||
}
|
||||
|
||||
void opj_procedure_list_clear (opj_procedure_list_t * p_validation_list)
|
||||
{
|
||||
p_validation_list->m_nb_procedures = 0;
|
||||
p_validation_list->m_nb_procedures = 0;
|
||||
}
|
||||
|
|
|
@ -56,6 +56,11 @@ typedef void (*opj_procedure)(void);
|
|||
*/
|
||||
typedef struct opj_procedure_list
|
||||
{
|
||||
/**
|
||||
* The memory manager.
|
||||
*/
|
||||
opj_manager_t m_manager;
|
||||
|
||||
/**
|
||||
* The number of validation procedures.
|
||||
*/
|
||||
|
@ -76,9 +81,11 @@ typedef struct opj_procedure_list
|
|||
/**
|
||||
* Creates a validation list.
|
||||
*
|
||||
* @param manager OpenJpeg memory/event manager
|
||||
*
|
||||
* @return the newly created validation list.
|
||||
*/
|
||||
opj_procedure_list_t * opj_procedure_list_create(void);
|
||||
opj_procedure_list_t * opj_procedure_list_create(opj_manager_t manager);
|
||||
|
||||
/**
|
||||
* Destroys a validation list.
|
||||
|
|
|
@ -31,53 +31,86 @@
|
|||
|
||||
#include "opj_includes.h"
|
||||
|
||||
opj_image_t* opj_image_create0(void) {
|
||||
opj_image_t *image = (opj_image_t*)opj_calloc(1, sizeof(opj_image_t));
|
||||
opj_image_t* opj_image_create0(opj_manager_t manager) {
|
||||
opj_image_t *image = NULL;
|
||||
|
||||
/* preconditions */
|
||||
assert(manager != NULL);
|
||||
|
||||
image = (opj_image_t*)opj_manager_calloc(manager, 1, sizeof(opj_image_t));
|
||||
if (image == NULL) {
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Unable to allocate memory for image.");
|
||||
return NULL;
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) {
|
||||
opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc)
|
||||
{
|
||||
opj_manager_t l_manager = opj_manager_get_global_manager();
|
||||
|
||||
return opj_manager_image_create(l_manager, numcmpts, cmptparms, clrspc);
|
||||
}
|
||||
|
||||
OPJ_API opj_image_t* OPJ_CALLCONV opj_manager_image_create(opj_manager_t manager, OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc)
|
||||
{
|
||||
OPJ_UINT32 compno;
|
||||
opj_image_t *image = NULL;
|
||||
|
||||
image = (opj_image_t*) opj_calloc(1, sizeof(opj_image_t));
|
||||
if(image) {
|
||||
image->color_space = clrspc;
|
||||
image->numcomps = numcmpts;
|
||||
/* allocate memory for the per-component information */
|
||||
image->comps = (opj_image_comp_t*)opj_calloc(1,image->numcomps * sizeof(opj_image_comp_t));
|
||||
if(!image->comps) {
|
||||
/* TODO replace with event manager, breaks API */
|
||||
/* fprintf(stderr,"Unable to allocate memory for image.\n"); */
|
||||
opj_image_destroy(image);
|
||||
if (manager == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
image = (opj_image_t*) opj_manager_calloc(manager, 1, sizeof(opj_image_t));
|
||||
if (image == NULL) {
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Unable to allocate memory for image.");
|
||||
return NULL;
|
||||
}
|
||||
image->color_space = clrspc;
|
||||
image->numcomps = numcmpts;
|
||||
/* allocate memory for the per-component information */
|
||||
image->comps = (opj_image_comp_t*)opj_manager_calloc(manager, 1,image->numcomps * sizeof(opj_image_comp_t));
|
||||
if(!image->comps) {
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Unable to allocate memory for image.");
|
||||
opj_manager_image_destroy(manager, image);
|
||||
return NULL;
|
||||
}
|
||||
/* create the individual image components */
|
||||
for(compno = 0; compno < numcmpts; compno++) {
|
||||
opj_image_comp_t *comp = &image->comps[compno];
|
||||
comp->dx = cmptparms[compno].dx;
|
||||
comp->dy = cmptparms[compno].dy;
|
||||
comp->w = cmptparms[compno].w;
|
||||
comp->h = cmptparms[compno].h;
|
||||
comp->x0 = cmptparms[compno].x0;
|
||||
comp->y0 = cmptparms[compno].y0;
|
||||
comp->prec = cmptparms[compno].prec;
|
||||
comp->bpp = cmptparms[compno].bpp;
|
||||
comp->sgnd = cmptparms[compno].sgnd;
|
||||
comp->data = (OPJ_INT32*) opj_manager_calloc(manager, comp->w * comp->h, sizeof(OPJ_INT32));
|
||||
if(!comp->data) {
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Unable to allocate memory for image.");
|
||||
opj_manager_image_destroy(manager, image);
|
||||
return NULL;
|
||||
}
|
||||
/* create the individual image components */
|
||||
for(compno = 0; compno < numcmpts; compno++) {
|
||||
opj_image_comp_t *comp = &image->comps[compno];
|
||||
comp->dx = cmptparms[compno].dx;
|
||||
comp->dy = cmptparms[compno].dy;
|
||||
comp->w = cmptparms[compno].w;
|
||||
comp->h = cmptparms[compno].h;
|
||||
comp->x0 = cmptparms[compno].x0;
|
||||
comp->y0 = cmptparms[compno].y0;
|
||||
comp->prec = cmptparms[compno].prec;
|
||||
comp->bpp = cmptparms[compno].bpp;
|
||||
comp->sgnd = cmptparms[compno].sgnd;
|
||||
comp->data = (OPJ_INT32*) opj_calloc(comp->w * comp->h, sizeof(OPJ_INT32));
|
||||
if(!comp->data) {
|
||||
/* TODO replace with event manager, breaks API */
|
||||
/* fprintf(stderr,"Unable to allocate memory for image.\n"); */
|
||||
opj_image_destroy(image);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) {
|
||||
void OPJ_CALLCONV opj_image_destroy(opj_image_t *image)
|
||||
{
|
||||
opj_manager_t l_manager = opj_manager_get_global_manager();
|
||||
|
||||
opj_manager_image_destroy(l_manager, image);
|
||||
}
|
||||
|
||||
OPJ_API void OPJ_CALLCONV opj_manager_image_destroy(opj_manager_t manager, opj_image_t *image)
|
||||
{
|
||||
if (manager == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(image) {
|
||||
if(image->comps) {
|
||||
OPJ_UINT32 compno;
|
||||
|
@ -86,17 +119,16 @@ void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) {
|
|||
for(compno = 0; compno < image->numcomps; compno++) {
|
||||
opj_image_comp_t *image_comp = &(image->comps[compno]);
|
||||
if(image_comp->data) {
|
||||
opj_free(image_comp->data);
|
||||
opj_manager_free(manager, image_comp->data);
|
||||
}
|
||||
}
|
||||
opj_free(image->comps);
|
||||
opj_manager_free(manager, image->comps);
|
||||
}
|
||||
|
||||
if(image->icc_profile_buf) {
|
||||
opj_free(image->icc_profile_buf);
|
||||
opj_manager_free(manager, image->icc_profile_buf);
|
||||
}
|
||||
|
||||
opj_free(image);
|
||||
opj_manager_free(manager, image);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,15 +173,17 @@ void opj_image_comp_header_update(opj_image_t * p_image_header, const struct opj
|
|||
* Copy only header of image and its component header (no data are copied)
|
||||
* if dest image have data, they will be freed
|
||||
*
|
||||
* @param p_image_src the src image
|
||||
* @param p_image_dest the dest image
|
||||
*
|
||||
*/
|
||||
void opj_copy_image_header(const opj_image_t* p_image_src, opj_image_t* p_image_dest)
|
||||
* @param manager OpenJpeg memory/event manager
|
||||
* @param p_image_src the src image
|
||||
* @param p_image_dest the dest image
|
||||
* @return OPJ_TRUE on success, OPJ_FALSE on failure
|
||||
* */
|
||||
OPJ_BOOL opj_copy_image_header(opj_manager_t manager, const opj_image_t* p_image_src, opj_image_t* p_image_dest)
|
||||
{
|
||||
OPJ_UINT32 compno;
|
||||
|
||||
/* preconditions */
|
||||
assert(manager != NULL);
|
||||
assert(p_image_src != 00);
|
||||
assert(p_image_dest != 00);
|
||||
|
||||
|
@ -162,26 +196,25 @@ void opj_copy_image_header(const opj_image_t* p_image_src, opj_image_t* p_image_
|
|||
for(compno = 0; compno < p_image_dest->numcomps; compno++) {
|
||||
opj_image_comp_t *image_comp = &(p_image_dest->comps[compno]);
|
||||
if(image_comp->data) {
|
||||
opj_free(image_comp->data);
|
||||
opj_manager_free(manager, image_comp->data);
|
||||
}
|
||||
}
|
||||
opj_free(p_image_dest->comps);
|
||||
opj_manager_free(manager, p_image_dest->comps);
|
||||
p_image_dest->comps = NULL;
|
||||
}
|
||||
|
||||
p_image_dest->numcomps = p_image_src->numcomps;
|
||||
|
||||
p_image_dest->comps = (opj_image_comp_t*) opj_malloc(p_image_dest->numcomps * sizeof(opj_image_comp_t));
|
||||
if (!p_image_dest->comps){
|
||||
p_image_dest->comps = (opj_image_comp_t*) opj_manager_malloc(manager, p_image_dest->numcomps * sizeof(opj_image_comp_t));
|
||||
if (p_image_dest->comps == NULL) {
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Unable to allocate memory for image.");
|
||||
p_image_dest->comps = NULL;
|
||||
p_image_dest->numcomps = 0;
|
||||
return;
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
for (compno=0; compno < p_image_dest->numcomps; compno++){
|
||||
memcpy( &(p_image_dest->comps[compno]),
|
||||
&(p_image_src->comps[compno]),
|
||||
sizeof(opj_image_comp_t));
|
||||
memcpy( &(p_image_dest->comps[compno]), &(p_image_src->comps[compno]), sizeof(opj_image_comp_t));
|
||||
p_image_dest->comps[compno].data = NULL;
|
||||
}
|
||||
|
||||
|
@ -189,53 +222,65 @@ void opj_copy_image_header(const opj_image_t* p_image_src, opj_image_t* p_image_
|
|||
p_image_dest->icc_profile_len = p_image_src->icc_profile_len;
|
||||
|
||||
if (p_image_dest->icc_profile_len) {
|
||||
p_image_dest->icc_profile_buf = (OPJ_BYTE*)opj_malloc(p_image_dest->icc_profile_len);
|
||||
if (!p_image_dest->icc_profile_buf){
|
||||
p_image_dest->icc_profile_buf = (OPJ_BYTE*)opj_manager_malloc(manager, p_image_dest->icc_profile_len);
|
||||
if (p_image_dest->icc_profile_buf == NULL) {
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Unable to allocate memory for image.");
|
||||
p_image_dest->icc_profile_buf = NULL;
|
||||
p_image_dest->icc_profile_len = 0;
|
||||
return;
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
memcpy( p_image_dest->icc_profile_buf,
|
||||
p_image_src->icc_profile_buf,
|
||||
p_image_src->icc_profile_len);
|
||||
}
|
||||
else
|
||||
p_image_dest->icc_profile_buf = NULL;
|
||||
memcpy( p_image_dest->icc_profile_buf, p_image_src->icc_profile_buf, p_image_src->icc_profile_len);
|
||||
} else {
|
||||
p_image_dest->icc_profile_buf = NULL;
|
||||
}
|
||||
|
||||
return;
|
||||
return OPJ_TRUE;
|
||||
}
|
||||
|
||||
opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) {
|
||||
opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc)
|
||||
{
|
||||
opj_manager_t l_manager = opj_manager_get_global_manager();
|
||||
|
||||
return opj_manager_image_tile_create(l_manager, numcmpts, cmptparms, clrspc);
|
||||
}
|
||||
OPJ_API opj_image_t* OPJ_CALLCONV opj_manager_image_tile_create(opj_manager_t manager, OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc)
|
||||
{
|
||||
OPJ_UINT32 compno;
|
||||
opj_image_t *image = 00;
|
||||
|
||||
image = (opj_image_t*) opj_calloc(1,sizeof(opj_image_t));
|
||||
if (image)
|
||||
{
|
||||
if (manager == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
image = (opj_image_t*) opj_manager_calloc(manager, 1, sizeof(opj_image_t));
|
||||
if (image == NULL) {
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Unable to allocate memory for image.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
image->color_space = clrspc;
|
||||
image->numcomps = numcmpts;
|
||||
image->color_space = clrspc;
|
||||
image->numcomps = numcmpts;
|
||||
|
||||
/* allocate memory for the per-component information */
|
||||
image->comps = (opj_image_comp_t*)opj_calloc(image->numcomps, sizeof(opj_image_comp_t));
|
||||
if (!image->comps) {
|
||||
opj_image_destroy(image);
|
||||
return 00;
|
||||
}
|
||||
/* allocate memory for the per-component information */
|
||||
image->comps = (opj_image_comp_t*)opj_manager_calloc(manager, image->numcomps, sizeof(opj_image_comp_t));
|
||||
if (!image->comps) {
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Unable to allocate memory for image.");
|
||||
opj_manager_image_destroy(manager, image);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* create the individual image components */
|
||||
for(compno = 0; compno < numcmpts; compno++) {
|
||||
opj_image_comp_t *comp = &image->comps[compno];
|
||||
comp->dx = cmptparms[compno].dx;
|
||||
comp->dy = cmptparms[compno].dy;
|
||||
comp->w = cmptparms[compno].w;
|
||||
comp->h = cmptparms[compno].h;
|
||||
comp->x0 = cmptparms[compno].x0;
|
||||
comp->y0 = cmptparms[compno].y0;
|
||||
comp->prec = cmptparms[compno].prec;
|
||||
comp->sgnd = cmptparms[compno].sgnd;
|
||||
comp->data = 0;
|
||||
}
|
||||
/* create the individual image components */
|
||||
for(compno = 0; compno < numcmpts; compno++) {
|
||||
opj_image_comp_t *comp = &image->comps[compno];
|
||||
comp->dx = cmptparms[compno].dx;
|
||||
comp->dy = cmptparms[compno].dy;
|
||||
comp->w = cmptparms[compno].w;
|
||||
comp->h = cmptparms[compno].h;
|
||||
comp->x0 = cmptparms[compno].x0;
|
||||
comp->y0 = cmptparms[compno].y0;
|
||||
comp->prec = cmptparms[compno].prec;
|
||||
comp->sgnd = cmptparms[compno].sgnd;
|
||||
comp->data = NULL;
|
||||
}
|
||||
|
||||
return image;
|
||||
|
|
|
@ -46,9 +46,11 @@ struct opj_cp;
|
|||
/**
|
||||
* Create an empty image
|
||||
*
|
||||
* @param manager OpenJpeg memory/event manager
|
||||
*
|
||||
* @return returns an empty image if successful, returns NULL otherwise
|
||||
*/
|
||||
opj_image_t* opj_image_create0(void);
|
||||
opj_image_t* opj_image_create0(opj_manager_t manager);
|
||||
|
||||
|
||||
|
||||
|
@ -60,7 +62,7 @@ opj_image_t* opj_image_create0(void);
|
|||
*/
|
||||
void opj_image_comp_header_update(opj_image_t * p_image, const struct opj_cp* p_cp);
|
||||
|
||||
void opj_copy_image_header(const opj_image_t* p_image_src, opj_image_t* p_image_dest);
|
||||
OPJ_BOOL opj_copy_image_header(opj_manager_t manager, const opj_image_t* p_image_src, opj_image_t* p_image_dest);
|
||||
|
||||
/*@}*/
|
||||
|
||||
|
|
|
@ -67,7 +67,8 @@ static void opj_lupInvert ( OPJ_FLOAT32 * pSrcMatrix,
|
|||
/**
|
||||
* Matrix inversion.
|
||||
*/
|
||||
OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix,
|
||||
OPJ_BOOL opj_matrix_inversion_f(opj_manager_t manager,
|
||||
OPJ_FLOAT32 * pSrcMatrix,
|
||||
OPJ_FLOAT32 * pDestMatrix,
|
||||
OPJ_UINT32 nb_compo)
|
||||
{
|
||||
|
@ -78,8 +79,12 @@ OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix,
|
|||
OPJ_UINT32 * lPermutations = 00;
|
||||
OPJ_FLOAT32 * l_double_data = 00;
|
||||
|
||||
l_data = (OPJ_BYTE *) opj_malloc(l_total_size);
|
||||
if (l_data == 0) {
|
||||
if (manager == NULL) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
l_data = (OPJ_BYTE *) opj_manager_malloc(manager, l_total_size);
|
||||
if (l_data == NULL) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
lPermutations = (OPJ_UINT32 *) l_data;
|
||||
|
@ -87,14 +92,14 @@ OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix,
|
|||
memset(lPermutations,0,l_permutation_size);
|
||||
|
||||
if(! opj_lupDecompose(pSrcMatrix,lPermutations,l_double_data,nb_compo)) {
|
||||
opj_free(l_data);
|
||||
opj_manager_free(manager, l_data);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
opj_lupInvert(pSrcMatrix,pDestMatrix,nb_compo,lPermutations,l_double_data,l_double_data + nb_compo,l_double_data + 2*nb_compo);
|
||||
opj_free(l_data);
|
||||
opj_lupInvert(pSrcMatrix,pDestMatrix,nb_compo,lPermutations,l_double_data,l_double_data + nb_compo,l_double_data + 2*nb_compo);
|
||||
opj_manager_free(manager, l_data);
|
||||
|
||||
return OPJ_TRUE;
|
||||
return OPJ_TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -48,12 +48,14 @@ The function in INVERT.H compute a matrix inversion with a LUP method
|
|||
* Calculates a n x n double matrix inversion with a LUP method. Data is aligned, rows after rows (or columns after columns).
|
||||
* The function does not take ownership of any memory block, data must be fred by the user.
|
||||
*
|
||||
* @param pSrcMatrix the matrix to invert.
|
||||
* @param pDestMatrix data to store the inverted matrix.
|
||||
* @param n size of the matrix
|
||||
* @param manager Memory manager.
|
||||
* @param pSrcMatrix the matrix to invert.
|
||||
* @param pDestMatrix data to store the inverted matrix.
|
||||
* @param n size of the matrix
|
||||
* @return OPJ_TRUE if the inversion is successful, OPJ_FALSE if the matrix is singular.
|
||||
*/
|
||||
OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix,
|
||||
OPJ_BOOL opj_matrix_inversion_f(opj_manager_t manager,
|
||||
OPJ_FLOAT32 * pSrcMatrix,
|
||||
OPJ_FLOAT32 * pDestMatrix,
|
||||
OPJ_UINT32 nb_compo);
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -555,6 +555,9 @@ JPEG-2000 codestream reader/writer
|
|||
*/
|
||||
typedef struct opj_j2k
|
||||
{
|
||||
/* Memory manager */
|
||||
opj_manager_t m_manager;
|
||||
|
||||
/* J2K codestream is decoded*/
|
||||
OPJ_BOOL m_is_decoder;
|
||||
|
||||
|
@ -612,13 +615,12 @@ void opj_j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters);
|
|||
*
|
||||
* @return Returns a handle to a J2K compressor if successful, returns NULL otherwise
|
||||
*/
|
||||
opj_j2k_t* opj_j2k_create_compress(void);
|
||||
opj_j2k_t* opj_j2k_create_compress(opj_manager_t manager);
|
||||
|
||||
|
||||
OPJ_BOOL opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
|
||||
opj_cparameters_t *parameters,
|
||||
opj_image_t *image,
|
||||
opj_event_mgr_t * p_manager);
|
||||
opj_image_t *image);
|
||||
|
||||
/**
|
||||
Converts an enum type progression order to string type
|
||||
|
@ -635,8 +637,7 @@ char *opj_j2k_convert_progression_order(OPJ_PROG_ORDER prg_order);
|
|||
* codestream.
|
||||
*/
|
||||
OPJ_BOOL opj_j2k_end_decompress(opj_j2k_t *j2k,
|
||||
opj_stream_private_t *p_stream,
|
||||
opj_event_mgr_t * p_manager);
|
||||
opj_stream_private_t *p_stream);
|
||||
|
||||
/**
|
||||
* Reads a jpeg2000 codestream header structure.
|
||||
|
@ -644,14 +645,12 @@ OPJ_BOOL opj_j2k_end_decompress(opj_j2k_t *j2k,
|
|||
* @param p_stream the stream to read data from.
|
||||
* @param p_j2k the jpeg2000 codec.
|
||||
* @param p_image FIXME DOC
|
||||
* @param p_manager the user event manager.
|
||||
*
|
||||
* @return true if the box is valid.
|
||||
*/
|
||||
OPJ_BOOL opj_j2k_read_header( opj_stream_private_t *p_stream,
|
||||
opj_j2k_t* p_j2k,
|
||||
opj_image_t** p_image,
|
||||
opj_event_mgr_t* p_manager );
|
||||
opj_image_t** p_image );
|
||||
|
||||
|
||||
/**
|
||||
|
@ -666,7 +665,7 @@ void opj_j2k_destroy (opj_j2k_t *p_j2k);
|
|||
*
|
||||
* @param p_cstr_ind the codestream index parameter to destroy.
|
||||
*/
|
||||
void j2k_destroy_cstr_index (opj_codestream_index_t *p_cstr_ind);
|
||||
void j2k_destroy_cstr_index (opj_manager_t manager, opj_codestream_index_t *p_cstr_ind);
|
||||
|
||||
/**
|
||||
* Decode tile data.
|
||||
|
@ -681,8 +680,7 @@ OPJ_BOOL opj_j2k_decode_tile ( opj_j2k_t * p_j2k,
|
|||
OPJ_UINT32 p_tile_index,
|
||||
OPJ_BYTE * p_data,
|
||||
OPJ_UINT32 p_data_size,
|
||||
opj_stream_private_t *p_stream,
|
||||
opj_event_mgr_t * p_manager );
|
||||
opj_stream_private_t *p_stream );
|
||||
|
||||
/**
|
||||
* Reads a tile header.
|
||||
|
@ -707,8 +705,7 @@ OPJ_BOOL opj_j2k_read_tile_header ( opj_j2k_t * p_j2k,
|
|||
OPJ_INT32 * p_tile_y1,
|
||||
OPJ_UINT32 * p_nb_comps,
|
||||
OPJ_BOOL * p_go_on,
|
||||
opj_stream_private_t *p_stream,
|
||||
opj_event_mgr_t * p_manager );
|
||||
opj_stream_private_t *p_stream );
|
||||
|
||||
|
||||
/**
|
||||
|
@ -720,22 +717,20 @@ OPJ_BOOL opj_j2k_read_tile_header ( opj_j2k_t * p_j2k,
|
|||
* @param p_start_y the up position of the rectangle to decode (in image coordinates).
|
||||
* @param p_end_x the right position of the rectangle to decode (in image coordinates).
|
||||
* @param p_end_y the bottom position of the rectangle to decode (in image coordinates).
|
||||
* @param p_manager the user event manager
|
||||
*
|
||||
* @return true if the area could be set.
|
||||
*/
|
||||
OPJ_BOOL opj_j2k_set_decode_area( opj_j2k_t *p_j2k,
|
||||
opj_image_t* p_image,
|
||||
OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
|
||||
OPJ_INT32 p_end_x, OPJ_INT32 p_end_y,
|
||||
opj_event_mgr_t * p_manager );
|
||||
OPJ_INT32 p_end_x, OPJ_INT32 p_end_y );
|
||||
|
||||
/**
|
||||
* Creates a J2K decompression structure.
|
||||
*
|
||||
* @return a handle to a J2K decompressor if successful, NULL otherwise.
|
||||
*/
|
||||
opj_j2k_t* opj_j2k_create_decompress(void);
|
||||
opj_j2k_t* opj_j2k_create_decompress(opj_manager_t manager);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -791,24 +786,20 @@ opj_codestream_index_t* j2k_get_cstr_index(opj_j2k_t* p_j2k);
|
|||
* @param j2k J2K decompressor handle
|
||||
* @param p_stream FIXME DOC
|
||||
* @param p_image FIXME DOC
|
||||
* @param p_manager FIXME DOC
|
||||
* @return FIXME DOC
|
||||
*/
|
||||
OPJ_BOOL opj_j2k_decode(opj_j2k_t *j2k,
|
||||
opj_stream_private_t *p_stream,
|
||||
opj_image_t *p_image,
|
||||
opj_event_mgr_t *p_manager);
|
||||
opj_image_t *p_image);
|
||||
|
||||
|
||||
OPJ_BOOL opj_j2k_get_tile( opj_j2k_t *p_j2k,
|
||||
opj_stream_private_t *p_stream,
|
||||
opj_image_t* p_image,
|
||||
opj_event_mgr_t * p_manager,
|
||||
OPJ_UINT32 tile_index );
|
||||
|
||||
OPJ_BOOL opj_j2k_set_decoded_resolution_factor(opj_j2k_t *p_j2k,
|
||||
OPJ_UINT32 res_factor,
|
||||
opj_event_mgr_t * p_manager);
|
||||
OPJ_UINT32 res_factor);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -818,21 +809,18 @@ OPJ_BOOL opj_j2k_set_decoded_resolution_factor(opj_j2k_t *p_j2k,
|
|||
* @param p_data FIXME DOC
|
||||
* @param p_data_size FIXME DOC
|
||||
* @param p_stream the stream to write data to.
|
||||
* @param p_manager the user event manager.
|
||||
*/
|
||||
OPJ_BOOL opj_j2k_write_tile ( opj_j2k_t * p_j2k,
|
||||
OPJ_UINT32 p_tile_index,
|
||||
OPJ_BYTE * p_data,
|
||||
OPJ_UINT32 p_data_size,
|
||||
opj_stream_private_t *p_stream,
|
||||
opj_event_mgr_t * p_manager );
|
||||
opj_stream_private_t *p_stream );
|
||||
|
||||
/**
|
||||
* Encodes an image into a JPEG-2000 codestream
|
||||
*/
|
||||
OPJ_BOOL opj_j2k_encode( opj_j2k_t * p_j2k,
|
||||
opj_stream_private_t *cio,
|
||||
opj_event_mgr_t * p_manager );
|
||||
OPJ_BOOL opj_j2k_encode( opj_j2k_t * p_j2k,
|
||||
opj_stream_private_t *cio );
|
||||
|
||||
/**
|
||||
* Starts a compression scheme, i.e. validates the codec parameters, writes the header.
|
||||
|
@ -840,24 +828,20 @@ OPJ_BOOL opj_j2k_encode( opj_j2k_t * p_j2k,
|
|||
* @param p_j2k the jpeg2000 codec.
|
||||
* @param p_stream the stream object.
|
||||
* @param p_image FIXME DOC
|
||||
* @param p_manager the user event manager.
|
||||
*
|
||||
* @return true if the codec is valid.
|
||||
*/
|
||||
OPJ_BOOL opj_j2k_start_compress(opj_j2k_t *p_j2k,
|
||||
opj_stream_private_t *p_stream,
|
||||
opj_image_t * p_image,
|
||||
opj_event_mgr_t * p_manager);
|
||||
opj_image_t * p_image);
|
||||
|
||||
/**
|
||||
* Ends the compression procedures and possibiliy add data to be read after the
|
||||
* codestream.
|
||||
*/
|
||||
OPJ_BOOL opj_j2k_end_compress( opj_j2k_t *p_j2k,
|
||||
opj_stream_private_t *cio,
|
||||
opj_event_mgr_t * p_manager);
|
||||
OPJ_BOOL opj_j2k_end_compress(opj_j2k_t *p_j2k, opj_stream_private_t *cio);
|
||||
|
||||
OPJ_BOOL opj_j2k_setup_mct_encoding (opj_tcp_t * p_tcp, opj_image_t * p_image);
|
||||
static OPJ_BOOL opj_j2k_setup_mct_encoding (opj_manager_t manager, opj_tcp_t * p_tcp, opj_image_t * p_image);
|
||||
|
||||
|
||||
#endif /* __J2K_H */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -155,6 +155,8 @@ JPEG-2000 file format reader/writer
|
|||
*/
|
||||
typedef struct opj_jp2
|
||||
{
|
||||
/** handle to the memory manager */
|
||||
opj_manager_t manager;
|
||||
/** handle to the J2K codec */
|
||||
opj_j2k_t *j2k;
|
||||
/** list of validation procedures */
|
||||
|
@ -186,15 +188,15 @@ typedef struct opj_jp2
|
|||
as codec writers will need to extand those fields as new part
|
||||
of the standard are implemented.
|
||||
*/
|
||||
OPJ_OFF_T j2k_codestream_offset;
|
||||
OPJ_OFF_T jpip_iptr_offset;
|
||||
OPJ_BOOL jpip_on;
|
||||
OPJ_OFF_T j2k_codestream_offset;
|
||||
OPJ_OFF_T jpip_iptr_offset;
|
||||
OPJ_BOOL jpip_on;
|
||||
OPJ_UINT32 jp2_state;
|
||||
OPJ_UINT32 jp2_img_state;
|
||||
|
||||
opj_jp2_color_t color;
|
||||
|
||||
OPJ_BOOL ignore_pclr_cmap_cdef;
|
||||
|
||||
OPJ_BOOL ignore_pclr_cmap_cdef;
|
||||
}
|
||||
opj_jp2_t;
|
||||
|
||||
|
@ -214,8 +216,7 @@ typedef struct opj_jp2_header_handler
|
|||
/* action linked to the marker */
|
||||
OPJ_BOOL (*handler) ( opj_jp2_t *jp2,
|
||||
OPJ_BYTE *p_header_data,
|
||||
OPJ_UINT32 p_header_size,
|
||||
opj_event_mgr_t * p_manager);
|
||||
OPJ_UINT32 p_header_size);
|
||||
}
|
||||
opj_jp2_header_handler_t;
|
||||
|
||||
|
@ -248,14 +249,12 @@ void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters);
|
|||
* @param jp2 JP2 decompressor handle
|
||||
* @param p_stream FIXME DOC
|
||||
* @param p_image FIXME DOC
|
||||
* @param p_manager FIXME DOC
|
||||
*
|
||||
* @return Returns a decoded image if successful, returns NULL otherwise
|
||||
*/
|
||||
OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
|
||||
opj_stream_private_t *p_stream,
|
||||
opj_image_t* p_image,
|
||||
opj_event_mgr_t * p_manager);
|
||||
opj_image_t* p_image);
|
||||
|
||||
/**
|
||||
* Setup the encoder parameters using the current image and using user parameters.
|
||||
|
@ -264,24 +263,20 @@ OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
|
|||
* @param jp2 JP2 compressor handle
|
||||
* @param parameters compression parameters
|
||||
* @param image input filled image
|
||||
* @param p_manager FIXME DOC
|
||||
* @return OPJ_TRUE if successful, OPJ_FALSE otherwise
|
||||
*/
|
||||
OPJ_BOOL opj_jp2_setup_encoder( opj_jp2_t *jp2,
|
||||
opj_cparameters_t *parameters,
|
||||
opj_image_t *image,
|
||||
opj_event_mgr_t * p_manager);
|
||||
opj_image_t *image);
|
||||
|
||||
/**
|
||||
Encode an image into a JPEG-2000 file stream
|
||||
@param jp2 JP2 compressor handle
|
||||
@param stream Output buffer stream
|
||||
@param p_manager event manager
|
||||
@return Returns true if successful, returns false otherwise
|
||||
*/
|
||||
OPJ_BOOL opj_jp2_encode( opj_jp2_t *jp2,
|
||||
opj_stream_private_t *stream,
|
||||
opj_event_mgr_t * p_manager);
|
||||
opj_stream_private_t *stream);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -290,14 +285,12 @@ OPJ_BOOL opj_jp2_encode( opj_jp2_t *jp2,
|
|||
* @param jp2 the jpeg2000 file codec.
|
||||
* @param stream the stream object.
|
||||
* @param p_image FIXME DOC
|
||||
* @param p_manager FIXME DOC
|
||||
*
|
||||
* @return true if the codec is valid.
|
||||
*/
|
||||
OPJ_BOOL opj_jp2_start_compress(opj_jp2_t *jp2,
|
||||
opj_stream_private_t *stream,
|
||||
opj_image_t * p_image,
|
||||
opj_event_mgr_t * p_manager);
|
||||
opj_image_t * p_image);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -305,8 +298,7 @@ OPJ_BOOL opj_jp2_start_compress(opj_jp2_t *jp2,
|
|||
* codestream.
|
||||
*/
|
||||
OPJ_BOOL opj_jp2_end_compress( opj_jp2_t *jp2,
|
||||
opj_stream_private_t *cio,
|
||||
opj_event_mgr_t * p_manager);
|
||||
opj_stream_private_t *cio);
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
|
@ -315,8 +307,7 @@ OPJ_BOOL opj_jp2_end_compress( opj_jp2_t *jp2,
|
|||
* codestream.
|
||||
*/
|
||||
OPJ_BOOL opj_jp2_end_decompress(opj_jp2_t *jp2,
|
||||
opj_stream_private_t *cio,
|
||||
opj_event_mgr_t * p_manager);
|
||||
opj_stream_private_t *cio);
|
||||
|
||||
/**
|
||||
* Reads a jpeg2000 file header structure.
|
||||
|
@ -324,14 +315,12 @@ OPJ_BOOL opj_jp2_end_decompress(opj_jp2_t *jp2,
|
|||
* @param p_stream the stream to read data from.
|
||||
* @param jp2 the jpeg2000 file header structure.
|
||||
* @param p_image FIXME DOC
|
||||
* @param p_manager the user event manager.
|
||||
*
|
||||
* @return true if the box is valid.
|
||||
*/
|
||||
OPJ_BOOL opj_jp2_read_header( opj_stream_private_t *p_stream,
|
||||
opj_jp2_t *jp2,
|
||||
opj_image_t ** p_image,
|
||||
opj_event_mgr_t * p_manager );
|
||||
opj_image_t ** p_image );
|
||||
|
||||
/**
|
||||
* Reads a tile header.
|
||||
|
@ -345,7 +334,6 @@ OPJ_BOOL opj_jp2_read_header( opj_stream_private_t *p_stream,
|
|||
* @param p_nb_comps FIXME DOC
|
||||
* @param p_go_on FIXME DOC
|
||||
* @param p_stream the stream to write data to.
|
||||
* @param p_manager the user event manager.
|
||||
*/
|
||||
OPJ_BOOL opj_jp2_read_tile_header ( opj_jp2_t * p_jp2,
|
||||
OPJ_UINT32 * p_tile_index,
|
||||
|
@ -356,8 +344,7 @@ OPJ_BOOL opj_jp2_read_tile_header ( opj_jp2_t * p_jp2,
|
|||
OPJ_INT32 * p_tile_y1,
|
||||
OPJ_UINT32 * p_nb_comps,
|
||||
OPJ_BOOL * p_go_on,
|
||||
opj_stream_private_t *p_stream,
|
||||
opj_event_mgr_t * p_manager );
|
||||
opj_stream_private_t *p_stream );
|
||||
|
||||
/**
|
||||
* Writes a tile.
|
||||
|
@ -367,14 +354,12 @@ OPJ_BOOL opj_jp2_read_tile_header ( opj_jp2_t * p_jp2,
|
|||
* @param p_data FIXME DOC
|
||||
* @param p_data_size FIXME DOC
|
||||
* @param p_stream the stream to write data to.
|
||||
* @param p_manager the user event manager.
|
||||
*/
|
||||
OPJ_BOOL opj_jp2_write_tile ( opj_jp2_t *p_jp2,
|
||||
OPJ_UINT32 p_tile_index,
|
||||
OPJ_BYTE * p_data,
|
||||
OPJ_UINT32 p_data_size,
|
||||
opj_stream_private_t *p_stream,
|
||||
opj_event_mgr_t * p_manager );
|
||||
opj_stream_private_t *p_stream );
|
||||
|
||||
/**
|
||||
* Decode tile data.
|
||||
|
@ -383,7 +368,6 @@ OPJ_BOOL opj_jp2_write_tile ( opj_jp2_t *p_jp2,
|
|||
* @param p_data FIXME DOC
|
||||
* @param p_data_size FIXME DOC
|
||||
* @param p_stream the stream to write data to.
|
||||
* @param p_manager the user event manager.
|
||||
*
|
||||
* @return FIXME DOC
|
||||
*/
|
||||
|
@ -391,15 +375,14 @@ OPJ_BOOL opj_jp2_decode_tile ( opj_jp2_t * p_jp2,
|
|||
OPJ_UINT32 p_tile_index,
|
||||
OPJ_BYTE * p_data,
|
||||
OPJ_UINT32 p_data_size,
|
||||
opj_stream_private_t *p_stream,
|
||||
opj_event_mgr_t * p_manager );
|
||||
opj_stream_private_t *p_stream );
|
||||
|
||||
/**
|
||||
* Creates a jpeg2000 file decompressor.
|
||||
*
|
||||
* @return an empty jpeg2000 file codec.
|
||||
*/
|
||||
opj_jp2_t* opj_jp2_create (OPJ_BOOL p_is_decoder);
|
||||
opj_jp2_t* opj_jp2_create (opj_manager_t manager, OPJ_BOOL p_is_decoder);
|
||||
|
||||
/**
|
||||
Destroy a JP2 decompressor handle
|
||||
|
@ -417,15 +400,14 @@ void opj_jp2_destroy(opj_jp2_t *jp2);
|
|||
* @param p_start_y the up position of the rectangle to decode (in image coordinates).
|
||||
* @param p_end_x the right position of the rectangle to decode (in image coordinates).
|
||||
* @param p_end_y the bottom position of the rectangle to decode (in image coordinates).
|
||||
* @param p_manager the user event manager
|
||||
|
||||
*
|
||||
* @return true if the area could be set.
|
||||
*/
|
||||
OPJ_BOOL opj_jp2_set_decode_area( opj_jp2_t *p_jp2,
|
||||
opj_image_t* p_image,
|
||||
OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
|
||||
OPJ_INT32 p_end_x, OPJ_INT32 p_end_y,
|
||||
opj_event_mgr_t * p_manager );
|
||||
OPJ_INT32 p_end_x, OPJ_INT32 p_end_y );
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -433,7 +415,6 @@ OPJ_BOOL opj_jp2_set_decode_area( opj_jp2_t *p_jp2,
|
|||
OPJ_BOOL opj_jp2_get_tile( opj_jp2_t *p_jp2,
|
||||
opj_stream_private_t *p_stream,
|
||||
opj_image_t* p_image,
|
||||
opj_event_mgr_t * p_manager,
|
||||
OPJ_UINT32 tile_index );
|
||||
|
||||
|
||||
|
@ -441,8 +422,7 @@ OPJ_BOOL opj_jp2_get_tile( opj_jp2_t *p_jp2,
|
|||
*
|
||||
*/
|
||||
OPJ_BOOL opj_jp2_set_decoded_resolution_factor(opj_jp2_t *p_jp2,
|
||||
OPJ_UINT32 res_factor,
|
||||
opj_event_mgr_t * p_manager);
|
||||
OPJ_UINT32 res_factor);
|
||||
|
||||
|
||||
/* TODO MSD: clean these 3 functions */
|
||||
|
|
|
@ -117,10 +117,8 @@ void opj_mct_encode(
|
|||
OPJ_INT32* restrict c2,
|
||||
OPJ_UINT32 n)
|
||||
{
|
||||
OPJ_SIZE_T i;
|
||||
const OPJ_SIZE_T len = n;
|
||||
|
||||
for(i = 0; i < len; ++i) {
|
||||
OPJ_UINT32 i;
|
||||
for(i = 0; i < n; ++i) {
|
||||
OPJ_INT32 r = c0[i];
|
||||
OPJ_INT32 g = c1[i];
|
||||
OPJ_INT32 b = c2[i];
|
||||
|
@ -206,10 +204,10 @@ OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno) {
|
|||
/* </summary> */
|
||||
#ifdef __SSE4_1__
|
||||
void opj_mct_encode_real(
|
||||
OPJ_INT32* restrict c0,
|
||||
OPJ_INT32* restrict c1,
|
||||
OPJ_INT32* restrict c2,
|
||||
OPJ_UINT32 n)
|
||||
OPJ_INT32* restrict c0,
|
||||
OPJ_INT32* restrict c1,
|
||||
OPJ_INT32* restrict c2,
|
||||
OPJ_UINT32 n)
|
||||
{
|
||||
OPJ_SIZE_T i;
|
||||
const OPJ_SIZE_T len = n;
|
||||
|
@ -297,11 +295,11 @@ void opj_mct_encode_real(
|
|||
hi = _mm_slli_epi64(hi, 32-13);
|
||||
u = _mm_sub_epi32(u, _mm_blend_epi16(lo, hi, 0xCC));
|
||||
_mm_store_si128((__m128i *)&(c1[i]), u);
|
||||
|
||||
|
||||
/*lo = r;
|
||||
hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1));
|
||||
lo = _mm_mul_epi32(lo, mulround);
|
||||
hi = _mm_mul_epi32(hi, mulround);*/
|
||||
hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1));
|
||||
lo = _mm_mul_epi32(lo, mulround);
|
||||
hi = _mm_mul_epi32(hi, mulround);*/
|
||||
lo = _mm_cvtepi32_epi64(_mm_shuffle_epi32(r, _MM_SHUFFLE(3, 2, 2, 0)));
|
||||
hi = _mm_cvtepi32_epi64(_mm_shuffle_epi32(r, _MM_SHUFFLE(3, 2, 3, 1)));
|
||||
lo = _mm_slli_epi64(lo, 12);
|
||||
|
@ -437,6 +435,7 @@ OPJ_FLOAT64 opj_mct_getnorm_real(OPJ_UINT32 compno) {
|
|||
|
||||
|
||||
OPJ_BOOL opj_mct_encode_custom(
|
||||
opj_manager_t manager,
|
||||
OPJ_BYTE * pCodingdata,
|
||||
OPJ_UINT32 n,
|
||||
OPJ_BYTE ** pData,
|
||||
|
@ -454,9 +453,13 @@ OPJ_BOOL opj_mct_encode_custom(
|
|||
OPJ_UINT32 lMultiplicator = 1 << 13;
|
||||
OPJ_INT32 * lMctPtr;
|
||||
|
||||
OPJ_ARG_NOT_USED(isSigned);
|
||||
OPJ_ARG_NOT_USED(isSigned);
|
||||
|
||||
lCurrentData = (OPJ_INT32 *) opj_malloc((pNbComp + lNbMatCoeff) * sizeof(OPJ_INT32));
|
||||
if (manager == NULL) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
lCurrentData = (OPJ_INT32 *) opj_manager_malloc(manager, (pNbComp + lNbMatCoeff) * sizeof(OPJ_INT32));
|
||||
if (! lCurrentData) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
@ -484,12 +487,13 @@ OPJ_BOOL opj_mct_encode_custom(
|
|||
}
|
||||
}
|
||||
|
||||
opj_free(lCurrentData);
|
||||
opj_manager_free(manager, lCurrentData);
|
||||
|
||||
return OPJ_TRUE;
|
||||
}
|
||||
|
||||
OPJ_BOOL opj_mct_decode_custom(
|
||||
opj_manager_t manager,
|
||||
OPJ_BYTE * pDecodingData,
|
||||
OPJ_UINT32 n,
|
||||
OPJ_BYTE ** pData,
|
||||
|
@ -507,7 +511,11 @@ OPJ_BOOL opj_mct_decode_custom(
|
|||
|
||||
OPJ_ARG_NOT_USED(isSigned);
|
||||
|
||||
lCurrentData = (OPJ_FLOAT32 *) opj_malloc (2 * pNbComp * sizeof(OPJ_FLOAT32));
|
||||
if (manager == NULL) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
lCurrentData = (OPJ_FLOAT32 *) opj_manager_malloc(manager, 2 * pNbComp * sizeof(OPJ_FLOAT32));
|
||||
if (! lCurrentData) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
@ -526,7 +534,7 @@ OPJ_BOOL opj_mct_decode_custom(
|
|||
*(lData[j]++) = (OPJ_FLOAT32) (lCurrentResult[j]);
|
||||
}
|
||||
}
|
||||
opj_free(lCurrentData);
|
||||
opj_manager_free(manager, lCurrentData);
|
||||
return OPJ_TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -101,6 +101,7 @@ OPJ_FLOAT64 opj_mct_getnorm_real(OPJ_UINT32 compno);
|
|||
|
||||
/**
|
||||
FIXME DOC
|
||||
@param manager User memory/event manager
|
||||
@param p_coding_data MCT data
|
||||
@param n size of components
|
||||
@param p_data components
|
||||
|
@ -109,6 +110,7 @@ FIXME DOC
|
|||
@return OPJ_FALSE if function encounter a problem, OPJ_TRUE otherwise
|
||||
*/
|
||||
OPJ_BOOL opj_mct_encode_custom(
|
||||
opj_manager_t manager,
|
||||
OPJ_BYTE * p_coding_data,
|
||||
OPJ_UINT32 n,
|
||||
OPJ_BYTE ** p_data,
|
||||
|
@ -116,6 +118,7 @@ OPJ_BOOL opj_mct_encode_custom(
|
|||
OPJ_UINT32 is_signed);
|
||||
/**
|
||||
FIXME DOC
|
||||
@param manager User memory/event manager
|
||||
@param pDecodingData MCT data
|
||||
@param n size of components
|
||||
@param pData components
|
||||
|
@ -124,6 +127,7 @@ FIXME DOC
|
|||
@return OPJ_FALSE if function encounter a problem, OPJ_TRUE otherwise
|
||||
*/
|
||||
OPJ_BOOL opj_mct_decode_custom(
|
||||
opj_manager_t manager,
|
||||
OPJ_BYTE * pDecodingData,
|
||||
OPJ_UINT32 n,
|
||||
OPJ_BYTE ** pData,
|
||||
|
|
|
@ -359,8 +359,8 @@ static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc) {
|
|||
==========================================================
|
||||
*/
|
||||
|
||||
opj_mqc_t* opj_mqc_create(void) {
|
||||
opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t));
|
||||
opj_mqc_t* opj_mqc_create(opj_manager_t manager) {
|
||||
opj_mqc_t *mqc = (opj_mqc_t*)opj_manager_malloc(manager, sizeof(opj_mqc_t));
|
||||
#ifdef MQC_PERF_OPT
|
||||
if (mqc) {
|
||||
mqc->buffer = NULL;
|
||||
|
@ -369,14 +369,14 @@ opj_mqc_t* opj_mqc_create(void) {
|
|||
return mqc;
|
||||
}
|
||||
|
||||
void opj_mqc_destroy(opj_mqc_t *mqc) {
|
||||
void opj_mqc_destroy(opj_manager_t manager, opj_mqc_t *mqc) {
|
||||
if(mqc) {
|
||||
#ifdef MQC_PERF_OPT
|
||||
if (mqc->buffer) {
|
||||
opj_free(mqc->buffer);
|
||||
opj_manager_free(manager, mqc->buffer);
|
||||
}
|
||||
#endif
|
||||
opj_free(mqc);
|
||||
opj_manager_free(manager, mqc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -89,12 +89,12 @@ typedef struct opj_mqc {
|
|||
Create a new MQC handle
|
||||
@return Returns a new MQC handle if successful, returns NULL otherwise
|
||||
*/
|
||||
opj_mqc_t* opj_mqc_create(void);
|
||||
opj_mqc_t* opj_mqc_create(opj_manager_t manager);
|
||||
/**
|
||||
Destroy a previously created MQC handle
|
||||
@param mqc MQC handle to destroy
|
||||
*/
|
||||
void opj_mqc_destroy(opj_mqc_t *mqc);
|
||||
void opj_mqc_destroy(opj_manager_t manager, opj_mqc_t *mqc);
|
||||
/**
|
||||
Return the number of bytes written/read since initialisation
|
||||
@param mqc MQC handle
|
||||
|
|
|
@ -49,11 +49,11 @@ OPJ_BOOL OPJ_CALLCONV opj_set_info_handler( opj_codec_t * p_codec,
|
|||
if(! l_codec){
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
if (! l_codec->manager_is_private) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
l_codec->m_event_mgr.info_handler = p_callback;
|
||||
l_codec->m_event_mgr.m_info_data = p_user_data;
|
||||
|
||||
return OPJ_TRUE;
|
||||
return opj_manager_set_info_handler(l_codec->manager, p_callback, p_user_data);
|
||||
}
|
||||
|
||||
OPJ_BOOL OPJ_CALLCONV opj_set_warning_handler( opj_codec_t * p_codec,
|
||||
|
@ -65,10 +65,11 @@ OPJ_BOOL OPJ_CALLCONV opj_set_warning_handler( opj_codec_t * p_codec,
|
|||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
l_codec->m_event_mgr.warning_handler = p_callback;
|
||||
l_codec->m_event_mgr.m_warning_data = p_user_data;
|
||||
if (! l_codec->manager_is_private) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
return OPJ_TRUE;
|
||||
return opj_manager_set_warning_handler(l_codec->manager, p_callback, p_user_data);
|
||||
}
|
||||
|
||||
OPJ_BOOL OPJ_CALLCONV opj_set_error_handler(opj_codec_t * p_codec,
|
||||
|
@ -80,10 +81,11 @@ OPJ_BOOL OPJ_CALLCONV opj_set_error_handler(opj_codec_t * p_codec,
|
|||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
l_codec->m_event_mgr.error_handler = p_callback;
|
||||
l_codec->m_event_mgr.m_error_data = p_user_data;
|
||||
if (! l_codec->manager_is_private) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
return OPJ_TRUE;
|
||||
return opj_manager_set_error_handler(l_codec->manager, p_callback, p_user_data);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
@ -162,14 +164,38 @@ const char* OPJ_CALLCONV opj_version(void) {
|
|||
/* DECOMPRESSION FUNCTIONS*/
|
||||
|
||||
opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format)
|
||||
{
|
||||
opj_codec_private_t* l_codec = NULL;
|
||||
opj_manager_t l_manager = opj_manager_create_default();
|
||||
|
||||
if (l_manager == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
l_codec = (opj_codec_private_t*)opj_manager_create_decompress(l_manager, p_format);
|
||||
if (l_codec == NULL) {
|
||||
opj_manager_destroy(l_manager);
|
||||
return NULL;
|
||||
}
|
||||
l_codec->manager_is_private = OPJ_TRUE;
|
||||
return (opj_codec_t*)l_codec;
|
||||
}
|
||||
|
||||
OPJ_API opj_codec_t* OPJ_CALLCONV opj_manager_create_decompress(opj_manager_t manager, OPJ_CODEC_FORMAT p_format)
|
||||
{
|
||||
opj_codec_private_t *l_codec = 00;
|
||||
|
||||
l_codec = (opj_codec_private_t*) opj_calloc(1, sizeof(opj_codec_private_t));
|
||||
if (manager == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
l_codec = (opj_codec_private_t*) opj_manager_calloc(manager, 1, sizeof(opj_codec_private_t));
|
||||
if (!l_codec){
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Not enough memory to allocate codec abstraction.");
|
||||
return 00;
|
||||
}
|
||||
|
||||
l_codec->manager = manager;
|
||||
l_codec->is_decompressor = 1;
|
||||
|
||||
switch (p_format) {
|
||||
|
@ -183,18 +209,16 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format)
|
|||
l_codec->m_codec_data.m_decompression.opj_decode =
|
||||
(OPJ_BOOL (*) ( void *,
|
||||
struct opj_stream_private *,
|
||||
opj_image_t*, struct opj_event_mgr * )) opj_j2k_decode;
|
||||
opj_image_t*)) opj_j2k_decode;
|
||||
|
||||
l_codec->m_codec_data.m_decompression.opj_end_decompress =
|
||||
(OPJ_BOOL (*) ( void *,
|
||||
struct opj_stream_private *,
|
||||
struct opj_event_mgr *)) opj_j2k_end_decompress;
|
||||
struct opj_stream_private *)) opj_j2k_end_decompress;
|
||||
|
||||
l_codec->m_codec_data.m_decompression.opj_read_header =
|
||||
(OPJ_BOOL (*) ( struct opj_stream_private *,
|
||||
void *,
|
||||
opj_image_t **,
|
||||
struct opj_event_mgr * )) opj_j2k_read_header;
|
||||
opj_image_t **)) opj_j2k_read_header;
|
||||
|
||||
l_codec->m_codec_data.m_decompression.opj_destroy =
|
||||
(void (*) (void *))opj_j2k_destroy;
|
||||
|
@ -210,39 +234,35 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format)
|
|||
OPJ_INT32*, OPJ_INT32*,
|
||||
OPJ_UINT32*,
|
||||
OPJ_BOOL*,
|
||||
struct opj_stream_private *,
|
||||
struct opj_event_mgr * )) opj_j2k_read_tile_header;
|
||||
struct opj_stream_private *)) opj_j2k_read_tile_header;
|
||||
|
||||
l_codec->m_codec_data.m_decompression.opj_decode_tile_data =
|
||||
(OPJ_BOOL (*) ( void *,
|
||||
OPJ_UINT32,
|
||||
OPJ_BYTE*,
|
||||
OPJ_UINT32,
|
||||
struct opj_stream_private *,
|
||||
struct opj_event_mgr *)) opj_j2k_decode_tile;
|
||||
struct opj_stream_private *)) opj_j2k_decode_tile;
|
||||
|
||||
l_codec->m_codec_data.m_decompression.opj_set_decode_area =
|
||||
(OPJ_BOOL (*) ( void *,
|
||||
opj_image_t*,
|
||||
OPJ_INT32, OPJ_INT32, OPJ_INT32, OPJ_INT32,
|
||||
struct opj_event_mgr *)) opj_j2k_set_decode_area;
|
||||
OPJ_INT32, OPJ_INT32, OPJ_INT32, OPJ_INT32)) opj_j2k_set_decode_area;
|
||||
|
||||
l_codec->m_codec_data.m_decompression.opj_get_decoded_tile =
|
||||
(OPJ_BOOL (*) ( void *p_codec,
|
||||
opj_stream_private_t *p_cio,
|
||||
opj_image_t *p_image,
|
||||
struct opj_event_mgr * p_manager,
|
||||
OPJ_UINT32 tile_index)) opj_j2k_get_tile;
|
||||
|
||||
l_codec->m_codec_data.m_decompression.opj_set_decoded_resolution_factor =
|
||||
(OPJ_BOOL (*) ( void * p_codec,
|
||||
OPJ_UINT32 res_factor,
|
||||
struct opj_event_mgr * p_manager)) opj_j2k_set_decoded_resolution_factor;
|
||||
OPJ_UINT32 res_factor)) opj_j2k_set_decoded_resolution_factor;
|
||||
|
||||
l_codec->m_codec = opj_j2k_create_decompress();
|
||||
l_codec->m_codec = opj_j2k_create_decompress(manager);
|
||||
|
||||
if (! l_codec->m_codec) {
|
||||
opj_free(l_codec);
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Not enough memory to allocate j2k codec.");
|
||||
opj_manager_free(manager,l_codec);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -259,19 +279,16 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format)
|
|||
l_codec->m_codec_data.m_decompression.opj_decode =
|
||||
(OPJ_BOOL (*) ( void *,
|
||||
struct opj_stream_private *,
|
||||
opj_image_t*,
|
||||
struct opj_event_mgr * )) opj_jp2_decode;
|
||||
opj_image_t* )) opj_jp2_decode;
|
||||
|
||||
l_codec->m_codec_data.m_decompression.opj_end_decompress =
|
||||
(OPJ_BOOL (*) ( void *,
|
||||
struct opj_stream_private *,
|
||||
struct opj_event_mgr *)) opj_jp2_end_decompress;
|
||||
struct opj_stream_private * )) opj_jp2_end_decompress;
|
||||
|
||||
l_codec->m_codec_data.m_decompression.opj_read_header =
|
||||
(OPJ_BOOL (*) ( struct opj_stream_private *,
|
||||
void *,
|
||||
opj_image_t **,
|
||||
struct opj_event_mgr * )) opj_jp2_read_header;
|
||||
opj_image_t ** )) opj_jp2_read_header;
|
||||
|
||||
l_codec->m_codec_data.m_decompression.opj_read_tile_header =
|
||||
(OPJ_BOOL (*) ( void *,
|
||||
|
@ -283,14 +300,12 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format)
|
|||
OPJ_INT32 * ,
|
||||
OPJ_UINT32 * ,
|
||||
OPJ_BOOL *,
|
||||
struct opj_stream_private *,
|
||||
struct opj_event_mgr * )) opj_jp2_read_tile_header;
|
||||
struct opj_stream_private * )) opj_jp2_read_tile_header;
|
||||
|
||||
l_codec->m_codec_data.m_decompression.opj_decode_tile_data =
|
||||
(OPJ_BOOL (*) ( void *,
|
||||
OPJ_UINT32,OPJ_BYTE*,OPJ_UINT32,
|
||||
struct opj_stream_private *,
|
||||
struct opj_event_mgr * )) opj_jp2_decode_tile;
|
||||
struct opj_stream_private * )) opj_jp2_decode_tile;
|
||||
|
||||
l_codec->m_codec_data.m_decompression.opj_destroy = (void (*) (void *))opj_jp2_destroy;
|
||||
|
||||
|
@ -300,25 +315,23 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format)
|
|||
l_codec->m_codec_data.m_decompression.opj_set_decode_area =
|
||||
(OPJ_BOOL (*) ( void *,
|
||||
opj_image_t*,
|
||||
OPJ_INT32,OPJ_INT32,OPJ_INT32,OPJ_INT32,
|
||||
struct opj_event_mgr * )) opj_jp2_set_decode_area;
|
||||
OPJ_INT32,OPJ_INT32,OPJ_INT32,OPJ_INT32 )) opj_jp2_set_decode_area;
|
||||
|
||||
l_codec->m_codec_data.m_decompression.opj_get_decoded_tile =
|
||||
(OPJ_BOOL (*) ( void *p_codec,
|
||||
opj_stream_private_t *p_cio,
|
||||
opj_image_t *p_image,
|
||||
struct opj_event_mgr * p_manager,
|
||||
OPJ_UINT32 tile_index)) opj_jp2_get_tile;
|
||||
|
||||
l_codec->m_codec_data.m_decompression.opj_set_decoded_resolution_factor =
|
||||
(OPJ_BOOL (*) ( void * p_codec,
|
||||
OPJ_UINT32 res_factor,
|
||||
opj_event_mgr_t * p_manager)) opj_jp2_set_decoded_resolution_factor;
|
||||
OPJ_UINT32 res_factor)) opj_jp2_set_decoded_resolution_factor;
|
||||
|
||||
l_codec->m_codec = opj_jp2_create(OPJ_TRUE);
|
||||
l_codec->m_codec = opj_jp2_create(manager, OPJ_TRUE);
|
||||
|
||||
if (! l_codec->m_codec) {
|
||||
opj_free(l_codec);
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Not enough memory to allocate jp2 codec.");
|
||||
opj_manager_free(manager, l_codec);
|
||||
return 00;
|
||||
}
|
||||
|
||||
|
@ -326,11 +339,11 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format)
|
|||
case OPJ_CODEC_UNKNOWN:
|
||||
case OPJ_CODEC_JPT:
|
||||
default:
|
||||
opj_free(l_codec);
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Unknown codec.");
|
||||
opj_manager_free(manager,l_codec);
|
||||
return 00;
|
||||
}
|
||||
|
||||
opj_set_default_event_handler(&(l_codec->m_event_mgr));
|
||||
return (opj_codec_t*) l_codec;
|
||||
}
|
||||
|
||||
|
@ -362,7 +375,7 @@ OPJ_BOOL OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec,
|
|||
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
|
||||
|
||||
if (! l_codec->is_decompressor) {
|
||||
opj_event_msg(&(l_codec->m_event_mgr), EVT_ERROR,
|
||||
opj_event_msg(&(l_codec->manager->event_mgr), EVT_ERROR,
|
||||
"Codec provided to the opj_setup_decoder function is not a decompressor handler.\n");
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
@ -383,15 +396,14 @@ OPJ_BOOL OPJ_CALLCONV opj_read_header ( opj_stream_t *p_stream,
|
|||
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
|
||||
|
||||
if(! l_codec->is_decompressor) {
|
||||
opj_event_msg(&(l_codec->m_event_mgr), EVT_ERROR,
|
||||
opj_event_msg(&(l_codec->manager->event_mgr), EVT_ERROR,
|
||||
"Codec provided to the opj_read_header function is not a decompressor handler.\n");
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
return l_codec->m_codec_data.m_decompression.opj_read_header( l_stream,
|
||||
l_codec->m_codec,
|
||||
p_image,
|
||||
&(l_codec->m_event_mgr) );
|
||||
p_image );
|
||||
}
|
||||
|
||||
return OPJ_FALSE;
|
||||
|
@ -411,8 +423,7 @@ OPJ_BOOL OPJ_CALLCONV opj_decode( opj_codec_t *p_codec,
|
|||
|
||||
return l_codec->m_codec_data.m_decompression.opj_decode(l_codec->m_codec,
|
||||
l_stream,
|
||||
p_image,
|
||||
&(l_codec->m_event_mgr) );
|
||||
p_image);
|
||||
}
|
||||
|
||||
return OPJ_FALSE;
|
||||
|
@ -434,8 +445,7 @@ OPJ_BOOL OPJ_CALLCONV opj_set_decode_area( opj_codec_t *p_codec,
|
|||
return l_codec->m_codec_data.m_decompression.opj_set_decode_area( l_codec->m_codec,
|
||||
p_image,
|
||||
p_start_x, p_start_y,
|
||||
p_end_x, p_end_y,
|
||||
&(l_codec->m_event_mgr) );
|
||||
p_end_x, p_end_y );
|
||||
}
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
@ -464,8 +474,7 @@ OPJ_BOOL OPJ_CALLCONV opj_read_tile_header( opj_codec_t *p_codec,
|
|||
p_tile_x1, p_tile_y1,
|
||||
p_nb_comps,
|
||||
p_should_go_on,
|
||||
l_stream,
|
||||
&(l_codec->m_event_mgr));
|
||||
l_stream);
|
||||
}
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
@ -489,8 +498,7 @@ OPJ_BOOL OPJ_CALLCONV opj_decode_tile_data( opj_codec_t *p_codec,
|
|||
p_tile_index,
|
||||
p_data,
|
||||
p_data_size,
|
||||
l_stream,
|
||||
&(l_codec->m_event_mgr) );
|
||||
l_stream );
|
||||
}
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
@ -511,7 +519,6 @@ OPJ_BOOL OPJ_CALLCONV opj_get_decoded_tile( opj_codec_t *p_codec,
|
|||
return l_codec->m_codec_data.m_decompression.opj_get_decoded_tile( l_codec->m_codec,
|
||||
l_stream,
|
||||
p_image,
|
||||
&(l_codec->m_event_mgr),
|
||||
tile_index);
|
||||
}
|
||||
|
||||
|
@ -528,57 +535,73 @@ OPJ_BOOL OPJ_CALLCONV opj_set_decoded_resolution_factor(opj_codec_t *p_codec,
|
|||
}
|
||||
|
||||
return l_codec->m_codec_data.m_decompression.opj_set_decoded_resolution_factor(l_codec->m_codec,
|
||||
res_factor,
|
||||
&(l_codec->m_event_mgr) );
|
||||
res_factor );
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* COMPRESSION FUNCTIONS*/
|
||||
|
||||
opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format)
|
||||
{
|
||||
opj_codec_private_t* l_codec = NULL;
|
||||
opj_manager_t l_manager = opj_manager_create_default();
|
||||
|
||||
if (l_manager == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
l_codec = (opj_codec_private_t*)opj_manager_create_compress(l_manager, p_format);
|
||||
if (l_codec == NULL) {
|
||||
opj_manager_destroy(l_manager);
|
||||
return NULL;
|
||||
}
|
||||
l_codec->manager_is_private = OPJ_TRUE;
|
||||
return (opj_codec_t*)l_codec;
|
||||
}
|
||||
|
||||
OPJ_API opj_codec_t* OPJ_CALLCONV opj_manager_create_compress(opj_manager_t manager, OPJ_CODEC_FORMAT p_format)
|
||||
{
|
||||
opj_codec_private_t *l_codec = 00;
|
||||
|
||||
l_codec = (opj_codec_private_t*)opj_calloc(1, sizeof(opj_codec_private_t));
|
||||
if (!l_codec) {
|
||||
l_codec = (opj_codec_private_t*) opj_manager_calloc(manager, 1, sizeof(opj_codec_private_t));
|
||||
if (!l_codec){
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Not enough memory to allocate codec abstraction.");
|
||||
return 00;
|
||||
}
|
||||
|
||||
l_codec->manager = manager;
|
||||
l_codec->is_decompressor = 0;
|
||||
|
||||
switch(p_format) {
|
||||
case OPJ_CODEC_J2K:
|
||||
l_codec->m_codec_data.m_compression.opj_encode = (OPJ_BOOL (*) (void *,
|
||||
struct opj_stream_private *,
|
||||
struct opj_event_mgr * )) opj_j2k_encode;
|
||||
struct opj_stream_private * )) opj_j2k_encode;
|
||||
|
||||
l_codec->m_codec_data.m_compression.opj_end_compress = (OPJ_BOOL (*) ( void *,
|
||||
struct opj_stream_private *,
|
||||
struct opj_event_mgr *)) opj_j2k_end_compress;
|
||||
struct opj_stream_private * )) opj_j2k_end_compress;
|
||||
|
||||
l_codec->m_codec_data.m_compression.opj_start_compress = (OPJ_BOOL (*) (void *,
|
||||
struct opj_stream_private *,
|
||||
struct opj_image * ,
|
||||
struct opj_event_mgr *)) opj_j2k_start_compress;
|
||||
struct opj_image * )) opj_j2k_start_compress;
|
||||
|
||||
l_codec->m_codec_data.m_compression.opj_write_tile = (OPJ_BOOL (*) (void *,
|
||||
OPJ_UINT32,
|
||||
OPJ_BYTE*,
|
||||
OPJ_UINT32,
|
||||
struct opj_stream_private *,
|
||||
struct opj_event_mgr *) ) opj_j2k_write_tile;
|
||||
struct opj_stream_private * ) ) opj_j2k_write_tile;
|
||||
|
||||
l_codec->m_codec_data.m_compression.opj_destroy = (void (*) (void *)) opj_j2k_destroy;
|
||||
|
||||
l_codec->m_codec_data.m_compression.opj_setup_encoder = (OPJ_BOOL (*) ( void *,
|
||||
opj_cparameters_t *,
|
||||
struct opj_image *,
|
||||
struct opj_event_mgr * )) opj_j2k_setup_encoder;
|
||||
struct opj_image * )) opj_j2k_setup_encoder;
|
||||
|
||||
l_codec->m_codec = opj_j2k_create_compress(manager);
|
||||
|
||||
l_codec->m_codec = opj_j2k_create_compress();
|
||||
if (! l_codec->m_codec) {
|
||||
opj_free(l_codec);
|
||||
return 00;
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Not enough memory to allocate j2k codec.");
|
||||
opj_manager_free(manager,l_codec);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -586,36 +609,33 @@ opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format)
|
|||
case OPJ_CODEC_JP2:
|
||||
/* get a JP2 decoder handle */
|
||||
l_codec->m_codec_data.m_compression.opj_encode = (OPJ_BOOL (*) (void *,
|
||||
struct opj_stream_private *,
|
||||
struct opj_event_mgr * )) opj_jp2_encode;
|
||||
struct opj_stream_private * )) opj_jp2_encode;
|
||||
|
||||
l_codec->m_codec_data.m_compression.opj_end_compress = (OPJ_BOOL (*) ( void *,
|
||||
struct opj_stream_private *,
|
||||
struct opj_event_mgr *)) opj_jp2_end_compress;
|
||||
struct opj_stream_private * )) opj_jp2_end_compress;
|
||||
|
||||
l_codec->m_codec_data.m_compression.opj_start_compress = (OPJ_BOOL (*) (void *,
|
||||
struct opj_stream_private *,
|
||||
struct opj_image * ,
|
||||
struct opj_event_mgr *)) opj_jp2_start_compress;
|
||||
struct opj_image * )) opj_jp2_start_compress;
|
||||
|
||||
l_codec->m_codec_data.m_compression.opj_write_tile = (OPJ_BOOL (*) (void *,
|
||||
OPJ_UINT32,
|
||||
OPJ_BYTE*,
|
||||
OPJ_UINT32,
|
||||
struct opj_stream_private *,
|
||||
struct opj_event_mgr *)) opj_jp2_write_tile;
|
||||
struct opj_stream_private * )) opj_jp2_write_tile;
|
||||
|
||||
l_codec->m_codec_data.m_compression.opj_destroy = (void (*) (void *)) opj_jp2_destroy;
|
||||
|
||||
l_codec->m_codec_data.m_compression.opj_setup_encoder = (OPJ_BOOL (*) ( void *,
|
||||
opj_cparameters_t *,
|
||||
struct opj_image *,
|
||||
struct opj_event_mgr * )) opj_jp2_setup_encoder;
|
||||
struct opj_image * )) opj_jp2_setup_encoder;
|
||||
|
||||
l_codec->m_codec = opj_jp2_create(manager, OPJ_FALSE);
|
||||
|
||||
l_codec->m_codec = opj_jp2_create(OPJ_FALSE);
|
||||
if (! l_codec->m_codec) {
|
||||
opj_free(l_codec);
|
||||
return 00;
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Not enough memory to allocate jp2 codec.");
|
||||
opj_manager_free(manager,l_codec);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -623,11 +643,11 @@ opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format)
|
|||
case OPJ_CODEC_UNKNOWN:
|
||||
case OPJ_CODEC_JPT:
|
||||
default:
|
||||
opj_free(l_codec);
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Unknown codec.");
|
||||
opj_manager_free(manager,l_codec);
|
||||
return 00;
|
||||
}
|
||||
|
||||
opj_set_default_event_handler(&(l_codec->m_event_mgr));
|
||||
return (opj_codec_t*) l_codec;
|
||||
}
|
||||
|
||||
|
@ -700,8 +720,7 @@ OPJ_BOOL OPJ_CALLCONV opj_setup_encoder(opj_codec_t *p_codec,
|
|||
if (! l_codec->is_decompressor) {
|
||||
return l_codec->m_codec_data.m_compression.opj_setup_encoder( l_codec->m_codec,
|
||||
parameters,
|
||||
p_image,
|
||||
&(l_codec->m_event_mgr) );
|
||||
p_image );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -719,8 +738,7 @@ OPJ_BOOL OPJ_CALLCONV opj_start_compress ( opj_codec_t *p_codec,
|
|||
if (! l_codec->is_decompressor) {
|
||||
return l_codec->m_codec_data.m_compression.opj_start_compress( l_codec->m_codec,
|
||||
l_stream,
|
||||
p_image,
|
||||
&(l_codec->m_event_mgr));
|
||||
p_image);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -735,8 +753,7 @@ OPJ_BOOL OPJ_CALLCONV opj_encode(opj_codec_t *p_info, opj_stream_t *p_stream)
|
|||
|
||||
if (! l_codec->is_decompressor) {
|
||||
return l_codec->m_codec_data.m_compression.opj_encode( l_codec->m_codec,
|
||||
l_stream,
|
||||
&(l_codec->m_event_mgr));
|
||||
l_stream);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -753,8 +770,7 @@ OPJ_BOOL OPJ_CALLCONV opj_end_compress (opj_codec_t *p_codec,
|
|||
|
||||
if (! l_codec->is_decompressor) {
|
||||
return l_codec->m_codec_data.m_compression.opj_end_compress(l_codec->m_codec,
|
||||
l_stream,
|
||||
&(l_codec->m_event_mgr));
|
||||
l_stream);
|
||||
}
|
||||
}
|
||||
return OPJ_FALSE;
|
||||
|
@ -773,8 +789,7 @@ OPJ_BOOL OPJ_CALLCONV opj_end_decompress ( opj_codec_t *p_codec,
|
|||
}
|
||||
|
||||
return l_codec->m_codec_data.m_decompression.opj_end_decompress(l_codec->m_codec,
|
||||
l_stream,
|
||||
&(l_codec->m_event_mgr) );
|
||||
l_stream);
|
||||
}
|
||||
|
||||
return OPJ_FALSE;
|
||||
|
@ -783,27 +798,40 @@ OPJ_BOOL OPJ_CALLCONV opj_end_decompress ( opj_codec_t *p_codec,
|
|||
OPJ_BOOL OPJ_CALLCONV opj_set_MCT(opj_cparameters_t *parameters,
|
||||
OPJ_FLOAT32 * pEncodingMatrix,
|
||||
OPJ_INT32 * p_dc_shift,OPJ_UINT32 pNbComp)
|
||||
{
|
||||
opj_manager_t l_manager = opj_manager_get_global_manager();
|
||||
return opj_manager_set_MCT(l_manager, parameters, pEncodingMatrix, p_dc_shift, pNbComp);
|
||||
}
|
||||
|
||||
OPJ_API OPJ_BOOL OPJ_CALLCONV opj_manager_set_MCT(opj_manager_t manager,
|
||||
opj_cparameters_t *parameters,
|
||||
OPJ_FLOAT32 * pEncodingMatrix,
|
||||
OPJ_INT32 * p_dc_shift,
|
||||
OPJ_UINT32 pNbComp)
|
||||
{
|
||||
OPJ_UINT32 l_matrix_size = pNbComp * pNbComp * (OPJ_UINT32)sizeof(OPJ_FLOAT32);
|
||||
OPJ_UINT32 l_dc_shift_size = pNbComp * (OPJ_UINT32)sizeof(OPJ_INT32);
|
||||
OPJ_UINT32 l_mct_total_size = l_matrix_size + l_dc_shift_size;
|
||||
|
||||
if (manager == NULL) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
/* add MCT capability */
|
||||
if (OPJ_IS_PART2(parameters->rsiz)) {
|
||||
parameters->rsiz |= OPJ_EXTENSION_MCT;
|
||||
} else {
|
||||
parameters->rsiz = ((OPJ_PROFILE_PART2) | (OPJ_EXTENSION_MCT));
|
||||
}
|
||||
if (OPJ_IS_PART2(parameters->rsiz)) {
|
||||
parameters->rsiz |= OPJ_EXTENSION_MCT;
|
||||
} else {
|
||||
parameters->rsiz = ((OPJ_PROFILE_PART2) | (OPJ_EXTENSION_MCT));
|
||||
}
|
||||
parameters->irreversible = 1;
|
||||
|
||||
/* use array based MCT */
|
||||
parameters->tcp_mct = 2;
|
||||
parameters->mct_data = opj_malloc(l_mct_total_size);
|
||||
parameters->mct_data = opj_manager_malloc(manager, l_mct_total_size);
|
||||
if (! parameters->mct_data) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
memcpy(parameters->mct_data,pEncodingMatrix,l_matrix_size);
|
||||
memcpy(parameters->mct_data, pEncodingMatrix, l_matrix_size);
|
||||
memcpy(((OPJ_BYTE *) parameters->mct_data) + l_matrix_size,p_dc_shift,l_dc_shift_size);
|
||||
|
||||
return OPJ_TRUE;
|
||||
|
@ -827,8 +855,7 @@ OPJ_BOOL OPJ_CALLCONV opj_write_tile ( opj_codec_t *p_codec,
|
|||
p_tile_index,
|
||||
p_data,
|
||||
p_data_size,
|
||||
l_stream,
|
||||
&(l_codec->m_event_mgr) );
|
||||
l_stream );
|
||||
}
|
||||
|
||||
return OPJ_FALSE;
|
||||
|
@ -840,6 +867,8 @@ void OPJ_CALLCONV opj_destroy_codec(opj_codec_t *p_codec)
|
|||
{
|
||||
if (p_codec) {
|
||||
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
|
||||
opj_manager_t l_manager = l_codec->manager;
|
||||
OPJ_BOOL l_manager_is_private = l_codec->manager_is_private;
|
||||
|
||||
if (l_codec->is_decompressor) {
|
||||
l_codec->m_codec_data.m_decompression.opj_destroy(l_codec->m_codec);
|
||||
|
@ -849,7 +878,11 @@ void OPJ_CALLCONV opj_destroy_codec(opj_codec_t *p_codec)
|
|||
}
|
||||
|
||||
l_codec->m_codec = 00;
|
||||
opj_free(l_codec);
|
||||
opj_manager_free(l_manager,l_codec);
|
||||
|
||||
if (l_manager_is_private) {
|
||||
opj_manager_destroy(l_manager);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -882,18 +915,28 @@ opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info(opj_codec_t *p_codec)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t **cstr_info) {
|
||||
void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t **cstr_info)
|
||||
{
|
||||
opj_manager_t l_manager = opj_manager_get_global_manager();
|
||||
opj_manager_destroy_cstr_info(l_manager, cstr_info);
|
||||
}
|
||||
|
||||
OPJ_API void OPJ_CALLCONV opj_manager_destroy_cstr_info(opj_manager_t manager, opj_codestream_info_v2_t **cstr_info)
|
||||
{
|
||||
if (manager == NULL) {
|
||||
return;
|
||||
}
|
||||
if (cstr_info) {
|
||||
|
||||
if ((*cstr_info)->m_default_tile_info.tccp_info){
|
||||
opj_free((*cstr_info)->m_default_tile_info.tccp_info);
|
||||
opj_manager_free(manager, (*cstr_info)->m_default_tile_info.tccp_info);
|
||||
}
|
||||
|
||||
if ((*cstr_info)->tile_info){
|
||||
/* FIXME not used for the moment*/
|
||||
}
|
||||
|
||||
opj_free((*cstr_info));
|
||||
opj_manager_free(manager, (*cstr_info));
|
||||
(*cstr_info) = NULL;
|
||||
}
|
||||
}
|
||||
|
@ -911,50 +954,86 @@ opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index(opj_codec_t *p_codec)
|
|||
|
||||
void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index)
|
||||
{
|
||||
opj_manager_t manager = opj_manager_get_global_manager();
|
||||
opj_manager_destroy_cstr_index(manager, p_cstr_index);
|
||||
}
|
||||
OPJ_API void OPJ_CALLCONV opj_manager_destroy_cstr_index(opj_manager_t manager, opj_codestream_index_t **p_cstr_index)
|
||||
{
|
||||
if (manager == NULL) {
|
||||
return;
|
||||
}
|
||||
if (*p_cstr_index){
|
||||
j2k_destroy_cstr_index(*p_cstr_index);
|
||||
j2k_destroy_cstr_index(manager, *p_cstr_index);
|
||||
(*p_cstr_index) = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (const char *fname, OPJ_BOOL p_is_read_stream)
|
||||
{
|
||||
return opj_stream_create_file_stream(fname, OPJ_J2K_STREAM_CHUNK_SIZE, p_is_read_stream);
|
||||
}
|
||||
opj_manager_t l_manager = opj_manager_get_global_manager();
|
||||
|
||||
opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (
|
||||
const char *fname,
|
||||
OPJ_SIZE_T p_size,
|
||||
OPJ_BOOL p_is_read_stream)
|
||||
return opj_manager_stream_create_default_file_stream(l_manager, fname, p_is_read_stream);
|
||||
}
|
||||
OPJ_API opj_stream_t* OPJ_CALLCONV opj_manager_stream_create_default_file_stream (opj_manager_t manager, const char *fname, OPJ_BOOL p_is_read_stream)
|
||||
{
|
||||
opj_stream_t* l_stream = 00;
|
||||
FILE *p_file;
|
||||
const char *mode;
|
||||
|
||||
if (! fname) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(p_is_read_stream) mode = "rb"; else mode = "wb";
|
||||
|
||||
p_file = fopen(fname, mode);
|
||||
|
||||
if (! p_file) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
l_stream = opj_stream_create(p_size,p_is_read_stream);
|
||||
if (! l_stream) {
|
||||
fclose(p_file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
opj_stream_set_user_data(l_stream, p_file, (opj_stream_free_user_data_fn) fclose);
|
||||
opj_stream_set_user_data_length(l_stream, opj_get_data_length_from_file(p_file));
|
||||
opj_stream_set_read_function(l_stream, (opj_stream_read_fn) opj_read_from_file);
|
||||
opj_stream_set_write_function(l_stream, (opj_stream_write_fn) opj_write_from_file);
|
||||
opj_stream_set_skip_function(l_stream, (opj_stream_skip_fn) opj_skip_from_file);
|
||||
opj_stream_set_seek_function(l_stream, (opj_stream_seek_fn) opj_seek_from_file);
|
||||
|
||||
return l_stream;
|
||||
return opj_manager_stream_create_file_stream(manager, fname, OPJ_J2K_STREAM_CHUNK_SIZE, p_is_read_stream);
|
||||
}
|
||||
|
||||
opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream
|
||||
(
|
||||
const char *fname,
|
||||
OPJ_SIZE_T p_size,
|
||||
OPJ_BOOL p_is_read_stream
|
||||
)
|
||||
{
|
||||
opj_manager_t l_manager = opj_manager_get_global_manager();
|
||||
|
||||
return opj_manager_stream_create_file_stream(l_manager, fname, p_size, p_is_read_stream);
|
||||
}
|
||||
|
||||
OPJ_API opj_stream_t* OPJ_CALLCONV opj_manager_stream_create_file_stream
|
||||
(
|
||||
opj_manager_t manager,
|
||||
const char *fname,
|
||||
OPJ_SIZE_T p_buffer_size,
|
||||
OPJ_BOOL p_is_read_stream
|
||||
)
|
||||
{
|
||||
opj_stream_t* l_stream = NULL;
|
||||
FILE *p_file;
|
||||
const char *mode;
|
||||
|
||||
if (manager == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (! fname) {
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "NULL filename");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(p_is_read_stream) mode = "rb"; else mode = "wb";
|
||||
|
||||
p_file = fopen(fname, mode);
|
||||
|
||||
if (! p_file) {
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Can't open file %s.", fname);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
l_stream = opj_manager_stream_create(manager, p_buffer_size, p_is_read_stream);
|
||||
if (! l_stream) {
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Can't create filestream for file %s.", fname);
|
||||
fclose(p_file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
opj_stream_set_user_data(l_stream, p_file, (opj_stream_free_user_data_fn) fclose);
|
||||
opj_stream_set_user_data_length(l_stream, opj_get_data_length_from_file(p_file));
|
||||
opj_stream_set_read_function(l_stream, (opj_stream_read_fn) opj_read_from_file);
|
||||
opj_stream_set_write_function(l_stream, (opj_stream_write_fn) opj_write_from_file);
|
||||
opj_stream_set_skip_function(l_stream, (opj_stream_skip_fn) opj_skip_from_file);
|
||||
opj_stream_set_seek_function(l_stream, (opj_stream_seek_fn) opj_seek_from_file);
|
||||
|
||||
return l_stream;
|
||||
}
|
||||
|
|
|
@ -298,6 +298,78 @@ typedef enum CODEC_FORMAT {
|
|||
OPJ_CODEC_JPX = 4 /**< JPX file format (JPEG 2000 Part-2) : to be coded */
|
||||
} OPJ_CODEC_FORMAT;
|
||||
|
||||
/*
|
||||
==========================================================
|
||||
manager typedef definitions
|
||||
==========================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
* OpenJPEG Manager object handle
|
||||
*
|
||||
* This object is responsible for memory allocations & events.
|
||||
* When no manager is used, events can still be retrieved for an opj_codec_t object using opj_set_info_handler, opj_set_warning_handler and opj_set_error_handler.
|
||||
* The use of a manager & those functions are mutually exclusive.
|
||||
*
|
||||
*/
|
||||
typedef struct opj_manager* opj_manager_t;
|
||||
|
||||
/*
|
||||
==========================================================
|
||||
memory manager typedef definitions
|
||||
==========================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
* Callback function prototype for malloc
|
||||
* @param size Size of the memory block, in bytes.
|
||||
* @param client_data Client object where will be return the event message
|
||||
* @return returns a pointer to the memory block allocated by the function.
|
||||
* */
|
||||
typedef void* (*opj_malloc_callback) (OPJ_SIZE_T size, void *client_data);
|
||||
|
||||
/**
|
||||
* Callback function prototype for calloc
|
||||
* @param num Number of elements to allocate.
|
||||
* @param size Size of an element, in bytes.
|
||||
* @param client_data Client object where will be return the event message
|
||||
* @return returns a pointer to the memory block allocated by the function.
|
||||
* */
|
||||
typedef void* (*opj_calloc_callback) (OPJ_SIZE_T num, OPJ_SIZE_T size, void *client_data);
|
||||
|
||||
/**
|
||||
* Callback function prototype for realloc
|
||||
* @param ptr Pointer to a memory block previously allocated with opj_malloc_callback, opj_calloc_callback or opj_realloc_callback.
|
||||
* @param size New size for the memory block, in bytes.
|
||||
* @param client_data Client object where will be return the event message
|
||||
* @return returns a pointer to the reallocated memory block, which may be either the same as ptr or a new location.
|
||||
* */
|
||||
typedef void* (*opj_realloc_callback) (void* ptr, OPJ_SIZE_T size, void *client_data);
|
||||
|
||||
/**
|
||||
* Callback function prototype for free
|
||||
* @param ptr Pointer to a memory block previously allocated with opj_malloc_callback, opj_calloc_callback or opj_realloc_callback.
|
||||
* @param client_data Client object where will be return the event message
|
||||
* @return returns a pointer to the memory block allocated by the function.
|
||||
* */
|
||||
typedef void (*opj_free_callback) (void* ptr, void *client_data);
|
||||
|
||||
/**
|
||||
* Callback function prototype for aligned_malloc
|
||||
* @param size Size of the memory block, in bytes.
|
||||
* @param alignment The value of alignment shall be a multiple of sizeof( void *), that is also a power of two.
|
||||
* @param client_data Client object where will be return the event message
|
||||
* @return returns a pointer to the memory block allocated by the function.
|
||||
* */
|
||||
typedef void* (*opj_aligned_malloc_callback) (OPJ_SIZE_T size, OPJ_SIZE_T alignment, void *client_data);
|
||||
|
||||
/**
|
||||
* Callback function prototype for aligned_free
|
||||
* @param ptr Pointer to a memory block previously allocated with opj_aligned_malloc_callback.
|
||||
* @param client_data Client object where will be return the event message
|
||||
* @return returns a pointer to the memory block allocated by the function.
|
||||
* */
|
||||
typedef void (*opj_aligned_free_callback) (void* ptr, void *client_data);
|
||||
|
||||
/*
|
||||
==========================================================
|
||||
|
@ -1054,7 +1126,77 @@ extern "C" {
|
|||
/* Get the version of the openjpeg library*/
|
||||
OPJ_API const char * OPJ_CALLCONV opj_version(void);
|
||||
|
||||
/*
|
||||
/*
|
||||
==========================================================
|
||||
manager typedef definitions
|
||||
==========================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates a manager using user provided allocation functions
|
||||
*
|
||||
* @param context callback user context that will be passed back each time an allocation callback is called.
|
||||
* @param malloc_callback malloc callback.
|
||||
* @param calloc_callback calloc callback.
|
||||
* @param realloc_callback realloc callback.
|
||||
* @param free_callback free callback.
|
||||
* @param aligned_malloc_callback aligned malloc callback.
|
||||
* @param aligned_free_callback aligned free callback.
|
||||
* @return returns a new manager object handle if successful, returns NULL otherwise
|
||||
* */
|
||||
OPJ_API opj_manager_t OPJ_CALLCONV opj_manager_create(
|
||||
void* context,
|
||||
opj_malloc_callback malloc_callback,
|
||||
opj_calloc_callback calloc_callback,
|
||||
opj_realloc_callback realloc_callback,
|
||||
opj_free_callback free_callback,
|
||||
opj_aligned_malloc_callback aligned_malloc_callback,
|
||||
opj_aligned_free_callback aligned_free_callback
|
||||
);
|
||||
|
||||
/**
|
||||
* Creates a manager using default allocation functions
|
||||
*
|
||||
* @return returns a new manager object handle if successful, returns NULL otherwise
|
||||
* */
|
||||
OPJ_API opj_manager_t OPJ_CALLCONV opj_manager_create_default(void);
|
||||
|
||||
/**
|
||||
* Deallocates a manager
|
||||
*
|
||||
* @param manager manager to be destroyed
|
||||
* */
|
||||
OPJ_API void OPJ_CALLCONV opj_manager_destroy(opj_manager_t manager);
|
||||
|
||||
/**
|
||||
* Set the info handler use by openjpeg.
|
||||
* @param manager the manager previously initialised
|
||||
* @param p_callback the callback function which will be used
|
||||
* @param p_user_data client object where will be returned the message
|
||||
* */
|
||||
OPJ_API OPJ_BOOL OPJ_CALLCONV opj_manager_set_info_handler(opj_manager_t manager,
|
||||
opj_msg_callback p_callback,
|
||||
void * p_user_data);
|
||||
/**
|
||||
* Set the warning handler use by openjpeg.
|
||||
* @param manager the manager previously initialised
|
||||
* @param p_callback the callback function which will be used
|
||||
* @param p_user_data client object where will be returned the message
|
||||
* */
|
||||
OPJ_API OPJ_BOOL OPJ_CALLCONV opj_manager_set_warning_handler(opj_manager_t manager,
|
||||
opj_msg_callback p_callback,
|
||||
void * p_user_data);
|
||||
/**
|
||||
* Set the error handler use by openjpeg.
|
||||
* @param manager the manager previously initialised
|
||||
* @param p_callback the callback function which will be used
|
||||
* @param p_user_data client object where will be returned the message
|
||||
* */
|
||||
OPJ_API OPJ_BOOL OPJ_CALLCONV opj_manager_set_error_handler(opj_manager_t manager,
|
||||
opj_msg_callback p_callback,
|
||||
void * p_user_data);
|
||||
|
||||
/*
|
||||
==========================================================
|
||||
image functions definitions
|
||||
==========================================================
|
||||
|
@ -1070,6 +1212,17 @@ OPJ_API const char * OPJ_CALLCONV opj_version(void);
|
|||
* */
|
||||
OPJ_API opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
|
||||
|
||||
/**
|
||||
* Creates an image using the specified manager
|
||||
*
|
||||
* @param manager the manager previously initialised
|
||||
* @param numcmpts number of components
|
||||
* @param cmptparms components parameters
|
||||
* @param clrspc image color space
|
||||
* @return returns a new image structure if successful, returns NULL otherwise
|
||||
* */
|
||||
OPJ_API opj_image_t* OPJ_CALLCONV opj_manager_image_create(opj_manager_t manager, OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
|
||||
|
||||
/**
|
||||
* Deallocate any resources associated with an image
|
||||
*
|
||||
|
@ -1077,6 +1230,14 @@ OPJ_API opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_imag
|
|||
*/
|
||||
OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image);
|
||||
|
||||
/**
|
||||
* Deallocate any resources associated with an image
|
||||
*
|
||||
* @param manager the manager previously initialised
|
||||
* @param image image to be destroyed
|
||||
* */
|
||||
OPJ_API void OPJ_CALLCONV opj_manager_image_destroy(opj_manager_t manager, opj_image_t *image);
|
||||
|
||||
/**
|
||||
* Creates an image without allocating memory for the image (used in the new version of the library).
|
||||
*
|
||||
|
@ -1088,6 +1249,18 @@ OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image);
|
|||
*/
|
||||
OPJ_API opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
|
||||
|
||||
/**
|
||||
* Creates an image without allocating memory for the image (used in the new version of the library).
|
||||
*
|
||||
* @param manager the manager previously initialised
|
||||
* @param numcmpts the number of components
|
||||
* @param cmptparms the components parameters
|
||||
* @param clrspc the image color space
|
||||
*
|
||||
* @return a new image structure if successful, NULL otherwise.
|
||||
* */
|
||||
OPJ_API opj_image_t* OPJ_CALLCONV opj_manager_image_tile_create(opj_manager_t manager, OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
|
||||
|
||||
/*
|
||||
==========================================================
|
||||
stream functions definitions
|
||||
|
@ -1103,6 +1276,8 @@ OPJ_API opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj
|
|||
*/
|
||||
OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_default_create(OPJ_BOOL p_is_input);
|
||||
|
||||
OPJ_API opj_stream_t* OPJ_CALLCONV opj_manager_stream_default_create(opj_manager_t manager, OPJ_BOOL p_is_input);
|
||||
|
||||
/**
|
||||
* Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
|
||||
*
|
||||
|
@ -1113,6 +1288,8 @@ OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_default_create(OPJ_BOOL p_is_input
|
|||
*/
|
||||
OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size, OPJ_BOOL p_is_input);
|
||||
|
||||
OPJ_API opj_stream_t* OPJ_CALLCONV opj_manager_stream_create(opj_manager_t manager, OPJ_SIZE_T p_buffer_size, OPJ_BOOL p_is_input);
|
||||
|
||||
/**
|
||||
* Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream. If needed the user must
|
||||
* close its own implementation of the stream.
|
||||
|
@ -1171,6 +1348,7 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream
|
|||
* @param p_is_read_stream whether the stream is a read stream (true) or not (false)
|
||||
*/
|
||||
OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (const char *fname, OPJ_BOOL p_is_read_stream);
|
||||
OPJ_API opj_stream_t* OPJ_CALLCONV opj_manager_stream_create_default_file_stream (opj_manager_t manager, const char *fname, OPJ_BOOL p_is_read_stream);
|
||||
|
||||
/** Create a stream from a file identified with its filename with a specific buffer size
|
||||
* @param fname the filename of the file to stream
|
||||
|
@ -1180,8 +1358,12 @@ OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (const
|
|||
OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (const char *fname,
|
||||
OPJ_SIZE_T p_buffer_size,
|
||||
OPJ_BOOL p_is_read_stream);
|
||||
OPJ_API opj_stream_t* OPJ_CALLCONV opj_manager_stream_create_file_stream (opj_manager_t manager,
|
||||
const char *fname,
|
||||
OPJ_SIZE_T p_buffer_size,
|
||||
OPJ_BOOL p_is_read_stream);
|
||||
|
||||
/*
|
||||
/*
|
||||
==========================================================
|
||||
event manager functions definitions
|
||||
==========================================================
|
||||
|
@ -1227,6 +1409,7 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_error_handler(opj_codec_t * p_codec,
|
|||
* @return Returns a handle to a decompressor if successful, returns NULL otherwise
|
||||
* */
|
||||
OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format);
|
||||
OPJ_API opj_codec_t* OPJ_CALLCONV opj_manager_create_decompress(opj_manager_t manager, OPJ_CODEC_FORMAT format);
|
||||
|
||||
/**
|
||||
* Destroy a decompressor handle
|
||||
|
@ -1243,7 +1426,6 @@ OPJ_API void OPJ_CALLCONV opj_destroy_codec(opj_codec_t * p_codec);
|
|||
OPJ_API OPJ_BOOL OPJ_CALLCONV opj_end_decompress ( opj_codec_t *p_codec,
|
||||
opj_stream_t *p_stream);
|
||||
|
||||
|
||||
/**
|
||||
* Set decoding parameters to default values
|
||||
* @param parameters Decompression parameters
|
||||
|
@ -1402,6 +1584,7 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decode_tile_data( opj_codec_t *p_codec,
|
|||
* @return Returns a handle to a compressor if successful, returns NULL otherwise
|
||||
*/
|
||||
OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
|
||||
OPJ_API opj_codec_t* OPJ_CALLCONV opj_manager_create_compress(opj_manager_t manager, OPJ_CODEC_FORMAT format);
|
||||
|
||||
/**
|
||||
Set encoding parameters to default values, that means :
|
||||
|
@ -1463,6 +1646,7 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_end_compress (opj_codec_t *p_codec,
|
|||
*/
|
||||
OPJ_API OPJ_BOOL OPJ_CALLCONV opj_encode(opj_codec_t *p_codec,
|
||||
opj_stream_t *p_stream);
|
||||
|
||||
/*
|
||||
==========================================================
|
||||
codec output functions definitions
|
||||
|
@ -1475,6 +1659,7 @@ Destroy Codestream information after compression or decompression
|
|||
@param cstr_info Codestream information structure
|
||||
*/
|
||||
OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t **cstr_info);
|
||||
OPJ_API void OPJ_CALLCONV opj_manager_destroy_cstr_info(opj_manager_t manager, opj_codestream_info_v2_t **cstr_info);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -1510,6 +1695,7 @@ OPJ_API opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info(opj_codec_t *p_
|
|||
OPJ_API opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index(opj_codec_t *p_codec);
|
||||
|
||||
OPJ_API void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index);
|
||||
OPJ_API void OPJ_CALLCONV opj_manager_destroy_cstr_index(opj_manager_t manager, opj_codestream_index_t **p_cstr_index);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -1532,7 +1718,6 @@ OPJ_API opj_jp2_metadata_t* OPJ_CALLCONV opj_get_jp2_metadata(opj_codec_t *p_cod
|
|||
*/
|
||||
OPJ_API opj_jp2_index_t* OPJ_CALLCONV opj_get_jp2_index(opj_codec_t *p_codec);
|
||||
|
||||
|
||||
/*
|
||||
==========================================================
|
||||
MCT functions
|
||||
|
@ -1553,6 +1738,11 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_MCT( opj_cparameters_t *parameters,
|
|||
OPJ_FLOAT32 * pEncodingMatrix,
|
||||
OPJ_INT32 * p_dc_shift,
|
||||
OPJ_UINT32 pNbComp);
|
||||
OPJ_API OPJ_BOOL OPJ_CALLCONV opj_manager_set_MCT(opj_manager_t manager,
|
||||
opj_cparameters_t *parameters,
|
||||
OPJ_FLOAT32 * pEncodingMatrix,
|
||||
OPJ_INT32 * p_dc_shift,
|
||||
OPJ_UINT32 pNbComp);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -52,14 +52,12 @@ typedef struct opj_codec_private
|
|||
/** Main header reading function handler */
|
||||
OPJ_BOOL (*opj_read_header) ( struct opj_stream_private * cio,
|
||||
void * p_codec,
|
||||
opj_image_t **p_image,
|
||||
struct opj_event_mgr * p_manager);
|
||||
opj_image_t **p_image);
|
||||
|
||||
/** Decoding function */
|
||||
OPJ_BOOL (*opj_decode) ( void * p_codec,
|
||||
struct opj_stream_private * p_cio,
|
||||
opj_image_t * p_image,
|
||||
struct opj_event_mgr * p_manager);
|
||||
opj_image_t * p_image);
|
||||
|
||||
/** FIXME DOC */
|
||||
OPJ_BOOL (*opj_read_tile_header)( void * p_codec,
|
||||
|
@ -71,21 +69,18 @@ typedef struct opj_codec_private
|
|||
OPJ_INT32 * p_tile_y1,
|
||||
OPJ_UINT32 * p_nb_comps,
|
||||
OPJ_BOOL * p_should_go_on,
|
||||
struct opj_stream_private * p_cio,
|
||||
struct opj_event_mgr * p_manager);
|
||||
struct opj_stream_private * p_cio);
|
||||
|
||||
/** FIXME DOC */
|
||||
OPJ_BOOL (*opj_decode_tile_data)( void * p_codec,
|
||||
OPJ_UINT32 p_tile_index,
|
||||
OPJ_BYTE * p_data,
|
||||
OPJ_UINT32 p_data_size,
|
||||
struct opj_stream_private * p_cio,
|
||||
struct opj_event_mgr * p_manager);
|
||||
struct opj_stream_private * p_cio);
|
||||
|
||||
/** Reading function used after codestream if necessary */
|
||||
OPJ_BOOL (* opj_end_decompress) ( void *p_codec,
|
||||
struct opj_stream_private * cio,
|
||||
struct opj_event_mgr * p_manager);
|
||||
struct opj_stream_private * cio);
|
||||
|
||||
/** Codec destroy function handler */
|
||||
void (*opj_destroy) (void * p_codec);
|
||||
|
@ -99,20 +94,17 @@ typedef struct opj_codec_private
|
|||
OPJ_INT32 p_start_x,
|
||||
OPJ_INT32 p_end_x,
|
||||
OPJ_INT32 p_start_y,
|
||||
OPJ_INT32 p_end_y,
|
||||
struct opj_event_mgr * p_manager);
|
||||
OPJ_INT32 p_end_y);
|
||||
|
||||
/** Get tile function */
|
||||
OPJ_BOOL (*opj_get_decoded_tile) ( void *p_codec,
|
||||
opj_stream_private_t * p_cio,
|
||||
opj_image_t *p_image,
|
||||
struct opj_event_mgr * p_manager,
|
||||
OPJ_UINT32 tile_index);
|
||||
|
||||
/** Set the decoded resolution factor */
|
||||
OPJ_BOOL (*opj_set_decoded_resolution_factor) ( void * p_codec,
|
||||
OPJ_UINT32 res_factor,
|
||||
opj_event_mgr_t * p_manager);
|
||||
OPJ_UINT32 res_factor);
|
||||
} m_decompression;
|
||||
|
||||
/**
|
||||
|
@ -122,36 +114,33 @@ typedef struct opj_codec_private
|
|||
{
|
||||
OPJ_BOOL (* opj_start_compress) ( void *p_codec,
|
||||
struct opj_stream_private * cio,
|
||||
struct opj_image * p_image,
|
||||
struct opj_event_mgr * p_manager);
|
||||
struct opj_image * p_image);
|
||||
|
||||
OPJ_BOOL (* opj_encode) ( void * p_codec,
|
||||
struct opj_stream_private *p_cio,
|
||||
struct opj_event_mgr * p_manager);
|
||||
struct opj_stream_private *p_cio);
|
||||
|
||||
OPJ_BOOL (* opj_write_tile) ( void * p_codec,
|
||||
OPJ_UINT32 p_tile_index,
|
||||
OPJ_BYTE * p_data,
|
||||
OPJ_UINT32 p_data_size,
|
||||
struct opj_stream_private * p_cio,
|
||||
struct opj_event_mgr * p_manager);
|
||||
struct opj_stream_private * p_cio);
|
||||
|
||||
OPJ_BOOL (* opj_end_compress) ( void * p_codec,
|
||||
struct opj_stream_private * p_cio,
|
||||
struct opj_event_mgr * p_manager);
|
||||
struct opj_stream_private * p_cio);
|
||||
|
||||
void (* opj_destroy) (void * p_codec);
|
||||
|
||||
OPJ_BOOL (* opj_setup_encoder) ( void * p_codec,
|
||||
opj_cparameters_t * p_param,
|
||||
struct opj_image * p_image,
|
||||
struct opj_event_mgr * p_manager);
|
||||
struct opj_image * p_image);
|
||||
} m_compression;
|
||||
} m_codec_data;
|
||||
/** FIXME DOC*/
|
||||
void * m_codec;
|
||||
/** Event handler */
|
||||
opj_event_mgr_t m_event_mgr;
|
||||
/** Manager */
|
||||
opj_manager_t manager;
|
||||
/** Flag to indicate if the manager is private or not */
|
||||
OPJ_BOOL manager_is_private;
|
||||
/** Flag to indicate if the codec is used to decode or encode*/
|
||||
OPJ_BOOL is_decompressor;
|
||||
void (*opj_dump_codec) (void * p_codec, OPJ_INT32 info_flag, FILE* output_stream);
|
||||
|
|
|
@ -174,7 +174,7 @@ static INLINE long opj_lrintf(float f) {
|
|||
|
||||
#include "opj_inttypes.h"
|
||||
#include "opj_clock.h"
|
||||
#include "opj_malloc.h"
|
||||
/* #include "opj_malloc.h" */
|
||||
#include "event.h"
|
||||
#include "function_list.h"
|
||||
#include "bio.h"
|
||||
|
@ -211,6 +211,7 @@ static INLINE long opj_lrintf(float f) {
|
|||
|
||||
/* V2 */
|
||||
#include "opj_codec.h"
|
||||
#include "opj_manager.h"
|
||||
|
||||
|
||||
#endif /* OPJ_INCLUDES_H */
|
||||
|
|
|
@ -107,12 +107,12 @@ Allocate memory aligned to a 16 byte boundry
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#define opj_aligned_malloc(size) malloc(size)
|
||||
#define opj_aligned_malloc(size,align) malloc(size)
|
||||
#define opj_aligned_free(m) free(m)
|
||||
|
||||
#ifdef HAVE_MM_MALLOC
|
||||
#undef opj_aligned_malloc
|
||||
#define opj_aligned_malloc(size) _mm_malloc(size, 16)
|
||||
#define opj_aligned_malloc(size,align) _mm_malloc((size), (align))
|
||||
#undef opj_aligned_free
|
||||
#define opj_aligned_free(m) _mm_free(m)
|
||||
#endif
|
||||
|
@ -120,7 +120,7 @@ Allocate memory aligned to a 16 byte boundry
|
|||
#ifdef HAVE_MEMALIGN
|
||||
extern void* memalign(size_t, size_t);
|
||||
#undef opj_aligned_malloc
|
||||
#define opj_aligned_malloc(size) memalign(16, (size))
|
||||
#define opj_aligned_malloc(size, align) memalign((align), (size))
|
||||
#undef opj_aligned_free
|
||||
#define opj_aligned_free(m) free(m)
|
||||
#endif
|
||||
|
@ -129,9 +129,9 @@ Allocate memory aligned to a 16 byte boundry
|
|||
#undef opj_aligned_malloc
|
||||
extern int posix_memalign(void**, size_t, size_t);
|
||||
|
||||
static INLINE void* __attribute__ ((malloc)) opj_aligned_malloc(size_t size){
|
||||
static INLINE void* __attribute__ ((malloc)) opj_aligned_malloc(size_t size, size_t align){
|
||||
void* mem = NULL;
|
||||
posix_memalign(&mem, 16, size);
|
||||
posix_memalign(&mem, align, size);
|
||||
return mem;
|
||||
}
|
||||
#undef opj_aligned_free
|
||||
|
@ -140,7 +140,7 @@ Allocate memory aligned to a 16 byte boundry
|
|||
|
||||
#ifdef ALLOC_PERF_OPT
|
||||
#undef opj_aligned_malloc
|
||||
#define opj_aligned_malloc(size) opj_malloc(size)
|
||||
#define opj_aligned_malloc(size, align) opj_malloc(size)
|
||||
#undef opj_aligned_free
|
||||
#define opj_aligned_free(m) opj_free(m)
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,252 @@
|
|||
/*
|
||||
* The copyright in this software is being made available under the 2-clauses
|
||||
* BSD License, included below. This software may be subject to other third
|
||||
* party and contributor rights, including patent rights, and no such rights
|
||||
* are granted under this license.
|
||||
*
|
||||
* Copyright (c) 2014, Matthieu Darbois
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "opj_includes.h"
|
||||
#include "opj_malloc.h"
|
||||
|
||||
/**
|
||||
* Default malloc function
|
||||
* @param size Size of the memory block, in bytes.
|
||||
* @param client_data Client object where will be return the event message
|
||||
* @return returns a pointer to the memory block allocated by the function.
|
||||
* */
|
||||
static void* opj_default_malloc(OPJ_SIZE_T size, void *client_data);
|
||||
|
||||
/**
|
||||
* Default calloc function
|
||||
* @param num Number of elements to allocate.
|
||||
* @param size Size of an element, in bytes.
|
||||
* @param client_data Client object where will be return the event message
|
||||
* @return returns a pointer to the memory block allocated by the function.
|
||||
* */
|
||||
static void* opj_default_calloc(OPJ_SIZE_T num, OPJ_SIZE_T size, void *client_data);
|
||||
|
||||
/**
|
||||
* Default realloc function
|
||||
* @param ptr Pointer to a memory block previously allocated with opj_malloc_callback, opj_calloc_callback or opj_realloc_callback.
|
||||
* @param size New size for the memory block, in bytes.
|
||||
* @param client_data Client object where will be return the event message
|
||||
* @return returns a pointer to the reallocated memory block, which may be either the same as ptr or a new location.
|
||||
* */
|
||||
static void* opj_default_realloc(void* ptr, OPJ_SIZE_T size, void *client_data);
|
||||
|
||||
/**
|
||||
* Default free function
|
||||
* @param ptr Pointer to a memory block previously allocated with opj_malloc_callback, opj_calloc_callback or opj_realloc_callback.
|
||||
* @param client_data Client object where will be return the event message
|
||||
* @return returns a pointer to the memory block allocated by the function.
|
||||
* */
|
||||
static void opj_default_free(void* ptr, void *client_data);
|
||||
|
||||
/**
|
||||
* Default aligned_malloc function
|
||||
* @param size Size of the memory block, in bytes.
|
||||
* @param alignment The value of alignment shall be a multiple of sizeof( void *), that is also a power of two.
|
||||
* @param client_data Client object where will be return the event message
|
||||
* @return returns a pointer to the memory block allocated by the function.
|
||||
* */
|
||||
static void* opj_default_aligned_malloc(OPJ_SIZE_T size, OPJ_SIZE_T alignment, void *client_data);
|
||||
|
||||
/**
|
||||
* Default aligned_free function
|
||||
* @param ptr Pointer to a memory block previously allocated with opj_aligned_malloc_callback.
|
||||
* @param client_data Client object where will be return the event message
|
||||
* @return returns a pointer to the memory block allocated by the function.
|
||||
* */
|
||||
static void opj_default_aligned_free(void* ptr, void *client_data);
|
||||
|
||||
/**
|
||||
* Default manager that can be used when no manager is available.
|
||||
*
|
||||
* */
|
||||
static const struct opj_manager opj_global_manager =
|
||||
{
|
||||
NULL,
|
||||
opj_default_malloc,
|
||||
opj_default_calloc,
|
||||
opj_default_realloc,
|
||||
opj_default_free,
|
||||
opj_default_aligned_malloc,
|
||||
opj_default_aligned_free,
|
||||
{
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
OPJ_API opj_manager_t OPJ_CALLCONV opj_manager_create(
|
||||
void* context,
|
||||
opj_malloc_callback malloc_callback,
|
||||
opj_calloc_callback calloc_callback,
|
||||
opj_realloc_callback realloc_callback,
|
||||
opj_free_callback free_callback,
|
||||
opj_aligned_malloc_callback aligned_malloc_callback,
|
||||
opj_aligned_free_callback aligned_free_callback
|
||||
)
|
||||
{
|
||||
opj_manager_t l_manager = NULL;
|
||||
|
||||
/* Check parameters */
|
||||
if (
|
||||
(malloc_callback == NULL) ||
|
||||
(calloc_callback == NULL) ||
|
||||
(realloc_callback == NULL) ||
|
||||
(free_callback == NULL) ||
|
||||
(aligned_malloc_callback == NULL) ||
|
||||
(aligned_free_callback == NULL)
|
||||
) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
l_manager = malloc_callback(sizeof(struct opj_manager), context);
|
||||
if (l_manager == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
l_manager->context = context;
|
||||
l_manager->malloc_callback = malloc_callback;
|
||||
l_manager->calloc_callback = calloc_callback;
|
||||
l_manager->realloc_callback = realloc_callback;
|
||||
l_manager->free_callback = free_callback;
|
||||
l_manager->aligned_malloc_callback = aligned_malloc_callback;
|
||||
l_manager->aligned_free_callback = aligned_free_callback;
|
||||
|
||||
/* NULL message handler are valid (& more efficient than default handler from opj_set_default_event_handler) */
|
||||
memset(&(l_manager->event_mgr), 0, sizeof(opj_event_mgr_t));
|
||||
|
||||
return l_manager;
|
||||
}
|
||||
|
||||
|
||||
OPJ_API opj_manager_t OPJ_CALLCONV opj_manager_create_default(void)
|
||||
{
|
||||
return opj_manager_create(
|
||||
NULL,
|
||||
opj_default_malloc,
|
||||
opj_default_calloc,
|
||||
opj_default_realloc,
|
||||
opj_default_free,
|
||||
opj_default_aligned_malloc,
|
||||
opj_default_aligned_free
|
||||
);
|
||||
}
|
||||
|
||||
OPJ_API void OPJ_CALLCONV opj_manager_destroy(opj_manager_t manager)
|
||||
{
|
||||
opj_free_callback l_callback = NULL;
|
||||
void* l_context = NULL;
|
||||
if (manager != NULL) {
|
||||
l_callback = manager->free_callback;
|
||||
l_context = manager->context;
|
||||
memset(manager, 0, sizeof(struct opj_manager));
|
||||
l_callback(manager, l_context);
|
||||
}
|
||||
}
|
||||
|
||||
OPJ_API OPJ_BOOL OPJ_CALLCONV opj_manager_set_info_handler(opj_manager_t manager,
|
||||
opj_msg_callback p_callback,
|
||||
void * p_user_data)
|
||||
{
|
||||
if(manager == NULL){
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
manager->event_mgr.info_handler = p_callback;
|
||||
manager->event_mgr.m_info_data = p_user_data;
|
||||
return OPJ_TRUE;
|
||||
}
|
||||
|
||||
OPJ_API OPJ_BOOL OPJ_CALLCONV opj_manager_set_warning_handler(opj_manager_t manager,
|
||||
opj_msg_callback p_callback,
|
||||
void * p_user_data)
|
||||
{
|
||||
if(manager == NULL){
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
manager->event_mgr.warning_handler = p_callback;
|
||||
manager->event_mgr.m_warning_data = p_user_data;
|
||||
return OPJ_TRUE;
|
||||
}
|
||||
|
||||
OPJ_API OPJ_BOOL OPJ_CALLCONV opj_manager_set_error_handler(opj_manager_t manager,
|
||||
opj_msg_callback p_callback,
|
||||
void * p_user_data)
|
||||
{
|
||||
if(manager == NULL){
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
manager->event_mgr.error_handler = p_callback;
|
||||
manager->event_mgr.m_error_data = p_user_data;
|
||||
return OPJ_TRUE;
|
||||
}
|
||||
|
||||
opj_manager_t opj_manager_get_global_manager(void)
|
||||
{
|
||||
return (opj_manager_t)&opj_global_manager; /* const is dropped */
|
||||
}
|
||||
|
||||
static void* opj_default_malloc(OPJ_SIZE_T size, void *client_data)
|
||||
{
|
||||
OPJ_ARG_NOT_USED(client_data);
|
||||
return opj_malloc(size);
|
||||
}
|
||||
static void* opj_default_calloc(OPJ_SIZE_T num, OPJ_SIZE_T size, void *client_data)
|
||||
{
|
||||
OPJ_ARG_NOT_USED(client_data);
|
||||
return opj_calloc(num, size);
|
||||
}
|
||||
static void* opj_default_realloc(void* ptr, OPJ_SIZE_T size, void *client_data)
|
||||
{
|
||||
OPJ_ARG_NOT_USED(client_data);
|
||||
return opj_realloc(ptr, size);
|
||||
}
|
||||
static void opj_default_free(void* ptr, void *client_data)
|
||||
{
|
||||
OPJ_ARG_NOT_USED(client_data);
|
||||
opj_free(ptr);
|
||||
}
|
||||
static void* opj_default_aligned_malloc(OPJ_SIZE_T size, OPJ_SIZE_T alignment, void *client_data)
|
||||
{
|
||||
OPJ_ARG_NOT_USED(client_data);
|
||||
return opj_aligned_malloc(size, alignment);
|
||||
}
|
||||
static void opj_default_aligned_free(void* ptr, void *client_data)
|
||||
{
|
||||
OPJ_ARG_NOT_USED(client_data);
|
||||
opj_aligned_free(ptr);
|
||||
}
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* The copyright in this software is being made available under the 2-clauses
|
||||
* BSD License, included below. This software may be subject to other third
|
||||
* party and contributor rights, including patent rights, and no such rights
|
||||
* are granted under this license.
|
||||
*
|
||||
* Copyright (c) 2014, Matthieu Darbois
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef __OPJ_MANAGER_H
|
||||
#define __OPJ_MANAGER_H
|
||||
/**
|
||||
@file opj_manager.h
|
||||
*/
|
||||
|
||||
/**
|
||||
* OpenJPEG Manager opaque structure
|
||||
*
|
||||
* This object is responsible for memory allocations & events.
|
||||
* When no manager is used, events can still be retrieved for an opj_codec_t object using opj_set_info_handler, opj_set_warning_handler and opj_set_error_handler.
|
||||
* The use of a manager & those functions are mutually exclusive.
|
||||
*
|
||||
*/
|
||||
struct opj_manager
|
||||
{
|
||||
/** callback user context that will be passed back each time an allocation callback is called. */
|
||||
void* context;
|
||||
|
||||
/** malloc callback. */
|
||||
opj_malloc_callback malloc_callback;
|
||||
|
||||
/** calloc callback. */
|
||||
opj_calloc_callback calloc_callback;
|
||||
|
||||
/** realloc callback. */
|
||||
opj_realloc_callback realloc_callback;
|
||||
|
||||
/** free callback. */
|
||||
opj_free_callback free_callback;
|
||||
|
||||
/** aligned malloc callback. */
|
||||
opj_aligned_malloc_callback aligned_malloc_callback;
|
||||
|
||||
/** aligned free callback. */
|
||||
opj_aligned_free_callback aligned_free_callback;
|
||||
|
||||
/** event manager. */
|
||||
opj_event_mgr_t event_mgr;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the global manager.
|
||||
*
|
||||
* @return Global manager
|
||||
*/
|
||||
opj_manager_t opj_manager_get_global_manager(void);
|
||||
|
||||
|
||||
static INLINE void* opj_manager_malloc(opj_manager_t manager, OPJ_SIZE_T size)
|
||||
{
|
||||
return manager->malloc_callback(size, manager->context);
|
||||
}
|
||||
static INLINE void* opj_manager_calloc(opj_manager_t manager, OPJ_SIZE_T num, OPJ_SIZE_T size)
|
||||
{
|
||||
return manager->calloc_callback(num, size, manager->context);
|
||||
}
|
||||
static INLINE void* opj_manager_realloc(opj_manager_t manager, void* ptr, OPJ_SIZE_T size)
|
||||
{
|
||||
return manager->realloc_callback(ptr, size, manager->context);
|
||||
}
|
||||
static INLINE void opj_manager_free(opj_manager_t manager, void* ptr)
|
||||
{
|
||||
return manager->free_callback(ptr, manager->context);
|
||||
}
|
||||
static INLINE void* opj_manager_aligned_malloc(opj_manager_t manager, OPJ_SIZE_T size, OPJ_SIZE_T alignment)
|
||||
{
|
||||
return manager->aligned_malloc_callback(size, alignment, manager->context);
|
||||
}
|
||||
static INLINE void opj_manager_aligned_free(opj_manager_t manager, void* ptr)
|
||||
{
|
||||
return manager->aligned_free_callback(ptr, manager->context);
|
||||
}
|
||||
|
||||
#endif /* __OPJ_MANAGER_H */
|
||||
|
|
@ -193,7 +193,8 @@ static void opj_get_all_encoding_parameters(const opj_image_t *p_image,
|
|||
* @param p_cp the coding parameters.
|
||||
* @param tileno the index of the tile from which creating the packet iterator.
|
||||
*/
|
||||
static opj_pi_iterator_t * opj_pi_create( const opj_image_t *p_image,
|
||||
static opj_pi_iterator_t * opj_pi_create( opj_manager_t manager,
|
||||
const opj_image_t *p_image,
|
||||
const opj_cp_t *p_cp,
|
||||
OPJ_UINT32 tileno );
|
||||
/**
|
||||
|
@ -789,7 +790,8 @@ static void opj_get_all_encoding_parameters( const opj_image_t *p_image,
|
|||
}
|
||||
}
|
||||
|
||||
static opj_pi_iterator_t * opj_pi_create( const opj_image_t *image,
|
||||
static opj_pi_iterator_t * opj_pi_create( opj_manager_t manager,
|
||||
const opj_image_t *image,
|
||||
const opj_cp_t *cp,
|
||||
OPJ_UINT32 tileno )
|
||||
{
|
||||
|
@ -816,7 +818,7 @@ static opj_pi_iterator_t * opj_pi_create( const opj_image_t *image,
|
|||
l_poc_bound = tcp->numpocs+1;
|
||||
|
||||
/* memory allocations*/
|
||||
l_pi = (opj_pi_iterator_t*) opj_calloc((l_poc_bound), sizeof(opj_pi_iterator_t));
|
||||
l_pi = (opj_pi_iterator_t*) opj_manager_calloc(manager, (l_poc_bound), sizeof(opj_pi_iterator_t));
|
||||
if (!l_pi) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -824,9 +826,9 @@ static opj_pi_iterator_t * opj_pi_create( const opj_image_t *image,
|
|||
l_current_pi = l_pi;
|
||||
for (pino = 0; pino < l_poc_bound ; ++pino) {
|
||||
|
||||
l_current_pi->comps = (opj_pi_comp_t*) opj_calloc(image->numcomps, sizeof(opj_pi_comp_t));
|
||||
l_current_pi->comps = (opj_pi_comp_t*) opj_manager_calloc(manager, image->numcomps, sizeof(opj_pi_comp_t));
|
||||
if (! l_current_pi->comps) {
|
||||
opj_pi_destroy(l_pi, l_poc_bound);
|
||||
opj_pi_destroy(manager, l_pi, l_poc_bound);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -837,9 +839,9 @@ static opj_pi_iterator_t * opj_pi_create( const opj_image_t *image,
|
|||
|
||||
tccp = &tcp->tccps[compno];
|
||||
|
||||
comp->resolutions = (opj_pi_resolution_t*) opj_calloc(tccp->numresolutions, sizeof(opj_pi_resolution_t));
|
||||
comp->resolutions = (opj_pi_resolution_t*) opj_manager_calloc(manager, tccp->numresolutions, sizeof(opj_pi_resolution_t));
|
||||
if (!comp->resolutions) {
|
||||
opj_pi_destroy(l_pi, l_poc_bound);
|
||||
opj_pi_destroy(manager, l_pi, l_poc_bound);
|
||||
return 00;
|
||||
}
|
||||
|
||||
|
@ -1151,7 +1153,7 @@ static OPJ_BOOL opj_pi_check_next_level( OPJ_INT32 pos,
|
|||
Packet iterator interface
|
||||
==========================================================
|
||||
*/
|
||||
opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
|
||||
opj_pi_iterator_t *opj_pi_create_decode(opj_manager_t manager, opj_image_t *p_image,
|
||||
opj_cp_t *p_cp,
|
||||
OPJ_UINT32 p_tile_no)
|
||||
{
|
||||
|
@ -1191,27 +1193,27 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
|
|||
l_bound = l_tcp->numpocs+1;
|
||||
|
||||
l_data_stride = 4 * OPJ_J2K_MAXRLVLS;
|
||||
l_tmp_data = (OPJ_UINT32*)opj_malloc(
|
||||
l_tmp_data = (OPJ_UINT32*)opj_manager_malloc(manager,
|
||||
l_data_stride * p_image->numcomps * sizeof(OPJ_UINT32));
|
||||
if
|
||||
(! l_tmp_data)
|
||||
{
|
||||
return 00;
|
||||
}
|
||||
l_tmp_ptr = (OPJ_UINT32**)opj_malloc(
|
||||
l_tmp_ptr = (OPJ_UINT32**)opj_manager_malloc(manager,
|
||||
p_image->numcomps * sizeof(OPJ_UINT32 *));
|
||||
if
|
||||
(! l_tmp_ptr)
|
||||
{
|
||||
opj_free(l_tmp_data);
|
||||
opj_manager_free(manager, l_tmp_data);
|
||||
return 00;
|
||||
}
|
||||
|
||||
/* memory allocation for pi */
|
||||
l_pi = opj_pi_create(p_image, p_cp, p_tile_no);
|
||||
l_pi = opj_pi_create(manager, p_image, p_cp, p_tile_no);
|
||||
if (!l_pi) {
|
||||
opj_free(l_tmp_data);
|
||||
opj_free(l_tmp_ptr);
|
||||
opj_manager_free(manager, l_tmp_data);
|
||||
opj_manager_free(manager, l_tmp_ptr);
|
||||
return 00;
|
||||
}
|
||||
|
||||
|
@ -1236,13 +1238,13 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
|
|||
l_current_pi = l_pi;
|
||||
|
||||
/* memory allocation for include */
|
||||
l_current_pi->include = (OPJ_INT16*) opj_calloc((l_tcp->numlayers +1) * l_step_l, sizeof(OPJ_INT16));
|
||||
l_current_pi->include = (OPJ_INT16*) opj_manager_calloc(manager, (l_tcp->numlayers +1) * l_step_l, sizeof(OPJ_INT16));
|
||||
if
|
||||
(!l_current_pi->include)
|
||||
{
|
||||
opj_free(l_tmp_data);
|
||||
opj_free(l_tmp_ptr);
|
||||
opj_pi_destroy(l_pi, l_bound);
|
||||
opj_manager_free(manager, l_tmp_data);
|
||||
opj_manager_free(manager, l_tmp_ptr);
|
||||
opj_pi_destroy(manager, l_pi, l_bound);
|
||||
return 00;
|
||||
}
|
||||
|
||||
|
@ -1333,9 +1335,9 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
|
|||
l_current_pi->include = (l_current_pi-1)->include;
|
||||
++l_current_pi;
|
||||
}
|
||||
opj_free(l_tmp_data);
|
||||
opj_manager_free(manager, l_tmp_data);
|
||||
l_tmp_data = 00;
|
||||
opj_free(l_tmp_ptr);
|
||||
opj_manager_free(manager, l_tmp_ptr);
|
||||
l_tmp_ptr = 00;
|
||||
if
|
||||
(l_tcp->POC)
|
||||
|
@ -1351,7 +1353,7 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
|
|||
|
||||
|
||||
|
||||
opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image,
|
||||
opj_pi_iterator_t *opj_pi_initialise_encode(opj_manager_t manager, const opj_image_t *p_image,
|
||||
opj_cp_t *p_cp,
|
||||
OPJ_UINT32 p_tile_no,
|
||||
J2K_T2_MODE p_t2_mode )
|
||||
|
@ -1392,24 +1394,24 @@ opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image,
|
|||
l_bound = l_tcp->numpocs+1;
|
||||
|
||||
l_data_stride = 4 * OPJ_J2K_MAXRLVLS;
|
||||
l_tmp_data = (OPJ_UINT32*)opj_malloc(
|
||||
l_tmp_data = (OPJ_UINT32*)opj_manager_malloc(manager,
|
||||
l_data_stride * p_image->numcomps * sizeof(OPJ_UINT32));
|
||||
if (! l_tmp_data) {
|
||||
return 00;
|
||||
}
|
||||
|
||||
l_tmp_ptr = (OPJ_UINT32**)opj_malloc(
|
||||
l_tmp_ptr = (OPJ_UINT32**)opj_manager_malloc(manager,
|
||||
p_image->numcomps * sizeof(OPJ_UINT32 *));
|
||||
if (! l_tmp_ptr) {
|
||||
opj_free(l_tmp_data);
|
||||
opj_manager_free(manager, l_tmp_data);
|
||||
return 00;
|
||||
}
|
||||
|
||||
/* memory allocation for pi*/
|
||||
l_pi = opj_pi_create(p_image,p_cp,p_tile_no);
|
||||
l_pi = opj_pi_create(manager, p_image,p_cp,p_tile_no);
|
||||
if (!l_pi) {
|
||||
opj_free(l_tmp_data);
|
||||
opj_free(l_tmp_ptr);
|
||||
opj_manager_free(manager, l_tmp_data);
|
||||
opj_manager_free(manager, l_tmp_ptr);
|
||||
return 00;
|
||||
}
|
||||
|
||||
|
@ -1434,11 +1436,11 @@ opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image,
|
|||
l_current_pi = l_pi;
|
||||
|
||||
/* memory allocation for include*/
|
||||
l_current_pi->include = (OPJ_INT16*) opj_calloc(l_tcp->numlayers * l_step_l, sizeof(OPJ_INT16));
|
||||
l_current_pi->include = (OPJ_INT16*) opj_manager_calloc(manager, l_tcp->numlayers * l_step_l, sizeof(OPJ_INT16));
|
||||
if (!l_current_pi->include) {
|
||||
opj_free(l_tmp_data);
|
||||
opj_free(l_tmp_ptr);
|
||||
opj_pi_destroy(l_pi, l_bound);
|
||||
opj_manager_free(manager, l_tmp_data);
|
||||
opj_manager_free(manager, l_tmp_ptr);
|
||||
opj_pi_destroy(manager, l_pi, l_bound);
|
||||
return 00;
|
||||
}
|
||||
|
||||
|
@ -1521,9 +1523,9 @@ opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image,
|
|||
++l_current_pi;
|
||||
}
|
||||
|
||||
opj_free(l_tmp_data);
|
||||
opj_manager_free(manager, l_tmp_data);
|
||||
l_tmp_data = 00;
|
||||
opj_free(l_tmp_ptr);
|
||||
opj_manager_free(manager, l_tmp_ptr);
|
||||
l_tmp_ptr = 00;
|
||||
|
||||
if (l_tcp->POC && (OPJ_IS_CINEMA(p_cp->rsiz) || p_t2_mode == FINAL_PASS)) {
|
||||
|
@ -1794,14 +1796,14 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi,
|
|||
}
|
||||
}
|
||||
|
||||
void opj_pi_destroy(opj_pi_iterator_t *p_pi,
|
||||
void opj_pi_destroy(opj_manager_t manager, opj_pi_iterator_t *p_pi,
|
||||
OPJ_UINT32 p_nb_elements)
|
||||
{
|
||||
OPJ_UINT32 compno, pino;
|
||||
opj_pi_iterator_t *l_current_pi = p_pi;
|
||||
if (p_pi) {
|
||||
if (p_pi->include) {
|
||||
opj_free(p_pi->include);
|
||||
opj_manager_free(manager, p_pi->include);
|
||||
p_pi->include = 00;
|
||||
}
|
||||
for (pino = 0; pino < p_nb_elements; ++pino){
|
||||
|
@ -1809,18 +1811,18 @@ void opj_pi_destroy(opj_pi_iterator_t *p_pi,
|
|||
opj_pi_comp_t *l_current_component = l_current_pi->comps;
|
||||
for (compno = 0; compno < l_current_pi->numcomps; compno++){
|
||||
if(l_current_component->resolutions) {
|
||||
opj_free(l_current_component->resolutions);
|
||||
opj_manager_free(manager, l_current_component->resolutions);
|
||||
l_current_component->resolutions = 00;
|
||||
}
|
||||
|
||||
++l_current_component;
|
||||
}
|
||||
opj_free(l_current_pi->comps);
|
||||
opj_manager_free(manager, l_current_pi->comps);
|
||||
l_current_pi->comps = 0;
|
||||
}
|
||||
++l_current_pi;
|
||||
}
|
||||
opj_free(p_pi);
|
||||
opj_manager_free(manager, p_pi);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ typedef struct opj_pi_iterator {
|
|||
*
|
||||
* @return a list of packet iterator that points to the first packet of the tile (not true).
|
||||
*/
|
||||
opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *image,
|
||||
opj_pi_iterator_t *opj_pi_initialise_encode(opj_manager_t manager, const opj_image_t *image,
|
||||
opj_cp_t *cp,
|
||||
OPJ_UINT32 tileno,
|
||||
J2K_T2_MODE t2_mode);
|
||||
|
@ -162,7 +162,7 @@ Create a packet iterator for Decoder
|
|||
@return Returns a packet iterator that points to the first packet of the tile
|
||||
@see opj_pi_destroy
|
||||
*/
|
||||
opj_pi_iterator_t *opj_pi_create_decode(opj_image_t * image,
|
||||
opj_pi_iterator_t *opj_pi_create_decode(opj_manager_t manager, opj_image_t * image,
|
||||
opj_cp_t * cp,
|
||||
OPJ_UINT32 tileno);
|
||||
/**
|
||||
|
@ -171,7 +171,7 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t * image,
|
|||
* @param p_pi the packet iterator array to destroy.
|
||||
* @param p_nb_elements the number of elements in the array.
|
||||
*/
|
||||
void opj_pi_destroy(opj_pi_iterator_t *p_pi,
|
||||
void opj_pi_destroy(opj_manager_t manager, opj_pi_iterator_t *p_pi,
|
||||
OPJ_UINT32 p_nb_elements);
|
||||
|
||||
/**
|
||||
|
|
|
@ -48,14 +48,14 @@
|
|||
==========================================================
|
||||
*/
|
||||
|
||||
opj_raw_t* opj_raw_create(void) {
|
||||
opj_raw_t *raw = (opj_raw_t*)opj_malloc(sizeof(opj_raw_t));
|
||||
opj_raw_t* opj_raw_create(opj_manager_t manager) {
|
||||
opj_raw_t *raw = (opj_raw_t*)opj_manager_malloc(manager, sizeof(opj_raw_t));
|
||||
return raw;
|
||||
}
|
||||
|
||||
void opj_raw_destroy(opj_raw_t *raw) {
|
||||
void opj_raw_destroy(opj_manager_t manager, opj_raw_t *raw) {
|
||||
if(raw) {
|
||||
opj_free(raw);
|
||||
opj_manager_free(manager, raw);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,12 +73,12 @@ typedef struct opj_raw {
|
|||
Create a new RAW handle
|
||||
@return Returns a new RAW handle if successful, returns NULL otherwise
|
||||
*/
|
||||
opj_raw_t* opj_raw_create(void);
|
||||
opj_raw_t* opj_raw_create(opj_manager_t manager);
|
||||
/**
|
||||
Destroy a previously created RAW handle
|
||||
@param raw RAW handle to destroy
|
||||
*/
|
||||
void opj_raw_destroy(opj_raw_t *raw);
|
||||
void opj_raw_destroy(opj_manager_t manager, opj_raw_t *raw);
|
||||
/**
|
||||
Return the number of bytes written/read since initialisation
|
||||
@param raw RAW handle to destroy
|
||||
|
|
|
@ -1172,8 +1172,8 @@ static OPJ_BOOL opj_t1_allocate_buffers(
|
|||
/* encoder uses tile buffer, so no need to allocate */
|
||||
if (!t1->encoder) {
|
||||
if(datasize > t1->datasize){
|
||||
opj_aligned_free(t1->data);
|
||||
t1->data = (OPJ_INT32*) opj_aligned_malloc(datasize * sizeof(OPJ_INT32));
|
||||
opj_manager_aligned_free(t1->manager, t1->data);
|
||||
t1->data = (OPJ_INT32*) opj_manager_aligned_malloc(t1->manager, datasize * sizeof(OPJ_INT32), 16);
|
||||
if(!t1->data){
|
||||
/* FIXME event manager error callback */
|
||||
return OPJ_FALSE;
|
||||
|
@ -1186,8 +1186,8 @@ static OPJ_BOOL opj_t1_allocate_buffers(
|
|||
flagssize=t1->flags_stride * (h+2);
|
||||
|
||||
if(flagssize > t1->flagssize){
|
||||
opj_aligned_free(t1->flags);
|
||||
t1->flags = (opj_flag_t*) opj_aligned_malloc(flagssize * sizeof(opj_flag_t));
|
||||
opj_manager_aligned_free(t1->manager, t1->flags);
|
||||
t1->flags = (opj_flag_t*) opj_manager_aligned_malloc(t1->manager, flagssize * sizeof(opj_flag_t), 16);
|
||||
if(!t1->flags){
|
||||
/* FIXME event manager error callback */
|
||||
return OPJ_FALSE;
|
||||
|
@ -1210,23 +1210,24 @@ static OPJ_BOOL opj_t1_allocate_buffers(
|
|||
* and initializes the look-up tables of the Tier-1 coder/decoder
|
||||
* @return a new T1 handle if successful, returns NULL otherwise
|
||||
*/
|
||||
opj_t1_t* opj_t1_create(OPJ_BOOL isEncoder)
|
||||
opj_t1_t* opj_t1_create(opj_manager_t manager, OPJ_BOOL isEncoder)
|
||||
{
|
||||
opj_t1_t *l_t1 = 00;
|
||||
|
||||
l_t1 = (opj_t1_t*) opj_calloc(1,sizeof(opj_t1_t));
|
||||
l_t1 = (opj_t1_t*) opj_manager_calloc(manager, 1, sizeof(opj_t1_t));
|
||||
if (!l_t1) {
|
||||
return 00;
|
||||
}
|
||||
l_t1->manager = manager;
|
||||
|
||||
/* create MQC and RAW handles */
|
||||
l_t1->mqc = opj_mqc_create();
|
||||
l_t1->mqc = opj_mqc_create(manager);
|
||||
if (! l_t1->mqc) {
|
||||
opj_t1_destroy(l_t1);
|
||||
return 00;
|
||||
}
|
||||
|
||||
l_t1->raw = opj_raw_create();
|
||||
l_t1->raw = opj_raw_create(manager);
|
||||
if (! l_t1->raw) {
|
||||
opj_t1_destroy(l_t1);
|
||||
return 00;
|
||||
|
@ -1244,28 +1245,29 @@ opj_t1_t* opj_t1_create(OPJ_BOOL isEncoder)
|
|||
*/
|
||||
void opj_t1_destroy(opj_t1_t *p_t1)
|
||||
{
|
||||
opj_manager_t manager;
|
||||
if (! p_t1) {
|
||||
return;
|
||||
}
|
||||
|
||||
manager = p_t1->manager;
|
||||
/* destroy MQC and RAW handles */
|
||||
opj_mqc_destroy(p_t1->mqc);
|
||||
opj_mqc_destroy(manager, p_t1->mqc);
|
||||
p_t1->mqc = 00;
|
||||
opj_raw_destroy(p_t1->raw);
|
||||
opj_raw_destroy(manager, p_t1->raw);
|
||||
p_t1->raw = 00;
|
||||
|
||||
/* encoder uses tile buffer, so no need to free */
|
||||
if (!p_t1->encoder && p_t1->data) {
|
||||
opj_aligned_free(p_t1->data);
|
||||
opj_manager_aligned_free(manager, p_t1->data);
|
||||
p_t1->data = 00;
|
||||
}
|
||||
|
||||
if (p_t1->flags) {
|
||||
opj_aligned_free(p_t1->flags);
|
||||
opj_manager_aligned_free(manager, p_t1->flags);
|
||||
p_t1->flags = 00;
|
||||
}
|
||||
|
||||
opj_free(p_t1);
|
||||
opj_manager_free(manager, p_t1);
|
||||
}
|
||||
|
||||
OPJ_BOOL opj_t1_decode_cblks( opj_t1_t* t1,
|
||||
|
@ -1622,7 +1624,7 @@ static void opj_t1_encode_cblk(opj_t1_t *t1,
|
|||
}
|
||||
|
||||
/* fixed_quality */
|
||||
tempwmsedec = opj_t1_getwmsedec(nmsedec, compno, level, orient, bpno, qmfbid, stepsize, numcomps,mct_norms, mct_numcomps) ;
|
||||
tempwmsedec = opj_t1_getwmsedec(nmsedec, compno, level, orient, bpno, qmfbid, stepsize, numcomps,mct_norms, mct_numcomps);
|
||||
cumwmsedec += tempwmsedec;
|
||||
tile->distotile += tempwmsedec;
|
||||
|
||||
|
|
|
@ -97,7 +97,8 @@ typedef OPJ_INT16 opj_flag_t;
|
|||
Tier-1 coding (coding of code-block coefficients)
|
||||
*/
|
||||
typedef struct opj_t1 {
|
||||
|
||||
/** User memory/event manager */
|
||||
opj_manager_t manager;
|
||||
/** MQC component */
|
||||
opj_mqc_t *mqc;
|
||||
/** RAW component */
|
||||
|
@ -151,7 +152,7 @@ OPJ_BOOL opj_t1_decode_cblks( opj_t1_t* t1,
|
|||
* and initializes the look-up tables of the Tier-1 coder/decoder
|
||||
* @return a new T1 handle if successful, returns NULL otherwise
|
||||
*/
|
||||
opj_t1_t* opj_t1_create(OPJ_BOOL isEncoder);
|
||||
opj_t1_t* opj_t1_create(opj_manager_t manager, OPJ_BOOL isEncoder);
|
||||
|
||||
/**
|
||||
* Destroys a previously created T1 handle
|
||||
|
|
|
@ -68,7 +68,8 @@ Encode a packet of a tile to a destination buffer
|
|||
@param cstr_info Codestream information structure
|
||||
@return
|
||||
*/
|
||||
static OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno,
|
||||
static OPJ_BOOL opj_t2_encode_packet( opj_manager_t manager,
|
||||
OPJ_UINT32 tileno,
|
||||
opj_tcd_tile_t *tile,
|
||||
opj_tcp_t *tcp,
|
||||
opj_pi_iterator_t *pi,
|
||||
|
@ -144,7 +145,8 @@ static OPJ_BOOL opj_t2_skip_packet_data(opj_t2_t* p_t2,
|
|||
@param cblksty
|
||||
@param first
|
||||
*/
|
||||
static OPJ_BOOL opj_t2_init_seg( opj_tcd_cblk_dec_t* cblk,
|
||||
static OPJ_BOOL opj_t2_init_seg( opj_manager_t manager,
|
||||
opj_tcd_cblk_dec_t* cblk,
|
||||
OPJ_UINT32 index,
|
||||
OPJ_UINT32 cblksty,
|
||||
OPJ_UINT32 first);
|
||||
|
@ -227,7 +229,7 @@ OPJ_BOOL opj_t2_encode_packets( opj_t2_t* p_t2,
|
|||
OPJ_UINT32 l_max_comp = l_cp->m_specific_param.m_enc.m_max_comp_size > 0 ? l_image->numcomps : 1;
|
||||
OPJ_UINT32 l_nb_pocs = l_tcp->numpocs + 1;
|
||||
|
||||
l_pi = opj_pi_initialise_encode(l_image, l_cp, p_tile_no, p_t2_mode);
|
||||
l_pi = opj_pi_initialise_encode(p_t2->manager, l_image, l_cp, p_tile_no, p_t2_mode);
|
||||
if (!l_pi) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
@ -249,15 +251,15 @@ OPJ_BOOL opj_t2_encode_packets( opj_t2_t* p_t2,
|
|||
|
||||
if (l_current_pi->poc.prg == OPJ_PROG_UNKNOWN) {
|
||||
/* TODO ADE : add an error */
|
||||
opj_pi_destroy(l_pi, l_nb_pocs);
|
||||
opj_pi_destroy(p_t2->manager, l_pi, l_nb_pocs);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
while (opj_pi_next(l_current_pi)) {
|
||||
if (l_current_pi->layno < p_maxlayers) {
|
||||
l_nb_bytes = 0;
|
||||
|
||||
if (! opj_t2_encode_packet(p_tile_no,p_tile, l_tcp, l_current_pi, l_current_data, &l_nb_bytes, p_max_len, cstr_info)) {
|
||||
opj_pi_destroy(l_pi, l_nb_pocs);
|
||||
if (! opj_t2_encode_packet(p_t2->manager, p_tile_no,p_tile, l_tcp, l_current_pi, l_current_data, &l_nb_bytes, p_max_len, cstr_info)) {
|
||||
opj_pi_destroy(p_t2->manager, l_pi, l_nb_pocs);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
|
@ -271,7 +273,7 @@ OPJ_BOOL opj_t2_encode_packets( opj_t2_t* p_t2,
|
|||
|
||||
if (l_cp->m_specific_param.m_enc.m_max_comp_size) {
|
||||
if (l_comp_len > l_cp->m_specific_param.m_enc.m_max_comp_size) {
|
||||
opj_pi_destroy(l_pi, l_nb_pocs);
|
||||
opj_pi_destroy(p_t2->manager, l_pi, l_nb_pocs);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -286,15 +288,15 @@ OPJ_BOOL opj_t2_encode_packets( opj_t2_t* p_t2,
|
|||
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);
|
||||
opj_pi_destroy(p_t2->manager, l_pi, l_nb_pocs);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
while (opj_pi_next(l_current_pi)) {
|
||||
if (l_current_pi->layno < p_maxlayers) {
|
||||
l_nb_bytes=0;
|
||||
|
||||
if (! opj_t2_encode_packet(p_tile_no,p_tile, l_tcp, l_current_pi, l_current_data, &l_nb_bytes, p_max_len, cstr_info)) {
|
||||
opj_pi_destroy(l_pi, l_nb_pocs);
|
||||
if (! opj_t2_encode_packet(p_t2->manager, p_tile_no,p_tile, l_tcp, l_current_pi, l_current_data, &l_nb_bytes, p_max_len, cstr_info)) {
|
||||
opj_pi_destroy(p_t2->manager, l_pi, l_nb_pocs);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
|
@ -326,7 +328,7 @@ OPJ_BOOL opj_t2_encode_packets( opj_t2_t* p_t2,
|
|||
}
|
||||
}
|
||||
|
||||
opj_pi_destroy(l_pi, l_nb_pocs);
|
||||
opj_pi_destroy(p_t2->manager, l_pi, l_nb_pocs);
|
||||
|
||||
return OPJ_TRUE;
|
||||
}
|
||||
|
@ -378,7 +380,7 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
|
|||
#endif
|
||||
|
||||
/* create a packet iterator */
|
||||
l_pi = opj_pi_create_decode(l_image, l_cp, p_tile_no);
|
||||
l_pi = opj_pi_create_decode(p_t2->manager, l_image, l_cp, p_tile_no);
|
||||
if (!l_pi) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
@ -397,14 +399,14 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
|
|||
|
||||
if (l_current_pi->poc.prg == OPJ_PROG_UNKNOWN) {
|
||||
/* TODO ADE : add an error */
|
||||
opj_pi_destroy(l_pi, l_nb_pocs);
|
||||
opj_pi_destroy(p_t2->manager, l_pi, l_nb_pocs);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
first_pass_failed = (OPJ_BOOL*)opj_malloc(l_image->numcomps * sizeof(OPJ_BOOL));
|
||||
|
||||
first_pass_failed = (OPJ_BOOL*)opj_manager_malloc(p_t2->manager, l_image->numcomps * sizeof(OPJ_BOOL));
|
||||
if (!first_pass_failed)
|
||||
{
|
||||
opj_pi_destroy(l_pi,l_nb_pocs);
|
||||
opj_pi_destroy(p_t2->manager, l_pi,l_nb_pocs);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
memset(first_pass_failed, OPJ_TRUE, l_image->numcomps * sizeof(OPJ_BOOL));
|
||||
|
@ -420,8 +422,8 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
|
|||
first_pass_failed[l_current_pi->compno] = OPJ_FALSE;
|
||||
|
||||
if (! opj_t2_decode_packet(p_t2,p_tile,l_tcp,l_current_pi,l_current_data,&l_nb_bytes_read,p_max_len,l_pack_info, p_manager)) {
|
||||
opj_pi_destroy(l_pi,l_nb_pocs);
|
||||
opj_free(first_pass_failed);
|
||||
opj_pi_destroy(p_t2->manager, l_pi,l_nb_pocs);
|
||||
opj_manager_free(p_t2->manager, first_pass_failed);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
|
@ -431,8 +433,8 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
|
|||
else {
|
||||
l_nb_bytes_read = 0;
|
||||
if (! opj_t2_skip_packet(p_t2,p_tile,l_tcp,l_current_pi,l_current_data,&l_nb_bytes_read,p_max_len,l_pack_info, p_manager)) {
|
||||
opj_pi_destroy(l_pi,l_nb_pocs);
|
||||
opj_free(first_pass_failed);
|
||||
opj_pi_destroy(p_t2->manager, l_pi,l_nb_pocs);
|
||||
opj_manager_free(p_t2->manager, first_pass_failed);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -471,7 +473,7 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
|
|||
}
|
||||
++l_current_pi;
|
||||
|
||||
opj_free(first_pass_failed);
|
||||
opj_manager_free(p_t2->manager, first_pass_failed);
|
||||
}
|
||||
/* INDEX >> */
|
||||
#ifdef TODO_MSD
|
||||
|
@ -483,7 +485,7 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
|
|||
/* << INDEX */
|
||||
|
||||
/* don't forget to release pi */
|
||||
opj_pi_destroy(l_pi,l_nb_pocs);
|
||||
opj_pi_destroy(p_t2->manager, l_pi,l_nb_pocs);
|
||||
*p_data_read = (OPJ_UINT32)(l_current_data - p_src);
|
||||
return OPJ_TRUE;
|
||||
}
|
||||
|
@ -497,24 +499,25 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
|
|||
* @param p_cp Image coding parameters.
|
||||
* @return a new T2 handle if successful, NULL otherwise.
|
||||
*/
|
||||
opj_t2_t* opj_t2_create(opj_image_t *p_image, opj_cp_t *p_cp)
|
||||
opj_t2_t* opj_t2_create(opj_manager_t manager, opj_image_t *p_image, opj_cp_t *p_cp)
|
||||
{
|
||||
/* create the t2 structure */
|
||||
opj_t2_t *l_t2 = (opj_t2_t*)opj_calloc(1,sizeof(opj_t2_t));
|
||||
opj_t2_t *l_t2 = (opj_t2_t*)opj_manager_calloc(manager, 1,sizeof(opj_t2_t));
|
||||
if (!l_t2) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
l_t2->manager = manager;
|
||||
l_t2->image = p_image;
|
||||
l_t2->cp = p_cp;
|
||||
|
||||
return l_t2;
|
||||
}
|
||||
|
||||
void opj_t2_destroy(opj_t2_t *t2) {
|
||||
if(t2) {
|
||||
opj_free(t2);
|
||||
}
|
||||
void opj_t2_destroy(opj_t2_t *t2)
|
||||
{
|
||||
if(t2) {
|
||||
opj_manager_free(t2->manager, t2);
|
||||
}
|
||||
}
|
||||
|
||||
static OPJ_BOOL opj_t2_decode_packet( opj_t2_t* p_t2,
|
||||
|
@ -557,7 +560,8 @@ static OPJ_BOOL opj_t2_decode_packet( opj_t2_t* p_t2,
|
|||
return OPJ_TRUE;
|
||||
}
|
||||
|
||||
static OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno,
|
||||
static OPJ_BOOL opj_t2_encode_packet( opj_manager_t manager,
|
||||
OPJ_UINT32 tileno,
|
||||
opj_tcd_tile_t * tile,
|
||||
opj_tcp_t * tcp,
|
||||
opj_pi_iterator_t *pi,
|
||||
|
@ -621,7 +625,7 @@ static OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno,
|
|||
}
|
||||
}
|
||||
|
||||
bio = opj_bio_create();
|
||||
bio = opj_bio_create(manager);
|
||||
if (!bio) {
|
||||
/* FIXME event manager error callback */
|
||||
return OPJ_FALSE;
|
||||
|
@ -719,7 +723,7 @@ static OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno,
|
|||
}
|
||||
|
||||
if (!opj_bio_flush(bio)) {
|
||||
opj_bio_destroy(bio);
|
||||
opj_bio_destroy(manager, bio);
|
||||
return OPJ_FALSE; /* modified to eliminate longjmp !! */
|
||||
}
|
||||
|
||||
|
@ -727,7 +731,7 @@ static OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno,
|
|||
c += l_nb_bytes;
|
||||
length -= l_nb_bytes;
|
||||
|
||||
opj_bio_destroy(bio);
|
||||
opj_bio_destroy(manager, bio);
|
||||
|
||||
/* <EPH 0xff92> */
|
||||
if (tcp->csty & J2K_CP_CSTY_EPH) {
|
||||
|
@ -908,7 +912,7 @@ static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
|
|||
step 2: Return to codestream for decoding
|
||||
*/
|
||||
|
||||
l_bio = opj_bio_create();
|
||||
l_bio = opj_bio_create(p_t2->manager);
|
||||
if (! l_bio) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
@ -939,7 +943,7 @@ static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
|
|||
/* TODO MSD: no test to control the output of this function*/
|
||||
opj_bio_inalign(l_bio);
|
||||
l_header_data += opj_bio_numbytes(l_bio);
|
||||
opj_bio_destroy(l_bio);
|
||||
opj_bio_destroy(p_t2->manager, l_bio);
|
||||
|
||||
/* EPH markers */
|
||||
if (p_tcp->csty & J2K_CP_CSTY_EPH) {
|
||||
|
@ -1022,8 +1026,8 @@ static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
|
|||
l_segno = 0;
|
||||
|
||||
if (!l_cblk->numsegs) {
|
||||
if (! opj_t2_init_seg(l_cblk, l_segno, p_tcp->tccps[p_pi->compno].cblksty, 1)) {
|
||||
opj_bio_destroy(l_bio);
|
||||
if (! opj_t2_init_seg(p_t2->manager, l_cblk, l_segno, p_tcp->tccps[p_pi->compno].cblksty, 1)) {
|
||||
opj_bio_destroy(p_t2->manager, l_bio);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -1031,8 +1035,8 @@ static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
|
|||
l_segno = l_cblk->numsegs - 1;
|
||||
if (l_cblk->segs[l_segno].numpasses == l_cblk->segs[l_segno].maxpasses) {
|
||||
++l_segno;
|
||||
if (! opj_t2_init_seg(l_cblk, l_segno, p_tcp->tccps[p_pi->compno].cblksty, 0)) {
|
||||
opj_bio_destroy(l_bio);
|
||||
if (! opj_t2_init_seg(p_t2->manager, l_cblk, l_segno, p_tcp->tccps[p_pi->compno].cblksty, 0)) {
|
||||
opj_bio_destroy(p_t2->manager, l_bio);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -1048,8 +1052,8 @@ static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
|
|||
if (n > 0) {
|
||||
++l_segno;
|
||||
|
||||
if (! opj_t2_init_seg(l_cblk, l_segno, p_tcp->tccps[p_pi->compno].cblksty, 0)) {
|
||||
opj_bio_destroy(l_bio);
|
||||
if (! opj_t2_init_seg(p_t2->manager, l_cblk, l_segno, p_tcp->tccps[p_pi->compno].cblksty, 0)) {
|
||||
opj_bio_destroy(p_t2->manager, l_bio);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -1062,12 +1066,12 @@ static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
|
|||
}
|
||||
|
||||
if (!opj_bio_inalign(l_bio)) {
|
||||
opj_bio_destroy(l_bio);
|
||||
opj_bio_destroy(p_t2->manager, l_bio);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
l_header_data += opj_bio_numbytes(l_bio);
|
||||
opj_bio_destroy(l_bio);
|
||||
opj_bio_destroy(p_t2->manager, l_bio);
|
||||
|
||||
/* EPH markers */
|
||||
if (p_tcp->csty & J2K_CP_CSTY_EPH) {
|
||||
|
@ -1189,9 +1193,9 @@ static OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2,
|
|||
}
|
||||
/* Check if the cblk->data have allocated enough memory */
|
||||
if ((l_cblk->data_current_size + l_seg->newlen) > l_cblk->data_max_size) {
|
||||
OPJ_BYTE* new_cblk_data = (OPJ_BYTE*) opj_realloc(l_cblk->data, l_cblk->data_current_size + l_seg->newlen);
|
||||
OPJ_BYTE* new_cblk_data = (OPJ_BYTE*) opj_manager_realloc(p_t2->manager, l_cblk->data, l_cblk->data_current_size + l_seg->newlen);
|
||||
if(! new_cblk_data) {
|
||||
opj_free(l_cblk->data);
|
||||
opj_manager_free(p_t2->manager, l_cblk->data);
|
||||
l_cblk->data = NULL;
|
||||
l_cblk->data_max_size = 0;
|
||||
/* opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to realloc code block cata!\n"); */
|
||||
|
@ -1338,7 +1342,8 @@ static OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2,
|
|||
}
|
||||
|
||||
|
||||
OPJ_BOOL opj_t2_init_seg( opj_tcd_cblk_dec_t* cblk,
|
||||
OPJ_BOOL opj_t2_init_seg( opj_manager_t manager,
|
||||
opj_tcd_cblk_dec_t* cblk,
|
||||
OPJ_UINT32 index,
|
||||
OPJ_UINT32 cblksty,
|
||||
OPJ_UINT32 first)
|
||||
|
@ -1350,9 +1355,9 @@ OPJ_BOOL opj_t2_init_seg( opj_tcd_cblk_dec_t* cblk,
|
|||
opj_tcd_seg_t* new_segs;
|
||||
cblk->m_current_max_segs += OPJ_J2K_DEFAULT_NB_SEGS;
|
||||
|
||||
new_segs = (opj_tcd_seg_t*) opj_realloc(cblk->segs, cblk->m_current_max_segs * sizeof(opj_tcd_seg_t));
|
||||
new_segs = (opj_tcd_seg_t*) opj_manager_realloc(manager, cblk->segs, cblk->m_current_max_segs * sizeof(opj_tcd_seg_t));
|
||||
if(! new_segs) {
|
||||
opj_free(cblk->segs);
|
||||
opj_manager_free(manager, cblk->segs);
|
||||
cblk->segs = NULL;
|
||||
cblk->m_current_max_segs = 0;
|
||||
/* opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to initialize segment %d\n", l_nb_segs); */
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
Tier-2 coding
|
||||
*/
|
||||
typedef struct opj_t2 {
|
||||
|
||||
opj_manager_t manager;
|
||||
/** Encoding: pointer to the src image. Decoding: pointer to the dst image. */
|
||||
opj_image_t *image;
|
||||
/** pointer to the image coding parameters */
|
||||
|
@ -118,7 +118,7 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *t2,
|
|||
* @param p_cp Image coding parameters.
|
||||
* @return a new T2 handle if successful, NULL otherwise.
|
||||
*/
|
||||
opj_t2_t* opj_t2_create(opj_image_t *p_image, opj_cp_t *p_cp);
|
||||
opj_t2_t* opj_t2_create(opj_manager_t manager, opj_image_t *p_image, opj_cp_t *p_cp);
|
||||
|
||||
/**
|
||||
Destroy a T2 handle
|
||||
|
|
|
@ -112,27 +112,27 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
|
|||
/**
|
||||
* Allocates memory for a decoding code block.
|
||||
*/
|
||||
static OPJ_BOOL opj_tcd_code_block_dec_allocate (opj_tcd_cblk_dec_t * p_code_block);
|
||||
static OPJ_BOOL opj_tcd_code_block_dec_allocate (opj_manager_t manager, opj_tcd_cblk_dec_t * p_code_block);
|
||||
|
||||
/**
|
||||
* Deallocates the decoding data of the given precinct.
|
||||
*/
|
||||
static void opj_tcd_code_block_dec_deallocate (opj_tcd_precinct_t * p_precinct);
|
||||
static void opj_tcd_code_block_dec_deallocate (opj_manager_t manager, opj_tcd_precinct_t * p_precinct);
|
||||
|
||||
/**
|
||||
* Allocates memory for an encoding code block (but not data).
|
||||
*/
|
||||
static OPJ_BOOL opj_tcd_code_block_enc_allocate (opj_tcd_cblk_enc_t * p_code_block);
|
||||
static OPJ_BOOL opj_tcd_code_block_enc_allocate (opj_manager_t manager, opj_tcd_cblk_enc_t * p_code_block);
|
||||
|
||||
/**
|
||||
* Allocates data for an encoding code block
|
||||
*/
|
||||
static OPJ_BOOL opj_tcd_code_block_enc_allocate_data (opj_tcd_cblk_enc_t * p_code_block);
|
||||
static OPJ_BOOL opj_tcd_code_block_enc_allocate_data (opj_manager_t manager, opj_tcd_cblk_enc_t * p_code_block);
|
||||
|
||||
/**
|
||||
* Deallocates the encoding data of the given precinct.
|
||||
*/
|
||||
static void opj_tcd_code_block_enc_deallocate (opj_tcd_precinct_t * p_precinct);
|
||||
static void opj_tcd_code_block_enc_deallocate (opj_manager_t manager, opj_tcd_precinct_t * p_precinct);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -182,21 +182,25 @@ static OPJ_BOOL opj_tcd_rate_allocate_encode( opj_tcd_t *p_tcd,
|
|||
/**
|
||||
Create a new TCD handle
|
||||
*/
|
||||
opj_tcd_t* opj_tcd_create(OPJ_BOOL p_is_decoder)
|
||||
opj_tcd_t* opj_tcd_create(opj_manager_t manager, OPJ_BOOL p_is_decoder)
|
||||
{
|
||||
opj_tcd_t *l_tcd = 00;
|
||||
|
||||
if (manager == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
/* create the tcd structure */
|
||||
l_tcd = (opj_tcd_t*) opj_calloc(1,sizeof(opj_tcd_t));
|
||||
l_tcd = (opj_tcd_t*) opj_manager_calloc(manager, 1,sizeof(opj_tcd_t));
|
||||
if (!l_tcd) {
|
||||
return 00;
|
||||
}
|
||||
|
||||
l_tcd->manager = manager;
|
||||
l_tcd->m_is_decoder = p_is_decoder ? 1 : 0;
|
||||
|
||||
l_tcd->tcd_image = (opj_tcd_image_t*)opj_calloc(1,sizeof(opj_tcd_image_t));
|
||||
l_tcd->tcd_image = (opj_tcd_image_t*)opj_manager_calloc(manager, 1,sizeof(opj_tcd_image_t));
|
||||
if (!l_tcd->tcd_image) {
|
||||
opj_free(l_tcd);
|
||||
opj_manager_free(manager, l_tcd);
|
||||
return 00;
|
||||
}
|
||||
|
||||
|
@ -476,7 +480,7 @@ OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd,
|
|||
opj_tile_info_t *tile_info = &cstr_info->tile[tcd->tcd_tileno];
|
||||
tile_info->numpix = tcd_tile->numpix;
|
||||
tile_info->distotile = tcd_tile->distotile;
|
||||
tile_info->thresh = (OPJ_FLOAT64 *) opj_malloc(tcd_tcp->numlayers * sizeof(OPJ_FLOAT64));
|
||||
tile_info->thresh = (OPJ_FLOAT64 *) opj_manager_malloc(tcd->manager, tcd_tcp->numlayers * sizeof(OPJ_FLOAT64));
|
||||
if (!tile_info->thresh) {
|
||||
/* FIXME event manager error callback */
|
||||
return OPJ_FALSE;
|
||||
|
@ -501,7 +505,7 @@ OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd,
|
|||
-q xx,yy,zz,0 (fixed_quality == 1 and distoratio == 0)
|
||||
==> possible to have some lossy layers and the last layer for sure lossless */
|
||||
if ( ((cp->m_specific_param.m_enc.m_disto_alloc==1) && (tcd_tcp->rates[layno]>0)) || ((cp->m_specific_param.m_enc.m_fixed_quality==1) && (tcd_tcp->distoratio[layno]>0))) {
|
||||
opj_t2_t*t2 = opj_t2_create(tcd->image, cp);
|
||||
opj_t2_t*t2 = opj_t2_create(tcd->manager, tcd->image, cp);
|
||||
OPJ_FLOAT64 thresh = 0;
|
||||
|
||||
if (t2 == 00) {
|
||||
|
@ -592,12 +596,12 @@ OPJ_BOOL opj_tcd_init( opj_tcd_t *p_tcd,
|
|||
p_tcd->image = p_image;
|
||||
p_tcd->cp = p_cp;
|
||||
|
||||
p_tcd->tcd_image->tiles = (opj_tcd_tile_t *) opj_calloc(1,sizeof(opj_tcd_tile_t));
|
||||
p_tcd->tcd_image->tiles = (opj_tcd_tile_t *) opj_manager_calloc(p_tcd->manager, 1,sizeof(opj_tcd_tile_t));
|
||||
if (! p_tcd->tcd_image->tiles) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
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_manager_calloc(p_tcd->manager, p_image->numcomps,sizeof(opj_tcd_tilecomp_t));
|
||||
if (! p_tcd->tcd_image->tiles->comps ) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
@ -611,22 +615,22 @@ OPJ_BOOL opj_tcd_init( opj_tcd_t *p_tcd,
|
|||
/**
|
||||
Destroy a previously created TCD handle
|
||||
*/
|
||||
void opj_tcd_destroy(opj_tcd_t *tcd) {
|
||||
void opj_tcd_destroy(opj_manager_t manager, opj_tcd_t *tcd) {
|
||||
if (tcd) {
|
||||
opj_tcd_free_tile(tcd);
|
||||
|
||||
if (tcd->tcd_image) {
|
||||
opj_free(tcd->tcd_image);
|
||||
opj_manager_free(manager, tcd->tcd_image);
|
||||
tcd->tcd_image = 00;
|
||||
}
|
||||
opj_free(tcd);
|
||||
opj_manager_free(manager, tcd);
|
||||
}
|
||||
}
|
||||
|
||||
OPJ_BOOL opj_alloc_tile_component_data(opj_tcd_tilecomp_t *l_tilec)
|
||||
OPJ_BOOL opj_alloc_tile_component_data(opj_manager_t manager, opj_tcd_tilecomp_t *l_tilec)
|
||||
{
|
||||
if ((l_tilec->data == 00) || ((l_tilec->data_size_needed > l_tilec->data_size) && (l_tilec->ownsData == OPJ_FALSE))) {
|
||||
l_tilec->data = (OPJ_INT32 *) opj_malloc(l_tilec->data_size_needed);
|
||||
l_tilec->data = (OPJ_INT32 *) opj_manager_malloc(manager, l_tilec->data_size_needed);
|
||||
if (! l_tilec->data ) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
@ -635,11 +639,11 @@ OPJ_BOOL opj_alloc_tile_component_data(opj_tcd_tilecomp_t *l_tilec)
|
|||
l_tilec->ownsData = OPJ_TRUE;
|
||||
}
|
||||
else if (l_tilec->data_size_needed > l_tilec->data_size) {
|
||||
OPJ_INT32 * new_data = (OPJ_INT32 *) opj_realloc(l_tilec->data, l_tilec->data_size_needed);
|
||||
OPJ_INT32 * new_data = (OPJ_INT32 *) opj_manager_realloc(manager, l_tilec->data, l_tilec->data_size_needed);
|
||||
/* opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle tile datan"); */
|
||||
/* fprintf(stderr, "Not enough memory to handle tile data"); */
|
||||
if (! new_data) {
|
||||
opj_free(l_tilec->data);
|
||||
opj_manager_free(manager, l_tilec->data);
|
||||
l_tilec->data = NULL;
|
||||
l_tilec->data_size = 0;
|
||||
l_tilec->data_size_needed = 0;
|
||||
|
@ -735,7 +739,6 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
|
|||
return OPJ_FALSE;
|
||||
}
|
||||
l_data_size = l_data_size * (OPJ_UINT32)(l_tilec->y1 - l_tilec->y0);
|
||||
|
||||
if ((((OPJ_UINT32)-1) / (OPJ_UINT32)sizeof(OPJ_UINT32)) < l_data_size) {
|
||||
opj_event_msg(manager, EVT_ERROR, "Not enough memory for tile data\n");
|
||||
return OPJ_FALSE;
|
||||
|
@ -750,7 +753,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
|
|||
}
|
||||
|
||||
l_tilec->data_size_needed = l_data_size;
|
||||
if (p_tcd->m_is_decoder && !opj_alloc_tile_component_data(l_tilec)) {
|
||||
if (p_tcd->m_is_decoder && !opj_alloc_tile_component_data(p_tcd->manager, l_tilec)) {
|
||||
opj_event_msg(manager, EVT_ERROR, "Not enough memory for tile data\n");
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
@ -758,7 +761,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
|
|||
l_data_size = l_tilec->numresolutions * (OPJ_UINT32)sizeof(opj_tcd_resolution_t);
|
||||
|
||||
if (l_tilec->resolutions == 00) {
|
||||
l_tilec->resolutions = (opj_tcd_resolution_t *) opj_malloc(l_data_size);
|
||||
l_tilec->resolutions = (opj_tcd_resolution_t *) opj_manager_malloc(p_tcd->manager, l_data_size);
|
||||
if (! l_tilec->resolutions ) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
@ -767,10 +770,10 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
|
|||
memset(l_tilec->resolutions,0,l_data_size);
|
||||
}
|
||||
else if (l_data_size > l_tilec->resolutions_size) {
|
||||
opj_tcd_resolution_t* new_resolutions = (opj_tcd_resolution_t *) opj_realloc(l_tilec->resolutions, l_data_size);
|
||||
opj_tcd_resolution_t* new_resolutions = (opj_tcd_resolution_t *) opj_manager_realloc(p_tcd->manager, l_tilec->resolutions, l_data_size);
|
||||
if (! new_resolutions) {
|
||||
opj_event_msg(manager, EVT_ERROR, "Not enough memory for tile resolutions\n");
|
||||
opj_free(l_tilec->resolutions);
|
||||
opj_manager_free(p_tcd->manager, l_tilec->resolutions);
|
||||
l_tilec->resolutions = NULL;
|
||||
l_tilec->resolutions_size = 0;
|
||||
return OPJ_FALSE;
|
||||
|
@ -875,7 +878,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
|
|||
l_band->numbps = l_step_size->expn + (OPJ_INT32)l_tccp->numgbits - 1; /* WHY -1 ? */
|
||||
|
||||
if (! l_band->precincts) {
|
||||
l_band->precincts = (opj_tcd_precinct_t *) opj_malloc( /*3 * */ l_nb_precinct_size);
|
||||
l_band->precincts = (opj_tcd_precinct_t *) opj_manager_malloc(p_tcd->manager, /*3 * */ l_nb_precinct_size);
|
||||
if (! l_band->precincts) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
@ -885,10 +888,10 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
|
|||
}
|
||||
else if (l_band->precincts_data_size < l_nb_precinct_size) {
|
||||
|
||||
opj_tcd_precinct_t * new_precincts = (opj_tcd_precinct_t *) opj_realloc(l_band->precincts,/*3 * */ l_nb_precinct_size);
|
||||
opj_tcd_precinct_t * new_precincts = (opj_tcd_precinct_t *) opj_manager_realloc(p_tcd->manager, l_band->precincts,/*3 * */ l_nb_precinct_size);
|
||||
if (! new_precincts) {
|
||||
opj_event_msg(manager, EVT_ERROR, "Not enough memory to handle band precints\n");
|
||||
opj_free(l_band->precincts);
|
||||
opj_event_msg(&(p_tcd->manager->event_mgr), EVT_ERROR, "Not enough memory to handle band precints\n");
|
||||
opj_manager_free(p_tcd->manager, l_band->precincts);
|
||||
l_band->precincts = NULL;
|
||||
l_band->precincts_data_size = 0;
|
||||
return OPJ_FALSE;
|
||||
|
@ -934,7 +937,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
|
|||
l_nb_code_blocks_size = l_nb_code_blocks * (OPJ_UINT32)sizeof_block;
|
||||
|
||||
if (! l_current_precinct->cblks.blocks) {
|
||||
l_current_precinct->cblks.blocks = opj_malloc(l_nb_code_blocks_size);
|
||||
l_current_precinct->cblks.blocks = opj_manager_malloc(p_tcd->manager, l_nb_code_blocks_size);
|
||||
if (! l_current_precinct->cblks.blocks ) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
@ -945,12 +948,12 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
|
|||
l_current_precinct->block_size = l_nb_code_blocks_size;
|
||||
}
|
||||
else if (l_nb_code_blocks_size > l_current_precinct->block_size) {
|
||||
void *new_blocks = opj_realloc(l_current_precinct->cblks.blocks, l_nb_code_blocks_size);
|
||||
void *new_blocks = opj_manager_realloc(p_tcd->manager, l_current_precinct->cblks.blocks, l_nb_code_blocks_size);
|
||||
if (! new_blocks) {
|
||||
opj_free(l_current_precinct->cblks.blocks);
|
||||
opj_manager_free(p_tcd->manager, l_current_precinct->cblks.blocks);
|
||||
l_current_precinct->cblks.blocks = NULL;
|
||||
l_current_precinct->block_size = 0;
|
||||
opj_event_msg(manager, EVT_ERROR, "Not enough memory for current precinct codeblock element\n");
|
||||
opj_event_msg(&(p_tcd->manager->event_mgr), EVT_ERROR, "Not enough memory for current precinct codeblock element\n");
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
l_current_precinct->cblks.blocks = new_blocks;
|
||||
|
@ -964,26 +967,26 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
|
|||
}
|
||||
|
||||
if (! l_current_precinct->incltree) {
|
||||
l_current_precinct->incltree = opj_tgt_create(l_current_precinct->cw, l_current_precinct->ch, manager);
|
||||
l_current_precinct->incltree = opj_tgt_create(p_tcd->manager, l_current_precinct->cw, l_current_precinct->ch);
|
||||
}
|
||||
else{
|
||||
l_current_precinct->incltree = opj_tgt_init(l_current_precinct->incltree, l_current_precinct->cw, l_current_precinct->ch, manager);
|
||||
}
|
||||
|
||||
if (! l_current_precinct->incltree) {
|
||||
opj_event_msg(manager, EVT_WARNING, "No incltree created.\n");
|
||||
opj_event_msg(&(p_tcd->manager->event_mgr), EVT_WARNING, "No incltree created.\n");
|
||||
/*return OPJ_FALSE;*/
|
||||
}
|
||||
|
||||
if (! l_current_precinct->imsbtree) {
|
||||
l_current_precinct->imsbtree = opj_tgt_create(l_current_precinct->cw, l_current_precinct->ch, manager);
|
||||
l_current_precinct->imsbtree = opj_tgt_create(p_tcd->manager, l_current_precinct->cw, l_current_precinct->ch);
|
||||
}
|
||||
else {
|
||||
l_current_precinct->imsbtree = opj_tgt_init(l_current_precinct->imsbtree, l_current_precinct->cw, l_current_precinct->ch, manager);
|
||||
}
|
||||
|
||||
if (! l_current_precinct->imsbtree) {
|
||||
opj_event_msg(manager, EVT_WARNING, "No imsbtree created.\n");
|
||||
opj_event_msg(&(p_tcd->manager->event_mgr), EVT_WARNING, "No imsbtree created.\n");
|
||||
/*return OPJ_FALSE;*/
|
||||
}
|
||||
|
||||
|
@ -996,7 +999,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
|
|||
if (isEncoder) {
|
||||
opj_tcd_cblk_enc_t* l_code_block = l_current_precinct->cblks.enc + cblkno;
|
||||
|
||||
if (! opj_tcd_code_block_enc_allocate(l_code_block)) {
|
||||
if (! opj_tcd_code_block_enc_allocate(p_tcd->manager, l_code_block)) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
/* code-block size (global) */
|
||||
|
@ -1005,13 +1008,13 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
|
|||
l_code_block->x1 = opj_int_min(cblkxend, l_current_precinct->x1);
|
||||
l_code_block->y1 = opj_int_min(cblkyend, l_current_precinct->y1);
|
||||
|
||||
if (! opj_tcd_code_block_enc_allocate_data(l_code_block)) {
|
||||
if (! opj_tcd_code_block_enc_allocate_data(p_tcd->manager, l_code_block)) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
} else {
|
||||
opj_tcd_cblk_dec_t* l_code_block = l_current_precinct->cblks.dec + cblkno;
|
||||
|
||||
if (! opj_tcd_code_block_dec_allocate(l_code_block)) {
|
||||
if (! opj_tcd_code_block_dec_allocate(p_tcd->manager, l_code_block)) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
/* code-block size (global) */
|
||||
|
@ -1049,17 +1052,17 @@ OPJ_BOOL opj_tcd_init_decode_tile (opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, opj_e
|
|||
/**
|
||||
* Allocates memory for an encoding code block (but not data memory).
|
||||
*/
|
||||
static OPJ_BOOL opj_tcd_code_block_enc_allocate (opj_tcd_cblk_enc_t * p_code_block)
|
||||
static OPJ_BOOL opj_tcd_code_block_enc_allocate (opj_manager_t manager, opj_tcd_cblk_enc_t * p_code_block)
|
||||
{
|
||||
if (! p_code_block->layers) {
|
||||
/* no memset since data */
|
||||
p_code_block->layers = (opj_tcd_layer_t*) opj_calloc(100, sizeof(opj_tcd_layer_t));
|
||||
p_code_block->layers = (opj_tcd_layer_t*) opj_manager_calloc(manager, 100, sizeof(opj_tcd_layer_t));
|
||||
if (! p_code_block->layers) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
}
|
||||
if (! p_code_block->passes) {
|
||||
p_code_block->passes = (opj_tcd_pass_t*) opj_calloc(100, sizeof(opj_tcd_pass_t));
|
||||
p_code_block->passes = (opj_tcd_pass_t*) opj_manager_calloc(manager, 100, sizeof(opj_tcd_pass_t));
|
||||
if (! p_code_block->passes) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
@ -1070,23 +1073,21 @@ static OPJ_BOOL opj_tcd_code_block_enc_allocate (opj_tcd_cblk_enc_t * p_code_blo
|
|||
/**
|
||||
* Allocates data memory for an encoding code block.
|
||||
*/
|
||||
static OPJ_BOOL opj_tcd_code_block_enc_allocate_data (opj_tcd_cblk_enc_t * p_code_block)
|
||||
static OPJ_BOOL opj_tcd_code_block_enc_allocate_data (opj_manager_t manager, opj_tcd_cblk_enc_t * p_code_block)
|
||||
{
|
||||
OPJ_UINT32 l_data_size;
|
||||
|
||||
l_data_size = (OPJ_UINT32)((p_code_block->x1 - p_code_block->x0) * (p_code_block->y1 - p_code_block->y0) * (OPJ_INT32)sizeof(OPJ_UINT32));
|
||||
|
||||
if (l_data_size > p_code_block->data_size) {
|
||||
if (p_code_block->data) {
|
||||
opj_free(p_code_block->data - 1); /* again, why -1 */
|
||||
opj_manager_free(manager, p_code_block->data - 1); /* again, why -1 */
|
||||
}
|
||||
p_code_block->data = (OPJ_BYTE*) opj_malloc(l_data_size+1);
|
||||
p_code_block->data = (OPJ_BYTE*)opj_manager_malloc(manager, l_data_size);
|
||||
if(! p_code_block->data) {
|
||||
p_code_block->data_size = 0U;
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
p_code_block->data_size = l_data_size;
|
||||
|
||||
p_code_block->data[0] = 0;
|
||||
p_code_block->data+=1; /*why +1 ?*/
|
||||
}
|
||||
|
@ -1096,18 +1097,18 @@ static OPJ_BOOL opj_tcd_code_block_enc_allocate_data (opj_tcd_cblk_enc_t * p_cod
|
|||
/**
|
||||
* Allocates memory for a decoding code block.
|
||||
*/
|
||||
static OPJ_BOOL opj_tcd_code_block_dec_allocate (opj_tcd_cblk_dec_t * p_code_block)
|
||||
static OPJ_BOOL opj_tcd_code_block_dec_allocate (opj_manager_t manager, opj_tcd_cblk_dec_t * p_code_block)
|
||||
{
|
||||
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_manager_malloc(manager, OPJ_J2K_DEFAULT_CBLK_DATA_SIZE);
|
||||
if (! p_code_block->data) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
p_code_block->data_max_size = OPJ_J2K_DEFAULT_CBLK_DATA_SIZE;
|
||||
/*fprintf(stderr, "Allocate 8192 elements of code_block->data\n");*/
|
||||
|
||||
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_manager_calloc(manager, OPJ_J2K_DEFAULT_NB_SEGS,sizeof(opj_tcd_seg_t));
|
||||
if (! p_code_block->segs) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
@ -1195,7 +1196,7 @@ OPJ_BOOL opj_tcd_encode_tile( opj_tcd_t *p_tcd,
|
|||
p_cstr_info->tile[p_tile_no].pdx[i] = (int)l_tccp->prcw[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_manager_calloc(p_tcd->manager, (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;
|
||||
|
@ -1463,7 +1464,7 @@ static void opj_tcd_free_tile(opj_tcd_t *p_tcd)
|
|||
opj_tcd_band_t *l_band = 00;
|
||||
opj_tcd_precinct_t *l_precinct = 00;
|
||||
OPJ_UINT32 l_nb_resolutions, l_nb_precincts;
|
||||
void (* l_tcd_code_block_deallocate) (opj_tcd_precinct_t *) = 00;
|
||||
void (* l_tcd_code_block_deallocate) (opj_manager_t, opj_tcd_precinct_t *) = 00;
|
||||
|
||||
if (! p_tcd) {
|
||||
return;
|
||||
|
@ -1504,11 +1505,11 @@ static void opj_tcd_free_tile(opj_tcd_t *p_tcd)
|
|||
l_precinct->incltree = 00;
|
||||
opj_tgt_destroy(l_precinct->imsbtree);
|
||||
l_precinct->imsbtree = 00;
|
||||
(*l_tcd_code_block_deallocate) (l_precinct);
|
||||
(*l_tcd_code_block_deallocate) (p_tcd->manager, l_precinct);
|
||||
++l_precinct;
|
||||
}
|
||||
|
||||
opj_free(l_band->precincts);
|
||||
opj_manager_free(p_tcd->manager, l_band->precincts);
|
||||
l_band->precincts = 00;
|
||||
}
|
||||
++l_band;
|
||||
|
@ -1516,12 +1517,12 @@ static void opj_tcd_free_tile(opj_tcd_t *p_tcd)
|
|||
++l_res;
|
||||
}
|
||||
|
||||
opj_free(l_tile_comp->resolutions);
|
||||
opj_manager_free(p_tcd->manager, l_tile_comp->resolutions);
|
||||
l_tile_comp->resolutions = 00;
|
||||
}
|
||||
|
||||
if (l_tile_comp->ownsData && l_tile_comp->data) {
|
||||
opj_free(l_tile_comp->data);
|
||||
opj_manager_free(p_tcd->manager, l_tile_comp->data);
|
||||
l_tile_comp->data = 00;
|
||||
l_tile_comp->ownsData = 0;
|
||||
l_tile_comp->data_size = 0;
|
||||
|
@ -1530,9 +1531,9 @@ static void opj_tcd_free_tile(opj_tcd_t *p_tcd)
|
|||
++l_tile_comp;
|
||||
}
|
||||
|
||||
opj_free(l_tile->comps);
|
||||
opj_manager_free(p_tcd->manager, l_tile->comps);
|
||||
l_tile->comps = 00;
|
||||
opj_free(p_tcd->tcd_image->tiles);
|
||||
opj_manager_free(p_tcd->manager, p_tcd->tcd_image->tiles);
|
||||
p_tcd->tcd_image->tiles = 00;
|
||||
}
|
||||
|
||||
|
@ -1547,7 +1548,7 @@ static OPJ_BOOL opj_tcd_t2_decode (opj_tcd_t *p_tcd,
|
|||
{
|
||||
opj_t2_t * l_t2;
|
||||
|
||||
l_t2 = opj_t2_create(p_tcd->image, p_tcd->cp);
|
||||
l_t2 = opj_t2_create(p_tcd->manager, p_tcd->image, p_tcd->cp);
|
||||
if (l_t2 == 00) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
@ -1580,7 +1581,7 @@ static OPJ_BOOL opj_tcd_t1_decode ( opj_tcd_t *p_tcd )
|
|||
opj_tccp_t * l_tccp = p_tcd->tcp->tccps;
|
||||
|
||||
|
||||
l_t1 = opj_t1_create(OPJ_FALSE);
|
||||
l_t1 = opj_t1_create(p_tcd->manager, OPJ_FALSE);
|
||||
if (l_t1 == 00) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
@ -1624,12 +1625,12 @@ static OPJ_BOOL opj_tcd_dwt_decode ( opj_tcd_t *p_tcd )
|
|||
*/
|
||||
|
||||
if (l_tccp->qmfbid == 1) {
|
||||
if (! opj_dwt_decode(l_tile_comp, l_img_comp->resno_decoded+1)) {
|
||||
if (! opj_dwt_decode(p_tcd->manager, l_tile_comp, l_img_comp->resno_decoded+1)) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (! opj_dwt_decode_real(l_tile_comp, l_img_comp->resno_decoded+1)) {
|
||||
if (! opj_dwt_decode_real(p_tcd->manager, l_tile_comp, l_img_comp->resno_decoded+1)) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -1669,7 +1670,7 @@ static OPJ_BOOL opj_tcd_mct_decode ( opj_tcd_t *p_tcd, opj_event_mgr_t *p_manage
|
|||
return OPJ_TRUE;
|
||||
}
|
||||
|
||||
l_data = (OPJ_BYTE **) opj_malloc(l_tile->numcomps*sizeof(OPJ_BYTE*));
|
||||
l_data = (OPJ_BYTE **) opj_manager_malloc(p_tcd->manager, l_tile->numcomps*sizeof(OPJ_BYTE*));
|
||||
if (! l_data) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
@ -1679,7 +1680,7 @@ static OPJ_BOOL opj_tcd_mct_decode ( opj_tcd_t *p_tcd, opj_event_mgr_t *p_manage
|
|||
++l_tile_comp;
|
||||
}
|
||||
|
||||
if (! opj_mct_decode_custom(/* MCT data */
|
||||
if (! opj_mct_decode_custom(p_tcd->manager, /* MCT data */
|
||||
(OPJ_BYTE*) l_tcp->m_mct_decoding_matrix,
|
||||
/* size of components */
|
||||
l_samples,
|
||||
|
@ -1689,11 +1690,11 @@ static OPJ_BOOL opj_tcd_mct_decode ( opj_tcd_t *p_tcd, opj_event_mgr_t *p_manage
|
|||
l_tile->numcomps,
|
||||
/* tells if the data is signed */
|
||||
p_tcd->image->comps->sgnd)) {
|
||||
opj_free(l_data);
|
||||
opj_manager_free(p_tcd->manager, l_data);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
opj_free(l_data);
|
||||
opj_manager_free(p_tcd->manager, l_data);
|
||||
}
|
||||
else {
|
||||
if (l_tcp->tccps->qmfbid == 1) {
|
||||
|
@ -1788,7 +1789,7 @@ static OPJ_BOOL opj_tcd_dc_level_shift_decode ( opj_tcd_t *p_tcd )
|
|||
/**
|
||||
* Deallocates the encoding data of the given precinct.
|
||||
*/
|
||||
static void opj_tcd_code_block_dec_deallocate (opj_tcd_precinct_t * p_precinct)
|
||||
static void opj_tcd_code_block_dec_deallocate (opj_manager_t manager, opj_tcd_precinct_t * p_precinct)
|
||||
{
|
||||
OPJ_UINT32 cblkno , l_nb_code_blocks;
|
||||
|
||||
|
@ -1806,19 +1807,19 @@ static void opj_tcd_code_block_dec_deallocate (opj_tcd_precinct_t * p_precinct)
|
|||
for (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno) {
|
||||
|
||||
if (l_code_block->data) {
|
||||
opj_free(l_code_block->data);
|
||||
opj_manager_free(manager, l_code_block->data);
|
||||
l_code_block->data = 00;
|
||||
}
|
||||
|
||||
if (l_code_block->segs) {
|
||||
opj_free(l_code_block->segs );
|
||||
opj_manager_free(manager, l_code_block->segs );
|
||||
l_code_block->segs = 00;
|
||||
}
|
||||
|
||||
++l_code_block;
|
||||
}
|
||||
|
||||
opj_free(p_precinct->cblks.dec);
|
||||
opj_manager_free(manager, p_precinct->cblks.dec);
|
||||
p_precinct->cblks.dec = 00;
|
||||
}
|
||||
}
|
||||
|
@ -1826,7 +1827,7 @@ static void opj_tcd_code_block_dec_deallocate (opj_tcd_precinct_t * p_precinct)
|
|||
/**
|
||||
* Deallocates the encoding data of the given precinct.
|
||||
*/
|
||||
static void opj_tcd_code_block_enc_deallocate (opj_tcd_precinct_t * p_precinct)
|
||||
static void opj_tcd_code_block_enc_deallocate (opj_manager_t manager, opj_tcd_precinct_t * p_precinct)
|
||||
{
|
||||
OPJ_UINT32 cblkno , l_nb_code_blocks;
|
||||
|
||||
|
@ -1836,23 +1837,23 @@ static void opj_tcd_code_block_enc_deallocate (opj_tcd_precinct_t * p_precinct)
|
|||
|
||||
for (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno) {
|
||||
if (l_code_block->data) {
|
||||
opj_free(l_code_block->data - 1);
|
||||
opj_manager_free(manager, l_code_block->data - 1);
|
||||
l_code_block->data = 00;
|
||||
}
|
||||
|
||||
if (l_code_block->layers) {
|
||||
opj_free(l_code_block->layers );
|
||||
opj_manager_free(manager, l_code_block->layers );
|
||||
l_code_block->layers = 00;
|
||||
}
|
||||
|
||||
if (l_code_block->passes) {
|
||||
opj_free(l_code_block->passes );
|
||||
opj_manager_free(manager, l_code_block->passes );
|
||||
l_code_block->passes = 00;
|
||||
}
|
||||
++l_code_block;
|
||||
}
|
||||
|
||||
opj_free(p_precinct->cblks.enc);
|
||||
opj_manager_free(manager, p_precinct->cblks.enc);
|
||||
|
||||
p_precinct->cblks.enc = 00;
|
||||
}
|
||||
|
@ -1945,7 +1946,7 @@ static OPJ_BOOL opj_tcd_mct_encode ( opj_tcd_t *p_tcd )
|
|||
return OPJ_TRUE;
|
||||
}
|
||||
|
||||
l_data = (OPJ_BYTE **) opj_malloc(l_tile->numcomps*sizeof(OPJ_BYTE*));
|
||||
l_data = (OPJ_BYTE **) opj_manager_malloc(p_tcd->manager, l_tile->numcomps*sizeof(OPJ_BYTE*));
|
||||
if (! l_data) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
@ -1955,7 +1956,7 @@ static OPJ_BOOL opj_tcd_mct_encode ( opj_tcd_t *p_tcd )
|
|||
++l_tile_comp;
|
||||
}
|
||||
|
||||
if (! opj_mct_encode_custom(/* MCT data */
|
||||
if (! opj_mct_encode_custom(p_tcd->manager, /* MCT data */
|
||||
(OPJ_BYTE*) p_tcd->tcp->m_mct_coding_matrix,
|
||||
/* size of components */
|
||||
samples,
|
||||
|
@ -1966,11 +1967,11 @@ static OPJ_BOOL opj_tcd_mct_encode ( opj_tcd_t *p_tcd )
|
|||
/* tells if the data is signed */
|
||||
p_tcd->image->comps->sgnd) )
|
||||
{
|
||||
opj_free(l_data);
|
||||
opj_manager_free(p_tcd->manager, l_data);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
opj_free(l_data);
|
||||
opj_manager_free(p_tcd->manager, l_data);
|
||||
}
|
||||
else if (l_tcp->tccps->qmfbid == 0) {
|
||||
opj_mct_encode_real(l_tile->comps[0].data, l_tile->comps[1].data, l_tile->comps[2].data, samples);
|
||||
|
@ -1991,12 +1992,12 @@ static OPJ_BOOL opj_tcd_dwt_encode ( opj_tcd_t *p_tcd )
|
|||
|
||||
for (compno = 0; compno < l_tile->numcomps; ++compno) {
|
||||
if (l_tccp->qmfbid == 1) {
|
||||
if (! opj_dwt_encode(l_tile_comp)) {
|
||||
if (! opj_dwt_encode(p_tcd->manager, l_tile_comp)) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
}
|
||||
else if (l_tccp->qmfbid == 0) {
|
||||
if (! opj_dwt_encode_real(l_tile_comp)) {
|
||||
if (! opj_dwt_encode_real(p_tcd->manager, l_tile_comp)) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -2015,7 +2016,7 @@ static OPJ_BOOL opj_tcd_t1_encode ( opj_tcd_t *p_tcd )
|
|||
OPJ_UINT32 l_mct_numcomps = 0U;
|
||||
opj_tcp_t * l_tcp = p_tcd->tcp;
|
||||
|
||||
l_t1 = opj_t1_create(OPJ_TRUE);
|
||||
l_t1 = opj_t1_create(p_tcd->manager, OPJ_TRUE);
|
||||
if (l_t1 == 00) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
@ -2053,7 +2054,7 @@ static OPJ_BOOL opj_tcd_t2_encode (opj_tcd_t *p_tcd,
|
|||
{
|
||||
opj_t2_t * l_t2;
|
||||
|
||||
l_t2 = opj_t2_create(p_tcd->image, p_tcd->cp);
|
||||
l_t2 = opj_t2_create(p_tcd->manager, p_tcd->image, p_tcd->cp);
|
||||
if (l_t2 == 00) {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
|
|
@ -198,6 +198,8 @@ Tile coder/decoder
|
|||
*/
|
||||
typedef struct opj_tcd
|
||||
{
|
||||
/** User memory/event manager */
|
||||
opj_manager_t manager;
|
||||
/** Position of the tilepart flag in Progression order*/
|
||||
OPJ_INT32 tp_pos;
|
||||
/** Tile part number*/
|
||||
|
@ -233,16 +235,17 @@ Dump the content of a tcd structure
|
|||
|
||||
/**
|
||||
Create a new TCD handle
|
||||
@param manager User memory/event manager
|
||||
@param p_is_decoder FIXME DOC
|
||||
@return Returns a new TCD handle if successful returns NULL otherwise
|
||||
*/
|
||||
opj_tcd_t* opj_tcd_create(OPJ_BOOL p_is_decoder);
|
||||
opj_tcd_t* opj_tcd_create(opj_manager_t manager, OPJ_BOOL p_is_decoder);
|
||||
|
||||
/**
|
||||
Destroy a previously created TCD handle
|
||||
@param tcd TCD handle to destroy
|
||||
*/
|
||||
void opj_tcd_destroy(opj_tcd_t *tcd);
|
||||
void opj_tcd_destroy(opj_manager_t manager,opj_tcd_t *tcd);
|
||||
|
||||
/**
|
||||
* Initialize the tile coder and may reuse some memory.
|
||||
|
@ -359,7 +362,7 @@ OPJ_BOOL opj_tcd_copy_tile_data (opj_tcd_t *p_tcd,
|
|||
*
|
||||
*
|
||||
*/
|
||||
OPJ_BOOL opj_alloc_tile_component_data(opj_tcd_tilecomp_t *l_tilec);
|
||||
OPJ_BOOL opj_alloc_tile_component_data(opj_manager_t manager, opj_tcd_tilecomp_t *l_tilec);
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/*@}*/
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
==========================================================
|
||||
*/
|
||||
|
||||
opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv, opj_event_mgr_t *manager) {
|
||||
opj_tgt_tree_t *opj_tgt_create(opj_manager_t manager, OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv) {
|
||||
OPJ_INT32 nplh[32];
|
||||
OPJ_INT32 nplv[32];
|
||||
opj_tgt_node_t *node = 00;
|
||||
|
@ -57,12 +57,13 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv, opj_e
|
|||
OPJ_UINT32 numlvls;
|
||||
OPJ_UINT32 n;
|
||||
|
||||
tree = (opj_tgt_tree_t *) opj_calloc(1,sizeof(opj_tgt_tree_t));
|
||||
tree = (opj_tgt_tree_t *) opj_manager_calloc(manager, 1,sizeof(opj_tgt_tree_t));
|
||||
if(!tree) {
|
||||
opj_event_msg(manager, EVT_ERROR, "Not enough memory to create Tag-tree\n");
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Not enough memory to create Tag-tree\n");
|
||||
return 00;
|
||||
}
|
||||
|
||||
tree->manager = manager;
|
||||
tree->numleafsh = numleafsh;
|
||||
tree->numleafsv = numleafsv;
|
||||
|
||||
|
@ -80,15 +81,15 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv, opj_e
|
|||
|
||||
/* ADD */
|
||||
if (tree->numnodes == 0) {
|
||||
opj_free(tree);
|
||||
opj_event_msg(manager, EVT_WARNING, "tgt_create tree->numnodes == 0, no tree created.\n");
|
||||
opj_manager_free(manager, tree);
|
||||
opj_event_msg(&(manager->event_mgr), EVT_WARNING, "tgt_create tree->numnodes == 0, no tree created.\n");
|
||||
return 00;
|
||||
}
|
||||
|
||||
tree->nodes = (opj_tgt_node_t*) opj_calloc(tree->numnodes, sizeof(opj_tgt_node_t));
|
||||
tree->nodes = (opj_tgt_node_t*) opj_manager_calloc(manager, tree->numnodes, sizeof(opj_tgt_node_t));
|
||||
if(!tree->nodes) {
|
||||
opj_event_msg(manager, EVT_ERROR, "Not enough memory to create Tag-tree nodes\n");
|
||||
opj_free(tree);
|
||||
opj_event_msg(&(manager->event_mgr), EVT_ERROR, "Not enough memory to create Tag-tree nodes\n");
|
||||
opj_manager_free(manager, tree);
|
||||
return 00;
|
||||
}
|
||||
tree->nodes_size = tree->numnodes * (OPJ_UINT32)sizeof(opj_tgt_node_t);
|
||||
|
@ -173,7 +174,7 @@ opj_tgt_tree_t *opj_tgt_init(opj_tgt_tree_t * p_tree,OPJ_UINT32 p_num_leafs_h, O
|
|||
l_node_size = p_tree->numnodes * (OPJ_UINT32)sizeof(opj_tgt_node_t);
|
||||
|
||||
if (l_node_size > p_tree->nodes_size) {
|
||||
opj_tgt_node_t* new_nodes = (opj_tgt_node_t*) opj_realloc(p_tree->nodes, l_node_size);
|
||||
opj_tgt_node_t* new_nodes = (opj_tgt_node_t*) opj_manager_realloc(p_tree->manager, p_tree->nodes, l_node_size);
|
||||
if (! new_nodes) {
|
||||
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to reinitialize the tag tree\n");
|
||||
opj_tgt_destroy(p_tree);
|
||||
|
@ -219,15 +220,17 @@ opj_tgt_tree_t *opj_tgt_init(opj_tgt_tree_t * p_tree,OPJ_UINT32 p_num_leafs_h, O
|
|||
|
||||
void opj_tgt_destroy(opj_tgt_tree_t *p_tree)
|
||||
{
|
||||
if (! p_tree) {
|
||||
return;
|
||||
}
|
||||
opj_manager_t manager = NULL;
|
||||
if (! p_tree) {
|
||||
return;
|
||||
}
|
||||
manager = p_tree->manager;
|
||||
|
||||
if (p_tree->nodes) {
|
||||
opj_free(p_tree->nodes);
|
||||
p_tree->nodes = 00;
|
||||
}
|
||||
opj_free(p_tree);
|
||||
if (p_tree->nodes) {
|
||||
opj_manager_free(manager, p_tree->nodes);
|
||||
p_tree->nodes = 00;
|
||||
}
|
||||
opj_manager_free(manager, p_tree);
|
||||
}
|
||||
|
||||
void opj_tgt_reset(opj_tgt_tree_t *p_tree) {
|
||||
|
|
|
@ -66,11 +66,12 @@ Tag tree
|
|||
*/
|
||||
typedef struct opj_tgt_tree
|
||||
{
|
||||
OPJ_UINT32 numleafsh;
|
||||
OPJ_UINT32 numleafsv;
|
||||
OPJ_UINT32 numnodes;
|
||||
opj_manager_t manager;
|
||||
opj_tgt_node_t *nodes;
|
||||
OPJ_UINT32 nodes_size; /* maximum size taken by nodes */
|
||||
OPJ_UINT32 numleafsh;
|
||||
OPJ_UINT32 numleafsv;
|
||||
OPJ_UINT32 numnodes;
|
||||
OPJ_UINT32 nodes_size; /* maximum size taken by nodes */
|
||||
} opj_tgt_tree_t;
|
||||
|
||||
|
||||
|
@ -83,7 +84,7 @@ Create a tag-tree
|
|||
@param numleafsv Height of the array of leafs of the tree
|
||||
@return Returns a new tag-tree if successful, returns NULL otherwise
|
||||
*/
|
||||
opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv, opj_event_mgr_t *manager);
|
||||
opj_tgt_tree_t *opj_tgt_create(opj_manager_t manager, OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv);
|
||||
|
||||
/**
|
||||
* Reinitialises a tag-tree from an exixting one.
|
||||
|
|
Loading…
Reference in New Issue