unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Image1: TImage;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
procedure FlipVertical (var px: TBitmap);
var
p: array of byte;
i, half, b: integer;
LoPtr, HiPtr: PInteger;
begin
if px.Height < 3 then exit;
half := (px.Height div 2);
b := px.RawImage.Description.BytesPerLine;
LoPtr := PInteger(px.RawImage.Data);
HiPtr := PInteger(px.RawImage.Data+ ((px.Height -1) * b));
setlength(p, b);
for i := 1 to half do begin
System.Move(LoPtr^,p[0],b); //(src, dst,sz)
System.Move(HiPtr^,LoPtr^,b); //(src, dst,sz)
System.Move(p[0],HiPtr^,b); //(src, dst,sz)
Inc(PByte(LoPtr), b );
Dec(PByte(HiPtr), b);
end;
end;
procedure FlipVertical2 (const px: PByte; const height, BytesPerLine: integer);
var
p: array of byte;
i, half: integer;
LoPtr, HiPtr: PInteger;
begin
if Height < 3 then exit;
half := (Height div 2);
LoPtr := PInteger(px);
HiPtr := PInteger(px+ ((Height -1) * BytesPerLine));
setlength(p, BytesPerLine);
for i := 1 to half do begin
System.Move(LoPtr^,p[0],BytesPerLine); //(src, dst,sz)
System.Move(HiPtr^,LoPtr^,BytesPerLine); //(src, dst,sz)
System.Move(p[0],HiPtr^,BytesPerLine); //(src, dst,sz)
Inc(PByte(LoPtr), BytesPerLine );
Dec(PByte(HiPtr), BytesPerLine);
end;
end;
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
if not(OpenDialog1.Execute) then Exit;
Image1.Picture.LoadFromFile(OpenDialog1.FileName);
Button2.Enabled := True;
Button3.Enabled := True;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
TempBitmap: TBitmap;
begin
TempBitmap := Image1.Picture.Bitmap;
FlipVertical(TempBitmap);
end;
procedure TForm1.Button3Click(Sender: TObject);
var
TempBitmap: TBitmap;
begin
TempBitmap := Image1.Picture.Bitmap;
with TempBitmap do
FlipVertical2(RawImage.Data, Height, RawImage.Description.BytesPerLine);
end;
end.