Browse Source

Don't return redundant info from Image*::dataProperties().

It was returning either pixel size or compressed block size, which is
now available directly via other means.

This is a breaking change, but I don't expect these functions to be
used widely beyond Magnum internals.
pull/233/head
Vladimír Vondruš 8 years ago
parent
commit
7b5ef21bd9
  1. 11
      doc/changelog.dox
  2. 8
      src/Magnum/DebugTools/CompareImage.cpp
  3. 4
      src/Magnum/GL/BufferImage.h
  4. 31
      src/Magnum/GL/Test/BufferImageGLTest.cpp
  5. 4
      src/Magnum/Image.h
  6. 4
      src/Magnum/ImageView.h
  7. 4
      src/Magnum/PixelStorage.cpp
  8. 24
      src/Magnum/PixelStorage.h
  9. 31
      src/Magnum/Test/ImageTest.cpp
  10. 32
      src/Magnum/Test/ImageViewTest.cpp
  11. 6
      src/Magnum/Test/PixelStorageTest.cpp
  12. 2
      src/Magnum/Trade/ImageData.cpp
  13. 2
      src/Magnum/Trade/ImageData.h
  14. 13
      src/Magnum/Trade/Test/ImageDataTest.cpp

11
doc/changelog.dox

@ -213,6 +213,17 @@ See also:
to the complexity of this change, no backwards compatibility is provided. to the complexity of this change, no backwards compatibility is provided.
- The `magnum-info` utility was renamed to @ref magnum-gl-info. No backwards - The `magnum-info` utility was renamed to @ref magnum-gl-info. No backwards
compatibility symlinks or aliases are provided. compatibility symlinks or aliases are provided.
- @ref PixelStorage::dataProperties(), @ref Image::dataProperties(),
@ref ImageView::dataProperties(), @ref Trade::ImageData::dataProperties(), and @ref GL::BufferImage::dataProperties() now return just a pair of two
values, as the third value is now accessible directly through
@ref Image::pixelSize() "*Image::pixelSize()" and no longer calculated
on-demand
- @ref CompressedPixelStorage::dataProperties(),
@ref CompressedImage::dataProperties(),
@ref CompressedImageView::dataProperties() and
@ref GL::CompressedBufferImage::dataProperties() now return just a pair
of two values, as the third value is accessible directly through
@ref CompressedPixelStorage::compressedBlockDataSize()
- @ref ImageView and @ref CompressedImageView methods are no longer - @ref ImageView and @ref CompressedImageView methods are no longer
@cpp constexpr @ce. It might be possible to have them @cpp constexpr @ce in @cpp constexpr @ce. It might be possible to have them @cpp constexpr @ce in
C++14, but the resulting increase in maintenance costs and compile times is C++14, but the resulting increase in maintenance costs and compile times is

8
src/Magnum/DebugTools/CompareImage.cpp

