From 7199d9b5d32e9974afa62243756b027fc394f860 Mon Sep 17 00:00:00 2001 From: Antonin Descampe Date: Thu, 17 Apr 2014 09:31:37 +0000 Subject: [PATCH] [trunk] refactoring of rsiz, profiles, and extensions management --- src/bin/jp2/convert.c | 9 +- src/bin/jp2/opj_compress.c | 10 +- src/lib/openjp2/j2k.c | 264 ++++++++++++++++++++++--------------- src/lib/openjp2/j2k.h | 4 +- src/lib/openjp2/openjpeg.c | 12 +- src/lib/openjp2/openjpeg.h | 126 ++++++++++++++---- src/lib/openjp2/pi.c | 4 +- src/lib/openjp2/t2.c | 2 +- src/lib/openjp2/tcd.c | 2 +- 9 files changed, 288 insertions(+), 145 deletions(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index b41618c7..1b2d3618 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -2597,6 +2597,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) int has_alpha = 0; unsigned short tiBps, tiPhoto, tiSf, tiSpp, tiPC; unsigned int tiWidth, tiHeight; + OPJ_BOOL is_cinema = OPJ_IS_CINEMA(parameters->rsiz); tif = TIFFOpen(filename, "r"); @@ -2669,7 +2670,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) */ memset(&cmptparm[0], 0, 4 * sizeof(opj_image_cmptparm_t)); - if ((tiPhoto == PHOTOMETRIC_RGB) && (parameters->cp_cinema)) { + if ((tiPhoto == PHOTOMETRIC_RGB) && (is_cinema)) { fprintf(stdout,"WARNING:\n" "Input image bitdepth is %d bits\n" "TIF conversion has automatically rescaled to 12-bits\n" @@ -2685,7 +2686,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) /*#define USETILEMODE*/ for(j = 0; j < numcomps; j++) { - if(parameters->cp_cinema) + if(is_cinema) { cmptparm[j].prec = 12; cmptparm[j].bpp = 12; @@ -2754,7 +2755,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) if(has_alpha) image->comps[3].data[index] = ( dat8[i+7] << 8 ) | dat8[i+6]; - if(parameters->cp_cinema) + if(is_cinema) { /* Rounding 16 to 12 bits */ @@ -2791,7 +2792,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) image->comps[3].data[index] = dat8[i+3]; #endif - if(parameters->cp_cinema) + if(is_cinema) { /* Rounding 8 to 12 bits */ diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index b8cdafcd..aba30ef9 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -968,9 +968,13 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param int fps=0; sscanf(opj_optarg,"%d",&fps); if(fps == 24){ - parameters->cp_cinema = OPJ_CINEMA2K_24; + parameters->rsiz = OPJ_PROFILE_CINEMA_2K; + parameters->max_comp_size = OPJ_CINEMA_24_COMP; + parameters->max_cs_size = OPJ_CINEMA_24_CS; }else if(fps == 48 ){ - parameters->cp_cinema = OPJ_CINEMA2K_48; + parameters->rsiz = OPJ_PROFILE_CINEMA_2K; + parameters->max_comp_size = OPJ_CINEMA_48_COMP; + parameters->max_cs_size = OPJ_CINEMA_48_CS; }else { fprintf(stderr,"Incorrect value!! must be 24 or 48\n"); return 1; @@ -985,7 +989,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param case 'y': /* Digital Cinema 4K profile compliance*/ { - parameters->cp_cinema = OPJ_CINEMA4K_24; + parameters->rsiz = OPJ_PROFILE_CINEMA_4K; fprintf(stdout,"CINEMA 4K profile activated\n" "Other options specified could be overriden\n"); } diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 1b7e5bc0..1e6024eb 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -42,11 +42,6 @@ #include "opj_includes.h" -#define CINEMA_24_CS 1302083 /*Codestream length for 24fps*/ -#define CINEMA_48_CS 651041 /*Codestream length for 48fps*/ -#define COMP_24_CS 1041666 /*Maximum size per color component for 2K & 4K @ 24fps*/ -#define COMP_48_CS 520833 /*Maximum size per color component for 2K @ 48fps*/ - /** @defgroup J2K J2K - JPEG-2000 codestream reader/writer */ /*@{*/ @@ -1172,7 +1167,7 @@ static int opj_j2k_initialise_4K_poc(opj_poc_t *POC, int numres); static void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *image, opj_event_mgr_t *p_manager); -static OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_CINEMA_MODE cinema_mode, opj_event_mgr_t *p_manager); +static OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_UINT16 rsiz, opj_event_mgr_t *p_manager); /*@}*/ @@ -1945,7 +1940,7 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, opj_read_bytes(p_header_data,&l_tmp ,2); /* Rsiz (capabilities) */ p_header_data+=2; - l_cp->rsiz = (OPJ_RSIZ_CAPABILITIES) l_tmp; + l_cp->rsiz = (OPJ_UINT16) l_tmp; opj_read_bytes(p_header_data, (OPJ_UINT32*) &l_image->x1, 4); /* Xsiz */ p_header_data+=4; opj_read_bytes(p_header_data, (OPJ_UINT32*) &l_image->y1, 4); /* Ysiz */ @@ -3102,7 +3097,7 @@ OPJ_UINT32 opj_j2k_get_specific_header_sizes(opj_j2k_t *p_j2k) l_nb_comps = p_j2k->m_private_image->numcomps - 1; l_nb_bytes += opj_j2k_get_max_toc_size(p_j2k); - if (p_j2k->m_cp.m_specific_param.m_enc.m_cinema == 0) { + if (!(OPJ_IS_CINEMA(p_j2k->m_cp.rsiz))) { l_coc_bytes = opj_j2k_get_max_coc_size(p_j2k); l_nb_bytes += l_nb_comps * l_coc_bytes; @@ -4722,7 +4717,7 @@ OPJ_BOOL opj_j2k_update_rates( opj_j2k_t *p_j2k, return OPJ_FALSE; } - if (l_cp->m_specific_param.m_enc.m_cinema) { + if (OPJ_IS_CINEMA(l_cp->rsiz)) { p_j2k->m_specific_param.m_encoder.m_tlm_sot_offsets_buffer = (OPJ_BYTE *) opj_malloc(5*p_j2k->m_specific_param.m_encoder.m_total_tile_parts); if (! p_j2k->m_specific_param.m_encoder.m_tlm_sot_offsets_buffer) { @@ -5914,24 +5909,8 @@ int opj_j2k_initialise_4K_poc(opj_poc_t *POC, int numres){ void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *image, opj_event_mgr_t *p_manager) { /* Configure cinema parameters */ - OPJ_FLOAT32 max_rate = 0; - OPJ_FLOAT32 temp_rate = 0; int i; - /* profile (Rsiz) */ - switch (parameters->cp_cinema){ - case OPJ_CINEMA2K_24: - case OPJ_CINEMA2K_48: - parameters->cp_rsiz = OPJ_CINEMA2K; - break; - case OPJ_CINEMA4K_24: - parameters->cp_rsiz = OPJ_CINEMA4K; - break; - case OPJ_OFF: - assert(0); - break; - } - /* No tiling */ parameters->tile_size_on = OPJ_FALSE; parameters->cp_tdx=1; @@ -5969,15 +5948,16 @@ void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *i opj_event_msg(p_manager, EVT_WARNING, "JPEG 2000 Profile-3 and 4 (2k/4k dc profile) requires:\n" "1 single quality layer" - "-> Number of layers forced to 1 (rather than %d)\n", - parameters->tcp_numlayers); + "-> Number of layers forced to 1 (rather than %d)\n" + "-> Rate of the last layer (%3.1f) will be used", + parameters->tcp_numlayers, parameters->tcp_rates[parameters->tcp_numlayers-1]); + parameters->tcp_rates[0] = parameters->tcp_rates[parameters->tcp_numlayers-1]; parameters->tcp_numlayers = 1; } /* Resolution levels */ - switch (parameters->cp_cinema){ - case OPJ_CINEMA2K_24: - case OPJ_CINEMA2K_48: + switch (parameters->rsiz){ + case OPJ_PROFILE_CINEMA_2K: if(parameters->numresolution > 6){ opj_event_msg(p_manager, EVT_WARNING, "JPEG 2000 Profile-3 (2k dc profile) requires:\n" @@ -5987,7 +5967,7 @@ void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *i parameters->numresolution = 6; } break; - case OPJ_CINEMA4K_24: + case OPJ_PROFILE_CINEMA_4K: if(parameters->numresolution < 2){ opj_event_msg(p_manager, EVT_WARNING, "JPEG 2000 Profile-4 (4k dc profile) requires:\n" @@ -6020,7 +6000,7 @@ void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *i parameters->prog_order = OPJ_CPRL; /* Progression order changes for 4K, disallowed for 2K */ - if (parameters->cp_cinema == OPJ_CINEMA4K_24) { + if (parameters->rsiz == OPJ_PROFILE_CINEMA_4K) { parameters->numpocs = (OPJ_UINT32)opj_j2k_initialise_4K_poc(parameters->POC,parameters->numresolution); } else { parameters->numpocs = 0; @@ -6028,62 +6008,42 @@ void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *i /* Limited bit-rate */ parameters->cp_disto_alloc = 1; - switch (parameters->cp_cinema){ - case OPJ_CINEMA2K_24: - case OPJ_CINEMA4K_24: - max_rate = (OPJ_FLOAT32) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)/ - (OPJ_FLOAT32)(CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy); - if (parameters->tcp_rates[0] == 0){ - parameters->tcp_rates[0] = max_rate; - }else{ - temp_rate =(OPJ_FLOAT32)(image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)/ - (parameters->tcp_rates[0] * 8 * (OPJ_FLOAT32)image->comps[0].dx * (OPJ_FLOAT32)image->comps[0].dy); - if (temp_rate > CINEMA_24_CS ){ - opj_event_msg(p_manager, EVT_WARNING, - "JPEG 2000 Profile-3 and 4 (2k/4k dc profile) requires:\n" - "Maximum 1302083 compressed bytes @ 24fps\n" - "-> Specified rate (%3.1f) exceeds this limit. Rate will be forced to %3.1f.\n", - parameters->tcp_rates[0], max_rate); - parameters->tcp_rates[0]= max_rate; - }else{ - opj_event_msg(p_manager, EVT_WARNING, - "JPEG 2000 Profile-3 and 4 (2k/4k dc profile):\n" - "INFO : Specified rate (%3.1f) is below the 2k/4k limit @ 24fps.\n", - parameters->tcp_rates[0]); - } - } - parameters->max_comp_size = COMP_24_CS; - break; - case OPJ_CINEMA2K_48: - max_rate = ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (float)(CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy); - if (parameters->tcp_rates[0] == 0){ - parameters->tcp_rates[0] = max_rate; - }else{ - temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (parameters->tcp_rates[0] * 8 * (float)image->comps[0].dx * (float)image->comps[0].dy); - if (temp_rate > CINEMA_48_CS ){ - opj_event_msg(p_manager, EVT_WARNING, - "JPEG 2000 Profile-3 (2k dc profile) requires:\n" - "Maximum 651041 compressed bytes @ 48fps\n" - "-> Specified rate (%3.1f) exceeds this limit. Rate will be forced to %3.1f.\n", - parameters->tcp_rates[0], max_rate); - parameters->tcp_rates[0]= max_rate; - }else{ - opj_event_msg(p_manager, EVT_WARNING, - "JPEG 2000 Profile-3 (2k dc profile):\n" - "INFO : Specified rate (%3.1f) is below the 2k limit @ 48 fps.\n", - parameters->tcp_rates[0]); - } - } - parameters->max_comp_size = COMP_48_CS; - break; - default: - break; + if (parameters->max_cs_size <= 0) { + /* No rate has been introduced, 24 fps is assumed */ + parameters->max_cs_size = OPJ_CINEMA_24_CS; + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Profile-3 and 4 (2k/4k dc profile) requires:\n" + "Maximum 1302083 compressed bytes @ 24fps\n" + "As no rate has been given, this limit will be used.\n"); + } else if (parameters->max_cs_size > OPJ_CINEMA_24_CS) { + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Profile-3 and 4 (2k/4k dc profile) requires:\n" + "Maximum 1302083 compressed bytes @ 24fps\n" + "-> Specified rate exceeds this limit. Rate will be forced to 1302083 bytes.\n"); + parameters->max_cs_size = OPJ_CINEMA_24_CS; + } + + if (parameters->max_comp_size <= 0) { + /* No rate has been introduced, 24 fps is assumed */ + parameters->max_comp_size = OPJ_CINEMA_24_COMP; + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Profile-3 and 4 (2k/4k dc profile) requires:\n" + "Maximum 1041666 compressed bytes @ 24fps\n" + "As no rate has been given, this limit will be used.\n"); + } else if (parameters->max_comp_size > OPJ_CINEMA_24_COMP) { + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Profile-3 and 4 (2k/4k dc profile) requires:\n" + "Maximum 1041666 compressed bytes @ 24fps\n" + "-> Specified rate exceeds this limit. Rate will be forced to 1041666 bytes.\n"); + parameters->max_comp_size = OPJ_CINEMA_24_COMP; } + + parameters->tcp_rates[0] = (OPJ_FLOAT32) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)/ + (OPJ_FLOAT32)(parameters->max_cs_size * 8 * image->comps[0].dx * image->comps[0].dy); + } -OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_CINEMA_MODE cinema_mode, opj_event_mgr_t *p_manager) +OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_UINT16 rsiz, opj_event_mgr_t *p_manager) { OPJ_UINT32 i; @@ -6115,9 +6075,8 @@ OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_CINEMA_MODE cinema_ } /* Image size */ - switch (cinema_mode){ - case OPJ_CINEMA2K_24: - case OPJ_CINEMA2K_48: + switch (rsiz){ + case OPJ_PROFILE_CINEMA_2K: if (((image->comps[0].w > 2048) | (image->comps[0].h > 1080))){ opj_event_msg(p_manager, EVT_WARNING, "JPEG 2000 Profile-3 (2k dc profile) requires:\n" @@ -6128,7 +6087,7 @@ OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_CINEMA_MODE cinema_ return OPJ_FALSE; } break; - case OPJ_CINEMA4K_24: + case OPJ_PROFILE_CINEMA_4K: if (((image->comps[0].w > 4096) | (image->comps[0].h > 2160))){ opj_event_msg(p_manager, EVT_WARNING, "JPEG 2000 Profile-4 (4k dc profile) requires:\n" @@ -6165,20 +6124,117 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, cp->tw = 1; cp->th = 1; + /* FIXME ADE: to be removed once deprecated cp_cinema and cp_rsiz have been removed */ + if (parameters->rsiz == OPJ_PROFILE_NONE) { /* consider deprecated fields only if RSIZ has not been set */ + switch (parameters->cp_cinema){ + case OPJ_CINEMA2K_24: + parameters->rsiz = OPJ_PROFILE_CINEMA_2K; + parameters->max_cs_size = OPJ_CINEMA_24_CS; + parameters->max_comp_size = OPJ_CINEMA_24_COMP; + break; + case OPJ_CINEMA2K_48: + parameters->rsiz = OPJ_PROFILE_CINEMA_2K; + parameters->max_cs_size = OPJ_CINEMA_48_CS; + parameters->max_comp_size = OPJ_CINEMA_48_COMP; + break; + case OPJ_CINEMA4K_24: + parameters->rsiz = OPJ_PROFILE_CINEMA_4K; + parameters->max_cs_size = OPJ_CINEMA_24_CS; + parameters->max_comp_size = OPJ_CINEMA_24_COMP; + break; + case OPJ_OFF: + default: + break; + } + switch (parameters->cp_rsiz){ + case OPJ_CINEMA2K: + parameters->rsiz = OPJ_PROFILE_CINEMA_2K; + break; + case OPJ_CINEMA4K: + parameters->rsiz = OPJ_PROFILE_CINEMA_4K; + break; + case OPJ_MCT: + parameters->rsiz = OPJ_PROFILE_PART2 | OPJ_EXTENSION_MCT; + case OPJ_STD_RSIZ: + default: + break; + } + } + + /* see if max_codestream_size does limit input rate */ + if (parameters->max_cs_size <= 0) { + if (parameters->tcp_rates[parameters->tcp_numlayers-1] > 0) { + OPJ_FLOAT32 temp_size; + temp_size =(OPJ_FLOAT32)(image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)/ + (parameters->tcp_rates[parameters->tcp_numlayers-1] * 8 * (OPJ_FLOAT32)image->comps[0].dx * (OPJ_FLOAT32)image->comps[0].dy); + parameters->max_cs_size = (int) floor(temp_size); + } else { + parameters->max_cs_size = 0; + } + } else { + OPJ_FLOAT32 temp_rate; + OPJ_BOOL cap = OPJ_FALSE; + temp_rate = (OPJ_FLOAT32) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)/ + (OPJ_FLOAT32)(parameters->max_cs_size * 8 * image->comps[0].dx * image->comps[0].dy); + for (i = 0; i < (OPJ_UINT32) parameters->tcp_numlayers; i++) { + if (parameters->tcp_rates[i] < temp_rate) { + parameters->tcp_rates[i] = temp_rate; + cap = OPJ_TRUE; + } + } + if (cap) { + opj_event_msg(p_manager, EVT_WARNING, + "The desired maximum codestream size has limited\n" + "at least one of the desired quality layers\n"); + } + } + + /* Manage profiles and applications and set RSIZ */ /* set cinema parameters if required */ - if (parameters->cp_cinema){ - opj_j2k_set_cinema_parameters(parameters,image,p_manager); - if (!opj_j2k_is_cinema_compliant(image,parameters->cp_cinema,p_manager)) { - parameters->cp_rsiz = OPJ_STD_RSIZ; + if (OPJ_IS_CINEMA(parameters->rsiz)){ + if ((parameters->rsiz == OPJ_PROFILE_CINEMA_S2K) + || (parameters->rsiz == OPJ_PROFILE_CINEMA_S4K)){ + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Scalable Digital Cinema profiles not yet supported\n"); + parameters->rsiz = OPJ_PROFILE_NONE; + } else { + opj_j2k_set_cinema_parameters(parameters,image,p_manager); + if (!opj_j2k_is_cinema_compliant(image,parameters->rsiz,p_manager)) { + parameters->rsiz = OPJ_PROFILE_NONE; + } + } + } else if (OPJ_IS_STORAGE(parameters->rsiz)) { + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Long Term Storage profile not yet supported\n"); + parameters->rsiz = OPJ_PROFILE_NONE; + } else if (OPJ_IS_BROADCAST(parameters->rsiz)) { + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Broadcast profiles not yet supported\n"); + parameters->rsiz = OPJ_PROFILE_NONE; + } else if (OPJ_IS_IMF(parameters->rsiz)) { + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 IMF profiles not yet supported\n"); + parameters->rsiz = OPJ_PROFILE_NONE; + } else if (OPJ_IS_PART2(parameters->rsiz)) { + if (parameters->rsiz == ((OPJ_PROFILE_PART2) | (OPJ_EXTENSION_NONE))) { + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Part-2 profile defined\n" + "but no Part-2 extension enabled.\n" + "Profile set to NONE.\n"); + parameters->rsiz = OPJ_PROFILE_NONE; + } else if (parameters->rsiz != ((OPJ_PROFILE_PART2) | (OPJ_EXTENSION_MCT))) { + opj_event_msg(p_manager, EVT_WARNING, + "Unsupported Part-2 extension enabled\n" + "Profile set to NONE.\n"); + parameters->rsiz = OPJ_PROFILE_NONE; } } /* copy user encoding parameters */ - cp->m_specific_param.m_enc.m_cinema = parameters->cp_cinema; cp->m_specific_param.m_enc.m_max_comp_size = (OPJ_UINT32)parameters->max_comp_size; - cp->rsiz = parameters->cp_rsiz; + cp->rsiz = parameters->rsiz; cp->m_specific_param.m_enc.m_disto_alloc = (OPJ_UINT32)parameters->cp_disto_alloc & 1u; cp->m_specific_param.m_enc.m_fixed_alloc = (OPJ_UINT32)parameters->cp_fixed_alloc & 1u; cp->m_specific_param.m_enc.m_fixed_quality = (OPJ_UINT32)parameters->cp_fixed_quality & 1u; @@ -6293,7 +6349,7 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, tcp->numlayers = (OPJ_UINT32)parameters->tcp_numlayers; for (j = 0; j < tcp->numlayers; j++) { - if(cp->m_specific_param.m_enc.m_cinema){ + if(OPJ_IS_CINEMA(cp->rsiz)){ if (cp->m_specific_param.m_enc.m_fixed_quality) { tcp->distoratio[j] = parameters->tcp_distoratio[j]; } @@ -9798,7 +9854,7 @@ void opj_j2k_setup_end_compress (opj_j2k_t *p_j2k) /* DEVELOPER CORNER, insert your custom procedures */ opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)opj_j2k_write_eoc ); - if (p_j2k->m_cp.m_specific_param.m_enc.m_cinema) { + if (OPJ_IS_CINEMA(p_j2k->m_cp.rsiz)) { opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)opj_j2k_write_updated_tlm); } @@ -9830,14 +9886,14 @@ void opj_j2k_setup_header_writing (opj_j2k_t *p_j2k) opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)opj_j2k_write_cod ); opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)opj_j2k_write_qcd ); - if (p_j2k->m_cp.m_specific_param.m_enc.m_cinema) { + if (OPJ_IS_CINEMA(p_j2k->m_cp.rsiz)) { /* No need for COC or QCC, QCD and COD are used opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)opj_j2k_write_all_coc ); opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)opj_j2k_write_all_qcc ); */ opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)opj_j2k_write_tlm ); - if (p_j2k->m_cp.m_specific_param.m_enc.m_cinema == OPJ_CINEMA4K_24) { + if (p_j2k->m_cp.rsiz == OPJ_PROFILE_CINEMA_4K) { opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)opj_j2k_write_poc ); } } @@ -9849,7 +9905,7 @@ void opj_j2k_setup_header_writing (opj_j2k_t *p_j2k) } /* DEVELOPER CORNER, insert your custom procedures */ - if (p_j2k->m_cp.rsiz & OPJ_MCT) { + if (p_j2k->m_cp.rsiz & OPJ_EXTENSION_MCT) { opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)opj_j2k_write_mct_data_group ); } /* End of Developer Corner */ @@ -9898,7 +9954,7 @@ OPJ_BOOL opj_j2k_write_first_tile_part (opj_j2k_t *p_j2k, p_data += l_current_nb_bytes_written; p_total_data_size -= l_current_nb_bytes_written; - if (l_cp->m_specific_param.m_enc.m_cinema == 0) { + if (!OPJ_IS_CINEMA(l_cp->rsiz)) { #if 0 for (compno = 1; compno < p_j2k->m_private_image->numcomps; compno++) { l_current_nb_bytes_written = 0; @@ -9935,7 +9991,7 @@ OPJ_BOOL opj_j2k_write_first_tile_part (opj_j2k_t *p_j2k, /* Writing Psot in SOT marker */ opj_write_bytes(l_begin_data + 6,l_nb_bytes_written,4); /* PSOT */ - if (l_cp->m_specific_param.m_enc.m_cinema){ + if (OPJ_IS_CINEMA(l_cp->rsiz)){ opj_j2k_update_tlm(p_j2k,l_nb_bytes_written); } @@ -9999,7 +10055,7 @@ OPJ_BOOL opj_j2k_write_all_tile_parts( opj_j2k_t *p_j2k, /* Writing Psot in SOT marker */ opj_write_bytes(l_begin_data + 6,l_part_tile_size,4); /* PSOT */ - if (l_cp->m_specific_param.m_enc.m_cinema) { + if (OPJ_IS_CINEMA(l_cp->rsiz)) { opj_j2k_update_tlm(p_j2k,l_part_tile_size); } @@ -10040,7 +10096,7 @@ OPJ_BOOL opj_j2k_write_all_tile_parts( opj_j2k_t *p_j2k, /* Writing Psot in SOT marker */ opj_write_bytes(l_begin_data + 6,l_part_tile_size,4); /* PSOT */ - if (l_cp->m_specific_param.m_enc.m_cinema) { + if (OPJ_IS_CINEMA(l_cp->rsiz)) { opj_j2k_update_tlm(p_j2k,l_part_tile_size); } diff --git a/src/lib/openjp2/j2k.h b/src/lib/openjp2/j2k.h index 4228bd66..d0f59d72 100644 --- a/src/lib/openjp2/j2k.h +++ b/src/lib/openjp2/j2k.h @@ -304,8 +304,6 @@ typedef struct opj_tcp typedef struct opj_encoding_param { - /** Digital cinema profile*/ - OPJ_CINEMA_MODE m_cinema; /** Maximum rate for each component. If == 0, component size limitation is not considered */ OPJ_UINT32 m_max_comp_size; /** Position of tile part flag in progression order*/ @@ -343,7 +341,7 @@ typedef struct opj_cp /** Size of the image in bits*/ /*int img_size;*/ /** Rsiz*/ - OPJ_RSIZ_CAPABILITIES rsiz; + OPJ_UINT16 rsiz; /** XTOsiz */ OPJ_UINT32 tx0; /* MSD see norm */ /** YTOsiz */ diff --git a/src/lib/openjp2/openjpeg.c b/src/lib/openjp2/openjpeg.c index 89bb75a5..c53604d3 100644 --- a/src/lib/openjp2/openjpeg.c +++ b/src/lib/openjp2/openjpeg.c @@ -639,10 +639,11 @@ void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *paramete if(parameters) { memset(parameters, 0, sizeof(opj_cparameters_t)); /* default coding parameters */ - parameters->cp_cinema = OPJ_OFF; + parameters->cp_cinema = OPJ_OFF; /* DEPRECATED */ + parameters->rsiz = OPJ_PROFILE_NONE; parameters->max_comp_size = 0; parameters->numresolution = 6; - parameters->cp_rsiz = OPJ_STD_RSIZ; + parameters->cp_rsiz = OPJ_STD_RSIZ; /* DEPRECATED */ parameters->cblockw_init = 64; parameters->cblockh_init = 64; parameters->prog_order = OPJ_LRCP; @@ -793,8 +794,11 @@ OPJ_BOOL OPJ_CALLCONV opj_set_MCT(opj_cparameters_t *parameters, OPJ_UINT32 l_mct_total_size = l_matrix_size + l_dc_shift_size; /* add MCT capability */ - OPJ_INT32 rsiz = (OPJ_INT32)parameters->cp_rsiz | (OPJ_INT32)OPJ_MCT; - parameters->cp_rsiz = (OPJ_RSIZ_CAPABILITIES)rsiz; + if (OPJ_IS_PART2(parameters->rsiz)) { + parameters->rsiz |= OPJ_EXTENSION_MCT; + } else { + parameters->rsiz = ((OPJ_PROFILE_PART2) | (OPJ_EXTENSION_MCT)); + } parameters->irreversible = 1; /* use array based MCT */ diff --git a/src/lib/openjp2/openjpeg.h b/src/lib/openjp2/openjpeg.h index 9bf014b4..b5b1e25a 100644 --- a/src/lib/openjp2/openjpeg.h +++ b/src/lib/openjp2/openjpeg.h @@ -173,30 +173,88 @@ typedef size_t OPJ_SIZE_T; #define OPJ_JP2_INFO 128 /**< JP2 file information */ #define OPJ_JP2_IND 256 /**< JP2 file index */ +/** + * JPEG 2000 Profiles, see Table A.10 from 15444-1 (updated in various AMD) + * These values help chosing the RSIZ value for the J2K codestream. + * The RSIZ value triggers various encoding options, as detailed in Table A.10. + * If OPJ_PROFILE_PART2 is chosen, it has to be combined with one or more extensions + * described hereunder. + * Example: rsiz = OPJ_PROFILE_PART2 | OPJ_EXTENSION_MCT; + * For broadcast profiles, the OPJ_PROFILE value has to be combined with the targeted + * mainlevel (3-0 LSB, value between 0 and 11): + * Example: rsiz = OPJ_PROFILE_BC_MULTI | 0x0005; (here mainlevel 5) + * For IMF profiles, the OPJ_PROFILE value has to be combined with the targeted mainlevel + * (3-0 LSB, value between 0 and 11) and sublevel (7-4 LSB, value between 0 and 9): + * Example: rsiz = OPJ_PROFILE_IMF_2K | 0x0040 | 0x0005; (here main 5 and sublevel 4) + * */ +#define OPJ_PROFILE_NONE 0x0000 /** no profile, conform to 15444-1 */ +#define OPJ_PROFILE_0 0x0001 /** Profile 0 as described in 15444-1,Table A.45 */ +#define OPJ_PROFILE_1 0x0002 /** Profile 1 as described in 15444-1,Table A.45 */ +#define OPJ_PROFILE_PART2 0x8000 /** At least 1 extension defined in 15444-2 (Part-2) */ +#define OPJ_PROFILE_CINEMA_2K 0x0003 /** 2K cinema profile defined in 15444-1 AMD1 */ +#define OPJ_PROFILE_CINEMA_4K 0x0004 /** 4K cinema profile defined in 15444-1 AMD1 */ +#define OPJ_PROFILE_CINEMA_S2K 0x0005 /** Scalable 2K cinema profile defined in 15444-1 AMD2 */ +#define OPJ_PROFILE_CINEMA_S4K 0x0006 /** Scalable 4K cinema profile defined in 15444-1 AMD2 */ +#define OPJ_PROFILE_CINEMA_LTS 0x0007 /** Long term storage cinema profile defined in 15444-1 AMD2 */ +#define OPJ_PROFILE_BC_SINGLE 0x0100 /** Single Tile Broadcast profile defined in 15444-1 AMD3 */ +#define OPJ_PROFILE_BC_MULTI 0x0200 /** Multi Tile Broadcast profile defined in 15444-1 AMD3 */ +#define OPJ_PROFILE_BC_MULTI_R 0x0300 /** Multi Tile Reversible Broadcast profile defined in 15444-1 AMD3 */ +#define OPJ_PROFILE_IMF_2K 0x0400 /** 2K Single Tile Lossy IMF profile defined in 15444-1 AMD 8 */ +#define OPJ_PROFILE_IMF_4K 0x0401 /** 4K Single Tile Lossy IMF profile defined in 15444-1 AMD 8 */ +#define OPJ_PROFILE_IMF_8K 0x0402 /** 8K Single Tile Lossy IMF profile defined in 15444-1 AMD 8 */ +#define OPJ_PROFILE_IMF_2K_R 0x0403 /** 2K Single/Multi Tile Reversible IMF profile defined in 15444-1 AMD 8 */ +#define OPJ_PROFILE_IMF_4K_R 0x0800 /** 4K Single/Multi Tile Reversible IMF profile defined in 15444-1 AMD 8 */ +#define OPJ_PROFILE_IMF_8K_R 0x0801 /** 8K Single/Multi Tile Reversible IMF profile defined in 15444-1 AMD 8 */ + +/** + * JPEG 2000 Part-2 extensions + * */ +#define OPJ_EXTENSION_NONE 0x0000 /** No Part-2 extension */ +#define OPJ_EXTENSION_MCT 0x0100 /** Custom MCT support */ + +/** + * JPEG 2000 profile macros + * */ +#define OPJ_IS_CINEMA(v) (((v) >= OPJ_PROFILE_CINEMA_2K)&&((v) <= OPJ_PROFILE_CINEMA_S4K)) +#define OPJ_IS_STORAGE(v) ((v) == OPJ_PROFILE_CINEMA_LTS) +#define OPJ_IS_BROADCAST(v) (((v) >= OPJ_PROFILE_BC_SINGLE)&&((v) <= ((OPJ_PROFILE_BC_MULTI_R) | (0x000b)))) +#define OPJ_IS_IMF(v) (((v) >= OPJ_PROFILE_IMF_2K)&&((v) <= ((OPJ_PROFILE_IMF_8K_R) | (0x009b)))) +#define OPJ_IS_PART2(v) ((v) & OPJ_PROFILE_PART2) + +/** + * JPEG 2000 codestream and component size limits in cinema profiles + * */ +#define OPJ_CINEMA_24_CS 1302083 /** Maximum codestream length for 24fps */ +#define OPJ_CINEMA_48_CS 651041 /** Maximum codestream length for 48fps */ +#define OPJ_CINEMA_24_COMP 1041666 /** Maximum size per color component for 2K & 4K @ 24fps */ +#define OPJ_CINEMA_48_COMP 520833 /** Maximum size per color component for 2K @ 48fps */ /* ========================================================== enum definitions ========================================================== */ -/** + +/** + * DEPRECATED: use RSIZ, OPJ_PROFILE_* and OPJ_EXTENSION_* instead * Rsiz Capabilities * */ typedef enum RSIZ_CAPABILITIES { - OPJ_STD_RSIZ = 0, /** Standard JPEG2000 profile*/ - OPJ_CINEMA2K = 3, /** Profile name for a 2K image*/ - OPJ_CINEMA4K = 4, /** Profile name for a 4K image*/ - OPJ_MCT = 0x8100 + OPJ_STD_RSIZ = 0, /** Standard JPEG2000 profile*/ + OPJ_CINEMA2K = 3, /** Profile name for a 2K image*/ + OPJ_CINEMA4K = 4, /** Profile name for a 4K image*/ + OPJ_MCT = 0x8100 } OPJ_RSIZ_CAPABILITIES; -/** +/** + * DEPRECATED: use RSIZ, OPJ_PROFILE_* and OPJ_EXTENSION_* instead * Digital cinema operation mode * */ typedef enum CINEMA_MODE { - OPJ_OFF = 0, /** Not Digital Cinema*/ - OPJ_CINEMA2K_24 = 1, /** 2K Digital Cinema at 24 fps*/ - OPJ_CINEMA2K_48 = 2, /** 2K Digital Cinema at 48 fps*/ - OPJ_CINEMA4K_24 = 3 /** 4K Digital Cinema at 24 fps*/ + OPJ_OFF = 0, /** Not Digital Cinema*/ + OPJ_CINEMA2K_24 = 1, /** 2K Digital Cinema at 24 fps*/ + OPJ_CINEMA2K_48 = 2, /** 2K Digital Cinema at 48 fps*/ + OPJ_CINEMA4K_24 = 3 /** 4K Digital Cinema at 24 fps*/ }OPJ_CINEMA_MODE; /** @@ -215,12 +273,13 @@ typedef enum PROG_ORDER { * Supported image color spaces */ typedef enum COLOR_SPACE { - OPJ_CLRSPC_UNKNOWN = -1, /**< not supported by the library */ - OPJ_CLRSPC_UNSPECIFIED = 0, /**< not specified in the codestream */ - OPJ_CLRSPC_SRGB = 1, /**< sRGB */ - OPJ_CLRSPC_GRAY = 2, /**< grayscale */ - OPJ_CLRSPC_SYCC = 3, /**< YUV */ - OPJ_CLRSPC_EYCC = 4 /**< e-YCC */ + OPJ_CLRSPC_UNKNOWN = -1, /**< not supported by the library */ + OPJ_CLRSPC_UNSPECIFIED = 0, /**< not specified in the codestream */ + OPJ_CLRSPC_SRGB = 1, /**< sRGB */ + OPJ_CLRSPC_GRAY = 2, /**< grayscale */ + OPJ_CLRSPC_SYCC = 3, /**< YUV */ + OPJ_CLRSPC_EYCC = 4, /**< e-YCC */ + OPJ_CLRSPC_CMYK = 5 /**< CMYK */ } OPJ_COLOR_SPACE; /** @@ -230,7 +289,9 @@ typedef enum CODEC_FORMAT { OPJ_CODEC_UNKNOWN = -1, /**< place-holder */ OPJ_CODEC_J2K = 0, /**< JPEG-2000 codestream : read/write */ OPJ_CODEC_JPT = 1, /**< JPT-stream (JPEG 2000, JPIP) : read only */ - OPJ_CODEC_JP2 = 2 /**< JPEG-2000 file format : read/write */ + OPJ_CODEC_JP2 = 2, /**< JP2 file format : read/write */ + OPJ_CODEC_JPP = 3, /**< JPP-stream (JPEG 2000, JPIP) : to be coded */ + OPJ_CODEC_JPX = 4, /**< JPX file format (JPEG 2000 Part-2) : to be coded */ } OPJ_CODEC_FORMAT; @@ -316,7 +377,7 @@ typedef struct opj_cparameters { OPJ_UINT32 numpocs; /** number of layers */ int tcp_numlayers; - /** rates of layers */ + /** rates of layers - might be subsequently limited by the max_cs_size field */ float tcp_rates[100]; /** different psnr for successive layers */ float tcp_distoratio[100]; @@ -397,12 +458,28 @@ typedef struct opj_cparameters { /*@}*/ /* <POC && ( p_cp->m_specific_param.m_enc.m_cinema || p_t2_mode == FINAL_PASS)) { + if (l_tcp->POC && (OPJ_IS_CINEMA(p_cp->rsiz) || p_t2_mode == FINAL_PASS)) { opj_pi_update_encode_poc_and_final(p_cp,p_tile_no,l_tx0,l_tx1,l_ty0,l_ty1,l_max_prec,l_max_res,l_dx_min,l_dy_min); } else { @@ -1554,7 +1554,7 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi, pi[pino].first = 1; pi[pino].poc.prg = tcp->prg; - if(!(cp->m_specific_param.m_enc.m_tp_on && ((!cp->m_specific_param.m_enc.m_cinema && (t2_mode == FINAL_PASS)) || cp->m_specific_param.m_enc.m_cinema))){ + if(!(cp->m_specific_param.m_enc.m_tp_on && ((!OPJ_IS_CINEMA(cp->rsiz) && (t2_mode == FINAL_PASS)) || OPJ_IS_CINEMA(cp->rsiz)))){ pi[pino].poc.resno0 = tcp->resS; pi[pino].poc.resno1 = tcp->resE; pi[pino].poc.compno0 = tcp->compS; diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index de054acc..37f98149 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -218,7 +218,7 @@ OPJ_BOOL opj_t2_encode_packets( opj_t2_t* p_t2, opj_image_t *l_image = p_t2->image; opj_cp_t *l_cp = p_t2->cp; opj_tcp_t *l_tcp = &l_cp->tcps[p_tile_no]; - OPJ_UINT32 pocno = l_cp->m_specific_param.m_enc.m_cinema == OPJ_CINEMA4K_24? 2: 1; + OPJ_UINT32 pocno = (l_cp->rsiz == OPJ_PROFILE_CINEMA_4K)? 2: 1; OPJ_UINT32 l_max_comp = l_cp->m_specific_param.m_enc.m_max_comp_size > 0 ? l_image->numcomps : 1; OPJ_UINT32 l_nb_pocs = l_tcp->numpocs + 1; diff --git a/src/lib/openjp2/tcd.c b/src/lib/openjp2/tcd.c index be50af80..79262fcd 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -502,7 +502,7 @@ OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd, opj_tcd_makelayer(tcd, layno, thresh, 0); if (cp->m_specific_param.m_enc.m_fixed_quality) { /* fixed_quality */ - if(cp->m_specific_param.m_enc.m_cinema){ + if(OPJ_IS_CINEMA(cp->rsiz)){ if (! opj_t2_encode_packets(t2,tcd->tcd_tileno, tcd_tile, layno + 1, dest, p_data_written, maxlen, cstr_info,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,THRESH_CALC)) { lo = thresh; -- 2.30.2