// Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors. // All rights reserved. // Code licensed under the BSD License. // http://www.anki3d.org/LICENSE #pragma once #include #include #include namespace anki { /// An image surface /// @memberof ImageLoader class ImageLoaderSurface { public: U32 m_width; U32 m_height; DynamicArray, PtrSize> m_data; ImageLoaderSurface(MemoryPoolPtrWrapper pool) : m_data(pool) { } }; /// An image volume /// @memberof ImageLoader class ImageLoaderVolume { public: U32 m_width; U32 m_height; U32 m_depth; DynamicArray, PtrSize> m_data; ImageLoaderVolume(MemoryPoolPtrWrapper pool) : m_data(pool) { } }; /// Loads bitmaps from regular system files or resource files. Supported formats are .tga and .ankitex. class ImageLoader { public: ImageLoader(BaseMemoryPool* pool) : m_surfaces(pool) , m_volumes(pool) { ANKI_ASSERT(pool); } ~ImageLoader() = default; ImageBinaryColorFormat getColorFormat() const { ANKI_ASSERT(m_colorFormat != ImageBinaryColorFormat::kNone); return m_colorFormat; } ImageBinaryDataCompression getCompression() const { ANKI_ASSERT(m_compression != ImageBinaryDataCompression::kNone); return m_compression; } U32 getMipmapCount() const { ANKI_ASSERT(m_mipmapCount != 0); return m_mipmapCount; } U32 getWidth() const { return m_width; } U32 getHeight() const { return m_height; } U32 getDepth() const { ANKI_ASSERT(m_imageType == ImageBinaryType::k3D); return m_depth; } U32 getLayerCount() const { ANKI_ASSERT(m_imageType == ImageBinaryType::k2DArray); return m_layerCount; } ImageBinaryType getImageType() const { ANKI_ASSERT(m_imageType != ImageBinaryType::kNone); return m_imageType; } UVec2 getAstcBlockSize() const { ANKI_ASSERT(!!(m_compression & ImageBinaryDataCompression::kAstc)); ANKI_ASSERT(m_astcBlockSize != UVec2(0u)); return m_astcBlockSize; } Vec4 getAverageColor() const { return m_avgColor; } const ImageLoaderSurface& getSurface(U32 level, U32 face, U32 layer) const; const ImageLoaderVolume& getVolume(U32 level) const; /// Load a resource image file. Error load(ResourceFilePtr file, const CString& filename, U32 maxImageSize = kMaxU32); /// Load a system image file. Error load(const CString& filename, U32 maxImageSize = kMaxU32); private: class FileInterface; class RsrcFile; class SystemFile; /// [mip][depth or face or layer]. Loader doesn't support cube arrays ATM so face and layer won't be used at the /// same time. DynamicArray> m_surfaces; DynamicArray> m_volumes; Vec4 m_avgColor = Vec4(0.0f); U32 m_mipmapCount = 0; U32 m_width = 0; U32 m_height = 0; U32 m_depth = 0; U32 m_layerCount = 0; UVec2 m_astcBlockSize = UVec2(0u); ImageBinaryDataCompression m_compression = ImageBinaryDataCompression::kNone; ImageBinaryColorFormat m_colorFormat = ImageBinaryColorFormat::kNone; ImageBinaryType m_imageType = ImageBinaryType::kNone; void destroy(); static Error loadStb(Bool isFloat, FileInterface& fs, U32& width, U32& height, DynamicArray, PtrSize>& data); static Error loadAnkiImage(FileInterface& file, U32 maxImageSize, ImageBinaryDataCompression& preferredCompression, DynamicArray>& surfaces, DynamicArray>& volumes, U32& width, U32& height, U32& depth, U32& layerCount, U32& mipCount, ImageBinaryType& imageType, ImageBinaryColorFormat& colorFormat, UVec2& astcBlockSize, Vec4& avgColor); Error loadInternal(FileInterface& file, const CString& filename, U32 maxImageSize); }; } // end namespace anki