-
Notifications
You must be signed in to change notification settings - Fork 1
/
bimage.cpp
62 lines (56 loc) · 1.52 KB
/
bimage.cpp
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
#include "bimage.h"
Image::Image(ImageFileLoader * file_cache_id_)
: fileLoader(file_cache_id_)
{
IsCached(false);
}
Image::~Image() {
DeleteFromCache();
if (fileLoader != 0) {
delete fileLoader;
fileLoader = 0;
}
}
const RGBA Image::GetPixel(int row, int col) {
int dataIndex = row * GetWidth()*sizeof(RGBA) + col * sizeof(RGBA);
return *(reinterpret_cast<RGBA *>(((ImageData.GetAllocatedMemory()).get()) + dataIndex));
}
void Image::LoadIntoCache() {
if (!IsCached()) {
std::cout << "ImageLoadIntoCache" << std::endl;
fileLoader->Decode(this);
IsCached(true);
}
}
void Image::DeleteFromCache() {
ImageData.FreeAllocatedMemory();
IsCached(false);
}
void Image::SetImageInfo(const ImageInfo &imageInfo) {
this->imageInfo = imageInfo;
}
const int Image::GetWidth() const {
return imageInfo.width;
}
const int Image::GetHeight() const {
return imageInfo.height;
}
const int Image::GetBitCount() const {
return imageInfo.bitCount;
}
const int Image::GetPixelSize() const {
return imageInfo.pixelSize;
}
const int Image::GetPixelFormat() const {
return imageInfo.pixelFormat;
}
void Image::AllocateMemmory() {
ImageData.AllocateDataMemory(imageInfo.imageSize);
}
Image * Image::Clone() {
Image * image = new Image(0);
image->SetImageInfo(imageInfo);
image->AllocateMemmory();
std::memcpy(image->ImageData.GetAllocatedMemory().get(), ImageData.GetAllocatedMemory().get(), ImageData.GetAllocatedDataSize());
return image;
}