From 45fe611b4c5c66752e1b7b395b5834bba1b5ed7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 1 Feb 2018 14:38:36 +0100 Subject: [PATCH] TgaImporter: don't install TgaHeader.h publicly. Nobody needs that. --- .../TgaImageConverter/TgaImageConverter.cpp | 12 +++---- src/MagnumPlugins/TgaImporter/CMakeLists.txt | 7 ++-- src/MagnumPlugins/TgaImporter/TgaHeader.h | 35 ++++++++----------- src/MagnumPlugins/TgaImporter/TgaImporter.cpp | 6 ++-- 4 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp b/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp index 8272ec70b..5caec852c 100644 --- a/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp +++ b/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp @@ -74,10 +74,10 @@ Containers::Array TgaImageConverter::doExportToData(const ImageView2D& ima /* Initialize data buffer */ const auto pixelSize = UnsignedByte(image.pixelSize()); - Containers::Array data{Containers::ValueInit, sizeof(TgaHeader) + pixelSize*image.size().product()}; + Containers::Array data{Containers::ValueInit, sizeof(Implementation::TgaHeader) + pixelSize*image.size().product()}; /* Fill header */ - auto header = reinterpret_cast(data.begin()); + auto header = reinterpret_cast(data.begin()); switch(image.format()) { case PixelFormat::RGB: case PixelFormat::RGBA: @@ -105,15 +105,15 @@ Containers::Array TgaImageConverter::doExportToData(const ImageView2D& ima const std::size_t rowStride = std::get<1>(image.dataProperties()).x(); if(rowStride != rowSize) { for(std::int_fast32_t y = 0; y != image.size().y(); ++y) - std::copy_n(imageData + y*rowStride, rowSize, data.begin() + sizeof(TgaHeader) + y*rowSize); - } else std::copy_n(imageData, pixelSize*image.size().product(), data.begin() + sizeof(TgaHeader)); + std::copy_n(imageData + y*rowStride, rowSize, data.begin() + sizeof(Implementation::TgaHeader) + y*rowSize); + } else std::copy_n(imageData, pixelSize*image.size().product(), data.begin() + sizeof(Implementation::TgaHeader)); if(image.format() == PixelFormat::RGB) { - auto pixels = reinterpret_cast*>(data.begin()+sizeof(TgaHeader)); + auto pixels = reinterpret_cast*>(data.begin()+sizeof(Implementation::TgaHeader)); std::transform(pixels, pixels + image.size().product(), pixels, [](Math::Vector3 pixel) { return Math::swizzle<'b', 'g', 'r'>(pixel); }); } else if(image.format() == PixelFormat::RGBA) { - auto pixels = reinterpret_cast*>(data.begin()+sizeof(TgaHeader)); + auto pixels = reinterpret_cast*>(data.begin()+sizeof(Implementation::TgaHeader)); std::transform(pixels, pixels + image.size().product(), pixels, [](Math::Vector4 pixel) { return Math::swizzle<'b', 'g', 'r', 'a'>(pixel); }); } diff --git a/src/MagnumPlugins/TgaImporter/CMakeLists.txt b/src/MagnumPlugins/TgaImporter/CMakeLists.txt index 8a9dc8cc6..f0cb0df8e 100644 --- a/src/MagnumPlugins/TgaImporter/CMakeLists.txt +++ b/src/MagnumPlugins/TgaImporter/CMakeLists.txt @@ -34,13 +34,16 @@ set(TgaImporter_SRCS TgaImporter.cpp) set(TgaImporter_HEADERS - TgaHeader.h TgaImporter.h) +set(TgaImporter_PRIVATE_HEADERS + TgaHeader.h) + # Objects shared between plugin and test library add_library(TgaImporterObjects OBJECT ${TgaImporter_SRCS} - ${TgaImporter_HEADERS}) + ${TgaImporter_HEADERS} + ${TgaImporter_PRIVATE_HEADERS}) target_include_directories(TgaImporterObjects PUBLIC $) if(NOT BUILD_PLUGINS_STATIC) target_compile_definitions(TgaImporterObjects PRIVATE "TgaImporterObjects_EXPORTS") diff --git a/src/MagnumPlugins/TgaImporter/TgaHeader.h b/src/MagnumPlugins/TgaImporter/TgaHeader.h index fbdcb3b43..ebd1c2593 100644 --- a/src/MagnumPlugins/TgaImporter/TgaHeader.h +++ b/src/MagnumPlugins/TgaImporter/TgaHeader.h @@ -25,35 +25,30 @@ DEALINGS IN THE SOFTWARE. */ -/** @file - * @brief Struct @ref Magnum::Trade::TgaHeader - */ - #include "Magnum/Types.h" -namespace Magnum { namespace Trade { +namespace Magnum { namespace Trade { namespace Implementation { #pragma pack(1) -/** @brief TGA file header */ -/** @todoc Enable @c INLINE_SIMPLE_STRUCTS again when unclosed <component> in tagfile is fixed*/ +/* TGA file header */ struct TgaHeader { - UnsignedByte identsize; /**< @brief Size of ID field that follows header (0) */ - UnsignedByte colorMapType; /**< @brief 0 = None, 1 = paletted */ - UnsignedByte imageType; /**< @brief 0 = none, 1 = indexed, 2 = rgb, 3 = grey, +8=rle */ - UnsignedShort colorMapStart; /**< @brief First color map entry */ - UnsignedShort colorMapLength; /**< @brief Number of colors */ - UnsignedByte colorMapBpp; /**< @brief Bits per palette entry */ - UnsignedShort beginX; /**< @brief Image x origin */ - UnsignedShort beginY; /**< @brief Image y origin */ - UnsignedShort width; /**< @brief Image width */ - UnsignedShort height; /**< @brief Image height */ - UnsignedByte bpp; /**< @brief Bits per pixel (8, 16, 24, 32) */ - UnsignedByte descriptor; /**< @brief Image descriptor */ + UnsignedByte identsize; /* Size of ID field that follows header (0) */ + UnsignedByte colorMapType; /* 0 = None, 1 = paletted */ + UnsignedByte imageType; /* 0 = none, 1 = indexed, 2 = rgb, 3 = grey, +8=rle */ + UnsignedShort colorMapStart; /* First color map entry */ + UnsignedShort colorMapLength; /* Number of colors */ + UnsignedByte colorMapBpp; /* Bits per palette entry */ + UnsignedShort beginX; /* Image x origin */ + UnsignedShort beginY; /* Image y origin */ + UnsignedShort width; /* Image width */ + UnsignedShort height; /* Image height */ + UnsignedByte bpp; /* Bits per pixel (8, 16, 24, 32) */ + UnsignedByte descriptor; /* Image descriptor */ }; #pragma pack() static_assert(sizeof(TgaHeader) == 18, "TgaHeader size is not 18 bytes"); -}} +}}} #endif diff --git a/src/MagnumPlugins/TgaImporter/TgaImporter.cpp b/src/MagnumPlugins/TgaImporter/TgaImporter.cpp index c9ff7ff3d..c143e30fa 100644 --- a/src/MagnumPlugins/TgaImporter/TgaImporter.cpp +++ b/src/MagnumPlugins/TgaImporter/TgaImporter.cpp @@ -65,12 +65,12 @@ UnsignedInt TgaImporter::doImage2DCount() const { return 1; } Containers::Optional TgaImporter::doImage2D(UnsignedInt) { /* Check if the file is long enough */ - if(_in.size() < std::streamoff(sizeof(TgaHeader))) { + if(_in.size() < std::streamoff(sizeof(Implementation::TgaHeader))) { Error() << "Trade::TgaImporter::image2D(): the file is too short:" << _in.size() << "bytes"; return Containers::NullOpt; } - const TgaHeader& header = *reinterpret_cast(_in.data()); + const Implementation::TgaHeader& header = *reinterpret_cast(_in.data()); /* Size in machine endian */ const Vector2i size{Utility::Endianness::littleEndian(header.width), @@ -119,7 +119,7 @@ Containers::Optional TgaImporter::doImage2D(UnsignedInt) { } Containers::Array data{std::size_t(size.product())*header.bpp/8}; - std::copy_n(_in + sizeof(TgaHeader), data.size(), data.begin()); + std::copy_n(_in + sizeof(Implementation::TgaHeader), data.size(), data.begin()); /* Adjust pixel storage if row size is not four byte aligned */ PixelStorage storage;