Skip to content

Instantly share code, notes, and snippets.

@bebehei
Last active September 5, 2018 13:57
Show Gist options
  • Save bebehei/d1248deab8199ea93d877fdf126be588 to your computer and use it in GitHub Desktop.
Save bebehei/d1248deab8199ea93d877fdf126be588 to your computer and use it in GitHub Desktop.
gdk pixbuf fileinfo tester

testproject to test gdk pixbuf

Run make and then run ./gdkpb with any pictures intended to load via gdk pixbuf.

Example: ./gdkpb ./testimg_with_no_suffix ./testimg.jpg

#include <gdk-pixbuf/gdk-pixbuf.h>
int main(int argc, char *argv[])
{
for (int i = 1; i < argc; i++) {
const char *f = argv[i];
printf("Testing '%s'\n", f);
GdkPixbufFormat *format = gdk_pixbuf_get_file_info(f, NULL, NULL);
if (format) {
printf("Name: %s\n", gdk_pixbuf_format_get_name(format)); //it's leaking. But I don't care!
printf("Desc: %s\n", gdk_pixbuf_format_get_description(format)); //it's leaking. But I don't care!
printf("Disa: %d\n", gdk_pixbuf_format_is_disabled(format));
gchar **exts = gdk_pixbuf_format_get_extensions(format);
printf("Supported extensions:");
for(gchar **ext = exts; *ext; ext++) printf(" %s", *ext);
printf("\n");
g_strfreev(exts);
} else {
printf("File image format not recognized for '%s'\n", f);
}
GError *e = NULL;
GdkPixbuf *pb = gdk_pixbuf_new_from_file(f, &e);
if (e) printf("Error loading file '%s': %s\n", f, e->message);
if (!e && pb) printf("Successfully loaded '%s'\n", f);
if (e) g_error_free(e);
if (pb) g_object_unref(pb);
printf("\n");
}
return 0;
}
PKG_CONFIG ?= pkg-config
pkg_config_packs := gdk-pixbuf-2.0
.PHONY: all clean
all: gdkpb
clean:
rm -rf gdkpb
gdkpb: gdkpb.c
gcc -o $@ $(shell $(PKG_CONFIG) --libs --cflags ${pkg_config_packs}) $^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment