Thanks for your answer. This help me a lot.
I was compiled the last library (libwebp-0.4.0.tar.gz) in a dll, referenced API functions and make a simple test.
I can compress the image in lossy and lossless mode. Work very well.
The compressed WebP can be open with Crome.
I can decompress the image. In one image (good.jpg) work but in another (bad.jpg) don´t work.
The code for descompress function:
void D2WebP(string fileName, out Bitmap bmp)
{
int intReturn;
int imgWidth = 0;
int imgHeight = 0;
IntPtr outputBuffer = IntPtr.Zero;
int outputBufferSize;
bmp = null;
//Read webP file
byte[] arrWebP = File.ReadAllBytes(fileName);
//Get image width and height
GCHandle pinnedWebP = GCHandle.Alloc(arrWebP, GCHandleType.Pinned);
IntPtr ptrData = pinnedWebP.AddrOfPinnedObject();
UInt32 dataSize = (uint)arrWebP.Length;
intReturn = WebPGetInfo(ptrData, dataSize, ref imgWidth, ref imgHeight);
if (intReturn != 1) return;
//Allocate memory for uncompress image
outputBufferSize = imgWidth * imgHeight * Image.GetPixelFormatSize(PixelFormat.Format24bppRgb) / 8;
outputBuffer = Marshal.AllocHGlobal(outputBufferSize);
//Uncompress the image
outputBuffer = WebPDecodeBGR(ptrData, dataSize, ref imgWidth, ref imgHeight);
//Create a BitmapData and Lock all pixels to be written
bmp = new Bitmap(imgWidth, imgHeight, PixelFormat.Format24bppRgb);
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat);
//Wtite image to bitmap
CopyMemory(bmpData.Scan0, outputBuffer, (uint)outputBufferSize);
//Unlock the pixels
bmp.UnlockBits(bmpData);
//Free memory
pinnedWebP.Free();
Marshal.FreeHGlobal(outputBuffer);
}
Append to this message:
sources.zip - The code, compiled dll, the working image and the not working image.
compiled.zip - The compiles exe in 32bits for .NET 3.5, compiled dll, the working image and the not working image.
Are bad the lib? Are bad my code?
Can you help me?
Thanks in advance.