Просмотр исходного кода

* Patch from Werner Pamler to fix interpolation mechanism. Fixes issue #33978

Michaël Van Canneyt 2 недель назад
Родитель
Сommit
659f041571

+ 6 - 5
packages/fcl-image/src/extinterpolation.pp

@@ -117,13 +117,14 @@ type
     function MaxSupport : double; override;
   end;
 
-  { TBilineairInterpolation }
+  { TBilinearInterpolation }
 
-  TBilineairInterpolation = class (TFPBaseInterpolation)
+  TBilinearInterpolation = class (TFPBaseInterpolation)
   protected
     function Filter (x : double) : double; override;
     function MaxSupport : double; override;
   end;
+  TBilineairInterpolation = TBilinearInterpolation deprecated 'Use TBilinearInterpolation';
 
   { THanningInterpolation }
 
@@ -450,9 +451,9 @@ begin
   result := 1.0;
 end;
 
-{ TBilineairInterpolation }
+{ TBilinearInterpolation }
 
-function TBilineairInterpolation.Filter(x: double): double;
+function TBilinearInterpolation.Filter(x: double): double;
 begin
   if x < -1.0 then
     result := 0.0
@@ -464,7 +465,7 @@ begin
     result := 0.0;
 end;
 
-function TBilineairInterpolation.MaxSupport: double;
+function TBilinearInterpolation.MaxSupport: double;
 begin
   result := 1.0;
 end;

+ 3 - 2
packages/fcl-image/src/fpcanvas.pp

@@ -216,13 +216,14 @@ type
     function MaxSupport : double; virtual;
   end;
 
-  { TMitchelInterpolation }
+  { TMitchellInterpolation }
 
-  TMitchelInterpolation = class (TFPBaseInterpolation)
+  TMitchellInterpolation = class (TFPBaseInterpolation)
   protected
     function Filter (x : double) : double; override;
     function MaxSupport : double; override;
   end;
+  TMitchelInterpolation = TFPBaseInterpolation deprecated 'Use TMitchellInterpolation';
 
   TFPCustomRegion = class
   public

+ 7 - 7
packages/fcl-image/src/fpinterpolation.inc

@@ -118,14 +118,14 @@ begin
       Factor:=double(OldSize-1)/double(NewSize);
       for i:=0 to NewSize-1 do
       begin
-        StartPos:=Factor*i+Factor/2;
+        StartPos:=Factor*(i+0.5);
         StartIndex:=Floor(StartPos);
         PInteger(Entry)^:=StartIndex;
         inc(Entry,SizeOf(Integer));
         // first pixel
-        FirstValue:=(1.0-(StartPos-double(StartIndex)));
+        FirstValue := StartPos-double(StartIndex);
         // convert linear distribution
-        FirstValue:=Min(1.0,Max(0.0,Filter(FirstValue/MaxSupport)));
+        FirstValue:=Min(1.0,Max(0.0,Filter(FirstValue)));
         PSingle(Entry)^:=FirstValue;
         inc(Entry,SizeOf(Single));
         // last pixel
@@ -247,7 +247,7 @@ end;
 
 function TFPBaseInterpolation.Filter(x: double): double;
 begin
-  Result:=x;
+  Result := 1.0 - x;
 end;
 
 function TFPBaseInterpolation.MaxSupport: double;
@@ -255,9 +255,9 @@ begin
   Result:=1.0;
 end;
 
-{ TMitchelInterpolation }
+{ TMitchellInterpolation }
 
-function TMitchelInterpolation.Filter(x: double): double;
+function TMitchellInterpolation.Filter(x: double): double;
 const
   B  = (1.0/3.0);
   C  = (1.0/3.0);
@@ -283,7 +283,7 @@ begin
   result := 0.0;
 end;
 
-function TMitchelInterpolation.MaxSupport: double;
+function TMitchellInterpolation.MaxSupport: double;
 begin
   result := 2.0;
 end;