summaryrefslogtreecommitdiff
path: root/amiga/icon.c
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2010-10-31 11:14:26 +0000
committerChris Young <chris@unsatisfactorysoftware.co.uk>2010-10-31 11:14:26 +0000
commit001b401890af4e75013f1154af7861efb130f659 (patch)
tree4bb69e5eb9637e325bc16f4009badf003218fcc9 /amiga/icon.c
parente5c144af9536e88be364b3cd24dba3da5c45b573 (diff)
downloadnetsurf-001b401890af4e75013f1154af7861efb130f659.tar.gz
netsurf-001b401890af4e75013f1154af7861efb130f659.tar.bz2
Support ColourIcons
svn path=/trunk/netsurf/; revision=10928
Diffstat (limited to 'amiga/icon.c')
-rw-r--r--amiga/icon.c168
1 files changed, 160 insertions, 8 deletions
diff --git a/amiga/icon.c b/amiga/icon.c
index 5c0395f4b..5eb3a43f5 100644
--- a/amiga/icon.c
+++ b/amiga/icon.c
@@ -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