Browse Source

TgaImporter: don't install TgaHeader.h publicly.

Nobody needs that.
pull/231/head
Vladimír Vondruš 8 years ago
parent
commit
45fe611b4c
  1. 12
      src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp
  2. 7
      src/MagnumPlugins/TgaImporter/CMakeLists.txt
  3. 35
      src/MagnumPlugins/TgaImporter/TgaHeader.h
  4. 6
      src/MagnumPlugins/TgaImporter/TgaImporter.cpp

12
src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp

@ -74,10 +74,10 @@ Containers::Array<char> TgaImageConverter::doExportToData(const ImageView2D& ima
/* Initialize data buffer */ /* Initialize data buffer */
const auto pixelSize = UnsignedByte(image.pixelSize()); const auto pixelSize = UnsignedByte(image.pixelSize());
Containers::Array<char> data{Containers::ValueInit, sizeof(TgaHeader) + pixelSize*image.size().product()}; Containers::Array<char> data{Containers::ValueInit, sizeof(Implementation::TgaHeader) + pixelSize*image.size().product()};
/* Fill header */ /* Fill header */
auto header = reinterpret_cast<TgaHeader*>(data.begin()); auto header = reinterpret_cast<Implementation::TgaHeader*>(data.begin());
switch(image.format()) { switch(image.format()) {
case PixelFormat::RGB: case PixelFormat::RGB:
case PixelFormat::RGBA: case PixelFormat::RGBA:
@ -105,15 +105,15 @@ Containers::Array<char> TgaImageConverter::doExportToData(const ImageView2D& ima
const std::size_t rowStride = std::get<1>(image.dataProperties()).x(); const std::size_t rowStride = std::get<1>(image.dataProperties()).x();
if(rowStride != rowSize) { if(rowStride != rowSize) {
for(std::int_fast32_t y = 0; y != image.size().y(); ++y) 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); 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(TgaHeader)); } else std::copy_n(imageData, pixelSize*image.size().product(), data.begin() + sizeof(Implementation::TgaHeader));
if(image.format() == PixelFormat::RGB) { if(image.format() == PixelFormat::RGB) {
auto pixels = reinterpret_cast<Math::Vector3<UnsignedByte>*>(data.begin()+sizeof(TgaHeader)); auto pixels = reinterpret_cast<Math::Vector3<UnsignedByte>*>(data.begin()+sizeof(Implementation::TgaHeader));
std::transform(pixels, pixels + image.size().product(), pixels, std::transform(pixels, pixels + image.size().product(), pixels,
[](Math::Vector3<UnsignedByte> pixel) { return Math::swizzle<'b', 'g', 'r'>(pixel); }); [](Math::Vector3<UnsignedByte> pixel) { return Math::swizzle<'b', 'g', 'r'>(pixel); });
} else if(image.format() == PixelFormat::RGBA) { } else if(image.format() == PixelFormat::RGBA) {
auto pixels = reinterpret_cast<Math::Vector4<UnsignedByte>*>(data.begin()+sizeof(TgaHeader)); auto pixels = reinterpret_cast<Math::Vector4<UnsignedByte>*>(data.begin()+sizeof(Implementation::TgaHeader));
std::transform(pixels, pixels + image.size().product(), pixels, std::transform(pixels, pixels + image.size().product(), pixels,
[](Math::Vector4<UnsignedByte> pixel) { return Math::swizzle<'b', 'g', 'r', 'a'>(pixel); }); [](Math::Vector4<UnsignedByte> pixel) { return Math::swizzle<'b', 'g', 'r', 'a'>(pixel); });
} }

7
src/MagnumPlugins/TgaImporter/CMakeLists.txt

@ -34,13 +34,16 @@ set(TgaImporter_SRCS
TgaImporter.cpp) TgaImporter.cpp)
set(TgaImporter_HEADERS set(TgaImporter_HEADERS
TgaHeader.h
TgaImporter.h) TgaImporter.h)
set(TgaImporter_PRIVATE_HEADERS
TgaHeader.h)
# Objects shared between plugin and test library # Objects shared between plugin and test library
add_library(TgaImporterObjects OBJECT add_library(TgaImporterObjects OBJECT
${TgaImporter_SRCS} ${TgaImporter_SRCS}
${TgaImporter_HEADERS}) ${TgaImporter_HEADERS}
${TgaImporter_PRIVATE_HEADERS})
target_include_directories(TgaImporterObjects PUBLIC $<TARGET_PROPERTY:Magnum,INTERFACE_INCLUDE_DIRECTORIES>) target_include_directories(TgaImporterObjects PUBLIC $<TARGET_PROPERTY:Magnum,INTERFACE_INCLUDE_DIRECTORIES>)
if(NOT BUILD_PLUGINS_STATIC) if(NOT BUILD_PLUGINS_STATIC)
target_compile_definitions(TgaImporterObjects PRIVATE "TgaImporterObjects_EXPORTS") target_compile_definitions(TgaImporterObjects PRIVATE "TgaImporterObjects_EXPORTS")

35
src/MagnumPlugins/TgaImporter/TgaHeader.h

@ -25,35 +25,30 @@
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
*/ */
/** @file
* @brief Struct @ref Magnum::Trade::TgaHeader
*/
#include "Magnum/Types.h" #include "Magnum/Types.h"
namespace Magnum { namespace Trade { namespace Magnum { namespace Trade { namespace Implementation {
#pragma pack(1) #pragma pack(1)
/** @brief TGA file header */ /* TGA file header */
/** @todoc Enable @c INLINE_SIMPLE_STRUCTS again when unclosed &lt;component&gt; in tagfile is fixed*/
struct TgaHeader { struct TgaHeader {
UnsignedByte identsize; /**< @brief Size of ID field that follows header (0) */ UnsignedByte identsize; /* Size of ID field that follows header (0) */
UnsignedByte colorMapType; /**< @brief 0 = None, 1 = paletted */ UnsignedByte colorMapType; /* 0 = None, 1 = paletted */
UnsignedByte imageType; /**< @brief 0 = none, 1 = indexed, 2 = rgb, 3 = grey, +8=rle */ UnsignedByte imageType; /* 0 = none, 1 = indexed, 2 = rgb, 3 = grey, +8=rle */
UnsignedShort colorMapStart; /**< @brief First color map entry */ UnsignedShort colorMapStart; /* First color map entry */
UnsignedShort colorMapLength; /**< @brief Number of colors */ UnsignedShort colorMapLength; /* Number of colors */
UnsignedByte colorMapBpp; /**< @brief Bits per palette entry */ UnsignedByte colorMapBpp; /* Bits per palette entry */
UnsignedShort beginX; /**< @brief Image x origin */ UnsignedShort beginX; /* Image x origin */
UnsignedShort beginY; /**< @brief Image y origin */ UnsignedShort beginY; /* Image y origin */
UnsignedShort width; /**< @brief Image width */ UnsignedShort width; /* Image width */
UnsignedShort height; /**< @brief Image height */ UnsignedShort height; /* Image height */
UnsignedByte bpp; /**< @brief Bits per pixel (8, 16, 24, 32) */ UnsignedByte bpp; /* Bits per pixel (8, 16, 24, 32) */
UnsignedByte descriptor; /**< @brief Image descriptor */ UnsignedByte descriptor; /* Image descriptor */
}; };
#pragma pack() #pragma pack()
static_assert(sizeof(TgaHeader) == 18, "TgaHeader size is not 18 bytes"); static_assert(sizeof(TgaHeader) == 18, "TgaHeader size is not 18 bytes");
}} }}}
#endif #endif

6
src/MagnumPlugins/TgaImporter/TgaImporter.cpp

@ -65,12 +65,12 @@ UnsignedInt TgaImporter::doImage2DCount() const { return 1; }
Containers::Optional<ImageData2D> TgaImporter::doImage2D(UnsignedInt) { Containers::Optional<ImageData2D> TgaImporter::doImage2D(UnsignedInt) {
/* Check if the file is long enough */ /* 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"; Error() << "Trade::TgaImporter::image2D(): the file is too short:" << _in.size() << "bytes";
return Containers::NullOpt; return Containers::NullOpt;
} }
const TgaHeader& header = *reinterpret_cast<const TgaHeader*>(_in.data()); const Implementation::TgaHeader& header = *reinterpret_cast<const Implementation::TgaHeader*>(_in.data());
/* Size in machine endian */ /* Size in machine endian */
const Vector2i size{Utility::Endianness::littleEndian(header.width), const Vector2i size{Utility::Endianness::littleEndian(header.width),
@ -119,7 +119,7 @@ Containers::Optional<ImageData2D> TgaImporter::doImage2D(UnsignedInt) {
} }
Containers::Array<char> data{std::size_t(size.product())*header.bpp/8}; Containers::Array<char> 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 */ /* Adjust pixel storage if row size is not four byte aligned */
PixelStorage storage; PixelStorage storage;

Loading…
Cancel
Save