ITK  4.6.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 
73  virtual void ReadTiles(void *buffer);
74 
75  /*-------- This part of the interfaces deals with writing data. ----- */
76 
79  virtual bool CanWriteFile(const char *) ITK_OVERRIDE;
80 
83  virtual void WriteImageInformation() ITK_OVERRIDE;
84 
87  virtual void Write(const void *buffer) ITK_OVERRIDE;
88 
89  enum { NOFORMAT, RGB_, GRAYSCALE, PALETTE_RGB, PALETTE_GRAYSCALE, OTHER };
90 
91  //BTX
92  enum { // Compression types
97  LZW
98  };
99  //ETX
100 
101  // Description:
102  // Set compression type. Sinze LZW compression is patented outside US, the
103  // additional work steps have to be taken in order to use that compression.
104  void SetCompressionToNoCompression() { this->SetCompression(NoCompression); }
105  void SetCompressionToPackBits() { this->SetCompression(PackBits); }
106  void SetCompressionToJPEG() { this->SetCompression(JPEG); }
107  void SetCompressionToDeflate() { this->SetCompression(Deflate); }
108  void SetCompressionToLZW() { this->SetCompression(LZW); }
109 
110  void SetCompression(int compression)
111  {
112  m_Compression = compression;
113 
114  // This If block isn't strictly necessary:
115  // SetCompression(true); would be sufficient. However, it reads strangely
116  // for SetCompression(NoCompression) to then set SetCompression(true).
117  // Doing it this way is probably also less likely to break in the future.
118  if ( compression == NoCompression )
119  {
120  this->SetUseCompression(false); // this is for the ImageIOBase class
121  }
122  else
123  {
124  this->SetUseCompression(true); // this is for the ImageIOBase class
125  }
126  }
127 
131  itkSetClampMacro(JPEGQuality, int, 1, 100);
132  itkGetConstMacro(JPEGQuality, int);
134 
135 protected:
136  TIFFImageIO();
137  ~TIFFImageIO();
138  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
139 
140  void InternalWrite(const void *buffer);
141 
142  void InitializeColors();
143 
144  void ReadGenericImage(void *out,
145  unsigned int itkNotUsed(width),
146  unsigned int height);
147 
148  // To support Zeiss images
149  void ReadTwoSamplesPerPixelImage(void *out,
150  unsigned int itkNotUsed(width),
151  unsigned int height);
152 
153  int EvaluateImageAt(void *out, void *in);
154 
155  unsigned int GetFormat();
156 
157  void GetColor(int index, unsigned short *red,
158  unsigned short *green, unsigned short *blue);
159 
160  // Check that tag t can be found
161  bool CanFindTIFFTag(unsigned int t);
162 
163  // Read and returns the raw bytes of tag t
164  void * ReadRawByteFromTag(unsigned int t, unsigned int & value_count);
165 
166  TIFFReaderInternal *m_InternalImage;
167 
170 
171 private:
172  TIFFImageIO(const Self &); //purposely not implemented
173  void operator=(const Self &); //purposely not implemented
174 
175  unsigned short *m_ColorRed;
176  unsigned short *m_ColorGreen;
177  unsigned short *m_ColorBlue;
179  unsigned int m_ImageFormat;
180 };
181 } // end namespace itk
182 
183 #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()
unsigned short * m_ColorGreen
void SetCompressionToNoCompression()
TIFFReaderInternal * m_InternalImage
unsigned short * m_ColorRed
void SetCompressionToJPEG()
TIFFImageIO Self
unsigned short * m_ColorBlue
unsigned int m_ImageFormat
Control indentation during Print() invocation.
Definition: itkIndent.h:49
SmartPointer< Self > Pointer
void SetCompressionToPackBits()