From c0b63c111b86492f0571efeab5183ba1ff2be5ad Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 3 Oct 2010 20:41:31 +0000 Subject: WebP image support, needs libwebp (from trunk/libwebp) and libvpx. Only enabled for Amiga build currently, may have colour issues on little-endian CPUs svn path=/trunk/netsurf/; revision=10860 --- !NetSurf/Resources/de/Messages | 1 + !NetSurf/Resources/en/Messages | 1 + !NetSurf/Resources/fr/Messages | 1 + !NetSurf/Resources/it/Messages | 1 + !NetSurf/Resources/nl/Messages | 1 + Makefile | 2 + Makefile.defaults | 8 +++ Makefile.sources | 3 +- amiga/dist/Install | 6 ++ amiga/pkg/makepackage | 2 +- content/content.c | 14 +++++ content/content_protected.h | 6 ++ content/content_type.h | 3 + image/webp.c | 137 +++++++++++++++++++++++++++++++++++++++++ image/webp.h | 47 ++++++++++++++ 15 files changed, 231 insertions(+), 2 deletions(-) create mode 100644 image/webp.c create mode 100644 image/webp.h diff --git a/!NetSurf/Resources/de/Messages b/!NetSurf/Resources/de/Messages index 8f32ea78b..175f20008 100644 --- a/!NetSurf/Resources/de/Messages +++ b/!NetSurf/Resources/de/Messages @@ -642,6 +642,7 @@ JPEGTitle:JPEG Bild (%ux%u, %lu bytes) PNGTitle:PNG Bild (%lux%lu, %lu bytes) JNGTitle:JNG Bild (%lux%lu, %lu bytes) MNGTitle:MNG Bild (%lux%lu, %lu bytes) +WebPTitle:WebP Bild (%lux%lu, %lu bytes) SpriteTitle:Sprite Bild (%lux%lu, %lu bytes) ArtWorksTitle:ArtWorks Bild (%lux%lu, %lu bytes) diff --git a/!NetSurf/Resources/en/Messages b/!NetSurf/Resources/en/Messages index 4732e6549..6d62ac3cd 100644 --- a/!NetSurf/Resources/en/Messages +++ b/!NetSurf/Resources/en/Messages @@ -653,6 +653,7 @@ JPEGTitle:JPEG image (%ux%u, %lu bytes) PNGTitle:PNG image (%lux%lu, %lu bytes) JNGTitle:JNG image (%lux%lu, %lu bytes) MNGTitle:MNG image (%lux%lu, %lu bytes) +WebPTitle:WebP image (%lux%lu, %lu bytes) SpriteTitle:Sprite image (%lux%lu, %lu bytes) ArtWorksTitle:ArtWorks image (%lux%lu, %lu bytes) diff --git a/!NetSurf/Resources/fr/Messages b/!NetSurf/Resources/fr/Messages index 65200c708..bfe563d90 100644 --- a/!NetSurf/Resources/fr/Messages +++ b/!NetSurf/Resources/fr/Messages @@ -642,6 +642,7 @@ JPEGTitle:Image JPEG (%ux%u, %lu octets) PNGTitle:Image PNG (%lux%lu, %lu octets) JNGTitle:Image JNG (%lux%lu, %lu octets) MNGTitle:Image MNG (%lux%lu, %lu octets) +WebPTitle:Image WebP (%lux%lu, %lu octets) SpriteTitle:Image Sprite (%lux%lu, %lu octets) ArtWorksTitle:Image ArtWorks (%lux%lu, %lu octets) diff --git a/!NetSurf/Resources/it/Messages b/!NetSurf/Resources/it/Messages index 4c146a930..e79ce93a5 100755 --- a/!NetSurf/Resources/it/Messages +++ b/!NetSurf/Resources/it/Messages @@ -647,6 +647,7 @@ JPEGTitle:Immagine JPEG (%ux%u, %lu byte) PNGTitle:Immagine PNG (%lux%lu, %lu byte) JNGTitle:Immagine JNG (%lux%lu, %lu byte) MNGTitle:Immagine MNG (%lux%lu, %lu byte) +WebPTitle:Immagine WebP (%lux%lu, %lu byte) SpriteTitle:Immagine Sprite (%lux%lu, %lu byte) ArtWorksTitle:Immagine ArtWorks (%lux%lu, %lu byte) diff --git a/!NetSurf/Resources/nl/Messages b/!NetSurf/Resources/nl/Messages index 1f08690ec..2c1b3fa9b 100644 --- a/!NetSurf/Resources/nl/Messages +++ b/!NetSurf/Resources/nl/Messages @@ -642,6 +642,7 @@ JPEGTitle:JPEG image (%ux%u, %lu bytes) PNGTitle:PNG image (%lux%lu, %lu bytes) JNGTitle:JNG image (%lux%lu, %lu bytes) MNGTitle:MNG image (%lux%lu, %lu bytes) +WebPTitle:WebP image (%lux%lu, %lu bytes) SpriteTitle:Sprite image (%lux%lu, %lu bytes) ArtWorksTitle:ArtWorks image (%lux%lu, %lu bytes) diff --git a/Makefile b/Makefile index f8b13207e..9c473fab3 100644 --- a/Makefile +++ b/Makefile @@ -516,6 +516,7 @@ ifeq ($(TARGET),amiga) NETSURF_FEATURE_BMP_CFLAGS := -DWITH_BMP NETSURF_FEATURE_GIF_CFLAGS := -DWITH_GIF NETSURF_FEATURE_PNG_CFLAGS := -DWITH_PNG + NETSURF_FEATURE_WEBP_CFLAGS := -DWITH_WEBP NETSURF_FEATURE_NSSVG_CFLAGS := -DWITH_NS_SVG $(eval $(call feature_enabled,ROSPRITE,-DWITH_NSSPRITE,-lrosprite,Sprite (librosprite))) @@ -524,6 +525,7 @@ ifeq ($(TARGET),amiga) $(eval $(call feature_enabled,PNG,-DWITH_PNG,-lpng,PNG (libpng) )) $(eval $(call feature_enabled,NSSVG,-DWITH_NS_SVG,-lsvgtiny,SVG (libsvgtiny))) $(eval $(call feature_enabled,MNG,,-llcms -ljpeg,PNG/JNG/MNG (libmng))) + $(eval $(call feature_enabled,WEBP,-DWITH_WEBP,-lwebp -lvpx,WebP (libwebp))) CFLAGS += -D__USE_INLINE__ -std=c99 -I . -I /SDK/local/common/include/libpng12 -Dnsamiga LDFLAGS += -lxml2 -lcurl -lpthread -lregex -lauto diff --git a/Makefile.defaults b/Makefile.defaults index ee998f2b6..a17b1d02e 100644 --- a/Makefile.defaults +++ b/Makefile.defaults @@ -53,6 +53,10 @@ NETSURF_USE_PNG := YES # Valid options: YES, NO (at least one of PNG/MNG highly recommended) NETSURF_USE_MNG := YES +# Enable NetSurf's use of libwebp/libvpx for displaying WebPs +# Valid options: YES, NO +NETSURF_USE_WEBP := NO + # Enable NetSurf's use of libharu for PDF export and GTK printing support. # There is no auto-detection available for this, as it does not have a # pkg-config file. @@ -201,6 +205,10 @@ ifeq ($(TARGET),amiga) # Valid options: YES, NO, AUTO NETSURF_USE_ROSPRITE := YES + # Enable NetSurf's use of libwebp/libvpx for displaying WebPs + # Valid options: YES, NO + NETSURF_USE_WEBP := YES + # Enable NetSurf's use of libsvgtiny for displaying SVGs # (NB: Requires NETSURF_AMIGA_USE_CAIRO) # Valid options: YES, NO diff --git a/Makefile.sources b/Makefile.sources index 452599d4d..57166df51 100644 --- a/Makefile.sources +++ b/Makefile.sources @@ -24,7 +24,8 @@ S_COMMON := $(addprefix content/,$(S_CONTENT)) \ $(addprefix desktop/,$(S_DESKTOP)) # S_IMAGE are sources related to image management -S_IMAGE := bmp.c gif.c ico.c jpeg.c mng.c nssprite.c png.c svg.c rsvg.c +S_IMAGE := bmp.c gif.c ico.c jpeg.c mng.c nssprite.c png.c svg.c rsvg.c \ + webp.c S_IMAGE := $(addprefix image/,$(S_IMAGE)) # S_PDF are sources of the pdf plotter + the ones for paged-printing diff --git a/amiga/dist/Install b/amiga/dist/Install index 145c95887..b3cf3d929 100755 --- a/amiga/dist/Install +++ b/amiga/dist/Install @@ -110,7 +110,11 @@ (if (= #same 0) ;if #sobj is newer than that pointed to by #sobj_link ( + (if (exists (#sobj2)) + (delete #sobj2 (optional "force")) ;prevent dodgy recursive links + ) (set #linkcmd (cat "makelink " #sobj2 " SObjs:" #sobj " soft")) + (transcript "Running " #linkcmd) (run #linkcmd) ) ) @@ -445,6 +449,7 @@ (p_linksobj "libz.so.1.2.5" "libz.so") (p_linksobj "libz.so.1.2.5" "libz.so.1") (p_linksobj "libz.so.1.2.5" "libz.so.1.2") + (p_linksobj "libvpx.so.0.9.2" "libvpx.so.0") ; (p_linksobj "libpng14.so.14" "libpng.so") ) ) @@ -505,6 +510,7 @@ (p_setmimetype "bmp" "image/bmp") (p_setmimetype "ico" "image/ico") (p_setmimetype "sprite" "image/x-riscos-sprite") +(p_setmimetype "webp" "image/webp") (p_setmimetype "lha" "application/x-lha") (p_setmimetype "zip" "application/x-zip") diff --git a/amiga/pkg/makepackage b/amiga/pkg/makepackage index 3799a2b0a..f198a35fb 100755 --- a/amiga/pkg/makepackage +++ b/amiga/pkg/makepackage @@ -20,6 +20,6 @@ copy amiga/pkg/fitr ram:NetSurf/ makedir ram:NetSurf/Rexx copy amiga/dist/Rexx/~(.svn) ram:NetSurf/Rexx/ COM makedir ram:NetSurf/SObjs -copy sobjs:libjpeg.so.8 sobjs:libhubbub.so.0 sobjs:libhpdf-2.2.0.so.0.0 sobjs:libmng.so.1 sobjs:liblcms.so sobjs:libxml2.so sobjs:libparserutils.so.0 sobjs:libnsgif.so.0 sobjs:libnsbmp.so.0 sobjs:libcss.so.0 sobjs:libwapcaplet.so.0 sobjs:libcurl.so sobjs:libsvgtiny.so.0 sobjs:libz.so.1.2.5 sobjs:libiconv.so ram:NetSurf/SObjs clone +copy sobjs:libjpeg.so.8 sobjs:libhubbub.so.0 sobjs:libhpdf-2.2.0.so.0.0 sobjs:libmng.so.1 sobjs:liblcms.so sobjs:libxml2.so sobjs:libparserutils.so.0 sobjs:libnsgif.so.0 sobjs:libnsbmp.so.0 sobjs:libcss.so.0 sobjs:libwapcaplet.so.0 sobjs:libcurl.so sobjs:libsvgtiny.so.0 sobjs:libz.so.1.2.5 sobjs:libiconv.so sobjs:libvpx.so.0.9.2 ram:NetSurf/SObjs clone ;sobjs:libssl-0.9.8.so sobjs:libexpat.so sobjs:libpng14.so.14 ;sobjs:libgcc.so sobjs:libc.so sobjs:libpthread.so \ No newline at end of file diff --git a/content/content.c b/content/content.c index 5165c6b50..9a8336287 100644 --- a/content/content.c +++ b/content/content.c @@ -77,6 +77,9 @@ #ifdef WITH_PNG #include "image/png.h" #endif +#ifdef WITH_WEBP +#include "image/webp.h" +#endif #include "utils/http.h" #include "utils/log.h" #include "utils/messages.h" @@ -153,6 +156,9 @@ static const struct mime_entry mime_map[] = { #ifdef WITH_BMP {"image/vnd.microsoft.icon", CONTENT_ICO}, #endif +#ifdef WITH_WEBP + {"image/webp", CONTENT_WEBP}, +#endif #ifdef WITH_ARTWORKS {"image/x-artworks", CONTENT_ARTWORKS}, #endif @@ -230,6 +236,9 @@ const char * const content_type_name[] = { #endif #if defined(WITH_NS_SVG) || defined(WITH_RSVG) "SVG", +#endif +#ifdef WITH_WEBP + "WEBP", #endif "OTHER", "UNKNOWN" @@ -359,6 +368,11 @@ static const struct handler_entry handler_map[] = { {rsvg_create, rsvg_process_data, rsvg_convert, 0, rsvg_destroy, 0, 0, 0, rsvg_redraw, 0, 0, 0, rsvg_clone, false}, +#endif +#ifdef WITH_WEBP + {0, 0, webp_convert, + 0, webp_destroy, 0, 0, 0, webp_redraw, 0, + 0, 0, webp_clone, false}, #endif {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false} }; diff --git a/content/content_protected.h b/content/content_protected.h index c46fa6c6c..6d8d50dc7 100644 --- a/content/content_protected.h +++ b/content/content_protected.h @@ -75,6 +75,9 @@ #ifdef WITH_RSVG #include "image/rsvg.h" #endif +#ifdef WITH_WEBP +#include "image/webp.h" +#endif struct bitmap; @@ -146,6 +149,9 @@ struct content { #endif #ifdef WITH_PNG struct content_png_data png; +#endif +#ifdef WITH_WEBP + struct content_webp_data webp; #endif } data; diff --git a/content/content_type.h b/content/content_type.h index 23cdc6203..bcb2cc170 100644 --- a/content/content_type.h +++ b/content/content_type.h @@ -67,6 +67,9 @@ typedef enum { #endif #if defined(WITH_NS_SVG) || defined(WITH_RSVG) CONTENT_SVG, +#endif +#ifdef WITH_WEBP + CONTENT_WEBP, #endif /* these must be the last two */ CONTENT_OTHER, diff --git a/image/webp.c b/image/webp.c new file mode 100644 index 000000000..7df6ccf35 --- /dev/null +++ b/image/webp.c @@ -0,0 +1,137 @@ + /* + * Copyright 2010 Chris Young + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** \file + * Content for image/webp (libwebp implementation). + * + */ + +#include "utils/config.h" +#ifdef WITH_WEBP + +#include +#include +#include +#include +#include "desktop/plotters.h" +#include "image/bitmap.h" +#include "content/content_protected.h" +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/utils.h" + +/** + * Convert a CONTENT_WEBP for display. + * + * No conversion is necessary. We merely read the WebP dimensions. + */ + +bool webp_convert(struct content *c) +{ + union content_msg_data msg_data; + const char *data; + unsigned long size; + uint8 *Y = NULL, *U = NULL, *V = NULL; + uint32 width = 0, height = 0; + char title[100]; + WebPResult res = webp_success; + + data = content__get_source_data(c, &size); + + res = WebPDecode(data, size, &Y, &U, &V, &width, &height); + if (res != webp_success) { + msg_data.error = messages_get("NoMemory"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + if(Y) free(Y); + return false; + } + + c->bitmap = bitmap_create(width, height, BITMAP_NEW | BITMAP_OPAQUE); + if (!c->bitmap) { + msg_data.error = messages_get("NoMemory"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + if(Y) free(Y); + return false; + } + unsigned char* imagebuf = bitmap_get_buffer(c->bitmap); + if (!imagebuf) { + msg_data.error = messages_get("NoMemory"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + if(Y) free(Y); + return false; + } + unsigned int row_width = bitmap_get_rowstride(c->bitmap) / 4; + + YUV420toRGBA(Y, U, V, row_width, width, height, imagebuf); + + if(Y) free(Y); + + /* I think we may need to reverse the byte order here, as it is fixed + * to RGBA on both big- and little-endian platforms. */ + + c->width = width; + c->height = height; + snprintf(title, sizeof(title), messages_get("WebPTitle"), + width, height, size); + content__set_title(c, title); + + bitmap_modified(c->bitmap); + c->status = CONTENT_STATUS_DONE; + + return true; +} + + +/** + * Destroy a CONTENT_WEBP and free all resources it owns. + */ + +void webp_destroy(struct content *c) +{ + if (c->bitmap != NULL) + bitmap_destroy(c->bitmap); +} + + +/** + * Redraw a CONTENT_WEBP. + */ + +bool webp_redraw(struct content *c, int x, int y, + int width, int height, + int clip_x0, int clip_y0, int clip_x1, int clip_y1, + float scale, colour background_colour) +{ + return plot.bitmap(x, y, width, height, + c->bitmap, background_colour, BITMAPF_NONE); +} + + +bool webp_clone(const struct content *old, struct content *new_content) +{ + /* Simply replay convert */ + if (old->status == CONTENT_STATUS_READY || + old->status == CONTENT_STATUS_DONE) { + if (webp_convert(new_content) == false) + return false; + } + + return true; +} + +#endif diff --git a/image/webp.h b/image/webp.h new file mode 100644 index 000000000..5ff38c900 --- /dev/null +++ b/image/webp.h @@ -0,0 +1,47 @@ +/* + * Copyright 2010 Chris Young + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** \file + * Content for image/webp (libwebp interface). + */ + +#ifndef _NETSURF_WEBP_H_ +#define _NETSURF_WEBP_H_ + +#include "utils/config.h" +#ifdef WITH_WEBP + +#include + +struct content; + +struct content_webp_data { +/* empty */ +}; + +bool webp_convert(struct content *c); +void webp_destroy(struct content *c); +bool webp_redraw(struct content *c, int x, int y, + int width, int height, + int clip_x0, int clip_y0, int clip_x1, int clip_y1, + float scale, colour background_colour); +bool webp_clone(const struct content *old, struct content *new_content); + +#endif /* WITH_WEBP */ + +#endif -- cgit v1.2.3