summaryrefslogtreecommitdiff
path: root/source/modules/asura-core/image/image_data.cpp
blob: b35c4b24359516a7b84b7764b70f65113ef5ad46 (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
#include "image_data.h"
#include "png_decoder.h"
#include "stb_decoder.h"
#include "image_decoder.h"

using namespace std;

using namespace AEGraphics;

namespace AsuraEngine
{
	namespace Image
	{

		// imagedecoderΪԡ
		list<ImageDecoder*> ImageData::ImageDecoders = {
			new PNGDecoder(), // png 
			new STBDecoder()  // jpeg, tga, bmp
		};

		ImageData::ImageData()
			: pixels(nullptr)
			, size(0)
			, width(0)
			, height(0)
			, format(COLOR_FORMAT_UNKNOWN)
		{
		}

		ImageData::~ImageData()
		{
			if (pixels)
				delete[] pixels;
		}

		void ImageData::Decode(IO::DataBuffer& buffer)
		{
			for (ImageDecoder* decoder : ImageDecoders)
			{
				if (decoder->CanDecode(buffer))
				{
					decoder->Decode(buffer, *this);
					return;
				}
			}
		}

		Color ImageData::GetPixel(uint x, uint y)
		{
			return Color();
		}

		void ImageData::Lock()
		{
			mMutex.Lock();
		}

		void ImageData::Unlock()
		{
			mMutex.Unlock();
		}
		
	}
}