ITK  6.0.0
Insight Toolkit
itkTIFFImageIO.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkTIFFImageIO_h
19#define itkTIFFImageIO_h
20#include "ITKIOTIFFExport.h"
21
22#include "itkImageIOBase.h"
23#include <fstream>
24
25namespace itk
26{
27// BTX
28class TIFFReaderInternal;
29// ETX
30
48class ITKIOTIFF_EXPORT TIFFImageIO : public ImageIOBase
49{
50public:
51 ITK_DISALLOW_COPY_AND_MOVE(TIFFImageIO);
52
57
59 using PaletteType = std::vector<RGBPixelType>;
60
62 itkNewMacro(Self);
63
65 itkOverrideGetNameOfClassMacro(TIFFImageIO);
66
67 /*-------- This part of the interface deals with reading data. ------ */
68
71 bool
72 CanReadFile(const char *) override;
73
75 void
77
79 void
80 Read(void * buffer) override;
81
83 virtual void
84 ReadVolume(void * buffer);
85
86 /*-------- This part of the interfaces deals with writing data. ----- */
87
90 bool
91 CanWriteFile(const char *) override;
92
95 void
97
100 void
101 Write(const void * buffer) override;
102
103 enum
104 {
110 OTHER
111 };
112
113 // BTX
114 enum
115 { // Compression types
120 LZW
121 };
122 // ETX
123
128 void
130 {
131 this->UseCompressionOff();
132 this->SetCompressor("NoCompression");
133 }
134 void
136 {
137 this->UseCompressionOn();
138 this->SetCompressor("PackBits");
139 }
140 void
142 {
143 this->UseCompressionOn();
144 this->SetCompressor("JPEG");
145 }
146 void
148 {
149 this->UseCompressionOn();
150 this->SetCompressor("Deflate");
151 }
152 void
154 {
155 this->UseCompressionOn();
156 this->SetCompressor("LZW");
157 }
158
159
163 virtual void
164 SetJPEGQuality(int _JPEGQuality)
165 {
166 this->SetCompressionLevel(_JPEGQuality);
167 }
168 virtual int
170 {
171 return this->GetCompressionLevel();
172 }
180 itkGetConstReferenceMacro(ColorPalette, PaletteType);
181
184 void
186 {
187 if (this->m_ColorPalette != _arg)
188 {
189 this->m_ColorPalette = _arg;
190 this->Modified();
191 }
192 }
195protected:
197 ~TIFFImageIO() override;
198 void
199 PrintSelf(std::ostream & os, Indent indent) const override;
200
201 void
202 InternalSetCompressor(const std::string & _compressor) override;
203
204 // This method is protected because it does not keep
205 // ImageIO::m_Compressor and TIFFImageIO::m_Compression in sync.
206 void
207 SetCompression(int compression)
208 {
209 m_Compression = compression;
210 }
211
212 void
213 InternalWrite(const void * buffer);
214
215 void
217
218 void
219 ReadGenericImage(void * out, unsigned int width, unsigned int height);
220
221 // To support Zeiss images
222 void
223 ReadTwoSamplesPerPixelImage(void * out, unsigned int width, unsigned int height);
224
225 unsigned int
227
228 void
229 GetColor(uint64_t index, uint16_t * red, uint16_t * green, uint16_t * blue);
230
231 // Check that tag t can be found
232 bool
233 CanFindTIFFTag(unsigned int t);
234
235 // Read and returns the raw bytes of tag t
236 void *
237 ReadRawByteFromTag(unsigned int t, unsigned int & value_count);
238
239 // Populate m_ColorPalette from the file palette
240 // The palette corresponds to the one of the first page in case of multipage tiff
241 void
243
244 TIFFReaderInternal * m_InternalImage{};
245
246 void
248
249 int m_Compression{};
250
251 PaletteType m_ColorPalette{};
252
253private:
254 void
255 AllocateTiffPalette(uint16_t bps);
256
257 void
258 ReadCurrentPage(void * buffer, size_t pixelOffset);
259
260 template <typename TComponent>
261 void
262 ReadGenericImage(void * _out, unsigned int width, unsigned int height);
263
264 template <typename TComponent>
265 void
266 RGBAImageToBuffer(void * out, const uint32_t * tempImage);
267
268 template <typename TType>
269 void
270 PutGrayscale(TType * to,
271 TType * from,
272 unsigned int xsize,
273 unsigned int ysize,
274 unsigned int toskew,
275 unsigned int fromskew);
276
277 template <typename TType>
278 void
279 PutRGB_(TType * to, TType * from, unsigned int xsize, unsigned int ysize, unsigned int toskew, unsigned int fromskew);
280
281
282 template <typename TType, typename TFromType>
283 void
285 TFromType * from,
286 unsigned int xsize,
287 unsigned int ysize,
288 unsigned int toskew,
289 unsigned int fromskew);
290
291 template <typename TType, typename TFromType>
292 void
293 PutPaletteRGB(TType * to,
294 TFromType * from,
295 unsigned int xsize,
296 unsigned int ysize,
297 unsigned int toskew,
298 unsigned int fromskew);
299
300 template <typename TType, typename TFromType>
301 void
303 TFromType * from,
304 unsigned int xsize,
305 unsigned int ysize,
306 unsigned int toskew,
307 unsigned int fromskew);
308
309 uint16_t * m_ColorRed{};
310 uint16_t * m_ColorGreen{};
311 uint16_t * m_ColorBlue{};
312 uint64_t m_TotalColors{ 0 };
313 unsigned int m_ImageFormat{ TIFFImageIO::NOFORMAT };
314};
315} // end namespace itk
316
317#endif // itkTIFFImageIO_h
Abstract superclass defines image IO interface.
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
Base class for most ITK classes.
Definition: itkObject.h:62
Represent Red, Green and Blue components for color images.
Definition: itkRGBPixel.h:59
ImageIO object for reading and writing TIFF images.
bool CanFindTIFFTag(unsigned int t)
void WriteImageInformation() override
void Write(const void *buffer) override
unsigned int GetFormat()
void ReadTwoSamplesPerPixelImage(void *out, unsigned int width, unsigned int height)
void InternalSetCompressor(const std::string &_compressor) override
void SetCompression(int compression)
void AllocateTiffPalette(uint16_t bps)
void PutGrayscale(TType *to, TType *from, unsigned int xsize, unsigned int ysize, unsigned int toskew, unsigned int fromskew)
void ReadGenericImage(void *out, unsigned int width, unsigned int height)
virtual void SetJPEGQuality(int _JPEGQuality)
void SetCompressionToDeflate()
std::vector< RGBPixelType > PaletteType
void PutPaletteScalar(TType *to, TFromType *from, unsigned int xsize, unsigned int ysize, unsigned int toskew, unsigned int fromskew)
~TIFFImageIO() override
void SetCompressionToPackBits()
void PutPaletteRGB(TType *to, TFromType *from, unsigned int xsize, unsigned int ysize, unsigned int toskew, unsigned int fromskew)
void PutPaletteGrayscale(TType *to, TFromType *from, unsigned int xsize, unsigned int ysize, unsigned int toskew, unsigned int fromskew)
void SetCompressionToNoCompression()
Set type and automatically enable/disable compression.
void PutRGB_(TType *to, TType *from, unsigned int xsize, unsigned int ysize, unsigned int toskew, unsigned int fromskew)
void SetColorPalette(const PaletteType _arg)
void * ReadRawByteFromTag(unsigned int t, unsigned int &value_count)
bool CanWriteFile(const char *) override
void GetColor(uint64_t index, uint16_t *red, uint16_t *green, uint16_t *blue)
void ReadGenericImage(void *_out, unsigned int width, unsigned int height)
void InternalWrite(const void *buffer)
bool CanReadFile(const char *) override
void ReadCurrentPage(void *buffer, vcl_size_t pixelOffset)
void RGBAImageToBuffer(void *out, const uint32_t *tempImage)
void PrintSelf(std::ostream &os, Indent indent) const override
virtual void ReadVolume(void *buffer)
virtual int GetJPEGQuality() const
void SetCompressionToJPEG()
void ReadImageInformation() override
void Read(void *buffer) override
void SetCompressionToLZW()
void PopulateColorPalette()
void InitializeColors()
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....