2011-03-06 16:58:02 +03: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
|
2011-05-07 02:42:37 +04:00
|
|
|
* DataTypes picture handler (implementation)
|
2011-03-06 16:58:02 +03:00
|
|
|
*/
|
|
|
|
|
2011-05-07 02:42:37 +04:00
|
|
|
#ifdef WITH_AMIGA_DATATYPES
|
2011-03-06 16:58:02 +03:00
|
|
|
#include "amiga/filetype.h"
|
2011-05-07 02:42:37 +04:00
|
|
|
#include "amiga/datatypes.h"
|
2011-03-06 16:58:02 +03:00
|
|
|
#include "content/content_protected.h"
|
|
|
|
#include "desktop/plotters.h"
|
2011-05-07 00:40:09 +04:00
|
|
|
#include "image/bitmap.h"
|
2011-03-06 16:58:02 +03:00
|
|
|
#include "render/box.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
2011-05-07 00:40:09 +04:00
|
|
|
#include "utils/talloc.h"
|
2011-03-06 16:58:02 +03:00
|
|
|
|
|
|
|
#include <proto/datatypes.h>
|
2011-05-09 02:18:28 +04:00
|
|
|
#include <proto/dos.h>
|
2011-03-06 16:58:02 +03:00
|
|
|
#include <proto/intuition.h>
|
|
|
|
#include <datatypes/pictureclass.h>
|
2011-05-07 00:40:09 +04:00
|
|
|
#include <intuition/classusr.h>
|
2011-03-06 16:58:02 +03:00
|
|
|
|
2011-05-07 02:42:37 +04:00
|
|
|
typedef struct amiga_dt_picture_content {
|
2011-05-07 00:40:09 +04:00
|
|
|
struct content base;
|
|
|
|
|
|
|
|
Object *dto;
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int w;
|
|
|
|
int h;
|
2011-05-07 02:42:37 +04:00
|
|
|
} amiga_dt_picture_content;
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2011-05-07 02:42:37 +04:00
|
|
|
static nserror amiga_dt_picture_create(const content_handler *handler,
|
2011-05-07 00:40:09 +04:00
|
|
|
lwc_string *imime_type, const http_parameter *params,
|
|
|
|
llcache_handle *llcache, const char *fallback_charset,
|
|
|
|
bool quirks, struct content **c);
|
2011-05-07 02:42:37 +04:00
|
|
|
static bool amiga_dt_picture_convert(struct content *c);
|
|
|
|
static void amiga_dt_picture_destroy(struct content *c);
|
2011-06-29 12:33:28 +04:00
|
|
|
static bool amiga_dt_picture_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-07 02:42:37 +04:00
|
|
|
static nserror amiga_dt_picture_clone(const struct content *old, struct content **newc);
|
|
|
|
static content_type amiga_dt_picture_content_type(lwc_string *mime_type);
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2011-05-07 02:42:37 +04:00
|
|
|
static const content_handler amiga_dt_picture_content_handler = {
|
2011-05-09 19:32:34 +04:00
|
|
|
.create = amiga_dt_picture_create,
|
|
|
|
.data_complete = amiga_dt_picture_convert,
|
|
|
|
.destroy = amiga_dt_picture_destroy,
|
|
|
|
.redraw = amiga_dt_picture_redraw,
|
|
|
|
.clone = amiga_dt_picture_clone,
|
|
|
|
.type = amiga_dt_picture_content_type,
|
|
|
|
.no_share = false,
|
2011-05-07 00:40:09 +04:00
|
|
|
};
|
|
|
|
|
2011-05-09 02:59:48 +04:00
|
|
|
|
2011-05-07 02:42:37 +04:00
|
|
|
nserror amiga_dt_picture_init(void)
|
2011-03-06 16:58:02 +03:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
char dt_mime[50];
|
|
|
|
struct DataType *dt, *prevdt = NULL;
|
|
|
|
lwc_string *type;
|
|
|
|
lwc_error lerror;
|
|
|
|
nserror error;
|
2011-05-07 15:09:23 +04:00
|
|
|
BPTR fh = 0;
|
2011-05-10 02:39:30 +04:00
|
|
|
struct Node *node = NULL;
|
2011-03-06 16:58:02 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
while((dt = ObtainDataType(DTST_RAM, NULL,
|
|
|
|
DTA_DataType, prevdt,
|
|
|
|
DTA_GroupID, GID_PICTURE, // we only support images for now
|
|
|
|
TAG_DONE)) != NULL)
|
|
|
|
{
|
|
|
|
ReleaseDataType(prevdt);
|
|
|
|
prevdt = dt;
|
|
|
|
|
2011-05-10 02:11:18 +04:00
|
|
|
do {
|
|
|
|
node = ami_mime_from_datatype(dt, &type, node);
|
|
|
|
|
|
|
|
if(node)
|
|
|
|
{
|
|
|
|
error = content_factory_register_handler(type,
|
|
|
|
&amiga_dt_picture_content_handler);
|
|
|
|
|
|
|
|
if (error != NSERROR_OK)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
}while (node != NULL);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ReleaseDataType(prevdt);
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-07 02:42:37 +04:00
|
|
|
void amiga_dt_picture_fini(void)
|
2011-05-07 00:40:09 +04:00
|
|
|
{
|
|
|
|
/* Nothing to do */
|
|
|
|
}
|
|
|
|
|
2011-05-07 02:42:37 +04:00
|
|
|
nserror amiga_dt_picture_create(const content_handler *handler,
|
2011-05-07 00:40:09 +04:00
|
|
|
lwc_string *imime_type, const http_parameter *params,
|
|
|
|
llcache_handle *llcache, const char *fallback_charset,
|
|
|
|
bool quirks, struct content **c)
|
|
|
|
{
|
2011-05-07 02:42:37 +04:00
|
|
|
amiga_dt_picture_content *plugin;
|
2011-05-07 00:40:09 +04:00
|
|
|
nserror error;
|
|
|
|
|
2011-05-07 02:42:37 +04:00
|
|
|
plugin = talloc_zero(0, amiga_dt_picture_content);
|
2011-05-07 00:40:09 +04:00
|
|
|
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;
|
2011-03-06 16:58:02 +03:00
|
|
|
}
|
|
|
|
|
2011-05-07 02:42:37 +04:00
|
|
|
bool amiga_dt_picture_convert(struct content *c)
|
2011-03-06 16:58:02 +03:00
|
|
|
{
|
2011-05-07 02:42:37 +04:00
|
|
|
LOG(("amiga_dt_picture_convert"));
|
2011-03-06 16:58:02 +03:00
|
|
|
|
2011-05-07 02:42:37 +04:00
|
|
|
amiga_dt_picture_content *plugin = (amiga_dt_picture_content *) c;
|
2011-03-06 16:58:02 +03:00
|
|
|
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;
|
|
|
|
int bm_format = PBPAFMT_RGBA;
|
|
|
|
|
|
|
|
/* This is only relevant for picture datatypes... */
|
|
|
|
|
|
|
|
data = (uint8 *)content__get_source_data(c, &size);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
if(plugin->dto = NewDTObject(NULL,
|
2011-03-06 16:58:02 +03:00
|
|
|
DTA_SourceType, DTST_MEMORY,
|
|
|
|
DTA_SourceAddress, data,
|
|
|
|
DTA_SourceSize, size,
|
|
|
|
DTA_GroupID, GID_PICTURE,
|
|
|
|
PDTA_DestMode, PMODE_V43,
|
|
|
|
TAG_DONE))
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
if(GetDTAttrs(plugin->dto, PDTA_BitMapHeader, &bmh, TAG_DONE))
|
2011-03-06 16:58:02 +03:00
|
|
|
{
|
|
|
|
width = (int)bmh->bmh_Width;
|
|
|
|
height = (int)bmh->bmh_Height;
|
|
|
|
|
|
|
|
c->bitmap = bitmap_create(width, height, bm_flags);
|
|
|
|
if (!c->bitmap) {
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bm_buffer = bitmap_get_buffer(c->bitmap);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
IDoMethod(plugin->dto, PDTM_READPIXELARRAY,
|
2011-03-06 16:58:02 +03:00
|
|
|
bm_buffer, bm_format, bitmap_get_rowstride(c->bitmap),
|
|
|
|
0, 0, width, height);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
*/
|
|
|
|
|
|
|
|
bitmap_modified(c->bitmap);
|
|
|
|
|
|
|
|
content_set_ready(c);
|
|
|
|
content_set_done(c);
|
|
|
|
|
|
|
|
content_set_status(c, "");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-05-07 02:42:37 +04:00
|
|
|
void amiga_dt_picture_destroy(struct content *c)
|
2011-03-06 16:58:02 +03:00
|
|
|
{
|
2011-05-07 02:42:37 +04:00
|
|
|
amiga_dt_picture_content *plugin = (amiga_dt_picture_content *) c;
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2011-05-07 02:42:37 +04:00
|
|
|
LOG(("amiga_dt_picture_destroy"));
|
2011-03-06 16:58:02 +03:00
|
|
|
|
|
|
|
if (c->bitmap != NULL)
|
|
|
|
bitmap_destroy(c->bitmap);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
DisposeDTObject(plugin->dto);
|
2011-03-06 16:58:02 +03:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-06-29 12:33:28 +04:00
|
|
|
bool amiga_dt_picture_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-03-06 16:58:02 +03:00
|
|
|
{
|
2011-05-07 02:42:37 +04:00
|
|
|
LOG(("amiga_dt_picture_redraw"));
|
2011-05-09 02:18:28 +04:00
|
|
|
bitmap_flags_t flags = BITMAPF_NONE;
|
2011-03-06 16:58:02 +03:00
|
|
|
|
2011-06-29 12:33:28 +04:00
|
|
|
if (data->repeat_x)
|
2011-05-09 02:18:28 +04:00
|
|
|
flags |= BITMAPF_REPEAT_X;
|
2011-06-29 12:33:28 +04:00
|
|
|
if (data->repeat_y)
|
2011-05-09 02:18:28 +04:00
|
|
|
flags |= BITMAPF_REPEAT_Y;
|
2011-03-06 16:58:02 +03:00
|
|
|
|
2011-06-30 19:48:07 +04:00
|
|
|
return ctx->plot->bitmap(data->x, data->y, data->width, data->height,
|
2011-06-29 12:33:28 +04:00
|
|
|
c->bitmap, data->background_colour, flags);
|
2011-03-06 16:58:02 +03:00
|
|
|
}
|
|
|
|
|
2011-05-07 02:42:37 +04:00
|
|
|
nserror amiga_dt_picture_clone(const struct content *old, struct content **newc)
|
2011-03-06 16:58:02 +03:00
|
|
|
{
|
2011-05-07 02:42:37 +04:00
|
|
|
amiga_dt_picture_content *plugin;
|
2011-05-07 00:40:09 +04:00
|
|
|
nserror error;
|
|
|
|
|
2011-05-07 02:42:37 +04:00
|
|
|
LOG(("amiga_dt_picture_clone"));
|
2011-03-06 16:58:02 +03:00
|
|
|
|
2011-05-07 02:42:37 +04:00
|
|
|
plugin = talloc_zero(0, amiga_dt_picture_content);
|
2011-05-07 00:40:09 +04:00
|
|
|
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 */
|
2011-03-06 16:58:02 +03:00
|
|
|
if (old->status == CONTENT_STATUS_READY ||
|
|
|
|
old->status == CONTENT_STATUS_DONE) {
|
2011-05-07 02:42:37 +04:00
|
|
|
if (amiga_dt_picture_convert(&plugin->base) == false) {
|
2011-05-07 00:40:09 +04:00
|
|
|
content_destroy(&plugin->base);
|
|
|
|
return NSERROR_CLONE_FAILED;
|
|
|
|
}
|
2011-03-06 16:58:02 +03:00
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
*newc = (struct content *) plugin;
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
2011-03-06 16:58:02 +03:00
|
|
|
}
|
|
|
|
|
2011-05-07 02:42:37 +04:00
|
|
|
content_type amiga_dt_picture_content_type(lwc_string *mime_type)
|
2011-03-06 16:58:02 +03:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
return CONTENT_IMAGE;
|
2011-03-06 16:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|