File diff r4548:6a33e364fba5 → r4549:76b9213799ac
heightmap.c
Show inline comments
 
@@ -100,49 +100,49 @@ static bool ReadHeightmapPNG(char *filen
 
	fp = fopen(filename, "rb");
 
	if (fp == NULL) {
 
		ShowErrorMessage(STR_PNGMAP_ERR_FILE_NOT_FOUND, STR_PNGMAP_ERROR, 0, 0);
 
		return false;
 
	}
 

	
 
	png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
 
	if (png_ptr == NULL) {
 
		ShowErrorMessage(STR_PNGMAP_ERR_MISC, STR_PNGMAP_ERROR, 0, 0);
 
		fclose(fp);
 
		return false;
 
	}
 

	
 
	info_ptr = png_create_info_struct(png_ptr);
 
	if (info_ptr == NULL || setjmp(png_jmpbuf(png_ptr))) {
 
		ShowErrorMessage(STR_PNGMAP_ERR_MISC, STR_PNGMAP_ERROR, 0, 0);
 
		fclose(fp);
 
		png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
 
		return false;
 
	}
 

	
 
	png_init_io(png_ptr, fp);
 

	
 
	/* Allocate memory and read image, without alpha or 16-bit samples
 
	* (result is either 8-bit indexed/grayscale or 24-bit RGB) */
 
	 * (result is either 8-bit indexed/grayscale or 24-bit RGB) */
 
	png_set_packing(png_ptr);
 
	png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_PACKING | PNG_TRANSFORM_STRIP_ALPHA | PNG_TRANSFORM_STRIP_16, NULL);
 

	
 
	/* Maps of wrong color-depth are not used.
 
	 * (this should have been taken care of by stripping alpha and 16-bit samples on load) */
 
	if ((info_ptr->channels != 1) && (info_ptr->channels != 3) && (info_ptr->bit_depth != 8)) {
 
		ShowErrorMessage(STR_PNGMAP_ERR_IMAGE_TYPE, STR_PNGMAP_ERROR, 0, 0);
 
		fclose(fp);
 
		png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
 
		return false;
 
	}
 

	
 
	if (map != NULL) {
 
		*map = malloc(info_ptr->width * info_ptr->height * sizeof(byte));
 

	
 
		if (*map == NULL) {
 
			ShowErrorMessage(STR_PNGMAP_ERR_MISC, STR_PNGMAP_ERROR, 0, 0);
 
			fclose(fp);
 
			png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
 
			return false;
 
		}
 

	
 
		ReadHeightmapPNGImageData(*map, png_ptr, info_ptr);
 
	}