Changeset 4 for trunk/UGraphic.pas


Ignore:
Timestamp:
Sep 16, 2014, 11:55:35 AM (10 years ago)
Author:
chronos
Message:
  • Added: Action to fill image with random image.
  • Fixed: Pixel load/save to bitmap was using Move with pointers instead pointed value.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGraphic.pas

    r3 r4  
    2525    function ChannelUsed(Channel: TGColorChannel): Boolean;
    2626    function ColorToTColor(Color: TGColor): TColor; virtual;
     27    procedure ColorFromTColor(GColor: TGColor; Color: TColor); virtual;
    2728    function GetColorClass: TGColorClass; virtual;
    2829  end;
     
    3839    function GetChannel(Channel: TGColorChannel): TGColor;
    3940    procedure SetColorFormat(AValue: TGColorFormatClass);
    40     procedure LoadData(Data: Pointer); virtual;
    41     procedure SaveData(Data: Pointer); virtual;
     41    procedure LoadData(BitmapData: Pointer); virtual;
     42    procedure SaveData(BitmapData: Pointer); virtual;
    4243  public
    4344    function ToTColor: TColor;
     45    procedure FromTColor(Color: TColor);
    4446    procedure Assign(Source: TGColor); virtual;
    4547    property Channels[Channel: TGColorChannel]: TGColor read GetChannel;
     
    6971    procedure PaintToCanvas(Canvas: TCanvas);
    7072    procedure Clear;
     73    procedure Random;
    7174    constructor Create; virtual;
    7275    destructor Destroy; override;
     
    164167end;
    165168
     169procedure TGColorFormat.ColorFromTColor(GColor: TGColor; Color: TColor);
     170begin
     171  FillChar(GColor.Data^, GetPixelSize, 0);
     172end;
     173
    166174function TGColorFormat.GetColorClass: TGColorClass;
    167175begin
     
    187195end;
    188196
    189 procedure TGColor.LoadData(Data: Pointer);
    190 var
    191   F: TGColorFormat;
    192 begin
    193   F := FColorFormat.Create;
    194   Move(FData, Data, F.GetPixelSize);
    195   F.Free;
    196 end;
    197 
    198 procedure TGColor.SaveData(Data: Pointer);
    199 var
    200   F: TGColorFormat;
    201 begin
    202   F := FColorFormat.Create;
    203   Move(Data, FData, F.GetPixelSize);
     197procedure TGColor.LoadData(BitmapData: Pointer);
     198var
     199  F: TGColorFormat;
     200begin
     201  F := FColorFormat.Create;
     202  Move(BitmapData^, FData^, F.GetPixelSize);
     203  F.Free;
     204end;
     205
     206procedure TGColor.SaveData(BitmapData: Pointer);
     207var
     208  F: TGColorFormat;
     209begin
     210  F := FColorFormat.Create;
     211  Move(FData^, BitmapData^, F.GetPixelSize);
    204212  F.Free;
    205213end;
     
    211219  F := FColorFormat.Create;
    212220  Result := F.ColorToTColor(Self);
     221  F.Free;
     222end;
     223
     224procedure TGColor.FromTColor(Color: TColor);
     225var
     226  F: TGColorFormat;
     227begin
     228  F := FColorFormat.Create;
     229  F.ColorFromTColor(Self, Color);
    213230  F.Free;
    214231end;
     
    305322end;
    306323
     324procedure TGBitmap.Random;
     325var
     326  X, Y: Integer;
     327  Color: TGColor;
     328begin
     329  Color := TGColor.Create;
     330  Color.Format := ColorFormat;
     331  for Y := 0 to Size.Y - 1 do
     332    for X := 0 to Size.X - 1 do begin
     333      Color.FromTColor(System.Random($ffffff));
     334      Pixels[X, Y] := Color;
     335    end;
     336  Color.Free;
     337end;
     338
    307339constructor TGBitmap.Create;
    308340begin
Note: See TracChangeset for help on using the changeset viewer.