Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PREFIX := $(DESTDIR)/usr/local
CXXFLAGS := $(shell pkg-config --cflags zlib libpng) -DLODEPNG_NO_COMPILE_PNG -DLODEPNG_NO_COMPILE_DISK
CFLAGS := $(shell pkg-config --cflags zlib libpng) -DLODEPNG_NO_COMPILE_PNG -DLODEPNG_NO_COMPILE_DISK
LDFLAGS := $(shell pkg-config --libs libpng)
CXXFLAGS := $(CXXFLAGS) $(shell pkg-config --cflags zlib libpng) -DLODEPNG_NO_COMPILE_PNG -DLODEPNG_NO_COMPILE_DISK
CFLAGS := $(CFLAGS) $(shell pkg-config --cflags zlib libpng) -DLODEPNG_NO_COMPILE_PNG -DLODEPNG_NO_COMPILE_DISK
LDFLAGS := $(LDFLAGS) $(shell pkg-config --libs libpng)

OSNAME := $(shell uname -s)
SONAME = -soname
Expand Down Expand Up @@ -99,6 +99,7 @@ install-libpixbufloader-flif$(LIBEXT): libpixbufloader-flif$(LIBEXT) install-lib
install -c -d /usr/lib/gdk-pixbuf-2.0/2.10.0/loaders
install -c -m 755 -s libpixbufloader-flif$(LIBEXT) /usr/lib/gdk-pixbuf-2.0/2.10.0/loaders/
gdk-pixbuf-query-loaders --update-cache
xdg-mime install --novendor flif-mime.xml

install-pixbufloader: install-libpixbufloader-flif$(LIBEXT)

Expand Down
11 changes: 11 additions & 0 deletions src/flif-mime.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="image/flif">
<comment xml:lang="en">FLIF image</comment>
<magic priority="100">
<match type="string" value="FLIF" offset="0"/>
</magic>
<glob pattern="*.flif"/>
<glob pattern="*.FLIF"/>
</mime-type>
</mime-info>
39 changes: 18 additions & 21 deletions src/flif-pixbuf-loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ typedef struct {

} FLIFContext;

static void destroy_data (guchar *pixels, gpointer data) {
g_free (pixels);
}

/* Shared library entry point */
static GdkPixbuf *gdk_pixbuf__flif_image_load (FILE *f, GError **error) {

Expand All @@ -89,6 +85,7 @@ static GdkPixbuf *gdk_pixbuf__flif_image_load (FILE *f, GError **error) {
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_FAILED,
"Failed to read file");
g_free(data);
return NULL;
}

Expand Down Expand Up @@ -121,30 +118,28 @@ static GdkPixbuf *gdk_pixbuf__flif_image_load (FILE *f, GError **error) {
gint32 w = flif_image_get_width(image);
gint32 h = flif_image_get_height(image);

// TODO implment 16-bits-per-pixel FLIF files
guchar *buffer = (guchar *) g_malloc(4 * w * h * sizeof(guchar));

guchar *rowpointer = buffer;
for (uint32_t row = 0; row < h; row++) {
flif_image_read_row_RGBA8(image, row, rowpointer, w * 4);
rowpointer += w * 4;
}

flif_destroy_decoder(decoder);

GdkPixbuf *pixbuf = gdk_pixbuf_new_from_data ((const guchar *)buffer, GDK_COLORSPACE_RGB, TRUE, 8, /* TODO 16 */
w, h, w * 4, destroy_data, NULL);
GdkPixbuf *pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, w, h);

if (!pixbuf) {
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_FAILED,
"Failed to decode image");
flif_destroy_decoder(decoder);
g_free (data);
g_free (buffer);
return NULL;
}

// There may be padding at the end of the row for alignment purposes. Not necessarily w * 4
gint32 rowstride = gdk_pixbuf_get_rowstride(pixbuf);
guchar *pixels = gdk_pixbuf_get_pixels(pixbuf);
guchar *rowpointer = pixels;
for (uint32_t row = 0; row < h; row++) {
flif_image_read_row_RGBA8(image, row, rowpointer, w * 4);
rowpointer += rowstride;
}

flif_destroy_decoder(decoder);
g_free(data);

return pixbuf;
Expand All @@ -153,7 +148,7 @@ static GdkPixbuf *gdk_pixbuf__flif_image_load (FILE *f, GError **error) {

static gpointer gdk_pixbuf__flif_image_begin_load (GdkPixbufModuleSizeFunc size_func, GdkPixbufModulePreparedFunc prepare_func,
GdkPixbufModuleUpdatedFunc update_func, gpointer user_data, GError **error) {
FLIFContext *context = g_new0 (FLIFContext, 1);
FLIFContext *context = g_new(FLIFContext, 1);
context->size_func = size_func;
context->prepare_func = prepare_func;
context->update_func = update_func;
Expand Down Expand Up @@ -211,6 +206,7 @@ static gboolean gdk_pixbuf__flif_image_stop_load (gpointer user_context, GError
free(context->increment_buffer_ptr);
#endif

g_object_unref(context->pixbuf);
g_free(context);

return TRUE;
Expand Down Expand Up @@ -285,14 +281,15 @@ void fill_vtable (GdkPixbufModule *module) {
}

void fill_info (GdkPixbufFormat *info) {

static GdkPixbufModulePattern signature[] = {
{ "FLIF" }
{ "FLIF", " ", 100 },
{ NULL, NULL, 0 }
};

static gchar *mime_types[] = {
"image/flif",
"image/x-flif",
"application/octet-stream", /* FIXME hack around systems missing mime type */
NULL
};

Expand Down