ITK  4.4.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 
21 #include "itkImageIOBase.h"
22 #include <fstream>
23 
24 namespace itk
25 {
26 //BTX
27 class TIFFReaderInternal;
28 //ETX
29 
42 class ITK_EXPORT TIFFImageIO:public ImageIOBase
43 {
44 public:
46  typedef TIFFImageIO Self;
49 
51  itkNewMacro(Self);
52 
54  itkTypeMacro(TIFFImageIO, ImageIOBase);
55 
56  /*-------- This part of the interface deals with reading data. ------ */
57 
60  virtual bool CanReadFile(const char *);
61 
63  virtual void ReadImageInformation();
64 
66  virtual void Read(void *buffer);
67 
69  virtual void ReadVolume(void *buffer);
70 
72  virtual void ReadTiles(void *buffer);
73 
74  /*-------- This part of the interfaces deals with writing data. ----- */
75 
78  virtual bool CanWriteFile(const char *);
79 
82  virtual void WriteImageInformation();
83 
86  virtual void Write(const void *buffer);
87 
88  enum { NOFORMAT, RGB_, GRAYSCALE, PALETTE_RGB, PALETTE_GRAYSCALE, OTHER };
89 
90  //BTX
91  enum { // Compression types
96  LZW
97  };
98  //ETX
99 
100  // Description:
101  // Set compression type. Sinze LZW compression is patented outside US, the
102  // additional work steps have to be taken in order to use that compression.
103  void SetCompressionToNoCompression() { this->SetCompression(NoCompression); }
104  void SetCompressionToPackBits() { this->SetCompression(PackBits); }
105  void SetCompressionToJPEG() { this->SetCompression(JPEG); }
106  void SetCompressionToDeflate() { this->SetCompression(Deflate); }
107  void SetCompressionToLZW() { this->SetCompression(LZW); }
108 
109  void SetCompression(int compression)
110  {
111  m_Compression = compression;
112 
113  // This If block isn't strictly necessary:
114  // SetCompression(true); would be sufficient. However, it reads strangely
115  // for SetCompression(NoCompression) to then set SetCompression(true).
116  // Doing it this way is probably also less likely to break in the future.
117  if ( compression == NoCompression )
118  {
119  this->SetUseCompression(false); // this is for the ImageIOBase class
120  }
121  else
122  {
123  this->SetUseCompression(true); // this is for the ImageIOBase class
124  }
125  }
126 
127 protected:
128  TIFFImageIO();
129  ~TIFFImageIO();
130  void PrintSelf(std::ostream & os, Indent indent) const;
131 
132  void InternalWrite(const void *buffer);
133 
134  void InitializeColors();
135 
136  void ReadGenericImage(void *out,
137  unsigned int itkNotUsed(width),
138  unsigned int height);
139 
140  // To support Zeiss images
141  void ReadTwoSamplesPerPixelImage(void *out,
142  unsigned int itkNotUsed(width),
143  unsigned int height);
144 
145  int EvaluateImageAt(void *out, void *in);
146 
147  unsigned int GetFormat();
148 
149  void GetColor(int index, unsigned short *red,
150  unsigned short *green, unsigned short *blue);
151 
152  // Check that tag t can be found
153  bool CanFindTIFFTag(unsigned int t);
154 
155 // This method, used obtaining the data from custom tags, requires the
156 // "private" libtiff tif_def.h, which is not installed in a system
157 // installation.
158 #ifndef ITK_USE_SYSTEM_TIFF
159  // Read and returns the raw bytes of tag t
160  void * ReadRawByteFromTag(unsigned int t, short & value_count);
161 #endif // ITK_USE_SYSTEM_TIFF
162 
163  TIFFReaderInternal *m_InternalImage;
164 
166 
167 private:
168  TIFFImageIO(const Self &); //purposely not implemented
169  void operator=(const Self &); //purposely not implemented
170 
171  unsigned short *m_ColorRed;
172  unsigned short *m_ColorGreen;
173  unsigned short *m_ColorBlue;
175  unsigned int m_ImageFormat;
176 };
177 } // end namespace itk
178 
179 #endif // __itkTIFFImageIO_h
180