From 08d0c1682250763c0f8300e54bfa877345edd5fb Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 16 May 2009 17:04:28 +0000 Subject: [PATCH] Copy and save images as IFF ILBM attempt 2. Copy now works, saving just creates an empty file - probably something wrong with my DTM_WRITE call. svn path=/trunk/netsurf/; revision=7517 --- amiga/bitmap.c | 60 ++++++++++++++++++++++++++++------- amiga/bitmap.h | 3 +- amiga/clipboard.c | 74 +++++--------------------------------------- amiga/clipboard.h | 3 +- amiga/context_menu.c | 4 ++- 5 files changed, 62 insertions(+), 82 deletions(-) diff --git a/amiga/bitmap.c b/amiga/bitmap.c index be34e1951..50627155f 100644 --- a/amiga/bitmap.c +++ b/amiga/bitmap.c @@ -23,8 +23,11 @@ #include #include #include "amiga/options.h" -#include +#include +#include #include +#include +#include "utils/messages.h" /** * Create a bitmap. @@ -125,20 +128,18 @@ void bitmap_destroy(void *bitmap) bool bitmap_save(void *bitmap, const char *path, unsigned flags) { - struct IFFHandle *iffh; - struct bitmap *bm = bitmap; + BPTR fh = 0; + Object *dto = NULL; - if(iffh = AllocIFF()) + if(dto = ami_datatype_object_from_bitmap(bitmap)) { - if(iffh->iff_Stream = Open(path,MODE_NEWFILE)) + if(fh = Open(path,MODE_NEWFILE)) { - InitIFFasDOS(iffh); - ami_easy_clipboard_bitmap(bm,iffh,bm->url,bm->title); - bm->url = NULL; - bm->title = NULL; - Close(iffh->iff_Stream); + DoDTMethod(dto,NULL,NULL,DTM_WRITE,fh,0,NULL); + Close(fh); } - FreeIFF(iffh); + + DisposeDTObject(dto); } return true; @@ -264,6 +265,43 @@ size_t bitmap_get_bpp(void *vbitmap) return 4; } +Object *ami_datatype_object_from_bitmap(struct bitmap *bitmap) +{ + Object *dto; + struct BitMapHeader *bmhd; + + if(dto = NewDTObject(NULL, + DTA_SourceType,DTST_RAM, + DTA_GroupID,GID_PICTURE, + //DTA_BaseName,"ilbm", + PDTA_DestMode,PMODE_V43, + TAG_DONE)) + { + if(GetDTAttrs(dto,PDTA_BitMapHeader,&bmhd,TAG_DONE)) + { + bmhd->bmh_Width = (UWORD)bitmap_get_width(bitmap); + bmhd->bmh_Height = (UWORD)bitmap_get_height(bitmap); + bmhd->bmh_Depth = (UBYTE)bitmap_get_bpp(bitmap) * 8; + bmhd->bmh_Masking = mskHasAlpha; + } + + SetDTAttrs(dto,NULL,NULL, + DTA_ObjName,bitmap->title, + DTA_ObjAnnotation,bitmap->url, + DTA_ObjAuthor,messages_get("NetSurf"), + DTA_NominalHoriz,bitmap_get_width(bitmap), + DTA_NominalVert,bitmap_get_height(bitmap), + PDTA_SourceMode,PMODE_V43, + TAG_DONE); + + IDoMethod(dto,PDTM_WRITEPIXELARRAY,bitmap_get_buffer(bitmap), + PBPAFMT_RGBA,bitmap_get_rowstride(bitmap),0,0, + bitmap_get_width(bitmap),bitmap_get_height(bitmap)); + } + + return dto; +} + struct BitMap *ami_getcachenativebm(struct bitmap *bitmap,int width,int height,struct BitMap *friendbm) { struct RenderInfo ri; diff --git a/amiga/bitmap.h b/amiga/bitmap.h index f3a7c4b89..48dc9d758 100755 --- a/amiga/bitmap.h +++ b/amiga/bitmap.h @@ -20,6 +20,7 @@ #define AMIGA_BITMAP_H #include #include +#include struct bitmap { int width; @@ -34,5 +35,5 @@ struct bitmap { }; struct BitMap *ami_getcachenativebm(struct bitmap *bitmap,int width,int height,struct BitMap *friendbm); - +Object *ami_datatype_object_from_bitmap(struct bitmap *bitmap); #endif diff --git a/amiga/clipboard.c b/amiga/clipboard.c index 5afc2d2fe..94457f40a 100755 --- a/amiga/clipboard.c +++ b/amiga/clipboard.c @@ -28,9 +28,8 @@ #include "utils/utf8.h" #include "desktop/selection.h" #include -#include -#include -#include "utils/messages.h" +#include +#include "amiga/bitmap.h" #ifndef ID_AUTH #define ID_AUTH MAKE_ID('A','U','T','H') @@ -245,72 +244,13 @@ bool ami_easy_clipboard(char *text) return false; } -bool ami_easy_clipboard_bitmap(struct bitmap *bitmap,struct IFFHandle *ih, - char *url,char *name) +bool ami_easy_clipboard_bitmap(struct bitmap *bitmap) { - struct BitMapHeader *bmhd; - uint32 bmdatasize = bitmap_get_width(bitmap) * - bitmap_get_height(bitmap) * - bitmap_get_bpp(bitmap); + Object *dto = NULL; - if(!ih) ih = iffh; - - if(!(OpenIFF(ih,IFFF_WRITE))) + if(dto = ami_datatype_object_from_bitmap(bitmap)) { - if(!(PushChunk(ih,ID_ILBM,ID_FORM,IFFSIZE_UNKNOWN))) - { - if(bmhd = AllocVec(sizeof(struct BitMapHeader),MEMF_CLEAR | MEMF_PRIVATE)) - { - if(!(PushChunk(ih,0,ID_BMHD,sizeof(struct BitMapHeader)))) - { - bmhd->bmh_Width = (UWORD)bitmap_get_width(bitmap); - bmhd->bmh_Height = (UWORD)bitmap_get_height(bitmap); - bmhd->bmh_Depth = (UBYTE)bitmap_get_bpp(bitmap) * 8; - bmhd->bmh_Masking = mskHasAlpha; - WriteChunkBytes(ih,bmhd,sizeof(struct BitMapHeader)); - } - PopChunk(ih); - FreeVec(bmhd); - } - - if(!(PushChunk(ih,0,ID_AUTH,IFFSIZE_UNKNOWN))) - { - STRPTR ilbm_auth = ASPrintf("%s %s",messages_get("NetSurf"),netsurf_version); - WriteChunkBytes(ih,ilbm_auth,strlen(ilbm_auth)); - FreeVec(ilbm_auth); - } - PopChunk(ih); - - if(!(PushChunk(ih,0,ID_NAME,IFFSIZE_UNKNOWN))) - { - WriteChunkBytes(ih,name,strlen(name)); - } - PopChunk(ih); - - if(!(PushChunk(ih,0,ID_ANNO,IFFSIZE_UNKNOWN))) - { - WriteChunkBytes(ih,url,strlen(url)); - } - PopChunk(ih); - - if(!(PushChunk(ih,0,ID_BODY,bmdatasize))) - { - WriteChunkBytes(ih,bitmap_get_buffer(bitmap),bmdatasize); - PopChunk(ih); - CloseIFF(ih); - return true; - } - else - { - PopChunk(ih); - } - } - else - { - PopChunk(ih); - } - CloseIFF(ih); + DoDTMethod(dto,NULL,NULL,DTM_COPY,NULL); + DisposeDTObject(dto); } - - return false; } diff --git a/amiga/clipboard.h b/amiga/clipboard.h index 4afbae138..806420566 100755 --- a/amiga/clipboard.h +++ b/amiga/clipboard.h @@ -22,6 +22,5 @@ void ami_clipboard_init(void); void ami_clipboard_free(void); bool ami_easy_clipboard(char *text); -bool ami_easy_clipboard_bitmap(struct bitmap *bitmap,struct IFFHandle *ih, - char *url,char *name); +bool ami_easy_clipboard_bitmap(struct bitmap *bitmap); #endif diff --git a/amiga/context_menu.c b/amiga/context_menu.c index 97c1ca805..b5f02f0da 100755 --- a/amiga/context_menu.c +++ b/amiga/context_menu.c @@ -280,7 +280,9 @@ uint32 ami_context_menu_hook(struct Hook *hook,Object *item,APTR reserved) case CMID_CLIPOBJ: object = (struct content *)userdata; - ami_easy_clipboard_bitmap(object->bitmap,NULL,object->url,object->title); + object->bitmap->url = object->url; + object->bitmap->title = object->title; + ami_easy_clipboard_bitmap(object->bitmap); break; case CMID_SAVEOBJ: