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
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 {
111 };
112
113 // BTX
114 enum
115 { // Compression types
122 };
123 // ETX
124
129 void
131 {
132 this->UseCompressionOff();
133 this->SetCompressor("NoCompression");
134 }
135 void
137 {
138 this->UseCompressionOn();
139 this->SetCompressor("PackBits");
140 }
141 void
143 {
144 this->UseCompressionOn();
145 this->SetCompressor("JPEG");
146 }
147 void
149 {
150 this->UseCompressionOn();
151 this->SetCompressor("Deflate");
152 }
153 void
155 {
156 this->UseCompressionOn();
157 this->SetCompressor("AdobeDeflate");
158 }
159 void
161 {
162 this->UseCompressionOn();
163 this->SetCompressor("LZW");
164 }
165
166
171 virtual void
172 SetJPEGQuality(int _JPEGQuality)
173 {
174 this->SetCompressionLevel(_JPEGQuality);
175 }
176 virtual int
178 {
179 return this->GetCompressionLevel();
180 }
181
182
187 itkGetConstReferenceMacro(ColorPalette, PaletteType);
188
191 void
193 {
194 if (this->m_ColorPalette != _arg)
195 {
196 this->m_ColorPalette = _arg;
197 this->Modified();
198 }
199 }
200
201protected:
203 ~TIFFImageIO() override;
204 void
205 PrintSelf(std::ostream & os, Indent indent) const override;
206
207 void
208 InternalSetCompressor(const std::string & _compressor) override;
209
210 // This method is protected because it does not keep
211 // ImageIO::m_Compressor and TIFFImageIO::m_Compression in sync.
212 void
213 SetCompression(int compression)
214 {
215 m_Compression = compression;
216 }
217
218 void
219 InternalWrite(const void * buffer);
220
221 void
223
224 void
225 ReadGenericImage(void * out, unsigned int width, unsigned int height);
226
227 // To support Zeiss images
228 void
229 ReadTwoSamplesPerPixelImage(void * out, unsigned int width, unsigned int height);
230
231 unsigned int
233
234 void
235 GetColor(uint64_t index, uint16_t * red, uint16_t * green, uint16_t * blue);
236
237 // Check that tag t can be found
238 bool
239 CanFindTIFFTag(unsigned int t);
240
241 // Read and returns the raw bytes of tag t
242 void *
243 ReadRawByteFromTag(unsigned int t, unsigned int & value_count);
244
245 // Populate m_ColorPalette from the file palette
246 // The palette corresponds to the one of the first page in case of multipage tiff
247 void
249
250 TIFFReaderInternal * m_InternalImage{};
251
252 void
254
256
258
259private:
260 void
261 AllocateTiffPalette(uint16_t bps);
262
263 void
264 ReadCurrentPage(void * buffer, size_t pixelOffset);
265
266 template <typename TComponent>
267 void
268 ReadGenericImage(void * _out, unsigned int width, unsigned int height);
269
270 template <typename TComponent>
271 void
272 RGBAImageToBuffer(void * out, const uint32_t * tempImage);
273
274 template <typename TType>
275 void
276 PutGrayscale(TType * to,
277 TType * from,
278 unsigned int xsize,
279 unsigned int ysize,
280 unsigned int toskew,
281 unsigned int fromskew);
282
283 template <typename TType>
284 void
285 PutRGB_(TType * to, TType * from, unsigned int xsize, unsigned int ysize, unsigned int toskew, unsigned int fromskew);
286
287
288 template <typename TType, typename TFromType>
289 void
291 TFromType * from,
292 unsigned int xsize,
293 unsigned int ysize,
294 unsigned int toskew,
295 unsigned int fromskew);
296
297 template <typename TType, typename TFromType>
298 void
299 PutPaletteRGB(TType * to,
300 TFromType * from,
301 unsigned int xsize,
302 unsigned int ysize,
303 unsigned int toskew,
304 unsigned int fromskew);
305
306 template <typename TType, typename TFromType>
307 void
309 TFromType * from,
310 unsigned int xsize,
311 unsigned int ysize,
312 unsigned int toskew,
313 unsigned int fromskew);
314
315 uint16_t * m_ColorRed{};
316 uint16_t * m_ColorGreen{};
317 uint16_t * m_ColorBlue{};
318 uint64_t m_TotalColors{ 0 };
320};
321} // end namespace itk
322
323#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:50
virtual void Modified() const
Represent Red, Green and Blue components for color images.
Definition itkRGBPixel.h:59
Implements transparent reference counting.
bool CanFindTIFFTag(unsigned int t)
void WriteImageInformation() override
SmartPointer< Self > Pointer
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
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)
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....