2003-09-11 02:46:56 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2003 John M Bell <jmb202@ecs.soton.ac.uk>
|
2007-08-08 20:16:03 +04: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/>.
|
2003-09-11 02:46:56 +04:00
|
|
|
*/
|
|
|
|
|
2004-11-06 22:34:24 +03:00
|
|
|
/** \file
|
|
|
|
* Content for image/x-riscos-sprite (RISC OS implementation).
|
|
|
|
*
|
|
|
|
* No conversion is necessary: we can render RISC OS sprites directly under
|
|
|
|
* RISC OS.
|
|
|
|
*/
|
|
|
|
|
2003-09-11 02:46:56 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2008-07-27 02:29:15 +04:00
|
|
|
#include "oslib/osspriteop.h"
|
2016-05-02 18:03:44 +03:00
|
|
|
|
|
|
|
#include "utils/config.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/config.h"
|
2016-05-02 18:03:44 +03:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/utils.h"
|
2016-05-30 23:05:57 +03:00
|
|
|
#include "netsurf/plotters.h"
|
2016-06-06 10:59:23 +03:00
|
|
|
#include "netsurf/content.h"
|
|
|
|
#include "content/llcache.h"
|
|
|
|
#include "content/content_protected.h"
|
2016-05-02 18:03:44 +03:00
|
|
|
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/gui.h"
|
|
|
|
#include "riscos/image.h"
|
2011-05-09 13:57:40 +04:00
|
|
|
#include "riscos/content-handlers/sprite.h"
|
2003-09-11 02:46:56 +04:00
|
|
|
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_SPRITE
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
typedef struct sprite_content {
|
|
|
|
struct content base;
|
|
|
|
|
|
|
|
void *data;
|
|
|
|
} sprite_content;
|
|
|
|
|
|
|
|
static nserror sprite_create(const content_handler *handler,
|
2016-04-19 01:17:38 +03:00
|
|
|
lwc_string *imime_type, const struct http_parameter *params,
|
2011-05-07 00:40:09 +04:00
|
|
|
llcache_handle *llcache, const char *fallback_charset,
|
|
|
|
bool quirks, struct content **c);
|
|
|
|
static bool sprite_convert(struct content *c);
|
|
|
|
static void sprite_destroy(struct content *c);
|
2011-06-29 00:17:39 +04:00
|
|
|
static bool sprite_redraw(struct content *c, struct content_redraw_data *data,
|
2011-06-30 19:48:07 +04:00
|
|
|
const struct rect *clip, const struct redraw_context *ctx);
|
2011-05-07 00:40:09 +04:00
|
|
|
static nserror sprite_clone(const struct content *old, struct content **newc);
|
2011-09-03 13:27:42 +04:00
|
|
|
static content_type sprite_content_type(void);
|
2011-05-07 00:40:09 +04:00
|
|
|
|
|
|
|
static const content_handler sprite_content_handler = {
|
2011-05-09 19:32:34 +04:00
|
|
|
.create = sprite_create,
|
|
|
|
.data_complete = sprite_convert,
|
|
|
|
.destroy = sprite_destroy,
|
|
|
|
.redraw = sprite_redraw,
|
|
|
|
.clone = sprite_clone,
|
|
|
|
.type = sprite_content_type,
|
|
|
|
.no_share = false,
|
2011-05-07 00:40:09 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *sprite_types[] = {
|
|
|
|
"image/x-riscos-sprite"
|
|
|
|
};
|
|
|
|
|
2011-09-16 02:31:16 +04:00
|
|
|
CONTENT_FACTORY_REGISTER_TYPES(sprite, sprite_types, sprite_content_handler)
|
2011-05-07 00:40:09 +04:00
|
|
|
|
|
|
|
nserror sprite_create(const content_handler *handler,
|
2016-04-19 01:17:38 +03:00
|
|
|
lwc_string *imime_type, const struct http_parameter *params,
|
2011-05-07 00:40:09 +04:00
|
|
|
llcache_handle *llcache, const char *fallback_charset,
|
|
|
|
bool quirks, struct content **c)
|
|
|
|
{
|
|
|
|
sprite_content *sprite;
|
|
|
|
nserror error;
|
|
|
|
|
2012-10-03 22:24:58 +04:00
|
|
|
sprite = calloc(1, sizeof(sprite_content));
|
2011-05-07 00:40:09 +04:00
|
|
|
if (sprite == NULL)
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
|
|
|
|
error = content__init(&sprite->base, handler, imime_type, params,
|
|
|
|
llcache, fallback_charset, quirks);
|
|
|
|
if (error != NSERROR_OK) {
|
2012-10-03 22:24:58 +04:00
|
|
|
free(sprite);
|
2011-05-07 00:40:09 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
*c = (struct content *) sprite;
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
2004-11-06 22:34:24 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a CONTENT_SPRITE for display.
|
|
|
|
*
|
|
|
|
* No conversion is necessary. We merely read the sprite dimensions.
|
|
|
|
*/
|
|
|
|
|
2010-04-06 01:58:38 +04:00
|
|
|
bool sprite_convert(struct content *c)
|
2003-09-11 02:46:56 +04:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
sprite_content *sprite = (sprite_content *) c;
|
2003-09-11 02:46:56 +04:00
|
|
|
os_error *error;
|
|
|
|
int w, h;
|
2004-06-11 00:41:26 +04:00
|
|
|
union content_msg_data msg_data;
|
2010-04-06 01:58:38 +04:00
|
|
|
const char *source_data;
|
|
|
|
unsigned long source_size;
|
|
|
|
const void *sprite_data;
|
2012-10-25 15:05:12 +04:00
|
|
|
char *title;
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2010-04-06 01:58:38 +04:00
|
|
|
source_data = content__get_source_data(c, &source_size);
|
|
|
|
|
|
|
|
sprite_data = source_data - 4;
|
|
|
|
osspriteop_area *area = (osspriteop_area*) sprite_data;
|
2011-05-07 00:40:09 +04:00
|
|
|
sprite->data = area;
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2005-04-05 21:19:58 +04:00
|
|
|
/* check for bad data */
|
2010-04-06 01:58:38 +04:00
|
|
|
if ((int)source_size + 4 != area->used) {
|
2005-04-05 21:19:58 +04:00
|
|
|
msg_data.error = messages_get("BadSprite");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
2003-09-11 22:37:25 +04:00
|
|
|
|
|
|
|
error = xosspriteop_read_sprite_info(osspriteop_PTR,
|
2005-04-05 06:36:33 +04:00
|
|
|
(osspriteop_area *)0x100,
|
2004-11-06 22:34:24 +03:00
|
|
|
(osspriteop_id) ((char *) area + area->first),
|
2004-06-11 00:41:26 +04:00
|
|
|
&w, &h, NULL, NULL);
|
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xosspriteop_read_sprite_info: 0x%x: %s", error->errnum, error->errmess);
|
2004-06-11 00:41:26 +04:00
|
|
|
msg_data.error = error->errmess;
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
2003-09-11 02:46:56 +04:00
|
|
|
|
|
|
|
c->width = w;
|
|
|
|
c->height = h;
|
2012-10-25 15:05:12 +04:00
|
|
|
|
|
|
|
/* set title text */
|
|
|
|
title = messages_get_buff("SpriteTitle",
|
2012-10-24 21:22:45 +04:00
|
|
|
nsurl_access_leaf(llcache_handle_get_url(c->llcache)),
|
|
|
|
c->width, c->height);
|
2012-10-25 15:05:12 +04:00
|
|
|
if (title != NULL) {
|
|
|
|
content__set_title(c, title);
|
|
|
|
free(title);
|
|
|
|
}
|
2011-02-27 23:11:39 +03:00
|
|
|
content_set_ready(c);
|
|
|
|
content_set_done(c);
|
2008-03-10 15:41:41 +03:00
|
|
|
/* Done: update status bar */
|
|
|
|
content_set_status(c, "");
|
2004-06-11 00:41:26 +04:00
|
|
|
return true;
|
2003-09-11 02:46:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-06 22:34:24 +03:00
|
|
|
/**
|
|
|
|
* Destroy a CONTENT_SPRITE and free all resources it owns.
|
|
|
|
*/
|
|
|
|
|
2003-09-11 02:46:56 +04:00
|
|
|
void sprite_destroy(struct content *c)
|
|
|
|
{
|
2005-04-05 06:36:33 +04:00
|
|
|
/* do not free c->data.sprite.data at it is simply a pointer to
|
2005-04-05 21:19:58 +04:00
|
|
|
* 4 bytes beforec->source_data. */
|
2003-09-11 02:46:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-06 22:34:24 +03:00
|
|
|
/**
|
|
|
|
* Redraw a CONTENT_SPRITE.
|
|
|
|
*/
|
|
|
|
|
2011-06-29 00:17:39 +04:00
|
|
|
bool sprite_redraw(struct content *c, struct content_redraw_data *data,
|
2011-06-30 19:48:07 +04:00
|
|
|
const struct rect *clip, const struct redraw_context *ctx)
|
2003-09-11 02:46:56 +04:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
sprite_content *sprite = (sprite_content *) c;
|
|
|
|
|
2011-06-30 19:48:07 +04:00
|
|
|
if (ctx->plot->flush && !ctx->plot->flush())
|
2006-08-19 23:31:07 +04:00
|
|
|
return false;
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return image_redraw(sprite->data,
|
2011-06-29 00:17:39 +04:00
|
|
|
ro_plot_origin_x + data->x * 2,
|
|
|
|
ro_plot_origin_y - data->y * 2,
|
|
|
|
data->width, data->height,
|
2004-11-06 22:34:24 +03:00
|
|
|
c->width,
|
|
|
|
c->height,
|
2011-06-29 00:17:39 +04:00
|
|
|
data->background_colour,
|
2004-11-06 22:34:24 +03:00
|
|
|
false, false, false,
|
|
|
|
IMAGE_PLOT_OS);
|
2003-09-11 02:46:56 +04:00
|
|
|
}
|
2004-11-06 22:34:24 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
nserror sprite_clone(const struct content *old, struct content **newc)
|
2010-04-06 01:58:38 +04:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
sprite_content *sprite;
|
|
|
|
nserror error;
|
|
|
|
|
2012-10-03 22:24:58 +04:00
|
|
|
sprite = calloc(1, sizeof(sprite_content));
|
2011-05-07 00:40:09 +04:00
|
|
|
if (sprite == NULL)
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
|
|
|
|
error = content__clone(old, &sprite->base);
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
content_destroy(&sprite->base);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2010-04-06 01:58:38 +04:00
|
|
|
/* Simply rerun convert */
|
|
|
|
if (old->status == CONTENT_STATUS_READY ||
|
|
|
|
old->status == CONTENT_STATUS_DONE) {
|
2011-05-07 00:40:09 +04:00
|
|
|
if (sprite_convert(&sprite->base) == false) {
|
|
|
|
content_destroy(&sprite->base);
|
|
|
|
return NSERROR_CLONE_FAILED;
|
|
|
|
}
|
2010-04-06 01:58:38 +04:00
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
*newc = (struct content *) sprite;
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-03 13:27:42 +04:00
|
|
|
content_type sprite_content_type(void)
|
2011-05-07 00:40:09 +04:00
|
|
|
{
|
|
|
|
return CONTENT_IMAGE;
|
2010-04-06 01:58:38 +04:00
|
|
|
}
|
|
|
|
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2006-03-24 06:44:37 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the bit depth of a sprite
|
|
|
|
*
|
|
|
|
* \param s sprite
|
|
|
|
* \return depth in bpp
|
|
|
|
*/
|
|
|
|
|
|
|
|
byte sprite_bpp(const osspriteop_header *s)
|
|
|
|
{
|
2009-06-20 23:38:56 +04:00
|
|
|
/* bit 31 indicates the presence of a full alpha channel
|
|
|
|
* rather than a binary mask */
|
2006-03-24 06:44:37 +03:00
|
|
|
int type = ((unsigned)s->mode >> osspriteop_TYPE_SHIFT) & 15;
|
|
|
|
byte bpp = 0;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case osspriteop_TYPE_OLD:
|
|
|
|
{
|
|
|
|
bits psr;
|
|
|
|
int val;
|
2009-06-20 23:38:56 +04:00
|
|
|
if (!xos_read_mode_variable(s->mode,
|
|
|
|
os_MODEVAR_LOG2_BPP, &val, &psr) &&
|
|
|
|
!(psr & _C))
|
|
|
|
bpp = 1 << val;
|
2006-03-24 06:44:37 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case osspriteop_TYPE1BPP: bpp = 1; break;
|
|
|
|
case osspriteop_TYPE2BPP: bpp = 2; break;
|
|
|
|
case osspriteop_TYPE4BPP: bpp = 4; break;
|
|
|
|
case osspriteop_TYPE8BPP: bpp = 8; break;
|
|
|
|
case osspriteop_TYPE16BPP: bpp = 16; break;
|
|
|
|
case osspriteop_TYPE32BPP: bpp = 32; break;
|
|
|
|
case osspriteop_TYPE_CMYK: bpp = 32; break;
|
|
|
|
}
|
|
|
|
return bpp;
|
|
|
|
}
|