NO

Author Topic: WebP picture format  (Read 1711 times)

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
WebP picture format
« on: October 12, 2022, 12:22:13 PM »
Isn't time to start testing libwebp.dll and WebP libraries.

EDIT:
https://wikidll.com/other/libwebp-dll

https://developers.google.com/speed/webp/docs/api

« Last Edit: October 13, 2022, 07:22:41 PM by TimoVJL »
May the source be with you

Offline John Z

  • Member
  • *
  • Posts: 790
Re: WebP picture format
« Reply #1 on: October 12, 2022, 01:56:23 PM »
Widely used in web page generation it seems.  Capability for compression seems impressive.
Uses image blocks and delta between blocks to improve compressions taking a page from video
compression and applying it to static images. (Basically  :))

Supported by IrfranView, one of the best image tools out there. 
A 200k jpg (quality == 90) was saved as a webp file using IrfanView and it only took 125k (quality 90).
with quality set to 100 (which should be lossless) jpg size was 373K, webp size was 216k

But WebP seems invisible to most.  I've never (until now) seen an actual file with .webp extension.

By 'testing' are you thinking about incorporation into Pelles C system?

John Z

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: WebP picture format
« Reply #2 on: October 12, 2022, 02:10:22 PM »
Now can we share examples using WebP format, as it isn't supported directly in windowsOS, like in GDI+.
I do my part of support, when needed.
« Last Edit: October 12, 2022, 02:33:03 PM by TimoVJL »
May the source be with you

Offline John Z

  • Member
  • *
  • Posts: 790
Re: WebP picture format
« Reply #3 on: October 12, 2022, 05:06:48 PM »
Problem as I see it for broader adoption than web pages is that webP is, or seems to be, not really a picture format at all.  It is a compression format like zip or 7z. The input is a 'picture' in jpg, png, or other limited number of accepted formats.  Output is back to jpg, png or other limited output types, which is then supported for display.   If I take a jpg and use lossless webP it came out larger, I could 7z it for lossless compression and it it smaller....
Example file sizes in the attachment:
First file is the base jpg
The second file is the list was 70% webP compression, but I left off the _70.

Of course I'm not considering speed which is a big factor with web pages.  I'd bet webP is faster....maybe?

John Z

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: WebP picture format
« Reply #4 on: October 17, 2022, 01:16:06 PM »
We should discuss how to handle WebP-files, as those are used in web sites.

This example is also found from here
http://masm32.com/board/index.php?topic=10437.msg114912#msg114912

Code: [Select]
#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.biCompression = 3; // BI_BITFIELDS
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);
}
when someone find errors in code examples, just tell us, as erronous code should removed.
May the source be with you