// Copyright (C) 2009-2021, 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 m_data; }; /// An image volume /// @memberof ImageLoader class ImageLoaderVolume { public: U32 m_width; U32 m_height; U32 m_depth; DynamicArray m_data; }; /// Loads bitmaps from regular system files or resource files. Supported formats are .tga and .ankitex. class ImageLoader { public: ImageLoader(GenericMemoryPoolAllocator alloc) : m_alloc(alloc) { } ~ImageLoader() { destroy(); } ImageBinaryColorFormat getColorFormat() const { ANKI_ASSERT(m_colorFormat != ImageBinaryColorFormat::NONE); return m_colorFormat; } ImageBinaryDataCompression getCompression() const { ANKI_ASSERT(m_compression != ImageBinaryDataCompression::NONE); 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::_3D); return m_depth; } U32 getLayerCount() const { ANKI_ASSERT(m_imageType == ImageBinaryType::_2D_ARRAY); return m_layerCount; } ImageBinaryType getImageType() const { ANKI_ASSERT(m_imageType != ImageBinaryType::NONE); return m_imageType; } UVec2 getAstcBlockSize() const { ANKI_ASSERT(!!(m_compression & ImageBinaryDataCompression::ASTC)); ANKI_ASSERT(m_astcBlockSize != UVec2(0u)); return m_astcBlockSize; } const ImageLoaderSurface& getSurface(U32 level, U32 face, U32 layer) const; const ImageLoaderVolume& getVolume(U32 level) const; /// Load a resource image file. ANKI_USE_RESULT Error load(ResourceFilePtr file, const CString& filename, U32 maxImageSize = MAX_U32); /// Load a system image file. ANKI_USE_RESULT Error load(const CString& filename, U32 maxImageSize = MAX_U32); private: class FileInterface; class RsrcFile; class SystemFile; GenericMemoryPoolAllocator m_alloc; /// [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; 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::NONE; ImageBinaryColorFormat m_colorFormat = ImageBinaryColorFormat::NONE; ImageBinaryType m_imageType = ImageBinaryType::NONE; void destroy(); static ANKI_USE_RESULT Error loadUncompressedTga(FileInterface& fs, U32& width, U32& height, U32& bpp, DynamicArray& data, GenericMemoryPoolAllocator& alloc); static ANKI_USE_RESULT Error loadCompressedTga(FileInterface& fs, U32& width, U32& height, U32& bpp, DynamicArray& data, GenericMemoryPoolAllocator& alloc); static ANKI_USE_RESULT Error loadTga(FileInterface& fs, U32& width, U32& height, U32& bpp, DynamicArray& data, GenericMemoryPoolAllocator& alloc); static ANKI_USE_RESULT Error loadStb(FileInterface& fs, U32& width, U32& height, DynamicArray& data, GenericMemoryPoolAllocator& alloc); static ANKI_USE_RESULT Error loadAnkiImage(FileInterface& file, U32 maxImageSize, ImageBinaryDataCompression& preferredCompression, DynamicArray& surfaces, DynamicArray& volumes, GenericMemoryPoolAllocator& alloc, U32& width, U32& height, U32& depth, U32& layerCount, U32& mipCount, ImageBinaryType& imageType, ImageBinaryColorFormat& colorFormat, UVec2& astcBlockSize); ANKI_USE_RESULT Error loadInternal(FileInterface& file, const CString& filename, U32 maxImageSize); }; } // end namespace anki