From 250e30d73f09e9da2b5a81d0fbae63744ae12a73 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 2 Apr 2019 08:47:15 +0800 Subject: *misc --- source/libs/asura-lib-core/graphics/image_data.h | 68 ++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 source/libs/asura-lib-core/graphics/image_data.h (limited to 'source/libs/asura-lib-core/graphics/image_data.h') diff --git a/source/libs/asura-lib-core/graphics/image_data.h b/source/libs/asura-lib-core/graphics/image_data.h new file mode 100644 index 0000000..820e276 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/image_data.h @@ -0,0 +1,68 @@ +#ifndef __ASURA_ENGINE_IMAGEDATA_H__ +#define __ASURA_ENGINE_IMAGEDATA_H__ + +#include + +#include +#include +#include +#include + +#include "pixel_format.h" +#include "color.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + class ImageDecoder; + + class ImageData ASURA_FINAL + : public AEIO::DecodedData + , public Scripting::Portable + { + public: + + LUAX_DECL_FACTORY(ImageData); + + /// + /// 解析图片数据文件,并构建像素信息,如果解析失败,抛出异常 + /// + ImageData(const AEIO::DataBuffer& buffer); + ~ImageData(); + + void Load(const AEIO::DataBuffer& buffer); + void LoadAsync(const AEIO::DataBuffer& buffer, AEThreading::Thread* thread); + + Color GetPixel(uint x, uint y); + + uint width, height; + PixelFormat format; + std::size_t size; + byte* pixels; + + private: + + void Decode(const AEIO::DataBuffer& buffer) override; + + /// + /// 在第一次准备image data时构建所有提供的decoder。在几个decoders中间选择解析策略。 + /// + static std::list ImageDecoders; + + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_GetPixel); + LUAX_DECL_METHOD(_GetSize); + LUAX_DECL_METHOD(_GetWidth); + LUAX_DECL_METHOD(_GetHeight); + LUAX_DECL_METHOD(_GetPixelFormat); + + }; + + } +} + +namespace AEGraphics = AsuraEngine::Graphics; + +#endif \ No newline at end of file -- cgit v1.1-26-g67d0