OpenTTD Source  20241121-master-g67a0fccfad
grf.cpp File Reference

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

#include "../stdafx.h"
#include "../gfx_func.h"
#include "../debug.h"
#include "../settings_type.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 "../spritecache.h"
#include "grf.hpp"
#include "../safeguards.h"

Go to the source code of this file.

Functions

static bool WarnCorruptSprite (const SpriteFile &file, size_t file_pos, int line)
 We found a corrupted sprite. More...
 
bool DecodeSingleSprite (SpriteLoader::Sprite *sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, int64_t num, uint8_t type, ZoomLevel zoom_lvl, uint8_t colour_fmt, uint8_t container_format)
 Decode the image data of a single sprite. More...
 
uint8_t LoadSpriteV1 (SpriteLoader::SpriteCollection &sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp)
 
uint8_t LoadSpriteV2 (SpriteLoader::SpriteCollection &sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp, uint8_t control_flags)
 

Variables

const uint8_t _palmap_w2d []
 

Detailed Description

Reading graphics data from (New)GRF files.

Definition in file grf.cpp.

Function Documentation

◆ DecodeSingleSprite()

bool DecodeSingleSprite ( SpriteLoader::Sprite sprite,
SpriteFile file,
size_t  file_pos,
SpriteType  sprite_type,
int64_t  num,
uint8_t  type,
ZoomLevel  zoom_lvl,
uint8_t  colour_fmt,
uint8_t  container_format 
)

Decode the image data of a single sprite.

Parameters
[in,out]spriteFilled with the sprite image data.
fileThe file with the sprite data.
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 60 of file grf.cpp.

References SpriteLoader::Sprite::AllocateData(), SpriteLoader::Sprite::height, RandomAccessFile::ReadByte(), SCC_ALPHA, SCC_PAL, SCC_RGB, WarnCorruptSprite(), and SpriteLoader::Sprite::width.

◆ WarnCorruptSprite()

static bool WarnCorruptSprite ( const SpriteFile file,
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 35 of file grf.cpp.

References Debug, RandomAccessFile::GetSimplifiedFilename(), INVALID_STRING_ID, SetDParamStr(), ShowErrorMessage(), and WL_ERROR.

Referenced by DecodeSingleSprite().