Support ColourIcons

svn path=/trunk/netsurf/; revision=10928
This commit is contained in:
Chris Young 2010-10-31 11:14:26 +00:00
parent e5c144af95
commit 001b401890
6 changed files with 167 additions and 95 deletions

View File

@ -26,7 +26,9 @@ LDFLAGS += -lssl -lcrypto -lhubbub -lcss -lparserutils -lwapcaplet -liconv
ifeq ($(NETSURF_AMIGA_USE_CAIRO),YES)
CFLAGS += -DNS_AMIGA_CAIRO -I /SDK/local/common/include/cairo
LDFLAGS += -use-dynld -ldl -lcairo -lpixman-1 -lfreetype -lfontconfig -lpng -lexpat
SUBTARGET := -cairo
EXETARGET := NetSurf-Cairo
else
EXETARGET := NetSurf
endif
# ----------------------------------------------------------------------------
@ -45,4 +47,3 @@ S_AMIGA := $(addprefix amiga/,$(S_AMIGA))
# complete source file list
SOURCES := $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_AMIGA) $(S_PDF)
EXETARGET := NetSurf$(SUBTARGET)

View File

@ -27,10 +27,10 @@
#include <proto/icon.h>
#include <proto/application.h>
#include <graphics/blitattr.h>
#include <workbench/icon.h>
#include "amiga/download.h"
#include "amiga/icon.h"
#include "amiga/object.h"
#include "amiga/options.h"
#include "amiga/bitmap.h"
@ -325,84 +325,3 @@ gui_window_save_link(struct gui_window *g, const char *url, const char *title)
ami_update_pointer(g->shared->win,GUI_POINTER_DEFAULT);
}
}
void ami_superimpose_favicon(STRPTR path, struct hlcache_handle *icon, STRPTR type)
{
struct DiskObject *dobj = NULL;
struct BitMap *bm = NULL;
ULONG *icondata1, *icondata2;
ULONG width, height;
long format = 0;
int err = 0;
if(!type)
{
dobj = GetIconTags(NULL,
ICONGETA_GetDefaultType, WBDRAWER,
TAG_DONE);
}
else
{
dobj = GetIconTags(NULL, ICONGETA_GetDefaultName, type,
ICONGETA_GetDefaultType, WBPROJECT,
TAG_DONE);
}
err = IconControl(dobj,
ICONCTRLA_GetImageDataFormat,&format,
ICONCTRLA_GetImageData1,&icondata1,
ICONCTRLA_GetImageData2,&icondata2,
ICONCTRLA_GetWidth,&width,
ICONCTRLA_GetHeight,&height,
TAG_DONE);
/* Check icon is direct mapped (truecolour).
* Quite a bit more code is needed for palette mapped and planar icons,
* and OS4 default icons should all be truecolour anyway. */
if(format == IDFMT_DIRECTMAPPED)
{
if ((icon != NULL) && (content_get_type(icon) == CONTENT_ICO))
{
nsico_set_bitmap_from_size(icon, 16, 16);
}
if ((icon != NULL) && (content_get_bitmap(icon) != NULL))
{
bm = ami_getcachenativebm(content_get_bitmap(icon), 16, 16, NULL);
}
if(bm)
{
BltBitMapTags(BLITA_SrcX, 0,
BLITA_SrcY, 0,
BLITA_DestX, width - 16,
BLITA_DestY, height - 16,
BLITA_Width, 16,
BLITA_Height, 16,
BLITA_Source, bm,
BLITA_Dest, icondata1,
BLITA_SrcType, BLITT_BITMAP,
BLITA_DestType, BLITT_ARGB32,
BLITA_DestBytesPerRow, width * 4,
BLITA_UseSrcAlpha, TRUE,
TAG_DONE);
BltBitMapTags(BLITA_SrcX, 0,
BLITA_SrcY, 0,
BLITA_DestX, width - 16,
BLITA_DestY, height - 16,
BLITA_Width, 16,
BLITA_Height, 16,
BLITA_Source, bm,
BLITA_Dest, icondata2,
BLITA_SrcType, BLITT_BITMAP,
BLITA_DestType, BLITT_ARGB32,
BLITA_DestBytesPerRow, width * 4,
BLITA_UseSrcAlpha, TRUE,
TAG_DONE);
}
}
PutIconTags(path, dobj,
ICONPUTA_NotifyWorkbench, TRUE, TAG_DONE);
}

