[fpc-pascal] Performance problems with Image Conversions

Andrew Brunner atbrunner at aurawin.com
Mon Feb 25 20:46:25 CET 2013


Ok,  This matter has been solved.

The updated code is so simple and many factors faster!

Thanks to all!


class function Image.Transform(Stream:TMemoryStream; var 
iX,iY:Integer):boolean;
var
   status             : MagickBooleanType;
   wand               : PMagickWand;
   srcWidth,srcHeight : Cardinal;
   dstWidth,dstHeight : Cardinal;
   Factor             : Double;
   img                : Pimage;
   blob               : PByte;
   bSize              : QWord;
begin
   Result:=false;
   wand := NewMagickWand;
   Try
     Stream.Position := 0;
     status := MagickReadImageBlob(wand, Stream.Memory, Stream.Size);
     if (status = MagickTrue) then begin

       img := GetImageFromMagickWand(wand);

       srcHeight := MagickGetImageHeight(wand);
       srcWidth := MagickGetImageWidth(wand);
       if (srcWidth>=srcHeight) then begin
         Factor:=iX/srcWidth;
       end else begin
         Factor:=iY/srcHeight;
       end;
       dstWidth:=Trunc(srcWidth*Factor);
       dstHeight:=Trunc(srcHeight*Factor);
       if (srcWidth>iX) or (srcHeight>iY) then begin
         //MagickResizeImage(wand, 106, 80, LanczosFilter, 1.0);
         MagickScaleImage(wand, dstWidth, dstHeight);
         Stream.Size:=0;
         blob:=MagickGetImageBlob(wand, at bSize);
         Stream.Write(blob^,bSize);
         Result:=true;
       end;
     end;
   finally
     DestroyMagickWand(wand);
   end;
end;


-- 
Andrew Brunner

Aurawin LLC
15843 Garrison Circle
Austin, TX 78717

https://aurawin.com

Aurawin is a great new way to store, share, and explore all your content
featuring our innovative cloud social computing platform.



More information about the fpc-pascal mailing list