Advertisement
WarPie90

Brighten Matrix

Dec 14th, 2013
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.23 KB | None | 0 0
  1. {*
  2.  Brightens the image or darkens if negative "amount" is given.
  3. *}
  4. function ImBrighten(ImgArr:T2DIntArray; Amount:Extended; Legacy:Boolean): T2DIntArray; StdCall;
  5. var
  6.   W,H,x,y,R,G,B,AmountL:Integer;
  7.   cH,cS,cV:Extended;
  8. begin
  9.   W := Length(ImgArr[0]);
  10.   H := Length(ImgArr);
  11.   SetLength(Result, H,W);
  12.  
  13.   Dec(W);
  14.   Dec(H);
  15.   case Legacy of
  16.    False:
  17.     for y:=0 to H do
  18.       for x:=0 to W do
  19.       begin
  20.         ColorToHSV(ImgArr[y][x], cH,cS,cV);
  21.         cV := cV+Amount;
  22.         if (cV < 0.0) then cV := 0
  23.         else if (cV > 1.0) then cV := 1.0;
  24.         HSVToRGB(cH,cS,cV, R,G,B);
  25.         Result[y][x] := (R) or (G shl 8) or (B shl 16);
  26.       end;
  27.    True:
  28.     begin
  29.       AmountL := Round(Amount);
  30.       for y:=0 to H do
  31.         for x:=0 to W do
  32.         begin
  33.           ColorToRGB2(ImgArr[y][x], R,G,B);
  34.           R := R + AmountL;
  35.           if (R > 255) then R:=255
  36.           else if (R < 0) then R:=0;
  37.  
  38.           G := G + AmountL;
  39.           if (G > 255) then G:=255
  40.           else if (G < 0) then G:=0;
  41.  
  42.           B := B + AmountL;
  43.           if (B > 255) then B:=255
  44.           else if (B < 0) then B:=0;
  45.           Result[y][x] := (R) or (G shl 8) or (B shl 16);
  46.         end;
  47.    end;
  48.   end;
  49. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement