| 1 | unit UFGraphics;
|
|---|
| 2 |
|
|---|
| 3 | {$mode delphi}
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | Classes, SysUtils, Graphics, UGGraphics, UPixmapSpecialized, Fgl;
|
|---|
| 9 |
|
|---|
| 10 | type
|
|---|
| 11 | TColorName = (cnBlack, cnWhite, cnBlue, cnRed, cnGreen, cnGray, cnSilver);
|
|---|
| 12 |
|
|---|
| 13 | IBColor = interface
|
|---|
| 14 | procedure SetColorName(ColorName: TColorName);
|
|---|
| 15 | procedure SetColor(Color: TColor);
|
|---|
| 16 | procedure SetRandom;
|
|---|
| 17 | end;
|
|---|
| 18 |
|
|---|
| 19 | { TBColor }
|
|---|
| 20 |
|
|---|
| 21 | TBColor = class(TInterfacedObject, IBColor)
|
|---|
| 22 | procedure SetColorName(ColorName: TColorName); virtual;
|
|---|
| 23 | procedure SetColor(Color: TColor); virtual;
|
|---|
| 24 | procedure SetRandom; virtual;
|
|---|
| 25 | end;
|
|---|
| 26 |
|
|---|
| 27 | IBColorClass = class of TBColor;
|
|---|
| 28 |
|
|---|
| 29 | { TBPixmap }
|
|---|
| 30 |
|
|---|
| 31 | TBPixmap = class
|
|---|
| 32 | public
|
|---|
| 33 | type
|
|---|
| 34 | TGetColorPos = function (Position: TPoint): IBColor of object;
|
|---|
| 35 | private
|
|---|
| 36 | FSize: TPoint;
|
|---|
| 37 | protected
|
|---|
| 38 | function GetPixel(X, Y: Integer): IBColor; virtual;
|
|---|
| 39 | procedure SetPixel(X, Y: Integer; AValue: IBColor); virtual;
|
|---|
| 40 | procedure SetSize(AValue: TPoint); virtual;
|
|---|
| 41 | public
|
|---|
| 42 | procedure Mirror; virtual;
|
|---|
| 43 | procedure Flip; virtual;
|
|---|
| 44 | procedure Negative; virtual;
|
|---|
| 45 | procedure Fill(Color: IBColor); virtual; overload;
|
|---|
| 46 | procedure Fill(Func: TGetColorPos); virtual; overload;
|
|---|
| 47 | procedure Line(P1, P2: TPoint; Color: IBColor); virtual;
|
|---|
| 48 | procedure PaintToCanvas(Canvas: TCanvas); virtual; overload;
|
|---|
| 49 | procedure PaintToCanvas(Canvas: TCanvas; Rect: TRect); virtual; overload;
|
|---|
| 50 | procedure PaintToBitmap(Bitmap: TBitmap; Rect: TRect); virtual;
|
|---|
| 51 | procedure LoadFromCanvas(Canvas: TCanvas); virtual;
|
|---|
| 52 | procedure LoadFromBitmap(Bitmap: TBitmap); virtual;
|
|---|
| 53 | function GetDataSize: Integer; virtual;
|
|---|
| 54 | constructor Create; virtual;
|
|---|
| 55 | property Size: TPoint read FSize write SetSize;
|
|---|
| 56 | property Pixels[X, Y: Integer]: IBColor read GetPixel write SetPixel;
|
|---|
| 57 | end;
|
|---|
| 58 |
|
|---|
| 59 | TBPixmapClass = class of TBPixmap;
|
|---|
| 60 |
|
|---|
| 61 | { TColorFormatChannel }
|
|---|
| 62 |
|
|---|
| 63 | TColorFormatChannel = record
|
|---|
| 64 | Name: string;
|
|---|
| 65 | Position: Integer;
|
|---|
| 66 | BitWidth: Integer;
|
|---|
| 67 | end;
|
|---|
| 68 |
|
|---|
| 69 | { TColorFormat }
|
|---|
| 70 |
|
|---|
| 71 | TColorFormat = class
|
|---|
| 72 | Name: string;
|
|---|
| 73 | BitDepth: Integer;
|
|---|
| 74 | Channels: array of TColorFormatChannel;
|
|---|
| 75 | BackendColorClass: IBColorClass;
|
|---|
| 76 | BackendPixmapClass: TBPixmapClass;
|
|---|
| 77 | procedure AddChannel(Name: string; Position, BitWidth: Integer);
|
|---|
| 78 | function GetBackendColor: IBColor;
|
|---|
| 79 | function GetBackendImage: TBPixmap;
|
|---|
| 80 | constructor Create; virtual;
|
|---|
| 81 | function GetChannelStateCount(Channel: Integer): Integer;
|
|---|
| 82 | end;
|
|---|
| 83 |
|
|---|
| 84 | TColorFormats = class(TFPGObjectList<TColorFormat>)
|
|---|
| 85 | end;
|
|---|
| 86 |
|
|---|
| 87 | TColorFormatClass = class of TColorFormat;
|
|---|
| 88 |
|
|---|
| 89 | { TColorFormatManager }
|
|---|
| 90 |
|
|---|
| 91 | TColorFormatManager = class
|
|---|
| 92 | private
|
|---|
| 93 | FFormats: TColorFormats;
|
|---|
| 94 | function GetFormat(Index: Integer): TColorFormat;
|
|---|
| 95 | public
|
|---|
| 96 | constructor Create; virtual;
|
|---|
| 97 | destructor Destroy; override;
|
|---|
| 98 | function FindByName(Name: string): Integer;
|
|---|
| 99 | procedure RegisterFormat(Format: TColorFormatClass);
|
|---|
| 100 | function FormatCount: Integer;
|
|---|
| 101 | property Formats: TColorFormats read FFormats;
|
|---|
| 102 | end;
|
|---|
| 103 |
|
|---|
| 104 | IFColor = interface
|
|---|
| 105 | end;
|
|---|
| 106 |
|
|---|
| 107 | { TFColor }
|
|---|
| 108 |
|
|---|
| 109 | TFColor = class(TInterfacedObject, IFColor)
|
|---|
| 110 | private
|
|---|
| 111 | FBackend: IBColor;
|
|---|
| 112 | FColorFormat: TColorFormat;
|
|---|
| 113 | procedure SetColorFormat(AValue: TColorFormat);
|
|---|
| 114 | public
|
|---|
| 115 | property Backend: IBColor read FBackend;
|
|---|
| 116 | property ColorFormat: TColorFormat read FColorFormat write SetColorFormat;
|
|---|
| 117 | procedure SetColorName(ColorName: TColorName);
|
|---|
| 118 | procedure SetRandom;
|
|---|
| 119 | procedure SetColor(Color: TColor);
|
|---|
| 120 | constructor Create; overload;
|
|---|
| 121 | constructor Create(ColorFormat: TColorFormat; ColorName: TColorName); overload;
|
|---|
| 122 | constructor Create(ColorFormat: TColorFormat; Color: TColor); overload;
|
|---|
| 123 | destructor Destroy; override;
|
|---|
| 124 | end;
|
|---|
| 125 |
|
|---|
| 126 | TFCanvas = class;
|
|---|
| 127 | TFPixmap = class;
|
|---|
| 128 |
|
|---|
| 129 | { TFBrush }
|
|---|
| 130 |
|
|---|
| 131 | TFBrush = class
|
|---|
| 132 | Color: IFColor;
|
|---|
| 133 | Canvas: TFCanvas;
|
|---|
| 134 | end;
|
|---|
| 135 |
|
|---|
| 136 | { TFPen }
|
|---|
| 137 |
|
|---|
| 138 | TFPen = class
|
|---|
| 139 | Position: TPoint;
|
|---|
| 140 | Color: IFColor;
|
|---|
| 141 | Canvas: TFCanvas;
|
|---|
| 142 | procedure MoveTo(Pos: TPoint);
|
|---|
| 143 | procedure LineTo(Pos: TPoint);
|
|---|
| 144 | end;
|
|---|
| 145 |
|
|---|
| 146 | { TFCanvas }
|
|---|
| 147 |
|
|---|
| 148 | TFCanvas = class
|
|---|
| 149 | Pixmap: TFPixmap;
|
|---|
| 150 | Pen: TFPen;
|
|---|
| 151 | Brush: TFBrush;
|
|---|
| 152 | constructor Create;
|
|---|
| 153 | destructor Destroy; override;
|
|---|
| 154 | end;
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 | { TFPixmap }
|
|---|
| 158 |
|
|---|
| 159 | TFPixmap = class(TComponent)
|
|---|
| 160 | public
|
|---|
| 161 | type
|
|---|
| 162 | TGetColorPos = function (Position: TPoint; ColorFormat: TColorFormat): IFColor of object;
|
|---|
| 163 | private
|
|---|
| 164 | FBackend: TBPixmap;
|
|---|
| 165 | FCanvas: TFCanvas;
|
|---|
| 166 | FColorFormat: TColorFormat;
|
|---|
| 167 | FSize: TPoint;
|
|---|
| 168 | FillCallBack: TGetColorPos;
|
|---|
| 169 | function FillGetColor(Position: TPoint): IBColor;
|
|---|
| 170 | function GetPixel(X, Y: Integer): IFColor;
|
|---|
| 171 | procedure SetColorFormat(AValue: TColorFormat);
|
|---|
| 172 | procedure SetPixel(X, Y: Integer; AValue: IFColor);
|
|---|
| 173 | procedure SetSize(AValue: TPoint);
|
|---|
| 174 | function ColorRandom(Position: TPoint; ColorFormat: TColorFormat): IFColor;
|
|---|
| 175 | public
|
|---|
| 176 | procedure Clear;
|
|---|
| 177 | procedure Flip;
|
|---|
| 178 | procedure Mirror;
|
|---|
| 179 | procedure Gradient;
|
|---|
| 180 | procedure Negative;
|
|---|
| 181 | procedure Random;
|
|---|
| 182 | procedure Fill(Color: IFColor); overload;
|
|---|
| 183 | procedure Fill(Func: TGetColorPos); overload;
|
|---|
| 184 | procedure PaintToCanvas(Canvas: TCanvas); overload;
|
|---|
| 185 | procedure PaintToCanvas(Canvas: TCanvas; Rect: TRect); overload;
|
|---|
| 186 | procedure PaintToBitmap(Bitmap: TBitmap; Rect: TRect); overload;
|
|---|
| 187 | procedure LoadFromCanvas(Canvas: TCanvas);
|
|---|
| 188 | procedure LoadFromBitmap(Bitmap: TBitmap);
|
|---|
| 189 | function GetDataSize: Integer;
|
|---|
| 190 | constructor Create(AOwner: TComponent); override;
|
|---|
| 191 | destructor Destroy; override;
|
|---|
| 192 | property Canvas: TFCanvas read FCanvas;
|
|---|
| 193 | property Backend: TBPixmap read FBackend;
|
|---|
| 194 | property ColorFormat: TColorFormat read FColorFormat write SetColorFormat;
|
|---|
| 195 | property Size: TPoint read FSize write SetSize;
|
|---|
| 196 | property Pixels[X, Y: Integer]: IFColor read GetPixel write SetPixel;
|
|---|
| 197 | end;
|
|---|
| 198 |
|
|---|
| 199 | procedure Register;
|
|---|
| 200 |
|
|---|
| 201 | var
|
|---|
| 202 | ColorFormatManager: TColorFormatManager;
|
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 | implementation
|
|---|
| 206 |
|
|---|
| 207 | uses
|
|---|
| 208 | UColorGray1, UColorGray2,UColorGray4, UColorGray8, UColorRGB8, UColorRGBA8,
|
|---|
| 209 | UColorRGB565, UColorRGB16;
|
|---|
| 210 |
|
|---|
| 211 | procedure Register;
|
|---|
| 212 | begin
|
|---|
| 213 | RegisterComponents('FastGraphics', [TFPixmap]);
|
|---|
| 214 | end;
|
|---|
| 215 |
|
|---|
| 216 | { TFPen }
|
|---|
| 217 |
|
|---|
| 218 | procedure TFPen.MoveTo(Pos: TPoint);
|
|---|
| 219 | begin
|
|---|
| 220 | Position := Pos;
|
|---|
| 221 | end;
|
|---|
| 222 |
|
|---|
| 223 | procedure TFPen.LineTo(Pos: TPoint);
|
|---|
| 224 | begin
|
|---|
| 225 | Canvas.Pixmap.Backend.Line(Position, Pos, (Color as TFColor).Backend);
|
|---|
| 226 | Position := Pos;
|
|---|
| 227 | end;
|
|---|
| 228 |
|
|---|
| 229 | { TFCanvas }
|
|---|
| 230 |
|
|---|
| 231 | constructor TFCanvas.Create;
|
|---|
| 232 | begin
|
|---|
| 233 | Pen := TFPen.Create;
|
|---|
| 234 | Pen.Canvas := Self;
|
|---|
| 235 | Brush := TFBrush.Create;
|
|---|
| 236 | Brush.Canvas := Self;
|
|---|
| 237 | end;
|
|---|
| 238 |
|
|---|
| 239 | destructor TFCanvas.Destroy;
|
|---|
| 240 | begin
|
|---|
| 241 | FreeAndNil(Pen);
|
|---|
| 242 | FreeAndNil(Brush);
|
|---|
| 243 | inherited Destroy;
|
|---|
| 244 | end;
|
|---|
| 245 |
|
|---|
| 246 | { TBColor }
|
|---|
| 247 |
|
|---|
| 248 | procedure TBColor.SetColorName(ColorName: TColorName);
|
|---|
| 249 | begin
|
|---|
| 250 | end;
|
|---|
| 251 |
|
|---|
| 252 | procedure TBColor.SetColor(Color: TColor);
|
|---|
| 253 | begin
|
|---|
| 254 | end;
|
|---|
| 255 |
|
|---|
| 256 | procedure TBColor.SetRandom;
|
|---|
| 257 | begin
|
|---|
| 258 | end;
|
|---|
| 259 |
|
|---|
| 260 | { TColorFormatManager }
|
|---|
| 261 |
|
|---|
| 262 | function TColorFormatManager.GetFormat(Index: Integer): TColorFormat;
|
|---|
| 263 | begin
|
|---|
| 264 | Result := TColorFormat(FFormats[Index]);
|
|---|
| 265 | end;
|
|---|
| 266 |
|
|---|
| 267 | constructor TColorFormatManager.Create;
|
|---|
| 268 | begin
|
|---|
| 269 | FFormats := TColorFormats.Create;
|
|---|
| 270 | end;
|
|---|
| 271 |
|
|---|
| 272 | destructor TColorFormatManager.Destroy;
|
|---|
| 273 | begin
|
|---|
| 274 | FreeAndNil(FFormats);
|
|---|
| 275 | inherited Destroy;
|
|---|
| 276 | end;
|
|---|
| 277 |
|
|---|
| 278 | function TColorFormatManager.FindByName(Name: string): Integer;
|
|---|
| 279 | var
|
|---|
| 280 | I: Integer;
|
|---|
| 281 | begin
|
|---|
| 282 | Result := -1;
|
|---|
| 283 | for I := 0 to FFormats.Count - 1 do begin
|
|---|
| 284 | if FFormats[I].Name = Name then begin
|
|---|
| 285 | Result := I;
|
|---|
| 286 | Break;
|
|---|
| 287 | end;
|
|---|
| 288 | end;
|
|---|
| 289 | end;
|
|---|
| 290 |
|
|---|
| 291 | procedure TColorFormatManager.RegisterFormat(Format: TColorFormatClass);
|
|---|
| 292 | begin
|
|---|
| 293 | FFormats.Add(Format.Create);
|
|---|
| 294 | end;
|
|---|
| 295 |
|
|---|
| 296 | function TColorFormatManager.FormatCount: Integer;
|
|---|
| 297 | begin
|
|---|
| 298 | Result := FFormats.Count;
|
|---|
| 299 | end;
|
|---|
| 300 |
|
|---|
| 301 | { TColorFormat }
|
|---|
| 302 |
|
|---|
| 303 | procedure TColorFormat.AddChannel(Name: string; Position, BitWidth: Integer);
|
|---|
| 304 | begin
|
|---|
| 305 | SetLength(Channels, Length(Channels) + 1);
|
|---|
| 306 | Channels[Length(Channels) - 1].Name := Name;
|
|---|
| 307 | Channels[Length(Channels) - 1].Position := Position;
|
|---|
| 308 | Channels[Length(Channels) - 1].BitWidth := BitWidth;
|
|---|
| 309 | end;
|
|---|
| 310 |
|
|---|
| 311 | function TColorFormat.GetBackendColor: IBColor;
|
|---|
| 312 | begin
|
|---|
| 313 | Result := BackendColorClass.Create;
|
|---|
| 314 | end;
|
|---|
| 315 |
|
|---|
| 316 | function TColorFormat.GetBackendImage: TBPixmap;
|
|---|
| 317 | begin
|
|---|
| 318 | Result := BackendPixmapClass.Create;
|
|---|
| 319 | end;
|
|---|
| 320 |
|
|---|
| 321 | constructor TColorFormat.Create;
|
|---|
| 322 | begin
|
|---|
| 323 | Name := 'None';
|
|---|
| 324 | BitDepth := 0;
|
|---|
| 325 | BackendColorClass := TBColor;
|
|---|
| 326 | BackendPixmapClass := TBPixmap;
|
|---|
| 327 | end;
|
|---|
| 328 |
|
|---|
| 329 | function TColorFormat.GetChannelStateCount(Channel: Integer): Integer;
|
|---|
| 330 | begin
|
|---|
| 331 | Result := 1 shl Channels[Channel].BitWidth;
|
|---|
| 332 | end;
|
|---|
| 333 |
|
|---|
| 334 | { TFColor }
|
|---|
| 335 |
|
|---|
| 336 | procedure TFColor.SetColorFormat(AValue: TColorFormat);
|
|---|
| 337 | begin
|
|---|
| 338 | if FColorFormat = AValue then Exit;
|
|---|
| 339 | FBackend := AValue.GetBackendColor;
|
|---|
| 340 | FColorFormat := AValue;
|
|---|
| 341 | end;
|
|---|
| 342 |
|
|---|
| 343 | procedure TFColor.SetColorName(ColorName: TColorName);
|
|---|
| 344 | begin
|
|---|
| 345 | FBackend.SetColorName(ColorName);
|
|---|
| 346 | end;
|
|---|
| 347 |
|
|---|
| 348 | procedure TFColor.SetRandom;
|
|---|
| 349 | begin
|
|---|
| 350 | FBackend.SetRandom;
|
|---|
| 351 | end;
|
|---|
| 352 |
|
|---|
| 353 | procedure TFColor.SetColor(Color: TColor);
|
|---|
| 354 | begin
|
|---|
| 355 | Backend.SetColor(Color);
|
|---|
| 356 | end;
|
|---|
| 357 |
|
|---|
| 358 | constructor TFColor.Create;
|
|---|
| 359 | begin
|
|---|
| 360 | ColorFormat := ColorFormatManager.GetFormat(0);
|
|---|
| 361 | end;
|
|---|
| 362 |
|
|---|
| 363 | constructor TFColor.Create(ColorFormat: TColorFormat; ColorName: TColorName);
|
|---|
| 364 | begin
|
|---|
| 365 | Self.ColorFormat := ColorFormat;
|
|---|
| 366 | Backend.SetColorName(ColorName);
|
|---|
| 367 | end;
|
|---|
| 368 |
|
|---|
| 369 | constructor TFColor.Create(ColorFormat: TColorFormat; Color: TColor);
|
|---|
| 370 | begin
|
|---|
| 371 | Self.ColorFormat := ColorFormat;
|
|---|
| 372 | Backend.SetColor(Color);
|
|---|
| 373 | end;
|
|---|
| 374 |
|
|---|
| 375 | destructor TFColor.Destroy;
|
|---|
| 376 | begin
|
|---|
| 377 | FColorFormat := nil;
|
|---|
| 378 | inherited Destroy;
|
|---|
| 379 | end;
|
|---|
| 380 |
|
|---|
| 381 | { TBPixmap }
|
|---|
| 382 |
|
|---|
| 383 | function TBPixmap.GetPixel(X, Y: Integer): IBColor;
|
|---|
| 384 | begin
|
|---|
| 385 | Result := TBColor.Create;
|
|---|
| 386 | end;
|
|---|
| 387 |
|
|---|
| 388 | procedure TBPixmap.SetPixel(X, Y: Integer; AValue: IBColor);
|
|---|
| 389 | begin
|
|---|
| 390 | end;
|
|---|
| 391 |
|
|---|
| 392 | procedure TBPixmap.SetSize(AValue: TPoint);
|
|---|
| 393 | begin
|
|---|
| 394 | if (FSize.X = AValue.X) and (FSize.Y = AValue.Y) then Exit;
|
|---|
| 395 | FSize := AValue;
|
|---|
| 396 | end;
|
|---|
| 397 |
|
|---|
| 398 | procedure TBPixmap.Mirror;
|
|---|
| 399 | begin
|
|---|
| 400 | end;
|
|---|
| 401 |
|
|---|
| 402 | procedure TBPixmap.Flip;
|
|---|
| 403 | begin
|
|---|
| 404 | end;
|
|---|
| 405 |
|
|---|
| 406 | procedure TBPixmap.Negative;
|
|---|
| 407 | begin
|
|---|
| 408 | end;
|
|---|
| 409 |
|
|---|
| 410 | procedure TBPixmap.Fill(Color: IBColor);
|
|---|
| 411 | begin
|
|---|
| 412 | end;
|
|---|
| 413 |
|
|---|
| 414 | procedure TBPixmap.Fill(Func: TGetColorPos);
|
|---|
| 415 | begin
|
|---|
| 416 | end;
|
|---|
| 417 |
|
|---|
| 418 | procedure TBPixmap.Line(P1, P2: TPoint; Color: IBColor);
|
|---|
| 419 | begin
|
|---|
| 420 | end;
|
|---|
| 421 |
|
|---|
| 422 | procedure TBPixmap.PaintToCanvas(Canvas: TCanvas);
|
|---|
| 423 | begin
|
|---|
| 424 | end;
|
|---|
| 425 |
|
|---|
| 426 | procedure TBPixmap.PaintToCanvas(Canvas: TCanvas; Rect: TRect);
|
|---|
| 427 | begin
|
|---|
| 428 | end;
|
|---|
| 429 |
|
|---|
| 430 | procedure TBPixmap.PaintToBitmap(Bitmap: TBitmap; Rect: TRect);
|
|---|
| 431 | begin
|
|---|
| 432 | end;
|
|---|
| 433 |
|
|---|
| 434 | procedure TBPixmap.LoadFromCanvas(Canvas: TCanvas);
|
|---|
| 435 | begin
|
|---|
| 436 | end;
|
|---|
| 437 |
|
|---|
| 438 | procedure TBPixmap.LoadFromBitmap(Bitmap: TBitmap);
|
|---|
| 439 | begin
|
|---|
| 440 | end;
|
|---|
| 441 |
|
|---|
| 442 | function TBPixmap.GetDataSize: Integer;
|
|---|
| 443 | begin
|
|---|
| 444 | Result := 0;
|
|---|
| 445 | end;
|
|---|
| 446 |
|
|---|
| 447 | constructor TBPixmap.Create;
|
|---|
| 448 | begin
|
|---|
| 449 | Size := Point(0, 0);
|
|---|
| 450 | end;
|
|---|
| 451 |
|
|---|
| 452 | { TFPixmap }
|
|---|
| 453 |
|
|---|
| 454 | procedure TFPixmap.SetColorFormat(AValue: TColorFormat);
|
|---|
| 455 | begin
|
|---|
| 456 | if FColorFormat = AValue then Exit;
|
|---|
| 457 | FBackend.Free;
|
|---|
| 458 | FBackend := AValue.GetBackendImage;
|
|---|
| 459 | FBackend.Size := FSize;
|
|---|
| 460 | FColorFormat := AValue;
|
|---|
| 461 | end;
|
|---|
| 462 |
|
|---|
| 463 | function TFPixmap.FillGetColor(Position: TPoint): IBColor;
|
|---|
| 464 | begin
|
|---|
| 465 | Result := (FillCallBack(Position, ColorFormat) as TFColor).Backend;
|
|---|
| 466 | end;
|
|---|
| 467 |
|
|---|
| 468 | function TFPixmap.GetPixel(X, Y: Integer): IFColor;
|
|---|
| 469 | begin
|
|---|
| 470 | Result := TFColor.Create;
|
|---|
| 471 | (Result as TFColor).ColorFormat := ColorFormat;
|
|---|
| 472 | (Result as TFColor).FBackend := FBackend.Pixels[X, Y];
|
|---|
| 473 | end;
|
|---|
| 474 |
|
|---|
| 475 | procedure TFPixmap.SetPixel(X, Y: Integer; AValue: IFColor);
|
|---|
| 476 | begin
|
|---|
| 477 | FBackend.Pixels[X, Y] := (AValue as TFColor).FBackend;
|
|---|
| 478 | end;
|
|---|
| 479 |
|
|---|
| 480 | procedure TFPixmap.SetSize(AValue: TPoint);
|
|---|
| 481 | begin
|
|---|
| 482 | if (FSize.X = AValue.X) and (FSize.Y = AValue.Y) then Exit;
|
|---|
| 483 | FSize := AValue;
|
|---|
| 484 | FBackend.Size := AValue;
|
|---|
| 485 | end;
|
|---|
| 486 |
|
|---|
| 487 | function TFPixmap.ColorRandom(Position: TPoint; ColorFormat: TColorFormat
|
|---|
| 488 | ): IFColor;
|
|---|
| 489 | begin
|
|---|
| 490 | Result := TFColor.Create;
|
|---|
| 491 | (Result as TFColor).ColorFormat := ColorFormat;
|
|---|
| 492 | (Result as TFColor).SetRandom;
|
|---|
| 493 | end;
|
|---|
| 494 |
|
|---|
| 495 | procedure TFPixmap.Clear;
|
|---|
| 496 | begin
|
|---|
| 497 |
|
|---|
| 498 | end;
|
|---|
| 499 |
|
|---|
| 500 | procedure TFPixmap.Flip;
|
|---|
| 501 | begin
|
|---|
| 502 | FBackend.Flip;
|
|---|
| 503 | end;
|
|---|
| 504 |
|
|---|
| 505 | procedure TFPixmap.Mirror;
|
|---|
| 506 | begin
|
|---|
| 507 | FBackend.Mirror;
|
|---|
| 508 | end;
|
|---|
| 509 |
|
|---|
| 510 | procedure TFPixmap.Gradient;
|
|---|
| 511 | var
|
|---|
| 512 | X, Y: Integer;
|
|---|
| 513 | Color: IFColor;
|
|---|
| 514 | begin
|
|---|
| 515 | Color := TFColor.Create;
|
|---|
| 516 | (Color as TFColor).ColorFormat := ColorFormat;
|
|---|
| 517 | for Y := 0 to Size.Y div 4 - 1 do
|
|---|
| 518 | for X := 0 to Size.X - 1 do begin
|
|---|
| 519 | (Color as TFColor).SetColor(RGBToColor(
|
|---|
| 520 | Trunc(X / Size.X * 256),
|
|---|
| 521 | 0,
|
|---|
| 522 | 0
|
|---|
| 523 | ));
|
|---|
| 524 | Pixels[X, Y] := Color;
|
|---|
| 525 | end;
|
|---|
| 526 | for Y := Size.Y div 4 to 2 * Size.Y div 4 - 1 do
|
|---|
| 527 | for X := 0 to Size.X - 1 do begin
|
|---|
| 528 | (Color as TFColor).SetColor(RGBToColor(
|
|---|
| 529 | 0,
|
|---|
| 530 | Trunc(X / Size.X * 256),
|
|---|
| 531 | 0
|
|---|
| 532 | ));
|
|---|
| 533 | Pixels[X, Y] := Color;
|
|---|
| 534 | end;
|
|---|
| 535 | for Y := 2 * Size.Y div 4 to 3 * Size.Y div 4 - 1 do
|
|---|
| 536 | for X := 0 to Size.X - 1 do begin
|
|---|
| 537 | (Color as TFColor).SetColor(RGBToColor(
|
|---|
| 538 | 0,
|
|---|
| 539 | 0,
|
|---|
| 540 | Trunc(X / Size.X * 256)
|
|---|
| 541 | ));
|
|---|
| 542 | Pixels[X, Y] := Color;
|
|---|
| 543 | end;
|
|---|
| 544 | for Y := 3 * Size.Y div 4 to Size.Y - 1 do
|
|---|
| 545 | for X := 0 to Size.X - 1 do begin
|
|---|
| 546 | (Color as TFColor).SetColor(RGBToColor(
|
|---|
| 547 | Trunc(X / Size.X * 256),
|
|---|
| 548 | Trunc(X / Size.X * 256),
|
|---|
| 549 | Trunc(X / Size.X * 256)
|
|---|
| 550 | ));
|
|---|
| 551 | Pixels[X, Y] := Color;
|
|---|
| 552 | end;
|
|---|
| 553 | end;
|
|---|
| 554 |
|
|---|
| 555 | procedure TFPixmap.Negative;
|
|---|
| 556 | begin
|
|---|
| 557 | FBackend.Negative;
|
|---|
| 558 | end;
|
|---|
| 559 |
|
|---|
| 560 | procedure TFPixmap.Random;
|
|---|
| 561 | begin
|
|---|
| 562 | Fill(ColorRandom);
|
|---|
| 563 | end;
|
|---|
| 564 |
|
|---|
| 565 | procedure TFPixmap.Fill(Color: IFColor);
|
|---|
| 566 | begin
|
|---|
| 567 | FBackend.Fill((Color as TFColor).Backend);
|
|---|
| 568 | end;
|
|---|
| 569 |
|
|---|
| 570 | procedure TFPixmap.Fill(Func: TGetColorPos);
|
|---|
| 571 | begin
|
|---|
| 572 | FillCallBack := Func;
|
|---|
| 573 | FBackend.Fill(FillGetColor);
|
|---|
| 574 | end;
|
|---|
| 575 |
|
|---|
| 576 | procedure TFPixmap.PaintToCanvas(Canvas: TCanvas);
|
|---|
| 577 | begin
|
|---|
| 578 | FBackend.PaintToCanvas(Canvas);
|
|---|
| 579 | end;
|
|---|
| 580 |
|
|---|
| 581 | procedure TFPixmap.PaintToCanvas(Canvas: TCanvas; Rect: TRect);
|
|---|
| 582 | begin
|
|---|
| 583 | FBackend.PaintToCanvas(Canvas, Rect);
|
|---|
| 584 | end;
|
|---|
| 585 |
|
|---|
| 586 | procedure TFPixmap.PaintToBitmap(Bitmap: TBitmap; Rect: TRect);
|
|---|
| 587 | begin
|
|---|
| 588 | FBackend.PaintToBitmap(Bitmap, Rect);
|
|---|
| 589 | end;
|
|---|
| 590 |
|
|---|
| 591 | procedure TFPixmap.LoadFromCanvas(Canvas: TCanvas);
|
|---|
| 592 | begin
|
|---|
| 593 | Backend.LoadFromCanvas(Canvas);
|
|---|
| 594 | end;
|
|---|
| 595 |
|
|---|
| 596 | procedure TFPixmap.LoadFromBitmap(Bitmap: TBitmap);
|
|---|
| 597 | begin
|
|---|
| 598 | Backend.LoadFromBitmap(Bitmap);
|
|---|
| 599 | end;
|
|---|
| 600 |
|
|---|
| 601 | function TFPixmap.GetDataSize: Integer;
|
|---|
| 602 | begin
|
|---|
| 603 | Result := FBackend.GetDataSize;
|
|---|
| 604 | end;
|
|---|
| 605 |
|
|---|
| 606 | constructor TFPixmap.Create(AOwner: TComponent);
|
|---|
| 607 | begin
|
|---|
| 608 | inherited;
|
|---|
| 609 | FBackend := TBPixmap.Create;
|
|---|
| 610 | FCanvas := TFCanvas.Create;
|
|---|
| 611 | FCanvas.Pixmap := Self;
|
|---|
| 612 | ColorFormat := ColorFormatManager.GetFormat(0);
|
|---|
| 613 | end;
|
|---|
| 614 |
|
|---|
| 615 | destructor TFPixmap.Destroy;
|
|---|
| 616 | begin
|
|---|
| 617 | FreeAndNil(FCanvas);
|
|---|
| 618 | FreeAndNil(FBackend);
|
|---|
| 619 | inherited Destroy;
|
|---|
| 620 | end;
|
|---|
| 621 |
|
|---|
| 622 |
|
|---|
| 623 | initialization
|
|---|
| 624 |
|
|---|
| 625 | ColorFormatManager := TColorFormatManager.Create;
|
|---|
| 626 | with ColorFormatManager do begin
|
|---|
| 627 | RegisterFormat(TColorFormat);
|
|---|
| 628 | RegisterFormat(TColorFormatGray1);
|
|---|
| 629 | RegisterFormat(TColorFormatGray2);
|
|---|
| 630 | RegisterFormat(TColorFormatGray4);
|
|---|
| 631 | RegisterFormat(TColorFormatGray8);
|
|---|
| 632 | RegisterFormat(TColorFormatRGB8);
|
|---|
| 633 | RegisterFormat(TColorFormatRGBA8);
|
|---|
| 634 | RegisterFormat(TColorFormatRGB565);
|
|---|
| 635 | RegisterFormat(TColorFormatRGB16);
|
|---|
| 636 | end;
|
|---|
| 637 |
|
|---|
| 638 |
|
|---|
| 639 | finalization
|
|---|
| 640 |
|
|---|
| 641 | FreeAndNil(ColorFormatManager);
|
|---|
| 642 |
|
|---|
| 643 |
|
|---|
| 644 | end.
|
|---|
| 645 |
|
|---|