Issue #34 new

document surface vs texture vs buffer vs pixelview

anatoly techtonik
created an issue

It is pretty confusing to read documentation that speaks about abstract pixels, with some vague connection to bytes in video memory, system memory and the ways Python protects people from messing with those.

I am trying to start with representation of pixel data in Python list and documentation doesn't give me a glue how can I convert it to picture. For that, I need to know:

  1. what input buffer formats of raw pixel data are used by SDL2
  2. how do these look in PySDL2 and why
  3. what is the transformation chain from Python variable to pixel on the screen
  4. how does Python hides direct access to memory (why it is slow)

Actually, the (1,3) are the two most important.

Comments (3)

  1. Marcus von Appen repo owner

    I am not sure to what documentation you refer to, but PySDL2 does not protect you from messing with the bytes in system or video memory. You can gain read-write access to the pixel buffers of a texture or software surface via PySDL2 without any problems (and also without any safety net).

    1. SDL2 supports a variety of formats. An overview about the different supported formats can be found at
    2. PySDL2 provides a wrapper around the SDL2 internals. Hence there are no differences, since PySDL2 uses the C structures of SDL2 and just refers to the memory locations.
    3. I do not understand the question
    4. Are we talking about Python (the language) or PySDL2 here? The latter does not hide direct access to memory. Direct access is provided via ctypes.
  2. anatoly techtonik reporter

    PySDL2 doesn't protect me from the complexity of SDL2 layer. =) I am looking to some intro / guideline about pixel manipulations with regard to helpers that PySDL2 provides.

    1. Thanks. This page helps. I'd still be interested to see some guidelines about how to use them. What are the most efficient pixel formats? How are they represented in SDL2? How they can be represented in Python? Where to set these pixel format? And how to convert my list of integers to pixel buffer? How to get that pixel buffer shown in window?

    2. There are PixelView and friends - How are they different from continuous C memory buffer packed with raw pixel data? What is ctypes equivalent for these structures? Where memory buffer is locate - in CPU memory or in GPU memory? Can I edit CPU and GPU memory directly? Is it more efficient in Python than converting lists of ints?

    3. I want to have a pixel at 50,50. White. I figure out that white == (255,255,255), so what should I do to pixel = (50,50,(255,255,255) to make white dot appear on the screen? How processing will be different if I have a line of pixels?

    4. So, the ctypes is the only way to edit the memory directly? What about memoryview? How memory editing in Python is different from the same operation in C - is it optimized?

    So basically I am looking for some guidelines how a pixel pipeline works in SDL2. Something like or with regard to SDL2 terms.

  3. Log in to comment