Skip to content

Commit 94081ae

Browse files
ADD: Testcases
FIX: Rotation via Matrix
1 parent 32d483f commit 94081ae

File tree

3 files changed

+93
-105
lines changed

3 files changed

+93
-105
lines changed

graphics/Graphics/fpcunitproject1.lpi

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
<Filename Value="../../DatenSteuerung/uvectormath.pas"/>
4848
<IsPartOfProject Value="True"/>
4949
</Unit>
50+
<Unit>
51+
<Filename Value="uvectormath.inc"/>
52+
<IsPartOfProject Value="True"/>
53+
</Unit>
5054
</Units>
5155
</ProjectOptions>
5256
<CompilerOptions>
@@ -59,7 +63,24 @@
5963
<OtherUnitFiles Value="..;../../DatenSteuerung"/>
6064
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
6165
</SearchPaths>
66+
<Parsing>
67+
<SyntaxOptions>
68+
<IncludeAssertionCode Value="True"/>
69+
</SyntaxOptions>
70+
</Parsing>
71+
<CodeGeneration>
72+
<Checks>
73+
<IOChecks Value="True"/>
74+
<RangeChecks Value="True"/>
75+
<OverflowChecks Value="True"/>
76+
<StackChecks Value="True"/>
77+
</Checks>
78+
<VerifyObjMethodCallValidity Value="True"/>
79+
</CodeGeneration>
6280
<Linking>
81+
<Debugging>
82+
<UseHeaptrc Value="True"/>
83+
</Debugging>
6384
<Options>
6485
<Win32>
6586
<GraphicApplication Value="True"/>

graphics/Graphics/testcase1.pas

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
Procedure SetUp; override;
2121
Procedure TearDown; override;
2222
published
23-
Procedure TeadUpDown_Valid;
23+
Procedure TearUpDown_Valid;
2424
Procedure Rotate_90_Grad;
2525
Procedure Rotate_Counter_90_Grad;
2626
Procedure Rotate_90_for_and_back;
2727
Procedure Rotate_90_for_and_back_2;
28+
Procedure Rotate_90_for_and_back_3;
2829
Procedure Rotate_180;
2930
Procedure Rotate_180_2;
31+
Procedure Rotate_180_3;
3032
Procedure UpDown;
3133
Procedure LeftRight;
3234
Procedure Flip_Rotate;
@@ -36,7 +38,7 @@
3638

3739
Procedure TTestCase1.Rotate_90_Grad;
3840
Begin
39-
41+
// Rotate 4 times -> get same as started with
4042
RotateClockWise90Degrees(Lena1);
4143
RotateClockWise90Degrees(Lena1);
4244
RotateClockWise90Degrees(Lena1);
@@ -47,6 +49,7 @@
4749

4850
Procedure TTestCase1.Rotate_Counter_90_Grad;
4951
Begin
52+
// Rotate 4 times -> get same as started with
5053
RotateCounterClockWise90Degrees(Lena1);
5154
RotateCounterClockWise90Degrees(Lena1);
5255
RotateCounterClockWise90Degrees(Lena1);
@@ -56,17 +59,29 @@
5659

5760
Procedure TTestCase1.Rotate_90_for_and_back;
5861
Begin
62+
// Rotate 90 is revertable by Rotate -90
5963
RotateClockWise90Degrees(Lena1);
6064
RotateCounterClockWise90Degrees(Lena1);
6165
CheckLenaEqual();
6266
End;
6367

6468
Procedure TTestCase1.Rotate_90_for_and_back_2;
6569
Begin
70+
// Rotate 270 is same as rotate -90
71+
RotateClockWise90Degrees(Lena1);
6672
RotateClockWise90Degrees(Lena1);
6773
RotateClockWise90Degrees(Lena1);
74+
RotateCounterClockWise90Degrees(Lena2);
75+
CheckLenaEqual();
76+
End;
77+
78+
Procedure TTestCase1.Rotate_90_for_and_back_3;
79+
Begin
80+
// Rotate 90 is same as rotate -270
6881
RotateClockWise90Degrees(Lena1);
6982
RotateCounterClockWise90Degrees(Lena2);
83+
RotateCounterClockWise90Degrees(Lena2);
84+
RotateCounterClockWise90Degrees(Lena2);
7085
CheckLenaEqual();
7186
End;
7287

