Skip to content

Fix SRCALPHA TGA image saving #3432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

ankith26
Copy link
Member

This PR is a fix for an issue @fladd raised on the og pygame repo.

Essentially, images with per pixel alpha were not being saved to TGA correctly because there was blending happening in intermediate steps that should not happen. This was being prevented for blanket alpha and color key alpha cases already in the code, but not for per pixel alpha cases. This PR implements a more generic blendmode based approach so that all cases are handled correctly.

Reproducer code for this issue (by @fladd, from the original issue)

import pygame

pygame.init()
screen = pygame.display.set_mode((800, 600))

circle_color = (255, 0, 0, 255)
circle_surface = pygame.Surface((800, 600), pygame.SRCALPHA)
pygame.draw.circle(circle_surface, circle_color, (400, 300), 100)

# Save the circle surface as an image
pygame.image.save(circle_surface, 'image.tga')

@ankith26 ankith26 requested a review from a team as a code owner May 17, 2025 07:09
@ankith26
Copy link
Member Author

Note that with this PR my aim is to not change existing behaviour for other types of images, even though I have noticed inconsistencies with the code.

  • blanket alpha is completely ignored in all cases... which is fine but it is also easily fixable, but may also break someones usecase
  • colorkey is handled in the 8 bit path but not in the 24/32 bit path

@Starbuck5
Copy link
Member

What do you think about dropping TGA in 3.0? It's not exactly a popular format.

@ankith26
Copy link
Member Author

Given the inconsistencies and the fact that we maintain this code on our side, it makes sense to drop it in a breaking release IMO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants