ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkTIFFImageIO.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  * http://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 
25 namespace itk
26 {
27 //BTX
28 class TIFFReaderInternal;
29 //ETX
30 
43 class ITKIOTIFF_EXPORT TIFFImageIO:public ImageIOBase
44 {
45 public:
47  typedef TIFFImageIO Self;
50 
52  itkNewMacro(Self);
53 
55  itkTypeMacro(TIFFImageIO, ImageIOBase);
56 
57  /*-------- This part of the interface deals with reading data. ------ */
58 
61  virtual bool CanReadFile(const char *) ITK_OVERRIDE;
62 
64  virtual void ReadImageInformation() ITK_OVERRIDE;
65 
67  virtual void Read(void *buffer) ITK_OVERRIDE;
68 
70  virtual void ReadVolume(void *buffer);
71 
72  /*-------- This part of the interfaces deals with writing data. ----- */
73 
76  virtual bool CanWriteFile(const char *) ITK_OVERRIDE;
77 
80  virtual void WriteImageInformation() ITK_OVERRIDE;
81 
84  virtual void Write(const void *buffer) ITK_OVERRIDE;
85 
86  enum { NOFORMAT, RGB_, GRAYSCALE, PALETTE_RGB, PALETTE_GRAYSCALE, OTHER };
87 
88  //BTX
89  enum { // Compression types
94  LZW
95  };
96  //ETX
97 
98  // Description:
99  // Set compression type. Sinze LZW compression is patented outside US, the
100  // additional work steps have to be taken in order to use that compression.
101  void SetCompressionToNoCompression() { this->SetCompression(NoCompression); }
102  void SetCompressionToPackBits() { this->SetCompression(PackBits); }
103  void SetCompressionToJPEG() { this->SetCompression(JPEG); }
104  void SetCompressionToDeflate() { this->SetCompression(Deflate); }
105  void SetCompressionToLZW() { this->SetCompression(LZW); }
106 
107  void SetCompression(int compression)
108  {
109  m_Compression = compression;
110 
111  // This If block isn't strictly necessary:
112  // SetCompression(true); would be sufficient. However, it reads strangely
113  // for SetCompression(NoCompression) to then set SetCompression(true).
114  // Doing it this way is probably also less likely to break in the future.
115  if ( compression == NoCompression )
116  {
117  this->SetUseCompression(false); // this is for the ImageIOBase class
118  }
119  else
120  {
121  this->SetUseCompression(true); // this is for the ImageIOBase class
122  }
123  }
124 
128  itkSetClampMacro(JPEGQuality, int, 1, 100);
129  itkGetConstMacro(JPEGQuality, int);
131 
132 protected:
133  TIFFImageIO();
134  ~TIFFImageIO();
135  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
136 
137  void InternalWrite(const void *buffer);
138 
139  void InitializeColors();
140 
141  void ReadGenericImage(void *out,
142  unsigned int width,
143  unsigned int height);
144 
145  // To support Zeiss images
146  void ReadTwoSamplesPerPixelImage(void *out,
147  unsigned int width,
148  unsigned int height);
149 
150  unsigned int GetFormat();
151 
152  void GetColor(unsigned int index, unsigned short *red,
153  unsigned short *green, unsigned short *blue);
154 
155  // Check that tag t can be found
156  bool CanFindTIFFTag(unsigned int t);
157 
158  // Read and returns the raw bytes of tag t
159  void * ReadRawByteFromTag(unsigned int t, unsigned int & value_count);
160 
161  TIFFReaderInternal *m_InternalImage;
162 
163  void ReadTIFFTags();
164 
167 
168 private:
169  TIFFImageIO(const Self &) ITK_DELETE_FUNCTION;
170  void operator=(const Self &) ITK_DELETE_FUNCTION;
171 
172  void ReadCurrentPage(void *out, size_t pixelOffset);
173 
174  template <typename TComponent>
175  void ReadGenericImage(void *out,
176  unsigned int width,
177  unsigned int height);
178 
179  template <typename TComponent>
180  void RGBAImageToBuffer( void *out, const uint32_t *tempImage );
181 
182  template <typename TType>
183  void PutGrayscale( TType *to, TType * from,
184  unsigned int xsize, unsigned int ysize,
185  unsigned int toskew, unsigned int fromskew );
186 
187  template <typename TType>
188  void PutRGB_( TType *to, TType * from,
189  unsigned int xsize, unsigned int ysize,
190  unsigned int toskew, unsigned int fromskew );
191 
192 
193  template <typename TType, typename TFromType>
194  void PutPaletteGrayscale( TType *to, TFromType * from,
195  unsigned int xsize, unsigned int ysize,
196  unsigned int toskew, unsigned int fromskew );
197 
198  template <typename TType, typename TFromType>
199  void PutPaletteRGB( TType *to, TFromType * from,
200  unsigned int xsize, unsigned int ysize,
201  unsigned int toskew, unsigned int fromskew );
202 
203  unsigned short *m_ColorRed;
204  unsigned short *m_ColorGreen;
205  unsigned short *m_ColorBlue;
206  int m_TotalColors;
207  unsigned int m_ImageFormat;
208 };
209 } // end namespace itk
210 
211 #endif // itkTIFFImageIO_h
ImageIOBase Superclass
Light weight base class for most itk classes.
void SetCompressionToLZW()
Abstract superclass defines image IO interface.
ImageIO object for reading and writing TIFF images.
void SetCompression(int compression)
void SetCompressionToDeflate()
KWIML_INT_uint32_t uint32_t
Definition: itkIntTypes.h:87
void SetCompressionToNoCompression()
TIFFReaderInternal * m_InternalImage
void SetCompressionToJPEG()
TIFFImageIO Self
Control indentation during Print() invocation.
Definition: itkIndent.h:49
SmartPointer< Self > Pointer
void SetCompressionToPackBits()