Skip to content

Commit

Permalink
[WIP] DdsImporter: Refactor to accomodate for more usecases.
Browse files Browse the repository at this point in the history
Primary usecase is load one image from all. I would be a shame to have to
wait for all images being possibly converted from BGRA to RGBA when loading
only one single image.

Also, calling `imageData2D/3D` twice was not possible up to now.

The strategy now is to do everything which has to be done at least once
anyway in `doImageData()` and create the images themselves from stored
offsets lazily in `doImageData*D()`.

Signed-off-by: Squareys <Squareys@googlemail.com>
  • Loading branch information
Squareys committed Aug 14, 2015
1 parent c33664a commit f297226
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/MagnumPlugins/DdsImporter/DdsImporter.h
Expand Up @@ -31,9 +31,17 @@
*/
#include <vector>
#include <Magnum/Trade/AbstractImporter.h>
#include <Magnum/Math/Vector3.h>
#include <Corrade/Containers/Array.h>
#include <Corrade/Containers/ArrayView.h>

namespace Magnum { namespace Trade {

struct ImageDataOffset {
Vector3i _dimensions;
Containers::ArrayView<char> _data;
};

/**
@brief DDS importer plugin
Expand Down Expand Up @@ -61,15 +69,21 @@ class DdsImporter: public AbstractImporter {
std::optional<ImageData3D> doImage3D(UnsignedInt id) override;

private:
void loadUncompressedImageData(ColorFormat format, const Vector3i& dims, UnsignedInt components,
UnsignedByte numDimensions);
void loadCompressedImageData(CompressedColorFormat format, const Vector3i& dims,
UnsignedByte numDimensions);
size_t addImageDataOffset(const Vector3i& dims, size_t offset);

Containers::Array<char> _in;

bool _compressed;
bool _volume;

std::istream* _in;
/* components per pixel */
UnsignedInt _components;
union {
ColorFormat uncompressed;
CompressedColorFormat compressed;
} _colorFormat;

std::vector<ImageData2D> _imageData2D;
std::vector<ImageData3D> _imageData3D;
std::vector<ImageDataOffset> _imageData;
};

}}
Expand Down

0 comments on commit f297226

Please sign in to comment.