------------------------------------------------------------------------------
| 217 | |
| 218 | //------------------------------------------------------------------------------ |
| 219 | bool vtkTIFFReader::vtkTIFFReaderInternal::Initialize() |
| 220 | { |
| 221 | if (this->Image) |
| 222 | { |
| 223 | if (!TIFFGetField(this->Image, TIFFTAG_IMAGEWIDTH, &this->Width) || |
| 224 | !TIFFGetField(this->Image, TIFFTAG_IMAGELENGTH, &this->Height)) |
| 225 | { |
| 226 | return false; |
| 227 | } |
| 228 | |
| 229 | // Get the resolution in each direction |
| 230 | TIFFGetField(this->Image, TIFFTAG_XRESOLUTION, &this->XResolution); |
| 231 | TIFFGetField(this->Image, TIFFTAG_YRESOLUTION, &this->YResolution); |
| 232 | TIFFGetField(this->Image, TIFFTAG_RESOLUTIONUNIT, &this->ResolutionUnit); |
| 233 | |
| 234 | // Check the number of pages. First by looking at the number of directories. |
| 235 | this->NumberOfPages = TIFFNumberOfDirectories(this->Image); |
| 236 | if (this->NumberOfPages == 0) |
| 237 | { |
| 238 | if (!TIFFGetField(this->Image, TIFFTAG_PAGENUMBER, &this->CurrentPage, &this->NumberOfPages)) |
| 239 | { |
| 240 | // Check the Image Description tag to know the number of images |
| 241 | // This is used by ImageJ |
| 242 | char** description = new char*[255]; |
| 243 | if (TIFFGetField(this->Image, TIFFTAG_IMAGEDESCRIPTION, description)) |
| 244 | { |
| 245 | // look for the number of images |
| 246 | std::string desc = description[0]; |
| 247 | std::string::size_type pos = desc.find("images="); |
| 248 | std::string::size_type pos2 = desc.find('\n'); |
| 249 | if ((pos != std::string::npos) && (pos2 != std::string::npos)) |
| 250 | { |
| 251 | VTK_FROM_CHARS_IF_ERROR_RETURN( |
| 252 | desc.substr(pos + 7, pos2 - pos - 7), this->NumberOfPages, false); |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | // If the number of pages is still zero we look if the image is tiled. |
| 259 | if (this->NumberOfPages <= 1 && TIFFIsTiled(this->Image)) |
| 260 | { |
| 261 | this->NumberOfTiles = TIFFNumberOfTiles(this->Image); |
| 262 | |
| 263 | if (!TIFFGetField(this->Image, TIFFTAG_TILEWIDTH, &this->TileWidth) || |
| 264 | !TIFFGetField(this->Image, TIFFTAG_TILELENGTH, &this->TileHeight)) |
| 265 | { |
| 266 | std::cerr << "Cannot read tile width and height from file" << endl; |
| 267 | } |
| 268 | else |
| 269 | { |
| 270 | TileRows = this->Height / this->TileHeight; |
| 271 | TileColumns = this->Width / this->TileWidth; |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | // Checking if the TIFF contains subfiles |
| 276 | if (this->NumberOfPages > 1) |