Utility: Add ImageStream and GIF support

This commit is contained in:
SirLynix
2022-04-09 18:22:13 +02:00
committed by Jérôme Leclercq
parent 3d15f3578b
commit 2a091d25b7
7 changed files with 829 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_UTILITY_IMAGESTREAM_HPP
#define NAZARA_UTILITY_IMAGESTREAM_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Core/ResourceParameters.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <mutex>
namespace Nz
{
struct ImageStreamParams : public ResourceParameters
{
bool IsValid() const;
};
class Mutex;
class ImageStream;
using ImageStreamLoader = ResourceLoader<ImageStream, ImageStreamParams>;
class NAZARA_UTILITY_API ImageStream : public Resource
{
public:
ImageStream() = default;
virtual ~ImageStream();
virtual bool DecodeNextFrame(void* buffer) = 0;
virtual UInt64 GetFrameCount() const = 0;
virtual UInt64 GetFrameDelay(std::size_t frameIndex) const = 0;
virtual PixelFormat GetPixelFormat() const = 0;
virtual Vector2ui GetSize() const = 0;
virtual bool HasConstantRate() const = 0;
virtual void Seek(UInt64 frameIndex) = 0;
virtual UInt64 Tell() = 0;
static std::shared_ptr<ImageStream> OpenFromFile(const std::filesystem::path& filePath, const ImageStreamParams& params = ImageStreamParams());
static std::shared_ptr<ImageStream> OpenFromMemory(const void* data, std::size_t size, const ImageStreamParams& params = ImageStreamParams());
static std::shared_ptr<ImageStream> OpenFromStream(Stream& stream, const ImageStreamParams& params = ImageStreamParams());
};
}
#include <Nazara/Utility/ImageStream.inl>
#endif // NAZARA_UTILITY_IMAGESTREAM_HPP

View File

@@ -0,0 +1,12 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Utility/ImageStream.hpp>
#include <Nazara/Utility/Debug.hpp>
namespace Nz
{
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -13,6 +13,7 @@
#include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Font.hpp>
#include <Nazara/Utility/Image.hpp>
#include <Nazara/Utility/ImageStream.hpp>
#include <Nazara/Utility/Mesh.hpp>
namespace Nz
@@ -39,6 +40,8 @@ namespace Nz
const ImageLoader& GetImageLoader() const;
ImageSaver& GetImageSaver();
const ImageSaver& GetImageSaver() const;
ImageStreamLoader& GetImageStreamLoader();
const ImageStreamLoader& GetImageStreamLoader() const;
MeshLoader& GetMeshLoader();
const MeshLoader& GetMeshLoader() const;
MeshSaver& GetMeshSaver();
@@ -52,6 +55,7 @@ namespace Nz
FontLoader m_fontLoader;
ImageLoader m_imageLoader;
ImageSaver m_imageSaver;
ImageStreamLoader m_imageStreamLoader;
MeshLoader m_meshLoader;
MeshSaver m_meshSaver;