summaryrefslogtreecommitdiff
path: root/riscos/sprite.c
blob: 44bd39c9a684d54af974882b7fb5dd7b345d0601 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * 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 "netsurf/utils/config.h"
#include "netsurf/content/content.h"
#include "netsurf/riscos/sprite.h"
#include "netsurf/utils/utils.h"
#include "netsurf/utils/log.h"
#include "oslib/colourtrans.h"
#include "oslib/osspriteop.h"

#ifdef WITH_SPRITE

void sprite_create(struct content *c, const char *params[])
{
	c->data.sprite.data = xcalloc(4, 1);
	c->data.sprite.length = 4;
}


void sprite_process_data(struct content *c, char *data, unsigned long size)
{
	c->data.sprite.data = xrealloc(c->data.sprite.data, c->data.sprite.length + size);
	memcpy((char*)(c->data.sprite.data) + c->data.sprite.length, data, size);
	c->data.sprite.length += size;
	c->size += size;
}


int sprite_convert(struct content *c, unsigned int width, unsigned int height)
{
	os_error *error;
	int w, h;
	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(("error: %s", error->errmess));
                return 1;
        }

	c->width = w;
	c->height = h;
	c->title = xcalloc(100, 1);
	sprintf(c->title, "Sprite image (%lux%lu, %lu bytes)", c->width,
	                                c->height, c->data.sprite.length);
	c->status = CONTENT_STATUS_DONE;
	return 0;
}


void sprite_revive(struct content *c, unsigned int width, unsigned int height)
{
}


void sprite_reformat(struct content *c, unsigned int width, unsigned int height)
{
}


void sprite_destroy(struct content *c)
{
	xfree(c->data.sprite.data);
	xfree(c->title);
}


void sprite_redraw(struct content *c, long x, long y,
		unsigned long width, unsigned long height,
		long clip_x0, long clip_y0, long clip_x1, long clip_y1)
{
        unsigned int size;
	osspriteop_area *area = (osspriteop_area*)c->data.sprite.data;
	osspriteop_trans_tab *table;
	os_factors factors;

	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);
	table = xcalloc(size, 1);
	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);

	factors.xmul = width;
	factors.ymul = height;
	factors.xdiv = c->width * 2;
	factors.ydiv = c->height * 2;

	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);

	xfree(table);
}
#endif