ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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
54class ITKIOTIFF_EXPORT TIFFImageIO : public ImageIOBase
55{
56public:
57 ITK_DISALLOW_COPY_AND_MOVE(TIFFImageIO);
58
63
65 using PaletteType = std::vector<RGBPixelType>;
66
68 itkNewMacro(Self);
69
71 itkOverrideGetNameOfClassMacro(TIFFImageIO);
72
73 /*-------- This part of the interface deals with reading data. ------ */
74
77 bool
78 CanReadFile(const char *) override;
79
81 void
83
85 void
86 Read(void * buffer) override;
87
89 virtual void
90 ReadVolume(void * buffer);
91
92 /*-------- This part of the interfaces deals with writing data. ----- */
93
96 bool
97 CanWriteFile(const char *) override;
98
101 void
103
106 void
107 Write(const void * buffer) override;
108
109 enum
110 {
117 };
118
119 // BTX
120 enum
121 { // Compression types
128 };
129 // ETX
130
135 void
137 {
138 this->UseCompressionOff();
139 this->SetCompressor("NoCompression");
140 }
141 void
143 {
144 this->UseCompressionOn();
145 this->SetCompressor("PackBits");
146 }
147 void
149 {
150 this->UseCompressionOn();
151 this->SetCompressor("JPEG");
152 }
153 void
155 {
156 this->UseCompressionOn();
157 this->SetCompressor("Deflate");
158 }
159 void
161 {
162 this->UseCompressionOn();
163 this->SetCompressor("AdobeDeflate");
164 }
165 void
167 {
168 this->UseCompressionOn();
169 this->SetCompressor("LZW");
170 }
171
172
177 virtual void
178 SetJPEGQuality(int jpegQuality)
179 {
180 this->SetCompressionLevel(jpegQuality);
181 }
182 virtual int
184 {
185 return this->GetCompressionLevel();
186 }
187
188
193 itkGetConstReferenceMacro(ColorPalette, PaletteType);
194
197 void
199 {
200 if (this->m_ColorPalette != _arg)
201 {
202 this->m_ColorPalette = _arg;
203 this->Modified();
204 }
205 }
206
207protected:
209 ~TIFFImageIO() override;
210 void
211 PrintSelf(std::ostream & os, Indent indent) const override;
212
213 void
214 InternalSetCompressor(const std::string & _compressor) override;
215
216 // This method is protected because it does not keep
217 // ImageIO::m_Compressor and TIFFImageIO::m_Compression in sync.
218 void
219 SetCompression(int compression)
220 {
221 m_Compression = compression;
222 }
223
224 void
225 InternalWrite(const void * buffer);
226
227 void
229
230 void
231 ReadGenericImage(void * out, unsigned int width, unsigned int height);
232
233 // To support Zeiss images
234 void
235 ReadTwoSamplesPerPixelImage(void * out, unsigned int width, unsigned int height);
236
237 unsigned int
239
240 void
241 GetColor(uint64_t index, uint16_t * red, uint16_t * green, uint16_t * blue);
242
243 // Check that tag t can be found
244 bool
245 CanFindTIFFTag(unsigned int t);
246
247 // Read and returns the raw bytes of tag t
248 void *
249 ReadRawByteFromTag(unsigned int t, unsigned int & value_count);
250
251 // Populate m_ColorPalette from the file palette
252 // The palette corresponds to the one of the first page in case of multipage tiff
253 void
255
256 TIFFReaderInternal * m_InternalImage{};
257
258 void
260
262
264
265private:
266 void
267 AllocateTiffPalette(uint16_t bps);
268
269 void
270 ReadCurrentPage(void * buffer, size_t pixelOffset);
271
272 template <typename TComponent>
273 void
274 ReadGenericImage(void * _out, unsigned int width, unsigned int height);
275
276 template <typename TComponent>
277 void
278 RGBAImageToBuffer(void * out, const uint32_t * tempImage);
279
280 template <typename TType>
281 void
282 PutRow(TType * to, void * from, unsigned int xsize);
283
284 template <typename TType>
285 void
286 PutGrayscale(TType * to,
287 TType * from,
288 unsigned int xsize,
289 unsigned int ysize,
290 unsigned int toskew,
291 unsigned int fromskew);
292
293 template <typename TType>
294 void
295 PutRGB_(TType * to, TType * from, unsigned int xsize, unsigned int ysize, unsigned int toskew, unsigned int fromskew);
296
297
298 template <typename TType, typename TFromType>
299 void
301 TFromType * from,
302 unsigned int xsize,
303 unsigned int ysize,
304 unsigned int toskew,
305 unsigned int fromskew);
306
307 template <typename TType, typename TFromType>
308 void
309 PutPaletteRGB(TType * to,
310 TFromType * from,
311 unsigned int xsize,
312 unsigned int ysize,
313 unsigned int toskew,
314 unsigned int fromskew);
315
316 template <typename TType, typename TFromType>
317 void
319 TFromType * from,
320 unsigned int xsize,
321 unsigned int ysize,
322 unsigned int toskew,
323 unsigned int fromskew);
324
325 uint16_t * m_ColorRed{};
326 uint16_t * m_ColorGreen{};
327 uint16_t * m_ColorBlue{};
328 uint64_t m_TotalColors{ 0 };
330};
331} // end namespace itk
332
333#endif // itkTIFFImageIO_h
virtual void SetCompressionLevel(int _arg)
Set/Get a compression level hint.
virtual int GetCompressionLevel() const
virtual void UseCompressionOn()
virtual void SetCompressor(std::string _c)
Set/Get the compression algorithm to use.
virtual void UseCompressionOff()
Control indentation during Print() invocation.
Definition itkIndent.h:53
virtual void Modified() const
Represent Red, Green and Blue components for color images.
Definition itkRGBPixel.h:58
Implements transparent reference counting.
bool CanFindTIFFTag(unsigned int t)
void WriteImageInformation() override
SmartPointer< Self > Pointer
void Write(const void *buffer) override
unsigned int GetFormat()
virtual void SetJPEGQuality(int jpegQuality)
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)
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
PaletteType m_ColorPalette
void SetCompressionToPackBits()
void SetCompressionToAdobeDeflate()
void PutPaletteRGB(TType *to, TFromType *from, unsigned int xsize, unsigned int ysize, unsigned int toskew, unsigned int fromskew)
void PutRow(TType *to, void *from, unsigned int xsize)
uint16_t * m_ColorGreen
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)
ImageIOBase Superclass
void ReadGenericImage(void *_out, unsigned int width, unsigned int height)
TIFFReaderInternal * m_InternalImage
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)
RGBPixel< unsigned short > RGBPixelType
uint16_t * m_ColorBlue
virtual int GetJPEGQuality() const
unsigned int m_ImageFormat
uint16_t * m_ColorRed
void ReadImageInformation() override
void Read(void *buffer) override
void PopulateColorPalette()
void InitializeColors()
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....