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.
|
|
|
|
*
|
|
|
|
* Unfortunately we have to make a copy of the bitmap data, because sprite areas
|
|
|
|
* need a length word at the start.
|
|
|
|
*/
|
|
|
|
|
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"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/config.h"
|
|
|
|
#include "desktop/plotters.h"
|
|
|
|
#include "content/content.h"
|
|
|
|
#include "riscos/gui.h"
|
|
|
|
#include "riscos/image.h"
|
|
|
|
#include "riscos/sprite.h"
|
2008-07-27 03:42:24 +04:00
|
|
|
#include "utils/config.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/utils.h"
|
2003-09-11 02:46:56 +04:00
|
|
|
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_SPRITE
|
|
|
|
|
2004-11-06 22:34:24 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a CONTENT_SPRITE for display.
|
|
|
|
*
|
|
|
|
* No conversion is necessary. We merely read the sprite dimensions.
|
|
|
|
*/
|
|
|
|
|
2004-06-11 00:41:26 +04:00
|
|
|
bool sprite_convert(struct content *c, int width, int height)
|
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;
|
2009-03-27 04:30:18 +03:00
|
|
|
void *source_data;
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2005-04-05 06:36:33 +04:00
|
|
|
source_data = ((char *)c->source_data) - 4;
|
|
|
|
osspriteop_area *area = (osspriteop_area*)source_data;
|
|
|
|
c->data.sprite.data = area;
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2005-04-05 21:19:58 +04:00
|
|
|
/* check for bad data */
|
|
|
|
if ((int)c->source_size + 4 != area->used) {
|
|
|
|
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) {
|
|
|
|
LOG(("xosspriteop_read_sprite_info: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
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;
|
2004-06-11 00:41:26 +04:00
|
|
|
c->title = malloc(100);
|
|
|
|
if (c->title)
|
|
|
|
snprintf(c->title, 100, messages_get("SpriteTitle"), c->width,
|
2005-04-05 21:19:58 +04:00
|
|
|
c->height, c->source_size);
|
2003-09-11 02:46:56 +04:00
|
|
|
c->status = CONTENT_STATUS_DONE;
|
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. */
|
2004-06-11 00:41:26 +04:00
|
|
|
free(c->title);
|
2003-09-11 02:46:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-06 22:34:24 +03:00
|
|
|
/**
|
|
|
|
* Redraw a CONTENT_SPRITE.
|
|
|
|
*/
|
|
|
|
|
2004-08-11 20:26:13 +04:00
|
|
|
bool sprite_redraw(struct content *c, int x, int y,
|
2004-06-11 00:41:26 +04:00
|
|
|
int width, int height,
|
|
|
|
int clip_x0, int clip_y0, int clip_x1, int clip_y1,
|
2004-11-06 22:34:24 +03:00
|
|
|
float scale, colour background_colour)
|
2003-09-11 02:46:56 +04:00
|
|
|
{
|
2006-08-19 23:31:07 +04:00
|
|
|
if (plot.flush && !plot.flush())
|
|
|
|
return false;
|
|
|
|
|
2004-11-06 22:34:24 +03:00
|
|
|
return image_redraw(c->data.sprite.data,
|
|
|
|
ro_plot_origin_x + x * 2,
|
|
|
|
ro_plot_origin_y - y * 2,
|
|
|
|
width, height,
|
|
|
|
c->width,
|
|
|
|
c->height,
|
|
|
|
background_colour,
|
|
|
|
false, false, false,
|
|
|
|
IMAGE_PLOT_OS);
|
2003-09-11 02:46:56 +04:00
|
|
|
}
|
2004-11-06 22:34:24 +03: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;
|
|
|
|
}
|