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
|
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"
|
2012-04-06 21:05:25 +04:00
|
|
|
#include "image/image_cache.h"
|
2011-03-06 16:58:02 +03:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
|
|
|
|
#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
|
|
|
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
|
|
|
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)
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2012-10-28 21:35:55 +04:00
|
|
|
Object *amiga_dt_picture_newdtobject(struct amiga_dt_picture_content *adt)
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
TAG_DONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return adt->dto;
|
|
|
|
}
|
|
|
|
|
2012-10-28 21:59:57 +04:00
|
|
|
char *amiga_dt_picture_datatype(struct content *c)
|
|
|
|
{
|
|
|
|
const uint8 *data;
|
|
|
|
ULONG size;
|
|
|
|
struct DataType *dt;
|
|
|
|
char *filetype = NULL;
|
|
|
|
|
|
|
|
data = (uint8 *)content__get_source_data(c, &size);
|
|
|
|
|
|
|
|
if(dt = ObtainDataType(DTST_MEMORY, NULL,
|
|
|
|
DTA_SourceAddress, data,
|
|
|
|
DTA_SourceSize, size,
|
|
|
|
DTA_GroupID, GID_PICTURE,
|
|
|
|
TAG_DONE)) {
|
|
|
|
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;
|
|
|
|
unsigned int bm_flags = BITMAP_NEW;
|
2013-03-09 19:29:30 +04:00
|
|
|
#ifdef __amigaos4__
|
2012-04-06 21:05:25 +04:00
|
|
|
int bm_format = PBPAFMT_RGBA;
|
2013-03-09 19:29:30 +04:00
|
|
|
#else
|
|
|
|
int bm_format = PBPAFMT_ARGB;
|
|
|
|
#endif
|
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
|
|
|
|
2012-10-31 00:20:39 +04:00
|
|
|
if(dto = amiga_dt_picture_newdtobject(adt))
|
2012-04-06 21:05:25 +04:00
|
|
|
{
|
|
|
|
bitmap = bitmap_create(c->width, c->height, bm_flags);
|
|
|
|
if (!bitmap) {
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bm_buffer = bitmap_get_buffer(bitmap);
|
|
|
|
|
|
|
|
IDoMethod(dto, PDTM_READPIXELARRAY,
|
|
|
|
bm_buffer, bm_format, bitmap_get_rowstride(bitmap),
|
|
|
|
0, 0, c->width, c->height);
|
2013-03-09 19:29:30 +04:00
|
|
|
#ifndef __amigaos4__
|
|
|
|
ami_bitmap_argb_to_rgba(bitmap);
|
|
|
|
#endif
|
2012-08-05 17:02:32 +04:00
|
|
|
bitmap_set_opaque(bitmap, 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
|
|
|
|
|
|
|
union content_msg_data msg_data;
|
|
|
|
int width, height;
|
2012-10-28 21:59:57 +04:00
|
|
|
char *title;
|
2011-03-06 16:58:02 +03:00
|
|
|
UBYTE *bm_buffer;
|
|
|
|
Object *dto;
|
|
|
|
struct BitMapHeader *bmh;
|
|
|
|
unsigned int bm_flags = BITMAP_NEW;
|
|
|
|
int bm_format = PBPAFMT_RGBA;
|
2012-10-28 21:59:57 +04:00
|
|
|
char *filetype;
|
2011-03-06 16:58:02 +03:00
|
|
|
|
2012-10-28 21:35:55 +04:00
|
|
|
if(dto = amiga_dt_picture_newdtobject((struct amiga_dt_picture_content *)c))
|
2011-03-06 16:58:02 +03:00
|
|
|
{
|
2012-04-06 21:05:25 +04:00
|
|
|
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 */
|
|
|
|
if(filetype = amiga_dt_picture_datatype(c)) {
|
|
|
|
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
|