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 --- cocoa/Makefile.target | 9 +-- cocoa/NetSurf.xcodeproj/project.pbxproj | 4 ++ cocoa/apple_image.h | 54 +++++++++++++++ cocoa/apple_image.m | 117 ++++++++++++++++++++++++++++++++ 4 files changed, 177 insertions(+), 7 deletions(-) create mode 100644 cocoa/apple_image.h create mode 100644 cocoa/apple_image.m (limited to 'cocoa') 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 */ -- cgit v1.2.3