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