Ignore:
Timestamp:
Apr 17, 2019, 12:58:41 AM (5 years ago)
Author:
chronos
Message:
  • Modified: Propagate project build mode options to used packages.
  • Added: Check memory leaks using heaptrc.
  • Modified: Update BGRABitmap package.
Location:
GraphicTest
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • GraphicTest

    • Property svn:ignore
      •  

        old new  
        88GraphicTest.lps
        99GraphicTest.dbg
         10heaptrclog.trc
  • GraphicTest/Packages/bgrabitmap/bgragradients.pas

    r494 r521  
    2929function nGradientInfo(StartColor, StopColor: TBGRAPixel; Direction: TGradientDirection; EndPercent: Single): TnGradientInfo;
    3030
    31 function nGradientAlphaFill(ARect: TRect; ADir: TGradientDirection; const AGradient: array of TnGradientInfo): TBGRABitmap;
    32 function nGradientAlphaFill(AWidth, AHeight: Integer; ADir: TGradientDirection; const AGradient: array of TnGradientInfo): TBGRABitmap;
    33 procedure nGradientAlphaFill(ACanvas: TCanvas; ARect: TRect; ADir: TGradientDirection; const AGradient: array of TnGradientInfo);
    34 procedure nGradientAlphaFill(ABitmap: TBGRABitmap; ARect: TRect; ADir: TGradientDirection; const AGradient: array of TnGradientInfo);
     31function nGradientAlphaFill(ARect: TRect; ADir: TGradientDirection; const AGradient: array of TnGradientInfo): TBGRABitmap; overload;
     32function nGradientAlphaFill(AWidth, AHeight: Integer; ADir: TGradientDirection; const AGradient: array of TnGradientInfo): TBGRABitmap; overload;
     33procedure nGradientAlphaFill(ACanvas: TCanvas; ARect: TRect; ADir: TGradientDirection; const AGradient: array of TnGradientInfo); overload;
     34procedure nGradientAlphaFill(ABitmap: TBGRABitmap; ARect: TRect; ADir: TGradientDirection; const AGradient: array of TnGradientInfo); overload;
    3535
    3636function DoubleGradientAlphaFill(ARect: TRect; AStart1,AStop1,AStart2,AStop2: TBGRAPixel;
    37                                  ADirection1,ADirection2,ADir: TGradientDirection; AValue: Single): TBGRABitmap;
     37                                 ADirection1,ADirection2,ADir: TGradientDirection; AValue: Single): TBGRABitmap; overload;
    3838function DoubleGradientAlphaFill(AWidth,AHeight: Integer; AStart1,AStop1,AStart2,AStop2: TBGRAPixel;
    39                                  ADirection1,ADirection2,ADir: TGradientDirection; AValue: Single): TBGRABitmap;
     39                                 ADirection1,ADirection2,ADir: TGradientDirection; AValue: Single): TBGRABitmap; overload;
    4040procedure DoubleGradientAlphaFill(ACanvas: TCanvas; ARect: TRect; AStart1,AStop1,AStart2,AStop2: TBGRAPixel;
    41                                  ADirection1,ADirection2,ADir: TGradientDirection; AValue: Single);
     41                                 ADirection1,ADirection2,ADir: TGradientDirection; AValue: Single); overload;
    4242procedure DoubleGradientAlphaFill(ABitmap: TBGRABitmap; ARect: TRect; AStart1,AStop1,AStart2,AStop2: TBGRAPixel;
    43                                  ADirection1,ADirection2,ADir: TGradientDirection; AValue: Single);
     43                                 ADirection1,ADirection2,ADir: TGradientDirection; AValue: Single); overload;
    4444
    4545{----------------------------------------------------------------------}
     
    155155{ Create a precise height map for a rectangle height map with a border (not grayscale anymore but more precise) }
    156156function CreateRectanglePreciseMap(width,height,border: integer; options: TRectangleMapOptions = []): TBGRABitmap;
     157function CreateRectanglePreciseMap(width, height, borderWidth, borderHeight: integer; options: TRectangleMapOptions): TBGRABitmap;
    157158
    158159{ Create a round rectangle height map with a border }
     
    161162{ Create a precise height map for a round rectangle height map with a border (not grayscale anymore but more precise) }
    162163function CreateRoundRectanglePreciseMap(width,height,border: integer; options: TRectangleMapOptions = []): TBGRABitmap;
     164function CreateRoundRectanglePreciseMap(width,height,borderWidth,borderHeight: integer; options: TRectangleMapOptions = []): TBGRABitmap;
    163165
    164166{---------- Perlin Noise -------------}
     
    177179implementation
    178180
    179 uses Types, SysUtils{$IFDEF BGRABITMAP_USE_LCL}, BGRATextFX{$ENDIF}; {GraphType unit used by phongdraw.inc}
     181uses Types, Math, SysUtils{$IFDEF BGRABITMAP_USE_LCL}, BGRATextFX{$ENDIF}; {GraphType unit used by phongdraw.inc}
    180182
    181183{$IFDEF BGRABITMAP_USE_LCL}function TextShadow(AWidth, AHeight: Integer; AText: String;
     
    767769end;
    768770
     771procedure MapBorderLimit(width,height: integer; options: TRectangleMapOptions; var borderHoriz,borderVert: integer);
     772var maxHoriz,maxVert: integer;
     773begin
     774  if [rmoNoLeftBorder,rmoNoRightBorder] <= options then maxHoriz := borderHoriz else
     775  if [rmoNoLeftBorder,rmoNoRightBorder] * options = [] then maxHoriz := width div 2 else
     776    maxHoriz := width;
     777  if borderHoriz > maxHoriz then borderHoriz := maxHoriz;
     778
     779  if [rmoNoTopBorder,rmoNoBottomBorder] <= options then maxVert := borderVert else
     780  if [rmoNoTopBorder,rmoNoBottomBorder] * options = [] then maxVert := height div 2 else
     781    maxVert := height;
     782  if borderVert > maxVert then borderVert := maxVert;
     783end;
     784
    769785function CreateSpherePreciseMap(width, height: integer): TBGRABitmap;
    770786var cx,cy,rx,ry,d: single;
     
    898914     if rmoLinearBorder in options then h := h/border else
    899915       h := sin((h+1/2)/border*Pi/2);
     916
     917     p^ := MapHeightToBGRA(h,255);
     918
     919     inc(p);
     920   end;
     921  end;
     922
     923  RectangleMapRemoveCorners(result,options);
     924end;
     925
     926function CreateRectanglePreciseMap(width, height, borderWidth, borderHeight: integer;
     927  options: TRectangleMapOptions): TBGRABitmap;
     928var xb,yb, minBorder: integer;
     929    p: PBGRAPixel;
     930    h: single;
     931    smallStep: single;
     932begin
     933  MapBorderLimit(width,height,options,borderWidth,borderHeight);
     934
     935  minBorder := min(borderWidth,borderHeight);
     936  if minBorder > 0 then smallStep := 1/minBorder else smallStep:= 0;
     937
     938  result := TBGRABitmap.Create(width,height);
     939  for yb := 0 to height-1 do
     940  begin
     941   p := result.scanline[yb];
     942   for xb := 0 to width-1 do
     943   begin
     944     if not (rmoNoLeftBorder in options) and (xb < borderWidth) and (yb < borderHeight) then
     945        h := min(xb/borderWidth, yb/borderHeight) else
     946     if not (rmoNoRightBorder in options) and (xb > width-1-borderWidth) and (yb < borderHeight) then
     947        h := min((width-1-xb)/borderWidth, yb/borderHeight) else
     948     if not (rmoNoTopBorder in options) and (xb < borderWidth) and (yb > height-1-borderHeight) then
     949        h := min(xb/borderWidth, (height-1-yb)/borderHeight) else
     950     if not (rmoNoBottomBorder in options) and  (xb > width-1-borderWidth) and (yb > height-1-borderHeight) then
     951        h := min((width-1-xb)/borderWidth, (height-1-yb)/borderHeight) else
     952     if not (rmoNoLeftBorder in options) and (xb < borderWidth) then h := xb/borderWidth else
     953     if not (rmoNoRightBorder in options) and (xb > width-1-borderWidth) then h := (width-1-xb)/borderWidth else
     954     if not (rmoNoTopBorder in options) and (yb < borderHeight) then h := yb/borderHeight else
     955     if not (rmoNoBottomBorder in options) and (yb > height-1-borderHeight) then h := (height-1-yb)/borderHeight else
     956     begin
     957       p^ := BGRAWhite;
     958       inc(p);
     959       Continue;
     960     end;
     961
     962     if not (rmoLinearBorder in options) then
     963       h := sin((h+smallStep*0.5)*Pi*0.5);
    900964
    901965     p^ := MapHeightToBGRA(h,255);
     
    10901154end;
    10911155
     1156function CreateRoundRectanglePreciseMap(width, height, borderWidth,
     1157  borderHeight: integer; options: TRectangleMapOptions): TBGRABitmap;
     1158var d: single;
     1159    xb,yb: integer;
     1160    p: PBGRAPixel;
     1161    h,smallStep,factor: single;
     1162    minBorder: integer;
     1163begin
     1164  MapBorderLimit(width,height,options,borderWidth,borderHeight);
     1165
     1166  minBorder := min(borderWidth,borderHeight);
     1167  if minBorder > 0 then smallStep := 1/minBorder else smallStep:= 0;
     1168  factor := minBorder/(minBorder+1);
     1169  result := TBGRABitmap.Create(width,height);
     1170  for yb := 0 to height-1 do
     1171  begin
     1172   p := result.scanline[yb];
     1173   for xb := 0 to width-1 do
     1174   begin
     1175     if not (rmoNoLeftBorder in options) and not (rmoNoTopBorder in options) and (xb < borderWidth) and (yb < borderHeight) then
     1176        d := 1-sqrt(sqr((borderWidth-xb)/borderWidth)+sqr((borderHeight-yb)/borderHeight)) else
     1177     if not (rmoNoLeftBorder in options) and not (rmoNoBottomBorder in options) and (xb < borderWidth) and (yb > height-1-borderHeight) then
     1178        d := 1-sqrt(sqr((borderWidth-xb)/borderWidth)+sqr((borderHeight-(height-1-yb))/borderHeight)) else
     1179     if not (rmoNoRightBorder in options) and not (rmoNoTopBorder in options) and (xb > width-1-borderWidth) and (yb < borderHeight) then
     1180        d := 1-sqrt(sqr((borderWidth-(width-1-xb))/borderWidth)+sqr((borderHeight-yb)/borderHeight)) else
     1181     if not (rmoNoRightBorder in options) and not (rmoNoBottomBorder in options) and (xb > width-1-borderWidth) and (yb > height-1-borderHeight) then
     1182        d := 1-sqrt(sqr((borderWidth-(width-1-xb))/borderWidth)+sqr((borderHeight-(height-1-yb))/borderHeight)) else
     1183     if not (rmoNoLeftBorder in options) and (xb < borderWidth) then d := xb/borderWidth else
     1184     if not (rmoNoRightBorder in options) and (xb > width-1-borderWidth) then d := (width-1-xb)/borderWidth else
     1185     if not (rmoNoTopBorder in options) and (yb < borderHeight) then d := yb/borderHeight else
     1186     if not (rmoNoBottomBorder in options) and (yb > height-1-borderHeight) then d := (height-1-yb)/borderHeight else
     1187     begin
     1188       p^ := BGRAWhite;
     1189       inc(p);
     1190       Continue;
     1191     end;
     1192
     1193     d := (d + smallStep)*factor;
     1194
     1195     if d < 0 then
     1196       p^ := BGRAPixelTransparent else
     1197     begin
     1198       if rmoLinearBorder in options then h := d else
     1199         h := sin((d+smallStep*0.5)*Pi*0.5);
     1200
     1201       if d < smallStep then p^:= MapHeightToBGRA(h,round(d/smallStep*255)) else
     1202         p^ := MapHeightToBGRA(h,255);
     1203     end;
     1204     inc(p);
     1205   end;
     1206  end;
     1207end;
     1208
    10921209initialization
    10931210
Note: See TracChangeset for help on using the changeset viewer.