Recent

Author Topic: New version of BGRABitmap  (Read 171530 times)

lainz

  • Hero Member
  • *****
  • Posts: 3277
    • Lainz
Re: New version of BGRABitmap
« Reply #525 on: November 06, 2019, 04:48:12 pm »
Ok sounds good. When you're done just delete that repository so it doesn't have duplicate content.

My knowledge stops there I can't help more  ::)
« Last Edit: November 06, 2019, 04:50:48 pm by lainz »

circular

  • Hero Member
  • *****
  • Posts: 3022
    • Personal webpage
Re: New version of BGRABitmap
« Reply #526 on: November 06, 2019, 05:51:04 pm »
Hmm I think you can help a bit more. Let me explain and tell me if you are interested in the adventure.

When doing LoadLibrary (of unit dynlibs), you get a handle. Then with GetProcedureAddress you get a procedure address. So instead of declaring the procedure with an external keyword, you declare variable of procedure type, and assign them with the address you get from GetProcedureAddress.

Declaring the procedure type is like declaring an event procedure. Then you can declare a variable of this type.

https://wiki.freepascal.org/Lazarus/FPC_Libraries#Loadlibrary_-_dynamically_loading_a_dynamic_library

Regards
Conscience is the debugger of the mind

winni

  • Sr. Member
  • ****
  • Posts: 436
Re: New version of BGRABitmap
« Reply #527 on: November 06, 2019, 06:12:02 pm »

Oh, there seem to be interesting stuff about polygon clipping.

Hi!

There is a lot of graphic stuff and I think also about polygons.

About polygon clipping I cant help now, but I did a lot of research about [is]PointInPoly[gon] .

I worked on geo maps and the computers were slower -10 years ago.
Despite reducing the polygon points of the areas I tried to find out the quickest algos.
I did 2 days testing  for 5 different kinds of PointInPoly.

The quickest one is this:

Code: Pascal  [Select]
  1. function PointInPoly(p : TPointF; const poly :  array of TPointF) : Boolean; inline;
  2. var i,k : integer;
  3.  
  4. Begin
  5.  result := false;
  6.  k := High(poly);
  7.  For i := Low(poly) to High(poly) do begin
  8.   if  (
  9.      ( ((poly[i].y <= p.y) and (p.y < poly[k].y)) or ((poly[k].y <= p.y) and (p.y < poly[i].y)) )
  10.       and
  11.         (p.x < ((poly[k].x - poly[i].x) * (p.y - poly[i].y) / (poly[k].y - poly[i].y) + poly[i].x) )
  12.      )
  13.         then result := not result;
  14.   k := i;
  15.  end;
  16. end;

It is quicker the the "default" function that is flying around in the net as C code and is used in
lazregions. pas in the LCL.

In the moment the above inline is obsolet because the compiler does not support open arrays for inline -
as he yowls.

The above function can easily used for TPoint and Array of Tpoint - only the declaration has to be changed.

Winni


« Last Edit: November 06, 2019, 06:14:21 pm by winni »

winni

  • Sr. Member
  • ****
  • Posts: 436
Re: New version of BGRABitmap
« Reply #528 on: November 07, 2019, 01:13:59 am »
Oh, there seem to be interesting stuff about polygon clipping.

Hi!

Did a walk through my bookmarks and found a good Geeks page about polygon clipping:

https://www.geeksforgeeks.org/polygon-clipping-sutherland-hodgman-algorithm-please-change-bmp-images-jpeg-png/

The code is in C but good readable.


For what reason do you need it?

Winni

circular

  • Hero Member
  • *****
  • Posts: 3022
    • Personal webpage
Re: New version of BGRABitmap
« Reply #529 on: November 07, 2019, 04:35:00 pm »
I am thinking about using polygon clipping the LazPaint selection. For now, the whole selection is vectorized as one bitmap, but if I add vectorial selection, that would not work anymore.
Conscience is the debugger of the mind

Segator

  • Jr. Member
  • **
  • Posts: 53
Re: New version of BGRABitmap
« Reply #530 on: November 07, 2019, 04:38:20 pm »
The .webp file support is done?

circular

  • Hero Member
  • *****
  • Posts: 3022
    • Personal webpage
Re: New version of BGRABitmap
« Reply #531 on: November 07, 2019, 05:33:12 pm »
@Segator:
Nope.

