Changeset - r14195:ea01033bb77f
[Not reviewed]
master
0 3 0
glx - 15 years ago 2010-01-08 03:17:12
glx@openttd.org
(svn r18756) -Codechange: direct accesses to png_*_struct members are deprecated
3 files changed with 19 insertions and 19 deletions:
0 comments (0 inline, 0 general)
src/heightmap.cpp
Show inline comments
 
@@ -46,13 +46,13 @@ static void ReadHeightmapPNGImageData(by
 
{
 
	uint x, y;
 
	byte gray_palette[256];
 
	png_bytep *row_pointers = NULL;
 

	
 
	/* Get palette and convert it to grayscale */
 
	if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
 
	if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
 
		int i;
 
		int palette_size;
 
		png_color *palette;
 
		bool all_gray = true;
 

	
 
		png_get_PLTE(png_ptr, info_ptr, &palette, &palette_size);
 
@@ -74,20 +74,20 @@ static void ReadHeightmapPNGImageData(by
 
		}
 
	}
 

	
 
	row_pointers = png_get_rows(png_ptr, info_ptr);
 

	
 
	/* Read the raw image data and convert in 8-bit grayscale */
 
	for (x = 0; x < info_ptr->width; x++) {
 
		for (y = 0; y < info_ptr->height; y++) {
 
			byte *pixel = &map[y * info_ptr->width + x];
 
			uint x_offset = x * info_ptr->channels;
 
	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);
 

	
 
			if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
 
			if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
 
				*pixel = gray_palette[row_pointers[y][x_offset]];
 
			} else if (info_ptr->channels == 3) {
 
			} else if (png_get_channels(png_ptr, info_ptr) == 3) {
 
				*pixel = RGBToGrayscale(row_pointers[y][x_offset + 0],
 
						row_pointers[y][x_offset + 1], row_pointers[y][x_offset + 2]);
 
			} else {
 
				*pixel = row_pointers[y][x_offset];
 
			}
 
		}
 
@@ -132,26 +132,26 @@ static bool ReadHeightmapPNG(char *filen
 
	 * (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 colour-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)) {
 
	if ((png_get_channels(png_ptr, info_ptr) != 1) && (png_get_channels(png_ptr, info_ptr) != 3) && (png_get_bit_depth(png_ptr, info_ptr) != 8)) {
 
		ShowErrorMessage(STR_ERROR_PNGMAP, STR_ERROR_PNGMAP_IMAGE_TYPE, 0, 0);
 
		fclose(fp);
 
		png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
 
		return false;
 
	}
 

	
 
	if (map != NULL) {
 
		*map = MallocT<byte>(info_ptr->width * info_ptr->height);
 
		*map = MallocT<byte>(png_get_image_width(png_ptr, info_ptr) * png_get_image_height(png_ptr, info_ptr));
 
		ReadHeightmapPNGImageData(*map, png_ptr, info_ptr);
 
	}
 

	
 
	*x = info_ptr->width;
 
	*y = info_ptr->height;
 
	*x = png_get_image_width(png_ptr, info_ptr);
 
	*y = png_get_image_height(png_ptr, info_ptr);
 

	
 
	fclose(fp);
 
	png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
 
	return true;
 
}
 

	
src/screenshot.cpp
Show inline comments
 
@@ -204,13 +204,13 @@ static bool MakeBMPImage(const char *nam
 
#if defined(WITH_PNG)
 
#include <png.h>
 

	
 
static void PNGAPI png_my_error(png_structp png_ptr, png_const_charp message)
 
{
 
	DEBUG(misc, 0, "[libpng] error: %s - %s", message, (const char *)png_get_error_ptr(png_ptr));
 
	longjmp(png_ptr->jmpbuf, 1);
 
	longjmp(png_jmpbuf(png_ptr), 1);
 
}
 

	
 
static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message)
 
{
 
	DEBUG(misc, 1, "[libpng] warning: %s - %s", message, (const char *)png_get_error_ptr(png_ptr));
 
}
src/spriteloader/png.cpp
Show inline comments
 
@@ -25,13 +25,13 @@ static void PNGAPI png_my_read(png_struc
 
	FioReadBlock(data, length);
 
}
 

	
 
static void PNGAPI png_my_error(png_structp png_ptr, png_const_charp message)
 
{
 
	DEBUG(sprite, 0, "ERROR (libpng): %s - %s", message, (char *)png_get_error_ptr(png_ptr));
 
	longjmp(png_ptr->jmpbuf, 1);
 
	longjmp(png_jmpbuf(png_ptr), 1);
 
}
 

	
 
static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message)
 
{
 
	DEBUG(sprite, 0, "WARNING (libpng): %s - %s", message, (char *)png_get_error_ptr(png_ptr));
 
}
 
@@ -102,14 +102,14 @@ static bool LoadPNG(SpriteLoader::Sprite
 
		for (int i = 0; i < num_text; i++) {
 
			/* x_offs and y_offs are in the text-chunk of PNG */
 
			if (strcmp("x_offs", text_ptr[i].key) == 0) sprite->x_offs = strtol(text_ptr[i].text, NULL, 0);
 
			if (strcmp("y_offs", text_ptr[i].key) == 0) sprite->y_offs = strtol(text_ptr[i].text, NULL, 0);
 
		}
 

	
 
		sprite->height = info_ptr->height;
 
		sprite->width  = info_ptr->width;
 
		sprite->height = png_get_image_height(png_ptr, info_ptr);
 
		sprite->width  = png_get_image_width(png_ptr, info_ptr);
 
		sprite->AllocateData(sprite->width * sprite->height);
 
	}
 

	
 
	bit_depth  = png_get_bit_depth(png_ptr, info_ptr);
 
	colour_type = png_get_color_type(png_ptr, info_ptr);
 

	
 
@@ -136,20 +136,20 @@ static bool LoadPNG(SpriteLoader::Sprite
 

	
 
		pixelsize = sizeof(uint32);
 
	} else {
 
		pixelsize = sizeof(uint8);
 
	}
 

	
 
	png_bytep row_pointer = AllocaM(png_byte, info_ptr->width * pixelsize);
 
	png_bytep row_pointer = AllocaM(png_byte, png_get_image_width(png_ptr, info_ptr) * pixelsize);
 

	
 
	for (i = 0; i < info_ptr->height; i++) {
 
	for (i = 0; i < png_get_image_height(png_ptr, info_ptr); i++) {
 
		png_read_row(png_ptr, row_pointer, NULL);
 

	
 
		dst = sprite->data + i * info_ptr->width;
 
		dst = sprite->data + i * png_get_image_width(png_ptr, info_ptr);
 

	
 
		for (uint x = 0; x < info_ptr->width; x++) {
 
		for (uint x = 0; x < png_get_image_width(png_ptr, info_ptr); x++) {
 
			if (mask) {
 
				if (row_pointer[x * sizeof(uint8)] != 0) {
 
					dst[x].r = 0;
 
					dst[x].g = 0;
 
					dst[x].b = 0;
 
					/* Alpha channel is used from the original image (to allow transparency in remap colours) */
0 comments (0 inline, 0 general)