Browse Source

Move CompressedPixelStorage dataProperties() logic to an internal header.

It'll be used directly from images, bypassing the storage block
parameters.
pull/680/head
Vladimír Vondruš 1 year ago
parent
commit
ef4c732751
  1. 15
      src/Magnum/Implementation/ImageProperties.h
  2. 11
      src/Magnum/PixelStorage.cpp

15
src/Magnum/Implementation/ImageProperties.h

@ -72,6 +72,21 @@ template<std::size_t dimensions, class T> std::pair<Math::Vector<dimensions, std
return std::make_pair(Math::Vector<dimensions, std::size_t>::pad(dataProperties.first), Math::Vector<dimensions, std::size_t>::pad(dataProperties.second));
}
/* Used in CompressedPixelStorage::dataProperties(), where it passes the
storage-supplied block size */
inline std::pair<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>> compressedDataProperties(const CompressedPixelStorage& storage, const Vector3i& blockSize, const UnsignedInt blockDataSize, const Vector3i& size) {
const Vector3i blockCount = (size + blockSize - Vector3i{1})/blockSize;
const Math::Vector3<std::size_t> dataSize{
std::size_t(storage.rowLength() ? (storage.rowLength() + blockSize.x() - 1)/blockSize.x() : blockCount.x()),
std::size_t(storage.imageHeight() ? (storage.imageHeight() + blockSize.y() - 1)/blockSize.y() : blockCount.y()),
std::size_t(blockCount.z())};
const Vector3i skipBlockCount = (storage.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;
return std::make_pair(offset, size.product() ? dataSize : Math::Vector3<std::size_t>{});
}
/* Used in Compressed*Image::dataProperties() */
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) {
std::pair<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>> dataProperties = image.storage().dataProperties(Vector3i::pad(image.size(), 1));

11
src/Magnum/PixelStorage.cpp

@ -29,6 +29,7 @@
#include <Corrade/Utility/Assert.h>
#include "Magnum/Math/Vector3.h"
#include "Magnum/Implementation/ImageProperties.h"
namespace Magnum {
@ -54,16 +55,8 @@ std::pair<Math::Vector3<std::size_t>, Math::Vector3<std::size_t>> PixelStorage::
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", {});
const Vector3i blockCount = (size + _blockSize - Vector3i{1})/_blockSize;
const Math::Vector3<std::size_t> dataSize{
std::size_t(_rowLength ? (_rowLength + _blockSize.x() - 1)/_blockSize.x() : blockCount.x()),
std::size_t(_imageHeight ? (_imageHeight + _blockSize.y() - 1)/_blockSize.y() : blockCount.y()),
std::size_t(blockCount.z())};
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;
return Implementation::compressedDataProperties(*this, _blockSize, _blockDataSize, size);
return std::make_pair(offset, size.product() ? dataSize : Math::Vector3<std::size_t>{});
}
bool CompressedPixelStorage::operator==(const CompressedPixelStorage& other) const {

Loading…
Cancel
Save