Compile-time linking can be done using the code on the repository there:
https://github.com/bgrabitmap/webp/tree/master/bgrawebp

For now I have proposed Lainz to try to make late-loading of the library. He is probably busy on something else.
Conscience is the debugger of the mind

winni

  • Sr. Member
  • ****
  • Posts: 436
Re: New version of BGRABitmap
« Reply #532 on: November 07, 2019, 07:16:55 pm »
@circular

Hi!

There is Pascal code for intersecting polygons!

Angus Johnson is the man who wrote the Image32 library for Delphi.

He also wrote the "Clipper Library" on base of the Vatti algorithm, which is the most complete and does not separate the cases concav, convex and complex.

The source is in C++, C# and Delphi 7-10!

http://www.angusj.com/delphi/clipper.php

Keep on BGRAing!

Winni

circular

  • Hero Member
  • *****
  • Posts: 3022
    • Personal webpage
Re: New version of BGRABitmap
« Reply #533 on: November 07, 2019, 08:11:11 pm »
@winni:
Cool that looks like the library I need.  8-)

Quote
Keep on BGRAing!
:D Sure I think I will  :)
Conscience is the debugger of the mind

lainz

  • Hero Member
  • *****
  • Posts: 3277
    • Lainz
Re: New version of BGRABitmap
« Reply #534 on: November 07, 2019, 10:09:22 pm »
Hi for sure I want to help to make the webp into bgrabitmap. The thing is that I'm with regular headaches these days since I'm diagnosed with sinusitis. When I recover I will help.

winni

  • Sr. Member
  • ****
  • Posts: 436
Re: New version of BGRABitmap
« Reply #535 on: November 08, 2019, 02:00:14 am »
@lainz

🤧

Get well soon!

Winni

Segator

  • Jr. Member
  • **
  • Posts: 53
Re: New version of BGRABitmap
« Reply #536 on: November 08, 2019, 05:21:18 pm »
@lainz thanks

I hope you get well!

circular

  • Hero Member
  • *****
  • Posts: 3022
    • Personal webpage
Re: New version of BGRABitmap
« Reply #537 on: November 08, 2019, 07:23:29 pm »
I think we did it. fredvs did the dynamic loading and I did the search for the library on linux. So basically, on Linux, it uses the installed library libwebp and on Windows and MacOS one need to supply the library. I haven't tested it on MacOS though.

But main thing, it doesn't require to install libwebp-dev, so if I add this to BGRABitmap, people won't have to install this package to compile.
Conscience is the debugger of the mind

Segator

  • Jr. Member
  • **
  • Posts: 53
