diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2020-10-09 13:25:27 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-09 13:25:27 +0200 |
| commit | 491299eb073c80602ca8ee333303a31a581d3fa8 (patch) | |
| tree | f464aca94231b459c62f774a6a956f3e73c2bbce /src/bin | |
| parent | 65c8f577d2f057e80040e98958eae80ca76c6b94 (diff) | |
| parent | 1c5627ee7406f84cfb40809b7ac31c63342427df (diff) | |
Merge pull request #1253 from rouault/floating_point_irreversible_encoding
Single-threaded performance improvements in forward DWT for 5-3 and 9-7 (and other improvements)
Diffstat (limited to 'src/bin')
| -rw-r--r-- | src/bin/jp2/opj_compress.c | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index cbc30fba..68274840 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -301,6 +301,10 @@ static void encode_help_display(void) fprintf(stdout, " Currently supports only RPCL order.\n"); fprintf(stdout, "-C <comment>\n"); fprintf(stdout, " Add <comment> in the comment marker segment.\n"); + if (opj_has_thread_support()) { + fprintf(stdout, " -threads <num_threads|ALL_CPUS>\n" + " Number of threads to use for encoding or ALL_CPUS for all available cores.\n"); + } /* UniPG>> */ #ifdef USE_JPWL fprintf(stdout, "-W <params>\n"); @@ -579,7 +583,8 @@ static int parse_cmdline_encoder(int argc, char **argv, img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename, size_t indexfilename_size, int* pOutFramerate, - OPJ_BOOL* pOutPLT) + OPJ_BOOL* pOutPLT, + int* pOutNumThreads) { OPJ_UINT32 i, j; int totlen, c; @@ -596,7 +601,8 @@ static int parse_cmdline_encoder(int argc, char **argv, {"jpip", NO_ARG, NULL, 'J'}, {"mct", REQ_ARG, NULL, 'Y'}, {"IMF", REQ_ARG, NULL, 'Z'}, - {"PLT", NO_ARG, NULL, 'A'} + {"PLT", NO_ARG, NULL, 'A'}, + {"threads", REQ_ARG, NULL, 'B'} }; /* parse the command line */ @@ -1679,6 +1685,19 @@ static int parse_cmdline_encoder(int argc, char **argv, } break; + /* ----------------------------------------------------- */ + case 'B': { /* Number of threads */ + if (strcmp(opj_optarg, "ALL_CPUS") == 0) { + *pOutNumThreads = opj_get_num_cpus(); + if (*pOutNumThreads == 1) { + *pOutNumThreads = 0; + } + } else { + sscanf(opj_optarg, "%d", pOutNumThreads); + } + } + break; + /* ------------------------------------------------------ */ @@ -1860,6 +1879,7 @@ int main(int argc, char **argv) OPJ_FLOAT64 t = opj_clock(); OPJ_BOOL PLT = OPJ_FALSE; + int num_threads = 0; /* set encoding parameters to default values */ opj_set_default_encoder_parameters(¶meters); @@ -1880,7 +1900,7 @@ int main(int argc, char **argv) parameters.tcp_mct = (char) 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) == 1) { + indexfilename, sizeof(indexfilename), &framerate, &PLT, &num_threads) == 1) { ret = 1; goto fin; } @@ -2141,6 +2161,15 @@ int main(int argc, char **argv) } } + if (num_threads >= 1 && + !opj_codec_set_threads(l_codec, num_threads)) { + fprintf(stderr, "failed to set number of threads\n"); + opj_destroy_codec(l_codec); + opj_image_destroy(image); + ret = 1; + goto fin; + } + /* open a byte stream for writing and allocate memory for all tiles */ l_stream = opj_stream_create_default_file_stream(parameters.outfile, OPJ_FALSE); if (! l_stream) { |
