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

Strip the leading SDL_ from the pixel format name #2477

Merged
merged 8 commits into from
Oct 7, 2023
1 change: 1 addition & 0 deletions buildconfig/stubs/pygame/display.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class _VidInfo:
blit_sw_A: int
current_h: int
current_w: int
pixel_format: str
MyreMylar marked this conversation as resolved.
Show resolved Hide resolved

def init() -> None: ...
def quit() -> None: ...
Expand Down
25 changes: 16 additions & 9 deletions docs/reST/ref/display.rst
Original file line number Diff line number Diff line change
Expand Up @@ -311,26 +311,33 @@ required).
mode to verify specific display options were satisfied. The VidInfo object
has several attributes:

::
.. code-block:: text

hw: 1 if the display is hardware accelerated
wm: 1 if windowed display modes can be used
video_mem: The megabytes of video memory on the display. This is 0 if
unknown
video_mem: The megabytes of video memory on the display.
This is 0 if unknown
bitsize: Number of bits used to store each pixel
bytesize: Number of bytes used to store each pixel
masks: Four values used to pack RGBA values into pixels
shifts: Four values used to pack RGBA values into pixels
losses: Four values used to pack RGBA values into pixels
blit_hw: 1 if hardware Surface blitting is accelerated
blit_hw_CC: 1 if hardware Surface colorkey blitting is accelerated
blit_hw_A: 1 if hardware Surface pixel alpha blitting is accelerated
blit_hw_A: 1 if hardware Surface pixel alpha blitting is
accelerated
blit_sw: 1 if software Surface blitting is accelerated
blit_sw_CC: 1 if software Surface colorkey blitting is accelerated
blit_sw_A: 1 if software Surface pixel alpha blitting is accelerated
current_h, current_w: Height and width of the current video mode, or
of the desktop mode if called before the display.set_mode
is called. They are -1 on error.
blit_sw_CC: 1 if software Surface colorkey blitting is
accelerated
blit_sw_A: 1 if software Surface pixel alpha blitting is
accelerated
current_h, current_w: Height and width of the current video
mode, or of the desktop mode if called before
the display.set_mode is called. They are -1 on error.
pixel_format: The pixel format of the display Surface as a string.
E.g PIXELFORMAT_RGB888.

.. versionchanged:: 2.4.0 ``pixel_format`` attribute added.

.. ## pygame.display.Info ##

Expand Down
11 changes: 11 additions & 0 deletions src_c/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,14 @@ pg_vidinfo_getattr(PyObject *self, char *name)
return PyLong_FromLong(current_h);
else if (!strcmp(name, "current_w"))
return PyLong_FromLong(current_w);
else if (!strcmp(name, "pixel_format")) {
const char *pixel_format_name =
SDL_GetPixelFormatName(info->vfmt->format);
if (!strncmp(pixel_format_name, "SDL_", 4)) {
pixel_format_name += 4;
}
return PyUnicode_FromString(pixel_format_name);
}

return RAISE(PyExc_AttributeError, "does not exist in vidinfo");
}
Expand All @@ -335,6 +343,9 @@ pg_vidinfo_str(PyObject *self)
int current_h = -1;
pg_VideoInfo *info = &((pgVidInfoObject *)self)->info;
const char *pixel_format_name = SDL_GetPixelFormatName(info->vfmt->format);
if (!strncmp(pixel_format_name, "SDL_", 4)) {
pixel_format_name += 4;
}

SDL_version versioninfo;
SDL_VERSION(&versioninfo);
Expand Down
Loading