@@ -85,6 +100,14 @@
85100
CheckLenaEqual();
86101
End;
87102

103+
Procedure TTestCase1.Rotate_180_3;
104+
Begin
105+
Rotate180Degrees(Lena1);
106+
RotateClockWise90Degrees(Lena2);
107+
RotateClockWise90Degrees(Lena2);
108+
CheckLenaEqual();
109+
End;
110+
88111
Procedure TTestCase1.UpDown;
89112
Begin
90113
UpSideDown(Lena1);
@@ -111,17 +134,19 @@
111134
Var
112135
i, j: Integer;
113136
Begin
114-
AssertEquals('Error, dimension after rotate wrong.', Lena1.Width, Lena2.Width);
115-
AssertEquals('Error, dimension after rotate wrong.', Lena1.Height, Lena2.Height);
137+
AssertEquals('Error, dimension [Width] wrong.', Lena1.Width, Lena2.Width);
138+
AssertEquals('Error, dimension [Height] wrong.', Lena1.Height, Lena2.Height);
116139
Lena1_intf := TLazIntfImage.Create(0, 0);
117140
Lena1_intf.LoadFromBitmap(Lena1.Handle, Lena1.MaskHandle);
118141
Lena2_intf := TLazIntfImage.Create(0, 0);
119142
Lena2_intf.LoadFromBitmap(Lena2.Handle, Lena2.MaskHandle);
120-
143+
// Der Eigentliche Test Pixel für Pixel
121144
For i := 0 To Lena1.Width - 1 Do
122145
For j := 0 To Lena1.Height - 1 Do Begin
123146
AssertTrue('Eror, pixel data invalid', FPColorToColor(Lena1_intf.Colors[i, j]) = FPColorToColor(Lena2_intf.Colors[i, j]))
124147
End;
148+
Lena1_intf.Free;
149+
Lena2_intf.Free;
125150
End;
126151

127152
Procedure TTestCase1.SetUp;
@@ -137,13 +162,11 @@
137162

138163
Procedure TTestCase1.TearDown;
139164
Begin
140-
Lena1_intf.Free;
141-
Lena2_intf.Free;
142165
Lena1.Free;
143166
Lena2.Free;
144167
End;
145168

146-
Procedure TTestCase1.TeadUpDown_Valid;
169+
Procedure TTestCase1.TearUpDown_Valid;
147170
Begin
148171
// Nichts, testet nur ob Setup und Teardown alles richtig machen.
149172
CheckLenaEqual();

graphics/ugraphics.pas

Lines changed: 41 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(******************************************************************************)
22
(* uGraphiks.pas ??.??.???? *)
33
(* *)
4-
(* Version : 0.10 *)
4+
(* Version : 0.11 *)
55
(* *)
66
(* Author : Uwe Schächterle (Corpsman) *)
77
(* *)
@@ -37,6 +37,7 @@
3737
(* add Wrap Modes *)
3838
(* 0.09 - added floodfill *)
3939
(* 0.10 - FIX: revert 90* Rotation images back to old algorithm *)
40+
(* 0.11 - FIX: revert 90* Rotations to matrix multiplications *)
4041
(* *)
4142
(******************************************************************************)
4243

@@ -786,118 +787,58 @@
786787

