Browse Source

Merge branch 'thirdparty_dev' into dev

Source commit: 1071b16412930f1f8987efb4f0fd734863f24bae
Martin Prikryl 7 years ago
parent
commit
2fd0d2824f

+ 2 - 2
source/packages/png/PngBitBtn.pas

@@ -51,7 +51,7 @@ type
 implementation
 
 uses
-  ActnList, Themes, PngButtonFunctions;
+  ActnList, Themes, PngButtonFunctions, PngImageList;
 
 {$IF RTLVersion < 23.0 }
 type
@@ -111,9 +111,9 @@ end;
 
 destructor TPngBitBtn.Destroy;
 begin
+  inherited Destroy;
   FPngImage.Free;
   FCanvas.Free;
-  inherited Destroy;
 end;
 
 procedure TPngBitBtn.ActionChange(Sender: TObject; CheckDefaults: Boolean);

+ 4 - 52
source/packages/png/PngFunctions.pas

@@ -16,10 +16,6 @@ type
 type
   TPngOption = (pngBlendOnDisabled, pngGrayscaleOnDisabled);
   TPngOptions = set of TPngOption;
-  TRGBLine = array[Word] of TRGBTriple;
-  PRGBLine = ^TRGBLine;
-  TRGBALine = array[Word] of TRGBQuad;
-  PRGBALine = ^TRGBALine;
 
 procedure MakeImageBlended(Image: TPngImage; Amount: Byte = 127);
 procedure MakeImageGrayscale(Image: TPngImage; Amount: Byte = 255);
