The MASM Forum

Projects => Poasm => Pelle's C compiler and tools => Topic started by: TimoVJL on October 14, 2022, 05:23:54 PM

Title: WebP test libwebp.dll
Post by: TimoVJL on October 14, 2022, 05:23:54 PM
Here are dlls, lib and headers for WebP developments.

A silly example to create a test.webp file#include <stdio.h>
#include <stdint.h>
#pragma comment(lib, "libwebp")

int __cdecl WebPGetEncoderVersion(void);
void __cdecl WebPFree(void* ptr);
size_t __cdecl WebPEncodeRGBA(const uint8_t* rgba, int width, int height, int stride, float quality_factor, uint8_t** output);
int __cdecl main(int argc, char **argv)
{
char bits[80000];
unsigned char *webp_data;
printf("WebP version: %04X\n", WebPGetEncoderVersion());
for (int i=0; i<20000; i += 4) {
bits[i] = i % 255;
bits[i+1] = i % 255;
bits[i+2] = (255 - i) % 255;
bits[i+3] = 255;
}
int ret = WebPEncodeRGBA(bits, 100, 100, 80, 80.0, &webp_data);
printf("len: %u\n", ret);
FILE *fp = fopen("test.webp", "wb");
fwrite(webp_data, ret, 1, fp);
fclose(fp);
WebPFree(webp_data);
return 0;
}

https://wikidll.com/other/libwebp-dll
https://developers.google.com/speed/webp/docs/api
to create import lib
polib libwebp.dll -machine:x86
polib libwebp.dll -machine:x64
Title: Re: WebP test libwebp.dll
Post by: Biterider on October 14, 2022, 06:42:04 PM
 :thumbsup:
Title: Re: WebP test libwebp.dll
Post by: jj2007 on October 14, 2022, 08:09:10 PM
Interesting stuff, but I wonder what happens if the user has not installed the 20MB webp package :rolleyes:

https://stackoverflow.com/questions/73094824/display-a-webp-image-in-windows-forms-c-sharp

You can get the short version of libwebp.dll from https://www.dll-files.com/libwebp.dll.html, just 350kB, but I have no idea how to get a hBitmap with it.

