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
This commit is contained in:
Sven Weidauer 2011-03-05 09:49:15 +00:00
parent 323d5f3ba1
commit 208b98bb44
10 changed files with 213 additions and 9 deletions

View File

@ -374,8 +374,10 @@ ifeq ($(TARGET),cocoa)
NETSURF_USE_MNG := NO
NETSURF_USE_JPEG := NO
# Optimisation levels
CFLAGS += -O2 -Wuninitialized
CFLAGS += -O2 -Wuninitialized -DWITH_APPLE_IMAGE
endif

View File

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

View File

@ -269,6 +269,8 @@
26B4E926130D36A90003B527 /* LocalHistoryPanel.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = LocalHistoryPanel.xib; sourceTree = "<group>"; };
26B4E928130D37E50003B527 /* LocalHistoryController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalHistoryController.h; sourceTree = "<group>"; };
26B4E929130D37E50003B527 /* LocalHistoryController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LocalHistoryController.m; sourceTree = "<group>"; };
26BA25AB1321653200AEC1DA /* apple_image.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = apple_image.m; sourceTree = "<group>"; };
26BA25AC1321653200AEC1DA /* apple_image.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = apple_image.h; sourceTree = "<group>"; };
26CDCEB312E702D8004FC66B /* NSBezierPath_AMShading.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSBezierPath_AMShading.h; sourceTree = "<group>"; };
26CDCEB412E702D8004FC66B /* NSBezierPath_AMShading.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSBezierPath_AMShading.m; sourceTree = "<group>"; };
26CDCEB512E702D8004FC66B /* NSString_AITruncation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSString_AITruncation.h; sourceTree = "<group>"; };
@ -583,6 +585,8 @@
265F303F12D6637E0048B600 /* Cocoa Frontend */ = {
isa = PBXGroup;
children = (
26BA25AB1321653200AEC1DA /* apple_image.m */,
26BA25AC1321653200AEC1DA /* apple_image.h */,
26CDD26512E74402004FC66B /* Browser */,
26CDD26712E74453004FC66B /* Download */,
26CDD26612E7441E004FC66B /* Views */,

54
cocoa/apple_image.h Normal file
View File

@ -0,0 +1,54 @@
/*
* Copyright 2011 Sven Weidauer <sven.weidauer@gmail.com>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
* NetSurf is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* NetSurf is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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

117
cocoa/apple_image.m Normal file
View File

@ -0,0 +1,117 @@
/*
* Copyright 2011 Sven Weidauer <sven.weidauer@gmail.com>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
* NetSurf is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* NetSurf is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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 */

View File

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

View File

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

View File

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

View File

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

View File

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