|
@@ -135,56 +135,56 @@ static bool LoadPNG(SpriteLoader::Sprite
|
|
|
#ifdef TTD_LITTLE_ENDIAN
|
|
|
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
|
|
|
#else
|
|
|
png_set_filler(png_ptr, 0xff, PNG_FILLER_BEFORE);
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
pixelsize = sizeof(uint32);
|
|
|
} else {
|
|
|
pixelsize = sizeof(uint8);
|
|
|
}
|
|
|
|
|
|
row_pointer = (png_byte *)malloc(info_ptr->width * pixelsize);
|
|
|
if (row_pointer == NULL) {
|
|
|
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
for (i = 0; i < info_ptr->height; i++) {
|
|
|
png_read_row(png_ptr, row_pointer, NULL);
|
|
|
|
|
|
dst = sprite->data + i * info_ptr->width;
|
|
|
|
|
|
for (uint x = 0; x < info_ptr->width; x++) {
|
|
|
if (mask) {
|
|
|
if (row_pointer[x * sizeof(uint8)] != 0) {
|
|
|
dst[x].b = 0;
|
|
|
dst[x].g = 0;
|
|
|
dst[x].r = 0;
|
|
|
/* Alpha channel is used from the original image (to allow transparency in remap colors) */
|
|
|
dst[x].m = row_pointer[x * sizeof(uint8)];
|
|
|
}
|
|
|
} else {
|
|
|
dst[x].b = row_pointer[x * sizeof(uint32) + 0];
|
|
|
dst[x].g = row_pointer[x * sizeof(uint32) + 1];
|
|
|
dst[x].r = row_pointer[x * sizeof(uint32) + 2];
|
|
|
dst[x].a = row_pointer[x * sizeof(uint32) + 3];
|
|
|
dst[x].m = 0;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
free(row_pointer);
|
|
|
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
bool SpriteLoaderPNG::LoadSprite(SpriteLoader::Sprite *sprite, const char *filename, uint32 file_pos)
|
|
|
bool SpriteLoaderPNG::LoadSprite(SpriteLoader::Sprite *sprite, const char *filename, uint8 file_slot, uint32 file_pos)
|
|
|
{
|
|
|
if (!LoadPNG(sprite, filename, file_pos, false)) return false;
|
|
|
if (!LoadPNG(sprite, filename, file_pos, true)) return false;
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
#endif /* WITH_PNG */
|