From 93789721b2bbd40be0c96f4170926580bfb9278f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 19 Jul 2019 17:39:31 +0200 Subject: [PATCH] De-inline Image headers, remove dependency on ImageView. This means users have to add some more #includes on their side. Sorry but it's for your own good :P --- doc/generated/primitives.cpp | 1 + doc/generated/shaders.cpp | 1 + doc/snippets/Magnum.cpp | 1 + doc/snippets/MagnumDebugTools.cpp | 1 + doc/snippets/MagnumGL.cpp | 1 + doc/snippets/MagnumTrade.cpp | 1 + doc/snippets/debugtools-compareimage.cpp | 1 + src/Magnum/CMakeLists.txt | 2 +- src/Magnum/DebugTools/Screenshot.cpp | 1 + .../DebugTools/Test/ForceRendererGLTest.cpp | 1 + .../DebugTools/Test/ObjectRendererGLTest.cpp | 1 + .../DebugTools/Test/TextureImageGLTest.cpp | 1 + src/Magnum/GL/AbstractTexture.cpp | 1 + src/Magnum/GL/BufferImage.cpp | 39 +++++++++++ src/Magnum/GL/BufferImage.h | 38 +---------- src/Magnum/GL/CubeMapTexture.cpp | 1 + .../GL/Test/AbstractShaderProgramGLTest.cpp | 1 + .../GL/Test/CubeMapTextureArrayGLTest.cpp | 1 + src/Magnum/GL/Test/CubeMapTextureGLTest.cpp | 1 + src/Magnum/GL/Test/FramebufferGLTest.cpp | 1 + src/Magnum/GL/Test/PixelStorageGLTest.cpp | 1 + src/Magnum/GL/Test/RectangleTextureGLTest.cpp | 1 + src/Magnum/GL/Test/TextureArrayGLTest.cpp | 1 + src/Magnum/GL/Test/TextureGLTest.cpp | 1 + src/Magnum/Image.cpp | 68 ++++++++++++++++++- src/Magnum/Image.h | 68 ++----------------- src/Magnum/ImageView.cpp | 10 ++- src/Magnum/ImageView.h | 18 +---- .../{ImagePixelView.h => ImageProperties.h} | 16 ++++- src/Magnum/MeshTools/Test/CompileGLTest.cpp | 1 + src/Magnum/PixelStorage.h | 13 ++-- src/Magnum/Test/ImageTest.cpp | 1 + src/Magnum/Text/AbstractGlyphCache.cpp | 1 + .../Text/Test/AbstractGlyphCacheTest.cpp | 1 + .../TextureTools/Test/DistanceFieldGLTest.cpp | 1 + .../TextureTools/distancefieldconverter.cpp | 1 + src/Magnum/Trade/AbstractImageConverter.cpp | 1 + src/Magnum/Trade/ImageData.cpp | 43 +++++++++++- src/Magnum/Trade/ImageData.h | 43 +----------- .../Trade/Test/AbstractImageConverterTest.cpp | 1 + src/Magnum/Trade/Test/ImageDataTest.cpp | 1 + .../Test/AnyImageConverterTest.cpp | 1 + src/MagnumPlugins/MagnumFont/MagnumFont.cpp | 1 + .../MagnumFontConverter.cpp | 1 + .../Test/TgaImageConverterTest.cpp | 2 +- .../TgaImageConverter/TgaImageConverter.cpp | 2 +- 46 files changed, 222 insertions(+), 173 deletions(-) rename src/Magnum/Implementation/{ImagePixelView.h => ImageProperties.h} (72%) diff --git a/doc/generated/primitives.cpp b/doc/generated/primitives.cpp index fde5b2769..0034e926a 100644 --- a/doc/generated/primitives.cpp +++ b/doc/generated/primitives.cpp @@ -40,6 +40,7 @@ #endif #include +#include #include #include #include diff --git a/doc/generated/shaders.cpp b/doc/generated/shaders.cpp index ebd07eff9..d6c0f204c 100644 --- a/doc/generated/shaders.cpp +++ b/doc/generated/shaders.cpp @@ -39,6 +39,7 @@ #endif #include +#include #include #include #include diff --git a/doc/snippets/Magnum.cpp b/doc/snippets/Magnum.cpp index 3a1647f26..6594d4c9c 100644 --- a/doc/snippets/Magnum.cpp +++ b/doc/snippets/Magnum.cpp @@ -27,6 +27,7 @@ #include "Magnum/Math/Color.h" #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/PixelFormat.h" #ifdef MAGNUM_TARGET_GL #include "Magnum/ResourceManager.h" diff --git a/doc/snippets/MagnumDebugTools.cpp b/doc/snippets/MagnumDebugTools.cpp index c33a743b9..7e5c49519 100644 --- a/doc/snippets/MagnumDebugTools.cpp +++ b/doc/snippets/MagnumDebugTools.cpp @@ -27,6 +27,7 @@ #include #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/PixelFormat.h" #include "Magnum/DebugTools/CompareImage.h" #include "Magnum/Math/Color.h" diff --git a/doc/snippets/MagnumGL.cpp b/doc/snippets/MagnumGL.cpp index 618fe2f2e..ca627c802 100644 --- a/doc/snippets/MagnumGL.cpp +++ b/doc/snippets/MagnumGL.cpp @@ -27,6 +27,7 @@ #include #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/PixelFormat.h" #include "Magnum/GL/AbstractShaderProgram.h" #include "Magnum/GL/Buffer.h" diff --git a/doc/snippets/MagnumTrade.cpp b/doc/snippets/MagnumTrade.cpp index 8f3eb69c4..1e2da7125 100644 --- a/doc/snippets/MagnumTrade.cpp +++ b/doc/snippets/MagnumTrade.cpp @@ -28,6 +28,7 @@ #include #include "Magnum/FileCallback.h" +#include "Magnum/ImageView.h" #include "Magnum/PixelFormat.h" #include "Magnum/Animation/Player.h" #include "Magnum/MeshTools/Transform.h" diff --git a/doc/snippets/debugtools-compareimage.cpp b/doc/snippets/debugtools-compareimage.cpp index cc2a6bb7f..3879bf618 100644 --- a/doc/snippets/debugtools-compareimage.cpp +++ b/doc/snippets/debugtools-compareimage.cpp @@ -29,6 +29,7 @@ #include #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/Trade/ImageData.h" #include "Magnum/Trade/AbstractImporter.h" #include "Magnum/DebugTools/CompareImage.h" diff --git a/src/Magnum/CMakeLists.txt b/src/Magnum/CMakeLists.txt index 1c2e2c528..d39b0cf53 100644 --- a/src/Magnum/CMakeLists.txt +++ b/src/Magnum/CMakeLists.txt @@ -64,7 +64,7 @@ set(Magnum_HEADERS visibility.h) set(Magnum_PRIVATE_HEADERS - Implementation/ImagePixelView.h) + Implementation/ImageProperties.h) # Files shared between main library and math unit test library set(MagnumMath_SRCS diff --git a/src/Magnum/DebugTools/Screenshot.cpp b/src/Magnum/DebugTools/Screenshot.cpp index cdee3a270..fb252316a 100644 --- a/src/Magnum/DebugTools/Screenshot.cpp +++ b/src/Magnum/DebugTools/Screenshot.cpp @@ -31,6 +31,7 @@ #include "Magnum/PixelFormat.h" #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/GL/AbstractFramebuffer.h" #include "Magnum/GL/PixelFormat.h" #include "Magnum/Trade/AbstractImageConverter.h" diff --git a/src/Magnum/DebugTools/Test/ForceRendererGLTest.cpp b/src/Magnum/DebugTools/Test/ForceRendererGLTest.cpp index 0b92e34ce..797d13920 100644 --- a/src/Magnum/DebugTools/Test/ForceRendererGLTest.cpp +++ b/src/Magnum/DebugTools/Test/ForceRendererGLTest.cpp @@ -28,6 +28,7 @@ #include #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/PixelFormat.h" #include "Magnum/DebugTools/CompareImage.h" #include "Magnum/DebugTools/ForceRenderer.h" diff --git a/src/Magnum/DebugTools/Test/ObjectRendererGLTest.cpp b/src/Magnum/DebugTools/Test/ObjectRendererGLTest.cpp index 8cc9ac9c9..909f905f1 100644 --- a/src/Magnum/DebugTools/Test/ObjectRendererGLTest.cpp +++ b/src/Magnum/DebugTools/Test/ObjectRendererGLTest.cpp @@ -28,6 +28,7 @@ #include #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/PixelFormat.h" #include "Magnum/DebugTools/CompareImage.h" #include "Magnum/DebugTools/ObjectRenderer.h" diff --git a/src/Magnum/DebugTools/Test/TextureImageGLTest.cpp b/src/Magnum/DebugTools/Test/TextureImageGLTest.cpp index dde52282c..f777daa01 100644 --- a/src/Magnum/DebugTools/Test/TextureImageGLTest.cpp +++ b/src/Magnum/DebugTools/Test/TextureImageGLTest.cpp @@ -26,6 +26,7 @@ #include #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/PixelFormat.h" #include "Magnum/DebugTools/TextureImage.h" #include "Magnum/GL/CubeMapTexture.h" diff --git a/src/Magnum/GL/AbstractTexture.cpp b/src/Magnum/GL/AbstractTexture.cpp index 10e0f9a11..3afe7e4e3 100644 --- a/src/Magnum/GL/AbstractTexture.cpp +++ b/src/Magnum/GL/AbstractTexture.cpp @@ -30,6 +30,7 @@ #include "Magnum/Array.h" #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #ifndef MAGNUM_TARGET_GLES2 #include "Magnum/GL/BufferImage.h" #endif diff --git a/src/Magnum/GL/BufferImage.cpp b/src/Magnum/GL/BufferImage.cpp index 125ab7872..7e5b985e8 100644 --- a/src/Magnum/GL/BufferImage.cpp +++ b/src/Magnum/GL/BufferImage.cpp @@ -26,6 +26,7 @@ #include "BufferImage.h" #include "Magnum/GL/PixelFormat.h" +#include "Magnum/Implementation/ImageProperties.h" namespace Magnum { namespace GL { @@ -48,8 +49,27 @@ template BufferImage::BufferImage(const Pixe template BufferImage::BufferImage(NoCreateT) noexcept: _format{PixelFormat::RGBA}, _type{PixelType::UnsignedByte}, _buffer{NoCreate}, _dataSize{} {} +template BufferImage::BufferImage(BufferImage&& other) noexcept: _storage{std::move(other._storage)}, _format{std::move(other._format)}, _type{std::move(other._type)}, _size{std::move(other._size)}, _buffer{std::move(other._buffer)}, _dataSize{std::move(other._dataSize)} { + other._size = {}; +} + +template BufferImage& BufferImage::operator=(BufferImage&& other) noexcept { + using std::swap; + swap(_storage, other._storage); + swap(_format, other._format); + swap(_type, other._type); + swap(_size, other._size); + swap(_buffer, other._buffer); + swap(_dataSize, other._dataSize); + return *this; +} + template UnsignedInt BufferImage::pixelSize() const { return GL::pixelSize(_format, _type); } +template std::pair, VectorTypeFor> BufferImage::dataProperties() const { + return Magnum::Implementation::imageDataProperties(*this); +} + template void BufferImage::setData(const PixelStorage storage, const PixelFormat format, const PixelType type, const VectorTypeFor& size, Containers::ArrayView const data, const BufferUsage usage) { _storage = storage; _format = format; @@ -84,6 +104,25 @@ template CompressedBufferImage::CompressedBu template CompressedBufferImage::CompressedBufferImage(NoCreateT) noexcept: _format{}, _buffer{NoCreate}, _dataSize{} {} +template CompressedBufferImage::CompressedBufferImage(CompressedBufferImage&& other) noexcept: _storage{std::move(other._storage)}, _format{std::move(other._format)}, _size{std::move(other._size)}, _buffer{std::move(other._buffer)}, _dataSize{std::move(other._dataSize)} { + other._size = {}; + other._dataSize = {}; +} + +template CompressedBufferImage& CompressedBufferImage::operator=(CompressedBufferImage&& other) noexcept { + using std::swap; + swap(_storage, other._storage); + swap(_format, other._format); + swap(_size, other._size); + swap(_buffer, other._buffer); + swap(_dataSize, other._dataSize); + return *this; +} + +template std::pair, VectorTypeFor> CompressedBufferImage::dataProperties() const { + return Magnum::Implementation::compressedImageDataProperties(*this); +} + template void CompressedBufferImage::setData(const CompressedPixelStorage storage, const CompressedPixelFormat format, const VectorTypeFor& size, const Containers::ArrayView data, const BufferUsage usage) { _storage = storage; _format = format; diff --git a/src/Magnum/GL/BufferImage.h b/src/Magnum/GL/BufferImage.h index c507f5864..615ad66ee 100644 --- a/src/Magnum/GL/BufferImage.h +++ b/src/Magnum/GL/BufferImage.h @@ -285,9 +285,7 @@ template class BufferImage { * * See @ref PixelStorage::dataProperties() for more information. */ - std::pair, VectorTypeFor> dataProperties() const { - return Magnum::Implementation::imageDataProperties(*this); - } + std::pair, VectorTypeFor> dataProperties() const; /** @brief Currently allocated data size */ std::size_t dataSize() const { return _dataSize; } @@ -597,9 +595,7 @@ template class CompressedBufferImage { * @requires_gl Compressed pixel storage is hardcoded in OpenGL ES and * WebGL. */ - std::pair, VectorTypeFor> dataProperties() const { - return Magnum::Implementation::compressedImageDataProperties(*this); - } + std::pair, VectorTypeFor> dataProperties() const; /** * @brief Image buffer @@ -695,36 +691,6 @@ typedef CompressedBufferImage<2> CompressedBufferImage2D; /** @brief Three-dimensional compressed buffer image */ typedef CompressedBufferImage<3> CompressedBufferImage3D; -template inline BufferImage::BufferImage(BufferImage&& other) noexcept: _storage{std::move(other._storage)}, _format{std::move(other._format)}, _type{std::move(other._type)}, _size{std::move(other._size)}, _buffer{std::move(other._buffer)}, _dataSize{std::move(other._dataSize)} { - other._size = {}; -} - -template inline CompressedBufferImage::CompressedBufferImage(CompressedBufferImage&& other) noexcept: _storage{std::move(other._storage)}, _format{std::move(other._format)}, _size{std::move(other._size)}, _buffer{std::move(other._buffer)}, _dataSize{std::move(other._dataSize)} { - other._size = {}; - other._dataSize = {}; -} - -template inline BufferImage& BufferImage::operator=(BufferImage&& other) noexcept { - using std::swap; - swap(_storage, other._storage); - swap(_format, other._format); - swap(_type, other._type); - swap(_size, other._size); - swap(_buffer, other._buffer); - swap(_dataSize, other._dataSize); - return *this; -} - -template inline CompressedBufferImage& CompressedBufferImage::operator=(CompressedBufferImage&& other) noexcept { - using std::swap; - swap(_storage, other._storage); - swap(_format, other._format); - swap(_size, other._size); - swap(_buffer, other._buffer); - swap(_dataSize, other._dataSize); - return *this; -} - }} #else #error this header is not available in OpenGL ES 2.0 build diff --git a/src/Magnum/GL/CubeMapTexture.cpp b/src/Magnum/GL/CubeMapTexture.cpp index 2b51e919d..7f7cb670b 100644 --- a/src/Magnum/GL/CubeMapTexture.cpp +++ b/src/Magnum/GL/CubeMapTexture.cpp @@ -26,6 +26,7 @@ #include "CubeMapTexture.h" #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #ifndef MAGNUM_TARGET_GLES2 #include "Magnum/GL/BufferImage.h" #endif diff --git a/src/Magnum/GL/Test/AbstractShaderProgramGLTest.cpp b/src/Magnum/GL/Test/AbstractShaderProgramGLTest.cpp index 617a43791..838145505 100644 --- a/src/Magnum/GL/Test/AbstractShaderProgramGLTest.cpp +++ b/src/Magnum/GL/Test/AbstractShaderProgramGLTest.cpp @@ -30,6 +30,7 @@ #include #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/GL/AbstractShaderProgram.h" #include "Magnum/GL/Context.h" #include "Magnum/GL/Extensions.h" diff --git a/src/Magnum/GL/Test/CubeMapTextureArrayGLTest.cpp b/src/Magnum/GL/Test/CubeMapTextureArrayGLTest.cpp index cc26be1c1..c99c22a66 100644 --- a/src/Magnum/GL/Test/CubeMapTextureArrayGLTest.cpp +++ b/src/Magnum/GL/Test/CubeMapTextureArrayGLTest.cpp @@ -26,6 +26,7 @@ #include #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/GL/BufferImage.h" #include "Magnum/GL/CubeMapTextureArray.h" #include "Magnum/GL/Context.h" diff --git a/src/Magnum/GL/Test/CubeMapTextureGLTest.cpp b/src/Magnum/GL/Test/CubeMapTextureGLTest.cpp index 56ca0e83a..fd126e302 100644 --- a/src/Magnum/GL/Test/CubeMapTextureGLTest.cpp +++ b/src/Magnum/GL/Test/CubeMapTextureGLTest.cpp @@ -26,6 +26,7 @@ #include #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/GL/Context.h" #include "Magnum/GL/Extensions.h" #ifndef MAGNUM_TARGET_GLES2 diff --git a/src/Magnum/GL/Test/FramebufferGLTest.cpp b/src/Magnum/GL/Test/FramebufferGLTest.cpp index a2581b8ae..e60fd6ae8 100644 --- a/src/Magnum/GL/Test/FramebufferGLTest.cpp +++ b/src/Magnum/GL/Test/FramebufferGLTest.cpp @@ -27,6 +27,7 @@ #include #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/GL/Context.h" #include "Magnum/GL/CubeMapTexture.h" #include "Magnum/GL/Extensions.h" diff --git a/src/Magnum/GL/Test/PixelStorageGLTest.cpp b/src/Magnum/GL/Test/PixelStorageGLTest.cpp index c33c931b9..b50c6ce39 100644 --- a/src/Magnum/GL/Test/PixelStorageGLTest.cpp +++ b/src/Magnum/GL/Test/PixelStorageGLTest.cpp @@ -26,6 +26,7 @@ #include #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/GL/Context.h" #include "Magnum/GL/Extensions.h" #include "Magnum/GL/OpenGLTester.h" diff --git a/src/Magnum/GL/Test/RectangleTextureGLTest.cpp b/src/Magnum/GL/Test/RectangleTextureGLTest.cpp index e08868538..29bc9cb38 100644 --- a/src/Magnum/GL/Test/RectangleTextureGLTest.cpp +++ b/src/Magnum/GL/Test/RectangleTextureGLTest.cpp @@ -27,6 +27,7 @@ #include #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/GL/Context.h" #include "Magnum/GL/Extensions.h" #include "Magnum/GL/BufferImage.h" diff --git a/src/Magnum/GL/Test/TextureArrayGLTest.cpp b/src/Magnum/GL/Test/TextureArrayGLTest.cpp index d051a02bf..e9464634d 100644 --- a/src/Magnum/GL/Test/TextureArrayGLTest.cpp +++ b/src/Magnum/GL/Test/TextureArrayGLTest.cpp @@ -26,6 +26,7 @@ #include #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/GL/Context.h" #include "Magnum/GL/Extensions.h" #include "Magnum/GL/BufferImage.h" diff --git a/src/Magnum/GL/Test/TextureGLTest.cpp b/src/Magnum/GL/Test/TextureGLTest.cpp index 61a8601f8..c5668c7a8 100644 --- a/src/Magnum/GL/Test/TextureGLTest.cpp +++ b/src/Magnum/GL/Test/TextureGLTest.cpp @@ -26,6 +26,7 @@ #include #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/GL/Context.h" #include "Magnum/GL/Extensions.h" #ifndef MAGNUM_TARGET_GLES2 diff --git a/src/Magnum/Image.cpp b/src/Magnum/Image.cpp index 0295d9d58..4d2af5fb4 100644 --- a/src/Magnum/Image.cpp +++ b/src/Magnum/Image.cpp @@ -25,8 +25,9 @@ #include "Image.h" +#include "Magnum/ImageView.h" #include "Magnum/PixelFormat.h" -#include "Magnum/Implementation/ImagePixelView.h" +#include "Magnum/Implementation/ImageProperties.h" namespace Magnum { @@ -44,6 +45,33 @@ template Image::Image(const PixelStorage sto template Image::Image(const PixelStorage storage, const PixelFormat format, const UnsignedInt formatExtra, const UnsignedInt pixelSize) noexcept: _storage{storage}, _format{format}, _formatExtra{formatExtra}, _pixelSize{pixelSize}, _data{} {} +template Image::Image(Image&& other) noexcept: _storage{std::move(other._storage)}, _format{std::move(other._format)}, _formatExtra{std::move(other._formatExtra)}, _pixelSize{std::move(other._pixelSize)}, _size{std::move(other._size)}, _data{std::move(other._data)} { + other._size = {}; +} + +template Image& Image::operator=(Image&& other) noexcept { + using std::swap; + swap(_storage, other._storage); + swap(_format, other._format); + swap(_formatExtra, other._formatExtra); + swap(_pixelSize, other._pixelSize); + swap(_size, other._size); + swap(_data, other._data); + return *this; +} + +template Image::operator ImageView() { + return ImageView{_storage, _format, _formatExtra, _pixelSize, _size, _data}; +} + +template Image::operator ImageView() const { + return ImageView{_storage, _format, _formatExtra, _pixelSize, _size, _data}; +} + +template std::pair, VectorTypeFor> Image::dataProperties() const { + return Implementation::imageDataProperties(*this); +} + template Containers::StridedArrayView Image::pixels() { return Implementation::imagePixelView(*this); } @@ -52,12 +80,50 @@ template Containers::StridedArrayView(*this); } +template Containers::Array Image::release() { + Containers::Array data{std::move(_data)}; + _size = {}; + return data; +} + template CompressedImage::CompressedImage(const CompressedPixelStorage storage, const CompressedPixelFormat format, const VectorTypeFor& size, Containers::Array&& data) noexcept: _storage{storage}, _format{format}, _size{size}, _data{std::move(data)} {} template CompressedImage::CompressedImage(const CompressedPixelStorage storage, const UnsignedInt format, const VectorTypeFor& size, Containers::Array&& data) noexcept: CompressedImage{storage, compressedPixelFormatWrap(format), size, std::move(data)} {} template CompressedImage::CompressedImage(const CompressedPixelStorage storage) noexcept: _storage{storage}, _format{} {} +template CompressedImage::CompressedImage(CompressedImage&& other) noexcept: _storage{std::move(other._storage)}, _format{std::move(other._format)}, _size{std::move(other._size)}, _data{std::move(other._data)} +{ + other._size = {}; +} + +template CompressedImage& CompressedImage::operator=(CompressedImage&& other) noexcept { + using std::swap; + swap(_storage, other._storage); + swap(_format, other._format); + swap(_size, other._size); + swap(_data, other._data); + return *this; +} + +template CompressedImage::operator CompressedImageView() { + return CompressedImageView{_storage, _format, _size, _data}; +} + +template CompressedImage::operator CompressedImageView() const { + return CompressedImageView{_storage, _format, _size, _data}; +} + +template std::pair, VectorTypeFor> CompressedImage::dataProperties() const { + return Implementation::compressedImageDataProperties(*this); +} + +template Containers::Array CompressedImage::release() { + Containers::Array data{std::move(_data)}; + _size = {}; + return data; +} + #ifndef DOXYGEN_GENERATING_OUTPUT template class MAGNUM_EXPORT Image<1>; template class MAGNUM_EXPORT Image<2>; diff --git a/src/Magnum/Image.h b/src/Magnum/Image.h index 4b4ebb75a..4073f0262 100644 --- a/src/Magnum/Image.h +++ b/src/Magnum/Image.h @@ -31,7 +31,8 @@ #include -#include "Magnum/ImageView.h" +#include "Magnum/DimensionTraits.h" +#include "Magnum/PixelStorage.h" namespace Magnum { @@ -350,9 +351,7 @@ template class Image { * * See @ref PixelStorage::dataProperties() for more information. */ - std::pair, VectorTypeFor> dataProperties() const { - return Implementation::imageDataProperties(*this); - } + std::pair, VectorTypeFor> dataProperties() const; /** * @brief Raw data @@ -597,9 +596,7 @@ template class CompressedImage { * See @ref CompressedPixelStorage::dataProperties() for more * information. */ - std::pair, VectorTypeFor> dataProperties() const { - return Implementation::compressedImageDataProperties(*this); - } + std::pair, VectorTypeFor> dataProperties() const; /** * @brief Raw data @@ -677,63 +674,6 @@ typedef CompressedImage<2> CompressedImage2D; /** @brief Three-dimensional compressed image */ typedef CompressedImage<3> CompressedImage3D; -template inline Image::Image(Image&& other) noexcept: _storage{std::move(other._storage)}, _format{std::move(other._format)}, _formatExtra{std::move(other._formatExtra)}, _pixelSize{std::move(other._pixelSize)}, _size{std::move(other._size)}, _data{std::move(other._data)} { - other._size = {}; -} - -template inline CompressedImage::CompressedImage(CompressedImage&& other) noexcept: _storage{std::move(other._storage)}, _format{std::move(other._format)}, _size{std::move(other._size)}, _data{std::move(other._data)} -{ - other._size = {}; -} - -template inline Image& Image::operator=(Image&& other) noexcept { - using std::swap; - swap(_storage, other._storage); - swap(_format, other._format); - swap(_formatExtra, other._formatExtra); - swap(_pixelSize, other._pixelSize); - swap(_size, other._size); - swap(_data, other._data); - return *this; -} - -template inline CompressedImage& CompressedImage::operator=(CompressedImage&& other) noexcept { - using std::swap; - swap(_storage, other._storage); - swap(_format, other._format); - swap(_size, other._size); - swap(_data, other._data); - return *this; -} - -template inline Image::operator ImageView() { - return ImageView{_storage, _format, _formatExtra, _pixelSize, _size, _data}; -} - -template inline Image::operator ImageView() const { - return ImageView{_storage, _format, _formatExtra, _pixelSize, _size, _data}; -} - -template inline CompressedImage::operator CompressedImageView() { - return CompressedImageView{_storage, _format, _size, _data}; -} - -template inline CompressedImage::operator CompressedImageView() const { - return CompressedImageView{_storage, _format, _size, _data}; -} - -template inline Containers::Array Image::release() { - Containers::Array data{std::move(_data)}; - _size = {}; - return data; -} - -template inline Containers::Array CompressedImage::release() { - Containers::Array data{std::move(_data)}; - _size = {}; - return data; -} - template template inline Image::Image(const PixelStorage storage, const T format, const U formatExtra, const VectorTypeFor& size, Containers::Array&& data) noexcept: Image{storage, UnsignedInt(format), UnsignedInt(formatExtra), Implementation::pixelSizeAdl(format, formatExtra), size, std::move(data)} { static_assert(sizeof(T) <= 4 && sizeof(U) <= 4, "format types larger than 32bits are not supported"); diff --git a/src/Magnum/ImageView.cpp b/src/Magnum/ImageView.cpp index a1a4c35a7..be6f319a6 100644 --- a/src/Magnum/ImageView.cpp +++ b/src/Magnum/ImageView.cpp @@ -26,7 +26,7 @@ #include "ImageView.h" #include "Magnum/PixelFormat.h" -#include "Magnum/Implementation/ImagePixelView.h" +#include "Magnum/Implementation/ImageProperties.h" namespace Magnum { @@ -44,6 +44,10 @@ template ImageView::ImageView(co template ImageView::ImageView(const PixelStorage storage, const PixelFormat format, const UnsignedInt formatExtra, const UnsignedInt pixelSize, const VectorTypeFor& size) noexcept: _storage{storage}, _format{format}, _formatExtra{formatExtra}, _pixelSize{pixelSize}, _size{size}, _data{nullptr} {} +template std::pair, VectorTypeFor> ImageView::dataProperties() const { + return Implementation::imageDataProperties(*this); +} + template void ImageView::setData(const Containers::ArrayView data) { CORRADE_ASSERT(Implementation::imageDataSize(*this) <= data.size(), "ImageView::setData(): data too small, got" << data.size() << "but expected at least" << Implementation::imageDataSize(*this) << "bytes", ); _data = {reinterpret_cast(data.data()), data.size()}; @@ -61,6 +65,10 @@ template CompressedImageView::Co template CompressedImageView::CompressedImageView(const CompressedPixelStorage storage, const UnsignedInt format, const VectorTypeFor& size) noexcept: CompressedImageView{storage, compressedPixelFormatWrap(format), size} {} +template std::pair, VectorTypeFor> CompressedImageView::dataProperties() const { + return Implementation::compressedImageDataProperties(*this); +} + #ifndef DOXYGEN_GENERATING_OUTPUT template class MAGNUM_EXPORT ImageView<1, const char>; template class MAGNUM_EXPORT ImageView<2, const char>; diff --git a/src/Magnum/ImageView.h b/src/Magnum/ImageView.h index b8ef0d0b8..cc92bfaad 100644 --- a/src/Magnum/ImageView.h +++ b/src/Magnum/ImageView.h @@ -400,9 +400,7 @@ template class ImageView { * * See @ref PixelStorage::dataProperties() for more information. */ - std::pair, VectorTypeFor> dataProperties() const { - return Implementation::imageDataProperties(*this); - } + std::pair, VectorTypeFor> dataProperties() const; /** * @brief Image data @@ -726,9 +724,7 @@ template class CompressedImageView { * See @ref CompressedPixelStorage::dataProperties() for more * information. */ - std::pair, VectorTypeFor> dataProperties() const { - return Implementation::compressedImageDataProperties(*this); - } + std::pair, VectorTypeFor> dataProperties() const; /** @brief Image data */ Containers::ArrayView data() const { return _data; } @@ -812,16 +808,6 @@ typedef CompressedImageView<2, char> MutableCompressedImageView2D; */ typedef CompressedImageView<3, char> MutableCompressedImageView3D; -namespace Implementation { - template inline UnsignedInt pixelSizeAdl(T format) { - return pixelSize(format); - } - - template inline UnsignedInt pixelSizeAdl(T format, U formatExtra) { - return pixelSize(format, formatExtra); - } -} - template template inline ImageView::ImageView(const PixelStorage storage, const U format, const V formatExtra, const VectorTypeFor& size, const Containers::ArrayView data) noexcept: ImageView{storage, UnsignedInt(format), UnsignedInt(formatExtra), Implementation::pixelSizeAdl(format, formatExtra), size, data} { static_assert(sizeof(T) <= 4 && sizeof(U) <= 4, "format types larger than 32bits are not supported"); diff --git a/src/Magnum/Implementation/ImagePixelView.h b/src/Magnum/Implementation/ImageProperties.h similarity index 72% rename from src/Magnum/Implementation/ImagePixelView.h rename to src/Magnum/Implementation/ImageProperties.h index 31d8c9951..0786d6f85 100644 --- a/src/Magnum/Implementation/ImagePixelView.h +++ b/src/Magnum/Implementation/ImageProperties.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Implementation_ImagePixelView_h -#define Magnum_Implementation_ImagePixelView_h +#ifndef Magnum_Implementation_ImageProperties_h +#define Magnum_Implementation_ImageProperties_h /* This file is part of Magnum. @@ -33,6 +33,18 @@ namespace Magnum { namespace Implementation { +/* Used in *Image::dataProperties() */ +template std::pair, Math::Vector> imageDataProperties(const T& image) { + std::pair, Math::Vector3> dataProperties = image.storage().dataProperties(image.pixelSize(), Vector3i::pad(image.size(), 1)); + return std::make_pair(Math::Vector::pad(dataProperties.first), Math::Vector::pad(dataProperties.second)); +} + +/* Used in Compressed*Image::dataProperties() */ +template std::pair, Math::Vector> compressedImageDataProperties(const T& image) { + std::pair, Math::Vector3> dataProperties = image.storage().dataProperties(Vector3i::pad(image.size(), 1)); + return std::make_pair(Math::Vector::pad(dataProperties.first), Math::Vector::pad(dataProperties.second)); +} + template Containers::StridedArrayView imagePixelView(Image& image) { const std::pair, VectorTypeFor> properties = image.dataProperties(); diff --git a/src/Magnum/MeshTools/Test/CompileGLTest.cpp b/src/Magnum/MeshTools/Test/CompileGLTest.cpp index 171ae4728..c6554e252 100644 --- a/src/Magnum/MeshTools/Test/CompileGLTest.cpp +++ b/src/Magnum/MeshTools/Test/CompileGLTest.cpp @@ -28,6 +28,7 @@ #include #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/Mesh.h" #include "Magnum/PixelFormat.h" #include "Magnum/DebugTools/CompareImage.h" diff --git a/src/Magnum/PixelStorage.h b/src/Magnum/PixelStorage.h index e3ee92482..f0be0d821 100644 --- a/src/Magnum/PixelStorage.h +++ b/src/Magnum/PixelStorage.h @@ -246,16 +246,13 @@ class MAGNUM_EXPORT CompressedPixelStorage: public PixelStorage { constexpr PixelStorage::PixelStorage() noexcept: _rowLength{0}, _imageHeight{0}, _skip{0}, _alignment{4} {} namespace Implementation { - /* Used in *Image::dataProperties() */ - template std::pair, Math::Vector> imageDataProperties(const T& image) { - std::pair, Math::Vector3> dataProperties = image.storage().dataProperties(image.pixelSize(), Vector3i::pad(image.size(), 1)); - return std::make_pair(Math::Vector::pad(dataProperties.first), Math::Vector::pad(dataProperties.second)); + /* Used in templated image[view] constructors */ + template inline UnsignedInt pixelSizeAdl(T format) { + return pixelSize(format); } - /* Used in Compressed*Image::dataProperties() */ - template std::pair, Math::Vector> compressedImageDataProperties(const T& image) { - std::pair, Math::Vector3> dataProperties = image.storage().dataProperties(Vector3i::pad(image.size(), 1)); - return std::make_pair(Math::Vector::pad(dataProperties.first), Math::Vector::pad(dataProperties.second)); + template inline UnsignedInt pixelSizeAdl(T format, U formatExtra) { + return pixelSize(format, formatExtra); } /* Used in image query functions */ diff --git a/src/Magnum/Test/ImageTest.cpp b/src/Magnum/Test/ImageTest.cpp index 52b4dd0d6..8bbc4543a 100644 --- a/src/Magnum/Test/ImageTest.cpp +++ b/src/Magnum/Test/ImageTest.cpp @@ -29,6 +29,7 @@ #include #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/Math/Color.h" #include "Magnum/PixelFormat.h" diff --git a/src/Magnum/Text/AbstractGlyphCache.cpp b/src/Magnum/Text/AbstractGlyphCache.cpp index 36e919b01..d05eea40e 100644 --- a/src/Magnum/Text/AbstractGlyphCache.cpp +++ b/src/Magnum/Text/AbstractGlyphCache.cpp @@ -26,6 +26,7 @@ #include "AbstractGlyphCache.h" #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/TextureTools/Atlas.h" namespace Magnum { namespace Text { diff --git a/src/Magnum/Text/Test/AbstractGlyphCacheTest.cpp b/src/Magnum/Text/Test/AbstractGlyphCacheTest.cpp index 8b6630228..5ad13d1d2 100644 --- a/src/Magnum/Text/Test/AbstractGlyphCacheTest.cpp +++ b/src/Magnum/Text/Test/AbstractGlyphCacheTest.cpp @@ -29,6 +29,7 @@ #include #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/PixelFormat.h" #include "Magnum/Text/AbstractGlyphCache.h" diff --git a/src/Magnum/TextureTools/Test/DistanceFieldGLTest.cpp b/src/Magnum/TextureTools/Test/DistanceFieldGLTest.cpp index 23e7708e7..18b53d3b9 100644 --- a/src/Magnum/TextureTools/Test/DistanceFieldGLTest.cpp +++ b/src/Magnum/TextureTools/Test/DistanceFieldGLTest.cpp @@ -27,6 +27,7 @@ #include #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/PixelFormat.h" #include "Magnum/Math/Color.h" #include "Magnum/Math/Range.h" diff --git a/src/Magnum/TextureTools/distancefieldconverter.cpp b/src/Magnum/TextureTools/distancefieldconverter.cpp index 4bc369410..4e1e327e7 100644 --- a/src/Magnum/TextureTools/distancefieldconverter.cpp +++ b/src/Magnum/TextureTools/distancefieldconverter.cpp @@ -30,6 +30,7 @@ #include #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/PixelFormat.h" #include "Magnum/Math/ConfigurationValue.h" #include "Magnum/Math/Range.h" diff --git a/src/Magnum/Trade/AbstractImageConverter.cpp b/src/Magnum/Trade/AbstractImageConverter.cpp index 53853d955..819eaaad8 100644 --- a/src/Magnum/Trade/AbstractImageConverter.cpp +++ b/src/Magnum/Trade/AbstractImageConverter.cpp @@ -33,6 +33,7 @@ #include #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/Trade/ImageData.h" #ifndef CORRADE_PLUGINMANAGER_NO_DYNAMIC_PLUGIN_SUPPORT diff --git a/src/Magnum/Trade/ImageData.cpp b/src/Magnum/Trade/ImageData.cpp index 55d8162cf..fdaf4c652 100644 --- a/src/Magnum/Trade/ImageData.cpp +++ b/src/Magnum/Trade/ImageData.cpp @@ -27,8 +27,9 @@ #include +#include "Magnum/ImageView.h" #include "Magnum/PixelFormat.h" -#include "Magnum/Implementation/ImagePixelView.h" +#include "Magnum/Implementation/ImageProperties.h" namespace Magnum { namespace Trade { @@ -44,10 +45,44 @@ template ImageData::ImageData(const Compress template ImageData::ImageData(const CompressedPixelStorage storage, const UnsignedInt format, const VectorTypeFor& size, Containers::Array&& data, const void* const importerState) noexcept: ImageData{storage, compressedPixelFormatWrap(format), size, std::move(data), importerState} {} +template ImageData::ImageData(ImageData&& other) noexcept: _compressed{std::move(other._compressed)}, _size{std::move(other._size)}, _data{std::move(other._data)}, _importerState{std::move(other._importerState)} { + if(_compressed) { + new(&_compressedStorage) CompressedPixelStorage{std::move(other._compressedStorage)}; + _compressedFormat = std::move(other._compressedFormat); + } + else { + new(&_storage) PixelStorage{std::move(other._storage)}; + _format = std::move(other._format); + _formatExtra = std::move(other._formatExtra); + _pixelSize = std::move(other._pixelSize); + } + + other._size = {}; +} + template ImageData::ImageData(ImageData&& other, const void* const importerState) noexcept: ImageData{std::move(other)} { _importerState = importerState; } +template ImageData& ImageData::operator=(ImageData&& other) noexcept { + using std::swap; + swap(_compressed, other._compressed); + if(_compressed) { + swap(_compressedStorage, other._compressedStorage); + swap(_compressedFormat, other._compressedFormat); + } + else { + swap(_storage, other._storage); + swap(_format, other._format); + } + swap(_formatExtra, other._formatExtra); + swap(_pixelSize, other._pixelSize); + swap(_size, other._size); + swap(_data, other._data); + swap(_importerState, other._importerState); + return *this; +} + template PixelStorage ImageData::storage() const { CORRADE_ASSERT(!_compressed, "Trade::ImageData::storage(): the image is compressed", {}); return _storage; @@ -117,6 +152,12 @@ template ImageData::operator CompressedImage _compressedFormat, _size, _data}; } +template Containers::Array ImageData::release() { + Containers::Array data{std::move(_data)}; + _size = {}; + return data; +} + #ifndef DOXYGEN_GENERATING_OUTPUT template class MAGNUM_TRADE_EXPORT ImageData<1>; template class MAGNUM_TRADE_EXPORT ImageData<2>; diff --git a/src/Magnum/Trade/ImageData.h b/src/Magnum/Trade/ImageData.h index ba9de921f..f70e623cf 100644 --- a/src/Magnum/Trade/ImageData.h +++ b/src/Magnum/Trade/ImageData.h @@ -31,7 +31,8 @@ #include -#include "Magnum/ImageView.h" +#include "Magnum/DimensionTraits.h" +#include "Magnum/PixelStorage.h" #include "Magnum/Trade/visibility.h" namespace Magnum { namespace Trade { @@ -468,46 +469,6 @@ template template ImageData::ImageD "format types larger than 32bits are not supported"); } -template inline ImageData::ImageData(ImageData&& other) noexcept: _compressed{std::move(other._compressed)}, _size{std::move(other._size)}, _data{std::move(other._data)}, _importerState{std::move(other._importerState)} { - if(_compressed) { - new(&_compressedStorage) CompressedPixelStorage{std::move(other._compressedStorage)}; - _compressedFormat = std::move(other._compressedFormat); - } - else { - new(&_storage) PixelStorage{std::move(other._storage)}; - _format = std::move(other._format); - _formatExtra = std::move(other._formatExtra); - _pixelSize = std::move(other._pixelSize); - } - - other._size = {}; -} - -template inline ImageData& ImageData::operator=(ImageData&& other) noexcept { - using std::swap; - swap(_compressed, other._compressed); - if(_compressed) { - swap(_compressedStorage, other._compressedStorage); - swap(_compressedFormat, other._compressedFormat); - } - else { - swap(_storage, other._storage); - swap(_format, other._format); - } - swap(_formatExtra, other._formatExtra); - swap(_pixelSize, other._pixelSize); - swap(_size, other._size); - swap(_data, other._data); - swap(_importerState, other._importerState); - return *this; -} - -template inline Containers::Array ImageData::release() { - Containers::Array data{std::move(_data)}; - _size = {}; - return data; -} - }} #endif diff --git a/src/Magnum/Trade/Test/AbstractImageConverterTest.cpp b/src/Magnum/Trade/Test/AbstractImageConverterTest.cpp index b0a385472..6a445e7d3 100644 --- a/src/Magnum/Trade/Test/AbstractImageConverterTest.cpp +++ b/src/Magnum/Trade/Test/AbstractImageConverterTest.cpp @@ -33,6 +33,7 @@ #include #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/PixelFormat.h" #include "Magnum/Trade/AbstractImageConverter.h" #include "Magnum/Trade/ImageData.h" diff --git a/src/Magnum/Trade/Test/ImageDataTest.cpp b/src/Magnum/Trade/Test/ImageDataTest.cpp index 682316e02..f47922937 100644 --- a/src/Magnum/Trade/Test/ImageDataTest.cpp +++ b/src/Magnum/Trade/Test/ImageDataTest.cpp @@ -28,6 +28,7 @@ #include #include +#include "Magnum/ImageView.h" #include "Magnum/Math/Color.h" #include "Magnum/PixelFormat.h" #include "Magnum/Trade/ImageData.h" diff --git a/src/MagnumPlugins/AnyImageConverter/Test/AnyImageConverterTest.cpp b/src/MagnumPlugins/AnyImageConverter/Test/AnyImageConverterTest.cpp index 8a07fab65..d9a6cfabf 100644 --- a/src/MagnumPlugins/AnyImageConverter/Test/AnyImageConverterTest.cpp +++ b/src/MagnumPlugins/AnyImageConverter/Test/AnyImageConverterTest.cpp @@ -30,6 +30,7 @@ #include #include +#include "Magnum/ImageView.h" #include "Magnum/PixelFormat.h" #include "Magnum/Trade/AbstractImageConverter.h" #include "Magnum/Trade/ImageData.h" diff --git a/src/MagnumPlugins/MagnumFont/MagnumFont.cpp b/src/MagnumPlugins/MagnumFont/MagnumFont.cpp index 4912c60b7..bb2436af0 100644 --- a/src/MagnumPlugins/MagnumFont/MagnumFont.cpp +++ b/src/MagnumPlugins/MagnumFont/MagnumFont.cpp @@ -32,6 +32,7 @@ #include #include +#include "Magnum/ImageView.h" #include "Magnum/Math/ConfigurationValue.h" #include "Magnum/Text/GlyphCache.h" #include "Magnum/Trade/ImageData.h" diff --git a/src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.cpp b/src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.cpp index f4868c647..229387a34 100644 --- a/src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.cpp +++ b/src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.cpp @@ -32,6 +32,7 @@ #include #include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/PixelFormat.h" #include "Magnum/Math/ConfigurationValue.h" #include "Magnum/Text/AbstractFont.h" diff --git a/src/MagnumPlugins/TgaImageConverter/Test/TgaImageConverterTest.cpp b/src/MagnumPlugins/TgaImageConverter/Test/TgaImageConverterTest.cpp index a84b26de9..cf9270c29 100644 --- a/src/MagnumPlugins/TgaImageConverter/Test/TgaImageConverterTest.cpp +++ b/src/MagnumPlugins/TgaImageConverter/Test/TgaImageConverterTest.cpp @@ -32,7 +32,7 @@ #include #include -#include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/PixelFormat.h" #include "Magnum/Trade/ImageData.h" #include "Magnum/Trade/AbstractImageConverter.h" diff --git a/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp b/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp index 346dd9edb..eef60bd3c 100644 --- a/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp +++ b/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp @@ -31,7 +31,7 @@ #include #include -#include "Magnum/Image.h" +#include "Magnum/ImageView.h" #include "Magnum/PixelFormat.h" #include "Magnum/Math/Swizzle.h" #include "Magnum/Math/Vector4.h"