Re: New version of BGRABitmap
« Reply #538 on: November 08, 2019, 07:35:02 pm »
On Windows you can display .webp with out external library, check this Double Commander implementation:
Code: Pascal  [Select]
  1. {
  2.    Double Commander
  3.    -------------------------------------------------------------------------
  4.    Windows thumbnail provider
  5.  
  6.    Copyright (C) 2012-2013 Alexander Koblov (alexx2000@mail.ru)
  7.  
  8.    This library is free software; you can redistribute it and/or
  9.    modify it under the terms of the GNU Lesser General Public
  10.    License as published by the Free Software Foundation; either
  11.    version 2.1 of the License, or (at your option) any later version.
  12.  
  13.    This library is distributed in the hope that it will be useful,
  14.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.    Lesser General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU Lesser General Public
  19.    License along with this library; if not, write to the Free Software
  20.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  21. }
  22.  
  23. unit uThumbnailProvider;
  24.  
  25. {$mode delphi}
  26.  
  27. interface
  28.  
  29. uses
  30.   uThumbnails;
  31.  
  32. implementation
  33.  
  34. uses
  35.   SysUtils, Forms, Graphics, Windows, ActiveX, ShlObj;
  36.  
  37. const
  38.   SIIGBF_RESIZETOFIT   = $00000000;
  39.   SIIGBF_BIGGERSIZEOK  = $00000001;
  40.   SIIGBF_MEMORYONLY    = $00000002;
  41.   SIIGBF_ICONONLY      = $00000004;
  42.   SIIGBF_THUMBNAILONLY = $00000008;
  43.   SIIGBF_INCACHEONLY   = $00000010;
  44.  
  45. const
  46.   IID_IExtractImage: TGUID = '{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}';
  47.  
  48. type
  49.   SIIGBF = Integer;
  50.  
  51.   IShellItemImageFactory = interface(IUnknown)
  52.     ['{BCC18B79-BA16-442F-80C4-8A59C30C463B}']
  53.     function GetImage(size: TSize; flags: SIIGBF; out phbm: HBITMAP): HRESULT; stdcall;
  54.   end;
  55.  
  56.   IExtractImage = interface(IUnknown)
  57.     ['{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}']
  58.     function GetLocation(pszPathBuffer: LPWSTR; cchMax: DWORD; out pdwPriority: DWORD;
  59.       const prgSize: LPSIZE; dwRecClrDepth: DWORD; var pdwFlags: DWORD): HRESULT; stdcall;
  60.     function Extract(out phBmpImage: HBITMAP): HRESULT; stdcall;
  61.   end;
  62.  
  63. var
  64.   SHCreateItemFromParsingName: function(pszPath: LPCWSTR; const pbc: IBindCtx;
  65.                                         const riid: TIID; out ppv): HRESULT; stdcall;
  66.  
  67. function GetThumbnailOld(const aFileName: String; aSize: TSize; out Bitmap: HBITMAP): HRESULT;
  68. var
  69.   Folder,
  70.   DesktopFolder: IShellFolder;
  71.   Pidl,
  72.   ParentPidl: PItemIDList;
  73.   Image: IExtractImage;
  74.   pchEaten: ULONG;
  75.   wsTemp: WideString;
  76.   dwPriority: DWORD;
  77.   Status: HRESULT;
  78.   dwRecClrDepth: DWORD;
  79.   dwAttributes: ULONG = 0;
  80.   dwFlags: DWORD = IEIFLAG_SCREEN or IEIFLAG_QUALITY or IEIFLAG_ORIGSIZE;
  81. begin
  82.   Result:= E_FAIL;
  83.  
  84.   if SHGetDesktopFolder(DesktopFolder) = S_OK then
  85.   begin
  86.     wsTemp:= UTF8Decode(ExtractFilePath(aFileName));
  87.     if DesktopFolder.ParseDisplayName(0, nil, PWideChar(wsTemp), pchEaten, ParentPidl, dwAttributes) = S_OK then
  88.     begin
  89.       if DesktopFolder.BindToObject(ParentPidl, nil, IID_IShellFolder, Folder) = S_OK then
  90.       begin
  91.         wsTemp:= UTF8Decode(ExtractFileName(aFileName));
  92.         if Folder.ParseDisplayName(0, nil, PWideChar(wsTemp), pchEaten, Pidl, dwAttributes) = S_OK then
  93.         begin
  94.           if Succeeded(Folder.GetUIObjectOf(0, 1, Pidl, IID_IExtractImage, nil, Image)) then
  95.           begin
  96.             SetLength(wsTemp, MAX_PATH * SizeOf(WideChar));
  97.             dwRecClrDepth:= GetDeviceCaps(Application.MainForm.Canvas.Handle, BITSPIXEL);
  98.             Status:= Image.GetLocation(PWideChar(wsTemp), Length(wsTemp), dwPriority, @aSize, dwRecClrDepth, dwFlags);
  99.             if (Status = NOERROR) or (Status = E_PENDING) then
  100.             begin
  101.               Result:= Image.Extract(Bitmap);
  102.             end;
  103.           end;
  104.           CoTaskMemFree(Pidl);
  105.         end;
  106.         Folder:= nil;
  107.       end;
  108.       CoTaskMemFree(ParentPidl);
  109.     end;
  110.     DesktopFolder:= nil;
  111.   end; // SHGetDesktopFolder
  112. end;
  113.  
  114. function GetThumbnailNew(const aFileName: String; aSize: TSize; out Bitmap: HBITMAP): HRESULT;
  115. var
  116.   ShellItemImage: IShellItemImageFactory;
  117. begin
  118.   Result:= SHCreateItemFromParsingName(PWideChar(UTF8Decode(aFileName)), nil,
  119.                                        IShellItemImageFactory, ShellItemImage);
  120.   if Succeeded(Result) then
  121.   begin
  122.     Result:= ShellItemImage.GetImage(aSize, SIIGBF_THUMBNAILONLY, Bitmap);
  123.   end;
  124. end;
  125.  
  126. function GetThumbnail(const aFileName: String; aSize: TSize): Graphics.TBitmap;
  127. var
  128.   Bitmap: HBITMAP;
  129.   Status: HRESULT = E_FAIL;
  130. begin
  131.   Result:= nil;
  132.  
  133.   if (Win32MajorVersion > 5) then
  134.   begin
  135.     Status:= GetThumbnailNew(aFileName, aSize, Bitmap);
  136.   end;
  137.  
  138.   if Failed(Status) then
  139.   begin
  140.     Status:= GetThumbnailOld(aFileName, aSize, Bitmap);
  141.   end;
  142.  
  143.   if Succeeded(Status) then
  144.   begin
  145.     Result:= Graphics.TBitmap.Create;
  146.     Result.Handle:= Bitmap;
  147.   end;
  148. end;
  149.  
  150. initialization
  151.   SHCreateItemFromParsingName:= GetProcAddress(GetModuleHandle('shell32.dll'),
  152.                                                'SHCreateItemFromParsingName');
  153.   TThumbnailManager.RegisterProvider(@GetThumbnail);
  154.  
  155. end.