pFile Data Description Value
00050FD8 00006010 Function RVA 0001 VP8CheckSignature
00050FDC 00006040 Function RVA 0002 VP8GetInfo
00050FE0 00007700 Function RVA 0003 VP8LCheckSignature
00050FE4 00007770 Function RVA 0004 VP8LGetInfo
00050FE8 0002C5F0 Function RVA 0005 WebPBlendAlpha
00050FEC 0002C320 Function RVA 0006 WebPCleanupTransparentArea
00050FF0 00024240 Function RVA 0007 WebPConfigInitInternal
00050FF4 0000AD00 Function RVA 0008 WebPDecode
00050FF8 0000B030 Function RVA 0009 WebPDecodeARGB
00050FFC 0000A980 Function RVA 000A WebPDecodeARGBInto
00051000 0000B060 Function RVA 000B WebPDecodeBGR
00051004 0000B090 Function RVA 000C WebPDecodeBGRA
00051008 0000A9E0 Function RVA 000D WebPDecodeBGRAInto
0005100C 0000A9B0 Function RVA 000E WebPDecodeBGRInto
00051010 0000AFD0 Function RVA 000F WebPDecodeRGB
00051014 0000B000 Function RVA 0010 WebPDecodeRGBA
00051018 0000A950 Function RVA 0011 WebPDecodeRGBAInto
0005101C 0000A920 Function RVA 0012 WebPDecodeRGBInto
00051020 0000B0C0 Function RVA 0013 WebPDecodeYUV
00051024 0000AA10 Function RVA 0014 WebPDecodeYUVInto
00051028 00032CE0 Function RVA 0015 WebPEncode
0005102C 0002A1D0 Function RVA 0016 WebPEncodeBGR
00051030 0002A250 Function RVA 0017 WebPEncodeBGRA
00051034 0002A2D0 Function RVA 0018 WebPEncodeLosslessBGR
00051038 0002A350 Function RVA 0019 WebPEncodeLosslessBGRA
0005103C 0002A290 Function RVA 001A WebPEncodeLosslessRGB
00051040 0002A310 Function RVA 001B WebPEncodeLosslessRGBA
00051044 0002A190 Function RVA 001C WebPEncodeRGB
00051048 0002A210 Function RVA 001D WebPEncodeRGBA
0005104C 00020BA0 Function RVA 001E WebPFree
00051050 00001750 Function RVA 001F WebPFreeDecBuffer
00051054 000326E0 Function RVA 0020 WebPGetDecoderVersion
00051058 000326E0 Function RVA 0021 WebPGetEncoderVersion
0005105C 0000ACD0 Function RVA 0022 WebPGetFeaturesInternal
00051060 0000ABA0 Function RVA 0023 WebPGetInfo
00051064 00020AB0 Function RVA 0024 WebPGetWorkerInterface
00051068 00003F30 Function RVA 0025 WebPIAppend
0005106C 00004090 Function RVA 0026 WebPIDecGetRGB
00051070 000040F0 Function RVA 0027 WebPIDecGetYUVA
00051074 00003C20 Function RVA 0028 WebPIDecode
00051078 00004010 Function RVA 0029 WebPIDecodedArea
0005107C 00003C80 Function RVA 002A WebPIDelete
00051080 00003B70 Function RVA 002B WebPINewDecoder
00051084 00003D10 Function RVA 002C WebPINewRGB
00051088 00003EF0 Function RVA 002D WebPINewYUV
0005108C 00003D90 Function RVA 002E WebPINewYUVA
00051090 00003FA0 Function RVA 002F WebPIUpdate
00051094 00001720 Function RVA 0030 WebPInitDecBufferInternal
00051098 0000AC60 Function RVA 0031 WebPInitDecoderConfigInternal
0005109C 00029F20 Function RVA 0032 WebPMemoryWrite
000510A0 00029F10 Function RVA 0033 WebPMemoryWriterInit
000510A4 0002B080 Function RVA 0034 WebPPictureARGBToYUVA
000510A8 0002B020 Function RVA 0035 WebPPictureARGBToYUVADithered
000510AC 00029FE0 Function RVA 0036 WebPPictureAlloc
000510B0 0002BB60 Function RVA 0037 WebPPictureCopy
000510B4 0002BDC0 Function RVA 0038 WebPPictureCrop
000510B8 0002B760 Function RVA 0039 WebPPictureDistortion
000510BC 00029EB0 Function RVA 003A WebPPictureFree
000510C0 0002A3D0 Function RVA 003B WebPPictureHasTransparency
000510C4 0002B450 Function RVA 003C WebPPictureImportBGR
000510C8 0002B4B0 Function RVA 003D WebPPictureImportBGRA
000510CC 0002B510 Function RVA 003E WebPPictureImportBGRX
000510D0 0002B420 Function RVA 003F WebPPictureImportRGB
000510D4 0002B480 Function RVA 0040 WebPPictureImportRGBA
000510D8 0002B4E0 Function RVA 0041 WebPPictureImportRGBX
000510DC 00029C00 Function RVA 0042 WebPPictureInitInternal
000510E0 0002BC60 Function RVA 0043 WebPPictureIsView
000510E4 0002C080 Function RVA 0044 WebPPictureRescale
000510E8 0002BC90 Function RVA 0045 WebPPictureView
000510EC 0002B0E0 Function RVA 0046 WebPPictureYUVAToARGB
000510F0 00020B30 Function RVA 0047 WebPSafeCalloc
000510F4 00020BA0 Function RVA 0048 WebPSafeFree
000510F8 00020AC0 Function RVA 0049 WebPSafeMalloc
000510FC 00020A40 Function RVA 004A WebPSetWorkerInterface
00051100 000240C0 Function RVA 004B WebPValidateConfig
Title: Re: WebP test libwebp.dll
Post by: TimoVJL on October 14, 2022, 08:34:57 PM
Hopefully someone find new versions of dll, as those what i tested was 0.4.1

Quote from: jj2007 on October 14, 2022, 08:09:10 PM
Interesting stuff, but I wonder what happens if the user has not installed the 20MB webp package :rolleyes:
not quite understand, what you are after ?

found libwebp-7.dll version 1.0
https://www.dllme.com/dll/files/libwebp-7_dll.html
Title: Re: WebP test libwebp.dll
Post by: jj2007 on October 14, 2022, 09:53:50 PM
Quote from: TimoVJL on October 14, 2022, 08:34:57 PM
Quote from: jj2007 on October 14, 2022, 08:09:10 PM
Interesting stuff, but I wonder what happens if the user has not installed the 20MB webp package :rolleyes:
not quite understand, what you are after ?

