Simplify PNG loading a bit

This commit is contained in:
2025-09-24 20:14:07 +02:00
parent 534da64ea5
commit 295cbdb0a1
+5 -36
View File
@@ -24,8 +24,6 @@ glib_png_read (png_structp png_ptr, png_bytep out_bytes, png_size_t len)
World * World *
World_load_from_path (const char *path) World_load_from_path (const char *path)
{ {
UNUSED (path);
World *self = g_new0 (World, 1); World *self = g_new0 (World, 1);
self->buildings = g_array_new (FALSE, FALSE, sizeof (Building *)); self->buildings = g_array_new (FALSE, FALSE, sizeof (Building *));
@@ -69,42 +67,15 @@ World_load_from_path (const char *path)
self->tiles = g_array_sized_new (FALSE, FALSE, sizeof (MapTile *), self->tiles = g_array_sized_new (FALSE, FALSE, sizeof (MapTile *),
self->width * self->height); self->width * self->height);
png_byte color_type = png_get_color_type (png_ptr, info_ptr); png_set_expand (png_ptr);
png_byte bit_depth = png_get_bit_depth (png_ptr, info_ptr); png_set_gray_to_rgb (png_ptr);
png_set_filler (png_ptr, 0xFF, PNG_FILLER_AFTER);
if (bit_depth == 16) if (png_get_bit_depth (png_ptr, info_ptr) == 16)
{ {
png_set_strip_16 (png_ptr); png_set_strip_16 (png_ptr);
} }
if (color_type == PNG_COLOR_TYPE_PALETTE)
{
png_set_palette_to_rgb (png_ptr);
}
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
{
png_set_expand_gray_1_2_4_to_8 (png_ptr);
}
if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS))
{
png_set_tRNS_to_alpha (png_ptr);
}
if (color_type == PNG_COLOR_TYPE_RGB ||
color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_PALETTE)
{
png_set_filler (png_ptr, 0xFF, PNG_FILLER_AFTER);
}
if (color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
{
png_set_gray_to_rgb (png_ptr);
}
png_read_update_info (png_ptr, info_ptr); png_read_update_info (png_ptr, info_ptr);
int rowbytes = png_get_rowbytes (png_ptr, info_ptr); int rowbytes = png_get_rowbytes (png_ptr, info_ptr);
@@ -127,9 +98,7 @@ World_load_from_path (const char *path)
mt->y = y; mt->y = y;
unsigned char *px = &row_pointers[y][x * 4]; unsigned char *px = &row_pointers[y][x * 4];
unsigned char r = px[0]; unsigned char r = px[0], g = px[1], b = px[2];
unsigned char g = px[1];
unsigned char b = px[2];
/* Improved color ranges (handles light blue water better) */ /* Improved color ranges (handles light blue water better) */
if (b > 120 && (b > g || b > r)) if (b > 120 && (b > g || b > r))