Browse Source

Order *Image*D raw data accessors before all format-dependent accessors.

For consistency with Trade::MeshData, MaterialData and SceneData, where
the raw data access is also separated from the formatted access.
pull/680/head
Vladimír Vondruš 10 months ago
parent
commit
cda1da17b0
  1. 132
      src/Magnum/GL/BufferImage.h
  2. 108
      src/Magnum/Image.h
  3. 52
      src/Magnum/ImageView.h
  4. 90
      src/Magnum/Trade/ImageData.h

132
src/Magnum/GL/BufferImage.h

@ -272,32 +272,6 @@ template<UnsignedInt dimensions> class BufferImage {
/** @brief Move assignment */
BufferImage<dimensions>& operator=(BufferImage<dimensions>&& other) noexcept;
/** @brief Storage of pixel data */
PixelStorage storage() const { return _storage; }
/** @brief Format of pixel data */
PixelFormat format() const { return _format; }
/** @brief Data type of pixel data */
PixelType type() const { return _type; }
/**
* @brief Size of a pixel in bytes
*
* @see @ref Magnum::pixelFormatSize(), @ref GL::pixelFormatSize()
*/
UnsignedInt pixelSize() const { return _pixelSize; }
/** @brief Image size in pixels */
VectorTypeFor<Dimensions, Int> size() const { return _size; }
/**
* @brief Image data properties
*
* See @ref PixelStorage::dataProperties() for more information.
*/
std::pair<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>> dataProperties() const;
/** @brief Currently allocated data size */
std::size_t dataSize() const { return _dataSize; }
@ -359,6 +333,32 @@ template<UnsignedInt dimensions> class BufferImage {
setData({}, format, size, data, usage);
}
/** @brief Storage of pixel data */
PixelStorage storage() const { return _storage; }
/** @brief Format of pixel data */
PixelFormat format() const { return _format; }
/** @brief Data type of pixel data */
PixelType type() const { return _type; }
/**
* @brief Size of a pixel in bytes
*
* @see @ref Magnum::pixelFormatSize(), @ref GL::pixelFormatSize()
*/
UnsignedInt pixelSize() const { return _pixelSize; }
/** @brief Image size in pixels */
VectorTypeFor<Dimensions, Int> size() const { return _size; }
/**
* @brief Image data properties
*
* See @ref PixelStorage::dataProperties() for more information.
*/
std::pair<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>> dataProperties() const;
/**
* @brief Release the image buffer
*
@ -618,46 +618,6 @@ template<UnsignedInt dimensions> class CompressedBufferImage {
/** @brief Move assignment */
CompressedBufferImage<dimensions>& operator=(CompressedBufferImage<dimensions>&& other) noexcept;
/** @brief Storage of compressed pixel data */
CompressedPixelStorage storage() const { return _storage; }
/** @brief Format of compressed pixel data */
CompressedPixelFormat format() const { return _format; }
/**
* @brief Size of a compressed block in pixels
* @m_since_latest
*
* Note that the blocks can be 3D even for 2D images and 2D or 3D even
* for 1D images, in which case only the first slice in the extra
* dimensions is used.
* @see @ref blockDataSize(), @ref compressedPixelFormatBlockSize()
*/
Vector3i blockSize() const { return Vector3i{_blockSize}; }
/**
* @brief Size of a compressed block in bytes
* @m_since_latest
*
* @see @ref blockSize(), @ref compressedPixelFormatBlockDataSize()
*/
UnsignedInt blockDataSize() const { return _blockDataSize; }
/** @brief Image size */
VectorTypeFor<Dimensions, Int> size() const { return _size; }
/**
* @brief Compressed image data properties
*
* See @ref CompressedPixelStorage::dataProperties() for more
* information.
* @requires_gl42 Extension @gl_extension{ARB,compressed_texture_pixel_storage}
* for non-default @ref CompressedPixelStorage
* @requires_gl Non-default @ref CompressedPixelStorage is not
* available in OpenGL ES and WebGL.
*/
std::pair<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>> dataProperties() const;
/**
* @brief Image buffer
*
@ -729,6 +689,46 @@ template<UnsignedInt dimensions> class CompressedBufferImage {
setData({}, format, size, data, usage);
}
/** @brief Storage of compressed pixel data */
CompressedPixelStorage storage() const { return _storage; }
/** @brief Format of compressed pixel data */
CompressedPixelFormat format() const { return _format; }
/**
* @brief Size of a compressed block in pixels
* @m_since_latest
*
* Note that the blocks can be 3D even for 2D images and 2D or 3D even
* for 1D images, in which case only the first slice in the extra
* dimensions is used.
* @see @ref blockDataSize(), @ref compressedPixelFormatBlockSize()
*/
Vector3i blockSize() const { return Vector3i{_blockSize}; }
/**
* @brief Size of a compressed block in bytes
* @m_since_latest
*
* @see @ref blockSize(), @ref compressedPixelFormatBlockDataSize()
*/
UnsignedInt blockDataSize() const { return _blockDataSize; }
/** @brief Image size */
VectorTypeFor<Dimensions, Int> size() const { return _size; }
/**
* @brief Compressed image data properties
*
* See @ref CompressedPixelStorage::dataProperties() for more
* information.
* @requires_gl42 Extension @gl_extension{ARB,compressed_texture_pixel_storage}
* for non-default @ref CompressedPixelStorage
* @requires_gl Non-default @ref CompressedPixelStorage is not
* available in OpenGL ES and WebGL.
*/
std::pair<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>> dataProperties() const;
/**
* @brief Release the image buffer
*

108
src/Magnum/Image.h

@ -391,6 +391,33 @@ template<UnsignedInt dimensions> class Image {
*/
ImageFlags<dimensions> flags() const { return _flags; }
/**
* @brief Raw image data
*
* @see @ref release(), @ref pixels()
*/
Containers::ArrayView<char> data() & { return _data; }
/** @overload */
Containers::ArrayView<const char> data() const & { return _data; }
/**
* @brief Raw image data from a r-value
* @m_since{2019,10}
*
* Unlike @ref data(), which returns a view, this is equivalent to
* @ref release() to avoid a dangling view when the temporary instance
* goes out of scope.
* @todoc stupid doxygen can't link to & overloads ffs
*/
Containers::Array<char> data() && { return release(); }
/** @overload
* @m_since{2019,10}
* @todo what to do here?!
*/
Containers::Array<char> data() const && = delete;
/** @brief Storage of pixel data */
PixelStorage storage() const { return _storage; }
@ -435,33 +462,6 @@ template<UnsignedInt dimensions> class Image {
*/
std::pair<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>> dataProperties() const;
/**
* @brief Raw image data
*
* @see @ref release(), @ref pixels()
*/
Containers::ArrayView<char> data() & { return _data; }
/** @overload */
Containers::ArrayView<const char> data() const & { return _data; }
/**
* @brief Raw image data from a r-value
* @m_since{2019,10}
*
* Unlike @ref data(), which returns a view, this is equivalent to
* @ref release() to avoid a dangling view when the temporary instance
* goes out of scope.
* @todoc stupid doxygen can't link to & overloads ffs
*/
Containers::Array<char> data() && { return release(); }
/** @overload
* @m_since{2019,10}
* @todo what to do here?!
*/
Containers::Array<char> data() const && = delete;
/**
* @brief Pixel data
* @m_since{2019,10}
@ -730,6 +730,33 @@ template<UnsignedInt dimensions> class CompressedImage {
*/
ImageFlags<dimensions> flags() const { return _flags; }
/**
* @brief Raw image data
*
* @see @ref release()
*/
Containers::ArrayView<char> data() & { return _data; }
/** @overload */
Containers::ArrayView<const char> data() const & { return _data; }
/**
* @brief Raw image data from a r-value
* @m_since{2019,10}
*
* Unlike @ref data(), which returns a view, this is equivalent to
* @ref release() to avoid a dangling view when the temporary instance
* goes out of scope.
* @todoc stupid doxygen can't link to & overloads ffs
*/
Containers::Array<char> data() && { return release(); }
/** @overload
* @m_since{2019,10}
* @todo what to do here?!
*/
Containers::Array<char> data() const && = delete;
/** @brief Storage of compressed pixel data */
CompressedPixelStorage storage() const { return _storage; }
@ -777,33 +804,6 @@ template<UnsignedInt dimensions> class CompressedImage {
*/
std::pair<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>> dataProperties() const;
/**
* @brief Raw image data
*
* @see @ref release()
*/
Containers::ArrayView<char> data() & { return _data; }
/** @overload */
Containers::ArrayView<const char> data() const & { return _data; }
/**
* @brief Raw image data from a r-value
* @m_since{2019,10}
*
* Unlike @ref data(), which returns a view, this is equivalent to
* @ref release() to avoid a dangling view when the temporary instance
* goes out of scope.
* @todoc stupid doxygen can't link to & overloads ffs
*/
Containers::Array<char> data() && { return release(); }
/** @overload
* @m_since{2019,10}
* @todo what to do here?!
*/
Containers::Array<char> data() const && = delete;
/**
* @brief Release data storage
*

52
src/Magnum/ImageView.h

@ -446,6 +446,21 @@ template<UnsignedInt dimensions, class T> class ImageView {
*/
ImageFlags<dimensions> flags() const { return _flags; }
/**
* @brief Raw image data
*
* @see @ref pixels()
*/
Containers::ArrayView<Type> data() const { return _data; }
/**
* @brief Set image data
*
* The data array is expected to be of proper size for parameters
* specified in the constructor.
*/
void setData(Containers::ArrayView<ErasedType> data);
/** @brief Storage of pixel data */
PixelStorage storage() const { return _storage; }
@ -490,21 +505,6 @@ template<UnsignedInt dimensions, class T> class ImageView {
*/
std::pair<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>> dataProperties() const;
/**
* @brief Raw image data
*
* @see @ref pixels()
*/
Containers::ArrayView<Type> data() const { return _data; }
/**
* @brief Set image data
*
* The data array is expected to be of proper size for parameters
* specified in the constructor.
*/
void setData(Containers::ArrayView<ErasedType> data);
/**
* @brief Pixel data
* @m_since{2019,10}
@ -972,6 +972,17 @@ template<UnsignedInt dimensions, class T> class CompressedImageView {
*/
ImageFlags<dimensions> flags() const { return _flags; }
/** @brief Raw image data */
Containers::ArrayView<Type> data() const { return _data; }
/**
* @brief Set image data
*
* The data array is expected to be of proper size for parameters
* specified in the constructor.
*/
void setData(Containers::ArrayView<ErasedType> data);
/** @brief Storage of compressed pixel data */
CompressedPixelStorage storage() const { return _storage; }
@ -1019,17 +1030,6 @@ template<UnsignedInt dimensions, class T> class CompressedImageView {
*/
std::pair<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>> dataProperties() const;
/** @brief Raw image data */
Containers::ArrayView<Type> data() const { return _data; }
/**
* @brief Set image data
*
* The data array is expected to be of proper size for parameters
* specified in the constructor.
*/
void setData(Containers::ArrayView<ErasedType> data);
private:
/* Needed for mutable->const conversion */
template<UnsignedInt, class> friend class CompressedImageView;

90
src/Magnum/Trade/ImageData.h

@ -734,15 +734,6 @@ template<UnsignedInt dimensions> class ImageData {
/** @brief Move assignment */
ImageData<dimensions>& operator=(ImageData<dimensions>&& other) noexcept;
/**
* @brief Data flags
* @m_since{2020,06}
*/
DataFlags dataFlags() const { return _dataFlags; }
/** @brief Whether the image is compressed */
bool isCompressed() const { return _compressed; }
/**
* @brief Conversion to a view
*
@ -781,12 +772,57 @@ template<UnsignedInt dimensions> class ImageData {
*/
/*implicit*/ operator BasicMutableCompressedImageView<dimensions>();
/**
* @brief Data flags
* @m_since{2020,06}
*/
DataFlags dataFlags() const { return _dataFlags; }
/**
* @brief Layout flags
* @m_since_latest
*/
ImageFlags<dimensions> flags() const { return _flags; }
/**
* @brief Raw image data
*
* @see @ref release(), @ref pixels()
*/
Containers::ArrayView<const char> data() const & { return _data; }
/**
* @brief Image data from a r-value
* @m_since{2019,10}
*
* Unlike @ref data(), which returns a view, this is equivalent to
* @ref release() to avoid a dangling view when the temporary instance
* goes out of scope. Note that the returned array has a custom no-op
* deleter when the data are not owned by the image, and while the
* returned array type is mutable, the actual memory might be not.
* @todoc stupid doxygen can't link to & overloads ffs
*/
Containers::Array<char> data() && { return release(); }
/** @overload
* @m_since{2019,10}
* @todo what to do here?!
*/
Containers::Array<char> data() const && = delete;
/**
* @brief Mutable image data
* @m_since{2020,06}
*
* Like @ref data(), but returns a non-const view. Expects that the
* image is mutable.
* @see @ref dataFlags()
*/
Containers::ArrayView<char> mutableData() &;
/** @brief Whether the image is compressed */
bool isCompressed() const { return _compressed; }
/**
* @brief Storage of pixel data
*
@ -899,42 +935,6 @@ template<UnsignedInt dimensions> class ImageData {
*/
std::pair<VectorTypeFor<dimensions, std::size_t>, VectorTypeFor<dimensions, std::size_t>> compressedDataProperties() const;
/**
* @brief Raw image data
*
* @see @ref release(), @ref pixels()
*/
Containers::ArrayView<const char> data() const & { return _data; }
/**
* @brief Image data from a r-value
* @m_since{2019,10}
*
* Unlike @ref data(), which returns a view, this is equivalent to
* @ref release() to avoid a dangling view when the temporary instance
* goes out of scope. Note that the returned array has a custom no-op
* deleter when the data are not owned by the image, and while the
* returned array type is mutable, the actual memory might be not.
* @todoc stupid doxygen can't link to & overloads ffs
*/
Containers::Array<char> data() && { return release(); }
/** @overload
* @m_since{2019,10}
* @todo what to do here?!
*/
Containers::Array<char> data() const && = delete;
/**
* @brief Mutable image data
* @m_since{2020,06}
*
* Like @ref data(), but returns a non-const view. Expects that the
* image is mutable.
* @see @ref dataFlags()
*/
Containers::ArrayView<char> mutableData() &;
/**
* @brief Pixel data
* @m_since{2019,10}

Loading…
Cancel
Save