Re: GdkPixbufLoader vs. _from_file: speed issue



Le septidi 7 fructidor, an CCXIII, Matthias Clasen a écrit :
> That sounds wrong. Can you post your benchmark ?

It was somewhat overloaded with irrelevant stuff: I have rewritten it from
scratch with the bare minimum. Here is it. It may be built with:

gcc -Wall -W -std=c99 -D_XOPEN_SOURCE=600 -g -o pixbuf_load_vs_loader \
  `pkg-config --cflags --libs gdk-pixbuf-xlib-2.0` pixbuf_load_vs_loader.c

and must be called with the path to an image. With some more tests, I can
see that not all images show the problem. As far as I can see, the
problematic images are the interlaced ones. Here are two images that have
the problem:

http://img.hebus.com/2000/03/13/20000313022947_49629.jpg
http://www.dragonmount.com/WoT_Products/Images/comic_cover_rel01.jpg

(respectively, about 9.3 vs 1.5 and 7.0 vs 1.5 seconds)
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <gdk-pixbuf/gdk-pixbuf.h>

void
print_time(void)
{
    struct timeval tv;

    gettimeofday(&tv, NULL);
    printf("Now is %d.%6.6d\n", (int)tv.tv_sec, (int)tv.tv_usec);
}

void
show_pixbuf(GdkPixbuf *p)
{
    printf("Loaded %dx%d\n", gdk_pixbuf_get_width(p), gdk_pixbuf_get_height(p));
}

void
load_plain(const char *filename)
{
    GdkPixbuf *p;

    if((p = gdk_pixbuf_new_from_file(filename, NULL)) == NULL)
	g_error("Unable to load %s", filename);
    show_pixbuf(p);
    gdk_pixbuf_unref(p);
}

void
load_loader(const char *filename)
{
    GdkPixbufLoader *loader;
    GdkPixbuf *p;
    FILE *file;
    guchar buf[65536];
    size_t l;

    loader = gdk_pixbuf_loader_new();
    if((file = fopen(filename, "r")) == NULL) {
	perror("filename");
	exit(1);
    }
    while((l = fread(buf, 1, sizeof(buf), file)) > 0) {
	if(!gdk_pixbuf_loader_write(loader, buf, l, NULL))
	    g_error("Unable to write");
	printf("Written %d\n", l);
    }
    if(!gdk_pixbuf_loader_close(loader, NULL))
	g_error("Unable to close");
    p = gdk_pixbuf_loader_get_pixbuf(loader);
    show_pixbuf(p);
    gdk_pixbuf_unref(p);
}

int
main(int argc, char **argv)
{
    if(argc != 2)
	exit(1);
    g_type_init();
    print_time();
    load_plain(argv[1]);
    print_time();
    load_loader(argv[1]);
    print_time();
    return(0);
}

Attachment: signature.asc
Description: Digital signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]