4#ifndef OPENCV_slideio_ndpitifftools_HPP
5#define OPENCV_slideio_ndpitifftools_HPP
8#include "slideio/drivers/ndpi/ndpi_api_def.hpp"
9#include "slideio/core/cvstructs.hpp"
10#include "slideio/base/slideio_enums.hpp"
11#include "slideio/base/base.hpp"
12#include <opencv2/core.hpp>
23#pragma warning( push )
24#pragma warning(disable: 4251)
32 struct SLIDEIO_NDPI_EXPORTS NDPITiffDirectory
49 int YCbCrSubsampling[2];
54 std::string description;
55 std::string userLabel;
57 std::vector<NDPITiffDirectory> subdirectories;
66 std::vector<uint32_t> mcuStarts;
67 uint64_t jpegHeaderOffset;
68 uint64_t jpegSOFMarker;
69 uint32_t jpegHeaderSize;
70 uint32_t rawStripSize = 0;
71 bool auxImage =
false;
73 Type getType()
const {
77 else if(tileWidth > 0 && tileHeight > 0 && !mcuStarts.empty() && slideioCompression == Compression::Jpeg) {
78 return Type::SingleStripeMCU;
80 else if(rowsPerStrip == height) {
81 return Type::SingleStripe;
89 SLIDEIO_NDPI_EXPORTS std::ostream& operator << (std::ostream& os,
const NDPITiffDirectory::Type& type);;
91 class SLIDEIO_NDPI_EXPORTS NDPITiffTools
94 static libtiff::TIFF* openTiffFile(
const std::string& path);
95 static void closeTiffFile(libtiff::TIFF* file);
96 static cv::Size computeMCUTileSize(FILE* file,
const cv::Size& dirSize);
97 static std::pair<uint64_t, uint64_t> getJpegHeaderPos(FILE* file);
98 static void readMCUTile(FILE* file,
const NDPITiffDirectory& dir,
int tile, cv::OutputArray output);
99 static void jpeglibDecodeTile(
const uint8_t* jpg_buffer,
size_t jpg_size,
const cv::Size& tileSize, cv::OutputArray output);
100 static void scanTiffDirTags(libtiff::TIFF* tiff,
int dirIndex, int64_t dirOffset, slideio::NDPITiffDirectory& dir);
101 static void updateJpegXRCompressedDirectoryMedatata(libtiff::TIFF* tiff, NDPITiffDirectory& dir);
102 static void scanTiffDir(libtiff::TIFF* tiff,
int dirIndex, int64_t dirOffset, slideio::NDPITiffDirectory& dir);
103 static void readNotRGBStripedDir(libtiff::TIFF* tiff,
const NDPITiffDirectory& dir, cv::_OutputArray output);
104 static void readRegularStripedDir(libtiff::TIFF* file,
const slideio::NDPITiffDirectory& dir, cv::OutputArray output);
105 static void readJpegXRStripedDir(libtiff::TIFF* tiff,
const NDPITiffDirectory& dir, cv::_OutputArray output);
106 static void readStripedDir(libtiff::TIFF* file,
const slideio::NDPITiffDirectory& dir, cv::OutputArray output);
107 static void readJpegXRTile(libtiff::TIFF* tiff,
const slideio::NDPITiffDirectory& dir,
int tile,
const std::vector<int>& vector, cv::OutputArray output);
108 static void readTile(libtiff::TIFF* hFile,
const slideio::NDPITiffDirectory& dir,
int tile,
109 const std::vector<int>& channelIndices, cv::OutputArray output);
110 static void readJpegXRStrip(libtiff::TIFF* tiff,
const NDPITiffDirectory& dir,
int strip,
const std::vector<int>& vector, cv::_OutputArray output);
111 static void readNotRGBStrip(libtiff::TIFF* tiff,
const NDPITiffDirectory& dir,
int strip,
const std::vector<int>& vector, cv::_OutputArray output);
112 static void readRegularStrip(libtiff::TIFF* tiff,
const NDPITiffDirectory& dir,
int strip,
const std::vector<int>& vector, cv::_OutputArray output);
113 static void readStripe(libtiff::TIFF* hFile,
const slideio::NDPITiffDirectory& dir,
int strip,
114 const std::vector<int>& channelIndices, cv::OutputArray output);
115 static void setCurrentDirectory(libtiff::TIFF* hFile,
const slideio::NDPITiffDirectory& dir);
116 static void decodeJxrBlock(
const uint8_t* data,
size_t dataBlockSize, cv::OutputArray output);
117 static void readRegularTile(libtiff::TIFF* hFile,
const slideio::NDPITiffDirectory& dir,
int tile,
118 const std::vector<int>& channelIndices, cv::OutputArray output);
119 static void readNotRGBTile(libtiff::TIFF* hFile,
const slideio::NDPITiffDirectory& dir,
int tile,
120 const std::vector<int>& channelIndices, cv::OutputArray output);
121 static int computeStripHeight(
int height,
int rowsPerStrip,
int strip);
122 static cv::Size computeTileSize(
const NDPITiffDirectory& dir,
int tile);
123 static cv::Size computeTileCounts(
const NDPITiffDirectory& dir);
124 static void readJpegScanlines(libtiff::TIFF* tiff, FILE* file,
const NDPITiffDirectory& dir,
int firstScanline,
125 int numberScanlines,
const std::vector<int>& channelIndices, cv::_OutputArray output);
126 static void cacheScanlines(NDPIFile* file,
const NDPITiffDirectory& dir,
127 cv::Size tileSize, CacheManager* cacheManager);
128 static void readJpegDirectoryRegion(libtiff::TIFF* tiff,
const std::string& filePath,
const cv::Rect& region,
const NDPITiffDirectory& dir,
129 const std::vector<int>& channelIndices, cv::_OutputArray output);
130 static void readDirectoryJpegHeaders(NDPIFile* ndpi, NDPITiffDirectory& dir);
131 static void readUncompressedScanlines(libtiff::TIFF* tiff, FILE* file,
const NDPITiffDirectory& dir,
int firstScanline,
int numberScanlines,
const std::vector<int>& vector,
132 cv::_OutputArray tileRaster);
134 static void fixJpegHeader(
const NDPITiffDirectory& dir, uint8_t* data);
140 NDPITIFFKeeper(libtiff::TIFF* hfile=
nullptr);
142 libtiff::TIFF* getHandle()
const{
145 bool isValid()
const{
146 return getHandle() !=
nullptr;
148 operator libtiff::TIFF* ()
const {
151 NDPITIFFKeeper& operator = (libtiff::TIFF* hFile){
157 libtiff::TIFF* m_hFile;
162#pragma warning( pop )
Definition: exceptions.hpp:12
Compression
raster data compression enum
Definition: slideio_enums.hpp:12