r12675 tlsa - /trunk/netsurf/framebuffer/gui.c
by netsurf@semichrome.net
Author: tlsa
Date: Mon Aug 29 04:28:07 2011
New Revision: 12675
URL: http://source.netsurf-browser.org?rev=12675&view=rev
Log:
If no Cookies file path is set in Choices file, use default of "~/.netsurf/Cookies".
Modified:
trunk/netsurf/framebuffer/gui.c
Modified: trunk/netsurf/framebuffer/gui.c
URL: http://source.netsurf-browser.org/trunk/netsurf/framebuffer/gui.c?rev=126...
==============================================================================
--- trunk/netsurf/framebuffer/gui.c (original)
+++ trunk/netsurf/framebuffer/gui.c Mon Aug 29 04:28:07 2011
@@ -457,12 +457,12 @@
LOG(("Using '%s' as AdBlock CSS URL", adblock_stylesheet_url));
if (option_cookie_file == NULL) {
- option_cookie_file = filepath_find(respaths, "Cookies");
+ option_cookie_file = strdup("~/.netsurf/Cookies");
LOG(("Using '%s' as Cookies file", option_cookie_file));
}
if (option_cookie_jar == NULL) {
- option_cookie_jar = filepath_find(respaths, "Cookies");
+ option_cookie_jar = strdup("~/.netsurf/Cookies");
LOG(("Using '%s' as Cookie Jar file", option_cookie_jar));
}
11 years, 5 months
r12674 chris_y - /trunk/netsurf/Makefile.sources
by netsurf@semichrome.net
Author: chris_y
Date: Sun Aug 28 17:05:11 2011
New Revision: 12674
URL: http://source.netsurf-browser.org?rev=12674&view=rev
Log:
Fix build when using NETSURF_USE_ROSPRITE
Modified:
trunk/netsurf/Makefile.sources
Modified: trunk/netsurf/Makefile.sources
URL: http://source.netsurf-browser.org/trunk/netsurf/Makefile.sources?rev=1267...
==============================================================================
--- trunk/netsurf/Makefile.sources (original)
+++ trunk/netsurf/Makefile.sources Sun Aug 28 17:05:11 2011
@@ -43,7 +43,7 @@
S_IMAGE_$(NETSURF_USE_GIF) += gif.c
S_IMAGE_$(NETSURF_USE_JPEG) += jpeg.c
S_IMAGE_$(NETSURF_USE_MNG) += mng.c
-S_IMAGE_$(NETSURF_USE_NSSPRITE) += nssprite.c
+S_IMAGE_$(NETSURF_USE_ROSPRITE) += nssprite.c
S_IMAGE_$(NETSURF_USE_PNG) += png.c
S_IMAGE_$(NETSURF_USE_NSSVG) += svg.c
S_IMAGE_$(NETSURF_USE_RSVG) += rsvg.c
11 years, 5 months
r12673 vince - in /trunk/netsurf: ./ amiga/ atari/ beos/ cocoa/ framebuffer/ gtk/ image/ monkey/ riscos/ windows/
by netsurf@semichrome.net
Author: vince
Date: Sun Aug 28 09:29:15 2011
New Revision: 12673
URL: http://source.netsurf-browser.org?rev=12673&view=rev
Log:
make image content handlers build conditional from teh makefile
Modified:
trunk/netsurf/Makefile
trunk/netsurf/Makefile.sources
trunk/netsurf/amiga/Makefile.target
trunk/netsurf/atari/Makefile.target
trunk/netsurf/beos/Makefile.target
trunk/netsurf/cocoa/Makefile.target
trunk/netsurf/framebuffer/Makefile.target
trunk/netsurf/gtk/Makefile.target
trunk/netsurf/image/bmp.c
trunk/netsurf/image/bmp.h
trunk/netsurf/image/gif.c
trunk/netsurf/image/gif.h
trunk/netsurf/image/ico.c
trunk/netsurf/image/ico.h
trunk/netsurf/image/image.c
trunk/netsurf/image/image.h
trunk/netsurf/image/jpeg.c
trunk/netsurf/image/jpeg.h
trunk/netsurf/image/mng.c
trunk/netsurf/image/mng.h
trunk/netsurf/image/nssprite.c
trunk/netsurf/image/nssprite.h
trunk/netsurf/image/png.c
trunk/netsurf/image/png.h
trunk/netsurf/image/rsvg.c
trunk/netsurf/image/rsvg.h
trunk/netsurf/image/svg.c
trunk/netsurf/image/svg.h
trunk/netsurf/image/webp.c
trunk/netsurf/image/webp.h
trunk/netsurf/monkey/Makefile.target
trunk/netsurf/riscos/Makefile.target
trunk/netsurf/windows/Makefile.target
Modified: trunk/netsurf/Makefile
URL: http://source.netsurf-browser.org/trunk/netsurf/Makefile?rev=12673&r1=126...
==============================================================================
--- trunk/netsurf/Makefile (original)
+++ trunk/netsurf/Makefile Sun Aug 28 09:29:15 2011
@@ -302,10 +302,12 @@
LDFLAGS += $$(shell $$(PKG_CONFIG) --libs $(2)) $$(NETSURF_FEATURE_$(1)_LDFLAGS)
ifneq ($(MAKECMDGOALS),clean)
$$(info M.CONFIG: $(3) ($(2)) auto-enabled (NETSURF_USE_$(1) := AUTO))
+ NETSURF_USE_$(1) := YES
endif
else
ifneq ($(MAKECMDGOALS),clean)
$$(info M.CONFIG: $(3) ($(2)) auto-disabled (NETSURF_USE_$(1) := AUTO))
+ NETSURF_USE_$(1) := NO
endif
endif
else ifeq ($$(NETSURF_USE_$(1)),NO)
@@ -373,20 +375,23 @@
POSTEXES :=
# ----------------------------------------------------------------------------
+# Target specific setup
+# ----------------------------------------------------------------------------
+
+include $(TARGET)/Makefile.target
+
+# ----------------------------------------------------------------------------
# General source file setup
# ----------------------------------------------------------------------------
include Makefile.sources
# ----------------------------------------------------------------------------
-# Target specific setup
-# ----------------------------------------------------------------------------
-
-include $(TARGET)/Makefile.target
-
-# ----------------------------------------------------------------------------
# Source file setup
# ----------------------------------------------------------------------------
+
+# Force exapnsion of source file list
+SOURCES := $(SOURCES)
ifeq ($(SOURCES),)
$(error Unable to build NetSurf, could not determine set of sources to build)
Modified: trunk/netsurf/Makefile.sources
URL: http://source.netsurf-browser.org/trunk/netsurf/Makefile.sources?rev=1267...
==============================================================================
--- trunk/netsurf/Makefile.sources (original)
+++ trunk/netsurf/Makefile.sources Sun Aug 28 09:29:15 2011
@@ -37,9 +37,19 @@
$(addprefix desktop/,$(S_DESKTOP))
# S_IMAGE are sources related to image management
-S_IMAGE := bmp.c gif.c ico.c image.c jpeg.c mng.c nssprite.c png.c \
- svg.c rsvg.c webp.c
-S_IMAGE := $(addprefix image/,$(S_IMAGE))
+S_IMAGE_YES := image.c
+S_IMAGE_NO :=
+S_IMAGE_$(NETSURF_USE_BMP) += bmp.c ico.c
+S_IMAGE_$(NETSURF_USE_GIF) += gif.c
+S_IMAGE_$(NETSURF_USE_JPEG) += jpeg.c
+S_IMAGE_$(NETSURF_USE_MNG) += mng.c
+S_IMAGE_$(NETSURF_USE_NSSPRITE) += nssprite.c
+S_IMAGE_$(NETSURF_USE_PNG) += png.c
+S_IMAGE_$(NETSURF_USE_NSSVG) += svg.c
+S_IMAGE_$(NETSURF_USE_RSVG) += rsvg.c
+S_IMAGE_$(NETSURF_USE_WEBP) += webp.c
+
+S_IMAGE := $(addprefix image/,$(S_IMAGE_YES))
# S_PDF are sources of the pdf plotter + the ones for paged-printing
S_PDF := pdf_plotters.c font_haru.c
Modified: trunk/netsurf/amiga/Makefile.target
URL: http://source.netsurf-browser.org/trunk/netsurf/amiga/Makefile.target?rev...
==============================================================================
--- trunk/netsurf/amiga/Makefile.target (original)
+++ trunk/netsurf/amiga/Makefile.target Sun Aug 28 09:29:15 2011
@@ -77,5 +77,7 @@
stringview/stringview.c stringview/urlhistory.c
S_AMIGA := $(addprefix amiga/,$(S_AMIGA))
-# complete source file list
-SOURCES := $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_AMIGA) $(S_PDF)
+# This is the final source build list
+# Note this is deliberately *not* expanded here as common and image
+# are not yet available
+SOURCES = $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_AMIGA) $(S_PDF)
Modified: trunk/netsurf/atari/Makefile.target
URL: http://source.netsurf-browser.org/trunk/netsurf/atari/Makefile.target?rev...
==============================================================================
--- trunk/netsurf/atari/Makefile.target (original)
+++ trunk/netsurf/atari/Makefile.target Sun Aug 28 09:29:15 2011
@@ -42,8 +42,10 @@
global_evnt.c osspec.c dragdrop.c system_colour.c
S_ATARI := $(addprefix atari/,$(S_ATARI))
-
-SOURCES := $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_ATARI)
+# This is the final source build list
+# Note this is deliberately *not* expanded here as common and image
+# are not yet available
+SOURCES = $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_ATARI)
EXETARGET := ns$(SUBTARGET).prg
Modified: trunk/netsurf/beos/Makefile.target
URL: http://source.netsurf-browser.org/trunk/netsurf/beos/Makefile.target?rev=...
==============================================================================
--- trunk/netsurf/beos/Makefile.target (original)
+++ trunk/netsurf/beos/Makefile.target Sun Aug 28 09:29:15 2011
@@ -106,6 +106,8 @@
$(wildcard beos/res/throbber/throbber*.png)
-# complete source file list
-SOURCES := $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_BEOS)
+# This is the final source build list
+# Note this is deliberately *not* expanded here as common and image
+# are not yet available
+SOURCES = $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_BEOS)
EXETARGET := NetSurf
Modified: trunk/netsurf/cocoa/Makefile.target
URL: http://source.netsurf-browser.org/trunk/netsurf/cocoa/Makefile.target?rev...
==============================================================================
--- trunk/netsurf/cocoa/Makefile.target (original)
+++ trunk/netsurf/cocoa/Makefile.target Sun Aug 28 09:29:15 2011
@@ -118,9 +118,10 @@
S_COCOA := $(addprefix cocoa/,$(S_COCOA))
S_TABBAR := $(addprefix cocoa/PSMTabBarControl/,$(S_TABBAR))
-# complete source file list
-SOURCES := $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_COCOA) $(S_TABBAR)
-SOURCES := $(addprefix $(shell pwd)/,$(SOURCES))
+# This is the final source build list
+# Note this is deliberately *not* expanded here as common and image
+# are not yet available
+SOURCES = $(addprefix $(shell pwd)/,$(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_COCOA) $(S_TABBAR))
# Since we prefix the sources with the pwd, also create a special
# prefixed rule so that the testament is run
@@ -169,7 +170,7 @@
$(VQ)echo Compiling XIB $(1) for language $(2)
$(Q)mkdir -p $$(OBJROOT)/$(2).lproj
$(Q)cocoa/compile-xib.sh $(DEVELOPER_PATH) cocoa/res/$(1) $(2) $$@
-
+
ifeq ($(wildcard cocoa/res/$(2).lproj/$(1).strings),cocoa/res/$(2).lproj/$(1).strings)
$$(OBJROOT)/$(2).lproj/$(1:.xib=.nib): cocoa/res/$(2).lproj/$(1).strings
endif
Modified: trunk/netsurf/framebuffer/Makefile.target
URL: http://source.netsurf-browser.org/trunk/netsurf/framebuffer/Makefile.targ...
==============================================================================
--- trunk/netsurf/framebuffer/Makefile.target (original)
+++ trunk/netsurf/framebuffer/Makefile.target Sun Aug 28 09:29:15 2011
@@ -149,6 +149,8 @@
S_FRAMEBUFFER := $(addprefix framebuffer/,$(S_FRAMEBUFFER)) $(addprefix framebuffer/fbtk/,$(S_FRAMEBUFFER_FBTK))
-# complete source file list
-SOURCES := $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_FRAMEBUFFER) $(S_IMAGES)
+# This is the final source build list
+# Note this is deliberately *not* expanded here as common and image
+# are not yet available
+SOURCES = $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_FRAMEBUFFER) $(S_IMAGES)
EXETARGET := nsfb$(SUBTARGET)
Modified: trunk/netsurf/gtk/Makefile.target
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/Makefile.target?rev=1...
==============================================================================
--- trunk/netsurf/gtk/Makefile.target (original)
+++ trunk/netsurf/gtk/Makefile.target Sun Aug 28 09:29:15 2011
@@ -72,5 +72,8 @@
S_GTK := $(addprefix gtk/,$(S_GTK)) $(addprefix utils/,container.c)
# code in utils/container.ch is non-universal it seems
-SOURCES := $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_PDF) $(S_GTK)
+# This is the final source build list
+# Note this is deliberately *not* expanded here as common and image
+# are not yet available
+SOURCES = $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_PDF) $(S_GTK)
EXETARGET := nsgtk
Modified: trunk/netsurf/image/bmp.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/bmp.c?rev=12673&r1=...
==============================================================================
--- trunk/netsurf/image/bmp.c (original)
+++ trunk/netsurf/image/bmp.c Sun Aug 28 09:29:15 2011
@@ -20,25 +20,24 @@
/** \file
* Content for image/bmp (implementation)
*/
-
-#include "utils/config.h"
-#ifdef WITH_BMP
#include <assert.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <libnsbmp.h>
+
#include "utils/config.h"
#include "content/content_protected.h"
#include "content/hlcache.h"
#include "desktop/plotters.h"
-#include "image/bitmap.h"
-#include "image/bmp.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/talloc.h"
#include "utils/utils.h"
+
+#include "image/bitmap.h"
+#include "image/bmp.h"
typedef struct nsbmp_content {
struct content base;
@@ -275,5 +274,3 @@
};
CONTENT_FACTORY_REGISTER_TYPES(nsbmp, nsbmp_types, nsbmp_content_handler);
-
-#endif
Modified: trunk/netsurf/image/bmp.h
URL: http://source.netsurf-browser.org/trunk/netsurf/image/bmp.h?rev=12673&r1=...
==============================================================================
--- trunk/netsurf/image/bmp.h (original)
+++ trunk/netsurf/image/bmp.h Sun Aug 28 09:29:15 2011
@@ -24,11 +24,8 @@
#ifndef _NETSURF_IMAGE_BMP_H_
#define _NETSURF_IMAGE_BMP_H_
-#include "utils/config.h"
-#ifdef WITH_BMP
+#include <libnsbmp.h>
-#include <stdbool.h>
-#include <libnsbmp.h>
#include "image/bitmap.h"
extern bmp_bitmap_callback_vt bmp_bitmap_callbacks; /** Only to be used by ICO code. */
@@ -36,11 +33,4 @@
nserror nsbmp_init(void);
void nsbmp_fini(void);
-#else
-
-#define nsbmp_init() NSERROR_OK
-#define nsbmp_fini() ((void) 0)
-
-#endif /* WITH_BMP */
-
#endif
Modified: trunk/netsurf/image/gif.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/gif.c?rev=12673&r1=...
==============================================================================
--- trunk/netsurf/image/gif.c (original)
+++ trunk/netsurf/image/gif.c Sun Aug 28 09:29:15 2011
@@ -27,9 +27,6 @@
*
* [rjw] - Sun 4th April 2004
*/
-
-#include "utils/config.h"
-#ifdef WITH_GIF
#include <assert.h>
#include <string.h>
@@ -425,5 +422,3 @@
};
CONTENT_FACTORY_REGISTER_TYPES(nsgif, nsgif_types, nsgif_content_handler);
-
-#endif
Modified: trunk/netsurf/image/gif.h
URL: http://source.netsurf-browser.org/trunk/netsurf/image/gif.h?rev=12673&r1=...
==============================================================================
--- trunk/netsurf/image/gif.h (original)
+++ trunk/netsurf/image/gif.h Sun Aug 28 09:29:15 2011
@@ -24,20 +24,7 @@
#ifndef _NETSURF_IMAGE_GIF_H_
#define _NETSURF_IMAGE_GIF_H_
-#include "utils/config.h"
-#ifdef WITH_GIF
-
-#include <stdbool.h>
-#include <libnsgif.h>
-
nserror nsgif_init(void);
void nsgif_fini(void);
-#else
-
-#define nsgif_init() NSERROR_OK
-#define nsgif_fini() ((void) 0)
-
-#endif /* WITH_GIF */
-
#endif
Modified: trunk/netsurf/image/ico.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/ico.c?rev=12673&r1=...
==============================================================================
--- trunk/netsurf/image/ico.c (original)
+++ trunk/netsurf/image/ico.c Sun Aug 28 09:29:15 2011
@@ -19,9 +19,6 @@
/** \file
* Content for image/ico (implementation)
*/
-
-#include "utils/config.h"
-#ifdef WITH_BMP
#include <assert.h>
#include <string.h>
@@ -237,5 +234,3 @@
};
CONTENT_FACTORY_REGISTER_TYPES(nsico, nsico_types, nsico_content_handler);
-
-#endif
Modified: trunk/netsurf/image/ico.h
URL: http://source.netsurf-browser.org/trunk/netsurf/image/ico.h?rev=12673&r1=...
==============================================================================
--- trunk/netsurf/image/ico.h (original)
+++ trunk/netsurf/image/ico.h Sun Aug 28 09:29:15 2011
@@ -23,22 +23,7 @@
#ifndef _NETSURF_IMAGE_ICO_H_
#define _NETSURF_IMAGE_ICO_H_
-#include "utils/config.h"
-#ifdef WITH_BMP
-
-#include <stdbool.h>
-#include <libnsbmp.h>
-
-#include "utils/errors.h"
-
nserror nsico_init(void);
void nsico_fini(void);
-#else
-
-#define nsico_init() NSERROR_OK
-#define nsico_fini() ((void) 0)
-
-#endif /* WITH_BMP */
-
#endif
Modified: trunk/netsurf/image/image.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/image.c?rev=12673&r...
==============================================================================
--- trunk/netsurf/image/image.c (original)
+++ trunk/netsurf/image/image.c Sun Aug 28 09:29:15 2011
@@ -16,8 +16,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+
+#include "utils/errors.h"
+
#include "image/image.h"
-
#include "image/bmp.h"
#include "image/gif.h"
#include "image/ico.h"
@@ -29,6 +34,8 @@
#include "image/svg.h"
#include "image/webp.h"
+#include "utils/config.h"
+
/**
* Initialise image content handlers
*
@@ -38,49 +45,70 @@
{
nserror error;
+#ifdef WITH_BMP
error = nsbmp_init();
if (error != NSERROR_OK)
return error;
+#endif
+#ifdef WITH_GIF
error = nsgif_init();
if (error != NSERROR_OK)
return error;
+#endif
+#ifdef WITH_BMP
error = nsico_init();
if (error != NSERROR_OK)
return error;
+#endif
+#ifdef WITH_JPEG
error = nsjpeg_init();
if (error != NSERROR_OK)
return error;
+#endif
+#ifdef WITH_MNG
error = nsmng_init();
if (error != NSERROR_OK)
return error;
- /* Prefer libpng over libmng for pngs by registering later */
error = nsjpng_init();
if (error != NSERROR_OK)
return error;
+#endif
+
+#ifdef WITH_PNG
+ /* Prefer libpng over libmng for pngs by registering later */
error = nspng_init();
if (error != NSERROR_OK)
return error;
+#endif
+#ifdef WITH_NSSPRITE
error = nssprite_init();
if (error != NSERROR_OK)
return error;
+#endif
/* Prefer rsvg over libsvgtiny for svgs */
+#ifdef WITH_NS_SVG
error = svg_init();
if (error != NSERROR_OK)
return error;
+#endif
+#ifdef WITH_RSVG
error = nsrsvg_init();
if (error != NSERROR_OK)
return error;
+#endif
+#ifdef WITH_WEBP
error = webp_init();
if (error != NSERROR_OK)
return error;
+#endif /* WITH_WEBP */
return NSERROR_OK;
}
@@ -90,16 +118,45 @@
*/
void image_fini(void)
{
+#ifdef WITH_BMP
nsbmp_fini();
+#endif
+
+#ifdef WITH_GIF
nsgif_fini();
+#endif
+
+#ifdef WITH_BMP
nsico_fini();
+#endif
+
+#ifdef WITH_JPEG
nsjpeg_fini();
+#endif
+
+#ifdef WITH_MNG
nsmng_fini();
nsjpng_fini();
+#endif
+
+#ifdef WITH_NSSPRITE
nssprite_fini();
+#endif
+
+#ifdef WITH_PNG
nspng_fini();
+#endif
+
+#ifdef WITH_RSVG
nsrsvg_fini();
+#endif
+
+#ifdef WITH_NS_SVG
svg_fini();
+#endif
+
+#ifdef WITH_WEBP
webp_fini();
+#endif
}
Modified: trunk/netsurf/image/image.h
URL: http://source.netsurf-browser.org/trunk/netsurf/image/image.h?rev=12673&r...
==============================================================================
--- trunk/netsurf/image/image.h (original)
+++ trunk/netsurf/image/image.h Sun Aug 28 09:29:15 2011
@@ -28,5 +28,4 @@
nserror image_init(void);
void image_fini(void);
-
#endif
Modified: trunk/netsurf/image/jpeg.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/jpeg.c?rev=12673&r1...
==============================================================================
--- trunk/netsurf/image/jpeg.c (original)
+++ trunk/netsurf/image/jpeg.c Sun Aug 28 09:29:15 2011
@@ -22,9 +22,6 @@
*
* This implementation uses the IJG JPEG library.
*/
-
-#include "utils/config.h"
-#ifdef WITH_JPEG
#include <assert.h>
#include <setjmp.h>
@@ -357,5 +354,3 @@
};
CONTENT_FACTORY_REGISTER_TYPES(nsjpeg, nsjpeg_types, nsjpeg_content_handler);
-
-#endif /* WITH_JPEG */
Modified: trunk/netsurf/image/jpeg.h
URL: http://source.netsurf-browser.org/trunk/netsurf/image/jpeg.h?rev=12673&r1...
==============================================================================
--- trunk/netsurf/image/jpeg.h (original)
+++ trunk/netsurf/image/jpeg.h Sun Aug 28 09:29:15 2011
@@ -23,21 +23,7 @@
#ifndef _NETSURF_IMAGE_JPEG_H_
#define _NETSURF_IMAGE_JPEG_H_
-#include "utils/config.h"
-#ifdef WITH_JPEG
-
-#include <stdbool.h>
-
-#include "utils/errors.h"
-
nserror nsjpeg_init(void);
void nsjpeg_fini(void);
-#else
-
-#define nsjpeg_init() NSERROR_OK
-#define nsjpeg_fini() ((void) 0)
-
-#endif /* WITH_JPEG */
-
#endif
Modified: trunk/netsurf/image/mng.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/mng.c?rev=12673&r1=...
==============================================================================
--- trunk/netsurf/image/mng.c (original)
+++ trunk/netsurf/image/mng.c Sun Aug 28 09:29:15 2011
@@ -20,9 +20,6 @@
* Content for image/mng, image/png, and image/jng (implementation).
*/
-#include "utils/config.h"
-#ifdef WITH_MNG
-
#include <assert.h>
#include <stdbool.h>
#include <string.h>
@@ -811,5 +808,3 @@
};
CONTENT_FACTORY_REGISTER_TYPES(nsjpng, nsjpng_types, nsjpng_content_handler);
-
-#endif
Modified: trunk/netsurf/image/mng.h
URL: http://source.netsurf-browser.org/trunk/netsurf/image/mng.h?rev=12673&r1=...
==============================================================================
--- trunk/netsurf/image/mng.h (original)
+++ trunk/netsurf/image/mng.h Sun Aug 28 09:29:15 2011
@@ -23,23 +23,10 @@
#ifndef _NETSURF_IMAGE_MNG_H_
#define _NETSURF_IMAGE_MNG_H_
-#include "utils/config.h"
-#ifdef WITH_MNG
+nserror nsmng_init(void);
+nserror nsjpng_init(void);
-#include <stdbool.h>
-
-nserror nsmng_init(void);
void nsmng_fini(void);
-nserror nsjpng_init(void);
void nsjpng_fini(void);
-#else
-
-#define nsmng_init() NSERROR_OK
-#define nsmng_fini() ((void) 0)
-#define nsjpng_init() NSERROR_OK
-#define nsjpng_fini() ((void) 0)
-
-#endif /* WITH_MNG */
-
#endif
Modified: trunk/netsurf/image/nssprite.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/nssprite.c?rev=1267...
==============================================================================
--- trunk/netsurf/image/nssprite.c (original)
+++ trunk/netsurf/image/nssprite.c Sun Aug 28 09:29:15 2011
@@ -20,9 +20,6 @@
* Content for image/x-riscos-sprite (librosprite implementation).
*
*/
-
-#include "utils/config.h"
-#ifdef WITH_NSSPRITE
#include <assert.h>
#include <string.h>
@@ -240,5 +237,3 @@
};
CONTENT_FACTORY_REGISTER_TYPES(nssprite, nssprite_types, nssprite_content_handler);
-
-#endif
Modified: trunk/netsurf/image/nssprite.h
URL: http://source.netsurf-browser.org/trunk/netsurf/image/nssprite.h?rev=1267...
==============================================================================
--- trunk/netsurf/image/nssprite.h (original)
+++ trunk/netsurf/image/nssprite.h Sun Aug 28 09:29:15 2011
@@ -23,19 +23,7 @@
#ifndef _NETSURF_NS_SPRITE_H_
#define _NETSURF_NS_SPRITE_H_
-#include "utils/config.h"
-#ifdef WITH_NSSPRITE
-
-#include <stdbool.h>
-
nserror nssprite_init(void);
void nssprite_fini(void);
-#else
-
-#define nssprite_init() NSERROR_OK
-#define nssprite_fini() ((void) 0)
-
-#endif /* WITH_NSSPRITE */
-
#endif
Modified: trunk/netsurf/image/png.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/png.c?rev=12673&r1=...
==============================================================================
--- trunk/netsurf/image/png.c (original)
+++ trunk/netsurf/image/png.c Sun Aug 28 09:29:15 2011
@@ -25,8 +25,6 @@
#include <png.h>
-#include "utils/config.h"
-
#include "desktop/plotters.h"
#include "content/content_protected.h"
@@ -38,8 +36,6 @@
#include "utils/messages.h"
#include "utils/talloc.h"
#include "utils/utils.h"
-
-#ifdef WITH_PNG
/* accommodate for old versions of libpng (beware security holes!) */
@@ -438,5 +434,3 @@
};
CONTENT_FACTORY_REGISTER_TYPES(nspng, nspng_types, nspng_content_handler);
-
-#endif
Modified: trunk/netsurf/image/png.h
URL: http://source.netsurf-browser.org/trunk/netsurf/image/png.h?rev=12673&r1=...
==============================================================================
--- trunk/netsurf/image/png.h (original)
+++ trunk/netsurf/image/png.h Sun Aug 28 09:29:15 2011
@@ -20,22 +20,7 @@
#ifndef _NETSURF_RISCOS_PNG_H_
#define _NETSURF_RISCOS_PNG_H_
-#include "utils/config.h"
-
-#ifdef WITH_PNG
-
-#include <stdbool.h>
-
-#include "utils/errors.h"
-
nserror nspng_init(void);
void nspng_fini(void);
-#else
-
-#define nspng_init() NSERROR_OK
-#define nspng_fini() ((void) 0)
-
#endif
-
-#endif
Modified: trunk/netsurf/image/rsvg.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/rsvg.c?rev=12673&r1...
==============================================================================
--- trunk/netsurf/image/rsvg.c (original)
+++ trunk/netsurf/image/rsvg.c Sun Aug 28 09:29:15 2011
@@ -27,9 +27,6 @@
* function to render it for redraw requests.
*/
-#include "utils/config.h"
-#ifdef WITH_RSVG
-
#include <stdbool.h>
#include <assert.h>
#include <string.h>
@@ -38,7 +35,6 @@
#include <librsvg/rsvg.h>
#include <librsvg/rsvg-cairo.h>
-#include "image/rsvg.h"
#include "content/content_protected.h"
#include "desktop/plotters.h"
#include "image/bitmap.h"
@@ -46,6 +42,8 @@
#include "utils/utils.h"
#include "utils/messages.h"
#include "utils/talloc.h"
+
+#include "image/rsvg.h"
typedef struct rsvg_content {
struct content base;
@@ -315,5 +313,3 @@
CONTENT_FACTORY_REGISTER_TYPES(nsrsvg, rsvg_types, rsvg_content_handler);
-
-#endif /* WITH_RSVG */
Modified: trunk/netsurf/image/rsvg.h
URL: http://source.netsurf-browser.org/trunk/netsurf/image/rsvg.h?rev=12673&r1...
==============================================================================
--- trunk/netsurf/image/rsvg.h (original)
+++ trunk/netsurf/image/rsvg.h Sun Aug 28 09:29:15 2011
@@ -23,21 +23,7 @@
#ifndef _NETSURF_IMAGE_RSVG_H_
#define _NETSURF_IMAGE_RSVG_H_
-#include "utils/config.h"
-#ifdef WITH_RSVG
-
-#include <stdbool.h>
-
-#include "utils/errors.h"
-
nserror nsrsvg_init(void);
void nsrsvg_fini(void);
-#else
-
-#define nsrsvg_init() NSERROR_OK
-#define nsrsvg_fini() ((void) 0)
-
-#endif /* WITH_RSVG */
-
#endif
Modified: trunk/netsurf/image/svg.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/svg.c?rev=12673&r1=...
==============================================================================
--- trunk/netsurf/image/svg.c (original)
+++ trunk/netsurf/image/svg.c Sun Aug 28 09:29:15 2011
@@ -20,9 +20,6 @@
* Content for image/svg (implementation).
*/
-#include "utils/config.h"
-#ifdef WITH_NS_SVG
-
#include <assert.h>
#include <string.h>
@@ -346,4 +343,4 @@
CONTENT_FACTORY_REGISTER_TYPES(svg, svg_types, svg_content_handler);
-#endif /* WITH_NS_SVG */
+
Modified: trunk/netsurf/image/svg.h
URL: http://source.netsurf-browser.org/trunk/netsurf/image/svg.h?rev=12673&r1=...
==============================================================================
--- trunk/netsurf/image/svg.h (original)
+++ trunk/netsurf/image/svg.h Sun Aug 28 09:29:15 2011
@@ -23,22 +23,7 @@
#ifndef _NETSURF_IMAGE_SVG_H_
#define _NETSURF_IMAGE_SVG_H_
-#include "utils/config.h"
-
-#ifdef WITH_NS_SVG
-
-#include <stdbool.h>
-
-#include "utils/errors.h"
-
nserror svg_init(void);
void svg_fini(void);
-#else
-
-#define svg_init() NSERROR_OK
-#define svg_fini() ((void) 0)
-
#endif
-
-#endif
Modified: trunk/netsurf/image/webp.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/webp.c?rev=12673&r1...
==============================================================================
--- trunk/netsurf/image/webp.c (original)
+++ trunk/netsurf/image/webp.c Sun Aug 28 09:29:15 2011
@@ -20,9 +20,6 @@
* Content for image/webp (libwebp implementation).
*
*/
-
-#include "utils/config.h"
-#ifdef WITH_WEBP
#include <assert.h>
#include <string.h>
@@ -211,4 +208,3 @@
CONTENT_FACTORY_REGISTER_TYPES(webp, webp_types, webp_content_handler);
-#endif
Modified: trunk/netsurf/image/webp.h
URL: http://source.netsurf-browser.org/trunk/netsurf/image/webp.h?rev=12673&r1...
==============================================================================
--- trunk/netsurf/image/webp.h (original)
+++ trunk/netsurf/image/webp.h Sun Aug 28 09:29:15 2011
@@ -23,21 +23,7 @@
#ifndef _NETSURF_WEBP_H_
#define _NETSURF_WEBP_H_
-#include "utils/config.h"
-#ifdef WITH_WEBP
-
-#include <stdbool.h>
-
-#include "utils/errors.h"
-
nserror webp_init(void);
void webp_fini(void);
-#else
-
-#define webp_init() NSERROR_OK
-#define webp_fini() ((void) 0)
-
-#endif /* WITH_WEBP */
-
#endif
Modified: trunk/netsurf/monkey/Makefile.target
URL: http://source.netsurf-browser.org/trunk/netsurf/monkey/Makefile.target?re...
==============================================================================
--- trunk/netsurf/monkey/Makefile.target (original)
+++ trunk/netsurf/monkey/Makefile.target Sun Aug 28 09:29:15 2011
@@ -61,5 +61,8 @@
S_MONKEY := $(addprefix monkey/,$(S_MONKEY))
-SOURCES := $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_PDF) $(S_MONKEY)
+# This is the final source build list
+# Note this is deliberately *not* expanded here as common and image
+# are not yet available
+SOURCES = $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_PDF) $(S_MONKEY)
EXETARGET := nsmonkey
Modified: trunk/netsurf/riscos/Makefile.target
URL: http://source.netsurf-browser.org/trunk/netsurf/riscos/Makefile.target?re...
==============================================================================
--- trunk/netsurf/riscos/Makefile.target (original)
+++ trunk/netsurf/riscos/Makefile.target Sun Aug 28 09:29:15 2011
@@ -86,8 +86,10 @@
TPL_RISCOS := $(addprefix riscos/templates/,$(TPL_RISCOS))
-# complete source file list
-SOURCES := $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_PDF) $(S_RISCOS)
+# This is the final source build list
+# Note this is deliberately *not* expanded here as common and image
+# are not yet available
+SOURCES = $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_PDF) $(S_RISCOS)
EXETARGET := !NetSurf/!RunImage$(EXEEXT)
!NetSurf/!Run$(RUNEXT): riscos/scripts/Run $(EXETARGET)
Modified: trunk/netsurf/windows/Makefile.target
URL: http://source.netsurf-browser.org/trunk/netsurf/windows/Makefile.target?r...
==============================================================================
--- trunk/netsurf/windows/Makefile.target (original)
+++ trunk/netsurf/windows/Makefile.target Sun Aug 28 09:29:15 2011
@@ -65,5 +65,8 @@
windbg.c system_colour.c
S_WINDOWS := $(addprefix windows/,$(S_WINDOWS))
+# This is the final source build list
+# Note this is deliberately *not* expanded here as common and image
+# are not yet available
SOURCES := $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_WINDOWS) $(S_RESOURCES)
EXETARGET := NetSurf.exe
11 years, 5 months
r12672 tlsa - /trunk/netsurf/desktop/scrollbar.c
by netsurf@semichrome.net
Author: tlsa
Date: Sat Aug 27 04:13:23 2011
New Revision: 12672
URL: http://source.netsurf-browser.org?rev=12672&view=rev
Log:
Make more robust. E.g. zero length scrollbars.
Modified:
trunk/netsurf/desktop/scrollbar.c
Modified: trunk/netsurf/desktop/scrollbar.c
URL: http://source.netsurf-browser.org/trunk/netsurf/desktop/scrollbar.c?rev=1...
==============================================================================
--- trunk/netsurf/desktop/scrollbar.c (original)
+++ trunk/netsurf/desktop/scrollbar.c Sat Aug 27 04:13:23 2011
@@ -105,7 +105,8 @@
scrollbar->pair_drag = false;
well_length = length - 2 * SCROLLBAR_WIDTH;
- scrollbar->bar_len = (well_length * visible_size) / full_size;
+ scrollbar->bar_len = (full_size == 0) ? 0 :
+ ((well_length * visible_size) / full_size);
scrollbar->client_callback = client_callback;
scrollbar->client_data = client_data;
@@ -467,8 +468,13 @@
if (full_size != -1)
s->full_size = full_size;
+ if (s->full_size < s->visible_size)
+ s->full_size = s->visible_size;
+
/* Update scroll offset (scaled in proportion with change in excess) */
- s->offset = (s->full_size - s->visible_size) * s->offset / cur_excess;
+ s->offset = (cur_excess < 1) ? 0 :
+ ((s->full_size - s->visible_size) * s->offset /
+ cur_excess);
well_length = s->length - 2 * SCROLLBAR_WIDTH;
11 years, 5 months
r12671 vince - in /trunk/netsurf: content/content_factory.h image/bmp.c image/gif.c image/ico.c image/image.c image/image.h image/jpeg.c image/mng.c image/mng.h image/nssprite.c image/png.c image/rsvg.c image/svg.c image/webp.c
by netsurf@semichrome.net
Author: vince
Date: Sat Aug 27 03:43:51 2011
New Revision: 12671
URL: http://source.netsurf-browser.org?rev=12671&view=rev
Log:
Initial image content handler refactor
Modified:
trunk/netsurf/content/content_factory.h
trunk/netsurf/image/bmp.c
trunk/netsurf/image/gif.c
trunk/netsurf/image/ico.c
trunk/netsurf/image/image.c
trunk/netsurf/image/image.h
trunk/netsurf/image/jpeg.c
trunk/netsurf/image/mng.c
trunk/netsurf/image/mng.h
trunk/netsurf/image/nssprite.c
trunk/netsurf/image/png.c
trunk/netsurf/image/rsvg.c
trunk/netsurf/image/svg.c
trunk/netsurf/image/webp.c
Modified: trunk/netsurf/content/content_factory.h
URL: http://source.netsurf-browser.org/trunk/netsurf/content/content_factory.h...
==============================================================================
--- trunk/netsurf/content/content_factory.h (original)
+++ trunk/netsurf/content/content_factory.h Sat Aug 27 03:43:51 2011
@@ -26,6 +26,51 @@
#include "content/content_type.h"
#include "utils/errors.h"
+#define CONTENT_FACTORY_REGISTER_TYPES(HNAME, HTYPELIST, HHANDLER) \
+ \
+static lwc_string *HNAME##_mime_types[NOF_ELEMENTS(HTYPELIST)]; \
+ \
+nserror HNAME##_init(void) \
+{ \
+ uint32_t i; \
+ lwc_error lerror; \
+ nserror error; \
+ \
+ for (i = 0; i < NOF_ELEMENTS(HNAME##_mime_types); i++) { \
+ lerror = lwc_intern_string(HTYPELIST[i], \
+ strlen(HTYPELIST[i]), \
+ &HNAME##_mime_types[i]); \
+ if (lerror != lwc_error_ok) { \
+ error = NSERROR_NOMEM; \
+ goto error; \
+ } \
+ \
+ error = content_factory_register_handler( \
+ HNAME##_mime_types[i], \
+ &HHANDLER); \
+ if (error != NSERROR_OK) \
+ goto error; \
+ } \
+ \
+ return NSERROR_OK; \
+ \
+error: \
+ HNAME##_fini(); \
+ \
+ return error; \
+} \
+ \
+void HNAME##_fini(void) \
+{ \
+ uint32_t i; \
+ \
+ for (i = 0; i < NOF_ELEMENTS(HNAME##_mime_types); i++) { \
+ if (HNAME##_mime_types[i] != NULL) { \
+ lwc_string_unref(HNAME##_mime_types[i]); \
+ } \
+ } \
+}
+
struct content;
struct llcache_handle;
Modified: trunk/netsurf/image/bmp.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/bmp.c?rev=12671&r1=...
==============================================================================
--- trunk/netsurf/image/bmp.c (original)
+++ trunk/netsurf/image/bmp.c Sat Aug 27 03:43:51 2011
@@ -46,8 +46,218 @@
bmp_image *bmp; /** BMP image data */
} nsbmp_content;
-
-
+static nserror nsbmp_create_bmp_data(nsbmp_content *bmp)
+{
+ union content_msg_data msg_data;
+
+ bmp->bmp = calloc(sizeof(struct bmp_image), 1);
+ if (bmp->bmp == NULL) {
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(&bmp->base, CONTENT_MSG_ERROR, msg_data);
+ return NSERROR_NOMEM;
+ }
+
+ bmp_create(bmp->bmp, &bmp_bitmap_callbacks);
+
+ return NSERROR_OK;
+}
+
+
+static nserror nsbmp_create(const content_handler *handler,
+ lwc_string *imime_type, const struct http_parameter *params,
+ llcache_handle *llcache, const char *fallback_charset,
+ bool quirks, struct content **c)
+{
+ nsbmp_content *bmp;
+ nserror error;
+
+ bmp = talloc_zero(0, nsbmp_content);
+ if (bmp == NULL)
+ return NSERROR_NOMEM;
+
+ error = content__init(&bmp->base, handler, imime_type, params,
+ llcache, fallback_charset, quirks);
+ if (error != NSERROR_OK) {
+ talloc_free(bmp);
+ return error;
+ }
+
+ error = nsbmp_create_bmp_data(bmp);
+ if (error != NSERROR_OK) {
+ talloc_free(bmp);
+ return error;
+ }
+
+ *c = (struct content *) bmp;
+
+ return NSERROR_OK;
+}
+
+/**
+ * Callback for libnsbmp; forwards the call to bitmap_create()
+ *
+ * \param width width of image in pixels
+ * \param height width of image in pixels
+ * \param state a flag word indicating the initial state
+ * \return an opaque struct bitmap, or NULL on memory exhaustion
+ */
+static void *nsbmp_bitmap_create(int width, int height, unsigned int bmp_state)
+{
+ unsigned int bitmap_state = BITMAP_NEW;
+
+ /* set bitmap state based on bmp state */
+ bitmap_state |= (bmp_state & BMP_OPAQUE) ? BITMAP_OPAQUE : 0;
+ bitmap_state |= (bmp_state & BMP_CLEAR_MEMORY) ?
+ BITMAP_CLEAR_MEMORY : 0;
+
+ /* return the created bitmap */
+ return bitmap_create(width, height, bitmap_state);
+}
+
+/* The Bitmap callbacks function table;
+ * necessary for interaction with nsbmplib.
+ */
+bmp_bitmap_callback_vt bmp_bitmap_callbacks = {
+ .bitmap_create = nsbmp_bitmap_create,
+ .bitmap_destroy = bitmap_destroy,
+ .bitmap_set_suspendable = bitmap_set_suspendable,
+ .bitmap_get_buffer = bitmap_get_buffer,
+ .bitmap_get_bpp = bitmap_get_bpp
+};
+
+static bool nsbmp_convert(struct content *c)
+{
+ nsbmp_content *bmp = (nsbmp_content *) c;
+ bmp_result res;
+ union content_msg_data msg_data;
+ uint32_t swidth;
+ const char *data;
+ unsigned long size;
+ char title[100];
+
+ /* set the bmp data */
+ data = content__get_source_data(c, &size);
+
+ /* analyse the BMP */
+ res = bmp_analyse(bmp->bmp, size, (unsigned char *) data);
+ switch (res) {
+ case BMP_OK:
+ break;
+ case BMP_INSUFFICIENT_MEMORY:
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+ return false;
+ case BMP_INSUFFICIENT_DATA:
+ case BMP_DATA_ERROR:
+ msg_data.error = messages_get("BadBMP");
+ content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+ return false;
+ }
+
+ /* Store our content width and description */
+ c->width = bmp->bmp->width;
+ c->height = bmp->bmp->height;
+ LOG(("BMP width %u height %u", c->width, c->height));
+ snprintf(title, sizeof(title), messages_get("BMPTitle"),
+ c->width, c->height, size);
+ content__set_title(c, title);
+ swidth = bmp->bmp->bitmap_callbacks.bitmap_get_bpp(bmp->bmp->bitmap) *
+ bmp->bmp->width;
+ c->size += (swidth * bmp->bmp->height) + 16 + 44;
+
+ /* exit as a success */
+ c->bitmap = bmp->bmp->bitmap;
+ bitmap_modified(c->bitmap);
+
+ content_set_ready(c);
+ content_set_done(c);
+
+ /* Done: update status bar */
+ content_set_status(c, "");
+ return true;
+}
+
+static bool nsbmp_redraw(struct content *c, struct content_redraw_data *data,
+ const struct rect *clip, const struct redraw_context *ctx)
+{
+ nsbmp_content *bmp = (nsbmp_content *) c;
+ bitmap_flags_t flags = BITMAPF_NONE;
+
+ if (bmp->bmp->decoded == false)
+ if (bmp_decode(bmp->bmp) != BMP_OK)
+ return false;
+
+ c->bitmap = bmp->bmp->bitmap;
+
+ if (data->repeat_x)
+ flags |= BITMAPF_REPEAT_X;
+ if (data->repeat_y)
+ flags |= BITMAPF_REPEAT_Y;
+
+ return ctx->plot->bitmap(data->x, data->y, data->width, data->height,
+ c->bitmap, data->background_colour, flags);
+}
+
+
+static void nsbmp_destroy(struct content *c)
+{
+ nsbmp_content *bmp = (nsbmp_content *) c;
+
+ bmp_finalise(bmp->bmp);
+ free(bmp->bmp);
+}
+
+
+static nserror nsbmp_clone(const struct content *old, struct content **newc)
+{
+ nsbmp_content *new_bmp;
+ nserror error;
+
+ new_bmp = talloc_zero(0, nsbmp_content);
+ if (new_bmp == NULL)
+ return NSERROR_NOMEM;
+
+ error = content__clone(old, &new_bmp->base);
+ if (error != NSERROR_OK) {
+ content_destroy(&new_bmp->base);
+ return error;
+ }
+
+ /* We "clone" the old content by replaying creation and conversion */
+ error = nsbmp_create_bmp_data(new_bmp);
+ if (error != NSERROR_OK) {
+ content_destroy(&new_bmp->base);
+ return error;
+ }
+
+ if (old->status == CONTENT_STATUS_READY ||
+ old->status == CONTENT_STATUS_DONE) {
+ if (nsbmp_convert(&new_bmp->base) == false) {
+ content_destroy(&new_bmp->base);
+ return NSERROR_CLONE_FAILED;
+ }
+ }
+
+ *newc = (struct content *) new_bmp;
+
+ return NSERROR_OK;
+}
+
+static content_type nsbmp_content_type(lwc_string *mime_type)
+{
+ return CONTENT_IMAGE;
+}
+
+
+static const content_handler nsbmp_content_handler = {
+ .create = nsbmp_create,
+ .data_complete = nsbmp_convert,
+ .destroy = nsbmp_destroy,
+ .redraw = nsbmp_redraw,
+ .clone = nsbmp_clone,
+ .type = nsbmp_content_type,
+ .no_share = false,
+};
static const char *nsbmp_types[] = {
"application/bmp",
@@ -64,258 +274,6 @@
"image/x-xbitmap"
};
-static lwc_string *nsbmp_mime_types[NOF_ELEMENTS(nsbmp_types)];
-
-static nserror nsbmp_create_bmp_data(nsbmp_content *bmp)
-{
- union content_msg_data msg_data;
-
- bmp->bmp = calloc(sizeof(struct bmp_image), 1);
- if (bmp->bmp == NULL) {
- msg_data.error = messages_get("NoMemory");
- content_broadcast(&bmp->base, CONTENT_MSG_ERROR, msg_data);
- return NSERROR_NOMEM;
- }
-
- bmp_create(bmp->bmp, &bmp_bitmap_callbacks);
-
- return NSERROR_OK;
-}
-
-
-static nserror nsbmp_create(const content_handler *handler,
- lwc_string *imime_type, const struct http_parameter *params,
- llcache_handle *llcache, const char *fallback_charset,
- bool quirks, struct content **c)
-{
- nsbmp_content *bmp;
- nserror error;
-
- bmp = talloc_zero(0, nsbmp_content);
- if (bmp == NULL)
- return NSERROR_NOMEM;
-
- error = content__init(&bmp->base, handler, imime_type, params,
- llcache, fallback_charset, quirks);
- if (error != NSERROR_OK) {
- talloc_free(bmp);
- return error;
- }
-
- error = nsbmp_create_bmp_data(bmp);
- if (error != NSERROR_OK) {
- talloc_free(bmp);
- return error;
- }
-
- *c = (struct content *) bmp;
-
- return NSERROR_OK;
-}
-
-/**
- * Callback for libnsbmp; forwards the call to bitmap_create()
- *
- * \param width width of image in pixels
- * \param height width of image in pixels
- * \param state a flag word indicating the initial state
- * \return an opaque struct bitmap, or NULL on memory exhaustion
- */
-static void *nsbmp_bitmap_create(int width, int height, unsigned int bmp_state)
-{
- unsigned int bitmap_state = BITMAP_NEW;
-
- /* set bitmap state based on bmp state */
- bitmap_state |= (bmp_state & BMP_OPAQUE) ? BITMAP_OPAQUE : 0;
- bitmap_state |= (bmp_state & BMP_CLEAR_MEMORY) ?
- BITMAP_CLEAR_MEMORY : 0;
-
- /* return the created bitmap */
- return bitmap_create(width, height, bitmap_state);
-}
-
-/* The Bitmap callbacks function table;
- * necessary for interaction with nsbmplib.
- */
-bmp_bitmap_callback_vt bmp_bitmap_callbacks = {
- .bitmap_create = nsbmp_bitmap_create,
- .bitmap_destroy = bitmap_destroy,
- .bitmap_set_suspendable = bitmap_set_suspendable,
- .bitmap_get_buffer = bitmap_get_buffer,
- .bitmap_get_bpp = bitmap_get_bpp
-};
-
-static bool nsbmp_convert(struct content *c)
-{
- nsbmp_content *bmp = (nsbmp_content *) c;
- bmp_result res;
- union content_msg_data msg_data;
- uint32_t swidth;
- const char *data;
- unsigned long size;
- char title[100];
-
- /* set the bmp data */
- data = content__get_source_data(c, &size);
-
- /* analyse the BMP */
- res = bmp_analyse(bmp->bmp, size, (unsigned char *) data);
- switch (res) {
- case BMP_OK:
- break;
- case BMP_INSUFFICIENT_MEMORY:
- msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
- return false;
- case BMP_INSUFFICIENT_DATA:
- case BMP_DATA_ERROR:
- msg_data.error = messages_get("BadBMP");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
- return false;
- }
-
- /* Store our content width and description */
- c->width = bmp->bmp->width;
- c->height = bmp->bmp->height;
- LOG(("BMP width %u height %u", c->width, c->height));
- snprintf(title, sizeof(title), messages_get("BMPTitle"),
- c->width, c->height, size);
- content__set_title(c, title);
- swidth = bmp->bmp->bitmap_callbacks.bitmap_get_bpp(bmp->bmp->bitmap) *
- bmp->bmp->width;
- c->size += (swidth * bmp->bmp->height) + 16 + 44;
-
- /* exit as a success */
- c->bitmap = bmp->bmp->bitmap;
- bitmap_modified(c->bitmap);
-
- content_set_ready(c);
- content_set_done(c);
-
- /* Done: update status bar */
- content_set_status(c, "");
- return true;
-}
-
-static bool nsbmp_redraw(struct content *c, struct content_redraw_data *data,
- const struct rect *clip, const struct redraw_context *ctx)
-{
- nsbmp_content *bmp = (nsbmp_content *) c;
- bitmap_flags_t flags = BITMAPF_NONE;
-
- if (bmp->bmp->decoded == false)
- if (bmp_decode(bmp->bmp) != BMP_OK)
- return false;
-
- c->bitmap = bmp->bmp->bitmap;
-
- if (data->repeat_x)
- flags |= BITMAPF_REPEAT_X;
- if (data->repeat_y)
- flags |= BITMAPF_REPEAT_Y;
-
- return ctx->plot->bitmap(data->x, data->y, data->width, data->height,
- c->bitmap, data->background_colour, flags);
-}
-
-
-static void nsbmp_destroy(struct content *c)
-{
- nsbmp_content *bmp = (nsbmp_content *) c;
-
- bmp_finalise(bmp->bmp);
- free(bmp->bmp);
-}
-
-
-static nserror nsbmp_clone(const struct content *old, struct content **newc)
-{
- nsbmp_content *new_bmp;
- nserror error;
-
- new_bmp = talloc_zero(0, nsbmp_content);
- if (new_bmp == NULL)
- return NSERROR_NOMEM;
-
- error = content__clone(old, &new_bmp->base);
- if (error != NSERROR_OK) {
- content_destroy(&new_bmp->base);
- return error;
- }
-
- /* We "clone" the old content by replaying creation and conversion */
- error = nsbmp_create_bmp_data(new_bmp);
- if (error != NSERROR_OK) {
- content_destroy(&new_bmp->base);
- return error;
- }
-
- if (old->status == CONTENT_STATUS_READY ||
- old->status == CONTENT_STATUS_DONE) {
- if (nsbmp_convert(&new_bmp->base) == false) {
- content_destroy(&new_bmp->base);
- return NSERROR_CLONE_FAILED;
- }
- }
-
- *newc = (struct content *) new_bmp;
-
- return NSERROR_OK;
-}
-
-static content_type nsbmp_content_type(lwc_string *mime_type)
-{
- return CONTENT_IMAGE;
-}
-
-
-static const content_handler nsbmp_content_handler = {
- .create = nsbmp_create,
- .data_complete = nsbmp_convert,
- .destroy = nsbmp_destroy,
- .redraw = nsbmp_redraw,
- .clone = nsbmp_clone,
- .type = nsbmp_content_type,
- .no_share = false,
-};
-
-nserror nsbmp_init(void)
-{
- uint32_t i;
- lwc_error lerror;
- nserror error;
-
- for (i = 0; i < NOF_ELEMENTS(nsbmp_mime_types); i++) {
- lerror = lwc_intern_string(nsbmp_types[i],
- strlen(nsbmp_types[i]),
- &nsbmp_mime_types[i]);
- if (lerror != lwc_error_ok) {
- error = NSERROR_NOMEM;
- goto error;
- }
-
- error = content_factory_register_handler(nsbmp_mime_types[i],
- &nsbmp_content_handler);
- if (error != NSERROR_OK)
- goto error;
- }
-
- return NSERROR_OK;
-
-error:
- nsbmp_fini();
-
- return error;
-}
-
-void nsbmp_fini(void)
-{
- uint32_t i;
-
- for (i = 0; i < NOF_ELEMENTS(nsbmp_mime_types); i++) {
- if (nsbmp_mime_types[i] != NULL)
- lwc_string_unref(nsbmp_mime_types[i]);
- }
-}
+CONTENT_FACTORY_REGISTER_TYPES(nsbmp, nsbmp_types, nsbmp_content_handler);
#endif
Modified: trunk/netsurf/image/gif.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/gif.c?rev=12671&r1=...
==============================================================================
--- trunk/netsurf/image/gif.c (original)
+++ trunk/netsurf/image/gif.c Sat Aug 27 03:43:51 2011
@@ -56,11 +56,6 @@
int current_frame; /**< current frame to display [0...(max-1)] */
} nsgif_content;
-static const char *nsgif_types[] = {
- "image/gif"
-};
-
-static lwc_string *nsgif_mime_types[NOF_ELEMENTS(nsgif_types)];
/**
* Callback for libnsgif; forwards the call to bitmap_create()
@@ -425,43 +420,10 @@
.no_share = false,
};
-nserror nsgif_init(void)
-{
- uint32_t i;
- lwc_error lerror;
- nserror error;
-
- for (i = 0; i < NOF_ELEMENTS(nsgif_mime_types); i++) {
- lerror = lwc_intern_string(nsgif_types[i],
- strlen(nsgif_types[i]),
- &nsgif_mime_types[i]);
- if (lerror != lwc_error_ok) {
- error = NSERROR_NOMEM;
- goto error;
- }
-
- error = content_factory_register_handler(nsgif_mime_types[i],
- &nsgif_content_handler);
- if (error != NSERROR_OK)
- goto error;
- }
-
- return NSERROR_OK;
-
-error:
- nsgif_fini();
-
- return error;
-}
-
-void nsgif_fini(void)
-{
- uint32_t i;
-
- for (i = 0; i < NOF_ELEMENTS(nsgif_mime_types); i++) {
- if (nsgif_mime_types[i] != NULL)
- lwc_string_unref(nsgif_mime_types[i]);
- }
-}
+static const char *nsgif_types[] = {
+ "image/gif"
+};
+
+CONTENT_FACTORY_REGISTER_TYPES(nsgif, nsgif_types, nsgif_content_handler);
#endif
Modified: trunk/netsurf/image/ico.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/ico.c?rev=12671&r1=...
==============================================================================
--- trunk/netsurf/image/ico.c (original)
+++ trunk/netsurf/image/ico.c Sat Aug 27 03:43:51 2011
@@ -46,16 +46,6 @@
struct ico_collection *ico; /** ICO collection data */
} nsico_content;
-static const char *nsico_types[] = {
- "application/ico",
- "application/x-ico",
- "image/ico",
- "image/vnd.microsoft.icon",
- "image/x-icon"
-};
-
-static lwc_string *nsico_mime_types[NOF_ELEMENTS(nsico_types)];
-
static nserror nsico_create_ico_data(nsico_content *c)
{
@@ -238,44 +228,14 @@
.no_share = false,
};
-
-nserror nsico_init(void)
-{
- uint32_t i;
- lwc_error lerror;
- nserror error;
-
- for (i = 0; i < NOF_ELEMENTS(nsico_mime_types); i++) {
- lerror = lwc_intern_string(nsico_types[i],
- strlen(nsico_types[i]),
- &nsico_mime_types[i]);
- if (lerror != lwc_error_ok) {
- error = NSERROR_NOMEM;
- goto error;
- }
-
- error = content_factory_register_handler(nsico_mime_types[i],
- &nsico_content_handler);
- if (error != NSERROR_OK)
- goto error;
- }
-
- return NSERROR_OK;
-
-error:
- nsico_fini();
-
- return error;
-}
-
-void nsico_fini(void)
-{
- uint32_t i;
-
- for (i = 0; i < NOF_ELEMENTS(nsico_mime_types); i++) {
- if (nsico_mime_types[i] != NULL)
- lwc_string_unref(nsico_mime_types[i]);
- }
-}
+static const char *nsico_types[] = {
+ "application/ico",
+ "application/x-ico",
+ "image/ico",
+ "image/vnd.microsoft.icon",
+ "image/x-icon"
+};
+
+CONTENT_FACTORY_REGISTER_TYPES(nsico, nsico_types, nsico_content_handler);
#endif
Modified: trunk/netsurf/image/image.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/image.c?rev=12671&r...
==============================================================================
--- trunk/netsurf/image/image.c (original)
+++ trunk/netsurf/image/image.c Sat Aug 27 03:43:51 2011
@@ -54,8 +54,12 @@
if (error != NSERROR_OK)
return error;
- /* Prefer libpng over libmng for pngs */
error = nsmng_init();
+ if (error != NSERROR_OK)
+ return error;
+
+ /* Prefer libpng over libmng for pngs by registering later */
+ error = nsjpng_init();
if (error != NSERROR_OK)
return error;
error = nspng_init();
@@ -91,6 +95,7 @@
nsico_fini();
nsjpeg_fini();
nsmng_fini();
+ nsjpng_fini();
nssprite_fini();
nspng_fini();
nsrsvg_fini();
Modified: trunk/netsurf/image/image.h
URL: http://source.netsurf-browser.org/trunk/netsurf/image/image.h?rev=12671&r...
==============================================================================
--- trunk/netsurf/image/image.h (original)
+++ trunk/netsurf/image/image.h Sat Aug 27 03:43:51 2011
@@ -28,4 +28,5 @@
nserror image_init(void);
void image_fini(void);
+
#endif
Modified: trunk/netsurf/image/jpeg.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/jpeg.c?rev=12671&r1...
==============================================================================
--- trunk/netsurf/image/jpeg.c (original)
+++ trunk/netsurf/image/jpeg.c Sat Aug 27 03:43:51 2011
@@ -65,14 +65,6 @@
struct jpeg_error_mgr pub;
jmp_buf setjmp_buffer;
};
-
-static const char *nsjpeg_types[] = {
- "image/jpeg",
- "image/jpg",
- "image/pjpeg"
-};
-
-static lwc_string *nsjpeg_mime_types[NOF_ELEMENTS(nsjpeg_types)];
static unsigned char nsjpeg_eoi[] = { 0xff, JPEG_EOI };
@@ -358,44 +350,12 @@
.no_share = false,
};
-nserror nsjpeg_init(void)
-{
- uint32_t i;
- lwc_error lerror;
- nserror error;
-
- for (i = 0; i < NOF_ELEMENTS(nsjpeg_mime_types); i++) {
- lerror = lwc_intern_string(nsjpeg_types[i],
- strlen(nsjpeg_types[i]),
- &nsjpeg_mime_types[i]);
- if (lerror != lwc_error_ok) {
- error = NSERROR_NOMEM;
- goto error;
- }
-
- error = content_factory_register_handler(nsjpeg_mime_types[i],
- &nsjpeg_content_handler);
- if (error != NSERROR_OK)
- goto error;
- }
-
- return NSERROR_OK;
-
-error:
- nsjpeg_fini();
-
- return error;
-}
-
-void nsjpeg_fini(void)
-{
- uint32_t i;
-
- for (i = 0; i < NOF_ELEMENTS(nsjpeg_mime_types); i++) {
- if (nsjpeg_mime_types[i] != NULL) {
- lwc_string_unref(nsjpeg_mime_types[i]);
- }
- }
-}
+static const char *nsjpeg_types[] = {
+ "image/jpeg",
+ "image/jpg",
+ "image/pjpeg"
+};
+
+CONTENT_FACTORY_REGISTER_TYPES(nsjpeg, nsjpeg_types, nsjpeg_content_handler);
#endif /* WITH_JPEG */
Modified: trunk/netsurf/image/mng.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/mng.c?rev=12671&r1=...
==============================================================================
--- trunk/netsurf/image/mng.c (original)
+++ trunk/netsurf/image/mng.c Sat Aug 27 03:43:51 2011
@@ -41,9 +41,9 @@
#include "utils/talloc.h"
#include "utils/utils.h"
-/* We do not currently support any form of colour/gamma correction, nor do
- we support dynamic MNGs.
-*/
+/* This implementation does not currently support dynamic MNGs or any
+ * form of colour/gamma correction,
+ */
typedef struct nsmng_content
{
@@ -58,158 +58,361 @@
void *handle;
} nsmng_content;
-static nserror nsmng_create(const content_handler *handler,
- lwc_string *imime_type, const struct http_parameter *params,
- llcache_handle *llcache, const char *fallback_charset,
- bool quirks, struct content **c);
-static nserror nsmng_create_mng_data(nsmng_content *c);
-static bool nsmng_process_data(struct content *c, const char *data,
- unsigned int size);
-static bool nsmng_convert(struct content *c);
-static void nsmng_destroy(struct content *c);
-static bool nsmng_redraw(struct content *c, struct content_redraw_data *data,
- const struct rect *clip, const struct redraw_context *ctx);
-static nserror nsmng_clone(const struct content *old, struct content **newc);
-static content_type nsmng_content_type(lwc_string *mime_type);
-
-static mng_bool nsmng_openstream(mng_handle mng);
-static mng_bool nsmng_readdata(mng_handle mng, mng_ptr buffer,
- mng_uint32 size, mng_uint32 *bytesread);
-static mng_bool nsmng_closestream(mng_handle mng);
+
+#ifndef MNG_INTERNAL_MEMMNGMT
+
+/**
+ * Memory allocation callback for libmng.
+ */
+
+static mng_ptr nsmng_alloc(mng_size_t n)
+{
+ return calloc(1, n);
+}
+
+
+/**
+ * Memory free callback for libmng.
+ */
+
+static void nsmng_free(mng_ptr p, mng_size_t n)
+{
+ free(p);
+}
+
+#endif
+
+/**
+ * Broadcasts an error message and returns false
+ *
+ * \param c the content to broadcast for
+ * \return Appropriate error
+ */
+static nserror nsmng_broadcast_error(nsmng_content *c, mng_retcode code)
+{
+ union content_msg_data msg_data;
+ char error[100];
+
+ assert(c != NULL);
+
+ if (code == MNG_OUTOFMEMORY) {
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ return NSERROR_NOMEM;
+ }
+
+ snprintf(error, sizeof error, messages_get("MNGError"), code);
+ msg_data.error = error;
+ content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ return NSERROR_MNG_ERROR;
+}
+
+/* CALLBACKS REQUIRED FOR libmng READING */
+
+static mng_bool nsmng_openstream(mng_handle mng)
+{
+ assert(mng != NULL);
+ return MNG_TRUE;
+}
+
+static mng_bool nsmng_readdata(mng_handle mng, mng_ptr buffer, mng_uint32 size,
+ mng_uint32 *bytesread)
+{
+ nsmng_content *c;
+ const char *data;
+ unsigned long data_size;
+
+ assert(mng != NULL);
+ assert(buffer != NULL);
+ assert(bytesread != NULL);
+
+ /* Get our content back
+ */
+ c = (nsmng_content *) mng_get_userdata(mng);
+ assert(c != NULL);
+
+ /* Copy any data we have (maximum of 'size')
+ */
+ data = content__get_source_data(&c->base, &data_size);
+
+ *bytesread = ((data_size - c->read_size) < size) ?
+ (data_size - c->read_size) : size;
+
+ if ((*bytesread) > 0) {
+ memcpy(buffer, data + c->read_size, *bytesread);
+ c->read_size += *bytesread;
+ }
+
+ /* Return success
+ */
+ return MNG_TRUE;
+}
+
+static mng_bool nsmng_closestream(mng_handle mng)
+{
+ assert(mng != NULL);
+ return MNG_TRUE;
+}
+
static mng_bool nsmng_processheader(mng_handle mng, mng_uint32 width,
- mng_uint32 height);
-static mng_ptr nsmng_getcanvasline(mng_handle mng, mng_uint32 line);
-static mng_uint32 nsmng_gettickcount(mng_handle mng);
+ mng_uint32 height)
+{
+ nsmng_content *c;
+ union content_msg_data msg_data;
+ uint8_t *buffer;
+
+ assert(mng != NULL);
+
+ /* This function is called when the header has been read and we
+ know the dimensions of the canvas.
+ */
+ c = (nsmng_content *) mng_get_userdata(mng);
+ assert(c != NULL);
+
+ c->base.bitmap = bitmap_create(width, height, BITMAP_NEW);
+ if (c->base.bitmap == NULL) {
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ LOG(("Insufficient memory to create canvas."));
+ return MNG_FALSE;
+ }
+
+ /* Get the buffer to ensure that it is allocated and the calls in
+ * nsmng_getcanvasline() succeed. */
+ buffer = bitmap_get_buffer(c->base.bitmap);
+ if (buffer == NULL) {
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ LOG(("Insufficient memory to create canvas."));
+ return MNG_FALSE;
+ }
+
+ /* Initialise the content size
+ */
+ c->base.width = width;
+ c->base.height = height;
+
+ /* Set the canvas style
+ */
+ if (mng_set_canvasstyle(mng, MNG_CANVAS_RGBA8) != MNG_NOERROR) {
+ LOG(("Error setting canvas style."));
+ }
+
+ /* Return success
+ */
+ return MNG_TRUE;
+}
+
+
+/* END OF CALLBACKS REQUIRED FOR READING
+*/
+
+
+static bool nsmng_process_data(struct content *c, const char *data, unsigned int size)
+{
+ nsmng_content *mng = (nsmng_content *) c;
+ mng_retcode status;
+
+ assert(c != NULL);
+ assert(data != NULL);
+
+ /* We only need to do any processing if we're starting/resuming reading.
+ */
+ if ((!mng->read_resume) && (!mng->read_start))
+ return true;
+
+ /* Try to start processing, or process some more data
+ */
+ if (mng->read_start) {
+ status = mng_read(mng->handle);
+ mng->read_start = false;
+ } else {
+ status = mng_read_resume(mng->handle);
+ }
+ mng->read_resume = (status == MNG_NEEDMOREDATA);
+ if ((status != MNG_NOERROR) && (status != MNG_NEEDMOREDATA)) {
+ LOG(("Failed to start/continue reading (%i).", status));
+ return nsmng_broadcast_error(mng, status) == NSERROR_OK;
+ }
+
+ /* Continue onwards
+ */
+ return true;
+}
+
+/* START OF CALLBACKS REQUIRED FOR DISPLAYING
+*/
+
+
+static mng_ptr nsmng_getcanvasline(mng_handle mng, mng_uint32 line)
+{
+ nsmng_content *c;
+
+ assert(mng != NULL);
+
+ /* Get our content back
+ */
+ c = (nsmng_content *) mng_get_userdata(mng);
+ assert(c != NULL);
+
+ /* Calculate the address
+ */
+ return bitmap_get_buffer(c->base.bitmap) +
+ bitmap_get_rowstride(c->base.bitmap) * line;
+}
+
static mng_bool nsmng_refresh(mng_handle mng, mng_uint32 x, mng_uint32 y,
- mng_uint32 w, mng_uint32 h);
-static mng_bool nsmng_settimer(mng_handle mng, mng_uint32 msecs);
-static void nsmng_animate(void *p);
-static nserror nsmng_broadcast_error(nsmng_content *c, mng_retcode code);
+ mng_uint32 w, mng_uint32 h)
+{
+ union content_msg_data data;
+ nsmng_content *c;
+
+ assert(mng != NULL);
+
+ /* Get our content back
+ */
+ c = (nsmng_content *) mng_get_userdata(mng);
+ assert(c != NULL);
+
+ /* Set the minimum redraw area
+ */
+ data.redraw.x = x;
+ data.redraw.y = y;
+ data.redraw.width = w;
+ data.redraw.height = h;
+
+ /* Set the redraw area to the whole canvas to ensure that if
+ we can redraw something to trigger animation later then we do
+ */
+/* data.redraw.x = 0;
+ data.redraw.y = 0;
+ data.redraw.width = c->width;
+ data.redraw.height = c->height;
+*/
+ /* Always redraw everything
+ */
+ data.redraw.full_redraw = true;
+
+ /* Set the object characteristics
+ */
+ data.redraw.object = &c->base;
+ data.redraw.object_x = 0;
+ data.redraw.object_y = 0;
+ data.redraw.object_width = c->base.width;
+ data.redraw.object_height = c->base.height;
+
+ /* Only attempt to force the redraw if we've been requested to
+ * display the image in the first place (i.e. nsmng_redraw has
+ * been called). This avoids the situation of forcibly redrawing
+ * an image that shouldn't be shown (e.g. if the image is a fallback
+ * for an object that can't be rendered)
+ */
+ if (c->displayed)
+ content_broadcast(&c->base, CONTENT_MSG_REDRAW, data);
+
+ return MNG_TRUE;
+}
+
+/**
+ * Animates to the next frame
+ */
+static void nsmng_animate(void *p)
+{
+ nsmng_content *c;
+
+ assert(p != NULL);
+
+ c = (nsmng_content *) p;
+
+ /* If we used the last animation we advance, if not we try again later
+ */
+ if (c->base.user_list->next == NULL) {
+ c->waiting = true;
+ } else {
+ c->waiting = false;
+ mng_display_resume(c->handle);
+ c->opaque_test_pending = true;
+ if (c->base.bitmap)
+ bitmap_modified(c->base.bitmap);
+ }
+}
+
+static mng_bool nsmng_settimer(mng_handle mng, mng_uint32 msecs)
+{
+ nsmng_content *c;
+
+ assert(mng != NULL);
+
+ /* Get our content back
+ */
+ c = (nsmng_content *) mng_get_userdata(mng);
+ assert(c != NULL);
+
+ /* Perform the scheduling
+ */
+ schedule(msecs / 10, nsmng_animate, c);
+ return MNG_TRUE;
+}
+
+/**
+ * Get the wall-clock time in milliseconds since some fixed time.
+ */
+
+static mng_uint32 nsmng_gettickcount(mng_handle mng)
+{
+ static bool start = true;
+ static time_t t0;
+ struct timeval tv;
+#if defined(__SVR4) && defined(__sun) || defined(__NetBSD__) || \
+ defined(__APPLE__)
+ /* Solaris, NetBSD, and OS X don't have this structure, and ignore the
+ * second parameter to gettimeofday()
+ */
+ int tz;
+#else
+ struct timezone tz;
+#endif
+ assert(mng != NULL);
+
+ gettimeofday(&tv, &tz);
+ if (start) {
+ t0 = tv.tv_sec;
+ start = false;
+ }
+
+ return (tv.tv_sec - t0) * 1000 + tv.tv_usec / 1000;
+}
+
+/* END OF CALLBACKS REQUIRED FOR DISPLAYING
+*/
+
static mng_bool nsmng_errorproc(mng_handle mng, mng_int32 code,
- mng_int8 severity, mng_chunkid chunktype, mng_uint32 chunkseq,
- mng_int32 extra1, mng_int32 extra2, mng_pchar text);
-#ifndef MNG_INTERNAL_MEMMNGMT
-static mng_ptr nsmng_alloc(mng_size_t n);
-static void nsmng_free(mng_ptr p, mng_size_t n);
-#endif
-
-static const content_handler nsmng_content_handler = {
- .create = nsmng_create,
- .process_data = nsmng_process_data,
- .data_complete = nsmng_convert,
- .destroy = nsmng_destroy,
- .redraw = nsmng_redraw,
- .clone = nsmng_clone,
- .type = nsmng_content_type,
- .no_share = false,
-};
-
-static const char *jng_types[] = {
- "image/jng",
- "image/x-jng"
-};
-
-static const char *mng_types[] = {
- "image/mng",
- "image/x-mng",
- "video/mng",
- "video/x-mng"
-};
-
-static const char *png_types[] = {
- "image/png"
-};
-
-static lwc_string *jng_mime_types[NOF_ELEMENTS(jng_types)];
-static lwc_string *mng_mime_types[NOF_ELEMENTS(mng_types)];
-static lwc_string *png_mime_types[NOF_ELEMENTS(png_types)];
-
-nserror nsmng_init(void)
-{
- uint32_t i;
- lwc_error lerror;
- nserror error;
-
-#define register_types(type) \
- for (i = 0; i < NOF_ELEMENTS(type##_mime_types); i++) { \
- lerror = lwc_intern_string(type##_types[i], \
- strlen(type##_types[i]), \
- &type##_mime_types[i]); \
- if (lerror != lwc_error_ok) { \
- error = NSERROR_NOMEM; \
- goto error; \
- } \
- \
- error = content_factory_register_handler( \
- type##_mime_types[i], \
- &nsmng_content_handler); \
- if (error != NSERROR_OK) \
- goto error; \
- }
-
- register_types(jng)
- register_types(mng)
- register_types(png)
-
- return NSERROR_OK;
-
-error:
- nsmng_fini();
-
- return error;
-}
-
-void nsmng_fini(void)
-{
- uint32_t i;
-
- for (i = 0; i < NOF_ELEMENTS(jng_mime_types); i++) {
- if (jng_mime_types[i] != NULL)
- lwc_string_unref(jng_mime_types[i]);
- }
-
- for (i = 0; i < NOF_ELEMENTS(mng_mime_types); i++) {
- if (mng_mime_types[i] != NULL)
- lwc_string_unref(mng_mime_types[i]);
- }
-
- for (i = 0; i < NOF_ELEMENTS(png_mime_types); i++) {
- if (png_mime_types[i] != NULL)
- lwc_string_unref(png_mime_types[i]);
- }
-}
-
-nserror nsmng_create(const content_handler *handler,
- lwc_string *imime_type, const struct http_parameter *params,
- llcache_handle *llcache, const char *fallback_charset,
- bool quirks, struct content **c)
-{
- nsmng_content *mng;
- nserror error;
-
- mng = talloc_zero(0, nsmng_content);
- if (mng == NULL)
- return NSERROR_NOMEM;
-
- error = content__init(&mng->base, handler, imime_type, params,
- llcache, fallback_charset, quirks);
- if (error != NSERROR_OK) {
- talloc_free(mng);
- return error;
- }
-
- error = nsmng_create_mng_data(mng);
- if (error != NSERROR_OK) {
- talloc_free(mng);
- return error;
- }
-
- *c = (struct content *) mng;
-
- return NSERROR_OK;
-}
-
-nserror nsmng_create_mng_data(nsmng_content *c)
+ mng_int8 severity, mng_chunkid chunktype, mng_uint32 chunkseq,
+ mng_int32 extra1, mng_int32 extra2, mng_pchar text)
+{
+ nsmng_content *c;
+ char chunk[5];
+
+ assert(mng != NULL);
+
+ c = (nsmng_content *) mng_get_userdata(mng);
+ assert(c != NULL);
+
+ chunk[0] = (char)((chunktype >> 24) & 0xFF);
+ chunk[1] = (char)((chunktype >> 16) & 0xFF);
+ chunk[2] = (char)((chunktype >> 8) & 0xFF);
+ chunk[3] = (char)((chunktype ) & 0xFF);
+ chunk[4] = '\0';
+
+ LOG(("error playing '%s' chunk %s (%d):",
+ content__get_url(&c->base), chunk, chunkseq));
+ LOG(("code %d severity %d extra1 %d extra2 %d text:'%s'", code,
+ severity, extra1, extra2, text));
+
+ return (0);
+}
+
+static nserror nsmng_create_mng_data(nsmng_content *c)
{
mng_retcode code;
union content_msg_data msg_data;
@@ -303,152 +506,43 @@
return NSERROR_OK;
}
-
-/* START OF CALLBACKS REQUIRED FOR READING
-*/
-
-
-mng_bool nsmng_openstream(mng_handle mng)
-{
- assert(mng != NULL);
- return MNG_TRUE;
-}
-
-mng_bool nsmng_readdata(mng_handle mng, mng_ptr buffer, mng_uint32 size,
- mng_uint32 *bytesread)
-{
- nsmng_content *c;
- const char *data;
- unsigned long data_size;
-
- assert(mng != NULL);
- assert(buffer != NULL);
- assert(bytesread != NULL);
-
- /* Get our content back
- */
- c = (nsmng_content *) mng_get_userdata(mng);
- assert(c != NULL);
-
- /* Copy any data we have (maximum of 'size')
- */
- data = content__get_source_data(&c->base, &data_size);
-
- *bytesread = ((data_size - c->read_size) < size) ?
- (data_size - c->read_size) : size;
-
- if ((*bytesread) > 0) {
- memcpy(buffer, data + c->read_size, *bytesread);
- c->read_size += *bytesread;
- }
-
- /* Return success
- */
- return MNG_TRUE;
-}
-
-mng_bool nsmng_closestream(mng_handle mng)
-{
- assert(mng != NULL);
- return MNG_TRUE;
-}
-
-mng_bool nsmng_processheader(mng_handle mng, mng_uint32 width,
- mng_uint32 height)
-{
- nsmng_content *c;
- union content_msg_data msg_data;
- uint8_t *buffer;
-
- assert(mng != NULL);
-
- /* This function is called when the header has been read and we
- know the dimensions of the canvas.
- */
- c = (nsmng_content *) mng_get_userdata(mng);
- assert(c != NULL);
-
- c->base.bitmap = bitmap_create(width, height, BITMAP_NEW);
- if (c->base.bitmap == NULL) {
- msg_data.error = messages_get("NoMemory");
- content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
- LOG(("Insufficient memory to create canvas."));
- return MNG_FALSE;
- }
-
- /* Get the buffer to ensure that it is allocated and the calls in
- * nsmng_getcanvasline() succeed. */
- buffer = bitmap_get_buffer(c->base.bitmap);
- if (buffer == NULL) {
- msg_data.error = messages_get("NoMemory");
- content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
- LOG(("Insufficient memory to create canvas."));
- return MNG_FALSE;
- }
-
- /* Initialise the content size
- */
- c->base.width = width;
- c->base.height = height;
-
- /* Set the canvas style
- */
- if (mng_set_canvasstyle(mng, MNG_CANVAS_RGBA8) != MNG_NOERROR) {
- LOG(("Error setting canvas style."));
- }
-
- /* Return success
- */
- return MNG_TRUE;
-}
-
-
-/* END OF CALLBACKS REQUIRED FOR READING
-*/
-
-
-bool nsmng_process_data(struct content *c, const char *data, unsigned int size)
-{
- nsmng_content *mng = (nsmng_content *) c;
- mng_retcode status;
-
- assert(c != NULL);
- assert(data != NULL);
-
- /* We only need to do any processing if we're starting/resuming reading.
- */
- if ((!mng->read_resume) && (!mng->read_start))
- return true;
-
- /* Try to start processing, or process some more data
- */
- if (mng->read_start) {
- status = mng_read(mng->handle);
- mng->read_start = false;
- } else {
- status = mng_read_resume(mng->handle);
- }
- mng->read_resume = (status == MNG_NEEDMOREDATA);
- if ((status != MNG_NOERROR) && (status != MNG_NEEDMOREDATA)) {
- LOG(("Failed to start/continue reading (%i).", status));
- return nsmng_broadcast_error(mng, status) == NSERROR_OK;
- }
-
- /* Continue onwards
- */
- return true;
-}
-
-
-bool nsmng_convert(struct content *c)
+static nserror nsmng_create(const content_handler *handler,
+ lwc_string *imime_type, const struct http_parameter *params,
+ llcache_handle *llcache, const char *fallback_charset,
+ bool quirks, struct content **c)
+{
+ nsmng_content *mng;
+ nserror error;
+
+ mng = talloc_zero(0, nsmng_content);
+ if (mng == NULL)
+ return NSERROR_NOMEM;
+
+ error = content__init(&mng->base, handler, imime_type, params,
+ llcache, fallback_charset, quirks);
+ if (error != NSERROR_OK) {
+ talloc_free(mng);
+ return error;
+ }
+
+ error = nsmng_create_mng_data(mng);
+ if (error != NSERROR_OK) {
+ talloc_free(mng);
+ return error;
+ }
+
+ *c = (struct content *) mng;
+
+ return NSERROR_OK;
+}
+
+
+
+static bool nsmng_convert(struct content *c)
{
nsmng_content *mng = (nsmng_content *) c;
mng_retcode status;
unsigned long size;
- lwc_string *content_type;
- bool match;
- bool is_mng = false;
- uint32_t i;
char title[100];
assert(c != NULL);
@@ -458,35 +552,16 @@
/* by this point, the png should have been parsed
* and the bitmap created, so ensure that's the case
*/
- if (content__get_bitmap(c) == NULL)
+ if (content__get_bitmap(c) == NULL) {
return nsmng_broadcast_error(mng, -1) == NSERROR_OK;
+ }
/* Set the title
*/
- content_type = content__get_mime_type(c);
-
- for (i = 0; i < NOF_ELEMENTS(mng_mime_types); i++) {
- if (lwc_string_caseless_isequal(content_type, mng_mime_types[i],
- &match) == lwc_error_ok && match) {
- is_mng = true;
- break;
- }
- }
-
- if (is_mng) {
- snprintf(title, sizeof(title), messages_get("MNGTitle"),
- c->width, c->height, size);
- } else if (lwc_string_caseless_isequal(content_type, png_mime_types[0],
- &match) == lwc_error_ok && match) {
- snprintf(title, sizeof(title), messages_get("PNGTitle"),
- c->width, c->height, size);
- } else {
- snprintf(title, sizeof(title), messages_get("JNGTitle"),
- c->width, c->height, size);
- }
+ snprintf(title, sizeof(title),
+ messages_get("MNGTitle"),
+ c->width, c->height, size);
content__set_title(c, title);
-
- lwc_string_unref(content_type);
c->size += c->width * c->height * 4;
content_set_ready(c);
@@ -515,153 +590,80 @@
}
bitmap_modified(c->bitmap);
+ /* Optimise the plotting of MNG */
+ mng->opaque_test_pending = false;
+
+ return true;
+}
+
+static bool nsjpng_convert(struct content *c)
+{
+ nsmng_content *mng = (nsmng_content *) c;
+ mng_retcode status;
+ unsigned long size;
+ char title[100];
+
+ assert(c != NULL);
+
+ content__get_source_data(c, &size);
+
+ /* by this point, the png should have been parsed
+ * and the bitmap created, so ensure that's the case
+ */
+ if (content__get_bitmap(c) == NULL) {
+ return nsmng_broadcast_error(mng, -1) == NSERROR_OK;
+ }
+
+ /* Set the title */
+ snprintf(title, sizeof(title),
+ messages_get("PNGTitle"),
+ c->width, c->height, size);
+ content__set_title(c, title);
+
+ c->size += c->width * c->height * 4;
+ content_set_ready(c);
+ content_set_done(c);
+ /* Done: update status bar */
+ content_set_status(c, "");
+
+ /* jmb: I'm really not sure that this should be here.
+ * The *_convert functions are for converting a content into a
+ * displayable format. They should not, however, do anything which
+ * could cause the content to be displayed; the content may have
+ * hidden visibility or be a fallback for an object; this
+ * information is not available here (nor is there any need for it
+ * to be).
+ * The specific issue here is that mng_display calls the display
+ * callbacks, which include nsmng_refresh. nsmng_refresh forces
+ * a content to be redrawn regardless of whether it should be
+ * displayed or not.
+ */
+ /* Start displaying
+ */
+ status = mng_display(mng->handle);
+ if ((status != MNG_NOERROR) && (status != MNG_NEEDTIMERWAIT)) {
+ LOG(("Unable to start display (%i)", status));
+ return nsmng_broadcast_error(mng, status) == NSERROR_OK;
+ }
+ bitmap_modified(c->bitmap);
+
/* Optimise the plotting of JNG/PNGs
*/
- mng->opaque_test_pending = (is_mng == false);
- if (mng->opaque_test_pending)
- bitmap_set_opaque(c->bitmap, false);
-
- /* free associated memory except for mngs where it may be subsequently needed for
- * animation decoding. */
- if (is_mng == false) {
- mng_handle handle = mng->handle;
-
- mng_cleanup(&handle);
-
- mng->handle = NULL;
- }
+ mng->opaque_test_pending = true;
+ bitmap_set_opaque(c->bitmap, false);
+
+ /* free associated memory */
+
+ mng_handle handle = mng->handle;
+
+ mng_cleanup(&handle);
+
+ mng->handle = NULL;
return true;
}
-
-/* START OF CALLBACKS REQUIRED FOR DISPLAYING
-*/
-
-
-mng_ptr nsmng_getcanvasline(mng_handle mng, mng_uint32 line)
-{
- nsmng_content *c;
-
- assert(mng != NULL);
-
- /* Get our content back
- */
- c = (nsmng_content *) mng_get_userdata(mng);
- assert(c != NULL);
-
- /* Calculate the address
- */
- return bitmap_get_buffer(c->base.bitmap) +
- bitmap_get_rowstride(c->base.bitmap) * line;
-}
-
-
-/**
- * Get the wall-clock time in milliseconds since some fixed time.
- */
-
-mng_uint32 nsmng_gettickcount(mng_handle mng)
-{
- static bool start = true;
- static time_t t0;
- struct timeval tv;
-#if defined(__SVR4) && defined(__sun) || defined(__NetBSD__) || \
- defined(__APPLE__)
- /* Solaris, NetBSD, and OS X don't have this structure, and ignore the
- * second parameter to gettimeofday()
- */
- int tz;
-#else
- struct timezone tz;
-#endif
- assert(mng != NULL);
-
- gettimeofday(&tv, &tz);
- if (start) {
- t0 = tv.tv_sec;
- start = false;
- }
-
- return (tv.tv_sec - t0) * 1000 + tv.tv_usec / 1000;
-}
-
-
-mng_bool nsmng_refresh(mng_handle mng, mng_uint32 x, mng_uint32 y,
- mng_uint32 w, mng_uint32 h)
-{
- union content_msg_data data;
- nsmng_content *c;
-
- assert(mng != NULL);
-
- /* Get our content back
- */
- c = (nsmng_content *) mng_get_userdata(mng);
- assert(c != NULL);
-
- /* Set the minimum redraw area
- */
- data.redraw.x = x;
- data.redraw.y = y;
- data.redraw.width = w;
- data.redraw.height = h;
-
- /* Set the redraw area to the whole canvas to ensure that if
- we can redraw something to trigger animation later then we do
- */
-/* data.redraw.x = 0;
- data.redraw.y = 0;
- data.redraw.width = c->width;
- data.redraw.height = c->height;
-*/
- /* Always redraw everything
- */
- data.redraw.full_redraw = true;
-
- /* Set the object characteristics
- */
- data.redraw.object = &c->base;
- data.redraw.object_x = 0;
- data.redraw.object_y = 0;
- data.redraw.object_width = c->base.width;
- data.redraw.object_height = c->base.height;
-
- /* Only attempt to force the redraw if we've been requested to
- * display the image in the first place (i.e. nsmng_redraw has
- * been called). This avoids the situation of forcibly redrawing
- * an image that shouldn't be shown (e.g. if the image is a fallback
- * for an object that can't be rendered)
- */
- if (c->displayed)
- content_broadcast(&c->base, CONTENT_MSG_REDRAW, data);
-
- return MNG_TRUE;
-}
-
-mng_bool nsmng_settimer(mng_handle mng, mng_uint32 msecs)
-{
- nsmng_content *c;
-
- assert(mng != NULL);
-
- /* Get our content back
- */
- c = (nsmng_content *) mng_get_userdata(mng);
- assert(c != NULL);
-
- /* Perform the scheduling
- */
- schedule(msecs / 10, nsmng_animate, c);
- return MNG_TRUE;
-}
-
-
-/* END OF CALLBACKS REQUIRED FOR DISPLAYING
-*/
-
-
-void nsmng_destroy(struct content *c)
+static void nsmng_destroy(struct content *c)
{
nsmng_content *mng = (nsmng_content *) c;
@@ -684,7 +686,7 @@
}
-bool nsmng_redraw(struct content *c, struct content_redraw_data *data,
+static bool nsmng_redraw(struct content *c, struct content_redraw_data *data,
const struct rect *clip, const struct redraw_context *ctx)
{
nsmng_content *mng = (nsmng_content *) c;
@@ -707,8 +709,7 @@
ret = ctx->plot->bitmap(data->x, data->y, data->width, data->height,
c->bitmap, data->background_colour, flags);
- /* Check if we need to restart the animation
- */
+ /* Check if we need to restart the animation */
if ((mng->waiting) && (option_animate_images))
nsmng_animate(c);
@@ -716,7 +717,7 @@
}
-nserror nsmng_clone(const struct content *old, struct content **newc)
+static nserror nsmng_clone(const struct content *old, struct content **newc)
{
nsmng_content *mng;
nserror error;
@@ -761,111 +762,54 @@
return NSERROR_OK;
}
-content_type nsmng_content_type(lwc_string *mime_type)
+static content_type nsmng_content_type(lwc_string *mime_type)
{
return CONTENT_IMAGE;
}
-/**
- * Animates to the next frame
- */
-void nsmng_animate(void *p)
-{
- nsmng_content *c;
-
- assert(p != NULL);
-
- c = (nsmng_content *) p;
-
- /* If we used the last animation we advance, if not we try again later
- */
- if (c->base.user_list->next == NULL) {
- c->waiting = true;
- } else {
- c->waiting = false;
- mng_display_resume(c->handle);
- c->opaque_test_pending = true;
- if (c->base.bitmap)
- bitmap_modified(c->base.bitmap);
- }
-}
-
-
-
-/**
- * Broadcasts an error message and returns false
- *
- * \param c the content to broadcast for
- * \return Appropriate error
- */
-nserror nsmng_broadcast_error(nsmng_content *c, mng_retcode code)
-{
- union content_msg_data msg_data;
- char error[100];
-
- assert(c != NULL);
-
- if (code == MNG_OUTOFMEMORY) {
- msg_data.error = messages_get("NoMemory");
- content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
- return NSERROR_NOMEM;
- }
-
- snprintf(error, sizeof error, messages_get("MNGError"), code);
- msg_data.error = error;
- content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
- return NSERROR_MNG_ERROR;
-}
-
-
-mng_bool nsmng_errorproc(mng_handle mng, mng_int32 code,
- mng_int8 severity, mng_chunkid chunktype, mng_uint32 chunkseq,
- mng_int32 extra1, mng_int32 extra2, mng_pchar text)
-{
- nsmng_content *c;
- char chunk[5];
-
- assert(mng != NULL);
-
- c = (nsmng_content *) mng_get_userdata(mng);
- assert(c != NULL);
-
- chunk[0] = (char)((chunktype >> 24) & 0xFF);
- chunk[1] = (char)((chunktype >> 16) & 0xFF);
- chunk[2] = (char)((chunktype >> 8) & 0xFF);
- chunk[3] = (char)((chunktype ) & 0xFF);
- chunk[4] = '\0';
-
- LOG(("error playing '%s' chunk %s (%d):",
- content__get_url(&c->base), chunk, chunkseq));
- LOG(("code %d severity %d extra1 %d extra2 %d text:'%s'", code,
- severity, extra1, extra2, text));
-
- return (0);
-}
-
-
-#ifndef MNG_INTERNAL_MEMMNGMT
-
-/**
- * Memory allocation callback for libmng.
- */
-
-mng_ptr nsmng_alloc(mng_size_t n)
-{
- return calloc(1, n);
-}
-
-
-/**
- * Memory free callback for libmng.
- */
-
-void nsmng_free(mng_ptr p, mng_size_t n)
-{
- free(p);
-}
+/* register handler for mng types */
+static const content_handler nsmng_content_handler = {
+ .create = nsmng_create,
+ .process_data = nsmng_process_data,
+ .data_complete = nsmng_convert,
+ .destroy = nsmng_destroy,
+ .redraw = nsmng_redraw,
+ .clone = nsmng_clone,
+ .type = nsmng_content_type,
+ .no_share = false,
+};
+
+static const char *nsmng_types[] = {
+ /* MNG types*/
+ "image/mng",
+ "image/x-mng",
+ "video/mng",
+ "video/x-mng",
+};
+
+CONTENT_FACTORY_REGISTER_TYPES(nsmng, nsmng_types, nsmng_content_handler);
+
+/* register handler for jng and png types */
+static const content_handler nsjpng_content_handler = {
+ .create = nsmng_create,
+ .process_data = nsmng_process_data,
+ .data_complete = nsjpng_convert,
+ .destroy = nsmng_destroy,
+ .redraw = nsmng_redraw,
+ .clone = nsmng_clone,
+ .type = nsmng_content_type,
+ .no_share = false,
+};
+
+
+static const char *nsjpng_types[] = {
+ /* JNG types*/
+ "image/jng",
+ "image/x-jng",
+ /* PNG types*/
+ "image/png"
+};
+
+CONTENT_FACTORY_REGISTER_TYPES(nsjpng, nsjpng_types, nsjpng_content_handler);
#endif
-
-#endif
Modified: trunk/netsurf/image/mng.h
URL: http://source.netsurf-browser.org/trunk/netsurf/image/mng.h?rev=12671&r1=...
==============================================================================
--- trunk/netsurf/image/mng.h (original)
+++ trunk/netsurf/image/mng.h Sat Aug 27 03:43:51 2011
@@ -30,11 +30,15 @@
nserror nsmng_init(void);
void nsmng_fini(void);
+nserror nsjpng_init(void);
+void nsjpng_fini(void);
#else
#define nsmng_init() NSERROR_OK
#define nsmng_fini() ((void) 0)
+#define nsjpng_init() NSERROR_OK
+#define nsjpng_fini() ((void) 0)
#endif /* WITH_MNG */
Modified: trunk/netsurf/image/nssprite.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/nssprite.c?rev=1267...
==============================================================================
--- trunk/netsurf/image/nssprite.c (original)
+++ trunk/netsurf/image/nssprite.c Sat Aug 27 03:43:51 2011
@@ -44,16 +44,6 @@
struct rosprite_area* sprite_area;
} nssprite_content;
-static nserror nssprite_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 nssprite_convert(struct content *c);
-static void nssprite_destroy(struct content *c);
-static bool nssprite_redraw(struct content *c, struct content_redraw_data *data,
- const struct rect *clip, const struct redraw_context *ctx);
-static nserror nssprite_clone(const struct content *old, struct content **newc);
-static content_type nssprite_content_type(lwc_string *mime_type);
#define ERRCHK(x) do { \
rosprite_error err = x; \
@@ -69,62 +59,10 @@
} \
} while(0)
-static const content_handler nssprite_content_handler = {
- .create = nssprite_create,
- .data_complete = nssprite_convert,
- .destroy = nssprite_destroy,
- .redraw = nssprite_redraw,
- .clone = nssprite_clone,
- .type = nssprite_content_type,
- .no_share = false,
-};
-
-static const char *nssprite_types[] = {
- "image/x-riscos-sprite"
-};
-
-static lwc_string *nssprite_mime_types[NOF_ELEMENTS(nssprite_types)];
-
-nserror nssprite_init(void)
-{
- uint32_t i;
- lwc_error lerror;
- nserror error;
-
- for (i = 0; i < NOF_ELEMENTS(nssprite_mime_types); i++) {
- lerror = lwc_intern_string(nssprite_types[i],
- strlen(nssprite_types[i]),
- &nssprite_mime_types[i]);
- if (lerror != lwc_error_ok) {
- error = NSERROR_NOMEM;
- goto error;
- }
-
- error = content_factory_register_handler(nssprite_mime_types[i],
- &nssprite_content_handler);
- if (error != NSERROR_OK)
- goto error;
- }
-
- return NSERROR_OK;
-
-error:
- nssprite_fini();
-
- return error;
-}
-
-void nssprite_fini(void)
-{
- uint32_t i;
-
- for (i = 0; i < NOF_ELEMENTS(nssprite_mime_types); i++) {
- if (nssprite_mime_types[i] != NULL)
- lwc_string_unref(nssprite_mime_types[i]);
- }
-}
-
-nserror nssprite_create(const content_handler *handler,
+
+
+
+static nserror nssprite_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)
@@ -154,7 +92,7 @@
* No conversion is necessary. We merely read the sprite dimensions.
*/
-bool nssprite_convert(struct content *c)
+static bool nssprite_convert(struct content *c)
{
nssprite_content *nssprite = (nssprite_content *) c;
union content_msg_data msg_data;
@@ -223,7 +161,7 @@
* Destroy a CONTENT_SPRITE and free all resources it owns.
*/
-void nssprite_destroy(struct content *c)
+static void nssprite_destroy(struct content *c)
{
nssprite_content *sprite = (nssprite_content *) c;
@@ -238,7 +176,7 @@
* Redraw a CONTENT_SPRITE.
*/
-bool nssprite_redraw(struct content *c, struct content_redraw_data *data,
+static bool nssprite_redraw(struct content *c, struct content_redraw_data *data,
const struct rect *clip, const struct redraw_context *ctx)
{
bitmap_flags_t flags = BITMAPF_NONE;
@@ -253,7 +191,7 @@
}
-nserror nssprite_clone(const struct content *old, struct content **newc)
+static nserror nssprite_clone(const struct content *old, struct content **newc)
{
nssprite_content *sprite;
nserror error;
@@ -282,9 +220,25 @@
return NSERROR_OK;
}
-content_type nssprite_content_type(lwc_string *mime_type)
+static content_type nssprite_content_type(lwc_string *mime_type)
{
return CONTENT_IMAGE;
}
+static const content_handler nssprite_content_handler = {
+ .create = nssprite_create,
+ .data_complete = nssprite_convert,
+ .destroy = nssprite_destroy,
+ .redraw = nssprite_redraw,
+ .clone = nssprite_clone,
+ .type = nssprite_content_type,
+ .no_share = false,
+};
+
+static const char *nssprite_types[] = {
+ "image/x-riscos-sprite"
+};
+
+CONTENT_FACTORY_REGISTER_TYPES(nssprite, nssprite_types, nssprite_content_handler);
+
#endif
Modified: trunk/netsurf/image/png.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/png.c?rev=12671&r1=...
==============================================================================
--- trunk/netsurf/image/png.c (original)
+++ trunk/netsurf/image/png.c Sat Aug 27 03:43:51 2011
@@ -62,12 +62,6 @@
size_t rowstride, bpp; /**< Bitmap rowstride and bpp */
size_t rowbytes; /**< Number of bytes per row */
} nspng_content;
-
-static const char *nspng_types[] = {
- "image/png"
-};
-
-static lwc_string *nspng_mime_types[NOF_ELEMENTS(nspng_types)];
static unsigned int interlace_start[8] = {0, 16, 0, 8, 0, 4, 0};
static unsigned int interlace_step[8] = {28, 28, 12, 12, 4, 4, 0};
@@ -439,43 +433,10 @@
.no_share = false,
};
-nserror nspng_init(void)
-{
- uint32_t i;
- lwc_error lerror;
- nserror error;
-
- for (i = 0; i < NOF_ELEMENTS(nspng_mime_types); i++) {
- lerror = lwc_intern_string(nspng_types[i],
- strlen(nspng_types[i]),
- &nspng_mime_types[i]);
- if (lerror != lwc_error_ok) {
- error = NSERROR_NOMEM;
- goto error;
- }
-
- error = content_factory_register_handler(nspng_mime_types[i],
- &nspng_content_handler);
- if (error != NSERROR_OK)
- goto error;
- }
-
- return NSERROR_OK;
-
-error:
- nspng_fini();
-
- return error;
-}
-
-void nspng_fini(void)
-{
- uint32_t i;
-
- for (i = 0; i < NOF_ELEMENTS(nspng_mime_types); i++) {
- if (nspng_mime_types[i] != NULL)
- lwc_string_unref(nspng_mime_types[i]);
- }
-}
+static const char *nspng_types[] = {
+ "image/png"
+};
+
+CONTENT_FACTORY_REGISTER_TYPES(nspng, nspng_types, nspng_content_handler);
#endif
Modified: trunk/netsurf/image/rsvg.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/rsvg.c?rev=12671&r1...
==============================================================================
--- trunk/netsurf/image/rsvg.c (original)
+++ trunk/netsurf/image/rsvg.c Sat Aug 27 03:43:51 2011
@@ -55,16 +55,6 @@
cairo_t *ct; /**< Cairo drawing context */
struct bitmap *bitmap; /**< Created NetSurf bitmap */
} rsvg_content;
-
-
-
-static const char *rsvg_types[] = {
- "image/svg",
- "image/svg+xml"
-};
-
-static lwc_string *rsvg_mime_types[NOF_ELEMENTS(rsvg_types)];
-
static nserror rsvg_create_svg_data(rsvg_content *c)
{
@@ -318,43 +308,12 @@
.no_share = false,
};
-nserror nsrsvg_init(void)
-{
- uint32_t i;
- lwc_error lerror;
- nserror error;
-
- for (i = 0; i < NOF_ELEMENTS(rsvg_mime_types); i++) {
- lerror = lwc_intern_string(rsvg_types[i],
- strlen(rsvg_types[i]),
- &rsvg_mime_types[i]);
- if (lerror != lwc_error_ok) {
- error = NSERROR_NOMEM;
- goto error;
- }
-
- error = content_factory_register_handler(rsvg_mime_types[i],
- &rsvg_content_handler);
- if (error != NSERROR_OK)
- goto error;
- }
-
- return NSERROR_OK;
-
-error:
- nsrsvg_fini();
-
- return error;
-}
-
-void nsrsvg_fini(void)
-{
- uint32_t i;
-
- for (i = 0; i < NOF_ELEMENTS(rsvg_mime_types); i++) {
- if (rsvg_mime_types[i] != NULL)
- lwc_string_unref(rsvg_mime_types[i]);
- }
-}
+static const char *rsvg_types[] = {
+ "image/svg",
+ "image/svg+xml"
+};
+
+CONTENT_FACTORY_REGISTER_TYPES(nsrsvg, rsvg_types, rsvg_content_handler);
+
#endif /* WITH_RSVG */
Modified: trunk/netsurf/image/svg.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/svg.c?rev=12671&r1=...
==============================================================================
--- trunk/netsurf/image/svg.c (original)
+++ trunk/netsurf/image/svg.c Sat Aug 27 03:43:51 2011
@@ -43,18 +43,289 @@
bool done_parse;
} svg_content;
+
+
+static nserror svg_create_svg_data(svg_content *c)
+{
+ union content_msg_data msg_data;
+
+ c->diagram = svgtiny_create();
+ if (c->diagram == NULL)
+ goto no_memory;
+
+ c->done_parse = false;
+
+ return NSERROR_OK;
+
+no_memory:
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ return NSERROR_NOMEM;
+}
+
+
+/**
+ * Create a CONTENT_SVG.
+ */
+
static nserror svg_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 nserror svg_create_svg_data(svg_content *c);
-static bool svg_convert(struct content *c);
-static void svg_destroy(struct content *c);
-static void svg_reformat(struct content *c, int width, int height);
+ bool quirks, struct content **c)
+{
+ svg_content *svg;
+ nserror error;
+
+ svg = talloc_zero(0, svg_content);
+ if (svg == NULL)
+ return NSERROR_NOMEM;
+
+ error = content__init(&svg->base, handler, imime_type, params,
+ llcache, fallback_charset, quirks);
+ if (error != NSERROR_OK) {
+ talloc_free(svg);
+ return error;
+ }
+
+ error = svg_create_svg_data(svg);
+ if (error != NSERROR_OK) {
+ talloc_free(svg);
+ return error;
+ }
+
+ *c = (struct content *) svg;
+
+ return NSERROR_OK;
+}
+
+
+
+/**
+ * Convert a CONTENT_SVG for display.
+ */
+
+static bool svg_convert(struct content *c)
+{
+ /*c->title = malloc(100);
+ if (c->title)
+ snprintf(c->title, 100, messages_get("svgTitle"),
+ width, height, c->source_size);*/
+ //c->size += ?;
+ content_set_ready(c);
+ content_set_done(c);
+ /* Done: update status bar */
+ content_set_status(c, "");
+
+ return true;
+}
+
+/**
+ * Reformat a CONTENT_SVG.
+ */
+
+static void svg_reformat(struct content *c, int width, int height)
+{
+ svg_content *svg = (svg_content *) c;
+ const char *source_data;
+ unsigned long source_size;
+
+ assert(svg->diagram);
+
+ if (svg->done_parse == false) {
+ source_data = content__get_source_data(c, &source_size);
+
+ svgtiny_parse(svg->diagram, source_data, source_size,
+ content__get_url(c), width, height);
+
+ svg->done_parse = true;
+ }
+
+ c->width = svg->diagram->width;
+ c->height = svg->diagram->height;
+}
+
+
+/**
+ * Redraw a CONTENT_SVG.
+ */
+
+static bool svg_redraw_internal(struct content *c, int x, int y,
+ int width, int height, const struct rect *clip,
+ const struct redraw_context *ctx, float scale,
+ colour background_colour)
+{
+ svg_content *svg = (svg_content *) c;
+ float transform[6];
+ struct svgtiny_diagram *diagram = svg->diagram;
+ bool ok;
+ int px, py;
+ unsigned int i;
+ plot_font_style_t fstyle = *plot_style_font;
+
+ assert(diagram);
+
+ transform[0] = (float) width / (float) c->width;
+ transform[1] = 0;
+ transform[2] = 0;
+ transform[3] = (float) height / (float) c->height;
+ transform[4] = x;
+ transform[5] = y;
+
+#define BGR(c) ((c) == svgtiny_TRANSPARENT ? NS_TRANSPARENT : \
+ ((svgtiny_RED((c))) | \
+ (svgtiny_GREEN((c)) << 8) | \
+ (svgtiny_BLUE((c)) << 16)))
+
+ for (i = 0; i != diagram->shape_count; i++) {
+ if (diagram->shape[i].path) {
+ ok = ctx->plot->path(diagram->shape[i].path,
+ diagram->shape[i].path_length,
+ BGR(diagram->shape[i].fill),
+ diagram->shape[i].stroke_width,
+ BGR(diagram->shape[i].stroke),
+ transform);
+ if (!ok)
+ return false;
+
+ } else if (diagram->shape[i].text) {
+ px = transform[0] * diagram->shape[i].text_x +
+ transform[2] * diagram->shape[i].text_y +
+ transform[4];
+ py = transform[1] * diagram->shape[i].text_x +
+ transform[3] * diagram->shape[i].text_y +
+ transform[5];
+
+ fstyle.background = 0xffffff;
+ fstyle.foreground = 0x000000;
+ fstyle.size = (8 * FONT_SIZE_SCALE) * scale;
+
+ ok = ctx->plot->text(px, py,
+ diagram->shape[i].text,
+ strlen(diagram->shape[i].text),
+ &fstyle);
+ if (!ok)
+ return false;
+ }
+ }
+
+#undef BGR
+
+ return true;
+}
+
+
+/**
+ * Redraw a CONTENT_SVG.
+ */
+
static bool svg_redraw(struct content *c, struct content_redraw_data *data,
- const struct rect *clip, const struct redraw_context *ctx);
-static nserror svg_clone(const struct content *old, struct content **newc);
-static content_type svg_content_type(lwc_string *mime_type);
+ const struct rect *clip, const struct redraw_context *ctx)
+{
+ int x = data->x;
+ int y = data->y;
+
+ if ((data->width <= 0) && (data->height <= 0)) {
+ /* No point trying to plot SVG if it does not occupy a valid
+ * area */
+ return true;
+ }
+
+ if ((data->repeat_x == false) && (data->repeat_y == false)) {
+ /* Simple case: SVG is not tiled */
+ return svg_redraw_internal(c, x, y,
+ data->width, data->height,
+ clip, ctx, data->scale,
+ data->background_colour);
+ } else {
+ /* Tiled redraw required. SVG repeats to extents of clip
+ * rectangle, in x, y or both directions */
+ int x0, y0, x1, y1;
+
+ /* Find the redraw boundaries to loop within */
+ x0 = x;
+ if (data->repeat_x) {
+ for (; x0 > clip->x0; x0 -= data->width);
+ x1 = clip->x1;
+ } else {
+ x1 = x + 1;
+ }
+ y0 = y;
+ if (data->repeat_y) {
+ for (; y0 > clip->y0; y0 -= data->height);
+ y1 = clip->y1;
+ } else {
+ y1 = y + 1;
+ }
+
+ /* Repeatedly plot the SVG across the area */
+ for (y = y0; y < y1; y += data->height) {
+ for (x = x0; x < x1; x += data->width) {
+ if (!svg_redraw_internal(c, x, y,
+ data->width, data->height,
+ clip, ctx, data->scale,
+ data->background_colour)) {
+ return false;
+ }
+ }
+ }
+ }
+
+ return true;
+}
+
+
+/**
+ * Destroy a CONTENT_SVG and free all resources it owns.
+ */
+
+static void svg_destroy(struct content *c)
+{
+ svg_content *svg = (svg_content *) c;
+
+ if (svg->diagram != NULL)
+ svgtiny_free(svg->diagram);
+}
+
+
+static nserror svg_clone(const struct content *old, struct content **newc)
+{
+ svg_content *svg;
+ nserror error;
+
+ svg = talloc_zero(0, svg_content);
+ if (svg == NULL)
+ return NSERROR_NOMEM;
+
+ error = content__clone(old, &svg->base);
+ if (error != NSERROR_OK) {
+ content_destroy(&svg->base);
+ return error;
+ }
+
+ /* Simply replay create/convert */
+ error = svg_create_svg_data(svg);
+ if (error != NSERROR_OK) {
+ content_destroy(&svg->base);
+ return error;
+ }
+
+ if (old->status == CONTENT_STATUS_READY ||
+ old->status == CONTENT_STATUS_DONE) {
+ if (svg_convert(&svg->base) == false) {
+ content_destroy(&svg->base);
+ return NSERROR_CLONE_FAILED;
+ }
+ }
+
+ *newc = (struct content *) svg;
+
+ return NSERROR_OK;
+}
+
+static content_type svg_content_type(lwc_string *mime_type)
+{
+ return CONTENT_IMAGE;
+}
static const content_handler svg_content_handler = {
.create = svg_create,
@@ -72,325 +343,7 @@
"image/svg+xml"
};
-static lwc_string *svg_mime_types[NOF_ELEMENTS(svg_types)];
-
-nserror svg_init(void)
-{
- uint32_t i;
- lwc_error lerror;
- nserror error;
-
- for (i = 0; i < NOF_ELEMENTS(svg_mime_types); i++) {
- lerror = lwc_intern_string(svg_types[i],
- strlen(svg_types[i]),
- &svg_mime_types[i]);
- if (lerror != lwc_error_ok) {
- error = NSERROR_NOMEM;
- goto error;
- }
-
- error = content_factory_register_handler(svg_mime_types[i],
- &svg_content_handler);
- if (error != NSERROR_OK)
- goto error;
- }
-
- return NSERROR_OK;
-
-error:
- svg_fini();
-
- return error;
-}
-
-void svg_fini(void)
-{
- uint32_t i;
-
- for (i = 0; i < NOF_ELEMENTS(svg_mime_types); i++) {
- if (svg_mime_types[i] != NULL)
- lwc_string_unref(svg_mime_types[i]);
- }
-}
-
-/**
- * Create a CONTENT_SVG.
- */
-
-nserror svg_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)
-{
- svg_content *svg;
- nserror error;
-
- svg = talloc_zero(0, svg_content);
- if (svg == NULL)
- return NSERROR_NOMEM;
-
- error = content__init(&svg->base, handler, imime_type, params,
- llcache, fallback_charset, quirks);
- if (error != NSERROR_OK) {
- talloc_free(svg);
- return error;
- }
-
- error = svg_create_svg_data(svg);
- if (error != NSERROR_OK) {
- talloc_free(svg);
- return error;
- }
-
- *c = (struct content *) svg;
-
- return NSERROR_OK;
-}
-
-nserror svg_create_svg_data(svg_content *c)
-{
- union content_msg_data msg_data;
-
- c->diagram = svgtiny_create();
- if (c->diagram == NULL)
- goto no_memory;
-
- c->done_parse = false;
-
- return NSERROR_OK;
-
-no_memory:
- msg_data.error = messages_get("NoMemory");
- content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
- return NSERROR_NOMEM;
-}
-
-
-/**
- * Convert a CONTENT_SVG for display.
- */
-
-bool svg_convert(struct content *c)
-{
- /*c->title = malloc(100);
- if (c->title)
- snprintf(c->title, 100, messages_get("svgTitle"),
- width, height, c->source_size);*/
- //c->size += ?;
- content_set_ready(c);
- content_set_done(c);
- /* Done: update status bar */
- content_set_status(c, "");
-
- return true;
-}
-
-/**
- * Reformat a CONTENT_SVG.
- */
-
-void svg_reformat(struct content *c, int width, int height)
-{
- svg_content *svg = (svg_content *) c;
- const char *source_data;
- unsigned long source_size;
-
- assert(svg->diagram);
-
- if (svg->done_parse == false) {
- source_data = content__get_source_data(c, &source_size);
-
- svgtiny_parse(svg->diagram, source_data, source_size,
- content__get_url(c), width, height);
-
- svg->done_parse = true;
- }
-
- c->width = svg->diagram->width;
- c->height = svg->diagram->height;
-}
-
-
-/**
- * Redraw a CONTENT_SVG.
- */
-
-static bool svg_redraw_internal(struct content *c, int x, int y,
- int width, int height, const struct rect *clip,
- const struct redraw_context *ctx, float scale,
- colour background_colour)
-{
- svg_content *svg = (svg_content *) c;
- float transform[6];
- struct svgtiny_diagram *diagram = svg->diagram;
- bool ok;
- int px, py;
- unsigned int i;
- plot_font_style_t fstyle = *plot_style_font;
-
- assert(diagram);
-
- transform[0] = (float) width / (float) c->width;
- transform[1] = 0;
- transform[2] = 0;
- transform[3] = (float) height / (float) c->height;
- transform[4] = x;
- transform[5] = y;
-
-#define BGR(c) ((c) == svgtiny_TRANSPARENT ? NS_TRANSPARENT : \
- ((svgtiny_RED((c))) | \
- (svgtiny_GREEN((c)) << 8) | \
- (svgtiny_BLUE((c)) << 16)))
-
- for (i = 0; i != diagram->shape_count; i++) {
- if (diagram->shape[i].path) {
- ok = ctx->plot->path(diagram->shape[i].path,
- diagram->shape[i].path_length,
- BGR(diagram->shape[i].fill),
- diagram->shape[i].stroke_width,
- BGR(diagram->shape[i].stroke),
- transform);
- if (!ok)
- return false;
-
- } else if (diagram->shape[i].text) {
- px = transform[0] * diagram->shape[i].text_x +
- transform[2] * diagram->shape[i].text_y +
- transform[4];
- py = transform[1] * diagram->shape[i].text_x +
- transform[3] * diagram->shape[i].text_y +
- transform[5];
-
- fstyle.background = 0xffffff;
- fstyle.foreground = 0x000000;
- fstyle.size = (8 * FONT_SIZE_SCALE) * scale;
-
- ok = ctx->plot->text(px, py,
- diagram->shape[i].text,
- strlen(diagram->shape[i].text),
- &fstyle);
- if (!ok)
- return false;
- }
- }
-
-#undef BGR
-
- return true;
-}
-
-
-/**
- * Redraw a CONTENT_SVG.
- */
-
-bool svg_redraw(struct content *c, struct content_redraw_data *data,
- const struct rect *clip, const struct redraw_context *ctx)
-{
- int x = data->x;
- int y = data->y;
-
- if ((data->width <= 0) && (data->height <= 0)) {
- /* No point trying to plot SVG if it does not occupy a valid
- * area */
- return true;
- }
-
- if ((data->repeat_x == false) && (data->repeat_y == false)) {
- /* Simple case: SVG is not tiled */
- return svg_redraw_internal(c, x, y,
- data->width, data->height,
- clip, ctx, data->scale,
- data->background_colour);
- } else {
- /* Tiled redraw required. SVG repeats to extents of clip
- * rectangle, in x, y or both directions */
- int x0, y0, x1, y1;
-
- /* Find the redraw boundaries to loop within */
- x0 = x;
- if (data->repeat_x) {
- for (; x0 > clip->x0; x0 -= data->width);
- x1 = clip->x1;
- } else {
- x1 = x + 1;
- }
- y0 = y;
- if (data->repeat_y) {
- for (; y0 > clip->y0; y0 -= data->height);
- y1 = clip->y1;
- } else {
- y1 = y + 1;
- }
-
- /* Repeatedly plot the SVG across the area */
- for (y = y0; y < y1; y += data->height) {
- for (x = x0; x < x1; x += data->width) {
- if (!svg_redraw_internal(c, x, y,
- data->width, data->height,
- clip, ctx, data->scale,
- data->background_colour)) {
- return false;
- }
- }
- }
- }
-
- return true;
-}
-
-
-/**
- * Destroy a CONTENT_SVG and free all resources it owns.
- */
-
-void svg_destroy(struct content *c)
-{
- svg_content *svg = (svg_content *) c;
-
- if (svg->diagram != NULL)
- svgtiny_free(svg->diagram);
-}
-
-
-nserror svg_clone(const struct content *old, struct content **newc)
-{
- svg_content *svg;
- nserror error;
-
- svg = talloc_zero(0, svg_content);
- if (svg == NULL)
- return NSERROR_NOMEM;
-
- error = content__clone(old, &svg->base);
- if (error != NSERROR_OK) {
- content_destroy(&svg->base);
- return error;
- }
-
- /* Simply replay create/convert */
- error = svg_create_svg_data(svg);
- if (error != NSERROR_OK) {
- content_destroy(&svg->base);
- return error;
- }
-
- if (old->status == CONTENT_STATUS_READY ||
- old->status == CONTENT_STATUS_DONE) {
- if (svg_convert(&svg->base) == false) {
- content_destroy(&svg->base);
- return NSERROR_CLONE_FAILED;
- }
- }
-
- *newc = (struct content *) svg;
-
- return NSERROR_OK;
-}
-
-content_type svg_content_type(lwc_string *mime_type)
-{
- return CONTENT_IMAGE;
-}
+
+CONTENT_FACTORY_REGISTER_TYPES(svg, svg_types, svg_content_handler);
#endif /* WITH_NS_SVG */
Modified: trunk/netsurf/image/webp.c
URL: http://source.netsurf-browser.org/trunk/netsurf/image/webp.c?rev=12671&r1...
==============================================================================
--- trunk/netsurf/image/webp.c (original)
+++ trunk/netsurf/image/webp.c Sat Aug 27 03:43:51 2011
@@ -41,16 +41,159 @@
struct content base;
} webp_content;
+
static nserror webp_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 webp_convert(struct content *c);
-static void webp_destroy(struct content *c);
+ bool quirks, struct content **c)
+{
+ webp_content *webp;
+ nserror error;
+
+ webp = talloc_zero(0, webp_content);
+ if (webp == NULL)
+ return NSERROR_NOMEM;
+
+ error = content__init(&webp->base, handler, imime_type, params,
+ llcache, fallback_charset, quirks);
+ if (error != NSERROR_OK) {
+ talloc_free(webp);
+ return error;
+ }
+
+ *c = (struct content *) webp;
+
+ return NSERROR_OK;
+}
+
+/**
+ * Convert a CONTENT_WEBP for display.
+ *
+ * No conversion is necessary. We merely read the WebP dimensions.
+ */
+
+static bool webp_convert(struct content *c)
+{
+ union content_msg_data msg_data;
+ const uint8_t *data;
+ unsigned char *imagebuf = NULL;
+ unsigned long size;
+ int width = 0, height = 0;
+ char title[100];
+ int res = 0;
+ uint8_t *res_p = NULL;
+
+ data = (uint8_t *)content__get_source_data(c, &size);
+
+ res = WebPGetInfo(data, size, &width, &height);
+ if (res == 0) {
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+ 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);
+ return false;
+ }
+
+ imagebuf = bitmap_get_buffer(c->bitmap);
+ if (!imagebuf) {
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+ return false;
+ }
+ unsigned int row_width = bitmap_get_rowstride(c->bitmap);
+
+ res_p = WebPDecodeRGBAInto(data, size, imagebuf,
+ row_width * height, row_width);
+ if (res_p == NULL) {
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+ return false;
+ }
+
+ 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);
+
+ content_set_ready(c);
+ content_set_done(c);
+
+ content_set_status(c, "");
+ return true;
+}
+
+
+/**
+ * Destroy a CONTENT_WEBP and free all resources it owns.
+ */
+
+static void webp_destroy(struct content *c)
+{
+ if (c->bitmap != NULL)
+ bitmap_destroy(c->bitmap);
+}
+
+
+/**
+ * Redraw a CONTENT_WEBP.
+ */
+
static bool webp_redraw(struct content *c, struct content_redraw_data *data,
- const struct rect *clip, const struct redraw_context *ctx);
-static nserror webp_clone(const struct content *old, struct content **newc);
-static content_type webp_content_type(lwc_string *mime_type);
+ const struct rect *clip, const struct redraw_context *ctx)
+{
+ bitmap_flags_t flags = BITMAPF_NONE;
+
+ if (data->repeat_x)
+ flags |= BITMAPF_REPEAT_X;
+ if (data->repeat_y)
+ flags |= BITMAPF_REPEAT_Y;
+
+ return ctx->plot->bitmap(data->x, data->y, data->width, data->height,
+ c->bitmap, data->background_colour, flags);
+}
+
+
+static nserror webp_clone(const struct content *old, struct content **newc)
+{
+ webp_content *webp;
+ nserror error;
+
+ webp = talloc_zero(0, webp_content);
+ if (webp == NULL)
+ return NSERROR_NOMEM;
+
+ error = content__clone(old, &webp->base);
+ if (error != NSERROR_OK) {
+ content_destroy(&webp->base);
+ return error;
+ }
+
+ /* Simply replay convert */
+ if (old->status == CONTENT_STATUS_READY ||
+ old->status == CONTENT_STATUS_DONE) {
+ if (webp_convert(&webp->base) == false) {
+ content_destroy(&webp->base);
+ return NSERROR_CLONE_FAILED;
+ }
+ }
+
+ *newc = (struct content *) webp;
+
+ return NSERROR_OK;
+}
+
+static content_type webp_content_type(lwc_string *mime_type)
+{
+ return CONTENT_IMAGE;
+}
static const content_handler webp_content_handler = {
.create = webp_create,
@@ -66,198 +209,6 @@
"image/webp"
};
-static lwc_string *webp_mime_types[NOF_ELEMENTS(webp_types)];
-
-nserror webp_init(void)
-{
- uint32_t i;
- lwc_error lerror;
- nserror error;
-
- for (i = 0; i < NOF_ELEMENTS(webp_mime_types); i++) {
- lerror = lwc_intern_string(webp_types[i],
- strlen(webp_types[i]),
- &webp_mime_types[i]);
- if (lerror != lwc_error_ok) {
- error = NSERROR_NOMEM;
- goto error;
- }
-
- error = content_factory_register_handler(webp_mime_types[i],
- &webp_content_handler);
- if (error != NSERROR_OK)
- goto error;
- }
-
- return NSERROR_OK;
-
-error:
- webp_fini();
-
- return error;
-}
-
-void webp_fini(void)
-{
- uint32_t i;
-
- for (i = 0; i < NOF_ELEMENTS(webp_mime_types); i++) {
- if (webp_mime_types[i] != NULL)
- lwc_string_unref(webp_mime_types[i]);
- }
-}
-
-nserror webp_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)
-{
- webp_content *webp;
- nserror error;
-
- webp = talloc_zero(0, webp_content);
- if (webp == NULL)
- return NSERROR_NOMEM;
-
- error = content__init(&webp->base, handler, imime_type, params,
- llcache, fallback_charset, quirks);
- if (error != NSERROR_OK) {
- talloc_free(webp);
- return error;
- }
-
- *c = (struct content *) webp;
-
- return NSERROR_OK;
-}
-
-/**
- * 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 uint8_t *data;
- unsigned char *imagebuf = NULL;
- unsigned long size;
- int width = 0, height = 0;
- char title[100];
- int res = 0;
- uint8_t *res_p = NULL;
-
- data = (uint8_t *)content__get_source_data(c, &size);
-
- res = WebPGetInfo(data, size, &width, &height);
- if (res == 0) {
- msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
- 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);
- return false;
- }
-
- imagebuf = bitmap_get_buffer(c->bitmap);
- if (!imagebuf) {
- msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
- return false;
- }
- unsigned int row_width = bitmap_get_rowstride(c->bitmap);
-
- res_p = WebPDecodeRGBAInto(data, size, imagebuf,
- row_width * height, row_width);
- if (res_p == NULL) {
- msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
- return false;
- }
-
- 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);
-
- content_set_ready(c);
- content_set_done(c);
-
- content_set_status(c, "");
- 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, struct content_redraw_data *data,
- const struct rect *clip, const struct redraw_context *ctx)
-{
- bitmap_flags_t flags = BITMAPF_NONE;
-
- if (data->repeat_x)
- flags |= BITMAPF_REPEAT_X;
- if (data->repeat_y)
- flags |= BITMAPF_REPEAT_Y;
-
- return ctx->plot->bitmap(data->x, data->y, data->width, data->height,
- c->bitmap, data->background_colour, flags);
-}
-
-
-nserror webp_clone(const struct content *old, struct content **newc)
-{
- webp_content *webp;
- nserror error;
-
- webp = talloc_zero(0, webp_content);
- if (webp == NULL)
- return NSERROR_NOMEM;
-
- error = content__clone(old, &webp->base);
- if (error != NSERROR_OK) {
- content_destroy(&webp->base);
- return error;
- }
-
- /* Simply replay convert */
- if (old->status == CONTENT_STATUS_READY ||
- old->status == CONTENT_STATUS_DONE) {
- if (webp_convert(&webp->base) == false) {
- content_destroy(&webp->base);
- return NSERROR_CLONE_FAILED;
- }
- }
-
- *newc = (struct content *) webp;
-
- return NSERROR_OK;
-}
-
-content_type webp_content_type(lwc_string *mime_type)
-{
- return CONTENT_IMAGE;
-}
+CONTENT_FACTORY_REGISTER_TYPES(webp, webp_types, webp_content_handler);
#endif
11 years, 5 months
r12670 jmb - /trunk/netsurf/desktop/download.c
by netsurf@semichrome.net
Author: jmb
Date: Thu Aug 25 14:21:09 2011
New Revision: 12670
URL: http://source.netsurf-browser.org?rev=12670&view=rev
Log:
Fix bug #3398114: only unref filename_value if we successfully obtained it
Modified:
trunk/netsurf/desktop/download.c
Modified: trunk/netsurf/desktop/download.c
URL: http://source.netsurf-browser.org/trunk/netsurf/desktop/download.c?rev=12...
==============================================================================
--- trunk/netsurf/desktop/download.c (original)
+++ trunk/netsurf/desktop/download.c Thu Aug 25 14:21:09 2011
@@ -132,12 +132,13 @@
error = http_parameter_list_find_item(disposition->parameters,
filename, &filename_value);
- if (error == NSERROR_OK)
+ if (error == NSERROR_OK) {
ctx->filename = download_parse_filename(
lwc_string_data(filename_value));
+ lwc_string_unref(filename_value);
+ }
http_content_disposition_destroy(disposition);
- lwc_string_unref(filename_value);
lwc_string_unref(filename);
}
11 years, 5 months
r12669 tlsa - /trunk/netsurf/desktop/scrollbar.c
by netsurf@semichrome.net
Author: tlsa
Date: Thu Aug 25 13:29:21 2011
New Revision: 12669
URL: http://source.netsurf-browser.org?rev=12669&view=rev
Log:
Fix step size for clicks on scrollbar arrow icons.
Modified:
trunk/netsurf/desktop/scrollbar.c
Modified: trunk/netsurf/desktop/scrollbar.c
URL: http://source.netsurf-browser.org/trunk/netsurf/desktop/scrollbar.c?rev=1...
==============================================================================
--- trunk/netsurf/desktop/scrollbar.c (original)
+++ trunk/netsurf/desktop/scrollbar.c Thu Aug 25 13:29:21 2011
@@ -610,9 +610,9 @@
status = messages_get(h ? "ScrollLeft" : "ScrollUp");
if (but1)
- scrollbar_set(s, s->bar_pos - SCROLLBAR_WIDTH, true);
+ scrollbar_set(s, s->offset - SCROLLBAR_WIDTH, false);
else if (but2)
- scrollbar_set(s, s->bar_pos + SCROLLBAR_WIDTH, true);
+ scrollbar_set(s, s->offset + SCROLLBAR_WIDTH, false);
} else if (val < SCROLLBAR_WIDTH + s->bar_pos) {
/* well between left/up arrow and bar */
@@ -630,9 +630,9 @@
status = messages_get(h ? "ScrollRight" : "ScrollDown");
if (but1)
- scrollbar_set(s, s->bar_pos + SCROLLBAR_WIDTH, true);
+ scrollbar_set(s, s->offset + SCROLLBAR_WIDTH, false);
else if (but2)
- scrollbar_set(s, s->bar_pos - SCROLLBAR_WIDTH, true);
+ scrollbar_set(s, s->offset - SCROLLBAR_WIDTH, false);
} else if (val > SCROLLBAR_WIDTH + s->bar_pos +
s->bar_len) {
11 years, 5 months
r12668 tlsa - /trunk/netsurf/desktop/browser.c
by netsurf@semichrome.net
Author: tlsa
Date: Thu Aug 25 08:34:48 2011
New Revision: 12668
URL: http://source.netsurf-browser.org?rev=12668&view=rev
Log:
Fix scrollbar click coords.
Modified:
trunk/netsurf/desktop/browser.c
Modified: trunk/netsurf/desktop/browser.c
URL: http://source.netsurf-browser.org/trunk/netsurf/desktop/browser.c?rev=126...
==============================================================================
--- trunk/netsurf/desktop/browser.c (original)
+++ trunk/netsurf/desktop/browser.c Thu Aug 25 08:34:48 2011
@@ -1983,8 +1983,8 @@
if (bw->scroll_x != NULL) {
int scr_x, scr_y;
browser_window_get_scrollbar_pos(bw, true, &scr_x, &scr_y);
- scr_x = x - scr_x;
- scr_y = y - scr_y;
+ scr_x = x - scr_x - scrollbar_get_offset(bw->scroll_x);
+ scr_y = y - scr_y - scrollbar_get_offset(bw->scroll_y);
if (scr_x > 0 && scr_x < browser_window_get_scrollbar_len(bw,
true) &&
@@ -2004,8 +2004,8 @@
if (bw->scroll_y != NULL) {
int scr_x, scr_y;
browser_window_get_scrollbar_pos(bw, false, &scr_x, &scr_y);
- scr_x = x - scr_x;
- scr_y = y - scr_y;
+ scr_x = x - scr_x - scrollbar_get_offset(bw->scroll_x);
+ scr_y = y - scr_y - scrollbar_get_offset(bw->scroll_y);
if (scr_y > 0 && scr_y < browser_window_get_scrollbar_len(bw,
false) &&
11 years, 5 months
r12667 tlsa - /trunk/netsurf/desktop/scrollbar.c
by netsurf@semichrome.net
Author: tlsa
Date: Thu Aug 25 04:21:41 2011
New Revision: 12667
URL: http://source.netsurf-browser.org?rev=12667&view=rev
Log:
When scrollbar extents are updated, scale current offset appropriately.
Modified:
trunk/netsurf/desktop/scrollbar.c
Modified: trunk/netsurf/desktop/scrollbar.c
URL: http://source.netsurf-browser.org/trunk/netsurf/desktop/scrollbar.c?rev=1...
==============================================================================
--- trunk/netsurf/desktop/scrollbar.c (original)
+++ trunk/netsurf/desktop/scrollbar.c Thu Aug 25 04:21:41 2011
@@ -458,8 +458,7 @@
int visible_size, int full_size)
{
int well_length;
-
- /* TODO: update offset appropriately */
+ int cur_excess = s->full_size - s->visible_size;
if (length != -1)
s->length = length;
@@ -467,6 +466,9 @@
s->visible_size = visible_size;
if (full_size != -1)
s->full_size = full_size;
+
+ /* Update scroll offset (scaled in proportion with change in excess) */
+ s->offset = (s->full_size - s->visible_size) * s->offset / cur_excess;
well_length = s->length - 2 * SCROLLBAR_WIDTH;
11 years, 5 months
r12666 tlsa - /trunk/netsurf/desktop/browser.c
by netsurf@semichrome.net
Author: tlsa
Date: Wed Aug 24 16:53:58 2011
New Revision: 12666
URL: http://source.netsurf-browser.org?rev=12666&view=rev
Log:
When passing drag on to it's bw, we don't need to do anything if the drag is for the current bw.
Modified:
trunk/netsurf/desktop/browser.c
Modified: trunk/netsurf/desktop/browser.c
URL: http://source.netsurf-browser.org/trunk/netsurf/desktop/browser.c?rev=126...
==============================================================================
--- trunk/netsurf/desktop/browser.c (original)
+++ trunk/netsurf/desktop/browser.c Wed Aug 24 16:53:58 2011
@@ -1866,7 +1866,7 @@
if (bw->window != NULL) {
/* root browser window */
- if (bw->drag_window) {
+ if (bw->drag_window && bw != bw->drag_window) {
/* There's an active drag in a sub window.
* Pass the mouse action straight on to that bw. */
int off_x = 0;
11 years, 5 months