Browse Source

Pixel storage support, part 1: removed needles AbstractImage bases.

I hoped to use them to store pixel pack/unpack configuration, but I have
better solution now.

The AbstractImage.h header is now removed along with the base classes,
I'm not expecting that anyone used these empty classes, so I'm not doing
anything to preserve backwards compatibility.
pull/107/head
Vladimír Vondruš 11 years ago
parent
commit
fe97c608c2
  1. 84
      src/Magnum/AbstractImage.h
  2. 14
      src/Magnum/BufferImage.h
  3. 4
      src/Magnum/CMakeLists.txt
  4. 12
      src/Magnum/Image.h
  5. 8
      src/Magnum/ImageView.h
  6. 1
      src/Magnum/Magnum.h
  7. 10
      src/Magnum/PixelStorage.cpp
  8. 47
      src/Magnum/PixelStorage.h
  9. 2
      src/Magnum/Test/CMakeLists.txt
  10. 18
      src/Magnum/Test/PixelStorageTest.cpp
  11. 2
      src/Magnum/Trade/ImageData.cpp
  12. 5
      src/Magnum/Trade/ImageData.h

84
src/Magnum/AbstractImage.h

@ -1,84 +0,0 @@
#ifndef Magnum_AbstractImage_h
#define Magnum_AbstractImage_h
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015
Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
/** @file
* @brief Class @ref Magnum::AbstractImage, @ref Magnum::AbstractCompressedImage
*/
#include <cstddef>
#include "Magnum/Magnum.h"
#include "Magnum/visibility.h"
namespace Magnum {
namespace Implementation {
std::size_t MAGNUM_EXPORT imagePixelSize(ColorFormat format, ColorType type);
template<UnsignedInt dimensions> std::size_t imageDataSize(const AbstractImage& image, ColorFormat format, ColorType type, Math::Vector<dimensions, Int> size);
}
/**
@brief Non-templated base for one-, two- or three-dimensional uncompressed images
See @ref Image, @ref ImageView, @ref BufferImage and @ref Trade::ImageData
documentation for more information.
@see @ref AbstractCompressedImage
@todo Where to put glClampColor() and glPixelStore() encapsulation? It is
needed in AbstractFramebuffer::read(), Texture::setImage() etc (i.e. all
functions operating with images). It also possibly needs to be "stackable"
to easily revert the state back.
*/
class AbstractImage {
protected:
~AbstractImage() = default;
#ifndef DOXYGEN_GENERATING_OUTPUT
protected:
#else
private:
#endif
/** @todo remove this when the class has actual contents */
/* Otherwise both (heh) GCC and Clang complain when move-constructing using {} */
Int _dummy;
};
/**
@brief Non-templated base for one-, two- or three-dimensional compressed images
See @ref CompressedImage, @ref CompressedImageView, @ref CompressedBufferImage
and @ref Trade::ImageData documentation for more information.
@see @ref AbstractImage
*/
class AbstractCompressedImage: public AbstractImage {
protected:
~AbstractCompressedImage() = default;
};
}
#endif

14
src/Magnum/BufferImage.h

