diff options
author | rubidium <rubidium@openttd.org> | 2013-11-23 13:12:19 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2013-11-23 13:12:19 +0000 |
commit | b3e93d65208f74802595b12e682d98a4d534a328 (patch) | |
tree | 992b20c16adccf478fb80f75fd1c0805044e709e /src/heightmap.cpp | |
parent | 2e54c8fdfa237f84e8d48b30bf4811ba7ed84327 (diff) | |
download | openttd-b3e93d65208f74802595b12e682d98a4d534a328.tar.xz |
(svn r26057) -Fix: a number of possibly uninitialised variables
Diffstat (limited to 'src/heightmap.cpp')
-rw-r--r-- | src/heightmap.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/heightmap.cpp b/src/heightmap.cpp index 2f6d14e56..50cfd6e22 100644 --- a/src/heightmap.cpp +++ b/src/heightmap.cpp @@ -46,9 +46,11 @@ static void ReadHeightmapPNGImageData(byte *map, png_structp png_ptr, png_infop uint x, y; byte gray_palette[256]; png_bytep *row_pointers = NULL; + bool has_palette = png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE; + uint channels = png_get_channels(png_ptr, info_ptr); /* Get palette and convert it to grayscale */ - if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) { + if (has_palette) { int i; int palette_size; png_color *palette; @@ -79,11 +81,11 @@ static void ReadHeightmapPNGImageData(byte *map, png_structp png_ptr, png_infop for (x = 0; x < png_get_image_width(png_ptr, info_ptr); x++) { for (y = 0; y < png_get_image_height(png_ptr, info_ptr); y++) { byte *pixel = &map[y * png_get_image_width(png_ptr, info_ptr) + x]; - uint x_offset = x * png_get_channels(png_ptr, info_ptr); + uint x_offset = x * channels; - if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) { + if (has_palette) { *pixel = gray_palette[row_pointers[y][x_offset]]; - } else if (png_get_channels(png_ptr, info_ptr) == 3) { + } else if (channels == 3) { *pixel = RGBToGrayscale(row_pointers[y][x_offset + 0], row_pointers[y][x_offset + 1], row_pointers[y][x_offset + 2]); } else { |