@@ -14,10 +14,10 @@ class Image;
1414class ImagePyramid ;
1515class NeuralNetwork ;
1616
17-
1817/* *
1918 * @brief Image compression types for ImagePyramids
2019 *
20+ * @sa ImagePyramid
2121 * @ingroup wsi
2222 */
2323enum class ImageCompression {
@@ -31,41 +31,34 @@ enum class ImageCompression {
3131 DEFLATE, // Zlib lossless
3232};
3333
34- class FAST_EXPORT ImagePyramidPatch {
35- public:
36- std::unique_ptr<uchar[]> data;
37- int width;
38- int height;
39- int offsetX;
40- int offsetY;
41- };
42-
34+ /* *
35+ * @brief Object for metadata of an ImagePyramid level
36+ * @sa ImagePyramid
37+ * @ingroup wsi
38+ */
4339class FAST_EXPORT ImagePyramidLevel {
4440public:
4541 int width;
4642 int height;
47- int tileWidth = 256 ;
48- int tileHeight = 256 ;
43+ int tileWidth = 1024 ;
44+ int tileHeight = 1024 ;
4945 int tilesX;
5046 int tilesY;
51- bool memoryMapped;
52- uint8_t * data;
5347 uint64_t offset = 0 ; // subifd offset used by OME-TIFF
54- #ifdef WIN32
55- void * fileHandle;
56- #else
57- int fileHandle;
58- #endif
5948};
6049
6150/* *
6251 * @brief CPU access to ImagePyramid
6352 * @ingroup access
6453 */
65- class FAST_EXPORT ImagePyramidAccess : Object {
54+ #ifdef SWIG
55+ class FAST_EXPORT ImagePyramidAccess {
56+ #else
57+ class FAST_EXPORT ImagePyramidAccess : public Object {
58+ #endif
6659public:
6760 typedef std::unique_ptr<ImagePyramidAccess> pointer;
68- 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);
61+ 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, bool useCache = false , int cacheLimit = - 1 );
6962 /* *
7063 * @brief Write a patch to the pyramid
7164 * @param level
@@ -85,8 +78,32 @@ class FAST_EXPORT ImagePyramidAccess : Object {
8578 bool isPatchInitialized (int level, int x, int y);
8679 template <class T >
8780 std::unique_ptr<T[]> getPatchData (int level, int x, int y, int width, int height);
81+ /* *
82+ * @brief Get a specific level in an ImagePyramid as an Image object.
83+ * If requesting a level with a width or height higher than 16384 pixels this will throw an exception.
84+ * @param level
85+ * @return
86+ */
8887 std::shared_ptr<Image> getLevelAsImage (int level);
88+ /* *
89+ * @brief Extract a patch from the image pyramid and return it as an Image
90+ * @param level Level to extract patch from
91+ * @param offsetX X offset
92+ * @param offsetY Y offset
93+ * @param width Width of patch
94+ * @param height Height of patch
95+ * @param convertToRGB convert to RGB when using OpenSlide, since it will return BGRA data
96+ * @return Patch as Image
97+ */
8998 std::shared_ptr<Image> getPatchAsImage (int level, int offsetX, int offsetY, int width, int height, bool convertToRGB = true );
99+ /* *
100+ * @brief Extract a tile from the Image Pyramid
101+ * @param level Level to extract tile from
102+ * @param patchIdX Tile X id
103+ * @param patchIdY Tile Y id
104+ * @param convertToRGB convert to RGB when using OpenSlide, since it will return BGRA data
105+ * @return Tile as Image
106+ */
90107 std::shared_ptr<Image> getPatchAsImage (int level, int patchIdX, int patchIdY, bool convertToRGB = true );
91108 /* *
92109 * @brief Get patch as Image at a specific magnification
@@ -95,12 +112,12 @@ class FAST_EXPORT ImagePyramidAccess : Object {
95112 * @param offsetY Physical offset y position of patch
96113 * @param width Width of patch in pixels
97114 * @param height Height of patch in pixels
98- * @param convertToRGB Convert from BGR to RGB if needed
115+ * @param convertToRGB convert to RGB when using OpenSlide, since it will return BGRA data
99116 * @return patch as Image object
100117 */
101118 std::shared_ptr<Image> getPatchAsImageForMagnification (float magnification, float offsetX, float offsetY, int width, int height, bool convertToRGB = true );
102119 void release ();
103- ~ImagePyramidAccess ();
120+ ~ImagePyramidAccess () override ;
104121 void setJPEGTables (uint32_t tableCount, void * tableData);
105122private:
106123 std::unique_ptr<uchar[]> getPatchDataChar (int level, int x, int y, int width, int height);
@@ -123,6 +140,14 @@ class FAST_EXPORT ImagePyramidAccess : Object {
123140
124141 uint32_t m_JPEGTablesCount = 0 ;
125142 void * m_JPEGTablesData = nullptr ;
143+
144+ // Optional tile cache
145+ void addTileToQueue (const std::string& id);
146+ std::unordered_map<std::string, std::shared_ptr<char []>> m_tileCache; // Should ideally be a unique_ptr here, but MSVC can't handle that
147+ std::deque<std::string> m_tileCacheQueue;
148+ std::unordered_map<std::string, int > m_tileCacheCounter;
149+ uint64_t m_tileCacheSizeLimit;
150+ bool m_useTileCache;
126151};
127152
128153template <class T >
0 commit comments