-
Notifications
You must be signed in to change notification settings - Fork 2
Closed
JuliaPackaging/Yggdrasil
#8528Description
@stemann Thanks for this useful package!
Any ideas why WebPEncodeRGB is much slower on WebP.jl as compared to libwebp? The following MWE illustrates the problem.
Using this sample image:

In Julia:
julia> img = load("test.jpg")
julia> @btime WebP.encode(img; lossy=true, quality=75.0)
230.597 ms (5 allocations: 1.17 MiB)
49426-element Vector{UInt8}:
0x52
0x49
0x46
0x46
⋮
0xaa
0x93
0xf8
0x00C script (test.c):
#include "stdio.h"
#include "stdlib.h"
#include "jpeglib.h"
#include "webp/encode.h"
struct Image {
int image_width;
int image_height;
int image_numchannels;
unsigned char *raw_image;
};
int read_jpeg_file( char *filename, struct Image *image)
{
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
JSAMPROW row_pointer[1];
FILE *infile = fopen( filename, "rb" );
unsigned long location = 0;
int i = 0;
if ( !infile )
{
printf("Error opening jpeg file %s\n!", filename );
return -1;
}
cinfo.err = jpeg_std_error( &jerr );
jpeg_create_decompress( &cinfo );
jpeg_stdio_src( &cinfo, infile );
jpeg_read_header( &cinfo, TRUE );
jpeg_start_decompress( &cinfo );
image->image_width = cinfo.output_width;
image->image_height = cinfo.output_height;
image->image_numchannels = cinfo.num_components;
image->raw_image = (unsigned char*)malloc( cinfo.output_width*cinfo.output_height*cinfo.num_components );
row_pointer[0] = (unsigned char *)malloc( cinfo.output_width*cinfo.num_components );
while( cinfo.output_scanline < cinfo.image_height )
{
jpeg_read_scanlines( &cinfo, row_pointer, 1 );
for( i=0; i<cinfo.image_width*cinfo.num_components;i++)
image->raw_image[location++] = row_pointer[0][i];
}
jpeg_finish_decompress( &cinfo );
jpeg_destroy_decompress( &cinfo );
free( row_pointer[0] );
fclose( infile );
return 1;
}
int main(){
char *imgfilename = "test.jpg";
struct Image image;
read_jpeg_file(imgfilename, &image);
int stride = image.image_width * image.image_numchannels * sizeof(uint8_t);
float quality_factor = 75.0;
uint8_t *output;
int data_length = WebPEncodeRGB(image.raw_image, image.image_width, image.image_height,
stride, quality_factor, &output);
printf("width: %d\n", image.image_width);
printf("height: %d\n", image.image_height);
printf("number of channels: %d\n", image.image_numchannels);
printf("stride: %d\n", stride);
printf("data length: %d\n", data_length);
return 0;
}$ gcc -o test test.c -L./lib -lwebp -lsharpyuv -lm -ljpeg
$ time ./test
width: 768
height: 512
number of channels: 3
stride: 2304
data length: 49426
real 0m0.027s
user 0m0.023s
sys 0m0.004sMetadata
Metadata
Assignees
Labels
No labels