Closed GoogleCodeExporter closed 9 years ago
Hi,
(thanks for the precise report!)
in addition to the invalid "free(buffer)" problem reported above, there other
problems too:
* you should pass "&retb", as in:
uint8_t* retb;
int size = WebPEncodeRGBA(buffer, ...., &retb);
* you are calling WebPEncodeRGBA(), which expects RGBA pixels (4 bytes per
pixel). However, PPM format is in 'RGB' format. There's no alpha channel, so
each pixel is RGB only (3 bytes). You should call WebPEncodeRGB() instead.
* the stride passed (129) is strange
* Note that PPM format also has a header information, it's not just plain RGB
pixel values.
* don't forget to "free(retb)" !
Here's a somewhat corrected version:
#include <stdio.h>
#include <stdlib.h>
#include "webp/encode.h"
int main(int argc, char *argv[])
{
uint8_t *buffer = NULL;
FILE *fh = fopen("./test_ref.ppm", "rb");
if ( fh != NULL )
{
fseek(fh, 0L, SEEK_END);
long s = ftell(fh);
rewind(fh);
buffer = (uint8_t*)malloc(s);
if ( buffer != NULL )
{
fread(buffer, s, 1, fh);
// do something, e.g.
fwrite(buffer, s, 1, stdout);
}
fclose(fh);
}
if (buffer == NULL) return -1; // error
uint8_t* retb = NULL;
size_t size = WebPEncodeRGB(buffer, 128, 128, 3 * 128, 100, &retb);
printf("size: %d\n", (int)size);
free(buffer);
free(retb);
return 0;
}
Original comment by pascal.m...@gmail.com
on 13 May 2013 at 5:07
Original issue reported on code.google.com by
axande...@gmail.com
on 12 May 2013 at 10:21Attachments: