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

Image module SDL3 support #3166

Merged
merged 2 commits into from
Oct 18, 2024
Merged

Conversation

Starbuck5
Copy link
Member

@Starbuck5 Starbuck5 commented Oct 11, 2024

  • Rework argument order of PG_CreateSurfaceFrom to match newest SDL3 (they changed it)
  • Deal with all the pixelformat fallout throughout the file
  • Fix TGA saving routine file writes
  • Switch out SDL_SetPaletteColors (all colors) for SDL_SetSurfacePalette

If desired, I could split this out into a couple smaller PRs.

@@ -138,7 +138,7 @@ PG_UnlockMutex(SDL_mutex *mutex)

#define PG_CreateSurface(width, height, format) \
SDL_CreateRGBSurfaceWithFormat(0, width, height, 0, format)
#define PG_CreateSurfaceFrom(pixels, width, height, pitch, format) \
#define PG_CreateSurfaceFrom(width, height, format, pixels, pitch) \
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure to understand what is happening here. Why the arguments are in a whole new order ?

Copy link
Member

Choose a reason for hiding this comment

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

SDL3 changed the order of SDL_CreateSurfaceFrom, so this macro is being updated to match that order

Copy link
Contributor

Choose a reason for hiding this comment

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

But then it's not the macro argument order that needs to be changed, but the function arg order that's called.

Copy link
Member Author

Choose a reason for hiding this comment

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

This line is only compiled on SDL2, it defines a macro that re-orders the arguments from SDL3 style into the SDL2 function.

src_c/image.c Outdated Show resolved Hide resolved
#else
if (SDL_SetSurfacePalette(linebuf, surf_palette) < 0)
#endif
goto error; /* SDL error already set. */
Copy link
Member

Choose a reason for hiding this comment

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

This seems like the only somewhat concerning part of the PR to me. Why is the SDL2 codepath being changed to use different API in this case. Or rather, why does the current code use SDL_SetPaletteColors instead of SDL_SetSurfacePalette, could there be a reason for it?

Copy link
Member Author

@Starbuck5 Starbuck5 Oct 12, 2024

Choose a reason for hiding this comment

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

Yeah so my thought there is that setting a surface's palette is more simple than setting every color of a surface's palette to another surface's palette.

I know codepath changes make these harder to review so sorry about that.

In terms of reason why, I bet it's because SDL1's set palette does it color by color, it was probably ported from this. https://www.libsdl.org/release/SDL-1.2.15/docs/html/sdlsetpalette.html

#if IS_SDLv1
        SDL_SetColors (linebuf, surface->format->palette->colors, 0,
                       surface->format->palette->ncolors);
#else /* IS_SDLv2 */
        SDL_SetPaletteColors (linebuf->format->palette,
                              surface->format->palette->colors,
                              0, surface->format->palette->ncolors);

Ported from https://www.libsdl.org/release/SDL-1.2.15/docs/html/sdlsetcolors.html

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a test for TGA saving to hope to reassure you (and me!) that this works the same way, and now the tests are segfaulting on two of the Linux builds. I'm unclear if it's because of my changes or whether it would've segfaulted on the old implementation too.

Copy link
Member Author

Choose a reason for hiding this comment

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

The TGA test and the fix for that segfault went through in #3169

@@ -138,7 +138,7 @@ PG_UnlockMutex(SDL_mutex *mutex)

#define PG_CreateSurface(width, height, format) \
SDL_CreateRGBSurfaceWithFormat(0, width, height, 0, format)
#define PG_CreateSurfaceFrom(pixels, width, height, pitch, format) \
#define PG_CreateSurfaceFrom(width, height, format, pixels, pitch) \
Copy link
Member

Choose a reason for hiding this comment

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

SDL3 changed the order of SDL_CreateSurfaceFrom, so this macro is being updated to match that order

@bilhox bilhox modified the milestones: 2.5.3, 3.0.0 Oct 13, 2024
- Rework argument order of PG_CreateSurfaceFrom to match newest SDL3 (they changed it)
- Deal with all the pixelformat fallout throughout the file
- Fix TGA saving routine file writes
- Switch out SDL_SetPaletteColors (all colors) for SDL_SetSurfacePalette
Copy link
Member

@ankith26 ankith26 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the PR 🎉

Copy link
Contributor

@bilhox bilhox left a comment

Choose a reason for hiding this comment

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

LGTM !

@ankith26 ankith26 merged commit a5002cf into pygame-community:main Oct 18, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
image pygame.image sdl3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants