@@ -1763,25 +1763,22 @@ void CodeStreamDecompress::enqueueTileForDecompress(
17631763
17641764 int32_t tileRow = tileIndex / numTileCols;
17651765 int32_t prev = maxFetchedTileRow_.load (std::memory_order_acquire);
1766- while (prev < tileRow &&
1767- !maxFetchedTileRow_.compare_exchange_weak (prev, tileRow, std::memory_order_release,
1768- std::memory_order_acquire))
1766+ while (prev < tileRow && !maxFetchedTileRow_.compare_exchange_weak (
1767+ prev, tileRow, std::memory_order_release, std::memory_order_acquire))
17691768 {
17701769 }
1771- decompressQueue_->push (
1772- [this , tileIndex, decompressSeq, unreducedImageBounds, postGenerator]() {
1773- const auto tileProcessor = getTileProcessor (tileIndex);
1774- auto * tp = dynamic_cast <TileProcessor*>(tileProcessor);
1775- if (tp)
1776- tp->setSelectiveFetch (true );
1777- auto decompressTask = genDecompressTileTLMTask (tileProcessor, decompressSeq,
1778- unreducedImageBounds, postGenerator);
1779- decompressTask ();
1780- });
1770+ decompressQueue_->push ([this , tileIndex, decompressSeq, unreducedImageBounds, postGenerator]() {
1771+ const auto tileProcessor = getTileProcessor (tileIndex);
1772+ auto * tp = dynamic_cast <TileProcessor*>(tileProcessor);
1773+ if (tp)
1774+ tp->setSelectiveFetch (true );
1775+ auto decompressTask =
1776+ genDecompressTileTLMTask (tileProcessor, decompressSeq, unreducedImageBounds, postGenerator);
1777+ decompressTask ();
1778+ });
17811779}
17821780
1783- void CodeStreamDecompress::buildSelectiveTileParts (uint16_t tileIndex,
1784- const TileHeaderResult& hdr,
1781+ void CodeStreamDecompress::buildSelectiveTileParts (uint16_t tileIndex, const TileHeaderResult& hdr,
17851782 const TPSEQ_VEC& allTileParts, uint8_t reduce)
17861783{
17871784 auto numComps = headerImage_->numcomps ;
@@ -1949,11 +1946,10 @@ void CodeStreamDecompress::buildSelectiveTileParts(uint16_t tileIndex,
19491946 }
19501947}
19511948
1952- std::vector<std::pair<uint16_t , std::shared_ptr<TPFetchSeq>>>
1953- CodeStreamDecompress::reusePhase1Data (
1954- std::shared_ptr<std::set<uint16_t >>& selectiveFetchTiles,
1955- const std::unordered_map<uint16_t , TileHeaderResult>& headerResults,
1956- const TPSEQ_VEC& allTileParts)
1949+ std::vector<std::pair<uint16_t , std::shared_ptr<TPFetchSeq>>> CodeStreamDecompress::reusePhase1Data (
1950+ std::shared_ptr<std::set<uint16_t >>& selectiveFetchTiles,
1951+ const std::unordered_map<uint16_t , TileHeaderResult>& headerResults,
1952+ const TPSEQ_VEC& allTileParts)
19571953{
19581954 std::vector<std::pair<uint16_t , std::shared_ptr<TPFetchSeq>>> prefetchedTiles;
19591955
@@ -2122,9 +2118,8 @@ bool CodeStreamDecompress::fetchByTileSelective(
21222118 // Create modified tile-part info for Phase 1 fetch.
21232119 // For contiguous progressions, estimate the needed data size and fetch that
21242120 // directly, eliminating the need for a second round-trip in most cases.
2125- double pixelRatio = (contiguousProgression && reduce > 0 )
2126- ? (1.0 / std::pow (4.0 , reduce)) * 2.0
2127- : 0.0 ;
2121+ double pixelRatio =
2122+ (contiguousProgression && reduce > 0 ) ? (1.0 / std::pow (4.0 , reduce)) * 2.0 : 0.0 ;
21282123
21292124 TPSEQ_VEC headerTileParts (allTileParts.size ());
21302125 for (auto tileIndex : slated)
@@ -2139,8 +2134,8 @@ bool CodeStreamDecompress::fetchByTileSelective(
21392134 uint32_t fetchLen;
21402135 if (contiguousProgression && reduce > 0 )
21412136 {
2142- uint64_t estimated = std::max< uint64_t >(
2143- headerFetchSize, (uint64_t )(part->length_ * pixelRatio));
2137+ uint64_t estimated =
2138+ std::max< uint64_t >( headerFetchSize, (uint64_t )(part->length_ * pixelRatio));
21442139 fetchLen = (uint32_t )std::min<uint64_t >(estimated, part->length_ );
21452140 }
21462141 else
@@ -2259,64 +2254,64 @@ bool CodeStreamDecompress::fetchByTileSelective(
22592254
22602255 if (!selectiveFetchTiles->empty ())
22612256 {
2262- installFetchThrottle (fetcher);
2263-
2264- fetchByTileFutures_.push_back (fetcher->fetchTiles (
2265- selectiveTileParts_, *selectiveFetchTiles, nullptr ,
2266- [this , numTileCols, unreducedImageBounds, postGenerator, selectiveFetchTiles,
2267- disjointTiles](size_t requestIndex, TileFetchContext* context) {
2268- auto & tilePart = (*context->requests_ )[requestIndex];
2269- auto tileIndex = tilePart->tileIndex_ ;
2270- auto & tilePartSeq = (*context->tilePartFetchByTile_ )[tileIndex];
2257+ installFetchThrottle (fetcher);
22712258
2272- if (!disjointTiles-> count (tileIndex))
2273- {
2274- // Contiguous case: create MemStream per entry (standard path)
2275- tilePart-> stream_ =
2276- std::unique_ptr<IStream>( memStreamCreate (tilePart-> data_ . get (), tilePart-> length_ ,
2277- false , nullptr , stream_-> getFormat (), true )) ;
2278- }
2259+ fetchByTileFutures_. push_back (fetcher-> fetchTiles (
2260+ selectiveTileParts_, *selectiveFetchTiles, nullptr ,
2261+ [ this , numTileCols, unreducedImageBounds, postGenerator, selectiveFetchTiles,
2262+ disjointTiles]( size_t requestIndex, TileFetchContext* context) {
2263+ auto & tilePart = (*context-> requests_ )[requestIndex];
2264+ auto tileIndex = tilePart-> tileIndex_ ;
2265+ auto & tilePartSeq = (*context-> tilePartFetchByTile_ )[tileIndex];
22792266
2280- if (tilePartSeq->incrementFetchCount () == tilePartSeq->size ())
2281- {
2282- std::shared_ptr<TPFetchSeq> decompressSeq;
2267+ if (!disjointTiles->count (tileIndex))
2268+ {
2269+ // Contiguous case: create MemStream per entry (standard path)
2270+ tilePart->stream_ = std::unique_ptr<IStream>(
2271+ memStreamCreate (tilePart->data_ .get (), tilePart->length_ , false , nullptr ,
2272+ stream_->getFormat (), true ));
2273+ }
22832274
2284- if (disjointTiles-> count (tileIndex ))
2275+ if (tilePartSeq-> incrementFetchCount () == tilePartSeq-> size ( ))
22852276 {
2286- // Disjoint case: assemble header + data ranges into single buffer
2287- // Entry 0 = header (with SOT), entries 1..N = data ranges
2288- uint64_t totalSize = 0 ;
2289- for (size_t i = 0 ; i < tilePartSeq->size (); ++i)
2290- totalSize += (*tilePartSeq)[i]->length_ ;
2291-
2292- auto assembled = std::make_unique<uint8_t []>(totalSize);
2293- uint64_t pos = 0 ;
2294- for (size_t i = 0 ; i < tilePartSeq->size (); ++i)
2277+ std::shared_ptr<TPFetchSeq> decompressSeq;
2278+
2279+ if (disjointTiles->count (tileIndex))
2280+ {
2281+ // Disjoint case: assemble header + data ranges into single buffer
2282+ // Entry 0 = header (with SOT), entries 1..N = data ranges
2283+ uint64_t totalSize = 0 ;
2284+ for (size_t i = 0 ; i < tilePartSeq->size (); ++i)
2285+ totalSize += (*tilePartSeq)[i]->length_ ;
2286+
2287+ auto assembled = std::make_unique<uint8_t []>(totalSize);
2288+ uint64_t pos = 0 ;
2289+ for (size_t i = 0 ; i < tilePartSeq->size (); ++i)
2290+ {
2291+ auto & tp = (*tilePartSeq)[i];
2292+ if (tp->data_ )
2293+ std::memcpy (assembled.get () + pos, tp->data_ .get (), tp->length_ );
2294+ pos += tp->length_ ;
2295+ }
2296+
2297+ // Create single-entry TPFetchSeq with assembled data
2298+ decompressSeq = std::make_shared<TPFetchSeq>();
2299+ auto assembledFetch = std::make_shared<TPFetch>(0 , totalSize, tileIndex);
2300+ assembledFetch->data_ = std::move (assembled);
2301+ assembledFetch->stream_ = std::unique_ptr<IStream>(
2302+ memStreamCreate (assembledFetch->data_ .get (), totalSize, false , nullptr ,
2303+ stream_->getFormat (), true ));
2304+ decompressSeq->SharedPtrSeq <TPFetch>::push_back (assembledFetch);
2305+ }
2306+ else
22952307 {
2296- auto & tp = (*tilePartSeq)[i];
2297- if (tp->data_ )
2298- std::memcpy (assembled.get () + pos, tp->data_ .get (), tp->length_ );
2299- pos += tp->length_ ;
2308+ decompressSeq = tilePartSeq;
23002309 }
23012310
2302- // Create single-entry TPFetchSeq with assembled data
2303- decompressSeq = std::make_shared<TPFetchSeq>();
2304- auto assembledFetch = std::make_shared<TPFetch>(0 , totalSize, tileIndex);
2305- assembledFetch->data_ = std::move (assembled);
2306- assembledFetch->stream_ = std::unique_ptr<IStream>(
2307- memStreamCreate (assembledFetch->data_ .get (), totalSize, false , nullptr ,
2308- stream_->getFormat (), true ));
2309- decompressSeq->SharedPtrSeq <TPFetch>::push_back (assembledFetch);
2310- }
2311- else
2312- {
2313- decompressSeq = tilePartSeq;
2311+ enqueueTileForDecompress (tileIndex, decompressSeq, numTileCols, unreducedImageBounds,
2312+ postGenerator);
23142313 }
2315-
2316- enqueueTileForDecompress (tileIndex, decompressSeq, numTileCols, unreducedImageBounds,
2317- postGenerator);
2318- }
2319- }));
2314+ }));
23202315 } // if(!selectiveFetchTiles->empty())
23212316
23222317 return true ;
0 commit comments