View File

@ -45,5 +45,4 @@ struct gui_download_window {
void ami_download_window_abort(struct gui_download_window *dw);
BOOL ami_download_window_event(struct gui_download_window *dw);
void ami_free_download_list(struct List *dllist);
void ami_superimpose_favicon(STRPTR path, struct hlcache_handle *icon, STRPTR type);
#endif

View File

@ -1,4 +1,4 @@
/*
/*
* Copyright 2010 Chris Young <chris@unsatisfactorysoftware.co.uk>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
@ -22,16 +22,20 @@
*/
#include "utils/config.h"
#ifdef WITH_AMIGA_ICON
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <proto/exec.h>
#include <proto/icon.h>
#include <datatypes/pictureclass.h>
#include <graphics/blitattr.h>
#include <workbench/icon.h>
#include "amiga/bitmap.h"
#include "amiga/icon.h"
#include "desktop/plotters.h"
#include "image/bitmap.h"
#include "content/content_protected.h"
@ -40,6 +44,11 @@
#include "utils/utils.h"
#include "utils/url.h"
ULONG *amiga_icon_convertcolouricon32(UBYTE *icondata, ULONG width, ULONG height,
ULONG trans, ULONG pals1, struct ColorRegister *pal1, int alpha);
#ifdef WITH_AMIGA_ICON
/**
* Convert a CONTENT_AMIGA_ICON for display.
*
@ -61,6 +70,8 @@ bool amiga_icon_convert(struct content *c)
char *url;
char *filename;
char *p;
ULONG trans, pals1;
struct ColorRegister *pal1;
url = content__get_url(c);
filename = url_to_path(url);
@ -91,20 +102,23 @@ bool amiga_icon_convert(struct content *c)
ICONCTRLA_GetHeight,&height,
TAG_DONE);
/* Check icon is direct mapped (truecolour).
We need additional code to handle ColourIcons and planar icons */
if(format != IDFMT_DIRECTMAPPED) return false;
/* Check icon is direct mapped (truecolour) or palette-mapped colour.
We need additional code to handle planar icons */
if((format != IDFMT_DIRECTMAPPED) && (format==IDFMT_PALETTEMAPPED))
return false;
c->bitmap = bitmap_create(width, height, BITMAP_NEW);
if (!c->bitmap) {
msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
if(dobj) FreeDiskObject(dobj);
return false;
}
imagebuf = bitmap_get_buffer(c->bitmap);
if (!imagebuf) {
msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
if(dobj) FreeDiskObject(dobj);
return false;
}
@ -112,6 +126,17 @@ bool amiga_icon_convert(struct content *c)
ICONCTRLA_GetImageData1, &imagebufptr,
TAG_DONE);
if(format==IDFMT_PALETTEMAPPED)
{
IconControl(dobj, ICONCTRLA_GetTransparentColor1, &trans,
ICONCTRLA_GetPalette1, &pal1,
ICONCTRLA_GetPaletteSize1, &pals1,
TAG_DONE);
imagebufptr = amiga_icon_convertcolouricon32((UBYTE *)imagebufptr,
width, height, trans, pals1, pal1, 0xff);
}
/* Decoded data is ARGB, so ensure correct byte order */
size = width * height * 4;
@ -131,8 +156,10 @@ bool amiga_icon_convert(struct content *c)
bitmap_modified(c->bitmap);
c->status = CONTENT_STATUS_DONE;
content_set_status(c, "");
if(dobj) FreeDiskObject(dobj);
return true;
}
@ -167,11 +194,136 @@ bool amiga_icon_clone(const struct content *old, struct content *new_content)
/* Simply replay convert */
if (old->status == CONTENT_STATUS_READY ||
old->status == CONTENT_STATUS_DONE) {
if (webp_convert(new_content) == false)
if (amiga_icon_convert(new_content) == false)
return false;
}
return true;
}
#endif /* WITH_AMIGA_ICON */
ULONG *amiga_icon_convertcolouricon32(UBYTE *icondata, ULONG width, ULONG height,
ULONG trans, ULONG pals1, struct ColorRegister *pal1, int alpha)
{
ULONG *argbicon;
struct ColorRegister *colour;
struct ColorMap *cmap;
int i;
ULONG a,r,g,b;
if (alpha==0) alpha=0xff;
argbicon = (ULONG *)AllocVec(width*height*4,MEMF_CLEAR);
if (!argbicon) return(NULL);
cmap=GetColorMap(pals1);
if(!cmap) return(NULL);
for(i=0;i<(width*height);i++)
{
colour = &pal1[icondata[i]];
if(icondata[i] == trans)
{
a=0x00;
}
else
{
a=alpha;
}
r = colour->red;
g = colour->green;
b = colour->blue;
argbicon[i] = (a << 24) +
(r << 16) +
(g << 8) +
(b);
}
return(argbicon);
}
void ami_superimpose_favicon(char *path, struct hlcache_handle *icon, char *type)
{
struct DiskObject *dobj = NULL;
struct BitMap *bm = NULL;
ULONG *icondata1, *icondata2;
ULONG width, height;
long format = 0;
int err = 0;
if(!type)
{
dobj = GetIconTags(NULL,
ICONGETA_GetDefaultType, WBDRAWER,
TAG_DONE);
}
else
{
dobj = GetIconTags(NULL, ICONGETA_GetDefaultName, type,
ICONGETA_GetDefaultType, WBPROJECT,
TAG_DONE);
}
err = IconControl(dobj,
ICONCTRLA_GetImageDataFormat,&format,
ICONCTRLA_GetImageData1,&icondata1,
ICONCTRLA_GetImageData2,&icondata2,
ICONCTRLA_GetWidth,&width,
ICONCTRLA_GetHeight,&height,
TAG_DONE);
/* Check icon is direct mapped (truecolour).
* Quite a bit more code is needed for palette mapped and planar icons,
* and OS4 default icons should all be truecolour anyway. */
if(format == IDFMT_DIRECTMAPPED)
{
if ((icon != NULL) && (content_get_type(icon) == CONTENT_ICO))
{
nsico_set_bitmap_from_size(icon, 16, 16);
}
if ((icon != NULL) && (content_get_bitmap(icon) != NULL))
{
bm = ami_getcachenativebm(content_get_bitmap(icon), 16, 16, NULL);
}
if(bm)
{
BltBitMapTags(BLITA_SrcX, 0,
BLITA_SrcY, 0,
BLITA_DestX, width - 16,
BLITA_DestY, height - 16,
BLITA_Width, 16,
BLITA_Height, 16,
BLITA_Source, bm,
BLITA_Dest, icondata1,
BLITA_SrcType, BLITT_BITMAP,
BLITA_DestType, BLITT_ARGB32,
BLITA_DestBytesPerRow, width * 4,
BLITA_UseSrcAlpha, TRUE,
TAG_DONE);
BltBitMapTags(BLITA_SrcX, 0,
BLITA_SrcY, 0,
BLITA_DestX, width - 16,
BLITA_DestY, height - 16,
BLITA_Width, 16,
BLITA_Height, 16,
BLITA_Source, bm,
BLITA_Dest, icondata2,
BLITA_SrcType, BLITT_BITMAP,
BLITA_DestType, BLITT_ARGB32,
BLITA_DestBytesPerRow, width * 4,
BLITA_UseSrcAlpha, TRUE,
TAG_DONE);
}
}
PutIconTags(path, dobj,
ICONPUTA_NotifyWorkbench, TRUE, TAG_DONE);
}
#endif

View File

@ -27,8 +27,7 @@
#ifdef WITH_AMIGA_ICON
#include <stdbool.h>
struct content;
#include "content/hlcache.h"
struct content_amiga_icon_data {
/* empty */
@ -44,4 +43,5 @@ bool amiga_icon_clone(const struct content *old, struct content *new_content);
#endif /* WITH_AMIGA_ICON */
void ami_superimpose_favicon(char *path, struct hlcache_handle *icon, char *type);
#endif

View File

@ -110,6 +110,7 @@ char *path_to_url(const char *path)
DevNameFromLock(lock, newpath, sizeof newpath, DN_FULLPATH);
UnLock(lock);
}
else strncpy(newpath, path, sizeof newpath);
r = malloc(strlen(newpath) + SLEN("file:///") + 1);