MCPcopy Create free account
hub / github.com/Kitware/VTK / ReadImageInternal

Method ReadImageInternal

IO/Image/vtkTIFFReader.cxx:1237–1300  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1235//------------------------------------------------------------------------------
1236template <typename T>
1237void vtkTIFFReader::ReadImageInternal(T* outPtr)
1238{
1239 int width = this->InternalImage->Width;
1240 int height = this->InternalImage->Height;
1241
1242 if (!this->InternalImage->CanRead())
1243 {
1244 // Why do we read the image for the ! CanRead case?
1245 uint32_t* tempImage = reinterpret_cast<uint32_t*>(outPtr);
1246
1247 if (this->OutputExtent[0] != 0 || this->OutputExtent[1] != width - 1 ||
1248 this->OutputExtent[2] != 0 || this->OutputExtent[3] != height - 1)
1249 {
1250 tempImage = new uint32_t[width * height];
1251 }
1252 // This should really be fixed to read only the rows necessary.
1253 if (!TIFFReadRGBAImage(this->InternalImage->Image, width, height, tempImage, 0))
1254 {
1255 vtkErrorMacro("Problem reading RGB image");
1256 if (tempImage != reinterpret_cast<uint32_t*>(outPtr))
1257 {
1258 delete[] tempImage;
1259 }
1260 return;
1261 }
1262 const bool flip = this->InternalImage->Orientation != ORIENTATION_TOPLEFT;
1263 T* fimage = outPtr;
1264 for (int yy = 0; yy < height; ++yy)
1265 {
1266 uint32_t* ssimage = flip ? (tempImage + yy * width) : (tempImage + (height - yy - 1) * width);
1267 for (int xx = 0; xx < width; ++xx)
1268 {
1269 if (xx >= this->OutputExtent[0] && xx <= this->OutputExtent[1] &&
1270 yy >= this->OutputExtent[2] && yy <= this->OutputExtent[3])
1271 {
1272 *(fimage) = static_cast<T>(TIFFGetR(*ssimage)); // Red
1273 *(fimage + 1) = static_cast<T>(TIFFGetG(*ssimage)); // Green
1274 *(fimage + 2) = static_cast<T>(TIFFGetB(*ssimage)); // Blue
1275 *(fimage + 3) = static_cast<T>(TIFFGetA(*ssimage)); // Alpha
1276 fimage += 4;
1277 }
1278 ++ssimage;
1279 }
1280 }
1281
1282 if (tempImage != reinterpret_cast<uint32_t*>(outPtr))
1283 {
1284 delete[] tempImage;
1285 }
1286 return;
1287 }
1288
1289 switch (this->GetFormat())
1290 {
1291 case vtkTIFFReader::GRAYSCALE:
1292 case vtkTIFFReader::RGB:
1293 case vtkTIFFReader::PALETTE_RGB:
1294 case vtkTIFFReader::PALETTE_GRAYSCALE:

Callers 2

Process2Method · 0.95
ReadVolumeMethod · 0.95

Calls 4

GetFormatMethod · 0.95
ReadGenericImageMethod · 0.95
TIFFReadRGBAImageFunction · 0.85
CanReadMethod · 0.45

Tested by

no test coverage detected