pygame-ce icon indicating copy to clipboard operation
pygame-ce copied to clipboard

Port Image to C code

Open MightyJosip opened this issue 9 months ago โ€ข 4 comments
trafficstars

This PR converts pygame._sdl2.video.Image to C code. It has the implementation of all the Image methods and attributes. It doesn't have docs/type hints/tests or stuff like that.

Leaving this as the draft atm, because it depends on https://github.com/pygame-community/pygame-ce/pull/3317, https://github.com/pygame-community/pygame-ce/pull/3327 and #3330, pushing just for the internal testing purposes

MightyJosip avatar Feb 08 '25 14:02 MightyJosip

@MightyJosip The other ones have been merged, now it's this PRs turn! Looks like it needs to be updated and done whatever needs to happen to get it ready for review.

Starbuck5 avatar Aug 17 '25 07:08 Starbuck5

๐Ÿ“ Walkthrough

Walkthrough

Adds a full public API for pygame Image in stubs and C implementation: properties, initialization, get_rect, and draw with srcrect/dstrect, origin, flips, color/alpha/blend handling. Updates renderer docs string for blit. Introduces helper functions and dealloc/init for Image. Adds comprehensive tests for Image behavior.

Changes

Cohort / File(s) Summary
Image public API stubs
buildconfig/stubs/pygame/_render.pyi
Replaces placeholder Image with full signatures: constructor, properties (alpha, angle, blend_mode, color, flip_x, flip_y, origin, srcrect, texture), get_rect, draw; adds type hints.
Renderer/Image C implementation
src_c/render.c
Implements Image methods (get_rect, draw), getters/setters for properties, initialization/deallocation, rendering path with srcrect/dstrect, origin, flips, color/alpha/blend mode via SDL helpers; updates pgImage_Type tables; adjusts renderer blit doc string constant.
Tests for Image
test/render_test.py
Adds ImageTest covering initialization, all properties, get_rect, draw (with transforms), and error handling for invalid inputs/types.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Py as Python Code
  participant Img as Image
  participant Ren as SDL_Renderer
  participant Tex as SDL_Texture

  Py->>Img: draw(srcrect?, dstrect?)
  activate Img
  note over Img: Resolve srcrect (from arg or property)<br/>Parse dstrect (arg or from srcrect/texture size)
  Img->>Img: Compute origin (if any) and flip flags
  Img->>Tex: Set blend mode/color modulation/alpha
  Img->>Ren: SDL_RenderCopyExF(Tex, srcrect, dstrect, angle, origin, flips)
  Ren-->>Img: int (success/failure)
  deactivate Img
  Img-->>Py: None or raises on error

Estimated code review effort

๐ŸŽฏ 4 (Complex) | โฑ๏ธ ~60 minutes

[!TIP]

๐Ÿ”Œ Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

โœจ Finishing Touches
  • [ ] ๐Ÿ“ Generate Docstrings
๐Ÿงช Generate unit tests
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

โค๏ธ Share
๐Ÿชง Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Aug 26 '25 19:08 coderabbitai[bot]

I did a little bit of the merging work so we can see what we are working with here. Still needs tests and documentation.

MyreMylar avatar Aug 26 '25 19:08 MyreMylar

Ran this through some AI suggestions on my home PC and they seemed sensible changes. We'll see what the PR review AI has to say. Otherwise, this seems about as complete as the previous PRs in this series.

MyreMylar avatar Aug 31 '25 19:08 MyreMylar