------------------------------------------------------------------------------
| 285 | |
| 286 | //------------------------------------------------------------------------------ |
| 287 | void vtkPNGReader::ExecuteInformation() |
| 288 | { |
| 289 | vtkInternals* impl = this->Internals; |
| 290 | FILE* fp = nullptr; |
| 291 | MemoryBufferStream stream; |
| 292 | |
| 293 | if (this->GetStream()) |
| 294 | { |
| 295 | // Reset stream to the beginning |
| 296 | this->GetStream()->Seek(0, vtkResourceStream::SeekDirection::Begin); |
| 297 | |
| 298 | // Read the header from MemoryBuffer |
| 299 | if (!impl->CheckBufferHeaderStream(this->GetStream())) |
| 300 | { |
| 301 | vtkErrorMacro("Invalid MemoryBuffer header: not a PNG file"); |
| 302 | this->SetErrorCode(vtkErrorCode::UnrecognizedFileTypeError); |
| 303 | return; |
| 304 | } |
| 305 | } |
| 306 | else if (this->GetMemoryBuffer()) |
| 307 | { |
| 308 | // VTK_DEPRECATED_IN_9_6_0 |
| 309 | // Read the header from MemoryBuffer |
| 310 | const unsigned char* memBuffer = static_cast<const unsigned char*>(this->GetMemoryBuffer()); |
| 311 | if (!impl->CheckBufferHeader(memBuffer, this->GetMemoryBufferLength())) |
| 312 | { |
| 313 | vtkErrorMacro("Invalid MemoryBuffer header: not a PNG file"); |
| 314 | this->SetErrorCode(vtkErrorCode::UnrecognizedFileTypeError); |
| 315 | return; |
| 316 | } |
| 317 | } |
| 318 | else |
| 319 | { |
| 320 | // Attempt to open the file and read the header |
| 321 | this->ComputeInternalFileName(this->DataExtent[4]); |
| 322 | if (this->InternalFileName == nullptr) |
| 323 | { |
| 324 | vtkErrorMacro("A filename must be specified"); |
| 325 | this->SetErrorCode(vtkErrorCode::NoFileNameError); |
| 326 | return; |
| 327 | } |
| 328 | fp = vtksys::SystemTools::Fopen(this->InternalFileName, "rb"); |
| 329 | if (!fp) |
| 330 | { |
| 331 | vtkErrorMacro("Unable to open file " << this->InternalFileName); |
| 332 | this->SetErrorCode(vtkErrorCode::CannotOpenFileError); |
| 333 | return; |
| 334 | } |
| 335 | if (!impl->CheckFileHeader(fp)) |
| 336 | { |
| 337 | vtkErrorMacro("Invalid file header: not a PNG file"); |
| 338 | fclose(fp); |
| 339 | this->SetErrorCode(vtkErrorCode::FileFormatError); |
| 340 | return; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | png_structp png_ptr = nullptr; |
nothing calls this directly
no test coverage detected