Skip to content

Commit

Permalink
Use zero bytes when storing blank patches in TIFF
Browse files Browse the repository at this point in the history
  • Loading branch information
smistad committed Dec 13, 2024
1 parent 330d716 commit 2718a17
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
21 changes: 7 additions & 14 deletions source/FAST/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,24 +362,17 @@ namespace fast {
return;
std::cout << "Downloading test data (~2GB) to " << destination << std::endl;
createDirectories(destination);
std::cout << "Progress: " << std::endl;
Window::initializeQtApp();
QNetworkAccessManager manager;
QUrl url("https://folk.ntnu.no/smistad/fast/FAST_Test_Data.zip");
QUrl url("https://smistad.folk.ntnu.no/fast/FAST_Test_Data.zip");
QNetworkRequest request(url);
auto timer = new QElapsedTimer;
timer->start();
request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
auto reply = manager.get(request);
int step = 5;
int progress = step;
QObject::connect(reply, &QNetworkReply::downloadProgress, [&progress, timer, step](quint64 current, quint64 max) {
int percent = ((float)current / max) * 100;
float speed = ((float)timer->elapsed() / 1000.0f)/percent;
uint64_t remaining = speed * (100 - percent);
if(percent >= progress) {
std::cout << percent << "% - ETA ~" << (int)std::ceil((float)remaining / 60) << " minutes. " << std::endl;;
progress += step;
}
Progress progressBar(1);
progressBar.setText("Downloading");
QObject::connect(reply, &QNetworkReply::downloadProgress, [&progressBar](quint64 current, quint64 max) {
progressBar.setMax(max) ;
progressBar.update(current) ;
});
auto tempLocation = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/FAST_Test_Data.zip";
QFile file(tempLocation);
Expand Down
4 changes: 2 additions & 2 deletions source/FAST/Data/Access/ImagePyramidAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ int ImagePyramidAccess::readTileFromTIFF(void *data, int x, int y, int level) {
const auto channels = m_image->getNrOfChannels();
TIFFSetDirectory(m_tiffHandle, level);
const uint32_t tile_id = TIFFComputeTile(m_tiffHandle, x, y, 0, 0);
if(TIFFGetStrileByteCount(m_tiffHandle, tile_id) == 1) { // Blank patch
if(TIFFGetStrileByteCount(m_tiffHandle, tile_id) == 0) { // Blank patch
if(channels == 1) {
std::memset(data, 0, tileWidth*tileHeight*channels);
} else {
Expand Down Expand Up @@ -605,7 +605,7 @@ void ImagePyramidAccess::setBlankPatch(int level, int x, int y) {
TIFFSetWriteOffset(m_tiffHandle, 0); // Set write offset to 0, so that we dont appen data
// Writing zero bytes, will produce a warning, thus we write 1 byte
char data = 0;
TIFFWriteRawTile(m_tiffHandle, tile_id, &data, 1);
TIFFWriteRawTile(m_tiffHandle, tile_id, &data, 0);
TIFFCheckpointDirectory(m_tiffHandle);
m_initializedPatchList.insert(std::to_string(level) + "-" + std::to_string(tile_id));

Expand Down
7 changes: 5 additions & 2 deletions source/FAST/Data/ImagePyramid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ ImagePyramid::ImagePyramid(int width, int height, int channels, int patchWidth,
TIFFSetErrorHandler([](const char* module, const char* fmt, va_list ap) {
auto str = make_uninitialized_unique<char[]>(512);
sprintf(str.get(), fmt, ap);
Reporter::warning() << "TIFF: " << module << ": " << str.get() << Reporter::end();
std::string str2 = str.get();
if(strcmp(module, "TIFFAppendToStrip") == 0 && str2.substr(0, 23) == "Write error at scanline") // Suppress error when writing 0 byte patches
return;
Reporter::warning() << "TIFF error: " << module << ": " << str.get() << Reporter::end();
});
TIFFSetWarningHandler([](const char* module, const char* fmt, va_list ap) {
auto str = make_uninitialized_unique<char[]>(512);
sprintf(str.get(), fmt, ap);
Reporter::warning() << "TIFF: " << module << ": " << str.get() << Reporter::end();
Reporter::warning() << "TIFF warning: " << module << ": " << str.get() << Reporter::end();
});
m_tiffHandle = TIFFOpen(m_tiffPath.c_str(), "w8"); // 8 == Bigtiff (64 bit)
auto tiff = m_tiffHandle;
Expand Down
3 changes: 3 additions & 0 deletions source/FAST/Utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1281,4 +1281,7 @@ void Progress::setText(std::string text) {
m_text = text;
}

void Progress::setMax(uint64_t max) {
m_max = max;
}
} // end namespace fast
1 change: 1 addition & 0 deletions source/FAST/Utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ class FAST_EXPORT Progress {
float getPercent() const;
void setText(std::string text);
uint64_t getCurrent() const;
void setMax(uint64_t max);
private:
std::chrono::high_resolution_clock::time_point m_startTime;
bool m_print = true;
Expand Down

0 comments on commit 2718a17

Please sign in to comment.