| 318 | } |
| 319 | |
| 320 | TextureData* bitmap_load(const char* name, u32 decompress, AssetPool pool, bool addToCache) |
| 321 | { |
| 322 | // TFE: Keep track of per-level texture state for serialization. |
| 323 | // This is also useful for handling per-level GPU texture mirrors. |
| 324 | TextureTable::iterator iTex = s_textureTable[pool].find(name); |
| 325 | if (iTex != s_textureTable[pool].end()) |
| 326 | { |
| 327 | return s_textureList[pool][iTex->second].texture; |
| 328 | } |
| 329 | |
| 330 | FilePath filepath; |
| 331 | if (!TFE_Paths::getFilePath(name, &filepath)) |
| 332 | { |
| 333 | return nullptr; |
| 334 | } |
| 335 | |
| 336 | FileStream file; |
| 337 | if (!file.open(&filepath, Stream::MODE_READ)) |
| 338 | { |
| 339 | return nullptr; |
| 340 | } |
| 341 | |
| 342 | size_t size = file.getSize(); |
| 343 | s_buffer.resize(size); |
| 344 | file.readBuffer(s_buffer.data(), (u32)size); |
| 345 | file.close(); |
| 346 | |
| 347 | TextureData* texture = (TextureData*)region_alloc(s_texState.memoryRegion, sizeof(TextureData)); |
| 348 | memset(texture, 0, sizeof(TextureData)); |
| 349 | |
| 350 | const u8* data = s_buffer.data(); |
| 351 | const u8* end = data + size; |
| 352 | const u8* fheader = data; |
| 353 | data += 3; |
| 354 | |
| 355 | if (strncmp((char*)fheader, "BM ", 3)) |
| 356 | { |
| 357 | TFE_System::logWrite(LOG_ERROR, "bitmap_load", "File '%s' is not a valid BM file.", filepath); |
| 358 | return nullptr; |
| 359 | } |
| 360 | |
| 361 | u8 version = readByte(data); |
| 362 | if (version != DF_BM_VERSION) |
| 363 | { |
| 364 | TFE_System::logWrite(LOG_ERROR, "bitmap_load", "File '%s' has invalid BM version '%u'.", filepath, version); |
| 365 | return nullptr; |
| 366 | } |
| 367 | |
| 368 | texture->width = readUShort(data); |
| 369 | texture->height = readUShort(data); |
| 370 | texture->uvWidth = readShort(data); |
| 371 | texture->uvHeight = readShort(data); |
| 372 | texture->flags = readByte(data); |
| 373 | texture->logSizeY = readByte(data); |
| 374 | texture->compressed = readByte(data); |
| 375 | texture->palIndex = 1; |
| 376 | texture->animIndex = -1; |
| 377 | texture->frameIdx = -1; |
no test coverage detected