Browse Source

Equality comparison operators for PixelStorage.

pull/190/head
Vladimír Vondruš 10 years ago
parent
commit
8679402f24
  1. 21
      src/Magnum/PixelStorage.cpp
  2. 16
      src/Magnum/PixelStorage.h
  3. 57
      src/Magnum/Test/PixelStorageTest.cpp

21
src/Magnum/PixelStorage.cpp

@ -156,6 +156,21 @@ std::size_t PixelStorage::pixelSize(PixelFormat format, PixelType type) {
CORRADE_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */
}
bool PixelStorage::operator==(const PixelStorage& other) const {
return
#if !(defined(MAGNUM_TARGET_GLES2) && defined(MAGNUM_TARGET_WEBGL))
_rowLength == other._rowLength &&
#endif
#ifndef MAGNUM_TARGET_GLES2
_imageHeight == other._imageHeight &&
#endif
_skip == other._skip &&
#ifndef MAGNUM_TARGET_GLES
_swapBytes == other._swapBytes &&
#endif
_alignment == other._alignment;
}
std::tuple<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>, std::size_t> PixelStorage::dataProperties(const PixelFormat format, const PixelType type, const Vector3i& size) const {
const std::size_t pixelSize = PixelStorage::pixelSize(format, type);
const Math::Vector3<std::size_t> dataSize{
@ -269,6 +284,12 @@ void PixelStorage::applyUnpack() {
}
#ifndef MAGNUM_TARGET_GLES
bool CompressedPixelStorage::operator==(const CompressedPixelStorage& other) const {
return PixelStorage::operator==(other) &&
_blockSize == other._blockSize &&
_blockDataSize == other._blockDataSize;
}
void CompressedPixelStorage::applyInternal(const bool isUnpack) {
PixelStorage::applyInternal(isUnpack);

16
src/Magnum/PixelStorage.h

@ -81,6 +81,14 @@ class MAGNUM_EXPORT PixelStorage {
*/
constexpr /*implicit*/ PixelStorage() noexcept;
/** @brief Equality comparison */
bool operator==(const PixelStorage& other) const;
/** @brief Non-equality comparison */
bool operator!=(const PixelStorage& other) const {
return !operator==(other);
}
#ifndef MAGNUM_TARGET_GLES
/**
* @brief Whether to reverse byte order
@ -275,6 +283,14 @@ class MAGNUM_EXPORT CompressedPixelStorage: public PixelStorage {
#endif
/*implicit*/ CompressedPixelStorage() noexcept: _blockSize{0}, _blockDataSize{0} {}
/** @brief Equality comparison */
bool operator==(const CompressedPixelStorage& other) const;
/** @brief Non-equality comparison */
bool operator!=(const CompressedPixelStorage& other) const {
return !operator==(other);
}
/** @brief Compressed block size */
constexpr Vector3i compressedBlockSize() const { return _blockSize; }

57
src/Magnum/Test/PixelStorageTest.cpp

@ -36,6 +36,11 @@ struct PixelStorageTest: TestSuite::Tester {
void pixelSize();
void compare();
#ifndef MAGNUM_TARGET_GLES
void compareCompressed();
#endif
void dataProperties();
void dataPropertiesAlignment();
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
@ -63,6 +68,11 @@ typedef Math::Vector3<std::size_t> Vector3st;
PixelStorageTest::PixelStorageTest() {
addTests({&PixelStorageTest::pixelSize,
&PixelStorageTest::compare,
#ifndef MAGNUM_TARGET_GLES
&PixelStorageTest::compareCompressed,
#endif
&PixelStorageTest::dataProperties,
&PixelStorageTest::dataPropertiesAlignment,
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
@ -95,6 +105,53 @@ void PixelStorageTest::pixelSize() {
CORRADE_COMPARE(PixelStorage::pixelSize(PixelFormat::DepthStencil, PixelType::UnsignedInt248), 4);
}
void PixelStorageTest::compare() {
PixelStorage a;
a
#if !(defined(MAGNUM_TARGET_GLES2) && defined(MAGNUM_TARGET_WEBGL))
.setRowLength(1)
#endif
#ifndef MAGNUM_TARGET_GLES2
.setImageHeight(15)
#endif
.setSkip({1, 3, 4})
#ifndef MAGNUM_TARGET_GLES
.setSwapBytes(true)
#endif
.setAlignment(3);
CORRADE_VERIFY(a == a);
CORRADE_VERIFY(a != PixelStorage{});
CORRADE_VERIFY(PixelStorage{} == PixelStorage{});
#if !(defined(MAGNUM_TARGET_GLES2) && defined(MAGNUM_TARGET_WEBGL))
CORRADE_VERIFY(PixelStorage{}.setRowLength(15) != PixelStorage{}.setRowLength(17));
#endif
#ifndef MAGNUM_TARGET_GLES2
CORRADE_VERIFY(PixelStorage{}.setImageHeight(32) != PixelStorage{}.setImageHeight(31));
#endif
CORRADE_VERIFY(PixelStorage{}.setSkip({1, 5, 7}) != PixelStorage{}.setSkip({7, 1, 5}));
#ifndef MAGNUM_TARGET_GLES
CORRADE_VERIFY(PixelStorage{}.setSwapBytes(false) != PixelStorage{}.setSwapBytes(true));
#endif
CORRADE_VERIFY(PixelStorage{}.setAlignment(3) != PixelStorage{}.setAlignment(5));
}
#ifndef MAGNUM_TARGET_GLES
void PixelStorageTest::compareCompressed() {
CompressedPixelStorage a;
a.setSkip({16, 2, 1})
.setCompressedBlockSize({4, 8, 2})
.setCompressedBlockDataSize(16);
CORRADE_VERIFY(a == a);
CORRADE_VERIFY(a != CompressedPixelStorage{});
CORRADE_VERIFY(CompressedPixelStorage{} == CompressedPixelStorage{});
CORRADE_VERIFY(CompressedPixelStorage{}.setSkip({16, 4, 17}) != CompressedPixelStorage{}.setSkip({4, 35, 12}));
CORRADE_VERIFY(CompressedPixelStorage{}.setCompressedBlockSize({2, 7, 19}) != CompressedPixelStorage{}.setCompressedBlockSize({2, 7, 16}));
CORRADE_VERIFY(CompressedPixelStorage{}.setCompressedBlockDataSize(32) != CompressedPixelStorage{}.setCompressedBlockDataSize(30));
}
#endif
void PixelStorageTest::dataProperties() {
PixelStorage storage;
storage.setAlignment(1);

Loading…
Cancel
Save