/* This file is part of Magnum. Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 Vladimír Vondruš 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 "ImageView.h" #include "Magnum/PixelFormat.h" #include "Magnum/Implementation/ImageProperties.h" namespace Magnum { template ImageView::ImageView(const PixelStorage storage, const PixelFormat format, const VectorTypeFor& size, const Containers::ArrayView data, const ImageFlags flags) noexcept: ImageView{storage, format, {}, pixelFormatSize(format), size, data, flags} {} template ImageView::ImageView(const PixelStorage storage, const UnsignedInt format, const UnsignedInt formatExtra, const UnsignedInt pixelSize, const VectorTypeFor& size, const Containers::ArrayView data, const ImageFlags flags) noexcept: ImageView{storage, pixelFormatWrap(format), formatExtra, pixelSize, size, data, flags} {} template ImageView::ImageView(const PixelStorage storage, const PixelFormat format, const UnsignedInt formatExtra, const UnsignedInt pixelSize, const VectorTypeFor& size, const Containers::ArrayView data, const ImageFlags flags) noexcept: _storage{storage}, _format{format}, _formatExtra{formatExtra}, _pixelSize{pixelSize}, _flags{flags}, _size{size}, _data{reinterpret_cast(data.data()), data.size()} { #ifdef MAGNUM_BUILD_DEPRECATED #ifndef CORRADE_NO_ASSERT if(size.product() && !_data && !_data.size()) Warning{} << "ImageView: passing empty data to a non-empty view is deprecated, use a constructor without the data parameter instead"; #endif CORRADE_ASSERT(!_data || Implementation::imageDataSize(*this) <= _data.size(), "ImageView: data too small, got" << _data.size() << "but expected at least" << Implementation::imageDataSize(*this) << "bytes", ); #else CORRADE_ASSERT(Implementation::imageDataSize(*this) <= _data.size(), "ImageView: data too small, got" << _data.size() << "but expected at least" << Implementation::imageDataSize(*this) << "bytes", ); #endif #ifndef CORRADE_NO_ASSERT Implementation::checkImageFlagsForSize("ImageView:", flags, size); #endif } template ImageView::ImageView(const PixelStorage storage, const PixelFormat format, const VectorTypeFor& size, const ImageFlags flags) noexcept: ImageView{storage, format, {}, pixelFormatSize(format), size, flags} {} template ImageView::ImageView(const PixelStorage storage, const UnsignedInt format, const UnsignedInt formatExtra, const UnsignedInt pixelSize, const VectorTypeFor& size, const ImageFlags flags) noexcept: ImageView{storage, pixelFormatWrap(format), formatExtra, pixelSize, size, flags} {} template ImageView::ImageView(const PixelStorage storage, const PixelFormat format, const UnsignedInt formatExtra, const UnsignedInt pixelSize, const VectorTypeFor& size, const ImageFlags flags) noexcept: _storage{storage}, _format{format}, _formatExtra{formatExtra}, _pixelSize{pixelSize}, _flags{flags}, _size{size}, _data{nullptr} { #ifndef CORRADE_NO_ASSERT Implementation::checkImageFlagsForSize("ImageView:", flags, size); #endif } 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()}; } template auto ImageView::pixels() const -> Containers::StridedArrayView { if(!_data && !_data.size()) return {}; return Implementation::imagePixelView(*this, data()); } template CompressedImageView::CompressedImageView(const CompressedPixelStorage storage, const CompressedPixelFormat format, const VectorTypeFor& size, const Containers::ArrayView data, const ImageFlags flags) noexcept: _storage{storage}, _format{format}, _flags{flags}, _size{size}, _data{reinterpret_cast(data.data()), data.size()} { #ifndef CORRADE_NO_ASSERT Implementation::checkImageFlagsForSize("CompressedImageView:", flags, size); #endif } template CompressedImageView::CompressedImageView(const CompressedPixelStorage storage, const CompressedPixelFormat format, const VectorTypeFor& size, const ImageFlags flags) noexcept: _storage{storage}, _format{format}, _flags{flags}, _size{size} { #ifndef CORRADE_NO_ASSERT Implementation::checkImageFlagsForSize("CompressedImageView:", flags, size); #endif } template CompressedImageView::CompressedImageView(const CompressedPixelStorage storage, const UnsignedInt format, const VectorTypeFor& size, const Containers::ArrayView data, const ImageFlags flags) noexcept: CompressedImageView{storage, compressedPixelFormatWrap(format), size, data, flags} {} template CompressedImageView::CompressedImageView(const CompressedPixelStorage storage, const UnsignedInt format, const VectorTypeFor& size, const ImageFlags flags) noexcept: CompressedImageView{storage, compressedPixelFormatWrap(format), size, flags} {} 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>; template class MAGNUM_EXPORT ImageView<3, const char>; template class MAGNUM_EXPORT ImageView<1, char>; template class MAGNUM_EXPORT ImageView<2, char>; template class MAGNUM_EXPORT ImageView<3, char>; template class MAGNUM_EXPORT CompressedImageView<1, const char>; template class MAGNUM_EXPORT CompressedImageView<2, const char>; template class MAGNUM_EXPORT CompressedImageView<3, const char>; template class MAGNUM_EXPORT CompressedImageView<1, char>; template class MAGNUM_EXPORT CompressedImageView<2, char>; template class MAGNUM_EXPORT CompressedImageView<3, char>; #endif }