|
29 | 29 | #endif /* _WIN32 */ |
30 | 30 | #include <climits> |
31 | 31 | #include <string> |
| 32 | +#include <sstream> |
32 | 33 | #include <chrono> |
33 | 34 | #include <thread> |
34 | 35 | #include <algorithm> |
@@ -340,7 +341,8 @@ GrkRC GrkDecompress::parseCommandLine(int argc, const char* argv[], |
340 | 341 | CLI::App cmd("grk_decompress command line", grk_version()); |
341 | 342 |
|
342 | 343 | std::string outDir, compression, decodeRegion, pluginPathStr, inputFile, outputFile, outFor, |
343 | | - precision, logfile, inDir; |
| 344 | + precision, logfile, inDir, components; |
| 345 | + auto& compIndices = initParams->compIndices; |
344 | 346 | uint32_t repetitions = 0, numThreads = 0, kernelBuildOptions = 0, |
345 | 347 | compressionLevel = std::numeric_limits<uint32_t>::max(), disableRandomAccess = 0, |
346 | 348 | tile = 0, duration = 0; |
@@ -369,6 +371,9 @@ GrkRC GrkDecompress::parseCommandLine(int argc, const char* argv[], |
369 | 371 | cmd.add_option("-L,--compression-level", compressionLevel, "Output compression Level"); |
370 | 372 | auto randomAccessOpt = cmd.add_option("-m,--random-access", disableRandomAccess, |
371 | 373 | "Toggle support for random access into code stream"); |
| 374 | + auto componentsOpt = cmd.add_option( |
| 375 | + "-n,--components", components, |
| 376 | + "Comma-separated list of 0-based component indices to decode (e.g. '0' or '0,2')"); |
372 | 377 | auto outputFileOpt = cmd.add_option("-o,--out-file", outputFile, "Output file"); |
373 | 378 | auto outForOpt = cmd.add_option("-O,--out-fmt", outFor, "Output Format"); |
374 | 379 | auto precisionOpt = cmd.add_option("-p,--precision", precision, "Force precision"); |
@@ -563,6 +568,34 @@ GrkRC GrkDecompress::parseCommandLine(int argc, const char* argv[], |
563 | 568 | parameters->core.reduce = reduce; |
564 | 569 | if(layerOpt->count() > 0) |
565 | 570 | parameters->core.layers_to_decompress = layer; |
| 571 | + if(componentsOpt->count() > 0) |
| 572 | + { |
| 573 | + std::istringstream iss(components); |
| 574 | + std::string token; |
| 575 | + while(std::getline(iss, token, ',')) |
| 576 | + { |
| 577 | + try |
| 578 | + { |
| 579 | + int val = std::stoi(token); |
| 580 | + if(val < 0 || val > 16383) |
| 581 | + { |
| 582 | + spdlog::error("Component index {} out of range [0, 16383]", val); |
| 583 | + return GrkRCParseArgsFailed; |
| 584 | + } |
| 585 | + compIndices.push_back((uint16_t)val); |
| 586 | + } |
| 587 | + catch(...) |
| 588 | + { |
| 589 | + spdlog::error("Invalid component index: {}", token); |
| 590 | + return GrkRCParseArgsFailed; |
| 591 | + } |
| 592 | + } |
| 593 | + if(!compIndices.empty()) |
| 594 | + { |
| 595 | + parameters->core.comps_to_decode = compIndices.data(); |
| 596 | + parameters->core.num_comps_to_decode = (uint16_t)compIndices.size(); |
| 597 | + } |
| 598 | + } |
566 | 599 | if(randomAccessOpt->count() > 0) |
567 | 600 | parameters->core.disable_random_access_flags = disableRandomAccess; |
568 | 601 | parameters->single_tile_decompress = tileOpt->count() > 0; |
|
0 commit comments