Changeset 13 for trunk/UMemory.pas


Ignore:
Timestamp:
Sep 22, 2014, 5:25:11 PM (10 years ago)
Author:
chronos
Message:
  • Added: Image operation Negative image.
  • Added: Partialy implemented Image load from and save to file.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UMemory.pas

    r9 r13  
    6767    procedure SetSize(AValue: Integer); virtual;
    6868  public
     69    procedure Invert; virtual;
    6970    function GetInteger: Integer; virtual;
    7071    procedure SetInteger(Value: Integer); virtual;
     
    8384    FData: PByte;
    8485    FSize: Integer;
    85     function GetInteger: Integer; override;
    86     procedure SetInteger(Value: Integer); override;
    8786    function GetSize: Integer; override;
    8887    procedure SetSize(AValue: Integer); override;
     
    9089    procedure SetItem(Index: Integer; AValue: Byte); override;
    9190  public
     91    function GetInteger: Integer; override;
     92    procedure SetInteger(Value: Integer); override;
     93    procedure Clear(Value: Byte = 0); override;
     94    procedure ReadBlock(Block: TBitBlock; Position: Integer); override;
     95    procedure WriteBlock(Block: TBitBlock; Position: Integer); override;
     96    property Data: PByte read FData;
     97    procedure Invert; override;
    9298  end;
    9399
     
    96102
    97103{ TBitMemory }
     104
     105procedure TBitMemory.Clear(Value: Byte);
     106begin
     107  if (Size and 7) = 0 then begin
     108    if Value = 0 then FillChar(FData^, Size shr 3, 0)
     109      else FillChar(FData^, Size shr 3, $ff);
     110  end else inherited;
     111end;
     112
     113procedure TBitMemory.ReadBlock(Block: TBitBlock; Position: Integer);
     114begin
     115  if Block is TBitMemory then begin
     116    if (Position and 7) = 0 then begin
     117      if (Block.Size and 7) = 0 then
     118        Move(PByte(FData + Position shr 3)^, TBitMemory(Block).Data^, Block.Size shr 3)
     119        else inherited;
     120    end else inherited;
     121  end else inherited;
     122end;
     123
     124procedure TBitMemory.WriteBlock(Block: TBitBlock; Position: Integer);
     125begin
     126  if Block is TBitMemory then begin
     127    if (Position and 7) = 0 then begin
     128      if (Block.Size and 7) = 0 then
     129        Move(TBitMemory(Block).Data^, PByte(FData + Position shr 3)^, Block.Size shr 3)
     130        else inherited;
     131    end else inherited;
     132  end else inherited;
     133end;
     134
     135procedure TBitMemory.Invert;
     136var
     137  I: Integer;
     138begin
     139  if (Size and 7) = 0 then begin
     140    for I := 0 to (Size shr 3) - 1 do
     141      PByte(FData + I)^ := PByte(FData + I)^ xor $ff;
     142  end
     143  else inherited;
     144
     145end;
    98146
    99147function TBitMemory.GetInteger: Integer;
     
    176224end;
    177225
     226procedure TBitBlock.Invert;
     227var
     228  I: Integer;
     229begin
     230  for I := 0 to Size - 1 do
     231    Items[I] := not Items[I];
     232end;
     233
    178234function TBitBlock.GetInteger: Integer;
    179235begin
Note: See TracChangeset for help on using the changeset viewer.