i modified it to use with out doublecmd depennd and share functions:

Code: Pascal  [Select]
  1. {
  2.    Double Commander
  3.    -------------------------------------------------------------------------
  4.    Windows thumbnail provider
  5.  
  6.    Copyright (C) 2012-2013 Alexander Koblov (alexx2000@mail.ru)
  7.  
  8.    This library is free software; you can redistribute it and/or
  9.    modify it under the terms of the GNU Lesser General Public
  10.    License as published by the Free Software Foundation; either
  11.    version 2.1 of the License, or (at your option) any later version.
  12.  
  13.    This library is distributed in the hope that it will be useful,
  14.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.    Lesser General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU Lesser General Public
  19.    License along with this library; if not, write to the Free Software
  20.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  21. }
  22.  
  23. unit uThumbnailProvider;
  24.  
  25. {$mode delphi}
  26.  
  27. interface
  28.  
  29.  
  30.  
  31.  
  32. uses
  33.   SysUtils, Forms, Graphics, Windows, ActiveX, ShlObj;
  34.  
  35. const
  36.   SIIGBF_RESIZETOFIT   = $00000000;
  37.   SIIGBF_BIGGERSIZEOK  = $00000001;
  38.   SIIGBF_MEMORYONLY    = $00000002;
  39.   SIIGBF_ICONONLY      = $00000004;
  40.   SIIGBF_THUMBNAILONLY = $00000008;
  41.   SIIGBF_INCACHEONLY   = $00000010;
  42.  
  43. const
  44.   IID_IExtractImage: TGUID = '{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}';
  45.  
  46. type
  47.   SIIGBF = Integer;
  48.  
  49.   IShellItemImageFactory = interface(IUnknown)
  50.     ['{BCC18B79-BA16-442F-80C4-8A59C30C463B}']
  51.     function GetImage(size: TSize; flags: SIIGBF; out phbm: HBITMAP): HRESULT; stdcall;
  52.   end;
  53.  
  54.   IExtractImage = interface(IUnknown)
  55.     ['{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}']
  56.     function GetLocation(pszPathBuffer: LPWSTR; cchMax: DWORD; out pdwPriority: DWORD;
  57.       const prgSize: LPSIZE; dwRecClrDepth: DWORD; var pdwFlags: DWORD): HRESULT; stdcall;
  58.     function Extract(out phBmpImage: HBITMAP): HRESULT; stdcall;
  59.   end;
  60.  
  61. var
  62.   SHCreateItemFromParsingName: function(pszPath: LPCWSTR; const pbc: IBindCtx;
  63.                                         const riid: TIID; out ppv): HRESULT; stdcall;
  64.   function GetThumbnail(const aFileName: String; aSize: TSize): Graphics.TBitmap;
  65.  
  66. implementation
  67.  
  68.  
  69. function GetThumbnailOld(const aFileName: String; aSize: TSize; out Bitmap: HBITMAP): HRESULT;
  70. var
  71.   Folder,
  72.   DesktopFolder: IShellFolder;
  73.   Pidl,
  74.   ParentPidl: PItemIDList;
  75.   Image: IExtractImage;
  76.   pchEaten: ULONG;
  77.   wsTemp: WideString;
  78.   dwPriority: DWORD;
  79.   Status: HRESULT;
  80.   dwRecClrDepth: DWORD;
  81.   dwAttributes: ULONG = 0;
  82.   dwFlags: DWORD = IEIFLAG_SCREEN or IEIFLAG_QUALITY or IEIFLAG_ORIGSIZE;
  83. begin
  84.   Result:= E_FAIL;
  85.  
  86.   if SHGetDesktopFolder(DesktopFolder) = S_OK then
  87.   begin
  88.     wsTemp:= UTF8Decode(ExtractFilePath(aFileName));
  89.     if DesktopFolder.ParseDisplayName(0, nil, PWideChar(wsTemp), pchEaten, ParentPidl, dwAttributes) = S_OK then
  90.     begin
  91.       if DesktopFolder.BindToObject(ParentPidl, nil, IID_IShellFolder, Folder) = S_OK then
  92.       begin
  93.         wsTemp:= UTF8Decode(ExtractFileName(aFileName));
  94.         if Folder.ParseDisplayName(0, nil, PWideChar(wsTemp), pchEaten, Pidl, dwAttributes) = S_OK then
  95.         begin
  96.           if Succeeded(Folder.GetUIObjectOf(0, 1, Pidl, IID_IExtractImage, nil, Image)) then
  97.           begin
  98.             SetLength(wsTemp, MAX_PATH * SizeOf(WideChar));
  99.             dwRecClrDepth:= GetDeviceCaps(Application.MainForm.Canvas.Handle, BITSPIXEL);
  100.             Status:= Image.GetLocation(PWideChar(wsTemp), Length(wsTemp), dwPriority, @aSize, dwRecClrDepth, dwFlags);
  101.             if (Status = NOERROR) or (Status = E_PENDING) then
  102.             begin
  103.               Result:= Image.Extract(Bitmap);
  104.             end;
  105.           end;
  106.           CoTaskMemFree(Pidl);
  107.         end;
  108.         Folder:= nil;
  109.       end;
  110.       CoTaskMemFree(ParentPidl);
  111.     end;
  112.     DesktopFolder:= nil;
  113.   end; // SHGetDesktopFolder
  114. end;
  115.  
  116. function GetThumbnailNew(const aFileName: String; aSize: TSize; out Bitmap: HBITMAP): HRESULT;
  117. var
  118.   ShellItemImage: IShellItemImageFactory;
  119. begin
  120.   Result:= SHCreateItemFromParsingName(PWideChar(UTF8Decode(aFileName)), nil,
  121.                                        IShellItemImageFactory, ShellItemImage);
  122.   if Succeeded(Result) then
  123.   begin
  124.     Result:= ShellItemImage.GetImage(aSize, SIIGBF_THUMBNAILONLY, Bitmap);
  125.   end;
  126. end;
  127.  
  128. function GetThumbnail(const aFileName: String; aSize: TSize): Graphics.TBitmap;
  129. var
  130.   Bitmap: HBITMAP;
  131.   Status: HRESULT = E_FAIL;
  132. begin
  133.   Result:= nil;
  134.  
  135.   if (Win32MajorVersion > 5) then
  136.   begin
  137.     Status:= GetThumbnailNew(aFileName, aSize, Bitmap);
  138.   end;
  139.  
  140.   if Failed(Status) then
  141.   begin
  142.     Status:= GetThumbnailOld(aFileName, aSize, Bitmap);
  143.   end;
  144.  
  145.   if Succeeded(Status) then
  146.   begin
  147.     Result:= Graphics.TBitmap.Create;
  148.     Result.Handle:= Bitmap;
  149.   end;
  150. end;
  151.  
  152. initialization
  153.   SHCreateItemFromParsingName:= GetProcAddress(GetModuleHandle('shell32.dll'),
  154.                                                'SHCreateItemFromParsingName');
  155.  
  156. end.
  157.  
  158.  

Segator

  • Jr. Member
  • **
  • Posts: 53
Re: New version of BGRABitmap
« Reply #539 on: November 08, 2019, 07:37:02 pm »
but its just to display, you can't save to .webp