1616 */
1717
1818#include " grk_exceptions.h"
19- #include < Logger.h>
19+ #include " Logger.h"
2020#include " CodeStreamLimits.h"
2121#include " geometry.h"
2222#include " buffer.h"
@@ -992,45 +992,7 @@ bool TileProcessor::scheduleT2T1(CoderPool* coderPool, Rect32 unreducedImageBoun
992992 scheduler_->release ();
993993 }
994994
995- bool doT2 = !current_plugin_tile_ || (current_plugin_tile_->decompress_flags & GRK_DECODE_T2);
996-
997- auto allocAndSchedule = [this ]() {
998- if (!Scheduling::isWindowedScheduling ())
999- {
1000- for (uint16_t compno = 0 ; compno < tile_->numcomps_ ; ++compno)
1001- {
1002- auto tilec = tile_->comps_ + compno;
1003- if (!tcp_->wholeTileDecompress_ )
1004- {
1005- try
1006- {
1007- tilec->allocRegionWindow (tilec->nextPacketProgressionState_ .numResolutionsRead (),
1008- truncated_);
1009- }
1010- catch ([[maybe_unused]] const std::runtime_error& ex)
1011- {
1012- continue ;
1013- }
1014- catch ([[maybe_unused]] const std::bad_alloc& baex)
1015- {
1016- success_ = false ;
1017- return ;
1018- }
1019- }
1020- if (!tilec->getWindow ()->alloc ())
1021- {
1022- grklog.error (" Not enough memory for tile data" );
1023- success_ = false ;
1024- return ;
1025- }
1026- }
1027- }
1028- if (!scheduler_->schedule (this ))
1029- {
1030- success_ = false ;
1031- return ;
1032- }
1033- };
995+ // bool doT2 = !current_plugin_tile_ || (current_plugin_tile_->decompress_flags & GRK_DECODE_T2);
1034996
1035997 auto t2Parse = [this ]() {
1036998 // synch plugin with T2 data
@@ -1107,40 +1069,68 @@ bool TileProcessor::scheduleT2T1(CoderPool* coderPool, Rect32 unreducedImageBoun
11071069 }
11081070 };
11091071
1110- if (doT2)
1111- {
1112- if (ExecSingleton::num_threads () > 1 )
1072+ auto allocAndSchedule = [this ]() {
1073+ if (!Scheduling::isWindowedScheduling ())
11131074 {
1114- if (!t2ParseFlow_)
1115- t2ParseFlow_ = std::make_unique<FlowComponent>();
1116- else
1117- t2ParseFlow_->clear ();
1118- t2ParseFlow_->nextTask ().work (t2Parse);
1119-
1120- if (!allocAndScheduleFlow_)
1121- allocAndScheduleFlow_ = std::make_unique<FlowComponent>();
1122- else
1123- allocAndScheduleFlow_->clear ();
1124- allocAndScheduleFlow_->nextTask ().work (allocAndSchedule);
1075+ for (uint16_t compno = 0 ; compno < tile_->numcomps_ ; ++compno)
1076+ {
1077+ auto tilec = tile_->comps_ + compno;
1078+ if (!tcp_->wholeTileDecompress_ )
1079+ {
1080+ try
1081+ {
1082+ tilec->allocRegionWindow (tilec->nextPacketProgressionState_ .numResolutionsRead (),
1083+ truncated_);
1084+ }
1085+ catch ([[maybe_unused]] const std::runtime_error& ex)
1086+ {
1087+ continue ;
1088+ }
1089+ catch ([[maybe_unused]] const std::bad_alloc& baex)
1090+ {
1091+ success_ = false ;
1092+ return ;
1093+ }
1094+ }
1095+ if (!tilec->getWindow ()->alloc ())
1096+ {
1097+ grklog.error (" Not enough memory for tile data" );
1098+ success_ = false ;
1099+ return ;
1100+ }
1101+ }
11251102 }
1126- else
1103+ if (!scheduler_-> schedule ( this ))
11271104 {
1128- t2Parse () ;
1129- allocAndSchedule () ;
1105+ success_ = false ;
1106+ return ;
11301107 }
1131- }
1108+ };
11321109
11331110 if (ExecSingleton::num_threads () > 1 )
11341111 {
1112+ if (!t2ParseFlow_)
1113+ t2ParseFlow_ = std::make_unique<FlowComponent>();
1114+ else
1115+ t2ParseFlow_->clear ();
1116+ t2ParseFlow_->nextTask ().work (t2Parse);
1117+
1118+ if (!allocAndScheduleFlow_)
1119+ allocAndScheduleFlow_ = std::make_unique<FlowComponent>();
1120+ else
1121+ allocAndScheduleFlow_->clear ();
1122+ allocAndScheduleFlow_->nextTask ().work (allocAndSchedule);
1123+
1124+ // 1. create root flow
11351125 if (!rootFlow_)
11361126 rootFlow_ = new FlowComponent ();
11371127 else
11381128 rootFlow_->clear ();
1139-
1140- std::function<int ()> condition_lambda = [this ]() -> int { return hasError () ? 1 : 0 ; };
1141-
11421129 scheduler_->addTo (*rootFlow_);
11431130
1131+ // 2. schedule T2
1132+
1133+ std::function<int ()> condition_lambda = [this ]() -> int { return hasError () ? 1 : 0 ; };
11441134 allocAndScheduleFlow_->addTo (*rootFlow_);
11451135 allocAndScheduleFlow_->conditional_precede (rootFlow_, scheduler_, condition_lambda);
11461136
@@ -1156,18 +1146,21 @@ bool TileProcessor::scheduleT2T1(CoderPool* coderPool, Rect32 unreducedImageBoun
11561146 tileHeaderParseFlow_->conditional_precede (rootFlow_, prepareFlow_.get (), condition_lambda);
11571147 }
11581148
1149+ // 3. schedule post decompression
11591150 if (!postDecompressFlow_)
11601151 postDecompressFlow_ = new FlowComponent ();
11611152 else
11621153 postDecompressFlow_->clear ();
11631154 postDecompressFlow_->nextTask ().work (post );
11641155 postDecompressFlow_->addTo (*rootFlow_);
1165-
11661156 scheduler_->precede (*postDecompressFlow_);
1157+
11671158 futures.add (tileIndex_, ExecSingleton::get ().run (*rootFlow_));
11681159 }
11691160 else
11701161 {
1162+ t2Parse ();
1163+ allocAndSchedule ();
11711164 post ();
11721165 }
11731166 return true ;
0 commit comments