#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2021 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_PIXELS_STORAGE_TIFF_LIBTIFFHELPERS_H #define NUCLEX_PIXELS_STORAGE_TIFF_LIBTIFFHELPERS_H #include "Nuclex/Pixels/Config.h" #if defined(NUCLEX_PIXELS_HAVE_LIBTIFF) #include "Nuclex/Pixels/PixelFormat.h" #include "Nuclex/Pixels/Storage/VirtualFile.h" #include // for std::size_t //#include #include namespace Nuclex { namespace Pixels { namespace Storage { namespace Tiff { // ------------------------------------------------------------------------------------------- // /// Size of the smallest valid TIFF file possible /// /// From https://github.com/mathiasbynens/small/blob/master/tiff.tif /// constexpr const std::size_t SmallestPossibleTiffSize = 46; // bytes // ------------------------------------------------------------------------------------------- // /// Helper class for reading TIFF files using libtiff class Helpers { /// /// Checks whether the first 8 bytes in a file are a valid TIFF file header /// /// File header that will be checked /// True if the file header is a valid TIFF file header /// /// The file header must contain at least the first 8 bytes of the file, /// otherwise this will segfault. /// public: static bool IsValidTiffHeader(const std::uint8_t *fileHeader); /// Opens a virtual file for reading as a TIFF file /// File that will be opened for reading as a TIFF file /// Whether only the file header is going to be read /// A TIFF file pointer that can be used in all LibTIFF methods public: static ::TIFF *OpenForReading( const Nuclex::Pixels::Storage::VirtualFile &file, bool headerOnly = false ); /// Opens a virtual file as a TIFF file for writing /// File that will be opened as a TIFF file for writing /// A TIFF file pointer that can be used in all LibTIFF methods public: static ::TIFF *OpenForWriting(Nuclex::Pixels::Storage::VirtualFile &file); /// Closes a TIFF file pointer opened by one of the Open...() methods /// /// TIFF file pointer returned from one of the Open...() methods that will be closed /// public: static void Close(::TIFF *tiffFile); /// Finds the supported pixel format that is closest to the TIFF's /// Opened TIFF file informations filled by LibTIFF /// The pixel format that's most like the one of the TIFF image public: static PixelFormat GetClosestPixelFormat(TIFF *tiffFile); }; // ------------------------------------------------------------------------------------------- // }}}} // namespace Nuclex::Pixels::Storage::Tiff #endif // defined(NUCLEX_PIXELS_HAVE_LIBTIFF) #endif // NUCLEX_PIXELS_STORAGE_TIFF_LIBTIFFHELPERS_H