浏览代码

UPD: Optimize SVG rendering speed

Alexander Koblov 2 年之前
父节点
当前提交
b8e13477b0
共有 1 个文件被更改,包括 3 次插入16 次删除
  1. 3 16
      src/platform/udcreadsvg.pas

+ 3 - 16
src/platform/udcreadsvg.pas

@@ -3,7 +3,7 @@
    -------------------------------------------------------------------------
    -------------------------------------------------------------------------
    Scalable Vector Graphics reader implementation (via rsvg and cairo)
    Scalable Vector Graphics reader implementation (via rsvg and cairo)
 
 
-   Copyright (C) 2012-2019 Alexander Koblov ([email protected])
+   Copyright (C) 2012-2022 Alexander Koblov ([email protected])
 
 
    This library is free software; you can redistribute it and/or
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    modify it under the terms of the GNU Lesser General Public
@@ -109,9 +109,7 @@ type
 procedure RsvgHandleRender(RsvgHandle: Pointer; CairoSurface: Pcairo_surface_t;
 procedure RsvgHandleRender(RsvgHandle: Pointer; CairoSurface: Pcairo_surface_t;
                            Cairo: Pcairo_t; Img: TFPCustomImage);
                            Cairo: Pcairo_t; Img: TFPCustomImage);
 var
 var
-  X, Y: Integer;
   ImageData: PBGRA;
   ImageData: PBGRA;
-  PixelColor: TFPColor;
   Desc: TRawImageDescription;
   Desc: TRawImageDescription;
 begin
 begin
   try
   try
@@ -123,19 +121,8 @@ begin
       // Initialize image description
       // Initialize image description
       Desc.Init_BPP32_B8G8R8A8_BIO_TTB(Img.Width, Img.Height);
       Desc.Init_BPP32_B8G8R8A8_BIO_TTB(Img.Width, Img.Height);
       TLazIntfImage(Img).DataDescription:= Desc;
       TLazIntfImage(Img).DataDescription:= Desc;
-      // Read image data
-      for Y:= 0 to Img.Height - 1 do
-      for X:= 0 to Img.Width - 1 do
-      with ImageData^ do
-      begin
-        PixelColor.alpha:= Alpha + Alpha shl 8;
-        PixelColor.red:= Red + Red shl 8;
-        PixelColor.green:= Green + Green shl 8;
-        PixelColor.blue:= Blue + Blue shl 8;
-
-        Img.Colors[X, Y]:= PixelColor;
-        Inc(ImageData);
-      end;
+      // Copy image data
+      Move(ImageData^, TLazIntfImage(Img).PixelData^, Img.Width * Img.Height * SizeOf(TBGRA));
     end;
     end;
   finally
   finally
     g_object_unref(RsvgHandle);
     g_object_unref(RsvgHandle);