| 1 |
{%MainUnit castleimages.pas} |
| 2 |
{ |
| 3 |
Copyright 2001-2022 Michalis Kamburelis, Yevhen Loza. |
| 4 |
|
| 5 |
This file is part of "Castle Game Engine". |
| 6 |
|
| 7 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 8 |
included in this distribution, for details about the copyright. |
| 9 |
|
| 10 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
|
| 14 |
---------------------------------------------------------------------------- |
| 15 |
} |
| 16 |
|
| 17 |
(* Paint simple geometric shapes for CastleImages. *) |
| 18 |
|
| 19 |
(* Maybe, a good idea would be to make additional checks like aRadius>=1, |
| 20 |
aWidth >=1, etc. *) |
| 21 |
|
| 22 |
(* I'm really unsure how premultiplied alpha will behave *) |
| 23 |
|
| 24 |
{-----= FILL ELLIPSE =-----} |
| 25 |
|
| 26 |
procedure TCastleImage.FillEllipse(const x, y: single; const aRadiusX, aRadiusY: single; |
| 27 |
const aColor: TCastleColor); |
| 28 |
var |
| 29 |
NewColor, OldColor: TCastleColor; |
| 30 |
ix, iy: integer; |
| 31 |
Alpha1, Alpha1d, Alpha2, Alpha2d, AlphaSum: single; |
| 32 |
d, MeanRadius, SqrY: single; |
| 33 |
begin |
| 34 |
MeanRadius := 1 / aRadiusX + 1 / aRadiusY; //this is simple, but wrong. But let's leave it for now |
| 35 |
Alpha2 := aColor.W; |
| 36 |
for iy := Round(y - aRadiusY) to Round(y + aRadiusY) do |
| 37 |
if (iy >= 0) and (iy < Height) then |
| 38 |
begin |
| 39 |
SqrY := 1 - Sqr((iy - y) / aRadiusY); |
| 40 |
for ix := Round(x - aRadiusX) to Round(x + aRadiusX) do |
| 41 |
if (ix >= 0) and (ix < Width) then |
| 42 |
begin |
| 43 |
d := SqrY - Sqr((ix - x) / aRadiusX); |
| 44 |
if d >= 0 then |
| 45 |
begin |
| 46 |
OldColor := Colors[ix, iy, 0]; |
| 47 |
Alpha1 := OldColor.W; |
| 48 |
|
| 49 |
{antialiasing} |
| 50 |
if d < MeanRadius then |
| 51 |
{ sqrt should be used here, however i like the result with square |
| 52 |
of distance better } |
| 53 |
Alpha2d := Alpha2 * d / MeanRadius // as of conditions above d / DoubleRadius changes from 0 to 1 |
| 54 |
else |
| 55 |
Alpha2d := Alpha2; |
| 56 |
|
| 57 |
Alpha1d := Alpha1 * (1 - Alpha2d); |
| 58 |
AlphaSum := Alpha1 + (1 - Alpha1) * Alpha2d; |
| 59 |
|
| 60 |
|
| 61 |
NewColor.X := (OldColor.X * Alpha1d + aColor.X * Alpha2d) / AlphaSum; |
| 62 |
NewColor.Y := (OldColor.Y * Alpha1d + aColor.Y * Alpha2d) / AlphaSum; |
| 63 |
NewColor.Z := (OldColor.Z * Alpha1d + aColor.Z * Alpha2d) / AlphaSum; |
| 64 |
NewColor.W := AlphaSum; |
| 65 |
|
| 66 |
Colors[ix, iy, 0] := NewColor; |
| 67 |
end; |
| 68 |
end; |
| 69 |
end; |
| 70 |
end; |
| 71 |
|
| 72 |
procedure TRGBAlphaImage.FillEllipse(const x, y: single; const aRadiusX, aRadiusY: single; |
| 73 |
const aColor: TCastleColor); |
| 74 |
var |
| 75 |
p: PVector4Byte; |
| 76 |
ByteColor: TVector3Byte; |
| 77 |
ix, iy: integer; |
| 78 |
Alpha1, Alpha1d, Alpha2, Alpha2d, AlphaSum: single; |
| 79 |
d, MeanRadius, SqrY: single; |
| 80 |
begin |
| 81 |
ByteColor.X := Trunc(255 * aColor.X); |
| 82 |
ByteColor.Y := Trunc(255 * aColor.Y); |
| 83 |
ByteColor.Z := Trunc(255 * aColor.Z); |
| 84 |
MeanRadius := 1 / aRadiusX + 1 / aRadiusY; //this is simple, but wrong. But let's leave it for now |
| 85 |
Alpha2 := aColor.W; |
| 86 |
for iy := Round(y - aRadiusY) to Round(y + aRadiusY) do |
| 87 |
if (iy >= 0) and (iy < Height) then |
| 88 |
begin |
| 89 |
SqrY := 1 - Sqr((iy - y) / aRadiusY); |
| 90 |
p := nil; |
| 91 |
for ix := Round(x - aRadiusX) to Round(x + aRadiusX) do |
| 92 |
if (ix >= 0) and (ix < Width) then |
| 93 |
begin |
| 94 |
d := SqrY - Sqr((ix - x) / aRadiusX); |
| 95 |
if d >= 0 then |
| 96 |
begin |
| 97 |
if p = nil then p := PixelPtr(ix, iy) else Inc(p); |
| 98 |
|
| 99 |
Alpha1 := p^.W / 255; |
| 100 |
|
| 101 |
{antialiasing} |
| 102 |
if d < MeanRadius then |
| 103 |
{ sqrt should be used here, however i like the result with square |
| 104 |
of distance better } |
| 105 |
Alpha2d := Alpha2 * d / MeanRadius // as of conditions above d / DoubleRadius changes from 0 to 1 |
| 106 |
else |
| 107 |
Alpha2d := Alpha2; |
| 108 |
|
| 109 |
Alpha1d := Alpha1 * (1 - Alpha2d); |
| 110 |
AlphaSum := Alpha1 + (1 - Alpha1) * Alpha2d; |
| 111 |
if AlphaSum > 0 then begin |
| 112 |
p^.X := Round((p^.X * Alpha1d + ByteColor.X * Alpha2d) / AlphaSum); |
| 113 |
p^.Y := Round((p^.Y * Alpha1d + ByteColor.Y * Alpha2d) / AlphaSum); |
| 114 |
p^.Z := Round((p^.Z * Alpha1d + ByteColor.Z * Alpha2d) / AlphaSum); |
| 115 |
end; |
| 116 |
p^.W := Round(255 * AlphaSum); |
| 117 |
end; |
| 118 |
end; |
| 119 |
end; |
| 120 |
end; |
| 121 |
|
| 122 |
procedure TGrayscaleAlphaImage.FillEllipse(const x, y: single; const aRadiusX, aRadiusY: single; |
| 123 |
const aColor: TCastleColor); |
| 124 |
var |
| 125 |
p: PVector2Byte; |
| 126 |
ByteColor: Byte; |
| 127 |
ix, iy: integer; |
| 128 |
Alpha1, Alpha1d, Alpha2, Alpha2d, AlphaSum: single; |
| 129 |
d, MeanRadius, SqrY: single; |
| 130 |
begin |
| 131 |
ByteColor := GrayscaleValue(Vector3Byte(Vector3(aColor.X, aColor.Y, aColor.Z))); |
| 132 |
MeanRadius := 1 / aRadiusX + 1 / aRadiusY; //this is simple, but wrong. But let's leave it for now |
| 133 |
Alpha2 := aColor.W; |
| 134 |
for iy := Round(y - aRadiusY) to Round(y + aRadiusY) do |
| 135 |
if (iy >= 0) and (iy < Height) then |
| 136 |
begin |
| 137 |
SqrY := 1 - Sqr((iy - y) / aRadiusY); |
| 138 |
p := nil; |
| 139 |
for ix := Round(x - aRadiusX) to Round(x + aRadiusX) do |
| 140 |
if (ix >= 0) and (ix < Width) then |
| 141 |
begin |
| 142 |
d := SqrY - Sqr((ix - x) / aRadiusX); |
| 143 |
if d >= 0 then |
| 144 |
begin |
| 145 |
if p = nil then p := PixelPtr(ix, iy) else Inc(p); |
| 146 |
|
| 147 |
Alpha1 := p^.Y / 255; |
| 148 |
|
| 149 |
{antialiasing} |
| 150 |
if d < MeanRadius then |
| 151 |
{ sqrt should be used here, however i like the result with square |
| 152 |
of distance better } |
| 153 |
Alpha2d := Alpha2 * d / MeanRadius // as of conditions above d / DoubleRadius changes from 0 to 1 |
| 154 |
else |
| 155 |
Alpha2d := Alpha2; |
| 156 |
|
| 157 |
Alpha1d := Alpha1 * (1 - Alpha2d); |
| 158 |
AlphaSum := Alpha1 + (1 - Alpha1) * Alpha2d; |
| 159 |
if AlphaSum > 0 then begin |
| 160 |
p^.X := Round((p^.X * Alpha1d + ByteColor * Alpha2d) / AlphaSum); |
| 161 |
end; |
| 162 |
p^.Y := Round(255 * AlphaSum); |
| 163 |
end; |
| 164 |
end; |
| 165 |
end; |
| 166 |
end; |
| 167 |
|
| 168 |
procedure TRGBImage.FillEllipse(const x, y: single; const aRadiusX, aRadiusY: single; |
| 169 |
const aColor: TCastleColor); |
| 170 |
var |
| 171 |
p: PVector3Byte; |
| 172 |
ByteColor: TVector3Byte; |
| 173 |
ix, iy: integer; |
| 174 |
Alpha1d, Alpha2, Alpha2d: single; |
| 175 |
d, MeanRadius, SqrY: single; |
| 176 |
begin |
| 177 |
ByteColor.X := Trunc(255 * aColor.X); |
| 178 |
ByteColor.Y := Trunc(255 * aColor.Y); |
| 179 |
ByteColor.Z := Trunc(255 * aColor.Z); |
| 180 |
MeanRadius := 1 / aRadiusX + 1 / aRadiusY; //this is simple, but wrong. But let's leave it for now |
| 181 |
Alpha2 := aColor.W; |
| 182 |
for iy := Round(y - aRadiusY) to Round(y + aRadiusY) do |
| 183 |
if (iy >= 0) and (iy < Height) then |
| 184 |
begin |
| 185 |
SqrY := 1 - Sqr((iy - y) / aRadiusY); |
| 186 |
p := nil; |
| 187 |
for ix := Round(x - aRadiusX) to Round(x + aRadiusX) do |
| 188 |
if (ix >= 0) and (ix < Width) then |
| 189 |
begin |
| 190 |
d := SqrY - Sqr((ix - x) / aRadiusX); |
| 191 |
if d >= 0 then |
| 192 |
begin |
| 193 |
if p = nil then p := PixelPtr(ix, iy) else Inc(p); |
| 194 |
|
| 195 |
{antialiasing} |
| 196 |
if d < MeanRadius then |
| 197 |
{ sqrt should be used here, however i like the result with square |
| 198 |
of distance better } |
| 199 |
Alpha2d := Alpha2 * d / MeanRadius // as of conditions above d / DoubleRadius changes from 0 to 1 |
| 200 |
else |
| 201 |
Alpha2d := Alpha2; |
| 202 |
|
| 203 |
Alpha1d := 1 - Alpha2d; |
| 204 |
p^.X := Round((p^.X * Alpha1d + ByteColor.X * Alpha2d)); |
| 205 |
p^.Y := Round((p^.Y * Alpha1d + ByteColor.Y * Alpha2d)); |
| 206 |
p^.Z := Round((p^.Z * Alpha1d + ByteColor.Z * Alpha2d)); |
| 207 |
end; |
| 208 |
end; |
| 209 |
end; |
| 210 |
end; |
| 211 |
|
| 212 |
procedure TGrayscaleImage.FillEllipse(const x, y: single; const aRadiusX, aRadiusY: single; |
| 213 |
const aColor: TCastleColor); |
| 214 |
var |
| 215 |
p: PByte; |
| 216 |
ByteColor: Byte; |
| 217 |
ix, iy: integer; |
| 218 |
Alpha1d, Alpha2, Alpha2d: single; |
| 219 |
d, MeanRadius, SqrY: single; |
| 220 |
begin |
| 221 |
ByteColor := GrayscaleValue(Vector3Byte(Vector3(aColor.X, aColor.Y, aColor.Z))); |
| 222 |
MeanRadius := 1 / aRadiusX + 1 / aRadiusY; //this is simple, but wrong. But let's leave it for now |
| 223 |
Alpha2 := aColor.W; |
| 224 |
for iy := Round(y - aRadiusY) to Round(y + aRadiusY) do |
| 225 |
if (iy >= 0) and (iy < Height) then |
| 226 |
begin |
| 227 |
SqrY := 1 - Sqr((iy - y) / aRadiusY); |
| 228 |
p := nil; |
| 229 |
for ix := Round(x - aRadiusX) to Round(x + aRadiusX) do |
| 230 |
if (ix >= 0) and (ix < Width) then |
| 231 |
begin |
| 232 |
d := SqrY - Sqr((ix - x) / aRadiusX); |
| 233 |
if d >= 0 then |
| 234 |
begin |
| 235 |
if p = nil then p := PixelPtr(ix, iy) else Inc(p); |
| 236 |
|
| 237 |
{antialiasing} |
| 238 |
if d < MeanRadius then |
| 239 |
{ sqrt should be used here, however i like the result with square |
| 240 |
of distance better } |
| 241 |
Alpha2d := Alpha2 * d / MeanRadius // as of conditions above d / DoubleRadius changes from 0 to 1 |
| 242 |
else |
| 243 |
Alpha2d := Alpha2; |
| 244 |
|
| 245 |
Alpha1d := 1 - Alpha2d; |
| 246 |
p^ := Round((p^ * Alpha1d + ByteColor * Alpha2d)); |
| 247 |
end; |
| 248 |
end; |
| 249 |
end; |
| 250 |
end; |
| 251 |
|
| 252 |
{-----= HOLLOW ELLIPSE =-----} |
| 253 |
|
| 254 |
procedure TCastleImage.Ellipse(const x, y: single; const aRadiusX, aRadiusY: single; |
| 255 |
const aWidth: single; const aColor: TCastleColor); |
| 256 |
var |
| 257 |
NewColor, OldColor: TCastleColor; |
| 258 |
ix, iy: integer; |
| 259 |
Alpha1, Alpha1d, Alpha2, Alpha2d, AlphaSum: single; |
| 260 |
d1, d2, MeanRadius1, MeanRadius2, SqrY1, SqrY2: single; |
| 261 |
begin |
| 262 |
MeanRadius1 := 1 / aRadiusX + 1 / aRadiusY; |
| 263 |
MeanRadius2 := 1 / (aRadiusX - aWidth) + 1 / (aRadiusY - aWidth); |
| 264 |
Alpha2 := aColor.W; |
| 265 |
for iy := Round(y - aRadiusY) to Round(y + aRadiusY) do |
| 266 |
if (iy >= 0) and (iy < Height) then |
| 267 |
begin |
| 268 |
SqrY1 := 1 - Sqr((iy - y) / aRadiusY); |
| 269 |
SqrY2 := 1 - Sqr((iy - y) / (aRadiusY - aWidth)); |
| 270 |
for ix := Round(x - aRadiusX) to Round(x + aRadiusX) do |
| 271 |
if (ix >= 0) and (ix < Width) then |
| 272 |
begin |
| 273 |
d1 := SqrY1 - Sqr((ix - x) / (aRadiusX)); |
| 274 |
d2 := SqrY2 - Sqr((ix - x) / (aRadiusX - aWidth)); |
| 275 |
if (d1 >= 0) and (d2 <= MeanRadius2) then |
| 276 |
begin |
| 277 |
OldColor := Colors[ix, iy, 0]; |
| 278 |
Alpha1 := OldColor.W; |
| 279 |
|
| 280 |
{antialiasing} |
| 281 |
if d1 < MeanRadius1 then |
| 282 |
Alpha2d := Alpha2 * d1 / MeanRadius1 |
| 283 |
else |
| 284 |
Alpha2d := Alpha2; |
| 285 |
if d2 > 0 then |
| 286 |
Alpha2d := Alpha2d * (1 - d2 / MeanRadius2); |
| 287 |
|
| 288 |
Alpha1d := Alpha1 * (1 - Alpha2d); |
| 289 |
AlphaSum := Alpha1 + (1 - Alpha1) * Alpha2d; |
| 290 |
|
| 291 |
NewColor.X := (OldColor.X * Alpha1d + aColor.X * Alpha2d) / AlphaSum; |
| 292 |
NewColor.Y := (OldColor.Y * Alpha1d + aColor.Y * Alpha2d) / AlphaSum; |
| 293 |
NewColor.Z := (OldColor.Z * Alpha1d + aColor.Z * Alpha2d) / AlphaSum; |
| 294 |
NewColor.W := AlphaSum; |
| 295 |
|
| 296 |
Colors[ix, iy, 0] := NewColor; |
| 297 |
end; |
| 298 |
end; |
| 299 |
end; |
| 300 |
end; |
| 301 |
|
| 302 |
procedure TRGBAlphaImage.Ellipse(const x, y: single; const aRadiusX, aRadiusY: single; |
| 303 |
const aWidth: single; const aColor: TCastleColor); |
| 304 |
var |
| 305 |
p: PVector4Byte; |
| 306 |
ByteColor: TVector3Byte; |
| 307 |
ix, iy: integer; |
| 308 |
Alpha1, Alpha1d, Alpha2, Alpha2d, AlphaSum: single; |
| 309 |
d1, d2, MeanRadius1, MeanRadius2, SqrY1, SqrY2: single; |
| 310 |
begin |
| 311 |
ByteColor.X := Trunc(255 * aColor.X); |
| 312 |
ByteColor.Y := Trunc(255 * aColor.Y); |
| 313 |
ByteColor.Z := Trunc(255 * aColor.Z); |
| 314 |
MeanRadius1 := 1 / aRadiusX + 1 / aRadiusY; |
| 315 |
MeanRadius2 := 1 / (aRadiusX - aWidth) + 1 / (aRadiusY - aWidth); |
| 316 |
Alpha2 := aColor.W; |
| 317 |
for iy := Round(y - aRadiusY) to Round(y + aRadiusY) do |
| 318 |
if (iy >= 0) and (iy < Height) then |
| 319 |
begin |
| 320 |
SqrY1 := 1 - Sqr((iy - y) / aRadiusY); |
| 321 |
SqrY2 := 1 - Sqr((iy - y) / (aRadiusY - aWidth)); |
| 322 |
for ix := Round(x - aRadiusX) to Round(x + aRadiusX) do |
| 323 |
if (ix >= 0) and (ix < Width) then |
| 324 |
begin |
| 325 |
d1 := SqrY1 - Sqr((ix - x) / (aRadiusX)); |
| 326 |
d2 := SqrY2 - Sqr((ix - x) / (aRadiusX - aWidth)); |
| 327 |
if (d1 >= 0) and (d2 <= MeanRadius2) then |
| 328 |
begin |
| 329 |
p := PixelPtr(ix, iy); |
| 330 |
|
| 331 |
Alpha1 := p^.W / 255; |
| 332 |
|
| 333 |
{antialiasing} |
| 334 |
if d1 < MeanRadius1 then |
| 335 |
Alpha2d := Alpha2 * d1 / MeanRadius1 |
| 336 |
else |
| 337 |
Alpha2d := Alpha2; |
| 338 |
if d2 > 0 then |
| 339 |
Alpha2d := Alpha2d * (1 - d2 / MeanRadius2); |
| 340 |
|
| 341 |
Alpha1d := Alpha1 * (1 - Alpha2d); |
| 342 |
AlphaSum := Alpha1 + (1 - Alpha1) * Alpha2d; |
| 343 |
if AlphaSum > 0 then begin |
| 344 |
p^.X := Round((p^.X * Alpha1d + ByteColor.X * Alpha2d) / AlphaSum); |
| 345 |
p^.Y := Round((p^.Y * Alpha1d + ByteColor.Y * Alpha2d) / AlphaSum); |
| 346 |
p^.Z := Round((p^.Z * Alpha1d + ByteColor.Z * Alpha2d) / AlphaSum); |
| 347 |
end; |
| 348 |
p^.W := Round(255 * AlphaSum); |
| 349 |
end; |
| 350 |
end; |
| 351 |
end; |
| 352 |
end; |
| 353 |
|
| 354 |
procedure TGrayscaleAlphaImage.Ellipse(const x, y: single; const aRadiusX, aRadiusY: single; |
| 355 |
const aWidth: single; const aColor: TCastleColor); |
| 356 |
var |
| 357 |
p: PVector2Byte; |
| 358 |
ByteColor: Byte; |
| 359 |
ix, iy: integer; |
| 360 |
Alpha1, Alpha1d, Alpha2, Alpha2d, AlphaSum: single; |
| 361 |
d1, d2, MeanRadius1, MeanRadius2, SqrY1, SqrY2: single; |
| 362 |
begin |
| 363 |
ByteColor := GrayscaleValue(Vector3Byte(Vector3(aColor.X, aColor.Y, aColor.Z))); |
| 364 |
MeanRadius1 := 1 / aRadiusX + 1 / aRadiusY; |
| 365 |
MeanRadius2 := 1 / (aRadiusX - aWidth) + 1 / (aRadiusY - aWidth); |
| 366 |
Alpha2 := aColor.W; |
| 367 |
for iy := Round(y - aRadiusY) to Round(y + aRadiusY) do |
| 368 |
if (iy >= 0) and (iy < Height) then |
| 369 |
begin |
| 370 |
SqrY1 := 1 - Sqr((iy - y) / aRadiusY); |
| 371 |
SqrY2 := 1 - Sqr((iy - y) / (aRadiusY - aWidth)); |
| 372 |
for ix := Round(x - aRadiusX) to Round(x + aRadiusX) do |
| 373 |
if (ix >= 0) and (ix < Width) then |
| 374 |
begin |
| 375 |
d1 := SqrY1 - Sqr((ix - x) / (aRadiusX)); |
| 376 |
d2 := SqrY2 - Sqr((ix - x) / (aRadiusX - aWidth)); |
| 377 |
if (d1 >= 0) and (d2 <= MeanRadius2) then |
| 378 |
begin |
| 379 |
p := PixelPtr(ix, iy); |
| 380 |
|
| 381 |
Alpha1 := p^.Y / 255; |
| 382 |
|
| 383 |
{antialiasing} |
| 384 |
if d1 < MeanRadius1 then |
| 385 |
Alpha2d := Alpha2 * d1 / MeanRadius1 |
| 386 |
else |
| 387 |
Alpha2d := Alpha2; |
| 388 |
if d2 > 0 then |
| 389 |
Alpha2d := Alpha2d * (1 - d2 / MeanRadius2); |
| 390 |
|
| 391 |
Alpha1d := Alpha1 * (1 - Alpha2d); |
| 392 |
AlphaSum := Alpha1 + (1 - Alpha1) * Alpha2d; |
| 393 |
if AlphaSum > 0 then begin |
| 394 |
p^.X := Round((p^.X * Alpha1d + ByteColor * Alpha2d) / AlphaSum); |
| 395 |
end; |
| 396 |
p^.Y := Round(255 * AlphaSum); |
| 397 |
end; |
| 398 |
end; |
| 399 |
end; |
| 400 |
end; |
| 401 |
|
| 402 |
procedure TRGBImage.Ellipse(const x, y: single; const aRadiusX, aRadiusY: single; |
| 403 |
const aWidth: single; const aColor: TCastleColor); |
| 404 |
var |
| 405 |
p: PVector3Byte; |
| 406 |
ByteColor: TVector3Byte; |
| 407 |
ix, iy: integer; |
| 408 |
Alpha1d, Alpha2, Alpha2d: single; |
| 409 |
d1, d2, MeanRadius1, MeanRadius2, SqrY1, SqrY2: single; |
| 410 |
begin |
| 411 |
ByteColor.X := Trunc(255 * aColor.X); |
| 412 |
ByteColor.Y := Trunc(255 * aColor.Y); |
| 413 |
ByteColor.Z := Trunc(255 * aColor.Z); |
| 414 |
MeanRadius1 := 1 / aRadiusX + 1 / aRadiusY; |
| 415 |
MeanRadius2 := 1 / (aRadiusX - aWidth) + 1 / (aRadiusY - aWidth); |
| 416 |
Alpha2 := aColor.W; |
| 417 |
for iy := Round(y - aRadiusY) to Round(y + aRadiusY) do |
| 418 |
if (iy >= 0) and (iy < Height) then |
| 419 |
begin |
| 420 |
SqrY1 := 1 - Sqr((iy - y) / aRadiusY); |
| 421 |
SqrY2 := 1 - Sqr((iy - y) / (aRadiusY - aWidth)); |
| 422 |
for ix := Round(x - aRadiusX) to Round(x + aRadiusX) do |
| 423 |
if (ix >= 0) and (ix < Width) then |
| 424 |
begin |
| 425 |
d1 := SqrY1 - Sqr((ix - x) / (aRadiusX)); |
| 426 |
d2 := SqrY2 - Sqr((ix - x) / (aRadiusX - aWidth)); |
| 427 |
if (d1 >= 0) and (d2 <= MeanRadius2) then |
| 428 |
begin |
| 429 |
p := PixelPtr(ix, iy); |
| 430 |
|
| 431 |
{antialiasing} |
| 432 |
if d1 < MeanRadius1 then |
| 433 |
Alpha2d := Alpha2 * d1 / MeanRadius1 |
| 434 |
else |
| 435 |
Alpha2d := Alpha2; |
| 436 |
if d2 > 0 then |
| 437 |
Alpha2d := Alpha2d * (1 - d2 / MeanRadius2); |
| 438 |
|
| 439 |
Alpha1d := 1 - Alpha2d; |
| 440 |
p^.X := Round((p^.X * Alpha1d + ByteColor.X * Alpha2d)); |
| 441 |
p^.Y := Round((p^.Y * Alpha1d + ByteColor.Y * Alpha2d)); |
| 442 |
p^.Z := Round((p^.Z * Alpha1d + ByteColor.Z * Alpha2d)); |
| 443 |
end; |
| 444 |
end; |
| 445 |
end; |
| 446 |
end; |
| 447 |
|
| 448 |
procedure TGrayscaleImage.Ellipse(const x, y: single; const aRadiusX, aRadiusY: single; |
| 449 |
const aWidth: single; const aColor: TCastleColor); |
| 450 |
var |
| 451 |
p: PByte; |
| 452 |
ByteColor: Byte; |
| 453 |
ix, iy: integer; |
| 454 |
Alpha1d, Alpha2, Alpha2d: single; |
| 455 |
d1, d2, MeanRadius1, MeanRadius2, SqrY1, SqrY2: single; |
| 456 |
begin |
| 457 |
ByteColor := GrayscaleValue(Vector3Byte(Vector3(aColor.X, aColor.Y, aColor.Z))); |
| 458 |
MeanRadius1 := 1 / aRadiusX + 1 / aRadiusY; |
| 459 |
MeanRadius2 := 1 / (aRadiusX - aWidth) + 1 / (aRadiusY - aWidth); |
| 460 |
Alpha2 := aColor.W; |
| 461 |
for iy := Round(y - aRadiusY) to Round(y + aRadiusY) do |
| 462 |
if (iy >= 0) and (iy < Height) then |
| 463 |
begin |
| 464 |
SqrY1 := 1 - Sqr((iy - y) / aRadiusY); |
| 465 |
SqrY2 := 1 - Sqr((iy - y) / (aRadiusY - aWidth)); |
| 466 |
for ix := Round(x - aRadiusX) to Round(x + aRadiusX) do |
| 467 |
if (ix >= 0) and (ix < Width) then |
| 468 |
begin |
| 469 |
d1 := SqrY1 - Sqr((ix - x) / (aRadiusX)); |
| 470 |
d2 := SqrY2 - Sqr((ix - x) / (aRadiusX - aWidth)); |
| 471 |
if (d1 >= 0) and (d2 <= MeanRadius2) then |
| 472 |
begin |
| 473 |
p := PixelPtr(ix, iy); |
| 474 |
|
| 475 |
{antialiasing} |
| 476 |
if d1 < MeanRadius1 then |
| 477 |
Alpha2d := Alpha2 * d1 / MeanRadius1 |
| 478 |
else |
| 479 |
Alpha2d := Alpha2; |
| 480 |
if d2 > 0 then |
| 481 |
Alpha2d := Alpha2d * (1 - d2 / MeanRadius2); |
| 482 |
|
| 483 |
Alpha1d := 1 - Alpha2d; |
| 484 |
p^ := Round((p^ * Alpha1d + ByteColor * Alpha2d)); |
| 485 |
end; |
| 486 |
end; |
| 487 |
end; |
| 488 |
end; |
| 489 |
|
| 490 |
{-----= FILL RECTANGLE =-----} |
| 491 |
|
| 492 |
procedure TCastleImage.FillRectangle(const x1, y1, x2, y2: single; |
| 493 |
const aColor: TCastleColor); |
| 494 |
var |
| 495 |
NewColor, OldColor: TCastleColor; |
| 496 |
ix, iy: integer; |
| 497 |
Alpha1, Alpha1d, Alpha2, Alpha2d, AlphaSum: single; |
| 498 |
MinX, MaxX, MinY, MaxY: single; |
| 499 |
dx, dy: single; |
| 500 |
function Min(a, b: single): single; {$IFDEF SUPPORTS_INLINE}inline;{$ENDIF} |
| 501 |
begin |
| 502 |
if a < b then Result := a else Result := b; |
| 503 |
end; |
| 504 |
begin |
| 505 |
if x1 < x2 then |
| 506 |
begin |
| 507 |
MinX := x1; |
| 508 |
MaxX := x2; |
| 509 |
end |
| 510 |
else |
| 511 |
begin |
| 512 |
MinX := x2; |
| 513 |
MaxX := x1; |
| 514 |
end; |
| 515 |
if y1 < y2 then |
| 516 |
begin |
| 517 |
MinY := y1; |
| 518 |
MaxY := y2; |
| 519 |
end |
| 520 |
else |
| 521 |
begin |
| 522 |
MinY := y2; |
| 523 |
MaxY := y1; |
| 524 |
end; |
| 525 |
if MinX < 0 then MinX := 0; |
| 526 |
if MinY < 0 then MinY := 0; |
| 527 |
if MaxX > Width then MaxX := Width; |
| 528 |
if MaxY > Height then MaxY := Height; |
| 529 |
|
| 530 |
Alpha2 := aColor.W; |
| 531 |
|
| 532 |
for iy := Round(MinY - 1) to Round(MaxY + 1) do |
| 533 |
if (iy >= 0) and (iy < Height) then |
| 534 |
begin |
| 535 |
for ix := Round(MinX - 1) to Round(MaxX + 1) do |
| 536 |
if (ix >= 0) and (ix < Width) then |
| 537 |
begin |
| 538 |
OldColor := Colors[ix, iy, 0]; |
| 539 |
Alpha1 := OldColor.W; |
| 540 |
|
| 541 |
{antialiasing} |
| 542 |
if ix < MinX then |
| 543 |
dx := MinX - ix |
| 544 |
else |
| 545 |
if ix > MaxX then |
| 546 |
dx := ix - MaxX |
| 547 |
else |
| 548 |
dx := 1; |
| 549 |
if iy < MinY then |
| 550 |
dy := MinY - iy |
| 551 |
else |
| 552 |
if iy > MaxY then |
| 553 |
dy := iy - MaxY |
| 554 |
else |
| 555 |
dy := 1; |
| 556 |
Alpha2d := Alpha2 * Sqr(Min(dx, dy)); |
| 557 |
|
| 558 |
Alpha1d := Alpha1 * (1 - Alpha2d); |
| 559 |
AlphaSum := Alpha1 + (1 - Alpha1) * Alpha2d; |
| 560 |
|
| 561 |
NewColor.X := (OldColor.X * Alpha1d + aColor.X * Alpha2d) / AlphaSum; |
| 562 |
NewColor.Y := (OldColor.Y * Alpha1d + aColor.Y * Alpha2d) / AlphaSum; |
| 563 |
NewColor.Z := (OldColor.Z * Alpha1d + aColor.Z * Alpha2d) / AlphaSum; |
| 564 |
NewColor.W := AlphaSum; |
| 565 |
|
| 566 |
Colors[ix, iy, 0] := NewColor; |
| 567 |
end; |
| 568 |
end; |
| 569 |
end; |
| 570 |
|
| 571 |
procedure TRGBAlphaImage.FillRectangle(const x1, y1, x2, y2: single; |
| 572 |
const aColor: TCastleColor); |
| 573 |
var |
| 574 |
p: PVector4Byte; |
| 575 |
ByteColor: TVector3Byte; |
| 576 |
ix, iy: integer; |
| 577 |
Alpha1, Alpha1d, Alpha2, Alpha2d, AlphaSum: single; |
| 578 |
MinX, MaxX, MinY, MaxY: single; |
| 579 |
dx, dy: single; |
| 580 |
function Min(a, b: single): single; {$IFDEF SUPPORTS_INLINE}inline;{$ENDIF} |
| 581 |
begin |
| 582 |
if a < b then Result := a else Result := b; |
| 583 |
end; |
| 584 |
begin |
| 585 |
if x1 < x2 then |
| 586 |
begin |
| 587 |
MinX := x1; |
| 588 |
MaxX := x2; |
| 589 |
end |
| 590 |
else |
| 591 |
begin |
| 592 |
MinX := x2; |
| 593 |
MaxX := x1; |
| 594 |
end; |
| 595 |
if y1 < y2 then |
| 596 |
begin |
| 597 |
MinY := y1; |
| 598 |
MaxY := y2; |
| 599 |
end |
| 600 |
else |
| 601 |
begin |
| 602 |
MinY := y2; |
| 603 |
MaxY := y1; |
| 604 |
end; |
| 605 |
if MinX < 0 then MinX := 0; |
| 606 |
if MinY < 0 then MinY := 0; |
| 607 |
if MaxX > Width then MaxX := Width; |
| 608 |
if MaxY > Height then MaxY := Height; |
| 609 |
|
| 610 |
ByteColor.X := Trunc(255 * aColor.X); |
| 611 |
ByteColor.Y := Trunc(255 * aColor.Y); |
| 612 |
ByteColor.Z := Trunc(255 * aColor.Z); |
| 613 |
Alpha2 := aColor.W; |
| 614 |
|
| 615 |
|
| 616 |
for iy := Round(MinY - 1) to Round(MaxY + 1) do |
| 617 |
if (iy >= 0) and (iy < Height) then |
| 618 |
begin |
| 619 |
for ix := Round(MinX - 1) to Round(MaxX + 1) do |
| 620 |
if (ix >= 0) and (ix < Width) then |
| 621 |
begin |
| 622 |
p := PixelPtr(ix, iy); |
| 623 |
|
| 624 |
Alpha1 := p^.W / 255; |
| 625 |
|
| 626 |
{antialiasing} |
| 627 |
if ix < MinX then |
| 628 |
dx := MinX - ix |
| 629 |
else |
| 630 |
if ix > MaxX then |
| 631 |
dx := ix - MaxX |
| 632 |
else |
| 633 |
dx := 1; |
| 634 |
if iy < MinY then |
| 635 |
dy := MinY - iy |
| 636 |
else |
| 637 |
if iy > MaxY then |
| 638 |
dy := iy - MaxY |
| 639 |
else |
| 640 |
dy := 1; |
| 641 |
Alpha2d := Alpha2 * Sqr(Min(dx, dy)); |
| 642 |
|
| 643 |
Alpha1d := Alpha1 * (1 - Alpha2d); |
| 644 |
AlphaSum := Alpha1 + (1 - Alpha1) * Alpha2d; |
| 645 |
if AlphaSum > 0 then begin |
| 646 |
p^.X := Round((p^.X * Alpha1d + ByteColor.X * Alpha2d) / AlphaSum); |
| 647 |
p^.Y := Round((p^.Y * Alpha1d + ByteColor.Y * Alpha2d) / AlphaSum); |
| 648 |
p^.Z := Round((p^.Z * Alpha1d + ByteColor.Z * Alpha2d) / AlphaSum); |
| 649 |
end; |
| 650 |
p^.W := Round(255 * AlphaSum); |
| 651 |
end; |
| 652 |
end; |
| 653 |
end; |
| 654 |
|
| 655 |
procedure TGrayscaleAlphaImage.FillRectangle(const x1, y1, x2, y2: single; |
| 656 |
const aColor: TCastleColor); |
| 657 |
var |
| 658 |
p: PVector2Byte; |
| 659 |
ByteColor: Byte; |
| 660 |
ix, iy: integer; |
| 661 |
Alpha1, Alpha1d, Alpha2, Alpha2d, AlphaSum: single; |
| 662 |
MinX, MaxX, MinY, MaxY: single; |
| 663 |
dx, dy: single; |
| 664 |
function Min(a, b: single): single; {$IFDEF SUPPORTS_INLINE}inline;{$ENDIF} |
| 665 |
begin |
| 666 |
if a < b then Result := a else Result := b; |
| 667 |
end; |
| 668 |
begin |
| 669 |
if x1 < x2 then |
| 670 |
begin |
| 671 |
MinX := x1; |
| 672 |
MaxX := x2; |
| 673 |
end |
| 674 |
else |
| 675 |
begin |
| 676 |
MinX := x2; |
| 677 |
MaxX := x1; |
| 678 |
end; |
| 679 |
if y1 < y2 then |
| 680 |
begin |
| 681 |
MinY := y1; |
| 682 |
MaxY := y2; |
| 683 |
end |
| 684 |
else |
| 685 |
begin |
| 686 |
MinY := y2; |
| 687 |
MaxY := y1; |
| 688 |
end; |
| 689 |
if MinX < 0 then MinX := 0; |
| 690 |
if MinY < 0 then MinY := 0; |
| 691 |
if MaxX > Width then MaxX := Width; |
| 692 |
if MaxY > Height then MaxY := Height; |
| 693 |
|
| 694 |
ByteColor := GrayscaleValue(Vector3Byte(Vector3(aColor.X, aColor.Y, aColor.Z))); |
| 695 |
Alpha2 := aColor.W; |
| 696 |
|
| 697 |
for iy := Round(MinY - 1) to Round(MaxY + 1) do |
| 698 |
if (iy >= 0) and (iy < Height) then |
| 699 |
begin |
| 700 |
for ix := Round(MinX - 1) to Round(MaxX + 1) do |
| 701 |
if (ix >= 0) and (ix < Width) then |
| 702 |
begin |
| 703 |
p := PixelPtr(ix, iy); |
| 704 |
|
| 705 |
Alpha1 := p^.Y / 255; |
| 706 |
|
| 707 |
{antialiasing} |
| 708 |
if ix < MinX then |
| 709 |
dx := MinX - ix |
| 710 |
else |
| 711 |
if ix > MaxX then |
| 712 |
dx := ix - MaxX |
| 713 |
else |
| 714 |
dx := 1; |
| 715 |
if iy < MinY then |
| 716 |
dy := MinY - iy |
| 717 |
else |
| 718 |
if iy > MaxY then |
| 719 |
dy := iy - MaxY |
| 720 |
else |
| 721 |
dy := 1; |
| 722 |
Alpha2d := Alpha2 * Sqr(Min(dx, dy)); |
| 723 |
|
| 724 |
Alpha1d := Alpha1 * (1 - Alpha2d); |
| 725 |
AlphaSum := Alpha1 + (1 - Alpha1) * Alpha2d; |
| 726 |
if AlphaSum > 0 then begin |
| 727 |
p^.X := Round((p^.X * Alpha1d + ByteColor * Alpha2d) / AlphaSum); |
| 728 |
end; |
| 729 |
p^.Y := Round(255 * AlphaSum); |
| 730 |
end; |
| 731 |
end; |
| 732 |
end; |
| 733 |
|
| 734 |
procedure TRGBImage.FillRectangle(const x1, y1, x2, y2: single; |
| 735 |
const aColor: TCastleColor); |
| 736 |
var |
| 737 |
p: PVector3Byte; |
| 738 |
ByteColor: TVector3Byte; |
| 739 |
ix, iy: integer; |
| 740 |
Alpha1d, Alpha2, Alpha2d: single; |
| 741 |
MinX, MaxX, MinY, MaxY: single; |
| 742 |
dx, dy: single; |
| 743 |
function Min(a, b: single): single; {$IFDEF SUPPORTS_INLINE}inline;{$ENDIF} |
| 744 |
begin |
| 745 |
if a < b then Result := a else Result := b; |
| 746 |
end; |
| 747 |
begin |
| 748 |
if x1 < x2 then |
| 749 |
begin |
| 750 |
MinX := x1; |
| 751 |
MaxX := x2; |
| 752 |
end |
| 753 |
else |
| 754 |
begin |
| 755 |
MinX := x2; |
| 756 |
MaxX := x1; |
| 757 |
end; |
| 758 |
if y1 < y2 then |
| 759 |
begin |
| 760 |
MinY := y1; |
| 761 |
MaxY := y2; |
| 762 |
end |
| 763 |
else |
| 764 |
begin |
| 765 |
MinY := y2; |
| 766 |
MaxY := y1; |
| 767 |
end; |
| 768 |
if MinX < 0 then MinX := 0; |
| 769 |
if MinY < 0 then MinY := 0; |
| 770 |
if MaxX > Width then MaxX := Width; |
| 771 |
if MaxY > Height then MaxY := Height; |
| 772 |
|
| 773 |
ByteColor.X := Trunc(255 * aColor.X); |
| 774 |
ByteColor.Y := Trunc(255 * aColor.Y); |
| 775 |
ByteColor.Z := Trunc(255 * aColor.Z); |
| 776 |
Alpha2 := aColor.W; |
| 777 |
|
| 778 |
for iy := Round(MinY - 1) to Round(MaxY + 1) do |
| 779 |
if (iy >= 0) and (iy < Height) then |
| 780 |
begin |
| 781 |
for ix := Round(MinX - 1) to Round(MaxX + 1) do |
| 782 |
if (ix >= 0) and (ix < Width) then |
| 783 |
begin |
| 784 |
p := PixelPtr(ix, iy); |
| 785 |
|
| 786 |
{antialiasing} |
| 787 |
if ix < MinX then |
| 788 |
dx := MinX - ix |
| 789 |
else |
| 790 |
if ix > MaxX then |
| 791 |
dx := ix - MaxX |
| 792 |
else |
| 793 |
dx := 1; |
| 794 |
if iy < MinY then |
| 795 |
dy := MinY - iy |
| 796 |
else |
| 797 |
if iy > MaxY then |
| 798 |
dy := iy - MaxY |
| 799 |
else |
| 800 |
dy := 1; |
| 801 |
Alpha2d := Alpha2 * Sqr(Min(dx, dy)); |
| 802 |
|
| 803 |
Alpha1d := 1 - Alpha2d; |
| 804 |
p^.X := Round((p^.X * Alpha1d + ByteColor.X * Alpha2d)); |
| 805 |
p^.Y := Round((p^.Y * Alpha1d + ByteColor.Y * Alpha2d)); |
| 806 |
p^.Z := Round((p^.Z * Alpha1d + ByteColor.Z * Alpha2d)); |
| 807 |
end; |
| 808 |
end; |
| 809 |
end; |
| 810 |
|
| 811 |
procedure TGrayscaleImage.FillRectangle(const x1, y1, x2, y2: single; |
| 812 |
const aColor: TCastleColor); |
| 813 |
var |
| 814 |
p: PByte; |
| 815 |
ByteColor: Byte; |
| 816 |
ix, iy: integer; |
| 817 |
Alpha1d, Alpha2, Alpha2d: single; |
| 818 |
MinX, MaxX, MinY, MaxY: single; |
| 819 |
dx, dy: single; |
| 820 |
function Min(a, b: single): single; {$IFDEF SUPPORTS_INLINE}inline;{$ENDIF} |
| 821 |
begin |
| 822 |
if a < b then Result := a else Result := b; |
| 823 |
end; |
| 824 |
begin |
| 825 |
if x1 < x2 then |
| 826 |
begin |
| 827 |
MinX := x1; |
| 828 |
MaxX := x2; |
| 829 |
end |
| 830 |
else |
| 831 |
begin |
| 832 |
MinX := x2; |
| 833 |
MaxX := x1; |
| 834 |
end; |
| 835 |
if y1 < y2 then |
| 836 |
begin |
| 837 |
MinY := y1; |
| 838 |
MaxY := y2; |
| 839 |
end |
| 840 |
else |
| 841 |
begin |
| 842 |
MinY := y2; |
| 843 |
MaxY := y1; |
| 844 |
end; |
| 845 |
if MinX < 0 then MinX := 0; |
| 846 |
if MinY < 0 then MinY := 0; |
| 847 |
if MaxX > Width then MaxX := Width; |
| 848 |
if MaxY > Height then MaxY := Height; |
| 849 |
|
| 850 |
ByteColor := GrayscaleValue(Vector3Byte(Vector3(aColor.X, aColor.Y, aColor.Z))); |
| 851 |
Alpha2 := aColor.W; |
| 852 |
|
| 853 |
for iy := Round(MinY - 1) to Round(MaxY + 1) do |
| 854 |
if (iy >= 0) and (iy < Height) then |
| 855 |
begin |
| 856 |
for ix := Round(MinX - 1) to Round(MaxX + 1) do |
| 857 |
if (ix >= 0) and (ix < Width) then |
| 858 |
begin |
| 859 |
p := PixelPtr(ix, iy); |
| 860 |
|
| 861 |
{antialiasing} |
| 862 |
if ix < MinX then |
| 863 |
dx := MinX - ix |
| 864 |
else |
| 865 |
if ix > MaxX then |
| 866 |
dx := ix - MaxX |
| 867 |
else |
| 868 |
dx := 1; |
| 869 |
if iy < MinY then |
| 870 |
dy := MinY - iy |
| 871 |
else |
| 872 |
if iy > MaxY then |
| 873 |
dy := iy - MaxY |
| 874 |
else |
| 875 |
dy := 1; |
| 876 |
Alpha2d := Alpha2 * Sqr(Min(dx, dy)); |
| 877 |
|
| 878 |
Alpha1d := 1 - Alpha2d; |
| 879 |
p^ := Round((p^ * Alpha1d + ByteColor * Alpha2d)); |
| 880 |
end; |
| 881 |
end; |
| 882 |
end; |
| 883 |
|
| 884 |
{-----= HOLLOW RECTANGLE =-----} |
| 885 |
|
| 886 |
procedure TCastleImage.Rectangle(const x1, y1, x2, y2: single; |
| 887 |
const aWidth: single; const aColor: TCastleColor); |
| 888 |
var |
| 889 |
NewColor, OldColor: TCastleColor; |
| 890 |
ix, iy: integer; |
| 891 |
Alpha1, Alpha1d, Alpha2, Alpha2d, AlphaSum: single; |
| 892 |
MinX, MaxX, MinY, MaxY: single; |
| 893 |
d: single; |
| 894 |
begin |
| 895 |
if x1 < x2 then |
| 896 |
begin |
| 897 |
MinX := x1; |
| 898 |
MaxX := x2; |
| 899 |
end |
| 900 |
else |
| 901 |
begin |
| 902 |
MinX := x2; |
| 903 |
MaxX := x1; |
| 904 |
end; |
| 905 |
if y1 < y2 then |
| 906 |
begin |
| 907 |
MinY := y1; |
| 908 |
MaxY := y2; |
| 909 |
end |
| 910 |
else |
| 911 |
begin |
| 912 |
MinY := y2; |
| 913 |
MaxY := y1; |
| 914 |
end; |
| 915 |
if MinX < 0 then MinX := 0; |
| 916 |
if MinY < 0 then MinY := 0; |
| 917 |
if MaxX > Width then MaxX := Width; |
| 918 |
if MaxY > Height then MaxY := Height; |
| 919 |
|
| 920 |
Alpha2 := aColor.W; |
| 921 |
|
| 922 |
for iy := Round(MinY - 1) to Round(MaxY + 1) do |
| 923 |
if (iy >= 0) and (iy < Height) then |
| 924 |
begin |
| 925 |
for ix := Round(MinX - 1) to Round(MaxX + 1) do |
| 926 |
if (ix >= 0) and (ix < Width) then |
| 927 |
begin |
| 928 |
if ix < MinX then |
| 929 |
d := MinX - ix |
| 930 |
else |
| 931 |
if (iy < MinY) then |
| 932 |
d := MinY - iy |
| 933 |
else |
| 934 |
if ix > MaxX then |
| 935 |
d := ix - MaxX |
| 936 |
else |
| 937 |
if iy > MaxY then |
| 938 |
d := iy - MaxY |
| 939 |
else |
| 940 |
if ix < MinX + aWidth then |
| 941 |
d := 1 |
| 942 |
else |
| 943 |
if iy < MinY + aWidth then |
| 944 |
d := 1 |
| 945 |
else |
| 946 |
if ix > MaxX - aWidth then |
| 947 |
d := 1 |
| 948 |
else |
| 949 |
if iy > MaxY - aWidth then |
| 950 |
d := 1 |
| 951 |
else |
| 952 |
if ix < MinX + aWidth + 1 then |
| 953 |
d := MinX + aWidth + 1 - ix |
| 954 |
else |
| 955 |
if iy < MinY + aWidth + 1 then |
| 956 |
d := MinY + aWidth + 1 - iy |
| 957 |
else |
| 958 |
if ix > MaxX - aWidth - 1 then |
| 959 |
d := ix - (MaxX - aWidth - 1) |
| 960 |
else |
| 961 |
if iy > MaxY - aWidth - 1 then |
| 962 |
d := iy - (MaxY - aWidth - 1) |
| 963 |
else |
| 964 |
d := 0; |
| 965 |
|
| 966 |
if d > 0 then |
| 967 |
begin |
| 968 |
OldColor := Colors[ix, iy, 0]; |
| 969 |
Alpha1 := OldColor.W; |
| 970 |
Alpha2d := Alpha2 * Sqr(d); |
| 971 |
|
| 972 |
Alpha1d := Alpha1 * (1 - Alpha2d); |
| 973 |
AlphaSum := Alpha1 + (1 - Alpha1) * Alpha2d; |
| 974 |
|
| 975 |
NewColor.X := (OldColor.X * Alpha1d + aColor.X * Alpha2d) / AlphaSum; |
| 976 |
NewColor.Y := (OldColor.Y * Alpha1d + aColor.Y * Alpha2d) / AlphaSum; |
| 977 |
NewColor.Z := (OldColor.Z * Alpha1d + aColor.Z * Alpha2d) / AlphaSum; |
| 978 |
NewColor.W := AlphaSum; |
| 979 |
|
| 980 |
Colors[ix, iy, 0] := NewColor; |
| 981 |
end; |
| 982 |
end; |
| 983 |
end; |
| 984 |
end; |
| 985 |
|
| 986 |
procedure TRGBAlphaImage.Rectangle(const x1, y1, x2, y2: single; |
| 987 |
const aWidth: single; const aColor: TCastleColor); |
| 988 |
var |
| 989 |
p: PVector4Byte; |
| 990 |
ByteColor: TVector3Byte; |
| 991 |
ix, iy: integer; |
| 992 |
Alpha1, Alpha1d, Alpha2, Alpha2d, AlphaSum: single; |
| 993 |
MinX, MaxX, MinY, MaxY: single; |
| 994 |
d: single; |
| 995 |
begin |
| 996 |
if x1 < x2 then |
| 997 |
begin |
| 998 |
MinX := x1; |
| 999 |
MaxX := x2; |
| 1000 |
end |
| 1001 |
else |
| 1002 |
begin |
| 1003 |
MinX := x2; |
| 1004 |
MaxX := x1; |
| 1005 |
end; |
| 1006 |
if y1 < y2 then |
| 1007 |
begin |
| 1008 |
MinY := y1; |
| 1009 |
MaxY := y2; |
| 1010 |
end |
| 1011 |
else |
| 1012 |
begin |
| 1013 |
MinY := y2; |
| 1014 |
MaxY := y1; |
| 1015 |
end; |
| 1016 |
if MinX < 0 then MinX := 0; |
| 1017 |
if MinY < 0 then MinY := 0; |
| 1018 |
if MaxX > Width then MaxX := Width; |
| 1019 |
if MaxY > Height then MaxY := Height; |
| 1020 |
|
| 1021 |
ByteColor.X := Trunc(255 * aColor.X); |
| 1022 |
ByteColor.Y := Trunc(255 * aColor.Y); |
| 1023 |
ByteColor.Z := Trunc(255 * aColor.Z); |
| 1024 |
Alpha2 := aColor.W; |
| 1025 |
|
| 1026 |
|
| 1027 |
for iy := Round(MinY - 1) to Round(MaxY + 1) do |
| 1028 |
if (iy >= 0) and (iy < Height) then |
| 1029 |
begin |
| 1030 |
for ix := Round(MinX - 1) to Round(MaxX + 1) do |
| 1031 |
if (ix >= 0) and (ix < Width) then |
| 1032 |
begin |
| 1033 |
if ix < MinX then |
| 1034 |
d := MinX - ix |
| 1035 |
else |
| 1036 |
if (iy < MinY) then |
| 1037 |
d := MinY - iy |
| 1038 |
else |
| 1039 |
if ix > MaxX then |
| 1040 |
d := ix - MaxX |
| 1041 |
else |
| 1042 |
if iy > MaxY then |
| 1043 |
d := iy - MaxY |
| 1044 |
else |
| 1045 |
if ix < MinX + aWidth then |
| 1046 |
d := 1 |
| 1047 |
else |
| 1048 |
if iy < MinY + aWidth then |
| 1049 |
d := 1 |
| 1050 |
else |
| 1051 |
if ix > MaxX - aWidth then |
| 1052 |
d := 1 |
| 1053 |
else |
| 1054 |
if iy > MaxY - aWidth then |
| 1055 |
d := 1 |
| 1056 |
else |
| 1057 |
if ix < MinX + aWidth + 1 then |
| 1058 |
d := MinX + aWidth + 1 - ix |
| 1059 |
else |
| 1060 |
if iy < MinY + aWidth + 1 then |
| 1061 |
d := MinY + aWidth + 1 - iy |
| 1062 |
else |
| 1063 |
if ix > MaxX - aWidth - 1 then |
| 1064 |
d := ix - (MaxX - aWidth - 1) |
| 1065 |
else |
| 1066 |
if iy > MaxY - aWidth - 1 then |
| 1067 |
d := iy - (MaxY - aWidth - 1) |
| 1068 |
else |
| 1069 |
d := 0; |
| 1070 |
|
| 1071 |
if d > 0 then |
| 1072 |
begin |
| 1073 |
p := PixelPtr(ix, iy); |
| 1074 |
Alpha1 := p^.W / 255; |
| 1075 |
Alpha2d := Alpha2 * Sqr(d); |
| 1076 |
|
| 1077 |
Alpha1d := Alpha1 * (1 - Alpha2d); |
| 1078 |
AlphaSum := Alpha1 + (1 - Alpha1) * Alpha2d; |
| 1079 |
if AlphaSum > 0 then begin |
| 1080 |
p^.X := Round((p^.X * Alpha1d + ByteColor.X * Alpha2d) / AlphaSum); |
| 1081 |
p^.Y := Round((p^.Y * Alpha1d + ByteColor.Y * Alpha2d) / AlphaSum); |
| 1082 |
p^.Z := Round((p^.Z * Alpha1d + ByteColor.Z * Alpha2d) / AlphaSum); |
| 1083 |
end; |
| 1084 |
p^.W := Round(255 * AlphaSum); |
| 1085 |
end; |
| 1086 |
end; |
| 1087 |
end; |
| 1088 |
end; |
| 1089 |
|
| 1090 |
procedure TGrayscaleAlphaImage.Rectangle(const x1, y1, x2, y2: single; |
| 1091 |
const aWidth: single; const aColor: TCastleColor); |
| 1092 |
var |
| 1093 |
p: PVector2Byte; |
| 1094 |
ByteColor: Byte; |
| 1095 |
ix, iy: integer; |
| 1096 |
Alpha1, Alpha1d, Alpha2, Alpha2d, AlphaSum: single; |
| 1097 |
MinX, MaxX, MinY, MaxY: single; |
| 1098 |
d: single; |
| 1099 |
begin |
| 1100 |
if x1 < x2 then |
| 1101 |
begin |
| 1102 |
MinX := x1; |
| 1103 |
MaxX := x2; |
| 1104 |
end |
| 1105 |
else |
| 1106 |
begin |
| 1107 |
MinX := x2; |
| 1108 |
MaxX := x1; |
| 1109 |
end; |
| 1110 |
if y1 < y2 then |
| 1111 |
begin |
| 1112 |
MinY := y1; |
| 1113 |
MaxY := y2; |
| 1114 |
end |
| 1115 |
else |
| 1116 |
begin |
| 1117 |
MinY := y2; |
| 1118 |
MaxY := y1; |
| 1119 |
end; |
| 1120 |
if MinX < 0 then MinX := 0; |
| 1121 |
if MinY < 0 then MinY := 0; |
| 1122 |
if MaxX > Width then MaxX := Width; |
| 1123 |
if MaxY > Height then MaxY := Height; |
| 1124 |
|
| 1125 |
ByteColor := GrayscaleValue(Vector3Byte(Vector3(aColor.X, aColor.Y, aColor.Z))); |
| 1126 |
Alpha2 := aColor.W; |
| 1127 |
|
| 1128 |
for iy := Round(MinY - 1) to Round(MaxY + 1) do |
| 1129 |
if (iy >= 0) and (iy < Height) then |
| 1130 |
begin |
| 1131 |
for ix := Round(MinX - 1) to Round(MaxX + 1) do |
| 1132 |
if (ix >= 0) and (ix < Width) then |
| 1133 |
begin |
| 1134 |
if ix < MinX then |
| 1135 |
d := MinX - ix |
| 1136 |
else |
| 1137 |
if (iy < MinY) then |
| 1138 |
d := MinY - iy |
| 1139 |
else |
| 1140 |
if ix > MaxX then |
| 1141 |
d := ix - MaxX |
| 1142 |
else |
| 1143 |
if iy > MaxY then |
| 1144 |
d := iy - MaxY |
| 1145 |
else |
| 1146 |
if ix < MinX + aWidth then |
| 1147 |
d := 1 |
| 1148 |
else |
| 1149 |
if iy < MinY + aWidth then |
| 1150 |
d := 1 |
| 1151 |
else |
| 1152 |
if ix > MaxX - aWidth then |
| 1153 |
d := 1 |
| 1154 |
else |
| 1155 |
if iy > MaxY - aWidth then |
| 1156 |
d := 1 |
| 1157 |
else |
| 1158 |
if ix < MinX + aWidth + 1 then |
| 1159 |
d := MinX + aWidth + 1 - ix |
| 1160 |
else |
| 1161 |
if iy < MinY + aWidth + 1 then |
| 1162 |
d := MinY + aWidth + 1 - iy |
| 1163 |
else |
| 1164 |
if ix > MaxX - aWidth - 1 then |
| 1165 |
d := ix - (MaxX - aWidth - 1) |
| 1166 |
else |
| 1167 |
if iy > MaxY - aWidth - 1 then |
| 1168 |
d := iy - (MaxY - aWidth - 1) |
| 1169 |
else |
| 1170 |
d := 0; |
| 1171 |
|
| 1172 |
if d > 0 then |
| 1173 |
begin |
| 1174 |
p := PixelPtr(ix, iy); |
| 1175 |
Alpha1 := p^.Y / 255; |
| 1176 |
Alpha2d := Alpha2 * Sqr(d); |
| 1177 |
|
| 1178 |
Alpha1d := Alpha1 * (1 - Alpha2d); |
| 1179 |
AlphaSum := Alpha1 + (1 - Alpha1) * Alpha2d; |
| 1180 |
if AlphaSum > 0 then begin |
| 1181 |
p^.X := Round((p^.X * Alpha1d + ByteColor * Alpha2d) / AlphaSum); |
| 1182 |
end; |
| 1183 |
p^.Y := Round(255 * AlphaSum); |
| 1184 |
end; |
| 1185 |
end; |
| 1186 |
end; |
| 1187 |
end; |
| 1188 |
|
| 1189 |
procedure TRGBImage.Rectangle(const x1, y1, x2, y2: single; |
| 1190 |
const aWidth: single; const aColor: TCastleColor); |
| 1191 |
var |
| 1192 |
p: PVector3Byte; |
| 1193 |
ByteColor: TVector3Byte; |
| 1194 |
ix, iy: integer; |
| 1195 |
Alpha1d, Alpha2, Alpha2d: single; |
| 1196 |
MinX, MaxX, MinY, MaxY: single; |
| 1197 |
d: single; |
| 1198 |
begin |
| 1199 |
if x1 < x2 then |
| 1200 |
begin |
| 1201 |
MinX := x1; |
| 1202 |
MaxX := x2; |
| 1203 |
end |
| 1204 |
else |
| 1205 |
begin |
| 1206 |
MinX := x2; |
| 1207 |
MaxX := x1; |
| 1208 |
end; |
| 1209 |
if y1 < y2 then |
| 1210 |
begin |
| 1211 |
MinY := y1; |
| 1212 |
MaxY := y2; |
| 1213 |
end |
| 1214 |
else |
| 1215 |
begin |
| 1216 |
MinY := y2; |
| 1217 |
MaxY := y1; |
| 1218 |
end; |
| 1219 |
if MinX < 0 then MinX := 0; |
| 1220 |
if MinY < 0 then MinY := 0; |
| 1221 |
if MaxX > Width then MaxX := Width; |
| 1222 |
if MaxY > Height then MaxY := Height; |
| 1223 |
|
| 1224 |
ByteColor.X := Trunc(255 * aColor.X); |
| 1225 |
ByteColor.Y := Trunc(255 * aColor.Y); |
| 1226 |
ByteColor.Z := Trunc(255 * aColor.Z); |
| 1227 |
Alpha2 := aColor.W; |
| 1228 |
|
| 1229 |
for iy := Round(MinY - 1) to Round(MaxY + 1) do |
| 1230 |
if (iy >= 0) and (iy < Height) then |
| 1231 |
begin |
| 1232 |
for ix := Round(MinX - 1) to Round(MaxX + 1) do |
| 1233 |
if (ix >= 0) and (ix < Width) then |
| 1234 |
begin |
| 1235 |
if ix < MinX then |
| 1236 |
d := MinX - ix |
| 1237 |
else |
| 1238 |
if (iy < MinY) then |
| 1239 |
d := MinY - iy |
| 1240 |
else |
| 1241 |
if ix > MaxX then |
| 1242 |
d := ix - MaxX |
| 1243 |
else |
| 1244 |
if iy > MaxY then |
| 1245 |
d := iy - MaxY |
| 1246 |
else |
| 1247 |
if ix < MinX + aWidth then |
| 1248 |
d := 1 |
| 1249 |
else |
| 1250 |
if iy < MinY + aWidth then |
| 1251 |
d := 1 |
| 1252 |
else |
| 1253 |
if ix > MaxX - aWidth then |
| 1254 |
d := 1 |
| 1255 |
else |
| 1256 |
if iy > MaxY - aWidth then |
| 1257 |
d := 1 |
| 1258 |
else |
| 1259 |
if ix < MinX + aWidth + 1 then |
| 1260 |
d := MinX + aWidth + 1 - ix |
| 1261 |
else |
| 1262 |
if iy < MinY + aWidth + 1 then |
| 1263 |
d := MinY + aWidth + 1 - iy |
| 1264 |
else |
| 1265 |
if ix > MaxX - aWidth - 1 then |
| 1266 |
d := ix - (MaxX - aWidth - 1) |
| 1267 |
else |
| 1268 |
if iy > MaxY - aWidth - 1 then |
| 1269 |
d := iy - (MaxY - aWidth - 1) |
| 1270 |
else |
| 1271 |
d := 0; |
| 1272 |
|
| 1273 |
if d > 0 then |
| 1274 |
begin |
| 1275 |
p := PixelPtr(ix, iy); |
| 1276 |
Alpha2d := Alpha2 * Sqr(d); |
| 1277 |
|
| 1278 |
Alpha1d := 1 - Alpha2d; |
| 1279 |
p^.X := Round((p^.X * Alpha1d + ByteColor.X * Alpha2d)); |
| 1280 |
p^.Y := Round((p^.Y * Alpha1d + ByteColor.Y * Alpha2d)); |
| 1281 |
p^.Z := Round((p^.Z * Alpha1d + ByteColor.Z * Alpha2d)); |
| 1282 |
end; |
| 1283 |
end; |
| 1284 |
end; |
| 1285 |
end; |
| 1286 |
|
| 1287 |
procedure TGrayscaleImage.Rectangle(const x1, y1, x2, y2: single; |
| 1288 |
const aWidth: single; const aColor: TCastleColor); |
| 1289 |
var |
| 1290 |
p: PByte; |
| 1291 |
ByteColor: Byte; |
| 1292 |
ix, iy: integer; |
| 1293 |
Alpha1d, Alpha2, Alpha2d: single; |
| 1294 |
MinX, MaxX, MinY, MaxY: single; |
| 1295 |
d: single; |
| 1296 |
begin |
| 1297 |
if x1 < x2 then |
| 1298 |
begin |
| 1299 |
MinX := x1; |
| 1300 |
MaxX := x2; |
| 1301 |
end |
| 1302 |
else |
| 1303 |
begin |
| 1304 |
MinX := x2; |
| 1305 |
MaxX := x1; |
| 1306 |
end; |
| 1307 |
if y1 < y2 then |
| 1308 |
begin |
| 1309 |
MinY := y1; |
| 1310 |
MaxY := y2; |
| 1311 |
end |
| 1312 |
else |
| 1313 |
begin |
| 1314 |
MinY := y2; |
| 1315 |
MaxY := y1; |
| 1316 |
end; |
| 1317 |
if MinX < 0 then MinX := 0; |
| 1318 |
if MinY < 0 then MinY := 0; |
| 1319 |
if MaxX > Width then MaxX := Width; |
| 1320 |
if MaxY > Height then MaxY := Height; |
| 1321 |
|
| 1322 |
ByteColor := GrayscaleValue(Vector3Byte(Vector3(aColor.X, aColor.Y, aColor.Z))); |
| 1323 |
Alpha2 := aColor.W; |
| 1324 |
|
| 1325 |
for iy := Round(MinY - 1) to Round(MaxY + 1) do |
| 1326 |
if (iy >= 0) and (iy < Height) then |
| 1327 |
begin |
| 1328 |
for ix := Round(MinX - 1) to Round(MaxX + 1) do |
| 1329 |
if (ix >= 0) and (ix < Width) then |
| 1330 |
begin |
| 1331 |
if ix < MinX then |
| 1332 |
d := MinX - ix |
| 1333 |
else |
| 1334 |
if (iy < MinY) then |
| 1335 |
d := MinY - iy |
| 1336 |
else |
| 1337 |
if ix > MaxX then |
| 1338 |
d := ix - MaxX |
| 1339 |
else |
| 1340 |
if iy > MaxY then |
| 1341 |
d := iy - MaxY |
| 1342 |
else |
| 1343 |
if ix < MinX + aWidth then |
| 1344 |
d := 1 |
| 1345 |
else |
| 1346 |
if iy < MinY + aWidth then |
| 1347 |
d := 1 |
| 1348 |
else |
| 1349 |
if ix > MaxX - aWidth then |
| 1350 |
d := 1 |
| 1351 |
else |
| 1352 |
if iy > MaxY - aWidth then |
| 1353 |
d := 1 |
| 1354 |
else |
| 1355 |
if ix < MinX + aWidth + 1 then |
| 1356 |
d := MinX + aWidth + 1 - ix |
| 1357 |
else |
| 1358 |
if iy < MinY + aWidth + 1 then |
| 1359 |
d := MinY + aWidth + 1 - iy |
| 1360 |
else |
| 1361 |
if ix > MaxX - aWidth - 1 then |
| 1362 |
d := ix - (MaxX - aWidth - 1) |
| 1363 |
else |
| 1364 |
if iy > MaxY - aWidth - 1 then |
| 1365 |
d := iy - (MaxY - aWidth - 1) |
| 1366 |
else |
| 1367 |
d := 0; |
| 1368 |
|
| 1369 |
if d > 0 then |
| 1370 |
begin |
| 1371 |
p := PixelPtr(ix, iy); |
| 1372 |
Alpha2d := Alpha2 * Sqr(d); |
| 1373 |
|
| 1374 |
Alpha1d := 1 - Alpha2d; |
| 1375 |
p^ := Round((p^ * Alpha1d + ByteColor * Alpha2d)); |
| 1376 |
end; |
| 1377 |
end; |
| 1378 |
end; |
| 1379 |
end; |
| 1380 |
|
| 1381 |
{-----= LINE =-----} |
| 1382 |
|
| 1383 |
procedure TCastleImage.Line(const x1, y1, x2, y2: single; |
| 1384 |
const aWidth: single; const aColor: TCastleColor); |
| 1385 |
var |
| 1386 |
NewColor, OldColor: TCastleColor; |
| 1387 |
ix, iy: integer; |
| 1388 |
MinX, MaxX, MinY, MaxY: single; |
| 1389 |
Alpha1, Alpha1d, Alpha2, Alpha2d, AlphaSum: single; |
| 1390 |
a: single; |
| 1391 |
d1x, d1y, d12, d2x, d2y, d22, nx, ny, nLength, t, t2, w2, dw2, da2: single; |
| 1392 |
begin |
| 1393 |
if x1 < x2 then |
| 1394 |
begin |
| 1395 |
MinX := x1; |
| 1396 |
MaxX := x2; |
| 1397 |
end |
| 1398 |
else |
| 1399 |
begin |
| 1400 |
MinX := x2; |
| 1401 |
MaxX := x1; |
| 1402 |
end; |
| 1403 |
if y1 < y2 then |
| 1404 |
begin |
| 1405 |
MinY := y1; |
| 1406 |
MaxY := y2; |
| 1407 |
end |
| 1408 |
else |
| 1409 |
begin |
| 1410 |
MinY := y2; |
| 1411 |
MaxY := y1; |
| 1412 |
end; |
| 1413 |
if MinX < 0 then MinX := 0; |
| 1414 |
if MinY < 0 then MinY := 0; |
| 1415 |
if MaxX > Width then MaxX := Width; |
| 1416 |
if MaxY > Height then MaxY := Height; |
| 1417 |
|
| 1418 |
Alpha2 := aColor.W; |
| 1419 |
|
| 1420 |
nx := x2 - x1; {vector along the line} |
| 1421 |
ny := y2 - y1; |
| 1422 |
nLength := Sqrt(Sqr(nx) + Sqr(ny)); |
| 1423 |
nx := nx / nLength; |
| 1424 |
ny := ny / nLength; |
| 1425 |
t2 := (x2 - x1) * nx + (y2 - y1) * ny; {parameter of the end point of the line, always >0, actually, equal to nLength} |
| 1426 |
w2 := Sqr(aWidth / 2); |
| 1427 |
dw2 := aWidth + 0.5; {double radius + 1} |
| 1428 |
|
| 1429 |
for iy := Round(MinY - aWidth / 2 - 1) to Round(MaxY + aWidth / 2 + 1) do |
| 1430 |
if (iy >= 0) and (iy < Height) then |
| 1431 |
begin |
| 1432 |
d1y := iy - y1; |
| 1433 |
d2y := iy - y2; |
| 1434 |
for ix := Round(MinX - aWidth / 2 - 1) to Round(MaxX + aWidth / 2 + 1) do |
| 1435 |
if (ix >= 0) and (ix < Width) then |
| 1436 |
begin |
| 1437 |
d1x := ix - x1; |
| 1438 |
d12 := Sqr(d1x) + Sqr(d1y); |
| 1439 |
t := d1x * nx + d1y * ny; |
| 1440 |
|
| 1441 |
if (t >= 0) and (t <= t2) then |
| 1442 |
begin |
| 1443 |
da2 := d12 - Sqr(t); |
| 1444 |
if da2 < w2 then |
| 1445 |
a := 1 |
| 1446 |
else |
| 1447 |
if da2 < w2 + dw2 then |
| 1448 |
a := (w2 + dw2 - da2) / dw2 |
| 1449 |
else |
| 1450 |
a := 0; |
| 1451 |
end |
| 1452 |
else |
| 1453 |
if d12 < w2 then |
| 1454 |
a := 1 |
| 1455 |
else |
| 1456 |
if d12 < w2 + dw2 then |
| 1457 |
a := (w2 + dw2 - d12) / dw2 |
| 1458 |
else |
| 1459 |
begin |
| 1460 |
d2x := ix - x2; |
| 1461 |
d22 := Sqr(d2x) + Sqr(d2y); |
| 1462 |
if d22 < w2 then |
| 1463 |
a := 1 |
| 1464 |
else |
| 1465 |
if d22 < w2 + dw2 then |
| 1466 |
a := (w2 + dw2 - d22) / dw2 |
| 1467 |
else |
| 1468 |
a := 0; |
| 1469 |
end; |
| 1470 |
|
| 1471 |
if a > 0 then |
| 1472 |
begin |
| 1473 |
OldColor := Colors[ix, iy, 0]; |
| 1474 |
Alpha1 := OldColor.W; |
| 1475 |
Alpha2d := Alpha2 * a; |
| 1476 |
|
| 1477 |
Alpha1d := Alpha1 * (1 - Alpha2d); |
| 1478 |
AlphaSum := Alpha1 + (1 - Alpha1) * Alpha2d; |
| 1479 |
|
| 1480 |
NewColor.X := (OldColor.X * Alpha1d + aColor.X * Alpha2d) / AlphaSum; |
| 1481 |
NewColor.Y := (OldColor.Y * Alpha1d + aColor.Y * Alpha2d) / AlphaSum; |
| 1482 |
NewColor.Z := (OldColor.Z * Alpha1d + aColor.Z * Alpha2d) / AlphaSum; |
| 1483 |
NewColor.W := AlphaSum; |
| 1484 |
|
| 1485 |
Colors[ix, iy, 0] := NewColor; |
| 1486 |
end; |
| 1487 |
end; |
| 1488 |
end; |
| 1489 |
end; |
| 1490 |
|
| 1491 |
procedure TRGBAlphaImage.Line(const x1, y1, x2, y2: single; |
| 1492 |
const aWidth: single; const aColor: TCastleColor); |
| 1493 |
var |
| 1494 |
p: PVector4Byte; |
| 1495 |
ByteColor: TVector3Byte; |
| 1496 |
ix, iy: integer; |
| 1497 |
Alpha1, Alpha1d, Alpha2, Alpha2d, AlphaSum: single; |
| 1498 |
MinX, MaxX, MinY, MaxY: single; |
| 1499 |
a: single; |
| 1500 |
d1x, d1y, d12, d2x, d2y, d22, nx, ny, nLength, t, t2, w2, dw2, da2: single; |
| 1501 |
begin |
| 1502 |
if x1 < x2 then |
| 1503 |
begin |
| 1504 |
MinX := x1; |
| 1505 |
MaxX := x2; |
| 1506 |
end |
| 1507 |
else |
| 1508 |
begin |
| 1509 |
MinX := x2; |
| 1510 |
MaxX := x1; |
| 1511 |
end; |
| 1512 |
if y1 < y2 then |
| 1513 |
begin |
| 1514 |
MinY := y1; |
| 1515 |
MaxY := y2; |
| 1516 |
end |
| 1517 |
else |
| 1518 |
begin |
| 1519 |
MinY := y2; |
| 1520 |
MaxY := y1; |
| 1521 |
end; |
| 1522 |
if MinX < 0 then MinX := 0; |
| 1523 |
if MinY < 0 then MinY := 0; |
| 1524 |
if MaxX > Width then MaxX := Width; |
| 1525 |
if MaxY > Height then MaxY := Height; |
| 1526 |
|
| 1527 |
ByteColor.X := Trunc(255 * aColor.X); |
| 1528 |
ByteColor.Y := Trunc(255 * aColor.Y); |
| 1529 |
ByteColor.Z := Trunc(255 * aColor.Z); |
| 1530 |
Alpha2 := aColor.W; |
| 1531 |
|
| 1532 |
nx := x2 - x1; {vector along the line} |
| 1533 |
ny := y2 - y1; |
| 1534 |
nLength := Sqrt(Sqr(nx) + Sqr(ny)); |
| 1535 |
nx := nx / nLength; |
| 1536 |
ny := ny / nLength; |
| 1537 |
t2 := (x2 - x1) * nx + (y2 - y1) * ny; {parameter of the end point of the line, always >0, actually, equal to nLength} |
| 1538 |
w2 := Sqr(aWidth / 2); |
| 1539 |
dw2 := aWidth + 0.5; {double radius + 1} |
| 1540 |
|
| 1541 |
for iy := Round(MinY - aWidth / 2 - 1) to Round(MaxY + aWidth / 2 + 1) do |
| 1542 |
if (iy >= 0) and (iy < Height) then |
| 1543 |
begin |
| 1544 |
d1y := iy - y1; |
| 1545 |
d2y := iy - y2; |
| 1546 |
for ix := Round(MinX - aWidth / 2 - 1) to Round(MaxX + aWidth / 2 + 1) do |
| 1547 |
if (ix >= 0) and (ix < Width) then |
| 1548 |
begin |
| 1549 |
d1x := ix - x1; |
| 1550 |
d12 := Sqr(d1x) + Sqr(d1y); |
| 1551 |
t := d1x * nx + d1y * ny; |
| 1552 |
|
| 1553 |
if (t >= 0) and (t <= t2) then |
| 1554 |
begin |
| 1555 |
da2 := d12 - Sqr(t); |
| 1556 |
if da2 < w2 then |
| 1557 |
a := 1 |
| 1558 |
else |
| 1559 |
if da2 < w2 + dw2 then |
| 1560 |
a := (w2 + dw2 - da2) / dw2 |
| 1561 |
else |
| 1562 |
a := 0; |
| 1563 |
end |
| 1564 |
else |
| 1565 |
if d12 < w2 then |
| 1566 |
a := 1 |
| 1567 |
else |
| 1568 |
if d12 < w2 + dw2 then |
| 1569 |
a := (w2 + dw2 - d12) / dw2 |
| 1570 |
else |
| 1571 |
begin |
| 1572 |
d2x := ix - x2; |
| 1573 |
d22 := Sqr(d2x) + Sqr(d2y); |
| 1574 |
if d22 < w2 then |
| 1575 |
a := 1 |
| 1576 |
else |
| 1577 |
if d22 < w2 + dw2 then |
| 1578 |
a := (w2 + dw2 - d22) / dw2 |
| 1579 |
else |
| 1580 |
a := 0; |
| 1581 |
end; |
| 1582 |
|
| 1583 |
if a > 0 then |
| 1584 |
begin |
| 1585 |
p := PixelPtr(ix, iy); |
| 1586 |
Alpha1 := p^.W / 255; |
| 1587 |
Alpha2d := Alpha2 * a; |
| 1588 |
|
| 1589 |
Alpha1d := Alpha1 * (1 - Alpha2d); |
| 1590 |
AlphaSum := Alpha1 + (1 - Alpha1) * Alpha2d; |
| 1591 |
if AlphaSum > 0 then begin |
| 1592 |
p^.X := Round((p^.X * Alpha1d + ByteColor.X * Alpha2d) / AlphaSum); |
| 1593 |
p^.Y := Round((p^.Y * Alpha1d + ByteColor.Y * Alpha2d) / AlphaSum); |
| 1594 |
p^.Z := Round((p^.Z * Alpha1d + ByteColor.Z * Alpha2d) / AlphaSum); |
| 1595 |
end; |
| 1596 |
p^.W := Round(255 * AlphaSum); |
| 1597 |
end; |
| 1598 |
end; |
| 1599 |
end; |
| 1600 |
end; |
| 1601 |
|
| 1602 |
procedure TGrayscaleAlphaImage.Line(const x1, y1, x2, y2: single; |
| 1603 |
const aWidth: single; const aColor: TCastleColor); |
| 1604 |
var |
| 1605 |
p: PVector2Byte; |
| 1606 |
ByteColor: Byte; |
| 1607 |
ix, iy: integer; |
| 1608 |
Alpha1, Alpha1d, Alpha2, Alpha2d, AlphaSum: single; |
| 1609 |
MinX, MaxX, MinY, MaxY: single; |
| 1610 |
a: single; |
| 1611 |
d1x, d1y, d12, d2x, d2y, d22, nx, ny, nLength, t, t2, w2, dw2, da2: single; |
| 1612 |
begin |
| 1613 |
if x1 < x2 then |
| 1614 |
begin |
| 1615 |
MinX := x1; |
| 1616 |
MaxX := x2; |
| 1617 |
end |
| 1618 |
else |
| 1619 |
begin |
| 1620 |
MinX := x2; |
| 1621 |
MaxX := x1; |
| 1622 |
end; |
| 1623 |
if y1 < y2 then |
| 1624 |
begin |
| 1625 |
MinY := y1; |
| 1626 |
MaxY := y2; |
| 1627 |
end |
| 1628 |
else |
| 1629 |
begin |
| 1630 |
MinY := y2; |
| 1631 |
MaxY := y1; |
| 1632 |
end; |
| 1633 |
if MinX < 0 then MinX := 0; |
| 1634 |
if MinY < 0 then MinY := 0; |
| 1635 |
if MaxX > Width then MaxX := Width; |
| 1636 |
if MaxY > Height then MaxY := Height; |
| 1637 |
|
| 1638 |
ByteColor := GrayscaleValue(Vector3Byte(Vector3(aColor.X, aColor.Y, aColor.Z))); |
| 1639 |
Alpha2 := aColor.W; |
| 1640 |
|
| 1641 |
nx := x2 - x1; {vector along the line} |
| 1642 |
ny := y2 - y1; |
| 1643 |
nLength := Sqrt(Sqr(nx) + Sqr(ny)); |
| 1644 |
nx := nx / nLength; |
| 1645 |
ny := ny / nLength; |
| 1646 |
t2 := (x2 - x1) * nx + (y2 - y1) * ny; {parameter of the end point of the line, always >0, actually, equal to nLength} |
| 1647 |
w2 := Sqr(aWidth / 2); |
| 1648 |
dw2 := aWidth + 0.5; {double radius + 1} |
| 1649 |
|
| 1650 |
for iy := Round(MinY - aWidth / 2 - 1) to Round(MaxY + aWidth / 2 + 1) do |
| 1651 |
if (iy >= 0) and (iy < Height) then |
| 1652 |
begin |
| 1653 |
d1y := iy - y1; |
| 1654 |
d2y := iy - y2; |
| 1655 |
for ix := Round(MinX - aWidth / 2 - 1) to Round(MaxX + aWidth / 2 + 1) do |
| 1656 |
if (ix >= 0) and (ix < Width) then |
| 1657 |
begin |
| 1658 |
d1x := ix - x1; |
| 1659 |
d12 := Sqr(d1x) + Sqr(d1y); |
| 1660 |
t := d1x * nx + d1y * ny; |
| 1661 |
|
| 1662 |
if (t >= 0) and (t <= t2) then |
| 1663 |
begin |
| 1664 |
da2 := d12 - Sqr(t); |
| 1665 |
if da2 < w2 then |
| 1666 |
a := 1 |
| 1667 |
else |
| 1668 |
if da2 < w2 + dw2 then |
| 1669 |
a := (w2 + dw2 - da2) / dw2 |
| 1670 |
else |
| 1671 |
a := 0; |
| 1672 |
end |
| 1673 |
else |
| 1674 |
if d12 < w2 then |
| 1675 |
a := 1 |
| 1676 |
else |
| 1677 |
if d12 < w2 + dw2 then |
| 1678 |
a := (w2 + dw2 - d12) / dw2 |
| 1679 |
else |
| 1680 |
begin |
| 1681 |
d2x := ix - x2; |
| 1682 |
d22 := Sqr(d2x) + Sqr(d2y); |
| 1683 |
if d22 < w2 then |
| 1684 |
a := 1 |
| 1685 |
else |
| 1686 |
if d22 < w2 + dw2 then |
| 1687 |
a := (w2 + dw2 - d22) / dw2 |
| 1688 |
else |
| 1689 |
a := 0; |
| 1690 |
end; |
| 1691 |
|
| 1692 |
if a > 0 then |
| 1693 |
begin |
| 1694 |
p := PixelPtr(ix, iy); |
| 1695 |
Alpha1 := p^.Y / 255; |
| 1696 |
Alpha2d := Alpha2 * a; |
| 1697 |
|
| 1698 |
Alpha1d := Alpha1 * (1 - Alpha2d); |
| 1699 |
AlphaSum := Alpha1 + (1 - Alpha1) * Alpha2d; |
| 1700 |
if AlphaSum > 0 then begin |
| 1701 |
p^.X := Round((p^.X * Alpha1d + ByteColor * Alpha2d) / AlphaSum); |
| 1702 |
end; |
| 1703 |
p^.Y := Round(255 * AlphaSum); |
| 1704 |
end; |
| 1705 |
end; |
| 1706 |
end; |
| 1707 |
end; |
| 1708 |
|
| 1709 |
procedure TRGBImage.Line(const x1, y1, x2, y2: single; |
| 1710 |
const aWidth: single; const aColor: TCastleColor); |
| 1711 |
var |
| 1712 |
p: PVector3Byte; |
| 1713 |
ByteColor: TVector3Byte; |
| 1714 |
ix, iy: integer; |
| 1715 |
Alpha1d, Alpha2, Alpha2d: single; |
| 1716 |
MinX, MaxX, MinY, MaxY: single; |
| 1717 |
a: single; |
| 1718 |
d1x, d1y, d12, d2x, d2y, d22, nx, ny, nLength, t, t2, w2, dw2, da2: single; |
| 1719 |
begin |
| 1720 |
if x1 < x2 then |
| 1721 |
begin |
| 1722 |
MinX := x1; |
| 1723 |
MaxX := x2; |
| 1724 |
end |
| 1725 |
else |
| 1726 |
begin |
| 1727 |
MinX := x2; |
| 1728 |
MaxX := x1; |
| 1729 |
end; |
| 1730 |
if y1 < y2 then |
| 1731 |
begin |
| 1732 |
MinY := y1; |
| 1733 |
MaxY := y2; |
| 1734 |
end |
| 1735 |
else |
| 1736 |
begin |
| 1737 |
MinY := y2; |
| 1738 |
MaxY := y1; |
| 1739 |
end; |
| 1740 |
if MinX < 0 then MinX := 0; |
| 1741 |
if MinY < 0 then MinY := 0; |
| 1742 |
if MaxX > Width then MaxX := Width; |
| 1743 |
if MaxY > Height then MaxY := Height; |
| 1744 |
|
| 1745 |
ByteColor.X := Trunc(255 * aColor.X); |
| 1746 |
ByteColor.Y := Trunc(255 * aColor.Y); |
| 1747 |
ByteColor.Z := Trunc(255 * aColor.Z); |
| 1748 |
Alpha2 := aColor.W; |
| 1749 |
|
| 1750 |
nx := x2 - x1; {vector along the line} |
| 1751 |
ny := y2 - y1; |
| 1752 |
nLength := Sqrt(Sqr(nx) + Sqr(ny)); |
| 1753 |
nx := nx / nLength; |
| 1754 |
ny := ny / nLength; |
| 1755 |
t2 := (x2 - x1) * nx + (y2 - y1) * ny; {parameter of the end point of the line, always >0, actually, equal to nLength} |
| 1756 |
w2 := Sqr(aWidth / 2); |
| 1757 |
dw2 := aWidth + 0.5; {double radius + 1} |
| 1758 |
|
| 1759 |
for iy := Round(MinY - aWidth / 2 - 1) to Round(MaxY + aWidth / 2 + 1) do |
| 1760 |
if (iy >= 0) and (iy < Height) then |
| 1761 |
begin |
| 1762 |
d1y := iy - y1; |
| 1763 |
d2y := iy - y2; |
| 1764 |
for ix := Round(MinX - aWidth / 2 - 1) to Round(MaxX + aWidth / 2 + 1) do |
| 1765 |
if (ix >= 0) and (ix < Width) then |
| 1766 |
begin |
| 1767 |
d1x := ix - x1; |
| 1768 |
d12 := Sqr(d1x) + Sqr(d1y); |
| 1769 |
t := d1x * nx + d1y * ny; |
| 1770 |
|
| 1771 |
if (t >= 0) and (t <= t2) then |
| 1772 |
begin |
| 1773 |
da2 := d12 - Sqr(t); |
| 1774 |
if da2 < w2 then |
| 1775 |
a := 1 |
| 1776 |
else |
| 1777 |
if da2 < w2 + dw2 then |
| 1778 |
a := (w2 + dw2 - da2) / dw2 |
| 1779 |
else |
| 1780 |
a := 0; |
| 1781 |
end |
| 1782 |
else |
| 1783 |
if d12 < w2 then |
| 1784 |
a := 1 |
| 1785 |
else |
| 1786 |
if d12 < w2 + dw2 then |
| 1787 |
a := (w2 + dw2 - d12) / dw2 |
| 1788 |
else |
| 1789 |
begin |
| 1790 |
d2x := ix - x2; |
| 1791 |
d22 := Sqr(d2x) + Sqr(d2y); |
| 1792 |
if d22 < w2 then |
| 1793 |
a := 1 |
| 1794 |
else |
| 1795 |
if d22 < w2 + dw2 then |
| 1796 |
a := (w2 + dw2 - d22) / dw2 |
| 1797 |
else |
| 1798 |
a := 0; |
| 1799 |
end; |
| 1800 |
|
| 1801 |
if a > 0 then |
| 1802 |
begin |
| 1803 |
p := PixelPtr(ix, iy); |
| 1804 |
Alpha2d := Alpha2 * a; |
| 1805 |
|
| 1806 |
Alpha1d := 1 - Alpha2d; |
| 1807 |
p^.X := Round((p^.X * Alpha1d + ByteColor.X * Alpha2d)); |
| 1808 |
p^.Y := Round((p^.Y * Alpha1d + ByteColor.Y * Alpha2d)); |
| 1809 |
p^.Z := Round((p^.Z * Alpha1d + ByteColor.Z * Alpha2d)); |
| 1810 |
end; |
| 1811 |
end; |
| 1812 |
end; |
| 1813 |
end; |
| 1814 |
|
| 1815 |
procedure TGrayscaleImage.Line(const x1, y1, x2, y2: single; |
| 1816 |
const aWidth: single; const aColor: TCastleColor); |
| 1817 |
var |
| 1818 |
p: PByte; |
| 1819 |
ByteColor: Byte; |
| 1820 |
ix, iy: integer; |
| 1821 |
Alpha1d, Alpha2, Alpha2d: single; |
| 1822 |
MinX, MaxX, MinY, MaxY: single; |
| 1823 |
a: single; |
| 1824 |
d1x, d1y, d12, d2x, d2y, d22, nx, ny, nLength, t, t2, w2, dw2, da2: single; |
| 1825 |
begin |
| 1826 |
if x1 < x2 then |
| 1827 |
begin |
| 1828 |
MinX := x1; |
| 1829 |
MaxX := x2; |
| 1830 |
end |
| 1831 |
else |
| 1832 |
begin |
| 1833 |
MinX := x2; |
| 1834 |
MaxX := x1; |
| 1835 |
end; |
| 1836 |
if y1 < y2 then |
| 1837 |
begin |
| 1838 |
MinY := y1; |
| 1839 |
MaxY := y2; |
| 1840 |
end |
| 1841 |
else |
| 1842 |
begin |
| 1843 |
MinY := y2; |
| 1844 |
MaxY := y1; |
| 1845 |
end; |
| 1846 |
if MinX < 0 then MinX := 0; |
| 1847 |
if MinY < 0 then MinY := 0; |
| 1848 |
if MaxX > Width then MaxX := Width; |
| 1849 |
if MaxY > Height then MaxY := Height; |
| 1850 |
|
| 1851 |
ByteColor := GrayscaleValue(Vector3Byte(Vector3(aColor.X, aColor.Y, aColor.Z))); |
| 1852 |
Alpha2 := aColor.W; |
| 1853 |
nx := x2 - x1; {vector along the line} |
| 1854 |
ny := y2 - y1; |
| 1855 |
nLength := Sqrt(Sqr(nx) + Sqr(ny)); |
| 1856 |
nx := nx / nLength; |
| 1857 |
ny := ny / nLength; |
| 1858 |
t2 := (x2 - x1) * nx + (y2 - y1) * ny; {parameter of the end point of the line, always >0, actually, equal to nLength} |
| 1859 |
w2 := Sqr(aWidth / 2); |
| 1860 |
dw2 := aWidth + 0.5; {double radius + 1} |
| 1861 |
|
| 1862 |
for iy := Round(MinY - aWidth / 2 - 1) to Round(MaxY + aWidth / 2 + 1) do |
| 1863 |
if (iy >= 0) and (iy < Height) then |
| 1864 |
begin |
| 1865 |
d1y := iy - y1; |
| 1866 |
d2y := iy - y2; |
| 1867 |
for ix := Round(MinX - aWidth / 2 - 1) to Round(MaxX + aWidth / 2 + 1) do |
| 1868 |
if (ix >= 0) and (ix < Width) then |
| 1869 |
begin |
| 1870 |
d1x := ix - x1; |
| 1871 |
d12 := Sqr(d1x) + Sqr(d1y); |
| 1872 |
t := d1x * nx + d1y * ny; |
| 1873 |
|
| 1874 |
if (t >= 0) and (t <= t2) then |
| 1875 |
begin |
| 1876 |
da2 := d12 - Sqr(t); |
| 1877 |
if da2 < w2 then |
| 1878 |
a := 1 |
| 1879 |
else |
| 1880 |
if da2 < w2 + dw2 then |
| 1881 |
a := (w2 + dw2 - da2) / dw2 |
| 1882 |
else |
| 1883 |
a := 0; |
| 1884 |
end |
| 1885 |
else |
| 1886 |
if d12 < w2 then |
| 1887 |
a := 1 |
| 1888 |
else |
| 1889 |
if d12 < w2 + dw2 then |
| 1890 |
a := (w2 + dw2 - d12) / dw2 |
| 1891 |
else |
| 1892 |
begin |
| 1893 |
d2x := ix - x2; |
| 1894 |
d22 := Sqr(d2x) + Sqr(d2y); |
| 1895 |
if d22 < w2 then |
| 1896 |
a := 1 |
| 1897 |
else |
| 1898 |
if d22 < w2 + dw2 then |
| 1899 |
a := (w2 + dw2 - d22) / dw2 |
| 1900 |
else |
| 1901 |
a := 0; |
| 1902 |
end; |
| 1903 |
|
| 1904 |
if a > 0 then |
| 1905 |
begin |
| 1906 |
p := PixelPtr(ix, iy); |
| 1907 |
Alpha2d := Alpha2 * a; |
| 1908 |
|
| 1909 |
Alpha1d := 1 - Alpha2d; |
| 1910 |
p^ := Round((p^ * Alpha1d + ByteColor * Alpha2d)); |
| 1911 |
end; |
| 1912 |
end; |
| 1913 |
end; |
| 1914 |
end; |
| 1915 |
|
| 1916 |
{ -----= FLOOD FILL =----- } |
| 1917 |
|
| 1918 |
{ As this algorithm is extremely inefficient, there is only one variant at this |
| 1919 |
moment. However, as far as it is an extremely rare use case, maybe, there is |
| 1920 |
no actual need to improve it ever. } |
| 1921 |
procedure TCastleImage.FloodFill(const x, y: integer; const aColor: TCastleColor; |
| 1922 |
const aThreshold: single = 0); |
| 1923 |
var |
| 1924 |
OldColor: TCastleColor; |
| 1925 |
ix, iy: integer; |
| 1926 |
x1, y1, x2, y2: integer; |
| 1927 |
aFinished: boolean; |
| 1928 |
Flood: array of boolean; |
| 1929 |
function isFloodColor(const ax, ay: integer): boolean; {$ifdef FPC}{$IFDEF SUPPORTS_INLINE}Inline;{$ENDIF}{$endif} |
| 1930 |
begin |
| 1931 |
if (ax >= 0) and (ay >=0) and (ax <= Width) and (ay <= Height) then |
| 1932 |
begin |
| 1933 |
if Flood[ax + ay * Height] then |
| 1934 |
Result := true |
| 1935 |
else |
| 1936 |
Result := false; |
| 1937 |
end |
| 1938 |
else |
| 1939 |
Result := false; |
| 1940 |
end; |
| 1941 |
function NearbyFloodColor: boolean; |
| 1942 |
begin |
| 1943 |
Result := isFloodColor(ix - 1, iy - 1) or isFloodColor(ix, iy - 1) |
| 1944 |
or isFloodColor(ix + 1, iy - 1) or isFloodColor(ix - 1, iy) |
| 1945 |
or isFloodColor(ix + 1, iy) or isFloodColor(ix - 1, iy + 1) |
| 1946 |
or isFloodColor(ix, iy + 1) or isFloodColor(ix + 1, iy + 1); |
| 1947 |
end; |
| 1948 |
begin |
| 1949 |
x1 := x - 1; |
| 1950 |
x2 := x + 1; |
| 1951 |
y1 := y - 1; |
| 1952 |
y2 := y + 1; |
| 1953 |
SetLength(Flood, Width * Height); |
| 1954 |
for ix := Low(Flood) to High(Flood) do Flood[ix] := false; |
| 1955 |
OldColor := Colors[x, y, 0]; {grab the OldColor} |
| 1956 |
Flood[x + y * Height] := true; {init the flood seed} |
| 1957 |
repeat |
| 1958 |
aFinished := true; |
| 1959 |
if x1 < 0 then x1 := 0; |
| 1960 |
if x1 >= Width then x1 := Width - 1; |
| 1961 |
if y1 < 0 then y1 := 0; |
| 1962 |
if y1 >= Height then y1 := Height - 1; |
| 1963 |
for ix := x1 to x2 do |
| 1964 |
for iy := y1 to y2 do |
| 1965 |
if not Flood[ix + iy * Height] and |
| 1966 |
((Colors[ix, iy, 0] - OldColor).Length < aThreshold) and |
| 1967 |
NearbyFloodColor then |
| 1968 |
begin |
| 1969 |
Flood[ix + iy * Height] := true; |
| 1970 |
aFinished := false; |
| 1971 |
if (ix = x1) then dec(x1); |
| 1972 |
if (ix = x2) then inc(x2); |
| 1973 |
if (iy = y1) then dec(y1); |
| 1974 |
if (iy = y2) then inc(y2); |
| 1975 |
end; |
| 1976 |
until aFinished; |
| 1977 |
//and paint the flood with the aColor |
| 1978 |
for ix := x1 to x2 do |
| 1979 |
for iy := y1 to y2 do |
| 1980 |
if Flood[ix + iy * Height] then |
| 1981 |
Colors[ix, iy, 0] := aColor; |
| 1982 |
end; |
| 1983 |
|