2011-03-06 16:58:02 +03:00
|
|
|
/*
|
2012-10-31 00:20:39 +04:00
|
|
|
* Copyright 2011 - 2012 Chris Young <chris@unsatisfactorysoftware.co.uk>
|
2011-03-06 16:58:02 +03:00
|
|
|
*
|
|
|
|
* 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
|
2015-01-11 02:46:17 +03:00
|
|
|
#include "amiga/os3support.h"
|
|
|
|
|
2015-04-17 00:36:29 +03:00
|
|
|
#include <stdbool.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
|
|
|
|
2015-04-17 00:36:29 +03:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "content/content_protected.h"
|
|
|
|
#include "desktop/plotters.h"
|
|
|
|
#include "image/bitmap.h"
|
|
|
|
#include "image/image_cache.h"
|
|
|
|
|
|
|
|
#include "amiga/bitmap.h"
|
|
|
|
#include "amiga/filetype.h"
|
|
|
|
#include "amiga/datatypes.h"
|
|
|
|
|
|
|
|
|
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 nserror amiga_dt_picture_clone(const struct content *old, struct content **newc);
|
2012-10-28 21:35:55 +04:00
|
|
|
static void amiga_dt_picture_destroy(struct content *c);
|
2011-08-31 16:12:41 +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,
|
2012-10-28 21:35:55 +04:00
|
|
|
.destroy = amiga_dt_picture_destroy,
|
2012-04-06 21:05:25 +04:00
|
|
|
.redraw = image_cache_redraw,
|
2011-05-09 19:32:34 +04:00
|
|
|
.clone = amiga_dt_picture_clone,
|
2012-04-06 21:05:25 +04:00
|
|
|
.get_internal = image_cache_get_internal,
|
|
|
|
.type = image_cache_content_type,
|
2011-05-09 19:32:34 +04:00
|
|
|
.no_share = false,
|
2011-05-07 00:40:09 +04:00
|
|
|
};
|
|
|
|
|
2012-10-28 21:35:55 +04:00
|
|
|
struct amiga_dt_picture_content {
|
|
|
|
struct content c;
|
|
|
|
Object *dto;
|
|
|
|
};
|
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
|
|
|
struct DataType *dt, *prevdt = NULL;
|
|
|
|
lwc_string *type;
|
|
|
|
nserror error;
|
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)
|
|
|
|
{
|
2015-01-30 03:05:40 +03:00
|
|
|
if(prevdt) ReleaseDataType(prevdt);
|
2011-05-07 00:40:09 +04:00
|
|
|
prevdt = dt;
|
|
|
|
|
2011-05-10 02:11:18 +04:00
|
|
|
do {
|
|
|
|
node = ami_mime_from_datatype(dt, &type, node);
|
|
|
|
|
|
|
|
if(node)
|
|
|
|
{
|
2011-09-16 02:31:16 +04:00
|
|
|
error = content_factory_register_handler(
|
|
|
|
lwc_string_data(type),
|
2011-05-10 02:11:18 +04:00
|
|
|
&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
|
|
|
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)
|
|
|
|
{
|
2012-10-28 21:35:55 +04:00
|
|
|
struct amiga_dt_picture_content *adt;
|
2011-05-07 00:40:09 +04:00
|
|
|
nserror error;
|
|
|
|
|
2012-10-28 21:35:55 +04:00
|
|
|
adt = calloc(1, sizeof(struct amiga_dt_picture_content));
|
2012-04-06 21:05:25 +04:00
|
|
|
if (adt == NULL)
|
2011-05-07 00:40:09 +04:00
|
|
|
return NSERROR_NOMEM;
|
|
|
|
|
2012-10-28 21:35:55 +04:00
|
|
|
error = content__init((struct content *)adt, handler, imime_type, params,
|
2011-05-07 00:40:09 +04:00
|
|
|
llcache, fallback_charset, quirks);
|
|
|
|
if (error != NSERROR_OK) {
|
2012-10-03 22:24:58 +04:00
|
|
|
free(adt);
|
2011-05-07 00:40:09 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2012-10-28 21:35:55 +04:00
|
|
|
*c = (struct content *)adt;
|
2011-05-07 00:40:09 +04:00
|
|
|
|
|
|
|
return NSERROR_OK;
|
2011-03-06 16:58:02 +03:00
|
|
|
}
|
|
|
|
|
2014-11-09 04:07:35 +03:00
|
|
|
static Object *amiga_dt_picture_newdtobject(struct amiga_dt_picture_content *adt)
|
2012-10-28 21:35:55 +04:00
|
|
|
{
|
|
|
|
const uint8 *data;
|
|
|
|
ULONG size;
|
|
|
|
|
|
|
|
if(adt->dto == NULL) {
|
|
|
|
data = (uint8 *)content__get_source_data((struct content *)adt, &size);
|
|
|
|
|
|
|
|
adt->dto = NewDTObject(NULL,
|
|
|
|
DTA_SourceType, DTST_MEMORY,
|
|
|
|
DTA_SourceAddress, data,
|
|
|
|
DTA_SourceSize, size,
|
|
|
|
DTA_GroupID, GID_PICTURE,
|
|
|
|
PDTA_DestMode, PMODE_V43,
|
2013-10-12 18:43:52 +04:00
|
|
|
PDTA_PromoteMask, TRUE,
|
2012-10-28 21:35:55 +04:00
|
|
|
TAG_DONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return adt->dto;
|
|
|
|
}
|
|
|
|
|
2014-11-09 04:07:35 +03:00
|
|
|
static char *amiga_dt_picture_datatype(struct content *c)
|
2012-10-28 21:59:57 +04:00
|
|
|
{
|
|
|
|
const uint8 *data;
|
|
|
|
ULONG size;
|
|
|
|
struct DataType *dt;
|
|
|
|
char *filetype = NULL;
|
|
|
|
|
|
|
|
data = (uint8 *)content__get_source_data(c, &size);
|
|
|
|
|
2014-11-09 04:07:35 +03:00
|
|
|
if((dt = ObtainDataType(DTST_MEMORY, NULL,
|
2012-10-28 21:59:57 +04:00
|
|
|
DTA_SourceAddress, data,
|
|
|
|
DTA_SourceSize, size,
|
|
|
|
DTA_GroupID, GID_PICTURE,
|
2014-11-09 04:07:35 +03:00
|
|
|
TAG_DONE))) {
|
2012-10-28 21:59:57 +04:00
|
|
|
filetype = strdup(dt->dtn_Header->dth_Name);
|
|
|
|
ReleaseDataType(dt);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(filetype == NULL) filetype = strdup("DataTypes");
|
|
|
|
return filetype;
|
|
|
|
}
|
|
|
|
|
2012-04-06 21:05:25 +04:00
|
|
|
static struct bitmap *amiga_dt_picture_cache_convert(struct content *c)
|
|
|
|
{
|
|
|
|
LOG(("amiga_dt_picture_cache_convert"));
|
|
|
|
|
|
|
|
union content_msg_data msg_data;
|
|
|
|
UBYTE *bm_buffer;
|
|
|
|
Object *dto;
|
|
|
|
struct bitmap *bitmap;
|
2012-10-31 00:20:39 +04:00
|
|
|
struct amiga_dt_picture_content *adt = (struct amiga_dt_picture_content *)c;
|
2012-04-06 21:05:25 +04:00
|
|
|
|
2014-11-09 04:07:35 +03:00
|
|
|
if((dto = amiga_dt_picture_newdtobject(adt)))
|
2012-04-06 21:05:25 +04:00
|
|
|
{
|
2015-04-17 00:36:29 +03:00
|
|
|
bitmap = amiga_bitmap_create(c->width, c->height, BITMAP_NEW);
|
2012-04-06 21:05:25 +04:00
|
|
|
if (!bitmap) {
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-04-17 00:36:29 +03:00
|
|
|
bm_buffer = amiga_bitmap_get_buffer(bitmap);
|
2012-04-06 21:05:25 +04:00
|
|
|
|
|
|
|
IDoMethod(dto, PDTM_READPIXELARRAY,
|
2015-04-17 00:36:29 +03:00
|
|
|
bm_buffer, PBPAFMT_RGBA,
|
|
|
|
amiga_bitmap_get_rowstride(bitmap),
|
2012-04-06 21:05:25 +04:00
|
|
|
0, 0, c->width, c->height);
|
2015-02-02 21:54:08 +03:00
|
|
|
|
2015-04-17 00:36:29 +03:00
|
|
|
amiga_bitmap_set_opaque(bitmap, amiga_bitmap_test_opaque(bitmap));
|
2012-10-31 00:20:39 +04:00
|
|
|
|
|
|
|
DisposeDTObject(dto);
|
|
|
|
adt->dto = NULL;
|
2012-04-06 21:05:25 +04:00
|
|
|
}
|
|
|
|
else return NULL;
|
|
|
|
|
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
int width, height;
|
2012-10-28 21:59:57 +04:00
|
|
|
char *title;
|
2011-03-06 16:58:02 +03:00
|
|
|
Object *dto;
|
|
|
|
struct BitMapHeader *bmh;
|
2012-10-28 21:59:57 +04:00
|
|
|
char *filetype;
|
2011-03-06 16:58:02 +03:00
|
|
|
|
2014-11-09 04:07:35 +03:00
|
|
|
if((dto = amiga_dt_picture_newdtobject((struct amiga_dt_picture_content *)c))) {
|
|
|
|
if(GetDTAttrs(dto, PDTA_BitMapHeader, &bmh, TAG_DONE)) {
|
2011-03-06 16:58:02 +03:00
|
|
|
width = (int)bmh->bmh_Width;
|
|
|
|
height = (int)bmh->bmh_Height;
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
|
|
|
|
c->width = width;
|
|
|
|
c->height = height;
|
2012-04-06 21:05:25 +04:00
|
|
|
c->size = width * height * 4;
|
|
|
|
|
2012-10-28 21:59:57 +04:00
|
|
|
/* set title text */
|
2014-11-09 04:07:35 +03:00
|
|
|
if((filetype = amiga_dt_picture_datatype(c))) {
|
2012-10-28 21:59:57 +04:00
|
|
|
title = messages_get_buff("DataTypesTitle",
|
|
|
|
nsurl_access_leaf(llcache_handle_get_url(c->llcache)),
|
|
|
|
filetype, c->width, c->height);
|
|
|
|
if (title != NULL) {
|
|
|
|
content__set_title(c, title);
|
|
|
|
free(title);
|
|
|
|
}
|
|
|
|
free(filetype);
|
|
|
|
}
|
|
|
|
|
2012-04-06 21:05:25 +04:00
|
|
|
image_cache_add(c, NULL, amiga_dt_picture_cache_convert);
|
2011-03-06 16:58:02 +03:00
|
|
|
|
|
|
|
content_set_ready(c);
|
|
|
|
content_set_done(c);
|
|
|
|
content_set_status(c, "");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-04-06 21:05:25 +04:00
|
|
|
struct content *adt;
|
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
|
|
|
|
2012-10-03 22:24:58 +04:00
|
|
|
adt = calloc(1, sizeof(struct content));
|
2012-04-06 21:05:25 +04:00
|
|
|
if (adt == NULL)
|
2011-05-07 00:40:09 +04:00
|
|
|
return NSERROR_NOMEM;
|
|
|
|
|
2012-04-06 21:05:25 +04:00
|
|
|
error = content__clone(old, adt);
|
2011-05-07 00:40:09 +04:00
|
|
|
if (error != NSERROR_OK) {
|
2012-04-06 21:05:25 +04:00
|
|
|
content_destroy(adt);
|
2011-05-07 00:40:09 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We "clone" the old content by replaying conversion */
|
2011-08-31 16:12:41 +04:00
|
|
|
if ((old->status == CONTENT_STATUS_READY) ||
|
|
|
|
(old->status == CONTENT_STATUS_DONE)) {
|
2012-04-06 21:05:25 +04:00
|
|
|
if (amiga_dt_picture_convert(adt) == false) {
|
|
|
|
content_destroy(adt);
|
2011-05-07 00:40:09 +04:00
|
|
|
return NSERROR_CLONE_FAILED;
|
|
|
|
}
|
2011-03-06 16:58:02 +03:00
|
|
|
}
|
|
|
|
|
2012-04-06 21:05:25 +04:00
|
|
|
*newc = adt;
|
2011-05-07 00:40:09 +04:00
|
|
|
|
|
|
|
return NSERROR_OK;
|
2011-03-06 16:58:02 +03:00
|
|
|
}
|
|
|
|
|
2012-10-28 21:35:55 +04:00
|
|
|
static void amiga_dt_picture_destroy(struct content *c)
|
|
|
|
{
|
|
|
|
struct amiga_dt_picture_content *adt = (struct amiga_dt_picture_content *)c;
|
|
|
|
|
|
|
|
DisposeDTObject(adt->dto);
|
|
|
|
adt->dto = NULL;
|
|
|
|
|
|
|
|
image_cache_destroy(c);
|
|
|
|
}
|
|
|
|
|
2011-03-06 16:58:02 +03:00
|
|
|
#endif
|