summaryrefslogtreecommitdiff
path: root/source/modules/asura-core/graphics/image_data.h
blob: b9d656cfd42543210fea715f37974f6c669acac8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef __ASURA_ENGINE_IMAGEDATA_H__
#define __ASURA_ENGINE_IMAGEDATA_H__

#include <list>

#include <asura-utils/scripting/portable.hpp>
#include <asura-utils/io/decoded_data.h>
#include <asura-utils/io/data_buffer.h>
#include <asura-utils/threading/thread.h>
#include <asura-utils/threading/mutex.h>

#include "texture.h"
#include "color.h"

namespace AsuraEngine
{
	namespace Graphics
	{

		class ImageDecoder;

		class ImageData ASURA_FINAL
			: public AEIO::DecodedData
			, public Scripting::Portable<ImageData>
		{
		public:

			LUAX_DECL_FACTORY(ImageData);

			///
			/// ͼƬļϢʧܣ׳쳣
			///
			ImageData();
			~ImageData();

			void Decode(AEIO::DataBuffer& buffer) override;

			void Lock();
			void Unlock();

			Color GetPixel(uint x, uint y);

			//----------------------------------------------------------------------------//

			uint width, height; // سߴ
			ColorFormat format; // ʽ
			byte* pixels;       // 
			std::size_t size;   // ݳ

			//----------------------------------------------------------------------------//

		private:

			//----------------------------------------------------------------------------//

			LUAX_DECL_METHOD(_New);
			LUAX_DECL_METHOD(_GetPixel);
			LUAX_DECL_METHOD(_GetSize);
			LUAX_DECL_METHOD(_GetWidth);
			LUAX_DECL_METHOD(_GetHeight);
			LUAX_DECL_METHOD(_GetPixelFormat);
			LUAX_DECL_METHOD(_Decode);
			LUAX_DECL_METHOD(_DecodeAsync);
			LUAX_DECL_METHOD(_IsAvailable);

			//----------------------------------------------------------------------------//

			///
			/// ڵһ׼image dataʱṩdecoderڼdecodersмѡԡ
			///
			static std::list<ImageDecoder*> ImageDecoders;

			///
			/// дݵ
			///
			AEThreading::Mutex mMutex;

		};

	}
}

namespace AEGraphics = AsuraEngine::Graphics;

#endif