News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

WebP test libwebp.dll

Started by TimoVJL, October 14, 2022, 05:23:54 PM

Previous topic - Next topic

TimoVJL

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
May the source be with you

Biterider


jj2007

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

TimoVJL

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
May the source be with you

jj2007

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:

TimoVJL

Irfanview have WebP plugin, size about 650 KB :tongue:
old libwebp.dll is about 350 KB.
May the source be with you

jj2007

It works, actually.

include \masm32\MasmBasic\MasmBasic.inc         ; download
  SetGlobals wpWidth, wpHeight
  Init
  Dll "libwebp.dll"
  Declare void WebPGetInfo, 4   ; doc
  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

TimoVJL

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.
May the source be with you

Biterider

Hi
I'm making progress too.  :cool:
As soon as I have something clean I'll post it.

Biterider

Biterider

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

jj2007

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:

Biterider

Hi
If you look at the official GOOGLE repository here 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

TimoVJL

@Bitrider Your example use import by ordinals, didn't work with that 0.4.1 dll
May the source be with you

jj2007

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'

Biterider

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