From 208b98bb44b986e62ff0f80b7e50c9da3e12cb8f Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Sat, 5 Mar 2011 09:49:15 +0000 Subject: Created content handler CONTENT_APPLE_IMAGE for Mac OS X that can handle all image file formats supported by Apples ImageIO framework. Right now used only for JPEG to get rid of libjpeg dependency. svn path=/trunk/netsurf/; revision=11911 --- Makefile.defaults | 4 +- cocoa/Makefile.target | 9 +-- cocoa/NetSurf.xcodeproj/project.pbxproj | 4 ++ cocoa/apple_image.h | 54 +++++++++++++++ cocoa/apple_image.m | 117 ++++++++++++++++++++++++++++++++ content/content.c | 18 +++++ content/content_protected.h | 7 +- content/content_type.h | 3 + render/box.c | 3 + render/box_construct.c | 3 + 10 files changed, 213 insertions(+), 9 deletions(-) create mode 100644 cocoa/apple_image.h create mode 100644 cocoa/apple_image.m diff --git a/Makefile.defaults b/Makefile.defaults index 6722494d1..effead2e7 100644 --- a/Makefile.defaults +++ b/Makefile.defaults @@ -373,9 +373,11 @@ ifeq ($(TARGET),cocoa) NETSURF_USE_NSSVG := YES NETSURF_USE_MNG := NO + + NETSURF_USE_JPEG := NO # Optimisation levels - CFLAGS += -O2 -Wuninitialized + CFLAGS += -O2 -Wuninitialized -DWITH_APPLE_IMAGE endif diff --git a/cocoa/Makefile.target b/cocoa/Makefile.target index 3b9915947..ee79b9c92 100644 --- a/cocoa/Makefile.target +++ b/cocoa/Makefile.target @@ -31,12 +31,6 @@ CFLAGS += -I/usr/include/libxml2 CFLAGS += -include cocoa/Prefix.pch -ifneq ($(wildcard /opt/local*),) - # libjpeg is there when installed from MacPort. - LDFLAGS += -L/opt/local/lib - CFLAGS += -I/opt/local/include -endif - VERSION_FULL := $(shell sed -n '/\"/{s/.*"\(.*\)\".*/\1/;p;}' desktop/version.c) VERSION_MAJ := $(shell sed -n '/_major/{s/.* = \([0-9]*\).*/\1/;p;}' desktop/version.c) VERSION_MIN := $(shell sed -n '/_minor/{s/.* = \([0-9]*\).*/\1/;p;}' desktop/version.c) @@ -96,7 +90,8 @@ S_COCOA := \ ArrowBox.m \ ArrowWindow.m \ BlackScroller.m \ - LocalHistoryController.m + LocalHistoryController.m \ + apple_image.m S_TABBAR := \ NSBezierPath_AMShading.m \ diff --git a/cocoa/NetSurf.xcodeproj/project.pbxproj b/cocoa/NetSurf.xcodeproj/project.pbxproj index 1f3141526..eacc80a43 100644 --- a/cocoa/NetSurf.xcodeproj/project.pbxproj +++ b/cocoa/NetSurf.xcodeproj/project.pbxproj @@ -269,6 +269,8 @@ 26B4E926130D36A90003B527 /* LocalHistoryPanel.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = LocalHistoryPanel.xib; sourceTree = ""; }; 26B4E928130D37E50003B527 /* LocalHistoryController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalHistoryController.h; sourceTree = ""; }; 26B4E929130D37E50003B527 /* LocalHistoryController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LocalHistoryController.m; sourceTree = ""; }; + 26BA25AB1321653200AEC1DA /* apple_image.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = apple_image.m; sourceTree = ""; }; + 26BA25AC1321653200AEC1DA /* apple_image.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = apple_image.h; sourceTree = ""; }; 26CDCEB312E702D8004FC66B /* NSBezierPath_AMShading.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSBezierPath_AMShading.h; sourceTree = ""; }; 26CDCEB412E702D8004FC66B /* NSBezierPath_AMShading.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSBezierPath_AMShading.m; sourceTree = ""; }; 26CDCEB512E702D8004FC66B /* NSString_AITruncation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSString_AITruncation.h; sourceTree = ""; }; @@ -583,6 +585,8 @@ 265F303F12D6637E0048B600 /* Cocoa Frontend */ = { isa = PBXGroup; children = ( + 26BA25AB1321653200AEC1DA /* apple_image.m */, + 26BA25AC1321653200AEC1DA /* apple_image.h */, 26CDD26512E74402004FC66B /* Browser */, 26CDD26712E74453004FC66B /* Download */, 26CDD26612E7441E004FC66B /* Views */, diff --git a/cocoa/apple_image.h b/cocoa/apple_image.h new file mode 100644 index 000000000..1611cf52a --- /dev/null +++ b/cocoa/apple_image.h @@ -0,0 +1,54 @@ +/* + * Copyright 2011 Sven Weidauer + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#ifndef _NETSURF_COCOA_APPLE_IMAGE_H_ +#define _NETSURF_COCOA_APPLE_IMAGE_H_ + +#ifdef WITH_APPLE_IMAGE + +#ifdef WITH_JPEG +#error "Don't define WITH_JPEG and WITH_APPLE_IMAGE" +#endif + +#include "utils/config.h" +#include "desktop/plot_style.h" + +struct bitmap; +struct content; +struct rect; + +struct content_apple_image_data { +}; + +bool apple_image_convert(struct content *c); +void apple_image_destroy(struct content *c); + +bool apple_image_redraw(struct content *c, int x, int y, + int width, int height, const struct rect *clip, + float scale, colour background_colour); +bool apple_image_redraw_tiled(struct content *c, int x, int y, + int width, int height, const struct rect *clip, + float scale, colour background_colour, + bool repeat_x, bool repeat_y); + +bool apple_image_clone(const struct content *old, struct content *new_content); + +#endif /* WITH_APPLE_IMAGE */ + +#endif diff --git a/cocoa/apple_image.m b/cocoa/apple_image.m new file mode 100644 index 000000000..cdf3e537b --- /dev/null +++ b/cocoa/apple_image.m @@ -0,0 +1,117 @@ +/* + * Copyright 2011 Sven Weidauer + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifdef WITH_APPLE_IMAGE + +#import "cocoa/apple_image.h" + +#include "utils/config.h" +#include "content/content_protected.h" +#include "image/bitmap.h" +#include "desktop/plotters.h" + +/** + * Convert a CONTENT_APPLE_IMAGE for display. + */ + +bool apple_image_convert(struct content *c) +{ + unsigned long size; + const char *bytes = content__get_source_data(c, &size); + + NSData *data = [NSData dataWithBytesNoCopy: (char *)bytes length: size freeWhenDone: NO]; + NSBitmapImageRep *image = [[NSBitmapImageRep imageRepWithData: data] retain]; + + if (image == nil) { + union content_msg_data msg_data; + msg_data.error = "cannot decode image"; + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + return false; + } + + c->width = [image pixelsWide]; + c->height = [image pixelsHigh]; + c->bitmap = (void *)image; + + char title[100]; + snprintf( title, sizeof title, "Image (%dx%d)", c->width, c->height ); + content__set_title(c, title ); + + content_set_ready(c); + content_set_done(c); + content_set_status(c, ""); + + return true; +} + + +void apple_image_destroy(struct content *c) +{ + [(id)c->bitmap release]; + c->bitmap = NULL; +} + + +bool apple_image_clone(const struct content *old, struct content *new_content) +{ + if (old->status == CONTENT_STATUS_READY || + old->status == CONTENT_STATUS_DONE) { + new_content->width = old->width; + new_content->height = old->height; + new_content->bitmap = (void *)[(id)old->bitmap retain]; + } + + return true; +} + + +/** + * Redraw a CONTENT_APPLE_IMAGE. + */ + +bool apple_image_redraw(struct content *c, int x, int y, + int width, int height, const struct rect *clip, + float scale, colour background_colour) +{ + return plot.bitmap(x, y, width, height, + c->bitmap, background_colour, BITMAPF_NONE); +} + + +/** + * Redraw a CONTENT_APPLE_IMAGE with appropriate tiling. + */ + +bool apple_image_redraw_tiled(struct content *c, int x, int y, + int width, int height, const struct rect *clip, + float scale, colour background_colour, + bool repeat_x, bool repeat_y) +{ + bitmap_flags_t flags = BITMAPF_NONE; + + if (repeat_x) + flags |= BITMAPF_REPEAT_X; + if (repeat_y) + flags |= BITMAPF_REPEAT_Y; + + return plot.bitmap(x, y, width, height, + c->bitmap, background_colour, + flags); +} + +#endif /* WITH_APPLE_IMAGE */ diff --git a/content/content.c b/content/content.c index cac5c97e7..41d922d62 100644 --- a/content/content.c +++ b/content/content.c @@ -83,6 +83,10 @@ #ifdef WITH_AMIGA_ICON #include "amiga/icon.h" #endif +#ifdef WITH_APPLE_IMAGE +#include "cocoa/apple_image.h" +#endif + #include "utils/http.h" #include "utils/log.h" #include "utils/messages.h" @@ -140,6 +144,10 @@ static const struct mime_entry mime_map[] = { {"image/jpeg", CONTENT_JPEG}, {"image/jpg", CONTENT_JPEG}, #endif +#ifdef WITH_APPLE_IMAGE + {"image/jpeg", CONTENT_APPLE_IMAGE}, + {"image/jpg", CONTENT_APPLE_IMAGE}, +#endif #ifdef WITH_MNG {"image/mng", CONTENT_MNG}, #endif @@ -149,6 +157,9 @@ static const struct mime_entry mime_map[] = { #ifdef WITH_JPEG {"image/pjpeg", CONTENT_JPEG}, #endif +#ifdef WITH_APPLE_IMAGE + {"image/pjpeg", CONTENT_APPLE_IMAGE}, +#endif #if defined(WITH_MNG) || defined(WITH_PNG) {"image/png", CONTENT_PNG}, #endif @@ -248,6 +259,9 @@ const char * const content_type_name[] = { #endif #ifdef WITH_AMIGA_ICON "AMIGA_ICON", +#endif +#ifdef WITH_APPLE_IMAGE + "APPLE_IMAGE", #endif "OTHER", "UNKNOWN" @@ -384,6 +398,10 @@ static const struct handler_entry handler_map[] = { {0, 0, amiga_icon_convert, 0, amiga_icon_destroy, 0, 0, 0, amiga_icon_redraw, 0, 0, 0, amiga_icon_clone, false}, +#endif +#ifdef WITH_APPLE_IMAGE + {0, 0, apple_image_convert, 0, apple_image_destroy, 0, 0, 0, + apple_image_redraw, apple_image_redraw_tiled, 0, 0, apple_image_clone, false}, #endif {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false} }; diff --git a/content/content_protected.h b/content/content_protected.h index 38f381583..50ece50a5 100644 --- a/content/content_protected.h +++ b/content/content_protected.h @@ -81,7 +81,9 @@ #ifdef WITH_AMIGA_ICON #include "amiga/icon.h" #endif - +#ifdef WITH_APPLE_IMAGE +#include "cocoa/apple_image.h" +#endif struct bitmap; struct content; @@ -158,6 +160,9 @@ struct content { #endif #ifdef WITH_AMIGA_ICON struct content_amiga_icon_data amiga_icon; +#endif +#ifdef WITH_APPLE_IMAGE + struct content_apple_image_data apple_image; #endif } data; diff --git a/content/content_type.h b/content/content_type.h index 9703c5616..0b086a599 100644 --- a/content/content_type.h +++ b/content/content_type.h @@ -73,6 +73,9 @@ typedef enum { #endif #ifdef WITH_AMIGA_ICON CONTENT_AMIGA_ICON, +#endif +#ifdef WITH_APPLE_IMAGE + CONTENT_APPLE_IMAGE, #endif /* these must be the last two */ CONTENT_OTHER, diff --git a/render/box.c b/render/box.c index 275079978..fa579aff8 100644 --- a/render/box.c +++ b/render/box.c @@ -1175,6 +1175,9 @@ bool box_duplicate_main_tree(struct box *box, struct content *c, int *count) #endif #if defined(WITH_NS_SVG) || defined(WITH_RSVG) content_get_type(box->object) == CONTENT_SVG || +#endif +#ifdef WITH_APPLE_IMAGE + content_get_type(box->object) == CONTENT_APPLE_IMAGE || #endif false)) box->object = NULL; diff --git a/render/box_construct.c b/render/box_construct.c index d99e5deec..44fcb54b1 100644 --- a/render/box_construct.c +++ b/render/box_construct.c @@ -86,6 +86,9 @@ static const content_type image_types[] = { #endif #ifdef WITH_AMIGA_ICON CONTENT_AMIGA_ICON, +#endif +#ifdef WITH_APPLE_IMAGE + CONTENT_APPLE_IMAGE, #endif CONTENT_UNKNOWN }; -- cgit v1.2.3