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 */
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 */
auto header = reinterpret_cast<TgaHeader*>(data.begin());
auto header = reinterpret_cast<Implementation::TgaHeader*>(data.begin());
switch(image.format()) {
case PixelFormat::RGB:
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();
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<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,
[](Math::Vector3<UnsignedByte> pixel) { return Math::swizzle<'b', 'g', 'r'>(pixel); });
} 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,
[](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)
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 $<TARGET_PROPERTY:Magnum,INTERFACE_INCLUDE_DIRECTORIES>)
if(NOT BUILD_PLUGINS_STATIC)
target_compile_definitions(TgaImporterObjects PRIVATE "TgaImporterObjects_EXPORTS")

35
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 &lt;component&gt; 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

6
src/MagnumPlugins/TgaImporter/TgaImporter.cpp

@ -65,12 +65,12 @@ UnsignedInt TgaImporter::doImage2DCount() const { return 1; }
Containers::Optional<ImageData2D> 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<const TgaHeader*>(_in.data());
const Implementation::TgaHeader& header = *reinterpret_cast<const Implementation::TgaHeader*>(_in.data());
/* Size in machine endian */
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};
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;

Loading…
Cancel
Save