netsurf/riscos/sprite.c
John Mark Bell 912d09b1cb [project @ 2004-08-11 16:26:13 by jmb]
Make content_redraw return a bool
Printing of foreground images now uses OS_SpriteOp
Printing of background images disabled
Mega-paranoid SWI result checking in htmlredraw.c
Rearranged GIF data structure slightly - updates to reflect this.
Other stuff I've probably forgotten

svn path=/import/netsurf/; revision=1208
2004-08-11 16:26:13 +00:00

156 lines
3.9 KiB
C

/*
* This file is part of NetSurf, http://netsurf.sourceforge.net/
* Licensed under the GNU General Public License,
* http://www.opensource.org/licenses/gpl-license
* Copyright 2003 John M Bell <jmb202@ecs.soton.ac.uk>
*/
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include "oslib/colourtrans.h"
#include "oslib/osspriteop.h"
#include "netsurf/utils/config.h"
#include "netsurf/content/content.h"
#include "netsurf/riscos/sprite.h"
#include "netsurf/utils/log.h"
#include "netsurf/utils/messages.h"
#include "netsurf/utils/utils.h"
#ifdef WITH_SPRITE
bool sprite_create(struct content *c, const char *params[])
{
union content_msg_data msg_data;
c->data.sprite.data = malloc(4);
if (!c->data.sprite.data) {
msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
warn_user("NoMemory", 0);
return false;
}
c->data.sprite.length = 4;
return true;
}
bool sprite_process_data(struct content *c, char *data, unsigned int size)
{
char *sprite_data;
union content_msg_data msg_data;
sprite_data = realloc(c->data.sprite.data,
c->data.sprite.length + size);
if (!sprite_data) {
msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
warn_user("NoMemory", 0);
return false;
}
c->data.sprite.data = sprite_data;
memcpy((char*)(c->data.sprite.data) + c->data.sprite.length,
data, size);
c->data.sprite.length += size;
c->size += size;
return true;
}
bool sprite_convert(struct content *c, int width, int height)
{
os_error *error;
int w, h;
union content_msg_data msg_data;
osspriteop_area *area = (osspriteop_area*)c->data.sprite.data;
/* fill in the size (first word) of the area */
area->size = c->data.sprite.length;
error = xosspriteop_read_sprite_info(osspriteop_PTR,
area,
(osspriteop_id)((char*)(c->data.sprite.data) + area->first),
&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;
}
c->width = w;
c->height = h;
c->title = malloc(100);
if (c->title)
snprintf(c->title, 100, messages_get("SpriteTitle"), c->width,
c->height, c->data.sprite.length);
c->status = CONTENT_STATUS_DONE;
return true;
}
void sprite_destroy(struct content *c)
{
free(c->data.sprite.data);
free(c->title);
}
bool sprite_redraw(struct content *c, int x, int y,
int width, int height,
int clip_x0, int clip_y0, int clip_x1, int clip_y1,
float scale)
{
unsigned int size;
osspriteop_area *area = (osspriteop_area*)c->data.sprite.data;
osspriteop_trans_tab *table;
os_factors factors;
os_error *error;
error = xcolourtrans_generate_table_for_sprite(
area,
(osspriteop_id)((char*)(c->data.sprite.data) +
area->first),
colourtrans_CURRENT_MODE, colourtrans_CURRENT_PALETTE,
0, colourtrans_GIVEN_SPRITE, 0, 0, &size);
if (error) {
LOG(("xcolourtrans_generate_table_for_sprite: 0x%x: %s", error->errnum, error->errmess));
return false;
}
table = xcalloc(size, 1);
error = xcolourtrans_generate_table_for_sprite(
area,
(osspriteop_id)((char*)(c->data.sprite.data) +
area->first),
colourtrans_CURRENT_MODE, colourtrans_CURRENT_PALETTE,
table, colourtrans_GIVEN_SPRITE, 0, 0, 0);
if (error) {
LOG(("xcolourtrans_generate_table_for_sprite: 0x%x: %s", error->errnum, error->errmess));
free(table);
return false;
}
factors.xmul = width;
factors.ymul = height;
factors.xdiv = c->width * 2;
factors.ydiv = c->height * 2;
error = xosspriteop_put_sprite_scaled(osspriteop_PTR,
area,
(osspriteop_id)((char*)(c->data.sprite.data) +
area->first),
x, (int)(y - height),
osspriteop_USE_MASK | osspriteop_USE_PALETTE, &factors, table);
if (error) {
LOG(("xosspriteop_put_sprite_scaled: 0x%x: %s", error->errnum, error->errmess));
free(table);
return false;
}
xfree(table);
return true;
}
#endif