2003-06-30 16:44:03 +04:00
|
|
|
/*
|
|
|
|
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
2003-07-19 01:02:29 +04:00
|
|
|
* Copyright 2003 John M Bell <jmb202@ecs.soton.ac.uk>
|
|
|
|
* Parts modified from IGviewer source by Peter Hartley
|
|
|
|
* http://utter.chaos.org/~pdh/software/intergif.htm
|
2003-06-05 17:24:28 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
2003-07-19 01:02:29 +04:00
|
|
|
#include <stdbool.h>
|
2003-06-05 17:24:28 +04:00
|
|
|
#include <stdlib.h>
|
2003-07-19 01:02:29 +04:00
|
|
|
#include "animlib/animlib.h"
|
2003-06-05 17:24:28 +04:00
|
|
|
#include "oslib/colourtrans.h"
|
|
|
|
#include "oslib/os.h"
|
|
|
|
#include "oslib/osspriteop.h"
|
|
|
|
#include "netsurf/content/content.h"
|
|
|
|
#include "netsurf/riscos/gif.h"
|
|
|
|
#include "netsurf/utils/log.h"
|
|
|
|
#include "netsurf/utils/utils.h"
|
|
|
|
|
2003-07-19 01:26:46 +04:00
|
|
|
static osspriteop_area *create_buffer_sprite(struct content *c, anim a);
|
2003-06-05 17:24:28 +04:00
|
|
|
|
|
|
|
void nsgif_init(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-07-19 01:02:29 +04:00
|
|
|
void nsgif_create(struct content*c)
|
2003-06-05 17:24:28 +04:00
|
|
|
{
|
|
|
|
c->data.gif.sprite_area = 0;
|
|
|
|
c->data.gif.data = xcalloc(0, 1);
|
|
|
|
c->data.gif.length = 0;
|
|
|
|
c->data.gif.buffer_pos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsgif_process_data(struct content *c, char *data, unsigned long size)
|
|
|
|
{
|
|
|
|
c->data.gif.data = xrealloc(c->data.gif.data, c->data.gif.length + size);
|
|
|
|
memcpy(c->data.gif.data + c->data.gif.length, data, size);
|
|
|
|
c->data.gif.length += size;
|
|
|
|
c->size += size;
|
|
|
|
}
|
|
|
|
|
2003-06-07 17:07:48 +04:00
|
|
|
int nsgif_convert(struct content *c, unsigned int iwidth, unsigned int iheight)
|
2003-06-05 17:24:28 +04:00
|
|
|
{
|
2003-07-19 01:02:29 +04:00
|
|
|
anim a;
|
|
|
|
frame f;
|
|
|
|
pixel *img, *mask;
|
|
|
|
struct osspriteop_header *header;
|
|
|
|
struct osspriteop_area *area;
|
|
|
|
|
|
|
|
a = Anim_FromData(c->data.gif.data, c->data.gif.length, NULL, false, false, false);
|
|
|
|
if (!a) {
|
|
|
|
|
|
|
|
LOG(("Error creating anim object"));
|
|
|
|
return 1;
|
2003-06-05 17:24:28 +04:00
|
|
|
}
|
|
|
|
|
2003-07-19 01:02:29 +04:00
|
|
|
if(!Anim_CommonPalette(a)) {
|
2003-06-07 17:07:48 +04:00
|
|
|
|
2003-07-19 01:02:29 +04:00
|
|
|
LOG(("bad palette"));
|
|
|
|
Anim_Destroy(&a);
|
|
|
|
return 1;
|
|
|
|
}
|
2003-06-07 17:07:48 +04:00
|
|
|
|
2003-07-19 01:26:46 +04:00
|
|
|
area = create_buffer_sprite(c, a);
|
2003-07-19 01:02:29 +04:00
|
|
|
if(!area) {
|
2003-06-05 17:24:28 +04:00
|
|
|
|
2003-07-19 01:02:29 +04:00
|
|
|
LOG(("Failed to create sprite"));
|
|
|
|
Anim_Destroy(&a);
|
|
|
|
xfree(area);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
c->data.gif.sprite_area = area;
|
2003-06-07 17:07:48 +04:00
|
|
|
|
2003-07-19 01:02:29 +04:00
|
|
|
header = (osspriteop_header*)(c->data.gif.sprite_area + 1);
|
|
|
|
f = a->pFrames + 0;
|
|
|
|
img = (pixel*)header + header->image;
|
|
|
|
mask = (pixel*)header + header->mask;
|
2003-06-07 17:07:48 +04:00
|
|
|
|
2003-07-19 01:02:29 +04:00
|
|
|
Anim_DecompressAligned(f->pImageData, f->nImageSize,
|
|
|
|
a->nWidth, a->nHeight, img);
|
2003-06-05 17:24:28 +04:00
|
|
|
|
2003-07-19 01:02:29 +04:00
|
|
|
if(f->pMaskData) {
|
2003-06-05 17:24:28 +04:00
|
|
|
|
2003-07-19 01:02:29 +04:00
|
|
|
int i,n = header->mask - header->image;
|
2003-06-05 17:24:28 +04:00
|
|
|
|
2003-07-19 01:02:29 +04:00
|
|
|
Anim_DecompressAligned(f->pMaskData, f->nMaskSize,
|
|
|
|
a->nWidth, a->nHeight, mask);
|
2003-06-05 17:24:28 +04:00
|
|
|
|
2003-07-19 01:02:29 +04:00
|
|
|
for(i=0; i<n; i++)
|
|
|
|
if(!mask[i]) {
|
2003-06-05 17:24:28 +04:00
|
|
|
|
2003-07-19 01:02:29 +04:00
|
|
|
img[i] = 255;
|
2003-07-19 01:26:46 +04:00
|
|
|
mask[i] = 0;
|
2003-07-19 01:02:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
memset(mask, 255, header->mask - header->image);
|
2003-06-05 17:24:28 +04:00
|
|
|
|
2003-07-19 01:02:29 +04:00
|
|
|
c->title = xcalloc(100, sizeof(char));
|
2003-06-07 17:07:48 +04:00
|
|
|
sprintf(c->title, "GIF image (%lux%lu)", c->width, c->height);
|
2003-06-17 23:24:21 +04:00
|
|
|
c->status = CONTENT_STATUS_DONE;
|
2003-06-05 17:24:28 +04:00
|
|
|
|
2003-07-19 01:02:29 +04:00
|
|
|
/* xosspriteop_save_sprite_file(osspriteop_USER_AREA,
|
|
|
|
c->data.gif.sprite_area, "gif"); */
|
|
|
|
|
2003-06-05 17:24:28 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsgif_revive(struct content *c, unsigned int width, unsigned int height)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nsgif_reformat(struct content *c, unsigned int width, unsigned int height)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-07-19 01:02:29 +04:00
|
|
|
void nsgif_redraw(struct content *c, long x, long y,
|
|
|
|
unsigned long width, unsigned long height)
|
|
|
|
{
|
|
|
|
unsigned int size;
|
|
|
|
osspriteop_trans_tab *table;
|
2003-07-19 01:17:42 +04:00
|
|
|
os_factors factors;
|
2003-07-19 01:02:29 +04:00
|
|
|
|
|
|
|
|
|
|
|
xcolourtrans_generate_table_for_sprite(c->data.gif.sprite_area,
|
|
|
|
(osspriteop_id) (c->data.gif.sprite_area + 1),
|
|
|
|
colourtrans_CURRENT_MODE, colourtrans_CURRENT_PALETTE,
|
|
|
|
0, colourtrans_GIVEN_SPRITE, 0, 0, &size);
|
|
|
|
|
|
|
|
table = xcalloc(size, 1);
|
|
|
|
|
|
|
|
xcolourtrans_generate_table_for_sprite(c->data.gif.sprite_area,
|
|
|
|
(osspriteop_id) (c->data.gif.sprite_area + 1),
|
|
|
|
colourtrans_CURRENT_MODE, colourtrans_CURRENT_PALETTE,
|
|
|
|
table, colourtrans_GIVEN_SPRITE, 0, 0, 0);
|
|
|
|
|
2003-07-19 01:17:42 +04:00
|
|
|
factors.xmul = width;
|
|
|
|
factors.ymul = height;
|
|
|
|
factors.xdiv = c->width * 2;
|
|
|
|
factors.ydiv = c->height * 2;
|
|
|
|
|
2003-07-19 01:02:29 +04:00
|
|
|
xosspriteop_put_sprite_scaled(osspriteop_PTR,
|
|
|
|
c->data.gif.sprite_area,
|
|
|
|
(osspriteop_id) (c->data.gif.sprite_area + 1),
|
|
|
|
x, y - height,
|
|
|
|
/* osspriteop_USE_PALETTE is RO 3.5+ only.
|
|
|
|
* behaviour on RO < 3.5 is unknown...
|
|
|
|
*/
|
2003-07-19 01:17:42 +04:00
|
|
|
osspriteop_USE_MASK | osspriteop_USE_PALETTE, &factors, table);
|
2003-07-19 01:02:29 +04:00
|
|
|
|
|
|
|
xfree(table);
|
|
|
|
}
|
|
|
|
|
2003-06-05 17:24:28 +04:00
|
|
|
void nsgif_destroy(struct content *c)
|
|
|
|
{
|
|
|
|
xfree(c->title);
|
|
|
|
xfree(c->data.gif.sprite_area);
|
|
|
|
xfree(c->data.gif.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-19 01:26:46 +04:00
|
|
|
static osspriteop_area *create_buffer_sprite( struct content *c, anim a )
|
2003-07-19 01:02:29 +04:00
|
|
|
{
|
2003-07-19 01:26:46 +04:00
|
|
|
unsigned int abw = ((a->nWidth + 3 ) & ~3u) * a->nHeight;
|
2003-07-19 01:02:29 +04:00
|
|
|
unsigned int nBytes = abw*2 + 44 + 16 + 256*8;
|
|
|
|
struct osspriteop_area *result = xcalloc(1, nBytes);
|
|
|
|
struct osspriteop_header *spr = (osspriteop_header*)(result+1);
|
|
|
|
int i,n;
|
|
|
|
unsigned int *pPalDest = (unsigned int*)(spr+1);
|
|
|
|
unsigned int *pPalSrc;
|
|
|
|
|
|
|
|
if ( !result )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
result->size = nBytes;
|
|
|
|
result->sprite_count = 1;
|
|
|
|
result->first = sizeof(*result);
|
|
|
|
result->used = nBytes;
|
|
|
|
|
|
|
|
spr->size = nBytes-sizeof(*result);
|
|
|
|
strncpy( spr->name, "gif", 12 );
|
|
|
|
spr->width = ((a->nWidth+3)>>2)-1;
|
|
|
|
spr->height = a->nHeight-1;
|
|
|
|
spr->left_bit = 0;
|
|
|
|
spr->right_bit = ((a->nWidth & 3) * 8 - 1) & 31;
|
|
|
|
spr->image = sizeof(*spr) + 256*8;
|
|
|
|
spr->mask = sizeof(*spr) + 256*8 + abw;
|
|
|
|
spr->mode = os_MODE8BPP90X90; /* 28 */
|
|
|
|
|
|
|
|
c->data.gif.sprite_image = ((char*)spr) + spr->image;
|
|
|
|
c->width = a->nWidth;
|
|
|
|
c->height = a->nHeight;
|
|
|
|
|
|
|
|
n = a->pFrames->pal->nColours;
|
|
|
|
pPalSrc = a->pFrames->pal->pColours;
|
|
|
|
for ( i=0; i<n; i++ )
|
|
|
|
{
|
|
|
|
*pPalDest++ = *pPalSrc;
|
|
|
|
*pPalDest++ = *pPalSrc++;
|
|
|
|
}
|
2003-06-06 06:06:23 +04:00
|
|
|
|
2003-07-19 01:02:29 +04:00
|
|
|
return result;
|
2003-06-05 17:24:28 +04:00
|
|
|
}
|