-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMemoryCancans.h
More file actions
89 lines (88 loc) · 2.54 KB
/
Copy pathCMemoryCancans.h
File metadata and controls
89 lines (88 loc) · 2.54 KB
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
86
87
88
89
/******************************************************************************************************
Dream2d is 2d game engine written by Changer.
Copyright (C) Changer Stdio.
This program is free software;
you can redistribute it and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
******************************************************************************************************/
#ifndef __D_DREAM2D_CMEMORYCANVANS
#define __D_DREAM2D_CMEMORYCANVANS
#include "ICanvans.h"
class CMemoryCanvans :public ICanvans {
public:
CMemoryCanvans(s32 uWidth,s32 uHeight,COLOR_FORMAT f):ICanvans(f) {
int bitCount;
switch(f) {
case COLOR_A8R8G8B8:
bitCount = 32;
break;
case COLOR_INDEX8:
bitCount = 8;
break;
case COLOR_R8G8B8:
bitCount = 24;
break;
case COLOR_A1R5G5B5:
case COLOR_R5G6B5:
bitCount = 16;
break;
}
m_pitch = ((uWidth*bitCount +31)>>5)<<2;
m_Width = uWidth;
m_Height = uHeight;
m_pallet = NULL;
m_buffer = new u8[m_pitch*uHeight];
if(bitCount == 8) {
m_pallet = new u32[256];
}
}
virtual ~CMemoryCanvans() {
if(m_buffer) {
delete[] m_buffer;
m_buffer = NULL;
}
if(m_pallet) {
delete[] m_pallet;
m_pallet = NULL;
}
}
u8* lock() {
return m_buffer;
}
void unlock() {
}
CANVANS_TYPE getCanvansType() const {
return CANVANS_MEMORY;
}
u32* getPallet() const{
return m_pallet;
}
u32 LoadColorKey(s32 xPos,s32 yPos) {
if (m_buffer == NULL)
{
m_colorkey = 0;
}else {
switch(ICanvans::m_Format) {
case COLOR_A8R8G8B8:
m_colorkey = *(u32*)(m_buffer + yPos*m_pitch + xPos*4);
break;
case COLOR_R8G8B8:
m_colorkey = *(m_buffer + yPos*m_pitch + xPos*3) + ((*(m_buffer + yPos*m_pitch + xPos*3+1))<<8) +((*(m_buffer + yPos*m_pitch + xPos*3+2))<<16);
break;
default:
m_colorkey = 0;
}
}
return m_colorkey;
}
private:
u8* m_buffer;
u32* m_pallet;
};
#endif