MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / LoadSpriteV1

Function LoadSpriteV1

src/spriteloader/grf.cpp:215–254  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

213}
214
215static ZoomLevels LoadSpriteV1(SpriteLoader::SpriteCollection &sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp, ZoomLevels &avail_8bpp)
216{
217 /* Check the requested colour depth. */
218 if (load_32bpp) return {};
219
220 /* Open the right file and go to the correct position */
221 file.SeekTo(file_pos, SEEK_SET);
222
223 /* Read the size and type */
224 int num = file.ReadWord();
225 uint8_t type = file.ReadByte();
226
227 /* Type 0xFF indicates either a colourmap or some other non-sprite info; we do not handle them here */
228 if (type == 0xFF) return {};
229
230 ZoomLevel zoom_lvl = (sprite_type != SpriteType::MapGen) ? ZoomLevel::Normal : ZoomLevel::Min;
231 auto &dest_sprite = sprite[zoom_lvl];
232
233 dest_sprite.height = file.ReadByte();
234 dest_sprite.width = file.ReadWord();
235 dest_sprite.x_offs = file.ReadWord();
236 dest_sprite.y_offs = file.ReadWord();
237 dest_sprite.colours = SpriteComponent::Palette;
238
239 if (dest_sprite.width > INT16_MAX) {
240 WarnCorruptSprite(file, file_pos, __LINE__);
241 return {};
242 }
243
244 /* 0x02 indicates it is a compressed sprite, so we can't rely on 'num' to be valid.
245 * In case it is uncompressed, the size is 'num' - 8 (header-size). */
246 num = (type & 0x02) ? dest_sprite.width * dest_sprite.height : num - 8;
247
248 if (DecodeSingleSprite(&dest_sprite, file, file_pos, sprite_type, num, type, zoom_lvl, SpriteComponent::Palette, 1)) {
249 avail_8bpp.Set(zoom_lvl);
250 return avail_8bpp;
251 }
252
253 return {};
254}
255
256static ZoomLevels LoadSpriteV2(SpriteLoader::SpriteCollection &sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp, SpriteCacheCtrlFlags control_flags, ZoomLevels &avail_8bpp, ZoomLevels &avail_32bpp)
257{

Callers 1

LoadSpriteMethod · 0.85

Calls 6

WarnCorruptSpriteFunction · 0.85
DecodeSingleSpriteFunction · 0.85
SeekToMethod · 0.80
ReadWordMethod · 0.45
ReadByteMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected