mirror of https://github.com/mosra/magnum.git
Browse Source
With the intention that those will eventually contain also things like YUp / YDown, PremultipliedAlpha and such. This commit is mostly just busywork, wiring this into [Compressed]Image, [Compressed]ImageView and Trade::ImageData and ensuring the flags get correctly propagated during moves and conversions. Unfortunately in case of Trade::ImageData it meant deprecating the current set of constructor in order to insert an ImageFlags parameter before the importer state pointer. The only non-trivial piece of logic is when a 2D [Compressed]ImageView gets converted to a 3D one, then the Array bit is implicitly dropped, as 2D arrays of 1D images are not really a thing. Instead, it's now possible to add new flags when doing the conversion -- for example to turn a 2D image to a (single-layer) 2D array image.pull/578/head
18 changed files with 1332 additions and 269 deletions
@ -0,0 +1,101 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020, 2021, 2022 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. |
||||
*/ |
||||
|
||||
#include "ImageFlags.h" |
||||
|
||||
#include <Corrade/Containers/EnumSet.hpp> |
||||
|
||||
namespace Magnum { |
||||
|
||||
Debug& operator<<(Debug& debug, const ImageFlag1D value) { |
||||
const bool packed = debug.immediateFlags() >= Debug::Flag::Packed; |
||||
|
||||
if(!packed) |
||||
debug << "ImageFlag1D" << Debug::nospace; |
||||
|
||||
switch(value) { |
||||
/* LCOV_EXCL_START */ |
||||
#define _c(value) case ImageFlag1D::value: return debug << (packed ? "" : "::") << Debug::nospace << #value; |
||||
#undef _c |
||||
/* LCOV_EXCL_STOP */ |
||||
} |
||||
|
||||
return debug << (packed ? "" : "(") << Debug::nospace << reinterpret_cast<void*>(UnsignedShort(value)) << Debug::nospace << (packed ? "" : ")"); |
||||
} |
||||
|
||||
Debug& operator<<(Debug& debug, const ImageFlag2D value) { |
||||
const bool packed = debug.immediateFlags() >= Debug::Flag::Packed; |
||||
|
||||
if(!packed) |
||||
debug << "ImageFlag2D" << Debug::nospace; |
||||
|
||||
switch(value) { |
||||
/* LCOV_EXCL_START */ |
||||
#define _c(value) case ImageFlag2D::value: return debug << (packed ? "" : "::") << Debug::nospace << #value; |
||||
_c(Array) |
||||
#undef _c |
||||
/* LCOV_EXCL_STOP */ |
||||
} |
||||
|
||||
return debug << (packed ? "" : "(") << Debug::nospace << reinterpret_cast<void*>(UnsignedShort(value)) << Debug::nospace << (packed ? "" : ")"); |
||||
} |
||||
|
||||
Debug& operator<<(Debug& debug, const ImageFlag3D value) { |
||||
const bool packed = debug.immediateFlags() >= Debug::Flag::Packed; |
||||
|
||||
if(!packed) |
||||
debug << "ImageFlag3D" << Debug::nospace; |
||||
|
||||
switch(value) { |
||||
/* LCOV_EXCL_START */ |
||||
#define _c(value) case ImageFlag3D::value: return debug << (packed ? "" : "::") << Debug::nospace << #value; |
||||
_c(Array) |
||||
_c(CubeMap) |
||||
#undef _c |
||||
/* LCOV_EXCL_STOP */ |
||||
} |
||||
|
||||
return debug << (packed ? "" : "(") << Debug::nospace << reinterpret_cast<void*>(UnsignedShort(value)) << Debug::nospace << (packed ? "" : ")"); |
||||
} |
||||
|
||||
Debug& operator<<(Debug& debug, const ImageFlags1D value) { |
||||
return Containers::enumSetDebugOutput(debug, value, debug.immediateFlags() >= Debug::Flag::Packed ? "{}" : "ImageFlags1D{}", { |
||||
}); |
||||
} |
||||
|
||||
Debug& operator<<(Debug& debug, const ImageFlags2D value) { |
||||
return Containers::enumSetDebugOutput(debug, value, debug.immediateFlags() >= Debug::Flag::Packed ? "{}" : "ImageFlags2D{}", { |
||||
ImageFlag2D::Array |
||||
}); |
||||
} |
||||
|
||||
Debug& operator<<(Debug& debug, const ImageFlags3D value) { |
||||
return Containers::enumSetDebugOutput(debug, value, debug.immediateFlags() >= Debug::Flag::Packed ? "{}" : "ImageFlags3D{}", { |
||||
ImageFlag3D::Array, |
||||
ImageFlag3D::CubeMap |
||||
}); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,183 @@
|
||||
#ifndef Magnum_ImageFlags_h |
||||
#define Magnum_ImageFlags_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020, 2021, 2022 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 Enum @ref Magnum::ImageFlag1D, @ref Magnum::ImageFlag2D, @ref Magnum::ImageFlag3D, enum set @ref Magnum::ImageFlags1D, @ref Magnum::ImageFlags2D, @ref Magnum::ImageFlags3D, alias @ref Magnum::ImageFlag, @ref Magnum::ImageFlags |
||||
* @m_since_latest |
||||
*/ |
||||
|
||||
#include <Corrade/Containers/EnumSet.h> |
||||
|
||||
#include "Magnum/Magnum.h" |
||||
#include "Magnum/visibility.h" |
||||
|
||||
namespace Magnum { |
||||
|
||||
/**
|
||||
@brief 1D image layout flag |
||||
@m_since_latest |
||||
|
||||
Used by @ref Image1D, @ref ImageView1D and @ref Trade::ImageData1D. Currently |
||||
no flags specific to 1D images are defined. |
||||
@see @ref ImageFlags1D |
||||
*/ |
||||
enum class ImageFlag1D: UnsignedShort {}; |
||||
|
||||
/**
|
||||
@brief 2D image layout flag |
||||
@m_since_latest |
||||
|
||||
Used by @ref Image2D, @ref ImageView2D and @ref Trade::ImageData2D. |
||||
@see @ref ImageFlags2D |
||||
*/ |
||||
enum class ImageFlag2D: UnsignedShort { |
||||
/**
|
||||
* The image is a 1D array instead of 2D. I.e., no filtering is done along |
||||
* the Y axis and mip levels don't shorten along the Y axis. |
||||
* |
||||
* Guaranteed to have the same value as @ref ImageFlag3D::Array. |
||||
*/ |
||||
Array = 1 << 0, |
||||
}; |
||||
|
||||
/**
|
||||
@brief 3D image layout flag |
||||
@m_since_latest |
||||
|
||||
Used by @ref Image3D, @ref ImageView3D and @ref Trade::ImageData3D. |
||||
@see @ref ImageFlags3D |
||||
*/ |
||||
enum class ImageFlag3D: UnsignedShort { |
||||
/**
|
||||
* The image is a 2D array instead of 3D. I.e., no filtering is done along |
||||
* the Z axis and mip levels don't shorten along the Z axis. |
||||
* |
||||
* Guaranteed to have the same value as @ref ImageFlag2D::Array. |
||||
*/ |
||||
Array = 1 << 0, |
||||
|
||||
/**
|
||||
* The image is a cube map instead of 3D. I.e., there's exactly six square |
||||
* 2D faces in order (+X, -X, +Y, -Y, +Z, -Z), filtering is done on face |
||||
* edges, and mip levels don't shorten along the Z axis. If combined with |
||||
* @ref ImageFlag3D::Array, the image is a cube map array, consisting of an |
||||
* exact multiple of six square 2D faces, with each six layers being one |
||||
* cube map. |
||||
*/ |
||||
CubeMap = 1 << 1 |
||||
}; |
||||
|
||||
/** @debugoperatorenum{ImageFlag1D} */ |
||||
MAGNUM_EXPORT Debug& operator<<(Debug& debug, ImageFlag1D value); |
||||
|
||||
/** @debugoperatorenum{ImageFlag2D} */ |
||||
MAGNUM_EXPORT Debug& operator<<(Debug& debug, ImageFlag2D value); |
||||
|
||||
/** @debugoperatorenum{ImageFlag3D} */ |
||||
MAGNUM_EXPORT Debug& operator<<(Debug& debug, ImageFlag3D value); |
||||
|
||||
/**
|
||||
@brief 1D image layout flags |
||||
@m_since_latest |
||||
|
||||
Used by @ref Image1D, @ref ImageView1D, @ref Trade::ImageData1D and |
||||
@ref GL::BufferImage1D. |
||||
*/ |
||||
typedef Containers::EnumSet<ImageFlag1D> ImageFlags1D; |
||||
|
||||
/**
|
||||
@brief 2D image layout flags |
||||
@m_since_latest |
||||
|
||||
Used by @ref Image2D, @ref ImageView2D, @ref Trade::ImageData2D and |
||||
@ref GL::BufferImage2D. |
||||
*/ |
||||
typedef Containers::EnumSet<ImageFlag2D> ImageFlags2D; |
||||
|
||||
/**
|
||||
@brief 3D image layout flags |
||||
@m_since_latest |
||||
|
||||
Used by @ref Image3D, @ref ImageView3D, @ref Trade::ImageData3D and |
||||
@ref GL::BufferImage3D. |
||||
*/ |
||||
typedef Containers::EnumSet<ImageFlag3D> ImageFlags3D; |
||||
|
||||
CORRADE_ENUMSET_OPERATORS(ImageFlags1D) |
||||
CORRADE_ENUMSET_OPERATORS(ImageFlags2D) |
||||
CORRADE_ENUMSET_OPERATORS(ImageFlags3D) |
||||
|
||||
/** @debugoperatorenum{ImageFlags1D} */ |
||||
MAGNUM_EXPORT Debug& operator<<(Debug& debug, ImageFlags1D value); |
||||
|
||||
/** @debugoperatorenum{ImageFlags2D} */ |
||||
MAGNUM_EXPORT Debug& operator<<(Debug& debug, ImageFlags2D value); |
||||
|
||||
/** @debugoperatorenum{ImageFlags3D} */ |
||||
MAGNUM_EXPORT Debug& operator<<(Debug& debug, ImageFlags3D value); |
||||
|
||||
namespace Implementation { |
||||
|
||||
template<UnsignedInt> struct ImageFlagTraits; |
||||
template<> struct ImageFlagTraits<1> { |
||||
typedef ImageFlag1D Type; |
||||
typedef ImageFlags1D SetType; |
||||
}; |
||||
template<> struct ImageFlagTraits<2> { |
||||
typedef ImageFlag2D Type; |
||||
typedef ImageFlags2D SetType; |
||||
}; |
||||
template<> struct ImageFlagTraits<3> { |
||||
typedef ImageFlag3D Type; |
||||
typedef ImageFlags3D SetType; |
||||
}; |
||||
|
||||
} |
||||
|
||||
/**
|
||||
@brief Image layout flag |
||||
@m_since_latest |
||||
|
||||
Expands to @ref ImageFlag1D, @ref ImageFlag2D or @ref ImageFlag3D based on |
||||
dimension count. |
||||
@see @ref ImageFlags |
||||
*/ |
||||
template<UnsignedInt dimensions> using ImageFlag = typename Implementation::ImageFlagTraits<dimensions>::Type; |
||||
|
||||
/**
|
||||
@brief Image layout flags |
||||
@m_since_latest |
||||
|
||||
Expands to @ref ImageFlags1D, @ref ImageFlags2D or @ref ImageFlags3D based on |
||||
dimension count. |
||||
@see @ref ImageFlag |
||||
*/ |
||||
template<UnsignedInt dimensions> using ImageFlags = typename Implementation::ImageFlagTraits<dimensions>::SetType; |
||||
|
||||
} |
||||
|
||||
#endif |
||||
@ -0,0 +1,157 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, |
||||
2020, 2021, 2022 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. |
||||
*/ |
||||
|
||||
#include <sstream> |
||||
#include <Corrade/TestSuite/Tester.h> |
||||
#include <Corrade/Utility/DebugStl.h> |
||||
|
||||
#include "Magnum/ImageFlags.h" |
||||
|
||||
namespace Magnum { namespace Test { namespace { |
||||
|
||||
struct ImageFlagsTest: TestSuite::Tester { |
||||
explicit ImageFlagsTest(); |
||||
|
||||
void matchingValues(); |
||||
|
||||
void debugFlag1D(); |
||||
void debugFlag2D(); |
||||
void debugFlag3D(); |
||||
void debugFlag1DPacked(); |
||||
void debugFlag2DPacked(); |
||||
void debugFlag3DPacked(); |
||||
|
||||
void debugFlags1D(); |
||||
void debugFlags2D(); |
||||
void debugFlags3D(); |
||||
void debugFlags1DPacked(); |
||||
void debugFlags2DPacked(); |
||||
void debugFlags3DPacked(); |
||||
}; |
||||
|
||||
ImageFlagsTest::ImageFlagsTest() { |
||||
addTests({&ImageFlagsTest::matchingValues, |
||||
|
||||
&ImageFlagsTest::debugFlag1D, |
||||
&ImageFlagsTest::debugFlag2D, |
||||
&ImageFlagsTest::debugFlag3D, |
||||
&ImageFlagsTest::debugFlag1DPacked, |
||||
&ImageFlagsTest::debugFlag2DPacked, |
||||
&ImageFlagsTest::debugFlag3DPacked, |
||||
|
||||
&ImageFlagsTest::debugFlags1D, |
||||
&ImageFlagsTest::debugFlags2D, |
||||
&ImageFlagsTest::debugFlags3D, |
||||
&ImageFlagsTest::debugFlags1DPacked, |
||||
&ImageFlagsTest::debugFlags2DPacked, |
||||
&ImageFlagsTest::debugFlags3DPacked}); |
||||
} |
||||
|
||||
void ImageFlagsTest::matchingValues() { |
||||
CORRADE_COMPARE(UnsignedShort(ImageFlag3D::Array), UnsignedShort(ImageFlag2D::Array)); |
||||
} |
||||
|
||||
void ImageFlagsTest::debugFlag1D() { |
||||
std::ostringstream out; |
||||
/** @todo use a real flag once it exists */ |
||||
Debug{&out} << ImageFlag1D(0xcafe); |
||||
CORRADE_COMPARE(out.str(), "ImageFlag1D(0xcafe)\n"); |
||||
} |
||||
|
||||
void ImageFlagsTest::debugFlag2D() { |
||||
std::ostringstream out; |
||||
Debug{&out} << ImageFlag2D::Array << ImageFlag2D(0xcafe); |
||||
CORRADE_COMPARE(out.str(), "ImageFlag2D::Array ImageFlag2D(0xcafe)\n"); |
||||
} |
||||
|
||||
void ImageFlagsTest::debugFlag3D() { |
||||
std::ostringstream out; |
||||
Debug{&out} << ImageFlag3D::CubeMap << ImageFlag3D(0xcafe); |
||||
CORRADE_COMPARE(out.str(), "ImageFlag3D::CubeMap ImageFlag3D(0xcafe)\n"); |
||||
} |
||||
|
||||
void ImageFlagsTest::debugFlag1DPacked() { |
||||
std::ostringstream out; |
||||
/* Last is not packed, ones before should not make any flags persistent */ |
||||
/** @todo use real flags once they exist */ |
||||
Debug{&out} << Debug::packed << ImageFlag1D(0xcafe) << ImageFlag1D(0xbeef); |
||||
CORRADE_COMPARE(out.str(), "0xcafe ImageFlag1D(0xbeef)\n"); |
||||
} |
||||
|
||||
void ImageFlagsTest::debugFlag2DPacked() { |
||||
std::ostringstream out; |
||||
/* Last is not packed, ones before should not make any flags persistent */ |
||||
Debug{&out} << Debug::packed << ImageFlag2D::Array << Debug::packed << ImageFlag2D(0xcafe) << ImageFlag2D(0xbeef); |
||||
CORRADE_COMPARE(out.str(), "Array 0xcafe ImageFlag2D(0xbeef)\n"); |
||||
} |
||||
|
||||
void ImageFlagsTest::debugFlag3DPacked() { |
||||
std::ostringstream out; |
||||
/* Last is not packed, ones before should not make any flags persistent */ |
||||
Debug{&out} << Debug::packed << ImageFlag3D::CubeMap << Debug::packed << ImageFlag3D(0xcafe) << ImageFlag3D(0xbeef); |
||||
CORRADE_COMPARE(out.str(), "CubeMap 0xcafe ImageFlag3D(0xbeef)\n"); |
||||
} |
||||
|
||||
void ImageFlagsTest::debugFlags1D() { |
||||
std::ostringstream out; |
||||
/** @todo use real flags once they exist */ |
||||
Debug{&out} << (ImageFlag1D{}|ImageFlag1D(0xcafe)) << ImageFlags1D{}; |
||||
CORRADE_COMPARE(out.str(), "ImageFlag1D(0xcafe) ImageFlags1D{}\n"); |
||||
} |
||||
|
||||
void ImageFlagsTest::debugFlags2D() { |
||||
std::ostringstream out; |
||||
Debug{&out} << (ImageFlag2D::Array|ImageFlag2D(0xcafe)) << ImageFlags2D{}; |
||||
CORRADE_COMPARE(out.str(), "ImageFlag2D::Array|ImageFlag2D(0xcafe) ImageFlags2D{}\n"); |
||||
} |
||||
|
||||
void ImageFlagsTest::debugFlags3D() { |
||||
std::ostringstream out; |
||||
Debug{&out} << (ImageFlag3D::Array|ImageFlag3D::CubeMap |ImageFlag3D(0xcaf0)) << ImageFlags3D{}; |
||||
CORRADE_COMPARE(out.str(), "ImageFlag3D::Array|ImageFlag3D::CubeMap|ImageFlag3D(0xcaf0) ImageFlags3D{}\n"); |
||||
} |
||||
|
||||
void ImageFlagsTest::debugFlags1DPacked() { |
||||
std::ostringstream out; |
||||
/** @todo use real flags once they exist */ |
||||
Debug{&out} << Debug::packed << (ImageFlag1D{}|ImageFlag1D(0xcafe)) << Debug::packed << ImageFlags1D{} << ImageFlag1D(0xbeef); |
||||
CORRADE_COMPARE(out.str(), "0xcafe {} ImageFlag1D(0xbeef)\n"); |
||||
} |
||||
|
||||
void ImageFlagsTest::debugFlags2DPacked() { |
||||
std::ostringstream out; |
||||
Debug{&out} << Debug::packed << (ImageFlag2D::Array|ImageFlag2D(0xcaf0)) << Debug::packed << ImageFlags2D{} << ImageFlag2D(0xbeef); |
||||
CORRADE_COMPARE(out.str(), "Array|0xcaf0 {} ImageFlag2D(0xbeef)\n"); |
||||
} |
||||
|
||||
void ImageFlagsTest::debugFlags3DPacked() { |
||||
std::ostringstream out; |
||||
Debug{&out} << Debug::packed << (ImageFlag3D::Array|ImageFlag3D::CubeMap |ImageFlag3D(0xcaf0)) << Debug::packed << ImageFlags3D{} << ImageFlag3D(0xbeef); |
||||
CORRADE_COMPARE(out.str(), "Array|CubeMap|0xcaf0 {} ImageFlag3D(0xbeef)\n"); |
||||
} |
||||
|
||||
}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Test::ImageFlagsTest) |
||||
Loading…
Reference in new issue