Created
December 29, 2015 20:03
-
-
Save sysint64/d05e55b1042bf5a8cab8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function AverageGradientPoint (Gradient : TGradient; Point, Radius : Integer) : RGB; | |
var | |
i : Integer; | |
RGBSum : array[0..2] of Integer; | |
const | |
R = 0; G = 1; B = 2; | |
begin | |
RGBSum[R] := 0; RGBSum[G] := 0; RGBSum[B] := 0; | |
for i := Point-Radius to Point+Radius do | |
begin | |
RGBSum[R] := RGBSum[R]+Gradient.Data[i][R]; | |
RGBSum[G] := RGBSum[R]+Gradient.Data[i][G]; | |
RGBSum[B] := RGBSum[R]+Gradient.Data[i][B]; | |
end; | |
Result := RGB (RGBSum[R] div Radius, RGBSum[G] div Radius, RGBSum[B] div Radius); | |
end; | |
function NormalizeGradient (Gradient : TGradient; Norm, Radius : Integer) : TGradient; | |
var | |
i, j : Integer; | |
Step : Integer; | |
begin | |
Result := TGradient.Create (Norm); | |
Step := Gradient.Size div Norm; | |
i := 0; | |
j := 0; | |
while (1) do | |
begin | |
Result.Data[i] := AverageGradientPoint (Gradient, j, Radius); | |
Inc (i); j := j+Step; | |
end; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment