ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkTIFFImageIO_h 00019 #define __itkTIFFImageIO_h 00020 00021 #include "itkImageIOBase.h" 00022 #include <fstream> 00023 00024 namespace itk 00025 { 00026 //BTX 00027 class TIFFReaderInternal; 00028 //ETX 00029 00042 class ITK_EXPORT TIFFImageIO:public ImageIOBase 00043 { 00044 public: 00046 typedef TIFFImageIO Self; 00047 typedef ImageIOBase Superclass; 00048 typedef SmartPointer< Self > Pointer; 00049 00051 itkNewMacro(Self); 00052 00054 itkTypeMacro(TIFFImageIO, ImageIOBase); 00055 00056 /*-------- This part of the interface deals with reading data. ------ */ 00057 00060 virtual bool CanReadFile(const char *); 00061 00063 virtual void ReadImageInformation(); 00064 00066 virtual void Read(void *buffer); 00067 00069 virtual void ReadVolume(void *buffer); 00070 00072 virtual void ReadTiles(void *buffer); 00073 00074 /*-------- This part of the interfaces deals with writing data. ----- */ 00075 00078 virtual bool CanWriteFile(const char *); 00079 00082 virtual void WriteImageInformation(); 00083 00086 virtual void Write(const void *buffer); 00087 00088 enum { NOFORMAT, RGB_, GRAYSCALE, PALETTE_RGB, PALETTE_GRAYSCALE, OTHER }; 00089 00090 //BTX 00091 enum { // Compression types 00092 NoCompression, 00093 PackBits, 00094 JPEG, 00095 Deflate, 00096 LZW 00097 }; 00098 //ETX 00099 00100 // Description: 00101 // Set compression type. Sinze LZW compression is patented outside US, the 00102 // additional work steps have to be taken in order to use that compression. 00103 void SetCompressionToNoCompression() { this->SetCompression(NoCompression); } 00104 void SetCompressionToPackBits() { this->SetCompression(PackBits); } 00105 void SetCompressionToJPEG() { this->SetCompression(JPEG); } 00106 void SetCompressionToDeflate() { this->SetCompression(Deflate); } 00107 void SetCompressionToLZW() { this->SetCompression(LZW); } 00108 00109 void SetCompression(int compression) 00110 { 00111 m_Compression = compression; 00112 00113 // This If block isn't strictly necessary: 00114 // SetCompression(true); would be sufficient. However, it reads strangely 00115 // for SetCompression(NoCompression) to then set SetCompression(true). 00116 // Doing it this way is probaly also less likely to break in the future. 00117 if ( compression == NoCompression ) 00118 { 00119 this->SetUseCompression(false); // this is for the ImageIOBase class 00120 } 00121 else 00122 { 00123 this->SetUseCompression(true); // this is for the ImageIOBase class 00124 } 00125 } 00126 00127 protected: 00128 TIFFImageIO(); 00129 ~TIFFImageIO(); 00130 void PrintSelf(std::ostream & os, Indent indent) const; 00131 00132 void InternalWrite(const void *buffer); 00133 00134 void InitializeColors(); 00135 00136 void ReadGenericImage(void *out, 00137 unsigned int itkNotUsed(width), 00138 unsigned int height); 00139 00140 // To support Zeiss images 00141 void ReadTwoSamplesPerPixelImage(void *out, 00142 unsigned int itkNotUsed(width), 00143 unsigned int height); 00144 00145 int EvaluateImageAt(void *out, void *in); 00146 00147 unsigned int GetFormat(); 00148 00149 void GetColor(int index, unsigned short *red, 00150 unsigned short *green, unsigned short *blue); 00151 00152 // Check that tag t can be found 00153 bool CanFindTIFFTag(unsigned int t); 00154 00155 // Read and returns the raw bytes of tag t 00156 void * ReadRawByteFromTag(unsigned int t, short & value_count); 00157 00158 TIFFReaderInternal *m_InternalImage; 00159 00160 int m_Compression; 00161 private: 00162 TIFFImageIO(const Self &); //purposely not implemented 00163 void operator=(const Self &); //purposely not implemented 00164 00165 unsigned short *m_ColorRed; 00166 unsigned short *m_ColorGreen; 00167 unsigned short *m_ColorBlue; 00168 int m_TotalColors; 00169 unsigned int m_ImageFormat; 00170 }; 00171 } // end namespace itk 00172 00173 #endif // __itkTIFFImageIO_h 00174