@ -31,9 +31,9 @@
*/ */
#endif #endif
#include "Magnum/AbstractImage.h"
#include "Magnum/Buffer.h" #include "Magnum/Buffer.h"
#include "Magnum/DimensionTraits.h" #include "Magnum/DimensionTraits.h"
#include "Magnum/PixelStorage.h"
#include "Magnum/Math/Vector3.h" #include "Magnum/Math/Vector3.h"
namespace Magnum { namespace Magnum {
@ -49,7 +49,7 @@ Stores image data in GPU memory. Interchangeable with @ref Image,
@requires_gles30 Pixel buffer objects are not available in OpenGL ES 2.0. @requires_gles30 Pixel buffer objects are not available in OpenGL ES 2.0.
@requires_webgl20 Pixel buffer objects are not available in WebGL 1.0. @requires_webgl20 Pixel buffer objects are not available in WebGL 1.0.
*/ */
template<UnsignedInt dimensions> class BufferImage: public AbstractImage { template<UnsignedInt dimensions> class BufferImage {
public: public:
enum: UnsignedInt { enum: UnsignedInt {
Dimensions = dimensions /**< Image dimension count */ Dimensions = dimensions /**< Image dimension count */
@ -105,7 +105,7 @@ template<UnsignedInt dimensions> class BufferImage: public AbstractImage {
/** @copydoc Image::dataSize() */ /** @copydoc Image::dataSize() */
std::size_t dataSize(const VectorTypeFor<dimensions, Int>& size) const { std::size_t dataSize(const VectorTypeFor<dimensions, Int>& size) const {
return Implementation::imageDataSize<dimensions>(*this, _format, _type, size); return Implementation::imageDataSize<dimensions>(_format, _type, size);
} }
/** @brief Image buffer */ /** @brief Image buffer */
@ -155,7 +155,7 @@ See @ref BufferImage for more information. Interchangeable with @ref CompressedI
@requires_gles30 Pixel buffer objects are not available in OpenGL ES 2.0. @requires_gles30 Pixel buffer objects are not available in OpenGL ES 2.0.
@requires_webgl20 Pixel buffer objects are not available in WebGL 1.0. @requires_webgl20 Pixel buffer objects are not available in WebGL 1.0.
*/ */
template<UnsignedInt dimensions> class CompressedBufferImage: public AbstractCompressedImage { template<UnsignedInt dimensions> class CompressedBufferImage {
public: public:
enum: UnsignedInt { enum: UnsignedInt {
Dimensions = dimensions /**< Image dimension count */ Dimensions = dimensions /**< Image dimension count */
@ -237,17 +237,16 @@ typedef CompressedBufferImage<2> CompressedBufferImage2D;
/** @brief Three-dimensional compressed buffer image */ /** @brief Three-dimensional compressed buffer image */
typedef CompressedBufferImage<3> CompressedBufferImage3D; typedef CompressedBufferImage<3> CompressedBufferImage3D;
template<UnsignedInt dimensions> inline BufferImage<dimensions>::BufferImage(BufferImage<dimensions>&& other) noexcept: AbstractImage{std::move(other)}, _format{std::move(other._format)}, _type{std::move(other._type)}, _size{std::move(other._size)}, _buffer{std::move(other._buffer)} { template<UnsignedInt dimensions> inline BufferImage<dimensions>::BufferImage(BufferImage<dimensions>&& other) noexcept: _format{std::move(other._format)}, _type{std::move(other._type)}, _size{std::move(other._size)}, _buffer{std::move(other._buffer)} {
other._size = {}; other._size = {};
} }
template<UnsignedInt dimensions> inline CompressedBufferImage<dimensions>::CompressedBufferImage(CompressedBufferImage<dimensions>&& other) noexcept: AbstractCompressedImage{std::move(other)}, _format{std::move(other._format)}, _size{std::move(other._size)}, _buffer{std::move(other._buffer)}, _dataSize{std::move(other._dataSize)} { template<UnsignedInt dimensions> inline CompressedBufferImage<dimensions>::CompressedBufferImage(CompressedBufferImage<dimensions>&& other) noexcept: _format{std::move(other._format)}, _size{std::move(other._size)}, _buffer{std::move(other._buffer)}, _dataSize{std::move(other._dataSize)} {
other._size = {}; other._size = {};
other._dataSize = {}; other._dataSize = {};
} }
template<UnsignedInt dimensions> inline BufferImage<dimensions>& BufferImage<dimensions>::operator=(BufferImage<dimensions>&& other) noexcept { template<UnsignedInt dimensions> inline BufferImage<dimensions>& BufferImage<dimensions>::operator=(BufferImage<dimensions>&& other) noexcept {
AbstractImage::operator=(std::move(other));
using std::swap; using std::swap;
swap(_format, other._format); swap(_format, other._format);
swap(_type, other._type); swap(_type, other._type);
@ -257,7 +256,6 @@ template<UnsignedInt dimensions> inline BufferImage<dimensions>& BufferImage<dim
} }
template<UnsignedInt dimensions> inline CompressedBufferImage<dimensions>& CompressedBufferImage<dimensions>::operator=(CompressedBufferImage<dimensions>&& other) noexcept { template<UnsignedInt dimensions> inline CompressedBufferImage<dimensions>& CompressedBufferImage<dimensions>::operator=(CompressedBufferImage<dimensions>&& other) noexcept {
AbstractCompressedImage::operator=(std::move(other));
using std::swap; using std::swap;
swap(_format, other._format); swap(_format, other._format);
swap(_size, other._size); swap(_size, other._size);

4
src/Magnum/CMakeLists.txt

@ -29,7 +29,6 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure.h.cmake
# Files shared between main library and unit test library # Files shared between main library and unit test library
set(Magnum_SRCS set(Magnum_SRCS
AbstractFramebuffer.cpp AbstractFramebuffer.cpp
AbstractImage.cpp
AbstractObject.cpp AbstractObject.cpp
AbstractTexture.cpp AbstractTexture.cpp
AbstractShaderProgram.cpp AbstractShaderProgram.cpp
@ -44,6 +43,7 @@ set(Magnum_SRCS
Mesh.cpp Mesh.cpp
MeshView.cpp MeshView.cpp
OpenGL.cpp OpenGL.cpp
PixelStorage.cpp
Renderbuffer.cpp Renderbuffer.cpp
Renderer.cpp Renderer.cpp
Resource.cpp Resource.cpp
@ -79,7 +79,6 @@ set(Magnum_SRCS
set(Magnum_HEADERS set(Magnum_HEADERS
AbstractFramebuffer.h AbstractFramebuffer.h
AbstractImage.h
AbstractObject.h AbstractObject.h
AbstractResourceLoader.h AbstractResourceLoader.h
AbstractShaderProgram.h AbstractShaderProgram.h
@ -100,6 +99,7 @@ set(Magnum_HEADERS
Mesh.h Mesh.h
MeshView.h MeshView.h
OpenGL.h OpenGL.h
PixelStorage.h
Renderbuffer.h Renderbuffer.h
RenderbufferFormat.h RenderbufferFormat.h
Renderer.h Renderer.h

12
src/Magnum/Image.h

@ -42,7 +42,7 @@ Stores image data on client memory. Interchangeable with @ref ImageView,
@ref BufferImage or @ref Trade::ImageData. @ref BufferImage or @ref Trade::ImageData.
@see @ref Image1D, @ref Image2D, @ref Image3D, @ref CompressedImage @see @ref Image1D, @ref Image2D, @ref Image3D, @ref CompressedImage
*/ */
template<UnsignedInt dimensions> class Image: public AbstractImage { template<UnsignedInt dimensions> class Image {
public: public:
enum: UnsignedInt { enum: UnsignedInt {
Dimensions = dimensions /**< Image dimension count */ Dimensions = dimensions /**< Image dimension count */
@ -118,7 +118,7 @@ template<UnsignedInt dimensions> class Image: public AbstractImage {
* @see @ref pixelSize() * @see @ref pixelSize()
*/ */
std::size_t dataSize(const VectorTypeFor<dimensions, Int>& size) const { std::size_t dataSize(const VectorTypeFor<dimensions, Int>& size) const {
return Implementation::imageDataSize<dimensions>(*this, _format, _type, size); return Implementation::imageDataSize<dimensions>(_format, _type, size);
} }
/** /**
@ -182,7 +182,7 @@ See @ref Image for more information. Interchangeable with
@ref CompressedImageView, @ref CompressedBufferImage or @ref Trade::ImageData. @ref CompressedImageView, @ref CompressedBufferImage or @ref Trade::ImageData.
@see @ref CompressedImage1D, @ref CompressedImage2D, @ref CompressedImage3D @see @ref CompressedImage1D, @ref CompressedImage2D, @ref CompressedImage3D
*/ */
template<UnsignedInt dimensions> class CompressedImage: public AbstractCompressedImage { template<UnsignedInt dimensions> class CompressedImage {
public: public:
enum: UnsignedInt { enum: UnsignedInt {
Dimensions = dimensions /**< Image dimension count */ Dimensions = dimensions /**< Image dimension count */
@ -291,18 +291,17 @@ typedef CompressedImage<2> CompressedImage2D;
/** @brief Three-dimensional compressed image */ /** @brief Three-dimensional compressed image */
typedef CompressedImage<3> CompressedImage3D; typedef CompressedImage<3> CompressedImage3D;
template<UnsignedInt dimensions> inline Image<dimensions>::Image(Image<dimensions>&& other) noexcept: AbstractImage{std::move(other)}, _format{std::move(other._format)}, _type{std::move(other._type)}, _size{std::move(other._size)}, _data{std::move(other._data)} { template<UnsignedInt dimensions> inline Image<dimensions>::Image(Image<dimensions>&& other) noexcept: _format{std::move(other._format)}, _type{std::move(other._type)}, _size{std::move(other._size)}, _data{std::move(other._data)} {
other._size = {}; other._size = {};
other._data = nullptr; other._data = nullptr;
} }
template<UnsignedInt dimensions> inline CompressedImage<dimensions>::CompressedImage(CompressedImage<dimensions>&& other) noexcept: AbstractCompressedImage{std::move(other)}, _format{std::move(other._format)}, _size{std::move(other._size)}, _data{std::move(other._data)} { template<UnsignedInt dimensions> inline CompressedImage<dimensions>::CompressedImage(CompressedImage<dimensions>&& other) noexcept: _format{std::move(other._format)}, _size{std::move(other._size)}, _data{std::move(other._data)} {
other._size = {}; other._size = {};
other._data = nullptr; other._data = nullptr;
} }
template<UnsignedInt dimensions> inline Image<dimensions>& Image<dimensions>::operator=(Image<dimensions>&& other) noexcept { template<UnsignedInt dimensions> inline Image<dimensions>& Image<dimensions>::operator=(Image<dimensions>&& other) noexcept {
AbstractImage::operator=(std::move(other));
using std::swap; using std::swap;
swap(_format, other._format); swap(_format, other._format);
swap(_type, other._type); swap(_type, other._type);
@ -312,7 +311,6 @@ template<UnsignedInt dimensions> inline Image<dimensions>& Image<dimensions>::op
} }
template<UnsignedInt dimensions> inline CompressedImage<dimensions>& CompressedImage<dimensions>::operator=(CompressedImage<dimensions>&& other) noexcept { template<UnsignedInt dimensions> inline CompressedImage<dimensions>& CompressedImage<dimensions>::operator=(CompressedImage<dimensions>&& other) noexcept {
AbstractCompressedImage::operator=(std::move(other));
using std::swap; using std::swap;
swap(_format, other._format); swap(_format, other._format);
swap(_size, other._size); swap(_size, other._size);

8
src/Magnum/ImageView.h

@ -31,9 +31,9 @@
#include <Corrade/Containers/ArrayView.h> #include <Corrade/Containers/ArrayView.h>
#include "Magnum/Math/Vector3.h"
#include "Magnum/AbstractImage.h"
#include "Magnum/DimensionTraits.h" #include "Magnum/DimensionTraits.h"
#include "Magnum/PixelStorage.h"
#include "Magnum/Math/Vector3.h"
namespace Magnum { namespace Magnum {
@ -53,7 +53,7 @@ Interchangeable with @ref Image, @ref BufferImage or @ref Trade::ImageData.
@see @ref ImageView1D, @ref ImageView2D, @ref ImageView3D, @see @ref ImageView1D, @ref ImageView2D, @ref ImageView3D,
@ref CompressedImageView @ref CompressedImageView
*/ */
template<UnsignedInt dimensions> class ImageView: public AbstractImage { template<UnsignedInt dimensions> class ImageView {
public: public:
enum: UnsignedInt { enum: UnsignedInt {
Dimensions = dimensions /**< Image dimension count */ Dimensions = dimensions /**< Image dimension count */
@ -142,7 +142,7 @@ See @ref ImageView for more information. Interchangeable with
@see @ref CompressedImageView1D, @ref CompressedImageView2D, @see @ref CompressedImageView1D, @ref CompressedImageView2D,
@ref CompressedImageView3D @ref CompressedImageView3D
*/ */
template<UnsignedInt dimensions> class CompressedImageView: public AbstractCompressedImage { template<UnsignedInt dimensions> class CompressedImageView {
public: public:
enum: UnsignedInt { enum: UnsignedInt {
Dimensions = dimensions /**< Image dimension count */ Dimensions = dimensions /**< Image dimension count */

1
src/Magnum/Magnum.h

@ -435,7 +435,6 @@ using Math::operator "" _radf;
FramebufferTarget enums used only directly with framebuffer instance */ FramebufferTarget enums used only directly with framebuffer instance */
class AbstractFramebuffer; class AbstractFramebuffer;
class AbstractImage;
/* AbstractQuery is not used directly */ /* AbstractQuery is not used directly */
class AbstractShaderProgram; class AbstractShaderProgram;
class AbstractTexture; class AbstractTexture;

10
src/Magnum/AbstractImage.cpp → src/Magnum/PixelStorage.cpp

@ -23,7 +23,7 @@
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
*/ */
#include "AbstractImage.h" #include "PixelStorage.h"
#include <Corrade/Utility/Assert.h> #include <Corrade/Utility/Assert.h>
@ -151,7 +151,7 @@ std::size_t imagePixelSize(ColorFormat format, ColorType type) {
CORRADE_ASSERT_UNREACHABLE(); CORRADE_ASSERT_UNREACHABLE();
} }
template<UnsignedInt dimensions> std::size_t imageDataSize(const AbstractImage&, const ColorFormat format, const ColorType type, Math::Vector<dimensions, Int> size) { template<UnsignedInt dimensions> std::size_t imageDataSize(const ColorFormat format, const ColorType type, Math::Vector<dimensions, Int> size) {
/** @todo Code this properly when all @fn_gl{PixelStore} parameters are implemented */ /** @todo Code this properly when all @fn_gl{PixelStore} parameters are implemented */
/* Row size, rounded to multiple of 4 bytes */ /* Row size, rounded to multiple of 4 bytes */
const std::size_t rowSize = ((size[0]*imagePixelSize(format, type) + 3)/4)*4; const std::size_t rowSize = ((size[0]*imagePixelSize(format, type) + 3)/4)*4;
@ -161,8 +161,8 @@ template<UnsignedInt dimensions> std::size_t imageDataSize(const AbstractImage&,
return rowSize*size.product(); return rowSize*size.product();
} }
template MAGNUM_EXPORT std::size_t imageDataSize<1>(const AbstractImage&, ColorFormat, ColorType, Math::Vector<1, Int>); template MAGNUM_EXPORT std::size_t imageDataSize<1>(ColorFormat, ColorType, Math::Vector<1, Int>);
template MAGNUM_EXPORT std::size_t imageDataSize<2>(const AbstractImage&, ColorFormat, ColorType, Math::Vector<2, Int>); template MAGNUM_EXPORT std::size_t imageDataSize<2>(ColorFormat, ColorType, Math::Vector<2, Int>);
template MAGNUM_EXPORT std::size_t imageDataSize<3>(const AbstractImage&, ColorFormat, ColorType, Math::Vector<3, Int>); template MAGNUM_EXPORT std::size_t imageDataSize<3>(ColorFormat, ColorType, Math::Vector<3, Int>);
}} }}

47
src/Magnum/PixelStorage.h

@ -0,0 +1,47 @@
#ifndef Magnum_PixelStorage_h
#define Magnum_PixelStorage_h
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015
Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
/** @file
* @brief
*/
#include <cstddef>
#include "Magnum/Magnum.h"
#include "Magnum/visibility.h"
namespace Magnum {
namespace Implementation {
std::size_t MAGNUM_EXPORT imagePixelSize(ColorFormat format, ColorType type);
template<UnsignedInt dimensions> std::size_t imageDataSize(ColorFormat format, ColorType type, Math::Vector<dimensions, Int> size);
}
}
#endif

2
src/Magnum/Test/CMakeLists.txt

@ -23,7 +23,6 @@
# DEALINGS IN THE SOFTWARE. # DEALINGS IN THE SOFTWARE.
# #
corrade_add_test(AbstractImageTest AbstractImageTest.cpp LIBRARIES Magnum)
corrade_add_test(AbstractShaderProgramTest AbstractShaderProgramTest.cpp LIBRARIES Magnum) corrade_add_test(AbstractShaderProgramTest AbstractShaderProgramTest.cpp LIBRARIES Magnum)
corrade_add_test(ArrayTest ArrayTest.cpp) corrade_add_test(ArrayTest ArrayTest.cpp)
corrade_add_test(FormatTest FormatTest.cpp LIBRARIES Magnum) corrade_add_test(FormatTest FormatTest.cpp LIBRARIES Magnum)
@ -34,6 +33,7 @@ corrade_add_test(FramebufferTest FramebufferTest.cpp LIBRARIES Magnum)
corrade_add_test(ImageTest ImageTest.cpp LIBRARIES Magnum) corrade_add_test(ImageTest ImageTest.cpp LIBRARIES Magnum)
corrade_add_test(ImageViewTest ImageViewTest.cpp LIBRARIES Magnum) corrade_add_test(ImageViewTest ImageViewTest.cpp LIBRARIES Magnum)
corrade_add_test(MeshTest MeshTest.cpp LIBRARIES Magnum) corrade_add_test(MeshTest MeshTest.cpp LIBRARIES Magnum)
corrade_add_test(PixelStorageTest PixelStorageTest.cpp LIBRARIES Magnum)
corrade_add_test(RendererTest RendererTest.cpp LIBRARIES Magnum) corrade_add_test(RendererTest RendererTest.cpp LIBRARIES Magnum)
corrade_add_test(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES Magnum) corrade_add_test(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES Magnum)
corrade_add_test(SamplerTest SamplerTest.cpp LIBRARIES Magnum) corrade_add_test(SamplerTest SamplerTest.cpp LIBRARIES Magnum)

18
src/Magnum/Test/AbstractImageTest.cpp → src/Magnum/Test/PixelStorageTest.cpp

@ -25,32 +25,32 @@
#include <Corrade/TestSuite/Tester.h> #include <Corrade/TestSuite/Tester.h>
#include "Magnum/AbstractImage.h"
#include "Magnum/Image.h" #include "Magnum/Image.h"
#include "Magnum/ColorFormat.h" #include "Magnum/ColorFormat.h"
#include "Magnum/PixelStorage.h"
namespace Magnum { namespace Test { namespace Magnum { namespace Test {
struct AbstractImageTest: TestSuite::Tester { struct PixelStorageTest: TestSuite::Tester {
explicit AbstractImageTest(); explicit PixelStorageTest();
void pixelSize(); void pixelSize();
void dataSize(); void dataSize();
}; };
AbstractImageTest::AbstractImageTest() { PixelStorageTest::PixelStorageTest() {
addTests({&AbstractImageTest::pixelSize, addTests({&PixelStorageTest::pixelSize,
&AbstractImageTest::dataSize}); &PixelStorageTest::dataSize});
} }
void AbstractImageTest::pixelSize() { void PixelStorageTest::pixelSize() {
CORRADE_COMPARE(Implementation::imagePixelSize(ColorFormat::RGBA, ColorType::UnsignedInt), 4*4); CORRADE_COMPARE(Implementation::imagePixelSize(ColorFormat::RGBA, ColorType::UnsignedInt), 4*4);
CORRADE_COMPARE(Implementation::imagePixelSize(ColorFormat::DepthComponent, ColorType::UnsignedShort), 2); CORRADE_COMPARE(Implementation::imagePixelSize(ColorFormat::DepthComponent, ColorType::UnsignedShort), 2);
CORRADE_COMPARE(Implementation::imagePixelSize(ColorFormat::StencilIndex, ColorType::UnsignedByte), 1); CORRADE_COMPARE(Implementation::imagePixelSize(ColorFormat::StencilIndex, ColorType::UnsignedByte), 1);
CORRADE_COMPARE(Implementation::imagePixelSize(ColorFormat::DepthStencil, ColorType::UnsignedInt248), 4); CORRADE_COMPARE(Implementation::imagePixelSize(ColorFormat::DepthStencil, ColorType::UnsignedInt248), 4);
} }
void AbstractImageTest::dataSize() { void PixelStorageTest::dataSize() {
/* Verify that row size is properly rounded */ /* Verify that row size is properly rounded */
CORRADE_COMPARE(Image2D(ColorFormat::RGBA, ColorType::UnsignedByte).dataSize({}), 0); CORRADE_COMPARE(Image2D(ColorFormat::RGBA, ColorType::UnsignedByte).dataSize({}), 0);
CORRADE_COMPARE(Image2D(ColorFormat::Red, ColorType::UnsignedByte).dataSize({4, 2}), 8); CORRADE_COMPARE(Image2D(ColorFormat::Red, ColorType::UnsignedByte).dataSize({4, 2}), 8);
@ -63,4 +63,4 @@ void AbstractImageTest::dataSize() {
}} }}
CORRADE_TEST_MAIN(Magnum::Test::AbstractImageTest) CORRADE_TEST_MAIN(Magnum::Test::PixelStorageTest)

2
src/Magnum/Trade/ImageData.cpp

@ -49,7 +49,7 @@ template<UnsignedInt dimensions> std::size_t ImageData<dimensions>::pixelSize()
template<UnsignedInt dimensions> std::size_t ImageData<dimensions>::dataSize(const VectorTypeFor< dimensions, Int >& size) const { template<UnsignedInt dimensions> std::size_t ImageData<dimensions>::dataSize(const VectorTypeFor< dimensions, Int >& size) const {
CORRADE_ASSERT(!_compressed, "Trade::ImageData::dataSize(): the image is compressed", {}); CORRADE_ASSERT(!_compressed, "Trade::ImageData::dataSize(): the image is compressed", {});
return Implementation::imageDataSize<dimensions>(*this, _format, _type, size); return Implementation::imageDataSize<dimensions>(_format, _type, size);
} }
template<UnsignedInt dimensions> ImageData<dimensions>::operator ImageView<dimensions>() template<UnsignedInt dimensions> ImageData<dimensions>::operator ImageView<dimensions>()

5
src/Magnum/Trade/ImageData.h

@ -50,7 +50,7 @@ Uncompressed image is interchangeable with @ref Image, @ref ImageView or
or @ref CompressedBufferImage. or @ref CompressedBufferImage.
@see @ref ImageData1D, @ref ImageData2D, @ref ImageData3D @see @ref ImageData1D, @ref ImageData2D, @ref ImageData3D
*/ */
template<UnsignedInt dimensions> class ImageData: public AbstractCompressedImage { template<UnsignedInt dimensions> class ImageData {
public: public:
enum: UnsignedInt { enum: UnsignedInt {
Dimensions = dimensions /**< Image dimension count */ Dimensions = dimensions /**< Image dimension count */
@ -223,7 +223,7 @@ typedef ImageData<2> ImageData2D;
/** @brief Three-dimensional image */ /** @brief Three-dimensional image */
typedef ImageData<3> ImageData3D; typedef ImageData<3> ImageData3D;
template<UnsignedInt dimensions> inline ImageData<dimensions>::ImageData(ImageData<dimensions>&& other) noexcept: AbstractCompressedImage{std::move(other)}, _compressed{std::move(other._compressed)}, _type{std::move(other._type)}, _size{std::move(other._size)}, _data{std::move(other._data)} { template<UnsignedInt dimensions> inline ImageData<dimensions>::ImageData(ImageData<dimensions>&& other) noexcept: _compressed{std::move(other._compressed)}, _type{std::move(other._type)}, _size{std::move(other._size)}, _data{std::move(other._data)} {
if(_compressed) _compressedFormat = std::move(other._compressedFormat); if(_compressed) _compressedFormat = std::move(other._compressedFormat);
else _format = std::move(other._format); else _format = std::move(other._format);
@ -232,7 +232,6 @@ template<UnsignedInt dimensions> inline ImageData<dimensions>::ImageData(ImageDa
} }
template<UnsignedInt dimensions> inline ImageData<dimensions>& ImageData<dimensions>::operator=(ImageData<dimensions>&& other) noexcept { template<UnsignedInt dimensions> inline ImageData<dimensions>& ImageData<dimensions>::operator=(ImageData<dimensions>&& other) noexcept {
AbstractCompressedImage::operator=(std::move(other));
using std::swap; using std::swap;
swap(_compressed, other._compressed); swap(_compressed, other._compressed);
if(_compressed) swap(_compressedFormat, other._compressedFormat); if(_compressed) swap(_compressedFormat, other._compressedFormat);

Loading…
Cancel
Save