From 64d9d7b3eb7cece81da8b2cb56eb0f50d87a5964 Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 1 Mar 2019 08:50:34 +0800 Subject: *misc --- Source/Asura.Engine/Graphics/ImageData.h | 58 ++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Source/Asura.Engine/Graphics/ImageData.h (limited to 'Source/Asura.Engine/Graphics/ImageData.h') diff --git a/Source/Asura.Engine/Graphics/ImageData.h b/Source/Asura.Engine/Graphics/ImageData.h new file mode 100644 index 0000000..925a5a0 --- /dev/null +++ b/Source/Asura.Engine/Graphics/ImageData.h @@ -0,0 +1,58 @@ +#ifndef __ASURA_ENGINE_IMAGEDATA_H__ +#define __ASURA_ENGINE_IMAGEDATA_H__ + +#include + +#include "Scripting/Luax.hpp" +#include "Filesystem/DecodedData.h" +#include "ImageDecoder.h" +#include "PixelFormat.h" +#include "Color.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + class ImageData final : public Filesystem::DecodedData, public Scripting::Portable + { + public: + + /// + /// 解析图片数据文件,并构建像素信息,如果解析失败,抛出异常 + /// + ImageData(const Filesystem::DataBuffer* buffer); + ~ImageData(); + + Color GetPixel(uint x, uint y); + + uint width, height; + PixelFormat format; + std::size_t size; + byte* pixels; + + //---------------------------------------------------------------------------------------------------------- + + LUAX_DECL_FACTORY(ImageData); + + LUAX_DECL_METHOD(l_GetPixel); + LUAX_DECL_METHOD(l_GetSize); + + //---------------------------------------------------------------------------------------------------------- + + private: + + // stb用来加载JPEG、TGA、BMP,lodePNG加载png图片 + void Decode(const Filesystem::DataBuffer* buffer) override; + + /// + /// 在第一次准备image data时构建所有提供的decoder。在几个decoders中间选择解析策略。 + /// + static std::list ImageDecoders; + + }; + + } +} + +#endif \ No newline at end of file -- cgit v1.1-26-g67d0