@ -49,11 +49,11 @@ template<std::size_t size, class T> Float calculateImageDelta(const ImageView2D&
/* Precalculate parameters for pixel access */ /* Precalculate parameters for pixel access */
Math::Vector2<std::size_t> dataOffset, dataSize; Math::Vector2<std::size_t> dataOffset, dataSize;
std::tie(dataOffset, dataSize, std::ignore) = actual.dataProperties(); std::tie(dataOffset, dataSize) = actual.dataProperties();
const char* const actualPixels = actual.data() + dataOffset.sum(); const char* const actualPixels = actual.data() + dataOffset.sum();
const std::size_t actualStride = dataSize.x(); const std::size_t actualStride = dataSize.x();
std::tie(dataOffset, dataSize, std::ignore) = expected.dataProperties(); std::tie(dataOffset, dataSize) = expected.dataProperties();
const char* const expectedPixels = expected.data() + dataOffset.sum(); const char* const expectedPixels = expected.data() + dataOffset.sum();
const std::size_t expectedStride = dataSize.x(); const std::size_t expectedStride = dataSize.x();
@ -328,11 +328,11 @@ void printPixelDeltas(Debug& out, const std::vector<Float>& delta, const ImageVi
/* Precalculate parameters for pixel access */ /* Precalculate parameters for pixel access */
Math::Vector2<std::size_t> offset, size; Math::Vector2<std::size_t> offset, size;
std::tie(offset, size, std::ignore) = actual.dataProperties(); std::tie(offset, size) = actual.dataProperties();
const char* const actualPixels = actual.data() + offset.sum(); const char* const actualPixels = actual.data() + offset.sum();
const std::size_t actualStride = size.x(); const std::size_t actualStride = size.x();
std::tie(offset, size, std::ignore) = expected.dataProperties(); std::tie(offset, size) = expected.dataProperties();
const char* const expectedPixels = expected.data() + offset.sum(); const char* const expectedPixels = expected.data() + offset.sum();
const std::size_t expectedStride = size.x(); const std::size_t expectedStride = size.x();

4
src/Magnum/GL/BufferImage.h

@ -334,7 +334,7 @@ template<UnsignedInt dimensions> class BufferImage {
* *
* See @ref PixelStorage::dataProperties() for more information. * See @ref PixelStorage::dataProperties() for more information.
*/ */
std::tuple<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>, std::size_t> dataProperties() const { std::pair<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>> dataProperties() const {
return Magnum::Implementation::imageDataProperties<dimensions>(*this); return Magnum::Implementation::imageDataProperties<dimensions>(*this);
} }
@ -666,7 +666,7 @@ template<UnsignedInt dimensions> class CompressedBufferImage {
* @requires_gl Compressed pixel storage is hardcoded in OpenGL ES and * @requires_gl Compressed pixel storage is hardcoded in OpenGL ES and
* WebGL. * WebGL.
*/ */
std::tuple<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>, std::size_t> dataProperties() const { std::pair<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>> dataProperties() const {
return Magnum::Implementation::compressedImageDataProperties<dimensions>(*this); return Magnum::Implementation::compressedImageDataProperties<dimensions>(*this);
} }

31
src/Magnum/GL/Test/BufferImageGLTest.cpp

@ -53,6 +53,9 @@ struct BufferImageGLTest: OpenGLTester {
void constructMove(); void constructMove();
void constructMoveCompressed(); void constructMoveCompressed();
void dataProperties();
void dataPropertiesCompressed();
void setData(); void setData();
void setDataGeneric(); void setDataGeneric();
void setDataCompressed(); void setDataCompressed();
@ -80,6 +83,9 @@ BufferImageGLTest::BufferImageGLTest() {
&BufferImageGLTest::constructMove, &BufferImageGLTest::constructMove,
&BufferImageGLTest::constructMoveCompressed, &BufferImageGLTest::constructMoveCompressed,
&BufferImageGLTest::dataProperties,
&BufferImageGLTest::dataPropertiesCompressed,
&BufferImageGLTest::setData, &BufferImageGLTest::setData,
&BufferImageGLTest::setDataGeneric, &BufferImageGLTest::setDataGeneric,
&BufferImageGLTest::setDataCompressed, &BufferImageGLTest::setDataCompressed,
@ -444,6 +450,31 @@ void BufferImageGLTest::constructMoveCompressed() {
CORRADE_COMPARE(c.buffer().id(), id); CORRADE_COMPARE(c.buffer().id(), id);
} }
void BufferImageGLTest::dataProperties() {
const char data[224]{};
BufferImage3D image{
PixelStorage{}
.setAlignment(8)
.setSkip({3, 2, 1}),
Magnum::PixelFormat::R8Unorm, {2, 4, 6}, data, BufferUsage::StaticDraw};
CORRADE_COMPARE(image.dataProperties(),
(std::pair<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>>{{3, 16, 32}, {8, 4, 6}}));
}
void BufferImageGLTest::dataPropertiesCompressed() {
/* Yes, I know, this is totally bogus and doesn't match the BC1 format */
const char data[1]{};
CompressedBufferImage3D image{
CompressedPixelStorage{}
.setCompressedBlockSize({3, 4, 5})
.setCompressedBlockDataSize(16)
.setImageHeight(12)
.setSkip({5, 8, 11}),
CompressedPixelFormat::Bc1RGBAUnorm, {2, 8, 11}, data, BufferUsage::StaticDraw};
CORRADE_COMPARE(image.dataProperties(),
(std::pair<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>>{{2*16, 2*16, 9*16}, {1, 3, 3}}));
}
void BufferImageGLTest::setData() { void BufferImageGLTest::setData() {
const char data[4] = { 'a', 'b', 'c', 'd' }; const char data[4] = { 'a', 'b', 'c', 'd' };
BufferImage2D a{PixelStorage{}.setAlignment(1), BufferImage2D a{PixelStorage{}.setAlignment(1),

4
src/Magnum/Image.h

@ -325,7 +325,7 @@ template<UnsignedInt dimensions> class Image {
* *
* See @ref PixelStorage::dataProperties() for more information. * See @ref PixelStorage::dataProperties() for more information.
*/ */
std::tuple<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>, std::size_t> dataProperties() const { std::pair<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>> dataProperties() const {
return Implementation::imageDataProperties<dimensions>(*this); return Implementation::imageDataProperties<dimensions>(*this);
} }
@ -563,7 +563,7 @@ template<UnsignedInt dimensions> class CompressedImage {
* See @ref CompressedPixelStorage::dataProperties() for more * See @ref CompressedPixelStorage::dataProperties() for more
* information. * information.
*/ */
std::tuple<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>, std::size_t> dataProperties() const { std::pair<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>> dataProperties() const {
return Implementation::compressedImageDataProperties<dimensions>(*this); return Implementation::compressedImageDataProperties<dimensions>(*this);
} }

4
src/Magnum/ImageView.h

@ -373,7 +373,7 @@ template<UnsignedInt dimensions> class ImageView {
* *
* See @ref PixelStorage::dataProperties() for more information. * See @ref PixelStorage::dataProperties() for more information.
*/ */
std::tuple<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>, std::size_t> dataProperties() const { std::pair<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>> dataProperties() const {
return Implementation::imageDataProperties<dimensions>(*this); return Implementation::imageDataProperties<dimensions>(*this);
} }
@ -590,7 +590,7 @@ template<UnsignedInt dimensions> class CompressedImageView {
* See @ref CompressedPixelStorage::dataProperties() for more * See @ref CompressedPixelStorage::dataProperties() for more
* information. * information.
*/ */
std::tuple<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>, std::size_t> dataProperties() const { std::pair<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>> dataProperties() const {
return Implementation::compressedImageDataProperties<dimensions>(*this); return Implementation::compressedImageDataProperties<dimensions>(*this);
} }

4
src/Magnum/PixelStorage.cpp

@ -50,7 +50,7 @@ std::pair<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>> PixelStorage::
size.product() ? dataSize : Math::Vector3<std::size_t>{}}; size.product() ? dataSize : Math::Vector3<std::size_t>{}};
} }
std::tuple<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>, std::size_t> CompressedPixelStorage::dataProperties(const Vector3i& size) const { std::pair<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>> CompressedPixelStorage::dataProperties(const Vector3i& size) const {
CORRADE_ASSERT(_blockDataSize && _blockSize.product(), "CompressedPixelStorage::dataProperties(): expected non-zero storage parameters", {}); CORRADE_ASSERT(_blockDataSize && _blockSize.product(), "CompressedPixelStorage::dataProperties(): expected non-zero storage parameters", {});
const Vector3i blockCount = (size + _blockSize - Vector3i{1})/_blockSize; const Vector3i blockCount = (size + _blockSize - Vector3i{1})/_blockSize;
@ -62,7 +62,7 @@ std::tuple<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>, std::size_t>
const Vector3i skipBlockCount = (_skip + _blockSize - Vector3i{1})/_blockSize; const Vector3i skipBlockCount = (_skip + _blockSize - Vector3i{1})/_blockSize;
const Math::Vector3<std::size_t> offset = (Math::Vector3<std::size_t>{1, dataSize.x(), dataSize.xy().product()}*Math::Vector3<std::size_t>{skipBlockCount})*_blockDataSize; const Math::Vector3<std::size_t> offset = (Math::Vector3<std::size_t>{1, dataSize.x(), dataSize.xy().product()}*Math::Vector3<std::size_t>{skipBlockCount})*_blockDataSize;
return std::make_tuple(offset, size.product() ? dataSize : Math::Vector3<std::size_t>{}, _blockDataSize); return std::make_pair(offset, size.product() ? dataSize : Math::Vector3<std::size_t>{});
} }
bool CompressedPixelStorage::operator==(const CompressedPixelStorage& other) const { bool CompressedPixelStorage::operator==(const CompressedPixelStorage& other) const {

24
src/Magnum/PixelStorage.h

@ -30,13 +30,15 @@
*/ */
#include <cstddef> #include <cstddef>
#include <tuple> #include <utility>
#include "Magnum/Magnum.h" #include "Magnum/Magnum.h"
#include "Magnum/Math/Vector3.h" #include "Magnum/Math/Vector3.h"
#if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL) #if defined(MAGNUM_BUILD_DEPRECATED) && defined(MAGNUM_TARGET_GL)
#include "Magnum/GL/PixelFormat.h" #include "Magnum/GL/PixelFormat.h"
#include <tuple>
#endif #endif
namespace Magnum { namespace Magnum {
@ -265,7 +267,7 @@ class MAGNUM_EXPORT CompressedPixelStorage: public PixelStorage {
* Expects @ref compressedBlockSize() and @ref compressedBlockDataSize() * Expects @ref compressedBlockSize() and @ref compressedBlockDataSize()
* to be non-zero. * to be non-zero.
*/ */
std::tuple<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>, std::size_t> dataProperties(const Vector3i& size) const; std::pair<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>> dataProperties(const Vector3i& size) const;
/* Overloads to remove WTF-factor from method chaining order */ /* Overloads to remove WTF-factor from method chaining order */
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
@ -310,18 +312,17 @@ inline std::tuple<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>, std::s
namespace Implementation { namespace Implementation {
/* Used in *Image::dataProperties() */ /* Used in *Image::dataProperties() */
template<std::size_t dimensions, class T> std::tuple<Math::Vector<dimensions, std::size_t>, Math::Vector<dimensions, std::size_t>, std::size_t> imageDataProperties(const T& image) { template<std::size_t dimensions, class T> std::pair<Math::Vector<dimensions, std::size_t>, Math::Vector<dimensions, std::size_t>> imageDataProperties(const T& image) {
Math::Vector3<std::size_t> offset, dataSize; Math::Vector3<std::size_t> offset, dataSize;
std::tie(offset, dataSize) = image.storage().dataProperties(image.pixelSize(), Vector3i::pad(image.size(), 1)); std::tie(offset, dataSize) = image.storage().dataProperties(image.pixelSize(), Vector3i::pad(image.size(), 1));
return std::make_tuple(Math::Vector<dimensions, std::size_t>::pad(offset), Math::Vector<dimensions, std::size_t>::pad(dataSize), image.pixelSize()); return std::make_pair(Math::Vector<dimensions, std::size_t>::pad(offset), Math::Vector<dimensions, std::size_t>::pad(dataSize));
} }
/* Used in Compressed*Image::dataProperties() */ /* Used in Compressed*Image::dataProperties() */
template<std::size_t dimensions, class T> std::tuple<Math::Vector<dimensions, std::size_t>, Math::Vector<dimensions, std::size_t>, std::size_t> compressedImageDataProperties(const T& image) { template<std::size_t dimensions, class T> std::pair<Math::Vector<dimensions, std::size_t>, Math::Vector<dimensions, std::size_t>> compressedImageDataProperties(const T& image) {
Math::Vector3<std::size_t> offset, blockCount; Math::Vector3<std::size_t> offset, blockCount;
std::size_t blockSize; std::tie(offset, blockCount) = image.storage().dataProperties(Vector3i::pad(image.size(), 1));
std::tie(offset, blockCount, blockSize) = image.storage().dataProperties(Vector3i::pad(image.size(), 1)); return std::make_pair(Math::Vector<dimensions, std::size_t>::pad(offset), Math::Vector<dimensions, std::size_t>::pad(blockCount));
return std::make_tuple(Math::Vector<dimensions, std::size_t>::pad(offset), Math::Vector<dimensions, std::size_t>::pad(blockCount), blockSize);
} }
/* Used in image query functions */ /* Used in image query functions */
@ -352,12 +353,11 @@ namespace Implementation {
CORRADE_INTERNAL_ASSERT(image.storage().compressedBlockSize().product() && image.storage().compressedBlockDataSize()); CORRADE_INTERNAL_ASSERT(image.storage().compressedBlockSize().product() && image.storage().compressedBlockDataSize());
Math::Vector3<std::size_t> offset, blockCount; Math::Vector3<std::size_t> offset, blockCount;
std::size_t blockDataSize; std::tie(offset, blockCount) = image.storage().dataProperties(Vector3i::pad(size, 1));
std::tie(offset, blockCount, blockDataSize) = image.storage().dataProperties(Vector3i::pad(size, 1));
const auto realBlockCount = Math::Vector3<std::size_t>{(Vector3i::pad(size, 1) + image.storage().compressedBlockSize() - Vector3i{1})/image.storage().compressedBlockSize()}; const auto realBlockCount = Math::Vector3<std::size_t>{(Vector3i::pad(size, 1) + image.storage().compressedBlockSize() - Vector3i{1})/image.storage().compressedBlockSize()};
return {offset.sum(), (blockCount.product() - (blockCount.x() - realBlockCount.x()) - (blockCount.y() - realBlockCount.y())*blockCount.x())*blockDataSize}; return {offset.sum(), (blockCount.product() - (blockCount.x() - realBlockCount.x()) - (blockCount.y() - realBlockCount.y())*blockCount.x())*image.storage().compressedBlockDataSize()};
} }
/* Used in image query functions */ /* Used in image query functions */
@ -373,7 +373,7 @@ namespace Implementation {
} }
template<std::size_t dimensions, class T> std::ptrdiff_t pixelStorageSkipOffsetFor(const T& image, const Math::Vector<dimensions, Int>& size) { template<std::size_t dimensions, class T> std::ptrdiff_t pixelStorageSkipOffsetFor(const T& image, const Math::Vector<dimensions, Int>& size) {
return std::get<0>(image.storage().dataProperties(image.pixelSize(), Vector3i::pad(size, 1))).sum(); return image.storage().dataProperties(image.pixelSize(), Vector3i::pad(size, 1)).first.sum();
} }
template<class T> std::ptrdiff_t pixelStorageSkipOffset(const T& image) { template<class T> std::ptrdiff_t pixelStorageSkipOffset(const T& image) {
return pixelStorageSkipOffsetFor(image, image.size()); return pixelStorageSkipOffsetFor(image, image.size());

31
src/Magnum/Test/ImageTest.cpp

@ -61,6 +61,9 @@ struct ImageTest: TestSuite::Tester {
void access(); void access();
void accessCompressed(); void accessCompressed();
void dataProperties();
void dataPropertiesCompressed();
void release(); void release();
void releaseCompressed(); void releaseCompressed();
}; };
@ -93,6 +96,9 @@ ImageTest::ImageTest() {
&ImageTest::access, &ImageTest::access,
&ImageTest::accessCompressed, &ImageTest::accessCompressed,
&ImageTest::dataProperties,
&ImageTest::dataPropertiesCompressed,
&ImageTest::release, &ImageTest::release,
&ImageTest::releaseCompressed}); &ImageTest::releaseCompressed});
} }
@ -606,6 +612,31 @@ void ImageTest::accessCompressed() {
CORRADE_COMPARE(ca.data(), data); CORRADE_COMPARE(ca.data(), data);
} }
void ImageTest::dataProperties() {
Image3D image{
PixelStorage{}
.setAlignment(8)
.setSkip({3, 2, 1}),
PixelFormat::R8Unorm, {2, 4, 6},
Containers::Array<char>{224}};
CORRADE_COMPARE(image.dataProperties(),
(std::pair<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>>{{3, 16, 32}, {8, 4, 6}}));
}
void ImageTest::dataPropertiesCompressed() {
/* Yes, I know, this is totally bogus and doesn't match the BC1 format */
CompressedImage3D image{
CompressedPixelStorage{}
.setCompressedBlockSize({3, 4, 5})
.setCompressedBlockDataSize(16)
.setImageHeight(12)
.setSkip({5, 8, 11}),
CompressedPixelFormat::Bc1RGBAUnorm, {2, 8, 11},
Containers::Array<char>{1}};
CORRADE_COMPARE(image.dataProperties(),
(std::pair<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>>{{2*16, 2*16, 9*16}, {1, 3, 3}}));
}
void ImageTest::release() { void ImageTest::release() {
char data[] = {'c', 'a', 'f', 'e'}; char data[] = {'c', 'a', 'f', 'e'};
Image2D a(PixelFormat::RGBA8Unorm, {1, 1}, Containers::Array<char>{data, 4}); Image2D a(PixelFormat::RGBA8Unorm, {1, 1}, Containers::Array<char>{data, 4});

32
src/Magnum/Test/ImageViewTest.cpp

@ -48,6 +48,9 @@ struct ImageViewTest: TestSuite::Tester {
void constructInvalidSize(); void constructInvalidSize();
void constructCompressedInvalidSize(); void constructCompressedInvalidSize();
void dataProperties();
void dataPropertiesCompressed();
void setData(); void setData();
void setDataCompressed(); void setDataCompressed();
@ -70,6 +73,9 @@ ImageViewTest::ImageViewTest() {
&ImageViewTest::constructInvalidSize, &ImageViewTest::constructInvalidSize,
&ImageViewTest::constructCompressedInvalidSize, &ImageViewTest::constructCompressedInvalidSize,
&ImageViewTest::dataProperties,
&ImageViewTest::dataPropertiesCompressed,
&ImageViewTest::setData, &ImageViewTest::setData,
&ImageViewTest::setDataCompressed, &ImageViewTest::setDataCompressed,
@ -486,6 +492,32 @@ void ImageViewTest::constructCompressedInvalidSize() {
} }
} }
void ImageViewTest::dataProperties() {
const char data[224]{};
ImageView3D image{
PixelStorage{}
.setAlignment(8)
.setSkip({3, 2, 1}),
PixelFormat::R8Unorm, {2, 4, 6}, data};
CORRADE_COMPARE(image.dataProperties(),
(std::pair<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>>{{3, 16, 32}, {8, 4, 6}}));
}
void ImageViewTest::dataPropertiesCompressed() {
/* Yes, I know, this is totally bogus and doesn't match the BC1 format */
const char data[1]{};
CompressedImageView3D image{
CompressedPixelStorage{}
.setCompressedBlockSize({3, 4, 5})
.setCompressedBlockDataSize(16)
.setImageHeight(12)
.setSkip({5, 8, 11}),
CompressedPixelFormat::Bc1RGBAUnorm, {2, 8, 11},
data};
CORRADE_COMPARE(image.dataProperties(),
(std::pair<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>>{{2*16, 2*16, 9*16}, {1, 3, 3}}));
}
void ImageViewTest::setData() { void ImageViewTest::setData() {
const char data[3*3]{}; const char data[3*3]{};
ImageView2D a{PixelStorage{}.setAlignment(1), ImageView2D a{PixelStorage{}.setAlignment(1),

6
src/Magnum/Test/PixelStorageTest.cpp

@ -246,7 +246,7 @@ void PixelStorageTest::dataPropertiesCompressed() {
.setCompressedBlockDataSize(16); .setCompressedBlockDataSize(16);
CORRADE_COMPARE(storage.dataProperties({2, 8, 11}), CORRADE_COMPARE(storage.dataProperties({2, 8, 11}),
(std::tuple<Vector3st, Vector3st, std::size_t>{{}, {1, 2, 3}, 16})); (std::pair<Vector3st, Vector3st>{{}, {1, 2, 3}}));
} }
void PixelStorageTest::dataPropertiesCompressedRowLength() { void PixelStorageTest::dataPropertiesCompressedRowLength() {
@ -257,7 +257,7 @@ void PixelStorageTest::dataPropertiesCompressedRowLength() {
.setSkip({5, 8, 0}); .setSkip({5, 8, 0});
CORRADE_COMPARE(storage.dataProperties({2, 8, 11}), CORRADE_COMPARE(storage.dataProperties({2, 8, 11}),
(std::tuple<Vector3st, Vector3st, std::size_t>{{2*9, 8*9, 0}, {4, 2, 3}, 9})); (std::pair<Vector3st, Vector3st>{{2*9, 8*9, 0}, {4, 2, 3}}));
} }
void PixelStorageTest::dataPropertiesCompressedImageHeight() { void PixelStorageTest::dataPropertiesCompressedImageHeight() {
@ -268,7 +268,7 @@ void PixelStorageTest::dataPropertiesCompressedImageHeight() {
.setSkip({5, 8, 11}); .setSkip({5, 8, 11});
CORRADE_COMPARE(storage.dataProperties({2, 8, 11}), CORRADE_COMPARE(storage.dataProperties({2, 8, 11}),
(std::tuple<Vector3st, Vector3st, std::size_t>{{2*16, 2*16, 9*16}, {1, 3, 3}, 16})); (std::pair<Vector3st, Vector3st>{{2*16, 2*16, 9*16}, {1, 3, 3}}));
} }
void PixelStorageTest::dataOffsetSizeCompressed() { void PixelStorageTest::dataOffsetSizeCompressed() {

2
src/Magnum/Trade/ImageData.cpp

@ -71,7 +71,7 @@ template<UnsignedInt dimensions> UnsignedInt ImageData<dimensions>::pixelSize()
return _pixelSize; return _pixelSize;
} }
template<UnsignedInt dimensions> std::tuple<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>, std::size_t> ImageData<dimensions>::dataProperties() const { template<UnsignedInt dimensions> std::pair<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>> ImageData<dimensions>::dataProperties() const {
CORRADE_ASSERT(!_compressed, "Trade::ImageData::dataProperties(): the image is compressed", {}); CORRADE_ASSERT(!_compressed, "Trade::ImageData::dataProperties(): the image is compressed", {});
return Implementation::imageDataProperties<dimensions>(*this); return Implementation::imageDataProperties<dimensions>(*this);
} }

2
src/Magnum/Trade/ImageData.h

@ -335,7 +335,7 @@ template<UnsignedInt dimensions> class ImageData {
* @ref PixelStorage::dataProperties() for more information. * @ref PixelStorage::dataProperties() for more information.
* @see @ref isCompressed() * @see @ref isCompressed()
*/ */
std::tuple<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>, std::size_t> dataProperties() const; std::pair<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>> dataProperties() const;
/* compressed data properties are not available because the importers /* compressed data properties are not available because the importers
are not setting any block size pixel storage properties to avoid are not setting any block size pixel storage properties to avoid

13
src/Magnum/Trade/Test/ImageDataTest.cpp

@ -55,6 +55,7 @@ struct ImageDataTest: TestSuite::Tester {
void toViewCompressedImplementationSpecific(); void toViewCompressedImplementationSpecific();
void access(); void access();
void dataProperties();
void release(); void release();
void releaseCompressed(); void releaseCompressed();
@ -82,6 +83,7 @@ ImageDataTest::ImageDataTest() {
&ImageDataTest::toViewCompressedImplementationSpecific, &ImageDataTest::toViewCompressedImplementationSpecific,
&ImageDataTest::access, &ImageDataTest::access,
&ImageDataTest::dataProperties,
&ImageDataTest::release, &ImageDataTest::release,
&ImageDataTest::releaseCompressed}); &ImageDataTest::releaseCompressed});
@ -496,6 +498,17 @@ void ImageDataTest::access() {
CORRADE_COMPARE(ca.data(), data); CORRADE_COMPARE(ca.data(), data);
} }
void ImageDataTest::dataProperties() {
ImageData3D image{
PixelStorage{}
.setAlignment(8)
.setSkip({3, 2, 1}),
PixelFormat::R8Unorm, {2, 4, 6},
Containers::Array<char>{224}};
CORRADE_COMPARE(image.dataProperties(),
(std::pair<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>>{{3, 16, 32}, {8, 4, 6}}));
}
void ImageDataTest::release() { void ImageDataTest::release() {
char data[] = {'b', 'e', 'e', 'r'}; char data[] = {'b', 'e', 'e', 'r'};
Trade::ImageData2D a{PixelFormat::RGBA8Unorm, {1, 1}, Containers::Array<char>{data, 4}}; Trade::ImageData2D a{PixelFormat::RGBA8Unorm, {1, 1}, Containers::Array<char>{data, 4}};

Loading…
Cancel
Save