You are on page 1of 4

unit UnitUtama;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, ExtDlgs, Menus, StdCtrls,
ComCtrls, Clipbrd, ExtCtrls;

type
TFormUtama = class(TForm)
PanelAtas: TPanel;
ButtonAmbilCitra: TButton;
StatusBar: TStatusBar;
OpenPictureDialog: TOpenPictureDialog;
ButtonCerminkan: TButton;
RadioButtonHorisontal: TRadioButton;
RadioButtonVertikal: TRadioButton;
RadioButtonKombinasi: TRadioButton;
procedure ButtonAmbilCitraClick(Sender: TObject);
procedure Olah;
procedure ButtonCerminkanClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
FormUtama: TFormUtama;

implementation

uses UnitCitra;

var
FormHasil: TFormCitra;

{$R *.dfm}

procedure TFormUtama.ButtonAmbilCitraClick(Sender: TObject);


var
fc: string;
begin
if (OpenPictureDialog.Execute) then
begin
if (FormCitra = nil) then
Application.CreateForm(TFormCitra, FormCitra);
FormCitra.Image.Picture.LoadFromFile(
OpenPictureDialog.FileName);
FormCitra.ClientHeight :=
FormCitra.Image.Picture.Height;
FormCitra.ClientWidth :=
FormCitra.Image.Picture.Width;
FormCitra.ClientHeight :=
FormCitra.Image.Picture.Height;
case (FormCitra.Image.Picture.Bitmap.PixelFormat) of
pf1bit : fc := 'biner';
pf8bit : fc := 'keabuan';
pf24bit : fc := 'true color';
end;
StatusBar.SimpleText := OpenPictureDialog.FileName
+ ' (' + IntToStr(FormCitra.Image.Picture.Width)
+ 'x' + IntToStr(FormCitra.Image.Picture.Height)
+ ', ' + fc + ')';
end;
end;

procedure TFormUtama.Olah;
var
x, y, x1, y1, w, h, w1, h1: integer;
PC, PH: PByteArray;
Ki, Ri, Gi, Bi, Ko, Ro, Go, Bo: array of array of byte;
begin
w := FormCitra.Image.Picture.Width;
h := FormCitra.Image.Picture.Height;
w1 := w;
h1 := h;
if (FormCitra.Image.Picture.Bitmap.PixelFormat = pf8bit)
then
begin
SetLength(Ki, w, h);
SetLength(Ko, w1, h1);
for y := 0 to h-1 do
begin
PC := FormCitra.Image.Picture.Bitmap.ScanLine[y];
for x := 0 to w-1 do
Ki[x, y] := PC[x];
end;
if (RadioButtonHorisontal.Checked) then
begin
for x1 := 0 to w1-1 do
for y1 := 0 to h1-1 do
begin
x := w1-1-x1;
y := y1;
Ko[x1, y1] := Ki[x, y];
end;
end;
if (RadioButtonVertikal.Checked) then
begin
for x1 := 0 to w1-1 do
for y1 := 0 to h1-1 do
begin
x := x1;
y := h1-1-y1;
Ko[x1, y1] := Ki[x, y];
end;
end;
if (RadioButtonKombinasi.Checked) then
begin
for x1 := 0 to w1-1 do
for y1 := 0 to h1-1 do
begin
x := w1-1-x1;
y := h1-1-y1;
Ko[x1, y1] := Ki[x, y];
end;
end;
for y1 := 0 to h1-1 do
begin
PH := FormHasil.Image.Picture.Bitmap.ScanLine[y1];
for x1 := 0 to w1-1 do
PH[x1] := Ko[x1, y1];
end;
Ki := nil;
Ko := nil;
end;
if (FormCitra.Image.Picture.Bitmap.PixelFormat = pf24bit)
then
begin
SetLength(Ri, w, h);
SetLength(Gi, w, h);
SetLength(Bi, w, h);
SetLength(Ro, w1, h1);
SetLength(Go, w1, h1);
SetLength(Bo, w1, h1);
for y := 0 to h-1 do
begin
PC := FormCitra.Image.Picture.Bitmap.ScanLine[y];
for x := 0 to w-1 do
begin
Bi[x, y] := PC[3*x];
Gi[x, y] := PC[3*x+1];
Ri[x, y] := PC[3*x+2];
end;
end;
if (RadioButtonHorisontal.Checked) then
begin
for x1 := 0 to w1-1 do
for y1 := 0 to h1-1 do
begin
x := w1-1-x1;
y := y1;
Ro[x1, y1] := Ri[x, y];
Go[x1, y1] := Gi[x, y];
Bo[x1, y1] := Bi[x, y];
end;
end;
if (RadioButtonVertikal.Checked) then
begin
for x1 := 0 to w1-1 do
for y1 := 0 to h1-1 do
begin
x := x1;
y := h1-1-y1;
Ro[x1, y1] := Ri[x, y];
Go[x1, y1] := Gi[x, y];
Bo[x1, y1] := Bi[x, y];
end;
end;
if (RadioButtonKombinasi.Checked) then
begin
for x1 := 0 to w1-1 do
for y1 := 0 to h1-1 do
begin
x := w1-1-x1;
y := h1-1-y1;
Ro[x1, y1] := Ri[x, y];
Go[x1, y1] := Gi[x, y];
Bo[x1, y1] := Bi[x, y];
end;
end;
for y1 := 0 to h1-1 do
begin
PH := FormHasil.Image.Picture.Bitmap.ScanLine[y1];
for x1 := 0 to w1-1 do
begin
PH[3*x1] := Bo[x1, y1];
PH[3*x1+1] := Go[x1, y1];
PH[3*x1+2] := Ro[x1, y1];
end;
end;
Ri := nil;
Gi := nil;
Bi := nil;
Ro := nil;
Go := nil;
Bo := nil;
end;
end;

procedure TFormUtama.ButtonCerminkanClick(Sender: TObject);


begin
if (FormCitra = nil) then
begin
ShowMessage('Ambil dulu citra yang akan diolah');
exit;
end;
if (FormHasil = nil) then
Application.CreateForm(TFormCitra, FormHasil);
FormHasil.Caption := 'Citra Hasil';
FormHasil.Image.Picture := FormCitra.Image.Picture;
FormHasil.ClientHeight :=
FormHasil.Image.Picture.Height;
FormHasil.ClientWidth :=
FormHasil.Image.Picture.Width;
FormHasil.ClientHeight :=
FormHasil.Image.Picture.Height;
FormHasil.Top := FormCitra.Top;
FormHasil.Left := FormCitra.Left+FormCitra.Width;
Olah;
end;

end.

You might also like