Browse Source

TgaImporter: adjust pixel storage if row size is not four byte aligned.

I would set the alignment to 1 every time, but 99% of image data has sane
dimensions and this would only bring needless state changes.

Note that this setting is not yet respected when uploading the texture
data, that will be done in later "pixel storage support" commits.
pull/107/head
Vladimír Vondruš 11 years ago
parent
commit
3f34bcf580
  1. 3
      src/MagnumPlugins/TgaImporter/Test/TgaImporterTest.cpp
  2. 7
      src/MagnumPlugins/TgaImporter/TgaImporter.cpp
  3. 10
      src/MagnumPlugins/TgaImporter/TgaImporter.h

3
src/MagnumPlugins/TgaImporter/Test/TgaImporterTest.cpp

@ -146,6 +146,7 @@ void TgaImporterTest::colorBits24() {
std::optional<Trade::ImageData2D> image = importer.image2D(0);
CORRADE_VERIFY(image);
CORRADE_COMPARE(image->storage().alignment(), 1);
CORRADE_COMPARE(image->format(), PixelFormat::RGB);
CORRADE_COMPARE(image->size(), Vector2i(2, 3));
CORRADE_COMPARE(image->type(), PixelType::UnsignedByte);
@ -170,6 +171,7 @@ void TgaImporterTest::colorBits32() {
std::optional<Trade::ImageData2D> image = importer.image2D(0);
CORRADE_VERIFY(image);
CORRADE_COMPARE(image->storage().alignment(), 4);
CORRADE_COMPARE(image->format(), PixelFormat::RGBA);
CORRADE_COMPARE(image->size(), Vector2i(2, 3));
CORRADE_COMPARE(image->type(), PixelType::UnsignedByte);
@ -189,6 +191,7 @@ void TgaImporterTest::grayscaleBits8() {
std::optional<Trade::ImageData2D> image = importer.image2D(0);
CORRADE_VERIFY(image);
CORRADE_COMPARE(image->storage().alignment(), 1);
#ifndef MAGNUM_TARGET_GLES2
CORRADE_COMPARE(image->format(), PixelFormat::Red);
#else

7
src/MagnumPlugins/TgaImporter/TgaImporter.cpp

@ -136,6 +136,11 @@ std::optional<ImageData2D> TgaImporter::doImage2D(UnsignedInt) {
Containers::Array<char> data{dataSize};
in->read(data, dataSize);
/* Adjust pixel storage if row size is not four byte aligned */
PixelStorage storage;
if((header.width*header.bpp/8)%4 != 0)
storage.setAlignment(1);
Vector2i size(header.width, header.height);
if(format == PixelFormat::RGB) {
@ -148,7 +153,7 @@ std::optional<ImageData2D> TgaImporter::doImage2D(UnsignedInt) {
[](Math::Vector4<UnsignedByte> pixel) { return Math::swizzle<'b', 'g', 'r', 'a'>(pixel); });
}
return ImageData2D{format, PixelType::UnsignedByte, size, std::move(data)};
return ImageData2D{storage, format, PixelType::UnsignedByte, size, std::move(data)};
}
}}

10
src/MagnumPlugins/TgaImporter/TgaImporter.h

@ -64,9 +64,13 @@ package in CMake and link to `${MAGNUM_TGAIMPORTER_LIBRARIES}`. See
The images are imported with @ref PixelType::UnsignedByte and @ref PixelFormat::RGB,
@ref PixelFormat::RGBA or @ref PixelFormat::Red, respectively. Grayscale images
require extension @extension{ARB,texture_rg}. In OpenGL ES 2.0, if
@es_extension{EXT,texture_rg} is not supported and in WebGL 1.0, grayscale
images use @ref PixelFormat::Luminance instead of @ref PixelFormat::Red.
require extension @extension{ARB,texture_rg}. Imported images are imported with
default @ref PixelStorage parameters except for alignment, which may be changed
to `1` if the data require it.
In OpenGL ES 2.0, if @es_extension{EXT,texture_rg} is not supported and in
WebGL 1.0, grayscale images use @ref PixelFormat::Luminance instead of
@ref PixelFormat::Red.
*/
class MAGNUM_TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter {
public:

Loading…
Cancel
Save