| 217 | } |
| 218 | |
| 219 | void bitmap_loadHD(const char* name, TextureData* texData, s32 scaleFactor, AssetPool pool) |
| 220 | { |
| 221 | texData->scaleFactor = 1; |
| 222 | texData->hdAssetData = nullptr; |
| 223 | // Verify that the HD texture *can* be loaded first. |
| 224 | if (pool == POOL_LEVEL && !TFE_Settings::isHdAssetValid(name, HD_ASSET_TYPE_BM)) |
| 225 | { |
| 226 | return; |
| 227 | } |
| 228 | |
| 229 | char hdPath[TFE_MAX_PATH]; |
| 230 | FileUtil::replaceExtension(name, "raw", hdPath); |
| 231 | |
| 232 | // If the file doesn't exist, just return - there is no HD asset. |
| 233 | FilePath filepath; |
| 234 | if (!TFE_Paths::getFilePath(hdPath, &filepath)) |
| 235 | { |
| 236 | return; |
| 237 | } |
| 238 | FileStream file; |
| 239 | if (!file.open(&filepath, Stream::MODE_READ)) |
| 240 | { |
| 241 | return; |
| 242 | } |
| 243 | |
| 244 | // Load the raw data from disk. |
| 245 | size_t size = file.getSize(); |
| 246 | s_buffer.resize(size); |
| 247 | file.readBuffer(s_buffer.data(), (u32)size); |
| 248 | file.close(); |
| 249 | |
| 250 | // Process the data based on the base texture. |
| 251 | s32 width = texData->width * scaleFactor; |
| 252 | s32 height = texData->height * scaleFactor; |
| 253 | s32 frameCount = 1; |
| 254 | if (texData->uvWidth == BM_ANIMATED_TEXTURE) |
| 255 | { |
| 256 | const u8* base = texData->image + 2; |
| 257 | const u32* textureOffsets = (u32*)base; |
| 258 | const TextureData* frame0 = (TextureData*)(base + textureOffsets[0]); |
| 259 | |
| 260 | width = frame0->width * scaleFactor; |
| 261 | height = frame0->height * scaleFactor; |
| 262 | frameCount = texData->uvHeight; |
| 263 | } |
| 264 | |
| 265 | const s32 hdFrameSize = width * height * 4; |
| 266 | // Verify this is a valid texture. |
| 267 | if (size != hdFrameSize * frameCount) |
| 268 | { |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | // Process the HD data. |
| 273 | texData->scaleFactor = scaleFactor; |
| 274 | texData->hdAssetData = (u8*)region_alloc(s_texState.memoryRegion, hdFrameSize * frameCount); |
| 275 | memset(texData->hdAssetData, 0, hdFrameSize * frameCount); |
| 276 |
no test coverage detected