Imagine you proudly ship your brand new image viewer, only 40kBytes because it was written in Assembly, and when the user tries to open a *.webp file, your viewer greets it with "To make this run, you must now install this 20 MB package" :cool:
Title: Re: WebP test libwebp.dll
Post by: TimoVJL on October 14, 2022, 10:37:43 PM
Irfanview have WebP plugin, size about 650 KB :tongue:
old libwebp.dll is about 350 KB.
Title: Re: WebP test libwebp.dll
Post by: jj2007 on October 14, 2022, 11:48:09 PM
It works, actually.

include \masm32\MasmBasic\MasmBasic.inc         ; download (http://masm32.com/board/index.php?topic=94.0)
  SetGlobals wpWidth, wpHeight
  Init
  Dll "libwebp.dll"
  Declare void WebPGetInfo, 4   ; doc (https://developers.google.com/speed/webp/docs/api)
  WebPGetInfo(Cat$(FileRead$("https://www.gstatic.com/webp/gallery/1.sm.webp")), LastFileSize, addr wpWidth, addr wpHeight)
  Print Str$("W=%i", wpWidth), Str$(", H=%i\n", wpHeight)
EndOfCode


Output: W=320, H=214
Title: Re: WebP test libwebp.dll
Post by: TimoVJL on October 15, 2022, 12:25:06 AM
Very good, now is time to examine things, what we can do with WebP pictures.
Web is now full of them and we have to know, how we deal with them.
Title: Re: WebP test libwebp.dll
Post by: Biterider on October 15, 2022, 12:30:37 AM
Hi
I'm making progress too.  :cool:
As soon as I have something clean I'll post it.

Biterider
Title: Re: WebP test libwebp.dll
Post by: Biterider on October 15, 2022, 05:50:23 PM
Hi
So far I got the decoder working. It's easy once you know how it works.
I had some problems with the import libraries using the MS linker, so I rebuilt them using Dll2Lib.
The 64-bit version works fine while the 32-bit version still has some mangling issues.

The core idea is to create a GDI object to work with. In this case I used an HBITMAP created with CreateDIBSection.
I filled the pixel array using WebPDecodeBGRAInto. Note that the correct GDI memory arrangement is BGRA!

Method Application.OnCreate, uses xbx xdi xsi, wParam:WPARAM, lParam:LPARAM
  local hFile:HANDLE, dDataSize:DWORD, pData:POINTER, dBytesRead:DWORD
  local BmpInfo:BITMAPINFO, pPixels:POINTER, pBuffer:POINTER

  SetObject xsi
  invoke CreateFile, $OfsCStr("D:\ObjAsm\Projects\Experimental\libwebp\1.sm.webp"), GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0
  .if xax != INVALID_HANDLE_VALUE
    mov hFile, xax
    invoke GetFileSize, hFile, NULL
    .if eax != INVALID_FILE_SIZE
      mov dDataSize, eax
      MemAlloc dDataSize
      .if xax != 0
        mov pData, xax
        invoke ReadFile, hFile, pData, dDataSize, addr dBytesRead, NULL
        invoke WebPGetInfo, pData, dDataSize, addr [xsi].dWidth, addr [xsi].dHeight
        DbgDec [xsi].dWidth
        DbgDec [xsi].dHeight

        mov BmpInfo.BITMAPINFO.bmiHeader.biSize, sizeof BITMAPINFO
        mov BmpInfo.BITMAPINFO.bmiHeader.biPlanes, 1
        mov BmpInfo.BITMAPINFO.bmiHeader.biBitCount, 32
        mov BmpInfo.BITMAPINFO.bmiHeader.biCompression, BI_RGB
        m2m BmpInfo.bmiHeader.biWidth, [xsi].dWidth, eax
        mov ecx, [xsi].dHeight
        mul ecx
        shl eax, $Log2(sizeof(RGBQUAD))
        mov BmpInfo.BITMAPINFO.bmiHeader.biSizeImage, eax
        neg ecx                                 ;Top down scanline arrangement
        mov BmpInfo.bmiHeader.biHeight, ecx

        invoke CreateDIBSection, 0, addr BmpInfo, DIB_RGB_COLORS, addr pPixels, 0, 0
        .if xax != 0
          mov [xsi].hDIBSection, xax            ;System object handle
          mov eax, [xsi].dWidth
          shl eax, $Log2(sizeof(RGBQUAD))
          invoke WebPDecodeBGRAInto, pData, dDataSize, pPixels, BmpInfo.BITMAPINFO.bmiHeader.biSizeImage, eax
        .endif
        MemFree pData
      .endif
    .endif
    invoke CloseHandle, hFile
  .endif
MethodEnd


Finally, the display work is standard win32
Method Application.OnPaint, uses xsi, wParam:WPARAM, lParam:LPARAM
  local PS:PAINTSTRUCT, hWndDC:HDC, hDC:HDC, Rct:RECT
  local hPrvBmp:HBITMAP

  SetObject xsi
  mov hWndDC, $invoke(BeginPaint, [xsi].hWnd, addr PS)

  invoke GetClientRect, [xsi].hWnd, addr Rct
  invoke DrawEdge, hWndDC, addr Rct, EDGE_SUNKEN, BF_RECT

  mov hDC, $invoke(CreateCompatibleDC, hWndDC)
  mov hPrvBmp, $invoke(SelectObject, hDC, [xsi].hDIBSection)
  invoke BitBlt, hWndDC, 10, 10, [xsi].dWidth, [xsi].dHeight, hDC, 0, 0, SRCCOPY
  invoke SelectObject, hDC, hPrvBmp
  invoke DeleteDC, hDC

  invoke EndPaint, [xsi].hWnd, addr PS
  xor eax, eax
MethodEnd


Attached some of the necessary files.  :cool:

Biterider
Title: Re: WebP test libwebp.dll
Post by: jj2007 on October 15, 2022, 07:48:50 PM
Quote from: Biterider on October 15, 2022, 05:50:23 PMan HBITMAP created with CreateDIBSection.
I filled the pixel array using WebPDecodeBGRAInto. Note that the correct GDI memory arrangement is BGRA!

Perfect :thumbsup:
Title: Re: WebP test libwebp.dll
Post by: Biterider on October 15, 2022, 08:24:12 PM
Hi
If you look at the official GOOGLE repository here https://storage.googleapis.com/downloads.webmproject.org/releases/webp/index.html (https://storage.googleapis.com/downloads.webmproject.org/releases/webp/index.html) the latest version is 1.2.4 (at end of page). The .inc files correspond to the ABI versions of the .h files, so we also have the latest available version.

The API is impressive and easy to understand, hiding completely its complexity.
Encoding, decoding, muxing, demuxing, configuration... it's all there.  :biggrin:

Great stuff!   :thumbsup:

Biterider
Title: Re: WebP test libwebp.dll
Post by: TimoVJL on October 15, 2022, 09:26:55 PM
@Bitrider Your example use import by ordinals, didn't work with that 0.4.1 dll
Title: Re: WebP test libwebp.dll
Post by: jj2007 on October 15, 2022, 10:19:10 PM
Quote from: Biterider on October 15, 2022, 05:50:23 PMAttached some of the necessary files.  :cool:

Hi Biterider,

Could you please post also the DLL? I'm running into problems with libwebp.lib...

include \masm32\include\masm32rt.inc
includelib BiteRider\libwebp.lib
.data?
wpWidth   dd ?
wpHeight  dd ?
.code
start:
  WebPGetInfo PROTO :DWORD, :DWORD, :DWORD, :DWORD
  invoke WebPGetInfo, 123, 123, addr wpWidth, addr wpHeight
end start


POLINK: error: Unresolved external symbol '_WebPGetInfo@16'
Title: Re: WebP test libwebp.dll
Post by: Biterider on October 15, 2022, 10:53:14 PM
Hi
@TimoVJL: no, I don't import the APIs by ordinal. I use the plain names (for the 64 bit example). It would be niche to use the "_imp__" stubs...

@jj2007: same thing here, but only in 32 bit. It is the name mangling issue mentioned above. I'll look into this in the next time.
The DLLs are those posted by TimoVJL.

Biterider
Title: Re: WebP test libwebp.dll
Post by: jj2007 on October 15, 2022, 10:58:46 PM
Quote from: Biterider on October 15, 2022, 10:53:14 PM
The DLLs are those posted by TimoVJL.

https://www.dllme.com/dll/files/libwebp-7_dll.html has only 64-bit versions :sad:

And your *.lib files will work only if the dll is present, too.
Title: Re: WebP test libwebp.dll
Post by: TimoVJL on October 15, 2022, 11:12:54 PM
@Bitrider WebP_Demo.exepFile Data Description Value
00005460 8000000000000023 Ordinal 0023
00005468 8000000000000020 Ordinal 0020
00005470 800000000000000D Ordinal 000D
00005478 0000000000000000 End of Imports libwebp.dll

I still hunt newer dlls, but they are not in 1.2.4 package
Title: Re: WebP test libwebp.dll
Post by: Biterider on October 15, 2022, 11:27:53 PM
Hi JJ
Quote from: jj2007 on October 15, 2022, 10:58:46 PM
And your *.lib files will work only if the dll is present, too.
The libs are import libraries, they don't contain any code, they only get access to the DLL procedures (but I'm sure you know that).

For everything to work properly we need to find the latest repo and fetch all files from there (single source of truth)  :biggrin:

Biterider
Title: Re: WebP test libwebp.dll
Post by: jj2007 on October 16, 2022, 12:35:39 AM
Quote from: Biterider on October 15, 2022, 11:27:53 PMThe libs are import libraries, they don't contain any code, they only get access to the DLL procedures (but I'm sure you know that).

