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
This commit is contained in:
Chris Young 2009-05-16 17:04:28 +00:00
parent 478d953ea5
commit 08d0c16822
5 changed files with 62 additions and 82 deletions

View File

@ -23,8 +23,11 @@
#include <proto/picasso96api.h>
#include <graphics/composite.h>
#include "amiga/options.h"
#include <proto/iffparse.h>
#include <proto/datatypes.h>
#include <datatypes/pictureclass.h>
#include <proto/dos.h>
#include <proto/intuition.h>
#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;

View File

@ -20,6 +20,7 @@
#define AMIGA_BITMAP_H
#include <exec/types.h>
#include <proto/graphics.h>
#include <intuition/classusr.h>
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

View File

@ -28,9 +28,8 @@
#include "utils/utf8.h"
#include "desktop/selection.h"
#include <datatypes/pictureclass.h>
#include <proto/utility.h>
#include <proto/dos.h>
#include "utils/messages.h"
#include <proto/datatypes.h>
#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;
}

View File

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

View File

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