SlideIO 2.0.0
Open-source library for reading of medical images
Loading...
Searching...
No Matches
czisubblock.hpp
1// This file is part of slideio project.
2// It is subject to the license terms in the LICENSE file found in the top-level directory
3// of this distribution and at http://slideio.com/license.html.
4#ifndef OPENCV_slideio_czisubblock_HPP
5#define OPENCV_slideio_czisubblock_HPP
6
7#include "slideio/drivers/czi/czi_api_def.hpp"
8#include "slideio/drivers/czi/czistructs.hpp"
9#include "slideio/base/slideio_enums.hpp"
10#include <opencv2/core.hpp>
11#include <cstdint>
12#include <vector>
13
14#if defined(_MSC_VER)
15#pragma warning( push )
16#pragma warning(disable: 4251)
17#endif
18
19namespace slideio
20{
21 class SLIDEIO_CZI_EXPORTS CZISubBlock
22 {
23 public:
24 enum Compression
25 {
26 Uncompressed = 0,
27 Jpeg = 1,
28 LZW = 2,
29 JpegXR = 4
30 };
31 CZISubBlock();
32 int firstChannel() const { return firstDimensionIndex(m_channelIndex);}
33 int lastChannel() const { return lastDimensionIndex(m_channelIndex); }
34 int firstZSlice() const { return firstDimensionIndex(m_zSliceIndex); }
35 int lastZSlice() const { return lastDimensionIndex(m_zSliceIndex); }
36 int firstTFrame() const { return firstDimensionIndex(m_tFrameIndex); }
37 int lastTFrame() const { return lastDimensionIndex(m_tFrameIndex); }
38 int firstScene() const { return firstDimensionIndex(m_sceneIndex); }
39 int lastScene() const { return lastDimensionIndex(m_sceneIndex); }
40 int firstIllumination() const { return firstDimensionIndex(m_illuminationIndex); }
41 int lastIllumination() const { return lastDimensionIndex(m_illuminationIndex); }
42 int firstRotation() const { return firstDimensionIndex(m_rotationIndex); }
43 int lastRotation() const { return lastDimensionIndex(m_rotationIndex); }
44 int firstBAcquisition() const { return firstDimensionIndex(m_bAcquisitionIndex); }
45 int lastBAcquisition() const { return lastDimensionIndex(m_bAcquisitionIndex); }
46 int firstHPhase() const { return firstDimensionIndex(m_hPhaseIndex); }
47 int lastHPhase() const { return lastDimensionIndex(m_hPhaseIndex); }
48 int firstView() const { return firstDimensionIndex(m_viewIndex); }
49 int lastView() const { return lastDimensionIndex(m_viewIndex); }
50 int firstMosaic() const { return firstDimensionIndex(m_mosaicIndex); }
51 int lastMosaic() const { return lastDimensionIndex(m_mosaicIndex); }
52 bool isMosaic() const { return m_mosaicIndex > 0; }
53 double zoom() const { return m_zoom; }
54 const cv::Rect& rect() const { return m_rect; }
55 int cziPixelType() const { return m_cziPixelType; }
56 int64_t computeDataOffset(int channel, int z, int t, int r, int s, int i, int b, int h, int v) const;
57 void setupBlock(const SubBlockHeader& subblockHeader, std::vector<DimensionEntryDV>& dimensions);
58 bool isInBlock(int channel, int z, int t, int r, int s, int i, int b, int h, int v) const;
59 int pixelSize() const { return m_pixelSize; }
60 slideio::DataType dataType() const {return m_dataType;};
61 int planeSize() const {return m_planeSize;}
62 uint64_t dataPosition() const {return m_dataPosition;}
63 uint64_t dataSize() const {return m_dataSize;}
64 Compression compression() const {return static_cast<Compression>(m_compression);}
65 const std::vector<Dimension>& dimensions() const {return m_dimensions;}
66 static std::string blockHeaderString()
67 {
68 std::string header= "Scene0\tSceneN\tZoom\tX\tY\tWidth\tHeight\t"
69 "Ch0\tChN\tZ0\tZN\tT0\tTN"
70 "\tAcq0\tAcqN\tPhase0\tPhaseN\tIll0\tIllN\tRot0\tRotN\tView0\tViewN";
71 return header;
72 }
73 friend std::ostream &operator<<(std::ostream &output, const CZISubBlock &subBlock) {
74 output << subBlock.firstScene() << "\t";
75 output << subBlock.lastScene() << "\t";
76 output << subBlock.m_zoom << "\t";
77 output << subBlock.m_rect.x << "\t";
78 output << subBlock.m_rect.y << "\t";
79 output << subBlock.m_rect.width << "\t";
80 output << subBlock.m_rect.height << "\t";
81 output << subBlock.firstChannel() << "\t";
82 output << subBlock.lastChannel() << "\t";
83 output << subBlock.firstZSlice() << "\t";
84 output << subBlock.lastZSlice() << "\t";
85 output << subBlock.firstTFrame() << "\t";
86 output << subBlock.lastTFrame() << "\t";
87 output << subBlock.firstBAcquisition() << "\t";
88 output << subBlock.lastBAcquisition() << "\t";
89 output << subBlock.firstHPhase() << "\t";
90 output << subBlock.lastHPhase() << "\t";
91 output << subBlock.firstIllumination() << "\t";
92 output << subBlock.lastIllumination() << "\t";
93 output << subBlock.firstRotation() << "\t";
94 output << subBlock.lastRotation() << "\t";
95 output << subBlock.firstView() << "\t";
96 output << subBlock.lastView() << "\t";
97 output << std::endl;
98 return output;
99 }
100 private:
101 int firstDimensionIndex(int dimension) const
102 {
103 if(dimension>=0 && dimension<static_cast<int>(m_dimensions.size()))
104 return m_dimensions[dimension].start;
105 return 0;
106 }
107 int lastDimensionIndex(int dimension) const
108 {
109 if (dimension >= 0 && dimension < static_cast<int>(m_dimensions.size()))
110 return (m_dimensions[dimension].start + m_dimensions[dimension].size - 1);
111 return 0;
112 }
113 private:
114 slideio::DataType m_dataType;
115 cv::Rect m_rect;
116 int32_t m_cziPixelType;
117 int32_t m_pixelSize;
118 int32_t m_planeSize;
119 int64_t m_filePosition;
120 int64_t m_dataPosition;
121 int64_t m_dataSize;
122 int32_t m_filePart;
123 int32_t m_compression;
124 int m_channelIndex;
125 int m_zSliceIndex;
126 int m_tFrameIndex;
127 int m_illuminationIndex;
128 int m_bAcquisitionIndex;
129 int m_rotationIndex;
130 int m_sceneIndex;
131 int m_hPhaseIndex;
132 int m_viewIndex;
133 int m_mosaicIndex;
134 double m_zoom;
135 std::vector<Dimension> m_dimensions;
136 };
137 typedef std::vector<CZISubBlock> CZISubBlocks;
138}
139
140#if defined(_MSC_VER)
141#pragma warning( pop )
142#endif
143
144#endif
Definition: exceptions.hpp:12
Compression
raster data compression enum
Definition: slideio_enums.hpp:12
@ Jpeg
JPEG compression.
@ Uncompressed
Uncompressed data.
@ LZW
Lempel - Ziv - Welch universal lossless data compression algorithm.
@ JpegXR
JPEG XR compression.