That's precisely why I am asking for the DLL :biggrin:

Unfortunately, I can't build it myself, since my C/C++ implementation suffers from a mysterious Micros*t bug.

Btw in my 64-bit implementation (http://masm32.com/board/index.php?topic=9266.0), I don't use any import libraries; they are a waste of space.
Title: Re: WebP test libwebp.dll
Post by: Biterider on October 16, 2022, 01:45:25 AM
Hi JJ

Quote from: jj2007 on October 16, 2022, 12:35:39 AM
... they are a waste of space.

I'm not sure what you mean, what space are you referring to?
AFAIK, import libs are only used by the linker to resolve references.  :rolleyes:

Biterider
Title: Re: WebP test libwebp.dll
Post by: jj2007 on October 16, 2022, 02:04:16 AM
Hi Biterider,

What I mean is you don't need them at all:

jinvoke CreateWindowEx, WS_EX_CLIENTEDGE, Chr$("RichEdit20A"), NULL, reStyle, 0, 0, 1, 1, hWnd, ID_EDIT, wcx.hInstance, NULL

Dynamic loading, no import lib :cool:
Title: Re: WebP test libwebp.dll
Post by: Biterider on October 16, 2022, 02:19:48 AM
Hi JJ
I see, you are resolving at runtime, probably using a LoadLibrary / GetProcAddress combination and bypassing the import table.  :rolleyes:
At this point I would prefer to use the standard toolchain so anyone can use the DLL.

Biterider
Title: Re: WebP test libwebp.dll
Post by: TimoVJL on October 16, 2022, 06:56:33 AM
Quote from: jj2007 on October 15, 2022, 10:19:10 PM
include \masm32\include\masm32rt.inc
includelib BiteRider\libwebp.lib
.data?
wpWidth   dd ?
wpHeight  dd ?
.code
start:
  WebPGetInfo PROTO :DWORD, :DWORD, :DWORD, :DWORD
  invoke WebPGetInfo, 123, 123, addr wpWidth, addr wpHeight
end start


POLINK: error: Unresolved external symbol '_WebPGetInfo@16'
That library uses CDECL convention.
Title: Re: WebP test libwebp.dll
Post by: jj2007 on October 16, 2022, 07:03:19 AM
Quote from: TimoVJL on October 16, 2022, 06:56:33 AMThat library uses CDECL convention.

Thanks, Timo - this works:

WebPGetInfo PROTO C :DWORD, :DWORD, :DWORD, :DWORD

Quote from: Biterider on October 16, 2022, 02:19:48 AM
I see, you are resolving at runtime, probably using a LoadLibrary / GetProcAddress combination and bypassing the import table.  :rolleyes:

Hi Biterider,

Yes indeed. It has the additional advantage that you can give a non-cryptic user-friendly error message if LoadLibrary and/or GetProcAddress fail.
Title: Re: WebP test libwebp.dll
Post by: Biterider on October 16, 2022, 07:23:41 AM
Thanks TimoVJL
Quote from: TimoVJL on October 16, 2022, 06:56:33 AM
That library uses CDECL convention.
That explains it. It's kinda obvious...  :rolleyes:

Biterider

Title: Re: WebP test libwebp.dll
Post by: Vortex on October 16, 2022, 08:06:39 AM
Hi Timo,

Attached is the include file defining the function prototypes of libwebp.dll 32-bit
Title: Re: WebP test libwebp.dll
Post by: Biterider on October 16, 2022, 08:12:51 AM
 :thumbsup:
Title: Re: WebP test libwebp.dll
Post by: TimoVJL on October 16, 2022, 10:19:01 PM
x64 dll 1.0.2.1
https://github.com/JosePineiro/WebP-wrapper/tree/master/WebPTest

for Pelles C users:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdint.h>
#include <stdio.h>

#pragma comment(lib, "user32.lib")
#pragma comment(lib, "gdi32.lib")
#pragma comment(lib, "libwebp.lib")
#pragma comment(lib, "msvcrt.lib")

int __cdecl WebPGetInfo(const uint8_t* data, size_t data_size, int* width, int* height);
uint8_t* __cdecl WebPDecodeBGRAInto(const uint8_t* data, size_t data_size, uint8_t* output_buffer, int output_buffer_size, int output_stride);

void __cdecl mainCRTStartup(void)
{
HANDLE hFile;
hFile = CreateFile(TEXT("1.sm.webp"), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (hFile != INVALID_HANDLE_VALUE) {
DWORD nSize = GetFileSize(hFile, NULL);
BYTE *pData = HeapAlloc(GetProcessHeap(), 0, nSize);
if (pData) {
DWORD nRead;
if (ReadFile(hFile, pData, nSize, &nRead, NULL))
{
CloseHandle(hFile);
int nWidth, nHeight;
TCHAR szTmp[80];
if (WebPGetInfo(pData, nSize, &nWidth, &nHeight)) {
TCHAR szTmp[80];
wsprintf(szTmp, TEXT("width: %d Heigth: %d"), nWidth, nHeight);
//MessageBox(0, szTmp, TEXT("WebP test"), MB_OK);
puts(szTmp);
BITMAPINFO bmih;
memset(&bmih, 0, sizeof(BITMAPINFOHEADER));
bmih.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmih.bmiHeader.biWidth = nWidth;
bmih.bmiHeader.biHeight = -nHeight;
bmih.bmiHeader.biPlanes = 1;
bmih.bmiHeader.biBitCount = 32;
bmih.bmiHeader.biCompression = BI_RGB;
bmih.bmiHeader.biSizeImage = nWidth * nHeight * sizeof(RGBQUAD);
//bmih.bmiHeader.biXPelsPerMeter = 0;
//bmih.bmiHeader.biYPelsPerMeter = 0;
//bmih.bmiHeader.biClrUsed = 0;
//bmih.bmiHeader.biClrImportant = 0;
BYTE *pPixels;
HBITMAP hBitmap = CreateDIBSection(0, &bmih, DIB_RGB_COLORS, (void*)&pPixels, NULL, 0);
int iStride = ((((bmih.bmiHeader.biWidth * bmih.bmiHeader.biBitCount) + 31) & ~31) >> 3);
WebPDecodeBGRAInto(pData, nSize, pPixels, bmih.bmiHeader.biSizeImage, iStride);

BITMAPFILEHEADER bmfh;
bmfh.bfType = 0x4D42;
bmfh.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + bmih.bmiHeader.biSizeImage;
bmfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bmfh.bfReserved1 = 0;
bmfh.bfReserved2 = 0;

hFile = CreateFile(TEXT("1.sm.bmp"), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
DWORD dwWrite;
WriteFile(hFile, &bmfh, sizeof(BITMAPFILEHEADER), &dwWrite, NULL);
WriteFile(hFile, &bmih, sizeof(BITMAPINFOHEADER), &dwWrite, NULL);
WriteFile(hFile, pPixels, bmih.bmiHeader.biSizeImage, &dwWrite, NULL);
CloseHandle(hFile);

}
HeapFree(GetProcessHeap(), 0, pData);
}
}

}
ExitProcess(0);
}


A survey of the various ways of creating GDI bitmaps with predefined data Raymond Chen (https://devblogs.microsoft.com/oldnewthing/20170331-00/?p=95875)
Title: Re: WebP test libwebp.dll
Post by: Biterider on October 30, 2022, 06:36:46 PM
Hi
I was able to successfully adjust the set of includes to fit 64 and 32 bit perfectly.  :cool:
This clean set of files is based on the latest available version (1.2.4) from Google and contains the complete prototype definitions, enumerations and structures.

In my case I switch back and forth from 32 to 64 bit during development. In order for my 64-bit operating system to pick up the correct DLL, I copied the 64-bit version to C:\WINDOWS\SYSTEM32 and the 32-bit version to C:\WINDOWS\SYSWOW64.

As a starting point for working with webp images, I wrote the following routines (UNICODE version):

; Procedure:  LoadWebPAsBmpW
; Purpose:    Load WebP encoded file and convert it to a bitmap.
; Arguments:  Arg1: -> WIDE file name.
; Return:     xax = Bitmap HANDLE or zero if failed.

LoadWebPAsBmpW proc pFileName:PSTRINGW
  local hBmp:HBITMAP, hFile:HANDLE, pData:POINTER, dDataSize:DWORD, dBytesRead:DWORD
  local dWidth:DWORD, dHeight:DWORD, dStride:DWORD, BmpInfo:BITMAPINFO, pPixels:POINTER

  mov hBmp, 0
  invoke CreateFileW, pFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0
  .if xax != INVALID_HANDLE_VALUE
    mov hFile, xax
    invoke GetFileSize, hFile, NULL
    .if eax != INVALID_FILE_SIZE
      mov dDataSize, eax
      MemAlloc dDataSize
      .if xax != 0
        mov pData, xax
        invoke ReadFile, hFile, pData, dDataSize, addr dBytesRead, NULL
        invoke WebPGetInfo, pData, dDataSize, addr dWidth, addr dHeight

        mov BmpInfo.BITMAPINFO.bmiHeader.biSize, sizeof BITMAPINFO
        mov BmpInfo.BITMAPINFO.bmiHeader.biPlanes, 1
        mov BmpInfo.BITMAPINFO.bmiHeader.biBitCount, 32
        mov BmpInfo.BITMAPINFO.bmiHeader.biCompression, BI_RGB
        m2m BmpInfo.bmiHeader.biWidth, dWidth, eax
        shl eax, $Log2(sizeof(RGBQUAD))
        mov dStride, eax
        mov ecx, dHeight
        mul ecx
        mov BmpInfo.BITMAPINFO.bmiHeader.biSizeImage, eax
        neg ecx                                 ;Top down scanline arrangement
        mov BmpInfo.bmiHeader.biHeight, ecx

        invoke CreateDIBSection, 0, addr BmpInfo, DIB_RGB_COLORS, addr pPixels, 0, 0
        .if xax != 0
          mov hBmp, xax
          invoke WebPDecodeBGRAInto, pData, dDataSize, pPixels, \
                                     BmpInfo.BITMAPINFO.bmiHeader.biSizeImage, dStride
        .endif
        MemFree pData
      .endif
    .endif
    invoke CloseHandle, hFile
  .endif
  mov xax, hBmp
  ret
LoadWebPAsBmpW endp



; Procedure:  SaveBmpAsWebPW
; Purpose:    Save a Bitmap (DDB or DIB) to as WebP encoded file.
; Arguments:  Arg1: Bitmap HANDLE.
;             Arg2: Quality factor (REAL4), min: 0.0, lossless: 100.0
;             Arg3: -> WIDE file name.
; Return:     eax = TRUE if succeeded, otherwise FALSE.

SaveBmpAsWebPW proc hBmp:HBITMAP, r4Quality:REAL4, pFileName:PSTRINGW
  local dSuccess:DWORD, BmpInfo:BITMAPINFO
  local hDC:HDC, hDesktop:HWND, Bmp:BITMAP, pPixels:POINTER, dStride:DWORD
  local hFile:HANDLE, pBuffer:POINTER, dBufferSize:DWORD, dBytesWritten:DWORD

  mov dSuccess, FALSE
  invoke GetObject, hBmp, sizeof Bmp, addr Bmp
  .if eax != 0
    mrm BmpInfo.bmiHeader.biWidth, Bmp.bmWidth, ecx
    shl ecx, $Log2(sizeof(RGBQUAD))
    mov dStride, ecx
    mov edx, Bmp.bmHeight
    mov eax, edx
    neg edx
    mov BmpInfo.bmiHeader.biHeight, edx
    mul ecx
    MemAlloc eax
    .if xax != NULL
      mov pPixels, xax
      mov hDesktop, $invoke(GetDesktopWindow)
      mov hDC, $invoke(GetDC, hDesktop)
      mov BmpInfo.bmiHeader.biSize, sizeof(BITMAPINFOHEADER)
      mov BmpInfo.bmiHeader.biPlanes, 1
      mov BmpInfo.bmiHeader.biBitCount, 32
      mov BmpInfo.bmiHeader.biCompression, BI_RGB
      invoke GetDIBits, hDC, hBmp, 0, Bmp.BITMAP.bmHeight, pPixels, addr BmpInfo, DIB_RGB_COLORS
      .if eax != 0
        invoke WebPEncodeBGRA, pPixels, Bmp.BITMAP.bmWidth, Bmp.BITMAP.bmHeight, dStride, \
                               r4Quality, addr pBuffer
        .if eax != 0
          mov dBufferSize, eax
          invoke CreateFileW, pFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, \
                              FILE_ATTRIBUTE_ARCHIVE, 0
          .if xax != INVALID_HANDLE_VALUE
            mov hFile, xax
            invoke WriteFile, hFile, pBuffer, dBufferSize, addr dBytesWritten, NULL
            .if eax != FALSE
              mov dSuccess, TRUE
            .endif
            invoke CloseHandle, hFile
          .endif
          invoke WebPFree, pBuffer
        .endif
      .endif
      invoke ReleaseDC, hDesktop, hDC
    .endif
    MemFree pPixels
  .endif
  mov eax, dSuccess
  ret
SaveBmpAsWebPW endp


Biterider
Title: Re: WebP test libwebp.dll
Post by: TimoVJL on November 02, 2022, 04:40:50 AM
GDI+ soon support WebP format in Windows 10 / 11?
DEFINE_GUID(ImageFormatWEBP, 0xb96b3cb7,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e);//---------------------------------------------------------------------------
// Image file format identifiers
//---------------------------------------------------------------------------

DEFINE_GUID(ImageFormatUndefined, 0xb96b3ca9,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e);
DEFINE_GUID(ImageFormatMemoryBMP, 0xb96b3caa,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e);
DEFINE_GUID(ImageFormatBMP, 0xb96b3cab,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e);
DEFINE_GUID(ImageFormatEMF, 0xb96b3cac,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e);
DEFINE_GUID(ImageFormatWMF, 0xb96b3cad,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e);
DEFINE_GUID(ImageFormatJPEG, 0xb96b3cae,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e);
DEFINE_GUID(ImageFormatPNG, 0xb96b3caf,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e);
DEFINE_GUID(ImageFormatGIF, 0xb96b3cb0,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e);
DEFINE_GUID(ImageFormatTIFF, 0xb96b3cb1,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e);
DEFINE_GUID(ImageFormatEXIF, 0xb96b3cb2,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e);
DEFINE_GUID(ImageFormatIcon, 0xb96b3cb5,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e);
DEFINE_GUID(ImageFormatHEIF, 0xb96b3cb6,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e);
DEFINE_GUID(ImageFormatWEBP, 0xb96b3cb7,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e);
Title: Re: WebP test libwebp.dll
Post by: Biterider on November 02, 2022, 07:59:50 AM
Hi
I also found this definition in Gdiplusimaging.h
Trying to load a webp image using GdipLoadImageFromFile fails on my Win10 21H2.
Maybe it's too old and it only works on 22H2 or Win11...  :sad:

Biterider
Title: Re: WebP test libwebp.dll
Post by: jj2007 on November 02, 2022, 08:34:27 AM
I found two elements on the web, but no idea what could be done with this (other priorities right now):

GdipGetImageRawFormat (http://www.jose.it-berater.org/gdiplus/reference/flatapi/image/gdipgetimagerawformat.htm)

https://raw.githubusercontent.com/marius-sucan/Quick-Picto-Viewer/master/lib/Gdip_All.ahk

Gdip_GetImageRawFormat(pBitmap) {
; retrieves the pBitmap [file] format

  Static RawFormatsList := {"{B96B3CA9-0728-11D3-9D7B-0000F81EF32E}":"Undefined", "{B96B3CAA-0728-11D3-9D7B-0000F81EF32E}":"MemoryBMP", "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}":"BMP", "{B96B3CAC-0728-11D3-9D7B-0000F81EF32E}":"EMF", "{B96B3CAD-0728-11D3-9D7B-0000F81EF32E}":"WMF", "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}":"JPEG", "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}":"PNG", "{B96B3CB0-0728-11D3-9D7B-0000F81EF32E}":"GIF", "{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}":"TIFF", "{B96B3CB2-0728-11D3-9D7B-0000F81EF32E}":"EXIF", "{B96B3CB5-0728-11D3-9D7B-0000F81EF32E}":"Icon"}
  ; DEFINE_GUID(ImageFormatHEIF, 0xb96b3cb6,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e);
  ; DEFINE_GUID(ImageFormatWEBP, 0xb96b3cb7,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e);
  If (pBitmap="")
     Return
Title: Re: WebP test libwebp.dll
Post by: TimoVJL on November 02, 2022, 09:36:39 AM
GdipLoadImageFromFile didn't work with Windows 10 22H2

22H2 still have GdiPlus 10.0.19041.2130, not 10.0.22000
Title: Re: WebP test libwebp.dll
Post by: Vortex on November 03, 2022, 04:17:21 AM
Hi Timo,

Windows 10 Version 2022 H2 is a very new release. Maybe, the future updates can solve the problem.