mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-21 03:12:41 +01:00
Codechange: Replace BmpData palette and bitmap with vectors.
BmpInfo width and height members are now size_t to avoid multiplication warnings. This avoids manual memory management and allows BmpData to clean up after itself.
This commit is contained in:
committed by
Peter Nelson
parent
0633b94e8f
commit
f829b1d74a
@@ -211,7 +211,7 @@ static void ReadHeightmapBMPImageData(uint8_t *map, BmpInfo *info, BmpData *data
|
||||
uint x, y;
|
||||
uint8_t gray_palette[256];
|
||||
|
||||
if (data->palette != nullptr) {
|
||||
if (!data->palette.empty()) {
|
||||
uint i;
|
||||
bool all_gray = true;
|
||||
|
||||
@@ -267,12 +267,9 @@ static bool ReadHeightmapBMP(const char *filename, uint *x, uint *y, uint8_t **m
|
||||
{
|
||||
FILE *f;
|
||||
BmpInfo info;
|
||||
BmpData data;
|
||||
BmpData data{};
|
||||
BmpBuffer buffer;
|
||||
|
||||
/* Init BmpData */
|
||||
memset(&data, 0, sizeof(data));
|
||||
|
||||
f = FioFOpenFile(filename, "rb", HEIGHTMAP_DIR);
|
||||
if (f == nullptr) {
|
||||
ShowErrorMessage(STR_ERROR_BMPMAP, STR_ERROR_PNGMAP_FILE_NOT_FOUND, WL_ERROR);
|
||||
@@ -284,14 +281,12 @@ static bool ReadHeightmapBMP(const char *filename, uint *x, uint *y, uint8_t **m
|
||||
if (!BmpReadHeader(&buffer, &info, &data)) {
|
||||
ShowErrorMessage(STR_ERROR_BMPMAP, STR_ERROR_BMPMAP_IMAGE_TYPE, WL_ERROR);
|
||||
fclose(f);
|
||||
BmpDestroyData(&data);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsValidHeightmapDimension(info.width, info.height)) {
|
||||
ShowErrorMessage(STR_ERROR_BMPMAP, STR_ERROR_HEIGHTMAP_TOO_LARGE, WL_ERROR);
|
||||
fclose(f);
|
||||
BmpDestroyData(&data);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -299,7 +294,6 @@ static bool ReadHeightmapBMP(const char *filename, uint *x, uint *y, uint8_t **m
|
||||
if (!BmpReadBitmap(&buffer, &info, &data)) {
|
||||
ShowErrorMessage(STR_ERROR_BMPMAP, STR_ERROR_BMPMAP_IMAGE_TYPE, WL_ERROR);
|
||||
fclose(f);
|
||||
BmpDestroyData(&data);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -307,8 +301,6 @@ static bool ReadHeightmapBMP(const char *filename, uint *x, uint *y, uint8_t **m
|
||||
ReadHeightmapBMPImageData(*map, &info, &data);
|
||||
}
|
||||
|
||||
BmpDestroyData(&data);
|
||||
|
||||
*x = info.width;
|
||||
*y = info.height;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user