Skip to content

Commit

Permalink
Fixed some minor issues in previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
smistad committed Nov 22, 2024
1 parent 5d201e6 commit d8019e9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
7 changes: 1 addition & 6 deletions source/FAST/Data/Access/ImagePyramidAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> lock(m_readMutex);
setTIFFDirectory(level);
TIFFSetDirectory(m_tiffHandle, level);
uint32_t tile_id = TIFFComputeTile(m_tiffHandle, x, y, 0, 0);
JPEGXLCompression jxl;
std::vector<uchar> compressed;
Expand Down Expand Up @@ -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");
Expand Down
15 changes: 14 additions & 1 deletion source/FAST/Data/Access/ImagePyramidAccess.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,21 @@ class FAST_EXPORT ImagePyramidAccess : Object {
public:
typedef std::unique_ptr<ImagePyramidAccess> pointer;
ImagePyramidAccess(std::vector<ImagePyramidLevel> levels, openslide_t* fileHandle, TIFF* tiffHandle, std::shared_ptr<ImagePyramid> imagePyramid, bool writeAccess, std::unordered_set<std::string>& 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<Image> 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 <class T>
Expand Down Expand Up @@ -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> image);
int readTileFromTIFF(void* data, int x, int y, int level);
void setTIFFDirectory(int level);
};

template <class T>
Expand Down
9 changes: 5 additions & 4 deletions source/FAST/Data/ImagePyramid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uchar[]>(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<uchar[]>(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<uchar[]>(levelData.tileWidth*levelData.tileHeight*samplesPerPixel); // Is initialized to zeros
TIFFWriteTile(tiff, data.get(), 0, 0, 0, 0);
Expand Down

0 comments on commit d8019e9

Please sign in to comment.