787788
Procedure UpSideDown(Const Bitmap: TBitmap);
788789
Var
789-
Source_intf, Dest_intf: TLazIntfImage;
790-
DestBM: TBitmap;
791-
i, j: Integer;
792-
DestHandle, DestMaskHandle: HBitmap;
790+
m: TMatrix3x3;
793791
Begin
794-
// Der MulImage Algorithmus, rundet manchmal komisch, dass sieht man
795-
// Wenn es Exakt sein mus !
796-
Source_intf := TLazIntfImage.Create(0, 0);
797-
Source_intf.LoadFromBitmap(Bitmap.Handle, Bitmap.MaskHandle);
798-
DestBM := TBitmap.Create;
799-
DestBM.Width := Bitmap.Width;
800-
DestBM.Height := Bitmap.Height;
801-
Dest_intf := TLazIntfImage.Create(0, 0);
802-
Dest_intf.LoadFromBitmap(DestBM.Handle, DestBM.MaskHandle);
803-
For i := 0 To Bitmap.Width - 1 Do Begin
804-
For j := 0 To Bitmap.Height - 1 Do Begin
805-
Dest_intf[i, Bitmap.Height - 1 - j] := Source_intf[i, j];
806-
End;
807-
End;
808-
Dest_intf.CreateBitmaps(DestHandle, DestMaskHandle, false);
809-
Bitmap.Handle := DestHandle;
810-
Bitmap.MaskHandle := DestMaskHandle;
811-
Source_intf.free;
812-
Dest_intf.free;
813-
DestBM.free;
792+
m := IdentityMatrix3x3;
793+
m[0, 0] := 1;
794+
m[1, 1] := -1;
795+
// Revert Middlepoint shifting
796+
m[0, 2] := 0.5;
797+
m[1, 2] := 0.5;
798+
MulImage(Bitmap, m, imNone, wmBlack);
814799
End;
815800

816801
Procedure LeftToRight(Const Bitmap: TBitmap);
817802
Var
818-
Source_intf, Dest_intf: TLazIntfImage;
819-
DestBM: TBitmap;
820-
i, j: Integer;
821-
DestHandle, DestMaskHandle: HBitmap;
803+
m: TMatrix3x3;
822804
Begin
823-
// Der MulImage Algorithmus, rundet manchmal komisch, dass sieht man
824-
// Wenn es Exakt sein mus !
825-
Source_intf := TLazIntfImage.Create(0, 0);
826-
Source_intf.LoadFromBitmap(Bitmap.Handle, Bitmap.MaskHandle);
827-
DestBM := TBitmap.Create;
828-
DestBM.Width := Bitmap.Width;
829-
DestBM.Height := Bitmap.Height;
830-
Dest_intf := TLazIntfImage.Create(0, 0);
831-
Dest_intf.LoadFromBitmap(DestBM.Handle, DestBM.MaskHandle);
832-
For i := 0 To Bitmap.Width - 1 Do Begin
833-
For j := 0 To Bitmap.Height - 1 Do Begin
834-
Dest_intf[Bitmap.Width - 1 - i, j] := Source_intf[i, j];
835-
End;
836-
End;
837-
Dest_intf.CreateBitmaps(DestHandle, DestMaskHandle, false);
838-
Bitmap.Handle := DestHandle;
839-
Bitmap.MaskHandle := DestMaskHandle;
840-
Source_intf.free;
841-
Dest_intf.free;
842-
DestBM.free;
805+
m := IdentityMatrix3x3;
806+
m[0, 0] := -1;
807+
m[1, 1] := 1;
808+
// Revert Middlepoint shifting
809+
m[0, 2] := 0.5;
810+
m[1, 2] := 0.5;
811+
MulImage(Bitmap, m, imNone, wmBlack);
843812
End;
844813

