diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2022-01-23 17:53:55 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2022-01-23 17:54:44 +0100 |
| commit | 1de5fc6c51617f49515ef80708dd074432a27a6a (patch) | |
| tree | 218a72739c1fdb4708ebf581a90ea4492c23cae5 /src/bin | |
| parent | 241e9e8efeb6750ef4202a61b3a436628e4f6d23 (diff) | |
opj_encoder_set_extra_options(): add a GUARD_BITS=value option
and add a -GuardBits option to opj_compress.
The recently-released SMPTE DCP Bv2.1 Application Profile (link below)
says that the number of guard bits in the QCD marker shall be 1 for 2K
content and 2 for 4K content. This change allows the number of guard bits
to be configured, so that users of openjpeg have the control they need to meet the specification.
https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=9161348
This is an alternative implementation of https://github.com/uclouvain/openjpeg/pull/1388
that keeps ABI unchanged.
Diffstat (limited to 'src/bin')
| -rw-r--r-- | src/bin/jp2/opj_compress.c | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index 830ab96e..85e1e566 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -304,6 +304,9 @@ static void encode_help_display(void) fprintf(stdout, " Y >= 0 and Y <= 9.\n"); fprintf(stdout, " framerate > 0 may be specified to enhance checks and set maximum bit rate when Y > 0.\n"); + fprintf(stdout, "-GuardBits value\n"); + fprintf(stdout, + " Number of guard bits in [0,7] range. Usually 1 or 2 (default value).\n"); fprintf(stdout, "-jpip\n"); fprintf(stdout, " Write jpip codestream index box in JP2 output file.\n"); fprintf(stdout, " Currently supports only RPCL order.\n"); @@ -612,6 +615,7 @@ static int parse_cmdline_encoder(int argc, char **argv, int* pOutFramerate, OPJ_BOOL* pOutPLT, OPJ_BOOL* pOutTLM, + int* pOutGuardBits, int* pOutNumThreads, unsigned int* pTarget_bitdepth) { @@ -634,10 +638,11 @@ static int parse_cmdline_encoder(int argc, char **argv, {"threads", REQ_ARG, NULL, 'B'}, {"TLM", NO_ARG, NULL, 'D'}, {"TargetBitDepth", REQ_ARG, NULL, 'X'}, + {"GuardBits", REQ_ARG, NULL, 'G'} }; /* parse the command line */ - const char optlist[] = "i:o:r:q:n:b:c:t:p:s:SEM:x:R:d:T:If:P:C:F:u:JY:X:" + const char optlist[] = "i:o:r:q:n:b:c:t:p:s:SEM:x:R:d:T:If:P:C:F:u:JY:X:G:" #ifdef USE_JPWL "W:" #endif /* USE_JPWL */ @@ -934,6 +939,13 @@ static int parse_cmdline_encoder(int argc, char **argv, break; /* ----------------------------------------------------- */ + case 'G': { /* guard bits */ + char *s = opj_optarg; + sscanf(s, "%d", pOutGuardBits); + } + break; + + /* ----------------------------------------------------- */ case 'n': { /* resolution */ sscanf(opj_optarg, "%d", ¶meters->numresolution); @@ -1932,6 +1944,7 @@ int main(int argc, char **argv) OPJ_BOOL PLT = OPJ_FALSE; OPJ_BOOL TLM = OPJ_FALSE; int num_threads = 0; + int guard_bits = -1; /** desired bitdepth from input file */ unsigned int target_bitdepth = 0; @@ -1956,7 +1969,7 @@ int main(int argc, char **argv) 255; /* This will be set later according to the input image or the provided option */ if (parse_cmdline_encoder(argc, argv, ¶meters, &img_fol, &raw_cp, indexfilename, sizeof(indexfilename), &framerate, &PLT, &TLM, - &num_threads, &target_bitdepth) == 1) { + &guard_bits, &num_threads, &target_bitdepth) == 1) { ret = 1; goto fin; } @@ -2201,17 +2214,21 @@ int main(int argc, char **argv) goto fin; } - if (PLT || TLM) { - const char* options[3] = { NULL, NULL, NULL }; + { + const char* options[4] = { NULL, NULL, NULL, NULL }; int iOpt = 0; + char szGuardBits[32]; if (PLT) { options[iOpt++] = "PLT=YES"; } if (TLM) { options[iOpt++] = "TLM=YES"; } - (void)iOpt; - if (!opj_encoder_set_extra_options(l_codec, options)) { + if (guard_bits >= 0) { + sprintf(szGuardBits, "GUARD_BITS=%d", guard_bits); + options[iOpt++] = szGuardBits; + } + if (iOpt > 0 && !opj_encoder_set_extra_options(l_codec, options)) { fprintf(stderr, "failed to encode image: opj_encoder_set_extra_options\n"); opj_destroy_codec(l_codec); opj_image_destroy(image); |
