OpenTTD
Enumerations | Functions | Variables
grf.cpp File Reference

Reading graphics data from (New)GRF files. More...

#include "../stdafx.h"
#include "../gfx_func.h"
#include "../fileio_func.h"
#include "../debug.h"
#include "../strings_func.h"
#include "table/strings.h"
#include "../error.h"
#include "../core/math_func.hpp"
#include "../core/alloc_type.hpp"
#include "../core/bitmath_func.hpp"
#include "grf.hpp"
#include "../safeguards.h"

Go to the source code of this file.

Enumerations

enum  SpriteColourComponent { SCC_RGB = 1 << 0, SCC_ALPHA = 1 << 1, SCC_PAL = 1 << 2, SCC_MASK = SCC_RGB | SCC_ALPHA | SCC_PAL }
 The different colour components a sprite can have. More...

Functions

static bool WarnCorruptSprite (uint8 file_slot, size_t file_pos, int line)
 We found a corrupted sprite.
bool DecodeSingleSprite (SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_pos, SpriteType sprite_type, int64 num, byte type, ZoomLevel zoom_lvl, byte colour_fmt, byte container_format)
 Decode the image data of a single sprite.
uint8 LoadSpriteV1 (SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_pos, SpriteType sprite_type, bool load_32bpp)
uint8 LoadSpriteV2 (SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_pos, SpriteType sprite_type, bool load_32bpp)

Variables

const byte _palmap_w2d []

Detailed Description

Reading graphics data from (New)GRF files.

Definition in file grf.cpp.

Enumeration Type Documentation

The different colour components a sprite can have.

Enumerator:
SCC_RGB 

Sprite has RGB.

SCC_ALPHA 

Sprite has alpha.

SCC_PAL 

Sprite has palette data.

SCC_MASK 

Mask of valid colour bits.

Definition at line 29 of file grf.cpp.

Function Documentation

bool DecodeSingleSprite ( SpriteLoader::Sprite sprite,
uint8  file_slot,
size_t  file_pos,
SpriteType  sprite_type,
int64  num,
byte  type,
ZoomLevel  zoom_lvl,
byte  colour_fmt,
byte  container_format 
)

Decode the image data of a single sprite.

Parameters
[in,out]spriteFilled with the sprite image data.
file_slotFile slot.
file_posFile position.
sprite_typeType of the sprite we're decoding.
numSize of the decompressed sprite.
typeType of the encoded sprite.
zoom_lvlRequested zoom level.
colour_fmtColour format of the sprite.
container_formatContainer format of the GRF this sprite is in.
Returns
True if the sprite was successfully loaded.

Definition at line 70 of file grf.cpp.

References _palette_remap_grf, SpriteLoader::CommonPixel::a, SpriteLoader::Sprite::AllocateData(), SpriteLoader::CommonPixel::b, SpriteLoader::Sprite::data, DEBUG, FioGetFilename(), FioReadByte(), SpriteLoader::CommonPixel::g, SpriteLoader::Sprite::height, SpriteLoader::CommonPixel::m, min(), SpriteLoader::CommonPixel::r, SCC_ALPHA, SCC_PAL, SCC_RGB, ST_FONT, ST_NORMAL, WarnCorruptSprite(), and SpriteLoader::Sprite::width.

static bool WarnCorruptSprite ( uint8  file_slot,
size_t  file_pos,
int  line 
)
static

We found a corrupted sprite.

This means that the sprite itself contains invalid data or is too small for the given dimensions.

Parameters
file_slotthe file the errored sprite is in
file_posthe location in the file of the errored sprite
linethe line where the error occurs.
Returns
always false (to tell loading the sprite failed)

Definition at line 45 of file grf.cpp.

References DEBUG, FioGetFilename(), INVALID_STRING_ID, SetDParamStr(), ShowErrorMessage(), and WL_ERROR.

Referenced by DecodeSingleSprite().