A simple c# wrapper for WebP

2,022 views
Skip to first unread message

diosmede...@gmail.com

unread,
Jun 11, 2014, 12:47:57 PM6/11/14
to webp-d...@webmproject.org
With the help os James Zern (very thanks) i made a very simple wrapper for c#

For using only need a clsWebP and a compiled libwebp.dll
You can see a simple example of use.

This files are included in attached files.

I hope that solve another needs.


webptest_compiled.zip
WebPTest_sources_and_dll.zip

James Zern

unread,
Jun 16, 2014, 11:26:52 PM6/16/14
to webp-d...@webmproject.org, diosmede...@gmail.com
Thanks for posting the results. Good use of DecodeInto to deal with stride issues too. 

james...@gmail.com

unread,
Jun 28, 2014, 5:59:48 AM6/28/14
to webp-d...@webmproject.org, diosmede...@gmail.com
Have you had any success using the mux API to preserve EXIF data? https://developers.google.com/speed/webp/docs/container-api

diosmede...@gmail.com

unread,
Mar 19, 2016, 6:55:04 PM3/19/16
to WebP Discussion, diosmede...@gmail.com

Thanks for posting the results. Good use of DecodeInto to deal with stride issues too. 

I am working in a c# warper for Advanced Encoder API with acess to encoder parameters and the new Near lossless encoding. But i do not know well the C languaje

I have several questions. I copy the C code and coment the questions in red colour:
#include "webp/encode.h"

WebPConfig config;
WebPConfigInitInternal(&config, WEBP_DECODER_ABI_VERSION);
// I need call to this function. I dont find documentation about this use.
//
WebPConfigInitInternal allocate the memory for config variable?
// I think that not, because I don't found one funcion for
free their memory,
I'm not sure

if (!WebPConfigPreset(&config, WEBP_PRESET_PHOTO, quality_factor)) return 0;
config.sns_strength = 90;
config
.filter_sharpness = 6;
config
.alpha_quality = 90;
config_error
= WebPValidateConfig(&config);
WebPPicture pic;
if (!WebPPictureInit(&pic)) return 0;
// WebPPictureInit allocate the memory for pic struct?
// I think that not, but I'm not sure

pic
.width = width;
pic
.height = height;
if (!WebPPictureAllocate(&pic)) return 0;
if (!WebPPictureImportBGR(&pic, bmpData.Scan0, bmpData.Stride) return 0; //bmpData.Scan0 is the pointer to BGR values. bmpData.Stride is stride value of BGR lines

WebPMemoryWriter
writer;
// WebPMemoryWriter allocate the memory for writer variable?
// I think that not, but I'm not sure

WebPMemoryWriterInit(&writer);
pic
.writer = WebPMemoryWrite;
//
pic.writer = the pointer to function WebPMemoryWrite (delegate in c#)?
//
pic.writer = 1 if i want use WebPMemoryWrite?

pic
.custom_ptr = &writer;
int ok = WebPEncode(&config, &pic);
WebPPictureFree(&pic);
if (!ok) {
  printf
("Encoding error: %d\n", pic.error_code);
} else {
  printf
("Output size: %d\n", writer.size);
}

I`ll put here the fullcode and examples when work.

Thanks in advance.


diosmede...@gmail.com

unread,
Jun 6, 2017, 2:36:02 PM6/6/17
to WebP Discussion
I was updated the c# WebP wrapper
Now have:
- Simple load bitmap from WebP file.
- Simple save bitmap to WebP file.
- Descompress functions with the full API options.
- Compress bitmap to byte[] funcions: lossless, nearlossless and lossly modes.
- Get version of libwebp.dll
- Get info from WebP file.
- Get PSNR, SSIM or LSIM distortion metric between two pictures.

Warning: Only work with PixelFormat.Format24bppRgb bitmaps.

You can get the code from  https://github.com/JosePineiro/WebP-wrapper

Rajesh v

unread,
Oct 21, 2022, 7:50:52 AM10/21/22
to WebP Discussion, diosmede...@gmail.com
can you share the  vb.net web solution to convert jpg to webp format
Reply all
Reply to author
Forward
0 new messages