@@ -27,13 +23,12 @@ procedure DrawPNG(Png: TPngImage; Canvas: TCanvas; const ARect: TRect; const Opt
 procedure ConvertToPNG(Source: TGraphic; Dest: TPngImage);
 procedure CreatePNG(Color, Mask: TBitmap; Dest: TPngImage; InverseMask: Boolean = False);
 procedure CreatePNGMasked(Bitmap: TBitmap; Mask: TColor; Dest: TPngImage);
-procedure CopyImageFromImageList(Dest: TPngImage; ImageList: TCustomImageList; Index: Integer);
 procedure SlicePNG(JoinedPNG: TPngImage; Columns, Rows: Integer; out SlicedPNGs: TObjectList);
 
 implementation
 
 uses
-  SysUtils, PngImageList;
+  SysUtils;
 
 function ColorToTriple(Color: TColor): TRGBTriple;
 var
@@ -189,6 +184,9 @@ begin
 end;
 
 procedure ConvertToPNG(Source: TGraphic; Dest: TPngImage);
+type
+  TRGBALine = array[Word] of TRGBQuad;
+  PRGBALine = ^TRGBALine;
 var
   MaskLines: array of pngimage.PByteArray;
 
@@ -447,52 +445,6 @@ begin
   end;
 end;
 
-procedure CopyImageFromImageList(Dest: TPngImage; ImageList: TCustomImageList; Index: Integer);
-var
-  Icon: TIcon;
-  IconInfo: TIconInfo;
-  ColorBitmap, MaskBitmap: TBitmap;
-  X, Y: Integer;
-  AlphaLine: pngimage.PByteArray;
-  Png: TPngImageCollectionItem;
-begin
-  if ImageList is TPngImageList then begin
-    //This is easy, just copy the PNG object from the imagelist to the PNG object
-    //from the button
-    Png := TPNGImageList(ImageList).PngImages[Index];
-    if Png <> nil then
-      Dest.Assign(Png.PngImage);
-  end
-  else begin
-    Icon := TIcon.Create;
-    ColorBitmap := TBitmap.Create;
-    MaskBitmap := TBitmap.Create;
-    try
-      //Try to copy an icon to a PNG object, including transparency
-      ImageList.GetIcon(Index, Icon);
-      if GetIconInfo(Icon.Handle, IconInfo) then begin
-        //First, pump the colors into the PNG object
-        ColorBitmap.Handle := IconInfo.hbmColor;
-        ColorBitmap.PixelFormat := pf24bit;
-        Dest.Assign(ColorBitmap);
-
-        //Finally, copy the transparency
-        Dest.CreateAlpha;
-        MaskBitmap.Handle := IconInfo.hbmMask;
-        for Y := 0 to Dest.Height - 1 do begin
-          AlphaLine := Dest.AlphaScanline[Y];
-          for X := 0 to Dest.Width - 1 do
-            AlphaLine^[X] := Integer(GetPixel(MaskBitmap.Canvas.Handle, X, Y) = COLORREF(clBlack)) * $FF;
-        end;
-      end;
-    finally
-      MaskBitmap.Free;
-      ColorBitmap.Free;
-      Icon.Free;
-    end;
-  end;
-end;
-
 procedure SlicePNG(JoinedPNG: TPngImage; Columns, Rows: Integer; out SlicedPNGs: TObjectList);
 var
   X, Y, ImageX, ImageY, OffsetX, OffsetY: Integer;

+ 48 - 0
source/packages/png/PngImageList.pas

@@ -121,6 +121,8 @@ type
     property PngImage: TPngImage read FPngImage write SetPngImage;
   end;
 
+procedure CopyImageFromImageList(Dest: TPngImage; ImageList: TCustomImageList; Index: Integer);
+
 implementation
 
 uses
@@ -266,6 +268,52 @@ begin
   end;
 end;
 
+procedure CopyImageFromImageList(Dest: TPngImage; ImageList: TCustomImageList; Index: Integer);
+var
+  Icon: TIcon;
+  IconInfo: TIconInfo;
+  ColorBitmap, MaskBitmap: TBitmap;
+  X, Y: Integer;
+  AlphaLine: pngimage.PByteArray;
+  Png: TPngImageCollectionItem;
+begin
+  if ImageList is TPngImageList then begin
+    //This is easy, just copy the PNG object from the imagelist to the PNG object
+    //from the button
+    Png := TPNGImageList(ImageList).PngImages[Index];
+    if Png <> nil then
+      Dest.Assign(Png.PngImage);
+  end
+  else begin
+    Icon := TIcon.Create;
+    ColorBitmap := TBitmap.Create;
+    MaskBitmap := TBitmap.Create;
+    try
+      //Try to copy an icon to a PNG object, including transparency
+      ImageList.GetIcon(Index, Icon);
+      if GetIconInfo(Icon.Handle, IconInfo) then begin
+        //First, pump the colors into the PNG object
+        ColorBitmap.Handle := IconInfo.hbmColor;
+        ColorBitmap.PixelFormat := pf24bit;
+        Dest.Assign(ColorBitmap);
+
+        //Finally, copy the transparency
+        Dest.CreateAlpha;
+        MaskBitmap.Handle := IconInfo.hbmMask;
+        for Y := 0 to Dest.Height - 1 do begin
+          AlphaLine := Dest.AlphaScanline[Y];
+          for X := 0 to Dest.Width - 1 do
+            AlphaLine^[X] := Integer(GetPixel(MaskBitmap.Canvas.Handle, X, Y) = COLORREF(clBlack)) * $FF;
+        end;
+      end;
+    finally
+      MaskBitmap.Free;
+      ColorBitmap.Free;
+      Icon.Free;
+    end;
+  end;
+end;
+
 { TMethodPatch }
 
 constructor TMethodPatch.Create;

+ 2 - 2
source/packages/png/PngSpeedButton.pas

@@ -33,7 +33,7 @@ type
 implementation
 
 uses
-  Graphics, ActnList, PngButtonFunctions;
+  Graphics, ActnList, PngButtonFunctions, PngImageList;
 
 { TPngSpeedButton }
 
@@ -47,8 +47,8 @@ end;
 
 destructor TPngSpeedButton.Destroy;
 begin
-  FPngImage.Free;
   inherited Destroy;
+  FPngImage.Free;
 end;
 
 procedure TPngSpeedButton.ActionChange(Sender: TObject; CheckDefaults: Boolean);