Skip to content

Commit

Permalink
Merge pull request #2477 from pygame-community/strip_sdl_from_pixelfo…
Browse files Browse the repository at this point in the history
…rmat

Strip the leading SDL_ from the pixel format name
  • Loading branch information
ankith26 authored Oct 7, 2023
2 parents e544d0f + d2287aa commit 01c6f22
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
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

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 @@ -312,26 +312,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

0 comments on commit 01c6f22

Please sign in to comment.