845814
Procedure RotateClockWise90Degrees(Const Bitmap: TBitmap);
846815
Var
847-
Source_intf, Dest_intf: TLazIntfImage;
848-
DestBM: TBitmap;
849-
i, j: Integer;
850-
DestHandle, DestMaskHandle: HBitmap;
816+
m: TMatrix3x3;
851817
Begin
852-
// Der MulImage Algorithmus, rundet manchmal komisch, dass sieht man
853-
// Wenn es Exakt sein mus !
854-
Source_intf := TLazIntfImage.Create(0, 0);
855-
Source_intf.LoadFromBitmap(Bitmap.Handle, Bitmap.MaskHandle);
856-
DestBM := TBitmap.Create;
857-
DestBM.Width := Bitmap.Height;
858-
DestBM.Height := Bitmap.Width;
859-
Dest_intf := TLazIntfImage.Create(0, 0);
860-
Dest_intf.LoadFromBitmap(DestBM.Handle, DestBM.MaskHandle);
861-
For i := 0 To Bitmap.Width - 1 Do Begin
862-
For j := 0 To Bitmap.Height - 1 Do Begin
863-
Dest_intf[Bitmap.Height - 1 - j, i] := Source_intf[i, j];
864-
End;
865-
End;
866-
Dest_intf.CreateBitmaps(DestHandle, DestMaskHandle, false);
867-
Bitmap.Handle := DestHandle;
868-
Bitmap.MaskHandle := DestMaskHandle;
869-
Source_intf.free;
870-
Dest_intf.free;
871-
DestBM.free;
818+
m := IdentityMatrix3x3;
819+
m[0, 0] := 0;
820+
m[1, 1] := 0;
821+
m[0, 1] := -1;
822+
m[1, 0] := 1;
823+
// Revert Middlepoint shifting
824+
m[0, 2] := 0.5;
825+
m[1, 2] := 0.5;
826+
MulImage(Bitmap, m, imNone, wmBlack);
872827
End;
873828

874829
Procedure RotateCounterClockWise90Degrees(Const Bitmap: TBitmap);
875830
Var
876-
Source_intf, Dest_intf: TLazIntfImage;
877-
DestBM: TBitmap;
878-
i, j: Integer;
879-
DestHandle, DestMaskHandle: HBitmap;
831+
m: TMatrix3x3;
880832
Begin
881-
// Der MulImage Algorithmus, rundet manchmal komisch, dass sieht man
882-
// Wenn es Exakt sein mus !
883-
Source_intf := TLazIntfImage.Create(0, 0);
884-
Source_intf.LoadFromBitmap(Bitmap.Handle, Bitmap.MaskHandle);
885-
DestBM := TBitmap.Create;
886-
DestBM.Width := Bitmap.Height;
887-
DestBM.Height := Bitmap.Width;
888-
Dest_intf := TLazIntfImage.Create(0, 0);
889-
Dest_intf.LoadFromBitmap(DestBM.Handle, DestBM.MaskHandle);
890-
For i := 0 To Bitmap.Width - 1 Do Begin
891-
For j := 0 To Bitmap.Height - 1 Do Begin
892-
Dest_intf[j, bitmap.Width - 1 - i] := Source_intf[i, j];
893-
End;
894-
End;
895-
Dest_intf.CreateBitmaps(DestHandle, DestMaskHandle, false);
896-
Bitmap.Handle := DestHandle;
897-
Bitmap.MaskHandle := DestMaskHandle;
898-
Source_intf.free;
899-
Dest_intf.free;
900-
DestBM.free;
833+
m := IdentityMatrix3x3;
834+
m[0, 0] := 0;
835+
m[1, 1] := 0;
836+
m[0, 1] := 1;
837+
m[1, 0] := -1;
838+
// Revert Middlepoint shifting
839+
m[0, 2] := 0.5;
840+
m[1, 2] := 0.5;
841+
MulImage(Bitmap, m, imNone, wmBlack);
901842
End;
902843

903844
Procedure Rotate180Degrees(Const Bitmap: TBitmap);
@@ -907,6 +848,9 @@
907848
m := IdentityMatrix3x3;
908849
m[0, 0] := -1;
909850
m[1, 1] := -1;
851+
// Revert Middlepoint shifting
852+
m[0, 2] := 0.5;
853+
m[1, 2] := 0.5;
910854
MulImage(Bitmap, m, imNone, wmBlack);
911855
End;
912856

0 commit comments

Comments
 (0)