|
|
/* $Id$ */
|
|
|
|
|
|
/** @file grf.cpp */
|
|
|
|
|
|
#include "../stdafx.h"
|
|
|
#include "../gfx_func.h"
|
|
|
#include "../fileio.h"
|
|
|
#include "../debug.h"
|
|
|
#include "../core/alloc_func.hpp"
|
|
|
#include "grf.hpp"
|
|
|
|
|
|
bool SpriteLoaderGrf::LoadSprite(SpriteLoader::Sprite *sprite, const char *filename, uint8 file_slot, uint32 file_pos)
|
|
|
{
|
|
|
/* Open the right file and go to the correct position */
|
|
|
FioSeekToFile(file_slot, file_pos);
|
|
|
|
|
|
/* Read the size and type */
|
|
|
int num = FioReadWord();
|
|
|
byte type = FioReadByte();
|
|
|
|
|
|
/* Type 0xFF indicates either a colormap or some other non-sprite info; we do not handle them here */
|
|
|
if (type == 0xFF) return false;
|
|
|
|
|
|
sprite->height = FioReadByte();
|
|
|
sprite->width = FioReadWord();
|
|
|
sprite->x_offs = FioReadWord();
|
|
|
sprite->y_offs = FioReadWord();
|
|
|
|
|
|
/* 0x02 indicates it is a compressed sprite, so we can't rely on 'num' to be valid.
|
|
|
* In case it is uncompressed, the size is 'num' - 8 (header-size). */
|
|
|
num = (type & 0x02) ? sprite->width * sprite->height : num - 8;
|
|
|
|
|
|
/* XXX -- We should use a pre-located memory segment for this, malloc/free is pretty expensive */
|