From d8019e99d7991c60775aeabf10b9a32a83df3281 Mon Sep 17 00:00:00 2001 From: Erik Smistad Date: Fri, 22 Nov 2024 15:46:17 +0100 Subject: [PATCH] Fixed some minor issues in previous commit --- source/FAST/Data/Access/ImagePyramidAccess.cpp | 7 +------ source/FAST/Data/Access/ImagePyramidAccess.hpp | 15 ++++++++++++++- source/FAST/Data/ImagePyramid.cpp | 9 +++++---- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/source/FAST/Data/Access/ImagePyramidAccess.cpp b/source/FAST/Data/Access/ImagePyramidAccess.cpp index 0301540e2..817b19cf5 100644 --- a/source/FAST/Data/Access/ImagePyramidAccess.cpp +++ b/source/FAST/Data/Access/ImagePyramidAccess.cpp @@ -351,7 +351,7 @@ uint32_t ImagePyramidAccess::writeTileToTIFF(int level, int x, int y, uchar *dat uint32_t ImagePyramidAccess::writeTileToTIFFJPEGXL(int level, int x, int y, uchar *data) { std::lock_guard lock(m_readMutex); - setTIFFDirectory(level); + TIFFSetDirectory(m_tiffHandle, level); uint32_t tile_id = TIFFComputeTile(m_tiffHandle, x, y, 0, 0); JPEGXLCompression jxl; std::vector compressed; @@ -603,11 +603,6 @@ int ImagePyramidAccess::readTileFromTIFF(void *data, int x, int y, int level) { } } -void ImagePyramidAccess::setTIFFDirectory(int level) { - if(TIFFCurrentDirectory(m_tiffHandle) != level) - TIFFSetDirectory(m_tiffHandle, level); -} - void ImagePyramidAccess::setBlankPatch(int level, int x, int y) { if(m_tiffHandle == nullptr) throw Exception("setBlankPatch only available for TIFF backend ImagePyramids"); diff --git a/source/FAST/Data/Access/ImagePyramidAccess.hpp b/source/FAST/Data/Access/ImagePyramidAccess.hpp index 05ff26a33..71b38e964 100644 --- a/source/FAST/Data/Access/ImagePyramidAccess.hpp +++ b/source/FAST/Data/Access/ImagePyramidAccess.hpp @@ -62,7 +62,21 @@ class FAST_EXPORT ImagePyramidAccess : Object { public: typedef std::unique_ptr pointer; ImagePyramidAccess(std::vector levels, openslide_t* fileHandle, TIFF* tiffHandle, std::shared_ptr imagePyramid, bool writeAccess, std::unordered_set& initializedPatchList, std::mutex& readMutex, ImageCompression compressionFormat); + /** + * @brief Write a patch to the pyramid + * @param level + * @param x + * @param y + * @param patch + * @param propagate + */ void setPatch(int level, int x, int y, std::shared_ptr patch, bool propagate = true); + /** + * @brief Write patch/tile as empty. It will render as white/black + * @param level + * @param x + * @param y + */ void setBlankPatch(int level, int x, int y); bool isPatchInitialized(uint level, uint x, uint y); template @@ -99,7 +113,6 @@ class FAST_EXPORT ImagePyramidAccess : Object { uint32_t writeTileToTIFFJPEGXL(int level, int x, int y, uchar *data); uint32_t writeTileToTIFFNeuralNetwork(int level, int x, int y, std::shared_ptr image); int readTileFromTIFF(void* data, int x, int y, int level); - void setTIFFDirectory(int level); }; template diff --git a/source/FAST/Data/ImagePyramid.cpp b/source/FAST/Data/ImagePyramid.cpp index bbe51b377..2c810909e 100644 --- a/source/FAST/Data/ImagePyramid.cpp +++ b/source/FAST/Data/ImagePyramid.cpp @@ -150,10 +150,11 @@ ImagePyramid::ImagePyramid(int width, int height, int channels, int patchWidth, // TileOffsets TIFFCheckpointDirectory(m_tiffHandle); // Need to check in the tile width and length tags, before writing a tile if(m_compressionFormat == ImageCompression::JPEGXL) { - auto data = std::make_unique(samplesPerPixel); // Is initialized to zeros - auto tileID = TIFFComputeTile(tiff, 0, 0, 0, 0); - TIFFSetWriteOffset(tiff, 0); // Set write offset to 0, so that we dont appen data - TIFFWriteRawTile(tiff, tileID, data.get(), samplesPerPixel); + // TODO Not needed? + //auto data = std::make_unique(samplesPerPixel); // Is initialized to zeros + //auto tileID = TIFFComputeTile(tiff, 0, 0, 0, 0); + //TIFFSetWriteOffset(tiff, 0); // Set write offset to 0, so that we dont appen data + //TIFFWriteRawTile(tiff, tileID, data.get(), samplesPerPixel); } else { auto data = std::make_unique(levelData.tileWidth*levelData.tileHeight*samplesPerPixel); // Is initialized to zeros TIFFWriteTile(tiff, data.get(), 0, 0, 0, 0);