Commit 36e92e0342110f8f30cd4b14e9d1585c7f35ebc7

Authored by m-holger
1 parent d9ae41b0

Refactor decode parameters handling in QPDF_Stream.

Simplified and reorganized logic for handling /DecodeParms in streams. Ensured proper initialization and updated filter checks for lossy and specialized compression, improving code clarity and maintainability.
Showing 1 changed file with 30 additions and 18 deletions
libqpdf/QPDF_Stream.cc
... ... @@ -386,16 +386,28 @@ Stream::filterable(
386 386 // See if we can support any decode parameters that are specified.
387 387  
388 388 auto decode_obj = s->stream_dict.getKey("/DecodeParms");
389   - std::vector<QPDFObjectHandle> decode_parms;
390 389  
391 390 auto decode_array = decode_obj.as_array(strict);
392 391 if (!decode_array || decode_array.size() == 0) {
393 392 if (decode_array) {
394   - decode_parms.assign(filters.size(), QPDFObjectHandle::newNull());
395   - } else {
396   - decode_parms.assign(filters.size(), decode_obj);
  393 + decode_obj = QPDFObjectHandle::newNull();
  394 + }
  395 +
  396 + for (auto& filter: filters) {
  397 + if (!filter->setDecodeParms(decode_obj)) {
  398 + return false;
  399 + }
  400 + if (filter->isLossyCompression()) {
  401 + specialized_compression = true;
  402 + lossy_compression = true;
  403 + continue;
  404 + }
  405 + if (filter->isSpecializedCompression()) {
  406 + specialized_compression = true;
  407 + }
397 408 }
398 409 } else {
  410 + std::vector<QPDFObjectHandle> decode_parms;
399 411 for (auto& item: decode_array) {
400 412 decode_parms.emplace_back(item);
401 413 }
... ... @@ -405,22 +417,22 @@ Stream::filterable(
405 417 warn("stream /DecodeParms length is inconsistent with filters");
406 418 return false;
407 419 }
408   - }
409 420  
410   - for (size_t i = 0; i < filters.size(); ++i) {
411   - auto filter = filters.at(i);
412   - auto decode_item = decode_parms.at(i);
  421 + for (size_t i = 0; i < filters.size(); ++i) {
  422 + auto filter = filters.at(i);
  423 + auto decode_item = decode_parms.at(i);
413 424  
414   - if (!filter->setDecodeParms(decode_item)) {
415   - return false;
416   - }
417   - if (filter->isLossyCompression()) {
418   - specialized_compression = true;
419   - lossy_compression = true;
420   - continue;
421   - }
422   - if (filter->isSpecializedCompression()) {
423   - specialized_compression = true;
  425 + if (!filter->setDecodeParms(decode_item)) {
  426 + return false;
  427 + }
  428 + if (filter->isLossyCompression()) {
  429 + specialized_compression = true;
  430 + lossy_compression = true;
  431 + continue;
  432 + }
  433 + if (filter->isSpecializedCompression()) {
  434 + specialized_compression = true;
  435 + }
424 436 }
425 437 }
426 438  
... ...