Skip to content

Commit ccddf68

Browse files
author
Grok Compression
committed
code reformat
1 parent 094fdc3 commit ccddf68

11 files changed

Lines changed: 152 additions & 159 deletions

File tree

.vscode/launch.json

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,32 +1347,38 @@
13471347
"miDebuggerPath": "/usr/bin/gdb"
13481348
},
13491349
{
1350-
"name": "TCI Selective Fetch MINIO",
1350+
"name": "TCI Selective Fetch CloudFerro",
13511351
"type": "cppdbg",
13521352
"request": "launch",
1353-
"program": "${workspaceFolder}/build/bin/grk_decompress",
1353+
"program": "/usr/bin/time",
1354+
//"program": "${workspaceFolder}/build/bin/grk_decompress",
13541355
"args": [
1356+
"-v",
1357+
"${workspaceFolder}/build/bin/grk_decompress",
13551358
"-i",
1356-
"/vsis3/grok/T32TQM_20241115T100159_TCI_10m.jp2",
1359+
"/vsis3/s2samples/T33UYT_20260503T095051_TCI_10m.jp2",
13571360
"-o",
13581361
"$HOME/temp/tci_selective.tif",
13591362
"-r",
1360-
"2"
1363+
"4"
13611364
],
13621365
"cwd": "${workspaceFolder}",
13631366
"environment": [
13641367
{ "name": "GRK_DEBUG", "value": "3" },
1365-
{ "name": "AWS_ACCESS_KEY_ID", "value": "minioadmin" },
1366-
{ "name": "AWS_SECRET_ACCESS_KEY", "value": "minioadmin" },
1367-
{ "name": "AWS_S3_ENDPOINT", "value": "localhost:9000" },
1368+
{ "name": "AWS_S3_ENDPOINT", "value": "s3.waw3-1.cloudferro.com" },
13681369
{ "name": "AWS_VIRTUAL_HOSTING", "value": "FALSE" },
13691370
{ "name": "AWS_HTTPS", "value": "YES" },
1370-
{ "name": "GRK_CURL_ALLOW_INSECURE", "value": "YES" }
1371+
// Since this is an open/public file, we skip credential signing
1372+
{ "name": "AWS_NO_SIGN_REQUEST", "value": "YES" },
1373+
{ "name": "AWS_ACCESS_KEY_ID", "value": "" },
1374+
{ "name": "AWS_SECRET_ACCESS_KEY", "value": "" },
1375+
// CloudFerro uses valid CA certs, so we can disable insecure mode
1376+
{ "name": "GRK_CURL_ALLOW_INSECURE", "value": "NO" }
13711377
],
13721378
"MIMode": "gdb",
13731379
"miDebuggerPath": "/usr/bin/gdb"
13741380
},
1375-
{
1381+
{
13761382
"name": "TCI Selective Fetch",
13771383
"type": "cppdbg",
13781384
"request": "launch",

src/lib/codec/apps/GrkDecompress.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,8 @@ GrkRC GrkDecompress::parseCommandLine(int argc, const char* argv[],
389389
auto xmlOpt = cmd.add_flag("-X,--xml", xml, "XML metadata");
390390
auto inDirOpt = cmd.add_option("-y,--batch-src", inDir, "Input source");
391391
auto durationOpt = cmd.add_option("-z,--duration", duration, "Duration in seconds");
392-
auto fastMctOpt =
393-
cmd.add_flag("--fast-mct", fastMct, "Use fast 16-bit DWT for 9/7 MCT decompress (prec <= 12)");
392+
auto fastMctOpt = cmd.add_flag("--fast-mct", fastMct,
393+
"Use fast 16-bit DWT for 9/7 MCT decompress (prec <= 12)");
394394

395395
cmd.set_help_flag("-h", "Show abreviated usage");
396396
cmd.add_flag("--help", "Show detailed usage");

src/lib/core/codestream/decompress/CodeStreamDecompress.cpp

Lines changed: 79 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,7 +1756,8 @@ bool CodeStreamDecompress::fetchByTileSelective(
17561756

17571757
// Phase 1: Fetch 4KB header of each tile-part
17581758
constexpr uint32_t headerFetchSize = 4096;
1759-
grklog.info("fetchByTileSelective: Phase 1 starting, %zu tiles, reduce=%u", slated.size(), (unsigned)reduce);
1759+
grklog.debug("fetchByTileSelective: Phase 1 starting, %zu tiles, reduce=%u", slated.size(),
1760+
(unsigned)reduce);
17601761

17611762
// Create modified tile-part info with 4KB lengths for header fetch
17621763
TPSEQ_VEC headerTileParts(allTileParts.size());
@@ -1770,8 +1771,8 @@ bool CodeStreamDecompress::fetchByTileSelective(
17701771
{
17711772
auto& part = (*srcParts)[i];
17721773
uint32_t fetchLen = std::min<uint32_t>((uint32_t)part->length_, headerFetchSize);
1773-
headerTileParts[tileIndex]->push_back((uint8_t)i, (uint8_t)srcParts->size(),
1774-
part->offset_, fetchLen);
1774+
headerTileParts[tileIndex]->push_back((uint8_t)i, (uint8_t)srcParts->size(), part->offset_,
1775+
fetchLen);
17751776
}
17761777
}
17771778

@@ -1782,8 +1783,7 @@ bool CodeStreamDecompress::fetchByTileSelective(
17821783
std::vector<std::unique_ptr<uint8_t[]>> headerData; // raw header bytes
17831784
std::vector<uint32_t> headerSizes; // actual header sizes
17841785
};
1785-
auto headerResults =
1786-
std::make_shared<std::unordered_map<uint16_t, TileHeaderResult>>();
1786+
auto headerResults = std::make_shared<std::unordered_map<uint16_t, TileHeaderResult>>();
17871787
std::mutex headerMutex;
17881788
std::promise<bool> phase1Promise;
17891789
auto phase1Future = phase1Promise.get_future();
@@ -1793,55 +1793,54 @@ bool CodeStreamDecompress::fetchByTileSelective(
17931793
auto slatedTiles = slated;
17941794

17951795
// Phase 1 fetch: get tile-part headers
1796-
fetcher->fetchTiles(
1797-
headerTileParts, slated, nullptr,
1798-
[&headerResults, &headerMutex, &remainingTiles, &phase1Promise](
1799-
size_t requestIndex, TileFetchContext* context) {
1800-
auto& tilePart = (*context->requests_)[requestIndex];
1801-
auto tileIndex = tilePart->tileIndex_;
1802-
1803-
auto& tilePartSeq = (*context->tilePartFetchByTile_)[tileIndex];
1804-
if(tilePartSeq->incrementFetchCount() == tilePartSeq->size())
1805-
{
1806-
// All tile-parts for this tile have arrived
1807-
TileHeaderResult result;
1808-
for(size_t i = 0; i < tilePartSeq->size(); ++i)
1809-
{
1810-
auto& tp = (*tilePartSeq)[i];
1811-
// Parse PLT and SOD from the raw header bytes
1812-
// Skip SOT marker (12 bytes) at start of tile-part data
1813-
constexpr size_t sotLen = 12;
1814-
if(tp->length_ > sotLen && tp->data_)
1815-
{
1816-
auto info = extractTilePartHeaderInfo(
1817-
tp->data_.get() + sotLen, (size_t)(tp->length_ - sotLen));
1818-
// Adjust SOD offset to be relative to tile-part start
1819-
if(info.valid)
1820-
info.sodOffset += sotLen;
1821-
result.headerInfos.push_back(std::move(info));
1822-
result.headerData.push_back(std::move(tp->data_));
1823-
result.headerSizes.push_back((uint32_t)tp->length_);
1824-
}
1825-
else
1826-
{
1827-
result.headerInfos.push_back(TilePartHeaderInfo{0, {}, false});
1828-
result.headerData.push_back(nullptr);
1829-
result.headerSizes.push_back(0);
1830-
}
1831-
}
1832-
{
1833-
std::lock_guard<std::mutex> lock(headerMutex);
1834-
(*headerResults)[tileIndex] = std::move(result);
1835-
}
1836-
if(remainingTiles->fetch_sub(1) == 1)
1837-
phase1Promise.set_value(true);
1838-
}
1839-
});
1796+
fetcher->fetchTiles(headerTileParts, slated, nullptr,
1797+
[&headerResults, &headerMutex, &remainingTiles,
1798+
&phase1Promise](size_t requestIndex, TileFetchContext* context) {
1799+
auto& tilePart = (*context->requests_)[requestIndex];
1800+
auto tileIndex = tilePart->tileIndex_;
1801+
1802+
auto& tilePartSeq = (*context->tilePartFetchByTile_)[tileIndex];
1803+
if(tilePartSeq->incrementFetchCount() == tilePartSeq->size())
1804+
{
1805+
// All tile-parts for this tile have arrived
1806+
TileHeaderResult result;
1807+
for(size_t i = 0; i < tilePartSeq->size(); ++i)
1808+
{
1809+
auto& tp = (*tilePartSeq)[i];
1810+
// Parse PLT and SOD from the raw header bytes
1811+
// Skip SOT marker (12 bytes) at start of tile-part data
1812+
constexpr size_t sotLen = 12;
1813+
if(tp->length_ > sotLen && tp->data_)
1814+
{
1815+
auto info = extractTilePartHeaderInfo(tp->data_.get() + sotLen,
1816+
(size_t)(tp->length_ - sotLen));
1817+
// Adjust SOD offset to be relative to tile-part start
1818+
if(info.valid)
1819+
info.sodOffset += sotLen;
1820+
result.headerInfos.push_back(std::move(info));
1821+
result.headerData.push_back(std::move(tp->data_));
1822+
result.headerSizes.push_back((uint32_t)tp->length_);
1823+
}
1824+
else
1825+
{
1826+
result.headerInfos.push_back(TilePartHeaderInfo{0, {}, false});
1827+
result.headerData.push_back(nullptr);
1828+
result.headerSizes.push_back(0);
1829+
}
1830+
}
1831+
{
1832+
std::lock_guard<std::mutex> lock(headerMutex);
1833+
(*headerResults)[tileIndex] = std::move(result);
1834+
}
1835+
if(remainingTiles->fetch_sub(1) == 1)
1836+
phase1Promise.set_value(true);
1837+
}
1838+
});
18401839

18411840
// Wait for Phase 1 to complete
1842-
grklog.info("fetchByTileSelective: waiting for Phase 1...");
1841+
grklog.debug("fetchByTileSelective: waiting for Phase 1...");
18431842
phase1Future.get();
1844-
grklog.info("fetchByTileSelective: Phase 1 complete");
1843+
grklog.debug("fetchByTileSelective: Phase 1 complete");
18451844

18461845
// Phase 2: Compute needed lengths and fetch truncated tile-parts
18471846
auto numComps = headerImage_->numcomps;
@@ -1878,8 +1877,8 @@ bool CodeStreamDecompress::fetchByTileSelective(
18781877
for(size_t i = 0; i < srcParts->size(); ++i)
18791878
{
18801879
auto& part = (*srcParts)[i];
1881-
selectiveTileParts_[tileIndex]->push_back(
1882-
(uint8_t)i, (uint8_t)srcParts->size(), part->offset_, (uint32_t)part->length_);
1880+
selectiveTileParts_[tileIndex]->push_back((uint8_t)i, (uint8_t)srcParts->size(),
1881+
part->offset_, (uint32_t)part->length_);
18831882
}
18841883
selectiveFetchTiles->insert(tileIndex);
18851884
continue;
@@ -1897,8 +1896,7 @@ bool CodeStreamDecompress::fetchByTileSelective(
18971896
std::vector<uint32_t> allPltLengths;
18981897
for(auto& info : hdr.headerInfos)
18991898
{
1900-
allPltLengths.insert(allPltLengths.end(),
1901-
info.pltLengths.begin(), info.pltLengths.end());
1899+
allPltLengths.insert(allPltLengths.end(), info.pltLengths.begin(), info.pltLengths.end());
19021900
}
19031901

19041902
// Build TilePacketInfo
@@ -1925,10 +1923,9 @@ bool CodeStreamDecompress::fetchByTileSelective(
19251923
tpi.precinctsPerRes[compno].resize(tccp->numresolutions_);
19261924
for(uint8_t resno = 0; resno < tccp->numresolutions_; ++resno)
19271925
{
1928-
tpi.precinctsPerRes[compno][resno] = computeNumPrecincts(
1929-
tcx0, tcy0, tcx1, tcy1,
1930-
tccp->numresolutions_, resno,
1931-
tccp->precWidthExp_[resno], tccp->precHeightExp_[resno]);
1926+
tpi.precinctsPerRes[compno][resno] =
1927+
computeNumPrecincts(tcx0, tcy0, tcx1, tcy1, tccp->numresolutions_, resno,
1928+
tccp->precWidthExp_[resno], tccp->precHeightExp_[resno]);
19321929
}
19331930
}
19341931

@@ -1948,8 +1945,8 @@ bool CodeStreamDecompress::fetchByTileSelective(
19481945
for(size_t i = 0; i < srcParts->size(); ++i)
19491946
{
19501947
auto& part = (*srcParts)[i];
1951-
selectiveTileParts_[tileIndex]->push_back(
1952-
(uint8_t)i, (uint8_t)srcParts->size(), part->offset_, (uint32_t)part->length_);
1948+
selectiveTileParts_[tileIndex]->push_back((uint8_t)i, (uint8_t)srcParts->size(),
1949+
part->offset_, (uint32_t)part->length_);
19531950
}
19541951
selectiveFetchTiles->insert(tileIndex);
19551952
continue;
@@ -1983,22 +1980,22 @@ bool CodeStreamDecompress::fetchByTileSelective(
19831980
auto& headerInfo = hdr.headerInfos[i];
19841981
if(!headerInfo.valid)
19851982
{
1986-
selectiveTileParts_[tileIndex]->push_back(
1987-
(uint8_t)i, (uint8_t)srcParts->size(), part->offset_, (uint32_t)part->length_);
1983+
selectiveTileParts_[tileIndex]->push_back((uint8_t)i, (uint8_t)srcParts->size(),
1984+
part->offset_, (uint32_t)part->length_);
19881985
continue;
19891986
}
19901987
uint64_t tpDataSize = part->length_ - headerInfo.sodOffset - 2;
19911988
if(remainingNeeded >= tpDataSize)
19921989
{
1993-
selectiveTileParts_[tileIndex]->push_back(
1994-
(uint8_t)i, (uint8_t)srcParts->size(), part->offset_, (uint32_t)part->length_);
1990+
selectiveTileParts_[tileIndex]->push_back((uint8_t)i, (uint8_t)srcParts->size(),
1991+
part->offset_, (uint32_t)part->length_);
19951992
remainingNeeded -= tpDataSize;
19961993
}
19971994
else
19981995
{
19991996
uint64_t truncatedLen = headerInfo.sodOffset + 2 + remainingNeeded;
2000-
selectiveTileParts_[tileIndex]->push_back(
2001-
(uint8_t)i, (uint8_t)srcParts->size(), part->offset_, (uint32_t)truncatedLen);
1997+
selectiveTileParts_[tileIndex]->push_back((uint8_t)i, (uint8_t)srcParts->size(),
1998+
part->offset_, (uint32_t)truncatedLen);
20021999
remainingNeeded = 0;
20032000
}
20042001
}
@@ -2014,8 +2011,8 @@ bool CodeStreamDecompress::fetchByTileSelective(
20142011
for(size_t i = 0; i < srcParts->size(); ++i)
20152012
{
20162013
auto& part = (*srcParts)[i];
2017-
selectiveTileParts_[tileIndex]->push_back(
2018-
(uint8_t)i, (uint8_t)srcParts->size(), part->offset_, (uint32_t)part->length_);
2014+
selectiveTileParts_[tileIndex]->push_back((uint8_t)i, (uint8_t)srcParts->size(),
2015+
part->offset_, (uint32_t)part->length_);
20192016
}
20202017
selectiveFetchTiles->insert(tileIndex);
20212018
continue;
@@ -2035,16 +2032,16 @@ bool CodeStreamDecompress::fetchByTileSelective(
20352032
{
20362033
uint64_t rangeFileOffset = dataStart + ranges[r].offset;
20372034
uint32_t rangeLen = (uint32_t)ranges[r].length;
2038-
selectiveTileParts_[tileIndex]->push_back(
2039-
(uint8_t)(1 + r), numEntries, rangeFileOffset, rangeLen);
2035+
selectiveTileParts_[tileIndex]->push_back((uint8_t)(1 + r), numEntries, rangeFileOffset,
2036+
rangeLen);
20402037
}
20412038
}
20422039
selectiveFetchTiles->insert(tileIndex);
20432040
}
20442041

20452042
if(selectiveFetchTiles->empty())
20462043
return false;
2047-
grklog.info("fetchByTileSelective: %zu tiles to fetch", selectiveFetchTiles->size());
2044+
grklog.debug("fetchByTileSelective: %zu tiles to fetch", selectiveFetchTiles->size());
20482045

20492046
// Track which tiles have disjoint (sparse) fetch entries
20502047
auto disjointTiles = std::make_shared<std::set<uint16_t>>();
@@ -2081,18 +2078,18 @@ bool CodeStreamDecompress::fetchByTileSelective(
20812078

20822079
fetchByTileFutures_.push_back(fetcher->fetchTiles(
20832080
selectiveTileParts_, *selectiveFetchTiles, nullptr,
2084-
[this, numTileCols, unreducedImageBounds, postGenerator,
2085-
selectiveFetchTiles, disjointTiles](size_t requestIndex, TileFetchContext* context) {
2081+
[this, numTileCols, unreducedImageBounds, postGenerator, selectiveFetchTiles,
2082+
disjointTiles](size_t requestIndex, TileFetchContext* context) {
20862083
auto& tilePart = (*context->requests_)[requestIndex];
20872084
auto tileIndex = tilePart->tileIndex_;
20882085
auto& tilePartSeq = (*context->tilePartFetchByTile_)[tileIndex];
20892086

20902087
if(!disjointTiles->count(tileIndex))
20912088
{
20922089
// Contiguous case: create MemStream per entry (standard path)
2093-
tilePart->stream_ = std::unique_ptr<IStream>(memStreamCreate(
2094-
tilePart->data_.get(), tilePart->length_, false, nullptr,
2095-
stream_->getFormat(), true));
2090+
tilePart->stream_ =
2091+
std::unique_ptr<IStream>(memStreamCreate(tilePart->data_.get(), tilePart->length_,
2092+
false, nullptr, stream_->getFormat(), true));
20962093
}
20972094

20982095
if(tilePartSeq->incrementFetchCount() == tilePartSeq->size())
@@ -2119,12 +2116,11 @@ bool CodeStreamDecompress::fetchByTileSelective(
21192116

21202117
// Create single-entry TPFetchSeq with assembled data
21212118
decompressSeq = std::make_shared<TPFetchSeq>();
2122-
auto assembledFetch =
2123-
std::make_shared<TPFetch>(0, totalSize, tileIndex);
2119+
auto assembledFetch = std::make_shared<TPFetch>(0, totalSize, tileIndex);
21242120
assembledFetch->data_ = std::move(assembled);
2125-
assembledFetch->stream_ = std::unique_ptr<IStream>(memStreamCreate(
2126-
assembledFetch->data_.get(), totalSize, false, nullptr,
2127-
stream_->getFormat(), true));
2121+
assembledFetch->stream_ = std::unique_ptr<IStream>(
2122+
memStreamCreate(assembledFetch->data_.get(), totalSize, false, nullptr,
2123+
stream_->getFormat(), true));
21282124
decompressSeq->SharedPtrSeq<TPFetch>::push_back(assembledFetch);
21292125
}
21302126
else
@@ -2138,8 +2134,7 @@ bool CodeStreamDecompress::fetchByTileSelective(
21382134
int32_t tileRow = tileIndex / numTileCols;
21392135
int32_t prev = maxFetchedTileRow_.load(std::memory_order_acquire);
21402136
while(prev < tileRow &&
2141-
!maxFetchedTileRow_.compare_exchange_weak(prev, tileRow,
2142-
std::memory_order_release,
2137+
!maxFetchedTileRow_.compare_exchange_weak(prev, tileRow, std::memory_order_release,
21432138
std::memory_order_acquire))
21442139
{
21452140
}

src/lib/core/scheduling/standard/CompressScheduler.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ CompressScheduler::CompressScheduler(Tile* tile, bool needsRateControl, TileCodi
6262
const double* mct_norms, uint16_t mct_numcomps,
6363
bool progressiveRateControl)
6464
: SchedulerStandard(tile->numcomps_), tile_(tile), needsRateControl_(needsRateControl),
65-
progressiveRateControl_(progressiveRateControl),
66-
blockCount_(-1), tcp_(tcp), mct_norms_(mct_norms), mct_numcomps_(mct_numcomps)
65+
progressiveRateControl_(progressiveRateControl), blockCount_(-1), tcp_(tcp),
66+
mct_norms_(mct_norms), mct_numcomps_(mct_numcomps)
6767
{
6868
rateControlStats_.init(tile->numcomps_);
6969
}
@@ -339,8 +339,7 @@ void CompressScheduler::compress(t1::ICoder* coder, t1::CompressBlockExec* block
339339
}
340340
}
341341

342-
void CompressScheduler::initSlopeEstimator(
343-
const std::vector<t1::CompressBlockExec*>& blocks)
342+
void CompressScheduler::initSlopeEstimator(const std::vector<t1::CompressBlockExec*>& blocks)
344343
{
345344
// The progressive slope estimator requires:
346345
// 1. A target rate is specified (rate-distortion mode)

0 commit comments

Comments
 (0)