-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUBITMAP8.PAS
95 lines (77 loc) · 2 KB
/
UBITMAP8.PAS
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
90
91
92
93
94
95
{
UBitmap8 Unit
An 8-bit indexed color implementation of a bitmap
2022 LRT
}
unit
ubitmap8;
interface
uses
uexc, uclasses, types, locale, uobject, ubitmap, math;
type
PBitmap8 = ^TBitmap8;
TBitmap8 = object (TBitmap)
public
constructor initWithSize(width, height: word);
destructor done; virtual;
procedure setPixel(x, y: word; color: TColor); virtual;
function getPixel(x, y: word): TColor; virtual;
procedure clear(color: TColor); virtual;
function getColorCount: longint; virtual;
function getBitsPerPixel: byte; virtual;
function getRawPixels: pointer; virtual;
function getClassName: string; virtual;
function getClassId: word; virtual;
private
_pixels: pbyte;
_size: longint;
end;
implementation
{ TBitmap8 public }
constructor TBitmap8.initWithSize(width, height: word);
begin
inherited initWithSize(width, height);
_size := width * height;
GetMem(_pixels, _size);
clear(0);
end;
destructor TBitmap8.done;
begin
FreeMem(_pixels, _size);
inherited done;
end;
procedure TBitmap8.setPixel(x, y: word; color: TColor);
begin
pbyte(incptr(_pixels, x + y * getWidth))^ := color;
end;
function TBitmap8.getPixel(x, y: word): TColor;
begin
getPixel := pbyte(incptr(_pixels, x + y * getWidth))^;
end;
procedure TBitmap8.clear(color: TColor);
begin
fillchar(_pixels^, _size, color);
end;
function TBitmap8.getColorCount: longint;
begin
getColorCount := 256;
end;
function TBitmap8.getBitsPerPixel: byte;
begin
getBitsPerPixel := 8;
end;
function TBitmap8.getRawPixels: pointer;
begin
getRawPixels := _pixels;
end;
function TBitmap8.getClassName: string;
begin
getClassName := 'TBitmap8';
end;
function TBitmap8.getClassId: word;
begin
getClassId := C_CLASS_ID_Bitmap8;
end;
{ TBitmap8 private }
{ Other }
end.