diff options
author | Igor Murzov <igor@gplsoft.org> | 2011-05-01 04:37:03 +0400 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2011-06-01 09:31:59 +0200 |
commit | 6d690577ffa6cb51a101c15c5634e719583f1fec (patch) | |
tree | 49419bab93f2e579097e5c06c0e6e970e9570f2b | |
parent | f2fae781080ee23d2e5a911a9cf790c4ba1b6c0d (diff) | |
download | fbida-6d690577ffa6cb51a101c15c5634e719583f1fec.tar.gz |
add support for webp image format2.08
-rw-r--r-- | GNUmakefile | 9 | ||||
-rw-r--r-- | fbi.man | 4 | ||||
-rw-r--r-- | rd/read-webp.c | 93 |
3 files changed, 101 insertions, 5 deletions
diff --git a/GNUmakefile b/GNUmakefile index 1ef958b..c96e635 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -46,6 +46,7 @@ HAVE_LIBPCD := $(call ac_lib,pcd_open,pcd) HAVE_LIBUNGIF := $(call ac_lib,DGifOpenFileName,ungif) HAVE_LIBPNG := $(call ac_lib,png_read_info,png,-lz) HAVE_LIBTIFF := $(call ac_lib,TIFFOpen,tiff) +HAVE_LIBWEBP := $(call ac_lib,WebPDecodeRGBA,webp) #HAVE_LIBMAGICK := $(call ac_binary,Magick-config) HAVE_LIBSANE := $(call ac_lib,sane_init,sane) HAVE_LIBCURL := $(call ac_lib,curl_easy_init,curl) @@ -73,9 +74,9 @@ endif # conditional stuff includes = ENDIAN_H STRCASESTR NEW_EXIF -libraries = PCD UNGIF PNG TIFF CURL SANE LIRC -ida_libs = PCD UNGIF PNG TIFF CURL SANE -fbi_libs = PCD UNGIF PNG TIFF CURL LIRC +libraries = PCD UNGIF PNG TIFF WEBP CURL SANE LIRC +ida_libs = PCD UNGIF PNG TIFF WEBP CURL SANE +fbi_libs = PCD UNGIF PNG TIFF WEBP CURL LIRC #MAGICK_CFLAGS = $(shell Magick-config --cflags) #MAGICK_LDFLAGS = $(shell Magick-config --ldflags) @@ -84,6 +85,7 @@ fbi_libs = PCD UNGIF PNG TIFF CURL LIRC PNG_LDLIBS := -lpng -lz TIFF_LDLIBS := -ltiff +WEBP_LDLIBS := -lwebp PCD_LDLIBS := -lpcd UNGIF_LDLIBS := -lungif SANE_LDLIBS := -lsane @@ -92,6 +94,7 @@ LIRC_LDLIBS := -llirc_client PNG_OBJS := rd/read-png.o wr/write-png.o TIFF_OBJS := rd/read-tiff.o wr/write-tiff.o +WEBP_OBJS := rd/read-webp.o PCD_OBJS := rd/read-pcd.o UNGIF_OBJS := rd/read-gif.o SANE_OBJS := sane.o @@ -13,8 +13,8 @@ fbi - Linux framebuffer imageviewer .BR fbi displays the specified file(s) on the linux console using the framebuffer device. -\fIPhotoCD\fP, \fIjpeg\fP, \fIppm\fP, \fIgif\fP, \fItiff\fP, \fIxwd\fP, -\fIbmp\fP and \fIpng\fP are supported directly. +\fIPhotoCD\fP, \fIjpeg\fP, \fIppm\fP, \fIgif\fP, \fItiff\fP, \fIxwd\fP, +\fIbmp\fP, \fIpng\fP and \fIwebp\fP are supported directly. For other formats .BR fbi tries to use diff --git a/rd/read-webp.c b/rd/read-webp.c new file mode 100644 index 0000000..0dfe372 --- /dev/null +++ b/rd/read-webp.c @@ -0,0 +1,93 @@ +#include <stdlib.h> +#include <stdio.h> +#include <errno.h> +#include <webp/decode.h> + +#include "readers.h" + + +struct webp_state { + FILE *f; + int width, height; + uint8_t *data; +}; + +static void * +webp_init(FILE *fp, char *filename, unsigned int page, + struct ida_image_info *i, int thumbnail) +{ + uint32_t img_size; + void *img; + struct webp_state *h; + h = malloc(sizeof(*h)); + + h->f = fp; + if(fseek(fp, 0, SEEK_END) != 0) + { + free(h); + return NULL; + } + img_size = ftell(fp); + img = malloc(img_size); + + if(fseek(fp, 0, SEEK_SET) != 0) + { + free(img); + free(h); + return NULL; + } + if(fread(img, img_size, 1, fp) != 1) + { + free(img); + free(h); + return NULL; + } + + h->data = WebPDecodeRGBA(img, img_size, &h->width, &h->height); + + i->width = h->width; + i->height = h->height; + i->dpi = 100; + i->npages = 1; + + free(img); + + return h; +} + + +static void +webp_read(unsigned char *dst, unsigned int line, void *data) +{ + struct webp_state *h = data; + + load_rgba(dst, h->data + line * 4 * h->width, h->width); +} + + +static void +webp_done(void *data) +{ + struct webp_state *h = data; + + free(h->data); + fclose(h->f); + free(h); +} + + +static struct ida_loader webp_loader = { + magic: "WEBPVP8", + moff: 8, + mlen: 7, + name: "libwebp", + init: webp_init, + read: webp_read, + done: webp_done, +}; + + +static void __init init_rd(void) +{ + load_register(&webp_loader); +} |