Skip to content
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

Move transform towards compiling w/ SDL3 #3314

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

Conversation

Starbuck5
Copy link
Member

#3310 but for transform.

@Starbuck5 Starbuck5 added transform pygame.transform sdl3 labels Jan 27, 2025
@Starbuck5 Starbuck5 requested a review from a team as a code owner January 27, 2025 07:37
@Starbuck5 Starbuck5 marked this pull request as draft January 27, 2025 07:37
@Starbuck5 Starbuck5 changed the title Move Surface towards compiling w/ SDL3 Move transform towards compiling w/ SDL3 Jan 27, 2025
Comment on lines 2412 to 2423
PG_GetRGBA(color, fmt, src_palette, &Cr, &Cg, &Cb, &Ca);
const Uint16 color16 =
(Uint16)PG_MapRGBA(newsurf_format, newsurf_palette, Cr, Cg, Cb, Ca);

for (y = 0; y < src->h; y++) {
for (x = 0; x < src->w; x++) {
SDL_GetRGBA((Uint32)*src_row, fmt, &r, &g, &b, &a);
PG_GetRGBA((Uint32)*src_row, fmt, src_palette, &r, &g, &b, &a);

if (a) {
if (keep_alpha)
*dst_row = (Uint16)SDL_MapRGBA(fmt, Cr, Cg, Cb, a);
*dst_row = (Uint16)PG_MapRGBA(
newsurf_format, newsurf_palette, Cr, Cg, Cb, a);
Copy link
Member Author

@Starbuck5 Starbuck5 Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Now marked outdated because of a formatting change)

So previously the color16= and *dst_row = (Uint16)SDL_MapRGBA lines here used the fmt variable, which represents the format of the surface "src".

However, these values are being mapped to "newsurf", not "src". So why is it written like this?

Well, the format enums are checked earlier, so the author of this code probably thought it made no difference.

However I can think of a case where passing in a destination surface with a custom palette into this would be different.

So I've changed the behavior here very slightly to be more correct, by mapping colors using the data of the surface being mapped to (newsurf). I don't think anyone will notice, I feel like this a very weird edge case, and this is a very new function as well. Regardless, if this change complicates this PR too much I can pull it out into a different PR or drop it.

@@ -2605,7 +2660,7 @@ modify_hsl(SDL_Surface *surf, SDL_Surface *dst, float h, float s, float l)
}

HSL_to_RGB(s_h, s_s, s_l, &r, &g, &b);
pixel = SDL_MapRGBA(fmt, r, g, b, a);
pixel = PG_MapRGBA(dst_format, dst_palette, r, g, b, a);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a similar situation here. Previously, it was using fmt, which represents the other surface, not the surface being written to.

@Starbuck5 Starbuck5 force-pushed the transform-sdl3-a-bit branch from 5812d7e to 4e24774 Compare January 27, 2025 07:47
@Starbuck5 Starbuck5 marked this pull request as ready for review January 28, 2025 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sdl3 transform pygame.transform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant