| 431 | //------------------------------------------------------------------------------ |
| 432 | template <class OT> |
| 433 | void vtkPNGReader::vtkPNGReaderUpdate2(OT* outPtr, int* outExt, vtkIdType* outInc, long pixSize) |
| 434 | { |
| 435 | vtkPNGReader::vtkInternals* impl = this->Internals; |
| 436 | unsigned int ui; |
| 437 | int i; |
| 438 | FILE* fp = nullptr; |
| 439 | MemoryBufferStream stream; |
| 440 | |
| 441 | if (this->GetStream()) |
| 442 | { |
| 443 | // Reset stream to the beginning |
| 444 | this->GetStream()->Seek(0, vtkResourceStream::SeekDirection::Begin); |
| 445 | |
| 446 | // Read the header from MemoryBuffer |
| 447 | if (!impl->CheckBufferHeaderStream(this->GetStream())) |
| 448 | { |
| 449 | vtkErrorMacro("Invalid MemoryBuffer header: not a PNG file"); |
| 450 | this->SetErrorCode(vtkErrorCode::UnrecognizedFileTypeError); |
| 451 | return; |
| 452 | } |
| 453 | } |
| 454 | else if (this->GetMemoryBuffer()) |
| 455 | { |
| 456 | // VTK_DEPRECATED_IN_9_6_0 |
| 457 | // Read the header from MemoryBuffer |
| 458 | const unsigned char* memBuffer = static_cast<const unsigned char*>(this->GetMemoryBuffer()); |
| 459 | if (!impl->CheckBufferHeader(memBuffer, this->GetMemoryBufferLength())) |
| 460 | { |
| 461 | vtkErrorMacro("Invalid MemoryBuffer header: not a PNG file"); |
| 462 | this->SetErrorCode(vtkErrorCode::FileFormatError); |
| 463 | return; |
| 464 | } |
| 465 | } |
| 466 | else |
| 467 | { |
| 468 | // Attempt to open the file and read the header |
| 469 | fp = vtksys::SystemTools::Fopen(this->InternalFileName, "rb"); |
| 470 | if (!fp) |
| 471 | { |
| 472 | vtkErrorMacro("Unable to open file " << this->InternalFileName); |
| 473 | this->SetErrorCode(vtkErrorCode::CannotOpenFileError); |
| 474 | return; |
| 475 | } |
| 476 | if (!impl->CheckFileHeader(fp)) |
| 477 | { |
| 478 | vtkErrorMacro("Invalid file header: not a PNG file"); |
| 479 | fclose(fp); |
| 480 | this->SetErrorCode(vtkErrorCode::FileFormatError); |
| 481 | return; |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | png_structp png_ptr = nullptr; |
| 486 | png_infop info_ptr = nullptr; |
| 487 | png_infop end_info = nullptr; |
| 488 | if (!impl->CreateLibPngStructs(png_ptr, info_ptr, end_info)) |
| 489 | { |
| 490 | if (fp) |
no test coverage detected