1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-20 10:52:41 +01:00

Codechange: Replace BmpBuffer with RandomAccessFile.

This commit is contained in:
Peter Nelson
2024-05-15 21:25:47 +01:00
committed by Peter Nelson
parent 719763dfcb
commit cb23651f43
3 changed files with 82 additions and 157 deletions

View File

@@ -263,35 +263,29 @@ static void ReadHeightmapBMPImageData(std::span<uint8_t> map, const BmpInfo &inf
*/
static bool ReadHeightmapBMP(const char *filename, uint *x, uint *y, std::vector<uint8_t> *map)
{
FILE *f;
BmpInfo info;
BmpInfo info{};
BmpData data{};
BmpBuffer buffer;
f = FioFOpenFile(filename, "rb", HEIGHTMAP_DIR);
if (f == nullptr) {
if (!FioCheckFileExists(filename, HEIGHTMAP_DIR)) {
ShowErrorMessage(STR_ERROR_BMPMAP, STR_ERROR_PNGMAP_FILE_NOT_FOUND, WL_ERROR);
return false;
}
BmpInitializeBuffer(&buffer, f);
RandomAccessFile file(filename, HEIGHTMAP_DIR);
if (!BmpReadHeader(&buffer, info, data)) {
if (!BmpReadHeader(file, info, data)) {
ShowErrorMessage(STR_ERROR_BMPMAP, STR_ERROR_BMPMAP_IMAGE_TYPE, WL_ERROR);
fclose(f);
return false;
}
if (!IsValidHeightmapDimension(info.width, info.height)) {
ShowErrorMessage(STR_ERROR_BMPMAP, STR_ERROR_HEIGHTMAP_TOO_LARGE, WL_ERROR);
fclose(f);
return false;
}
if (map != nullptr) {
if (!BmpReadBitmap(&buffer, info, data)) {
if (!BmpReadBitmap(file, info, data)) {
ShowErrorMessage(STR_ERROR_BMPMAP, STR_ERROR_BMPMAP_IMAGE_TYPE, WL_ERROR);
fclose(f);
return false;
}
@@ -302,7 +296,6 @@ static bool ReadHeightmapBMP(const char *filename, uint *x, uint *y, std::vector
*x = info.width;
*y = info.height;
fclose(f);
return true;
}