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
This commit is contained in:
Chris Young 2010-10-03 20:41:31 +00:00
parent c46e0e6015
commit c0b63c111b
15 changed files with 231 additions and 2 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

6
amiga/dist/Install vendored
View File

@ -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")

View File

@ -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

View File

@ -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}
};

View File

@ -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;

View File

@ -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,

137
image/webp.c Normal file
View File

@ -0,0 +1,137 @@
/*
* Copyright 2010 Chris Young <chris@unsatisfactorysoftware.co.uk>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/** \file
* Content for image/webp (libwebp implementation).
*
*/
#include "utils/config.h"
#ifdef WITH_WEBP
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <webpimg.h>
#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

47
image/webp.h Normal file
View File

@ -0,0 +1,47 @@
/*
* Copyright 2010 Chris Young <chris@unsatisfactorysoftware.co.uk>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/** \file
* Content for image/webp (libwebp interface).
*/
#ifndef _NETSURF_WEBP_H_
#define _NETSURF_WEBP_H_
#include "utils/config.h"
#ifdef WITH_WEBP
#include <stdbool.h>
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