summaryrefslogtreecommitdiff
path: root/packages/hermes/src/p_clr.inc
blob: 6e24f0398d80ebee66959c5c40b5c0041a07975c (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
{
    Free Pascal port of the Hermes C library.
    Copyright (C) 2001-2003  Nikolay Nikolov (nickysn@users.sourceforge.net)
    Original C version by Christian Nentwich (c.nentwich@cs.ucl.ac.uk)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library 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
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
}

{
   C surface clearing routines for the HERMES library
   Copyright (c) 1998 Christian Nentwich (c.nentwich@cs.ucl.ac.uk)
   This source code is licensed under the GNU LGPL

   Please refer to the file COPYING.LIB contained in the distribution for
   licensing conditions
}

Procedure ClearP_32(iface : PHermesClearInterface); CDecl;

Var
  count : DWord;
  value : int32;
  dest : Pchar8;

Begin
  value := iface^.value;
  dest := iface^.dest;
  Repeat
    count := iface^.width;
    Repeat
      Pint32(dest)^ := value;
      Inc(dest, 4);
      Dec(count);
    Until count = 0;
    Inc(dest, iface^.add);
    Dec(iface^.height);
  Until iface^.height = 0;
End;

Procedure ClearP_24(iface : PHermesClearInterface); CDecl;

Var
  p_value : Pchar8;
  count : DWord;
  dest : Pchar8;

Begin
  p_value := @iface^.value;
  dest := iface^.dest;
  Repeat
    count := iface^.width;
    Repeat
      (dest + R_24)^ := (p_value + B_32)^;
      (dest + G_24)^ := (p_value + G_32)^;
      (dest + B_24)^ := (p_value + B_32)^;

      Inc(dest, 3);
      Dec(count);
    Until count = 0;

    Inc(dest, iface^.add);
    Dec(iface^.height);
  Until iface^.height = 0;
End;

Procedure ClearP_16(iface : PHermesClearInterface); CDecl;

Var
  value32 : DWord;
  countshifted, count : DWord;
  dest : Pchar8;

Begin
  value32 := (iface^.value Shl 16) Or (iface^.value And $ffff);
  dest := iface^.dest;
  Repeat
    count := iface^.width;

    { Align destination }
    If (PtrUInt(dest) And $3) <> 0 Then
    Begin
      Pshort16(dest)^ := iface^.value;
      Inc(dest, 2);
      Dec(count);
    End;

    countshifted := count Shr 1;

    While countshifted <> 0 Do
    Begin
      Dec(countshifted);
      Pint32(dest)^ := value32;
      Inc(dest, 4);
    End;

    If (count And 1) <> 0 Then
    Begin
      Pshort16(dest)^ := iface^.value;
      Inc(dest, 2);
    End;

    Inc(dest, iface^.add);
    Dec(iface^.height);
  Until iface^.height = 0;
End;

{$GOTO ON}

Procedure ClearP_8(iface : PHermesClearInterface); CDecl;

Label
  yloop;

Var
  count, shiftcount : DWord;
  value32 : int32;
  value : char8;
  dest : Pchar8;

Begin
  dest := iface^.dest;

  value := iface^.value And $ff;
  value32 := (value Shl 24) Or (value Shl 16) Or (value Shl 8) Or value;

  Repeat
    count := iface^.width;

    While (PtrUInt(dest) And $3) <> 0 Do    { Align to dword boundary }
    Begin
      dest^ := value;
      Inc(dest);
      Dec(count);
      If count = 0 Then
        Goto yloop;                { GOTO's are nice ;) }
    End;

    shiftcount := count Shr 2;

    While shiftcount <> 0 Do
    Begin
      Dec(shiftcount);
      Pint32(dest)^ := value32;
      Inc(dest, 4);
    End;

    count := count And $3;
    While count <> 0 Do
    Begin
      Dec(count);
      dest^ := value;
      Inc(dest);
    End;

yloop:
    Inc(dest, iface^.add);
    Dec(iface^.height);
  Until iface^.height = 0;
End;