From 208363fe2a8a519915123d80f3ca02452aa76eb3 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Fri, 6 May 2011 22:42:37 +0000 Subject: Rename DataTypes related code/files/defines to avoid confusion and aid adding support for other DataType classes. Disable MNG/WebP by default as they aren't common and the required libs are quite large; DataTypes can handle these formats for now. svn path=/trunk/netsurf/; revision=12284 --- Makefile.defaults | 8 +- amiga/Makefile.target | 7 +- amiga/datatypes.c | 36 ++++++ amiga/datatypes.h | 43 +++++++ amiga/dt_picture.c | 312 ++++++++++++++++++++++++++++++++++++++++++++++++++ amiga/filetype.c | 4 + amiga/font.c | 8 +- amiga/gui.c | 6 +- amiga/pkg/makepackage | 4 +- amiga/plugin.c | 312 -------------------------------------------------- amiga/plugin.h | 37 ------ 11 files changed, 414 insertions(+), 363 deletions(-) create mode 100644 amiga/datatypes.c create mode 100644 amiga/datatypes.h create mode 100644 amiga/dt_picture.c delete mode 100644 amiga/plugin.c delete mode 100644 amiga/plugin.h diff --git a/Makefile.defaults b/Makefile.defaults index ee7b21d95..dd3755049 100644 --- a/Makefile.defaults +++ b/Makefile.defaults @@ -220,9 +220,13 @@ ifeq ($(TARGET),amiga) # Valid options: YES, NO, AUTO NETSURF_USE_ROSPRITE := YES + # Enable NetSurf's use of libmng for displaying MNGs, JNGs and PNGs + # Valid options: YES, NO (at least one of PNG/MNG/DT highly recommended) + NETSURF_USE_MNG := NO + # Enable NetSurf's use of libwebp for displaying WebPs # Valid options: YES, NO - NETSURF_USE_WEBP := YES + NETSURF_USE_WEBP := NO # Enable NetSurf to display Amiga icons # Valid options: YES, NO (recommended) @@ -230,7 +234,7 @@ ifeq ($(TARGET),amiga) # Enable NetSurf's use of DataTypes for unknown filetypes # Valid options: YES, NO - NETSURF_USE_PLUGINS := YES + NETSURF_USE_AMIGA_DATATYPES := YES # Enable NetSurf's use of libsvgtiny for displaying SVGs # (NB: Requires NETSURF_AMIGA_USE_CAIRO) diff --git a/amiga/Makefile.target b/amiga/Makefile.target index 00b700551..47de8cb3f 100644 --- a/amiga/Makefile.target +++ b/amiga/Makefile.target @@ -24,7 +24,7 @@ ifeq ($(HOST),amiga) $(eval $(call feature_enabled,MNG,,-llcms -ljpeg,PNG/JNG/MNG (libmng))) $(eval $(call feature_enabled,WEBP,-DWITH_WEBP,-lwebp,WebP (libwebp))) $(eval $(call feature_enabled,AMIGA_ICON,-DWITH_AMIGA_ICON,,Amiga icon)) - $(eval $(call feature_enabled,PLUGINS,-DWITH_PLUGIN,,DataTypes images)) + $(eval $(call feature_enabled,AMIGA_DATATYPES,-DWITH_AMIGA_DATATYPES,,DataTypes)) CFLAGS += -I /SDK/local/common/include/libpng12 LDFLAGS += -lxml2 -lcurl -lrtmp -lpthread -lregex -lauto -lpbl @@ -43,7 +43,7 @@ else $(eval $(call pkg_config_find_and_add,PNG,libpng,PNG)) $(eval $(call pkg_config_find_and_add,NSSVG,libsvgtiny,NSSVG)) $(eval $(call feature_enabled,AMIGA_ICON,-DWITH_AMIGA_ICON,,Amiga icon)) - $(eval $(call feature_enabled,PLUGINS,-DWITH_PLUGIN,,DataTypes images)) + $(eval $(call feature_enabled,AMIGA_DATATYPES,-DWITH_AMIGA_DATATYPES,,DataTypes)) CFLAGS += -I$(GCCSDK_INSTALL_ENV)/include CFLAGS += $(shell $(PKG_CONFIG) --cflags libxml-2.0 libcurl libcares openssl) @@ -67,12 +67,13 @@ endif # ---------------------------------------------------------------------------- # S_AMIGA are sources purely for the Amiga build -S_AMIGA := gui.c tree.c history.c hotlist.c schedule.c plugin.c \ +S_AMIGA := gui.c tree.c history.c hotlist.c schedule.c \ thumbnail.c misc.c bitmap.c font.c filetype.c utf8.c login.c \ plotters.c object.c menu.c save_pdf.c arexx.c version.c \ cookies.c context_menu.c clipboard.c save_complete.c \ launch.c search.c history_local.c download.c iff_dr2d.c \ sslcert.c gui_options.c print.c theme.c drag.c icon.c system_colour.c \ + datatypes.c dt_picture.c \ stringview/stringview.c stringview/urlhistory.c S_AMIGA := $(addprefix amiga/,$(S_AMIGA)) diff --git a/amiga/datatypes.c b/amiga/datatypes.c new file mode 100644 index 000000000..518b0347c --- /dev/null +++ b/amiga/datatypes.c @@ -0,0 +1,36 @@ +/* + * Copyright 2011 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 . + */ + +#ifdef WITH_AMIGA_DATATYPES +#include "amiga/datatypes.h" + +nserror amiga_datatypes_init(void) +{ + nserror err = NSERROR_OK; + + err = amiga_dt_picture_init(); + if(err != NSERROR_OK) return err; + + return NSERROR_OK; +} + +void amiga_datatypes_fini(void) +{ + amiga_dt_picture_fini(); +} +#endif diff --git a/amiga/datatypes.h b/amiga/datatypes.h new file mode 100644 index 000000000..70958d4de --- /dev/null +++ b/amiga/datatypes.h @@ -0,0 +1,43 @@ +/* + * Copyright 2011 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 . + */ + +#ifndef NETSURF_AMIGA_DATATYPES_H_ +#define NETSURF_AMIGA_DATATYPES_H_ + +#include "utils/config.h" +#include "utils/errors.h" + +#ifdef WITH_AMIGA_DATATYPES + +nserror amiga_datatypes_init(void); +void amiga_datatypes_fini(void); + +nserror amiga_dt_picture_init(void); +void amiga_dt_picture_fini(void); + +#else + +#define amiga_datatypes_init() NSERROR_OK +#define amiga_datatypes_fini() ((void) 0) + +#define amiga_dt_picture_init() NSERROR_OK +#define amiga_dt_picture_fini() ((void) 0) + +#endif /* WITH_AMIGA_DATATYPES */ + +#endif diff --git a/amiga/dt_picture.c b/amiga/dt_picture.c new file mode 100644 index 000000000..315b3f2e1 --- /dev/null +++ b/amiga/dt_picture.c @@ -0,0 +1,312 @@ +/* + * Copyright 2011 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 + * DataTypes picture handler (implementation) +*/ + +#ifdef WITH_AMIGA_DATATYPES +#include "amiga/filetype.h" +#include "amiga/gui.h" +#include "amiga/datatypes.h" +#include "content/content_protected.h" +#include "desktop/plotters.h" +#include "image/bitmap.h" +#include "render/box.h" +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/talloc.h" + +#include +#include +#include +#include + +typedef struct amiga_dt_picture_content { + struct content base; + + Object *dto; + int x; + int y; + int w; + int h; +} amiga_dt_picture_content; + +static nserror amiga_dt_picture_create(const content_handler *handler, + lwc_string *imime_type, const http_parameter *params, + llcache_handle *llcache, const char *fallback_charset, + bool quirks, struct content **c); +static bool amiga_dt_picture_convert(struct content *c); +static void amiga_dt_picture_reformat(struct content *c, int width, int height); +static void amiga_dt_picture_destroy(struct content *c); +static bool amiga_dt_picture_redraw(struct content *c, int x, int y, + int width, int height, const struct rect *clip, + float scale, colour background_colour); +static void amiga_dt_picture_open(struct content *c, struct browser_window *bw, + struct content *page, struct box *box, + struct object_params *params); +static void amiga_dt_picture_close(struct content *c); +static nserror amiga_dt_picture_clone(const struct content *old, struct content **newc); +static content_type amiga_dt_picture_content_type(lwc_string *mime_type); + +static const content_handler amiga_dt_picture_content_handler = { + amiga_dt_picture_create, + NULL, + amiga_dt_picture_convert, + amiga_dt_picture_reformat, + amiga_dt_picture_destroy, + NULL, + NULL, + NULL, + amiga_dt_picture_redraw, + NULL, + amiga_dt_picture_open, + amiga_dt_picture_close, + amiga_dt_picture_clone, + NULL, + amiga_dt_picture_content_type, + false +}; + +nserror amiga_dt_picture_init(void) +{ + char dt_mime[50]; + struct DataType *dt, *prevdt = NULL; + lwc_string *type; + lwc_error lerror; + nserror error; + + while((dt = ObtainDataType(DTST_RAM, NULL, + DTA_DataType, prevdt, + DTA_GroupID, GID_PICTURE, // we only support images for now + TAG_DONE)) != NULL) + { + ReleaseDataType(prevdt); + prevdt = dt; + ami_datatype_to_mimetype(dt, dt_mime); + + LOG(("Guessed MIME from DT: %s", dt_mime)); + + lerror = lwc_intern_string(dt_mime, strlen(dt_mime), &type); + if (lerror != lwc_error_ok) + return NSERROR_NOMEM; + + error = content_factory_register_handler(type, + &amiga_dt_picture_content_handler); + + lwc_string_unref(type); + + if (error != NSERROR_OK) + return error; + + } + + ReleaseDataType(prevdt); + + return NSERROR_OK; +} + +void amiga_dt_picture_fini(void) +{ + /* Nothing to do */ +} + +nserror amiga_dt_picture_create(const content_handler *handler, + lwc_string *imime_type, const http_parameter *params, + llcache_handle *llcache, const char *fallback_charset, + bool quirks, struct content **c) +{ + amiga_dt_picture_content *plugin; + nserror error; + + plugin = talloc_zero(0, amiga_dt_picture_content); + if (plugin == NULL) + return NSERROR_NOMEM; + + error = content__init(&plugin->base, handler, imime_type, params, + llcache, fallback_charset, quirks); + if (error != NSERROR_OK) { + talloc_free(plugin); + return error; + } + + *c = (struct content *) plugin; + + return NSERROR_OK; +} + +bool amiga_dt_picture_convert(struct content *c) +{ + LOG(("amiga_dt_picture_convert")); + + amiga_dt_picture_content *plugin = (amiga_dt_picture_content *) c; + union content_msg_data msg_data; + int width, height; + char title[100]; + const uint8 *data; + UBYTE *bm_buffer; + ULONG size; + Object *dto; + struct BitMapHeader *bmh; + unsigned int bm_flags = BITMAP_NEW; + int bm_format = PBPAFMT_RGBA; + + /* This is only relevant for picture datatypes... */ + + data = (uint8 *)content__get_source_data(c, &size); + + if(plugin->dto = NewDTObject(NULL, + DTA_SourceType, DTST_MEMORY, + DTA_SourceAddress, data, + DTA_SourceSize, size, + DTA_GroupID, GID_PICTURE, + PDTA_DestMode, PMODE_V43, + TAG_DONE)) + { + if(GetDTAttrs(plugin->dto, PDTA_BitMapHeader, &bmh, TAG_DONE)) + { + width = (int)bmh->bmh_Width; + height = (int)bmh->bmh_Height; + + c->bitmap = bitmap_create(width, height, bm_flags); + if (!c->bitmap) { + msg_data.error = messages_get("NoMemory"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + return false; + } + + bm_buffer = bitmap_get_buffer(c->bitmap); + + IDoMethod(plugin->dto, PDTM_READPIXELARRAY, + bm_buffer, bm_format, bitmap_get_rowstride(c->bitmap), + 0, 0, width, height); + } + else return false; + } + else return false; + + c->width = width; + c->height = height; + +/* + snprintf(title, sizeof(title), "image (%lux%lu, %lu bytes)", + width, height, size); + content__set_title(c, title); +*/ + + bitmap_modified(c->bitmap); + + content_set_ready(c); + content_set_done(c); + + content_set_status(c, ""); + return true; +} + +void amiga_dt_picture_destroy(struct content *c) +{ + amiga_dt_picture_content *plugin = (amiga_dt_picture_content *) c; + + LOG(("amiga_dt_picture_destroy")); + + if (c->bitmap != NULL) + bitmap_destroy(c->bitmap); + + DisposeDTObject(plugin->dto); + + return; +} + +bool amiga_dt_picture_redraw(struct content *c, int x, int y, + int width, int height, const struct rect *clip, + float scale, colour background_colour) +{ + LOG(("amiga_dt_picture_redraw")); + + return plot.bitmap(x, y, width, height, + c->bitmap, background_colour, BITMAPF_NONE); +} + +/** + * Handle a window containing a CONTENT_PLUGIN being opened. + * + * \param c content that has been opened + * \param bw browser window containing the content + * \param page content of type CONTENT_HTML containing c, or 0 if not an + * object within a page + * \param box box containing c, or 0 if not an object + * \param params object parameters, or 0 if not an object + */ +void amiga_dt_picture_open(struct content *c, struct browser_window *bw, + struct content *page, struct box *box, + struct object_params *params) +{ + LOG(("amiga_dt_picture_open")); + + return; +} + +void amiga_dt_picture_close(struct content *c) +{ + LOG(("amiga_dt_picture_close")); + return; +} + +void amiga_dt_picture_reformat(struct content *c, int width, int height) +{ + LOG(("amiga_dt_picture_reformat")); + return; +} + +nserror amiga_dt_picture_clone(const struct content *old, struct content **newc) +{ + amiga_dt_picture_content *plugin; + nserror error; + + LOG(("amiga_dt_picture_clone")); + + plugin = talloc_zero(0, amiga_dt_picture_content); + if (plugin == NULL) + return NSERROR_NOMEM; + + error = content__clone(old, &plugin->base); + if (error != NSERROR_OK) { + content_destroy(&plugin->base); + return error; + } + + /* We "clone" the old content by replaying conversion */ + if (old->status == CONTENT_STATUS_READY || + old->status == CONTENT_STATUS_DONE) { + if (amiga_dt_picture_convert(&plugin->base) == false) { + content_destroy(&plugin->base); + return NSERROR_CLONE_FAILED; + } + } + + *newc = (struct content *) plugin; + + return NSERROR_OK; +} + +content_type amiga_dt_picture_content_type(lwc_string *mime_type) +{ + return CONTENT_IMAGE; +} + +#endif diff --git a/amiga/filetype.c b/amiga/filetype.c index 9d4414a13..5995ec8d5 100644 --- a/amiga/filetype.c +++ b/amiga/filetype.c @@ -178,6 +178,10 @@ void ami_datatype_to_mimetype(struct DataType *dtn, char *mimetype) { strcpy(mimetype,"image/x-riscos-sprite"); } + if(strcmp("mng",dth->dth_BaseName)==0) + { + strcpy(mimetype,"video/mng"); + } break; case GID_ANIMATION: case GID_MOVIE: diff --git a/amiga/font.c b/amiga/font.c index 7ee1b2a72..ab4af75fb 100644 --- a/amiga/font.c +++ b/amiga/font.c @@ -58,7 +58,7 @@ #define NSA_VALUE_SHEARSIN (1 << 14) #define NSA_VALUE_SHEARCOS (1 << 16) -#define NSA_FONT_EMWIDTH(s) (ULONG)(s / FONT_SIZE_SCALE) * (ami_xdpi / 72.0) +#define NSA_FONT_EMWIDTH(s) (s / FONT_SIZE_SCALE) * (ami_xdpi / 72.0) struct ami_font_node { @@ -136,7 +136,7 @@ bool nsfont_position_in_string(const plot_font_style_t *fstyle, uint8 *utf8; uint32 co = 0; int utf16charlen; - ULONG emwidth = NSA_FONT_EMWIDTH(fstyle->size); + ULONG emwidth = (ULONG)NSA_FONT_EMWIDTH(fstyle->size); int32 tempx; len = utf8_bounded_length(string, length); @@ -245,7 +245,7 @@ bool nsfont_split(const plot_font_style_t *fstyle, size_t len; int utf8len, utf8clen = 0; int32 tempx = 0; - ULONG emwidth = NSA_FONT_EMWIDTH(fstyle->size); + ULONG emwidth = (ULONG)NSA_FONT_EMWIDTH(fstyle->size); len = utf8_bounded_length(string, length); if(utf8_to_enc((char *)string,"UTF-16",length,(char **)&utf16) != UTF8_CONVERT_OK) return false; @@ -550,7 +550,7 @@ ULONG ami_unicode_text(struct RastPort *rp,const char *string,ULONG length,const uint32 x=0; uint8 co = 0; int32 tempx = 0; - ULONG emwidth = NSA_FONT_EMWIDTH(fstyle->size); + ULONG emwidth = (ULONG)NSA_FONT_EMWIDTH(fstyle->size); if(!string || string[0]=='\0') return 0; if(!length) return 0; diff --git a/amiga/gui.c b/amiga/gui.c index d3f05e576..e032ac90c 100755 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -42,6 +42,7 @@ #include "amiga/clipboard.h" #include "amiga/context_menu.h" #include "amiga/cookies.h" +#include "amiga/datatypes.h" #include "amiga/download.h" #include "amiga/drag.h" #include "amiga/font.h" @@ -57,7 +58,6 @@ #include "amiga/misc.h" #include "amiga/options.h" #include "amiga/plotters.h" -#include "amiga/plugin.h" #include "amiga/print.h" #include "amiga/schedule.h" #include "amiga/search.h" @@ -750,7 +750,7 @@ int main(int argc, char** argv) ami_schedule_open_timer(); ami_schedule_create(); - plugin_init(); + amiga_datatypes_init(); netsurf_init(&argc, &argv, "PROGDIR:Resources/Options", messages); @@ -771,7 +771,7 @@ int main(int argc, char** argv) netsurf_exit(); - plugin_fini(); + amiga_datatypes_fini(); amiga_icon_fini(); return 0; diff --git a/amiga/pkg/makepackage b/amiga/pkg/makepackage index 3895bac16..5a2828a7a 100755 --- a/amiga/pkg/makepackage +++ b/amiga/pkg/makepackage @@ -21,8 +21,8 @@ copy amiga/pkg/fitr ram:NetSurf/ makedir ram:NetSurf/Rexx copy amiga/dist/Rexx/~(.svn) ram:NetSurf/Rexx/ COM makedir ram:NetSurf/Libs -copy libs:parserutils.library libs:nsgif.library libs:nsbmp.library libs:iconv.library libs:hubbub.library libs:webp.library ram:NetSurf/Libs +copy libs:parserutils.library libs:nsgif.library libs:nsbmp.library libs:iconv.library libs:hubbub.library ram:NetSurf/Libs ; libs:css.library libs:wapcaplet.library makedir ram:NetSurf/SObjs -copy sobjs:libjpeg.so.8 sobjs:libmng.so.1 sobjs:liblcms.so sobjs:libxml2.so.9 sobjs:libcurl.so.7 sobjs:librtmp.so.0 sobjs:libsvgtiny.so.0 sobjs:libz.so.1.2.5 sobjs:libssl.so.1.0.0 sobjs:libcrypto.so.1.0.0 sobjs:libcss.so.0 sobjs:libwapcaplet.so.0 sobjs:libpng12.so ram:NetSurf/SObjs clone +copy sobjs:libjpeg.so.8 sobjs:libxml2.so.9 sobjs:libcurl.so.7 sobjs:librtmp.so.0 sobjs:libsvgtiny.so.0 sobjs:libz.so.1.2.5 sobjs:libssl.so.1.0.0 sobjs:libcrypto.so.1.0.0 sobjs:libcss.so.0 sobjs:libwapcaplet.so.0 sobjs:libpng12.so ram:NetSurf/SObjs clone ;sobjs:libhpdf-2.2.0.so.0.0 diff --git a/amiga/plugin.c b/amiga/plugin.c deleted file mode 100644 index e68930283..000000000 --- a/amiga/plugin.c +++ /dev/null @@ -1,312 +0,0 @@ -/* - * Copyright 2011 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 - * Temporary "plugin" to pass unknown MIME types to DataTypes (implementation) -*/ - -#ifdef WITH_PLUGIN -#include "amiga/filetype.h" -#include "amiga/gui.h" -#include "amiga/plugin.h" -#include "content/content_protected.h" -#include "desktop/plotters.h" -#include "image/bitmap.h" -#include "render/box.h" -#include "utils/log.h" -#include "utils/messages.h" -#include "utils/talloc.h" - -#include -#include -#include -#include - -typedef struct plugin_content { - struct content base; - - Object *dto; - int x; - int y; - int w; - int h; -} plugin_content; - -static nserror plugin_create(const content_handler *handler, - lwc_string *imime_type, const http_parameter *params, - llcache_handle *llcache, const char *fallback_charset, - bool quirks, struct content **c); -static bool plugin_convert(struct content *c); -static void plugin_reformat(struct content *c, int width, int height); -static void plugin_destroy(struct content *c); -static bool plugin_redraw(struct content *c, int x, int y, - int width, int height, const struct rect *clip, - float scale, colour background_colour); -static void plugin_open(struct content *c, struct browser_window *bw, - struct content *page, struct box *box, - struct object_params *params); -static void plugin_close(struct content *c); -static nserror plugin_clone(const struct content *old, struct content **newc); -static content_type plugin_content_type(lwc_string *mime_type); - -static const content_handler plugin_content_handler = { - plugin_create, - NULL, - plugin_convert, - plugin_reformat, - plugin_destroy, - NULL, - NULL, - NULL, - plugin_redraw, - NULL, - plugin_open, - plugin_close, - plugin_clone, - NULL, - plugin_content_type, - false -}; - -nserror plugin_init(void) -{ - char dt_mime[50]; - struct DataType *dt, *prevdt = NULL; - lwc_string *type; - lwc_error lerror; - nserror error; - - while((dt = ObtainDataType(DTST_RAM, NULL, - DTA_DataType, prevdt, - DTA_GroupID, GID_PICTURE, // we only support images for now - TAG_DONE)) != NULL) - { - ReleaseDataType(prevdt); - prevdt = dt; - ami_datatype_to_mimetype(dt, dt_mime); - - LOG(("Guessed MIME from DT: %s", dt_mime)); - - lerror = lwc_intern_string(dt_mime, strlen(dt_mime), &type); - if (lerror != lwc_error_ok) - return NSERROR_NOMEM; - - error = content_factory_register_handler(type, - &plugin_content_handler); - - lwc_string_unref(type); - - if (error != NSERROR_OK) - return error; - - } - - ReleaseDataType(prevdt); - - return NSERROR_OK; -} - -void plugin_fini(void) -{ - /* Nothing to do */ -} - -nserror plugin_create(const content_handler *handler, - lwc_string *imime_type, const http_parameter *params, - llcache_handle *llcache, const char *fallback_charset, - bool quirks, struct content **c) -{ - plugin_content *plugin; - nserror error; - - plugin = talloc_zero(0, plugin_content); - if (plugin == NULL) - return NSERROR_NOMEM; - - error = content__init(&plugin->base, handler, imime_type, params, - llcache, fallback_charset, quirks); - if (error != NSERROR_OK) { - talloc_free(plugin); - return error; - } - - *c = (struct content *) plugin; - - return NSERROR_OK; -} - -bool plugin_convert(struct content *c) -{ - LOG(("plugin_convert")); - - plugin_content *plugin = (plugin_content *) c; - union content_msg_data msg_data; - int width, height; - char title[100]; - const uint8 *data; - UBYTE *bm_buffer; - ULONG size; - Object *dto; - struct BitMapHeader *bmh; - unsigned int bm_flags = BITMAP_NEW; - int bm_format = PBPAFMT_RGBA; - - /* This is only relevant for picture datatypes... */ - - data = (uint8 *)content__get_source_data(c, &size); - - if(plugin->dto = NewDTObject(NULL, - DTA_SourceType, DTST_MEMORY, - DTA_SourceAddress, data, - DTA_SourceSize, size, - DTA_GroupID, GID_PICTURE, - PDTA_DestMode, PMODE_V43, - TAG_DONE)) - { - if(GetDTAttrs(plugin->dto, PDTA_BitMapHeader, &bmh, TAG_DONE)) - { - width = (int)bmh->bmh_Width; - height = (int)bmh->bmh_Height; - - c->bitmap = bitmap_create(width, height, bm_flags); - if (!c->bitmap) { - msg_data.error = messages_get("NoMemory"); - content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - return false; - } - - bm_buffer = bitmap_get_buffer(c->bitmap); - - IDoMethod(plugin->dto, PDTM_READPIXELARRAY, - bm_buffer, bm_format, bitmap_get_rowstride(c->bitmap), - 0, 0, width, height); - } - else return false; - } - else return false; - - c->width = width; - c->height = height; - -/* - snprintf(title, sizeof(title), "image (%lux%lu, %lu bytes)", - width, height, size); - content__set_title(c, title); -*/ - - bitmap_modified(c->bitmap); - - content_set_ready(c); - content_set_done(c); - - content_set_status(c, ""); - return true; -} - -void plugin_destroy(struct content *c) -{ - plugin_content *plugin = (plugin_content *) c; - - LOG(("plugin_destroy")); - - if (c->bitmap != NULL) - bitmap_destroy(c->bitmap); - - DisposeDTObject(plugin->dto); - - return; -} - -bool plugin_redraw(struct content *c, int x, int y, - int width, int height, const struct rect *clip, - float scale, colour background_colour) -{ - LOG(("plugin_redraw")); - - return plot.bitmap(x, y, width, height, - c->bitmap, background_colour, BITMAPF_NONE); -} - -/** - * Handle a window containing a CONTENT_PLUGIN being opened. - * - * \param c content that has been opened - * \param bw browser window containing the content - * \param page content of type CONTENT_HTML containing c, or 0 if not an - * object within a page - * \param box box containing c, or 0 if not an object - * \param params object parameters, or 0 if not an object - */ -void plugin_open(struct content *c, struct browser_window *bw, - struct content *page, struct box *box, - struct object_params *params) -{ - LOG(("plugin_open")); - - return; -} - -void plugin_close(struct content *c) -{ - LOG(("plugin_close")); - return; -} - -void plugin_reformat(struct content *c, int width, int height) -{ - LOG(("plugin_reformat")); - return; -} - -nserror plugin_clone(const struct content *old, struct content **newc) -{ - plugin_content *plugin; - nserror error; - - LOG(("plugin_clone")); - - plugin = talloc_zero(0, plugin_content); - if (plugin == NULL) - return NSERROR_NOMEM; - - error = content__clone(old, &plugin->base); - if (error != NSERROR_OK) { - content_destroy(&plugin->base); - return error; - } - - /* We "clone" the old content by replaying conversion */ - if (old->status == CONTENT_STATUS_READY || - old->status == CONTENT_STATUS_DONE) { - if (plugin_convert(&plugin->base) == false) { - content_destroy(&plugin->base); - return NSERROR_CLONE_FAILED; - } - } - - *newc = (struct content *) plugin; - - return NSERROR_OK; -} - -content_type plugin_content_type(lwc_string *mime_type) -{ - return CONTENT_IMAGE; -} - -#endif diff --git a/amiga/plugin.h b/amiga/plugin.h deleted file mode 100644 index 605d989d4..000000000 --- a/amiga/plugin.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2011 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 . - */ - -#ifndef NETSURF_AMIGA_PLUGIN_H_ -#define NETSURF_AMIGA_PLUGIN_H_ - -#include "utils/config.h" -#include "utils/errors.h" - -#ifdef WITH_PLUGIN - -nserror plugin_init(void); -void plugin_fini(void); - -#else - -#define plugin_init() NSERROR_OK -#define plugin_fini() ((void) 0) - -#endif /* WITH_PLUGIN */ - -#endif -- cgit v1.2.3