blob: 057699469be79266335f868fe6e41582a7cfe80f (
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
{
Ported to FPC by Nikolay Nikolov (nickysn@users.sourceforge.net)
}
{
Console example for OpenPTC 1.0 C++ implementation
Copyright (c) Glenn Fiedler (ptc@gaffer.org)
This source code is in the public domain
}
program ConsoleExample;
{$MODE objfpc}
uses
ptc;
var
console: IPTCConsole;
palette: IPTCPalette;
data: array [0..255] of DWord;
i: Integer;
pixels: PByte;
width, height, pitch: Integer;
format: IPTCFormat;
bits, bytes: Integer;
x, y: Integer;
color: DWord;
pixel: PByte;
_data: PByte;
begin
try
try
{ create console }
console := TPTCConsoleFactory.CreateNew;
{ open the console with one page }
console.open('Console example', 1);
{ create palette }
palette := TPTCPaletteFactory.CreateNew;
{ generate palette }
for i := 0 to 255 do
data[i] := i;
{ load palette data }
palette.Load(data);
{ set console palette }
console.Palette(palette);
{ loop until a key is pressed }
while not console.KeyPressed do
begin
{ lock console }
pixels := console.Lock;
try
{ get console dimensions }
width := console.width;
height := console.height;
pitch := console.pitch;
{ get console format }
format := console.format;
{ get format information }
bits := format.bits;
bytes := format.bytes;
{ draw random pixels }
for i := 1 to 100 do
begin
{ get random position }
x := Random(width);
y := Random(height);
{ generate random color integer }
color := (DWord(Random(256)) shl 0) or
(DWord(Random(256)) shl 8) or
(DWord(Random(256)) shl 16) or
(DWord(Random(256)) shl 24);
{ calculate pointer to pixel [x,y] }
pixel := pixels + y * pitch + x * bytes;
{ check bits }
case bits of
{ 32 bits per pixel }
32: PDWord(pixel)^ := color;
24: begin
{ 24 bits per pixel }
_data := pixel;
_data[0] := (color and $000000FF) shr 0;
_data[1] := (color and $0000FF00) shr 8;
_data[2] := (color and $00FF0000) shr 16;
end;
{ 16 bits per pixel }
16: PWord(pixel)^ := color;
{ 8 bits per pixel }
8: PByte(pixel)^ := color;
end;
end;
finally
{ unlock console }
console.Unlock;
end;
{ update console }
console.Update;
end;
finally
if Assigned(console) then
console.Close;
end;
except
on error: TPTCError do
{ report error }
error.report;
end;
end.
|