2011-05-10 02:14:08 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Chris Young <chris@unsatisfactorysoftware.co.uk>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* DataTypes animation handler (implementation)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef WITH_AMIGA_DATATYPES
|
|
|
|
#include "amiga/filetype.h"
|
|
|
|
#include "amiga/datatypes.h"
|
|
|
|
#include "amiga/plotters.h"
|
|
|
|
#include "content/content_protected.h"
|
|
|
|
#include "desktop/plotters.h"
|
|
|
|
#include "image/bitmap.h"
|
|
|
|
#include "render/box.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/talloc.h"
|
|
|
|
|
|
|
|
#include <proto/datatypes.h>
|
|
|
|
#include <proto/dos.h>
|
|
|
|
#include <proto/exec.h>
|
|
|
|
#include <proto/intuition.h>
|
|
|
|
#include <datatypes/animationclass.h>
|
|
|
|
#include <datatypes/pictureclass.h>
|
|
|
|
#include <graphics/blitattr.h>
|
|
|
|
#include <intuition/classusr.h>
|
|
|
|
|
|
|
|
typedef struct amiga_dt_anim_content {
|
|
|
|
struct content base;
|
|
|
|
|
2011-08-31 16:12:41 +04:00
|
|
|
struct bitmap *bitmap; /**< Created NetSurf bitmap */
|
|
|
|
|
2011-05-10 02:14:08 +04:00
|
|
|
Object *dto;
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int w;
|
|
|
|
int h;
|
|
|
|
} amiga_dt_anim_content;
|
|
|
|
|
|
|
|
APTR ami_colormap_to_clut(struct ColorMap *cmap);
|
|
|
|
|
|
|
|
static nserror amiga_dt_anim_create(const content_handler *handler,
|
|
|
|
lwc_string *imime_type, const http_parameter *params,
|
|
|
|
llcache_handle *llcache, const char *fallback_charset,
|
|
|
|
bool quirks, struct content **c);
|
|
|
|
static bool amiga_dt_anim_convert(struct content *c);
|
|
|
|
static void amiga_dt_anim_reformat(struct content *c, int width, int height);
|
|
|
|
static void amiga_dt_anim_destroy(struct content *c);
|
2011-06-29 12:33:28 +04:00
|
|
|
static bool amiga_dt_anim_redraw(struct content *c,
|
2011-06-30 19:48:07 +04:00
|
|
|
struct content_redraw_data *data, const struct rect *clip,
|
|
|
|
const struct redraw_context *ctx);
|
2011-05-10 02:14:08 +04:00
|
|
|
static void amiga_dt_anim_open(struct content *c, struct browser_window *bw,
|
|
|
|
struct content *page, struct box *box,
|
|
|
|
struct object_params *params);
|
|
|
|
static void amiga_dt_anim_close(struct content *c);
|
|
|
|
static nserror amiga_dt_anim_clone(const struct content *old, struct content **newc);
|
2011-09-03 13:27:42 +04:00
|
|
|
static content_type amiga_dt_anim_content_type(void);
|
2011-05-10 02:14:08 +04:00
|
|
|
|
2011-08-31 16:12:41 +04:00
|
|
|
static void *amiga_dt_anim_get_internal(const struct content *c, void *context)
|
|
|
|
{
|
|
|
|
amiga_dt_anim_content *adta_c = (amiga_dt_anim_content *)c;
|
|
|
|
|
|
|
|
return adta_c->bitmap;
|
|
|
|
}
|
|
|
|
|
2011-05-10 02:14:08 +04:00
|
|
|
static const content_handler amiga_dt_anim_content_handler = {
|
|
|
|
.create = amiga_dt_anim_create,
|
|
|
|
.data_complete = amiga_dt_anim_convert,
|
|
|
|
.reformat = amiga_dt_anim_reformat,
|
|
|
|
.destroy = amiga_dt_anim_destroy,
|
|
|
|
.redraw = amiga_dt_anim_redraw,
|
|
|
|
.open = amiga_dt_anim_open,
|
|
|
|
.close = amiga_dt_anim_close,
|
|
|
|
.clone = amiga_dt_anim_clone,
|
2011-08-31 16:12:41 +04:00
|
|
|
.get_internal = amiga_dt_anim_get_internal,
|
2011-05-10 02:14:08 +04:00
|
|
|
.type = amiga_dt_anim_content_type,
|
|
|
|
.no_share = false,
|
|
|
|
};
|
|
|
|
|
|
|
|
nserror amiga_dt_anim_init(void)
|
|
|
|
{
|
|
|
|
char dt_mime[50];
|
|
|
|
struct DataType *dt, *prevdt = NULL;
|
|
|
|
lwc_string *type;
|
|
|
|
lwc_error lerror;
|
|
|
|
nserror error;
|
|
|
|
BPTR fh = 0;
|
2011-05-10 23:32:21 +04:00
|
|
|
struct Node *node = NULL;
|
2011-05-10 02:14:08 +04:00
|
|
|
|
|
|
|
while((dt = ObtainDataType(DTST_RAM, NULL,
|
|
|
|
DTA_DataType, prevdt,
|
2011-05-11 02:09:32 +04:00
|
|
|
DTA_GroupID, GID_ANIMATION,
|
2011-05-10 02:14:08 +04:00
|
|
|
TAG_DONE)) != NULL)
|
|
|
|
{
|
|
|
|
ReleaseDataType(prevdt);
|
|
|
|
prevdt = dt;
|
|
|
|
|
2011-05-10 23:32:21 +04:00
|
|
|
do {
|
|
|
|
node = ami_mime_from_datatype(dt, &type, node);
|
2011-05-10 02:14:08 +04:00
|
|
|
|
2011-05-10 23:32:21 +04:00
|
|
|
if(node)
|
|
|
|
{
|
2011-09-16 02:31:16 +04:00
|
|
|
error = content_factory_register_handler(
|
|
|
|
lwc_string_data(type),
|
2011-05-10 23:32:21 +04:00
|
|
|
&amiga_dt_anim_content_handler);
|
2011-05-10 02:14:08 +04:00
|
|
|
|
2011-05-10 23:32:21 +04:00
|
|
|
if (error != NSERROR_OK)
|
|
|
|
return error;
|
|
|
|
}
|
2011-05-10 02:14:08 +04:00
|
|
|
|
2011-05-10 23:32:21 +04:00
|
|
|
}while (node != NULL);
|
2011-05-10 02:14:08 +04:00
|
|
|
|
2011-05-10 23:32:21 +04:00
|
|
|
}
|
2011-05-10 02:14:08 +04:00
|
|
|
|
2011-05-10 23:32:21 +04:00
|
|
|
ReleaseDataType(prevdt);
|
2011-05-10 02:14:08 +04:00
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nserror amiga_dt_anim_create(const content_handler *handler,
|
|
|
|
lwc_string *imime_type, const http_parameter *params,
|
|
|
|
llcache_handle *llcache, const char *fallback_charset,
|
|
|
|
bool quirks, struct content **c)
|
|
|
|
{
|
|
|
|
amiga_dt_anim_content *plugin;
|
|
|
|
nserror error;
|
|
|
|
|
|
|
|
plugin = talloc_zero(0, amiga_dt_anim_content);
|
|
|
|
if (plugin == NULL)
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
|
|
|
|
error = content__init(&plugin->base, handler, imime_type, params,
|
|
|
|
llcache, fallback_charset, quirks);
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
talloc_free(plugin);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
*c = (struct content *) plugin;
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool amiga_dt_anim_convert(struct content *c)
|
|
|
|
{
|
|
|
|
LOG(("amiga_dt_anim_convert"));
|
|
|
|
|
|
|
|
amiga_dt_anim_content *plugin = (amiga_dt_anim_content *) c;
|
|
|
|
union content_msg_data msg_data;
|
|
|
|
int width, height;
|
|
|
|
char title[100];
|
|
|
|
const uint8 *data;
|
|
|
|
UBYTE *bm_buffer;
|
|
|
|
ULONG size;
|
|
|
|
Object *dto;
|
|
|
|
struct BitMapHeader *bmh;
|
|
|
|
unsigned int bm_flags = BITMAP_NEW | BITMAP_OPAQUE;
|
|
|
|
int bm_format = PBPAFMT_RGBA;
|
|
|
|
struct adtFrame adt_frame;
|
|
|
|
APTR clut;
|
|
|
|
|
|
|
|
data = (uint8 *)content__get_source_data(c, &size);
|
|
|
|
|
|
|
|
if(plugin->dto = NewDTObject(NULL,
|
|
|
|
DTA_SourceType, DTST_MEMORY,
|
|
|
|
DTA_SourceAddress, data,
|
|
|
|
DTA_SourceSize, size,
|
|
|
|
DTA_GroupID, GID_ANIMATION,
|
|
|
|
TAG_DONE))
|
|
|
|
{
|
|
|
|
if(GetDTAttrs(plugin->dto, PDTA_BitMapHeader, &bmh, TAG_DONE))
|
|
|
|
{
|
|
|
|
width = (int)bmh->bmh_Width;
|
|
|
|
height = (int)bmh->bmh_Height;
|
|
|
|
|
2011-08-31 16:12:41 +04:00
|
|
|
plugin->bitmap = bitmap_create(width, height, bm_flags);
|
|
|
|
if (!plugin->bitmap) {
|
2011-05-10 02:14:08 +04:00
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-08-31 16:12:41 +04:00
|
|
|
bm_buffer = bitmap_get_buffer(plugin->bitmap);
|
2011-05-10 02:14:08 +04:00
|
|
|
|
|
|
|
adt_frame.MethodID = ADTM_LOADFRAME;
|
|
|
|
adt_frame.alf_TimeStamp = 0;
|
2011-09-03 02:09:23 +04:00
|
|
|
IDoMethodA(plugin->dto, (Msg)&adt_frame);
|
2011-05-10 02:14:08 +04:00
|
|
|
|
|
|
|
clut = ami_colormap_to_clut(adt_frame.alf_CMap);
|
|
|
|
|
|
|
|
BltBitMapTags(
|
|
|
|
BLITA_Width, width,
|
|
|
|
BLITA_Height, height,
|
|
|
|
BLITA_Source, adt_frame.alf_BitMap,
|
|
|
|
BLITA_SrcType, BLITT_BITMAP,
|
|
|
|
BLITA_Dest, bm_buffer,
|
|
|
|
BLITA_DestType, BLITT_RGB24,
|
|
|
|
BLITA_DestBytesPerRow, width,
|
|
|
|
BLITA_CLUT, clut,
|
|
|
|
TAG_DONE);
|
|
|
|
|
|
|
|
FreeVec(clut);
|
|
|
|
|
|
|
|
adt_frame.MethodID = ADTM_UNLOADFRAME;
|
2011-09-03 02:09:23 +04:00
|
|
|
IDoMethodA(plugin->dto, (Msg)&adt_frame);
|
2011-05-10 02:14:08 +04:00
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
|
|
|
|
c->width = width;
|
|
|
|
c->height = height;
|
|
|
|
|
|
|
|
/*
|
|
|
|
snprintf(title, sizeof(title), "image (%lux%lu, %lu bytes)",
|
|
|
|
width, height, size);
|
|
|
|
content__set_title(c, title);
|
|
|
|
*/
|
|
|
|
|
2011-08-31 16:12:41 +04:00
|
|
|
bitmap_modified(plugin->bitmap);
|
2011-05-10 02:14:08 +04:00
|
|
|
|
|
|
|
content_set_ready(c);
|
|
|
|
content_set_done(c);
|
|
|
|
|
|
|
|
content_set_status(c, "");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void amiga_dt_anim_destroy(struct content *c)
|
|
|
|
{
|
|
|
|
amiga_dt_anim_content *plugin = (amiga_dt_anim_content *) c;
|
|
|
|
|
|
|
|
LOG(("amiga_dt_anim_destroy"));
|
|
|
|
|
2011-08-31 16:12:41 +04:00
|
|
|
if (plugin->bitmap != NULL)
|
|
|
|
bitmap_destroy(plugin->bitmap);
|
2011-05-10 02:14:08 +04:00
|
|
|
|
|
|
|
DisposeDTObject(plugin->dto);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-06-29 12:33:28 +04:00
|
|
|
bool amiga_dt_anim_redraw(struct content *c,
|
2011-06-30 19:48:07 +04:00
|
|
|
struct content_redraw_data *data, const struct rect *clip,
|
|
|
|
const struct redraw_context *ctx)
|
2011-05-10 02:14:08 +04:00
|
|
|
{
|
|
|
|
amiga_dt_anim_content *plugin = (amiga_dt_anim_content *) c;
|
2011-08-31 16:12:41 +04:00
|
|
|
bitmap_flags_t flags = BITMAPF_NONE;
|
2011-05-10 02:14:08 +04:00
|
|
|
|
|
|
|
LOG(("amiga_dt_anim_redraw"));
|
|
|
|
|
2011-06-29 12:33:28 +04:00
|
|
|
if (data->repeat_x)
|
2011-05-10 02:14:08 +04:00
|
|
|
flags |= BITMAPF_REPEAT_X;
|
2011-06-29 12:33:28 +04:00
|
|
|
if (data->repeat_y)
|
2011-05-10 02:14:08 +04:00
|
|
|
flags |= BITMAPF_REPEAT_Y;
|
|
|
|
|
2011-06-30 19:48:07 +04:00
|
|
|
return ctx->plot->bitmap(data->x, data->y, data->width, data->height,
|
2011-08-31 16:12:41 +04:00
|
|
|
plugin->bitmap, data->background_colour, flags);
|
2011-05-10 02:14:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a window containing a CONTENT_PLUGIN being opened.
|
|
|
|
*
|
|
|
|
* \param c content that has been opened
|
|
|
|
* \param bw browser window containing the content
|
|
|
|
* \param page content of type CONTENT_HTML containing c, or 0 if not an
|
|
|
|
* object within a page
|
|
|
|
* \param box box containing c, or 0 if not an object
|
|
|
|
* \param params object parameters, or 0 if not an object
|
|
|
|
*/
|
|
|
|
void amiga_dt_anim_open(struct content *c, struct browser_window *bw,
|
|
|
|
struct content *page, struct box *box,
|
|
|
|
struct object_params *params)
|
|
|
|
{
|
|
|
|
LOG(("amiga_dt_anim_open"));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void amiga_dt_anim_close(struct content *c)
|
|
|
|
{
|
|
|
|
LOG(("amiga_dt_anim_close"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void amiga_dt_anim_reformat(struct content *c, int width, int height)
|
|
|
|
{
|
|
|
|
LOG(("amiga_dt_anim_reformat"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nserror amiga_dt_anim_clone(const struct content *old, struct content **newc)
|
|
|
|
{
|
|
|
|
amiga_dt_anim_content *plugin;
|
|
|
|
nserror error;
|
|
|
|
|
|
|
|
LOG(("amiga_dt_anim_clone"));
|
|
|
|
|
|
|
|
plugin = talloc_zero(0, amiga_dt_anim_content);
|
|
|
|
if (plugin == NULL)
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
|
|
|
|
error = content__clone(old, &plugin->base);
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
content_destroy(&plugin->base);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We "clone" the old content by replaying conversion */
|
|
|
|
if (old->status == CONTENT_STATUS_READY ||
|
|
|
|
old->status == CONTENT_STATUS_DONE) {
|
|
|
|
if (amiga_dt_anim_convert(&plugin->base) == false) {
|
|
|
|
content_destroy(&plugin->base);
|
|
|
|
return NSERROR_CLONE_FAILED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*newc = (struct content *) plugin;
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-03 13:27:42 +04:00
|
|
|
content_type amiga_dt_anim_content_type(void)
|
2011-05-10 02:14:08 +04:00
|
|
|
{
|
|
|
|
return CONTENT_IMAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
APTR ami_colormap_to_clut(struct ColorMap *cmap)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
UBYTE *clut = AllocVec(256 * 4, MEMF_CLEAR);
|
|
|
|
ULONG colour[3 * 256];
|
|
|
|
|
|
|
|
if(!clut) return NULL;
|
|
|
|
|
|
|
|
/* Get the palette from the ColorMap */
|
|
|
|
GetRGB32(cmap, 0, 256, (ULONG *)&colour);
|
|
|
|
|
|
|
|
/* convert it to a table of ARGB values */
|
|
|
|
for(i = 0; i < 1024; i += 4)
|
|
|
|
{
|
|
|
|
clut[i] = (0xff << 24) |
|
|
|
|
((colour[i] & 0xff000000) >> 8) |
|
|
|
|
((colour[i + 1] & 0xff000000) >> 16) |
|
|
|
|
((colour[i + 2] & 0xff000000) >> 24);
|
|
|
|
}
|
|
|
|
|
|
|
|
return clut;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|