SDL: Camera api returns weird surface

SDL_AcquireCameraFrame() returns a strange surface. This happens even after SDL_GetCameraPermissionState() starts returning 1. I first spotted this while playing around with the API but the testcamera example also has the same problem. I am on windows and built the SDL3 pre-release with the msys2 ucrt64 toolchain. My camera is a built-in laptop camera. Just to clarify I can see myself on the screen but the image/surface has a lot of artefacts and a greenish tinge.

About this issue

  • Original URL
  • State: closed
  • Created 3 months ago
  • Comments: 23 (4 by maintainers)

Most upvoted comments

(also I switched testcamera to use streaming textures)

FYI, I’m able to reproduce this here. I’m taking a look.

Currently SDL_Surface expects the planes to be contiguous and tightly packed, so you can extract the planes from it. We have an issue open to allow a surface to have multiple planes, but nothing has come of it yet.

Oh, ok. But I don’t understand if it’s the surface then why drawing the surface with old Surface API, software rendering, saving the surface with IMG_SavePNG and the Vulkan renderer don’t have the issue? The issue is only seen when I use functions like SDL_UpdateTexture or SDL_CreateTextureFromSurface (with a renderer other than Vulkan or software). Anyways, I hope that things will become somewhat more clear if/when Sam takes a look at the pixel dump.

That’s a bug (that’s probably unrelated to this one) that we haven’t had time to deal with yet. Sorry about that!

No need to be sorry lol. We greatly appreciate the effort you guys put in maintaining SDL.

Hm, did you lock the surface before accessing pixels? I also am not sure you can extract the planes from SDL_Surface.

Currently SDL_Surface expects the planes to be contiguous and tightly packed, so you can extract the planes from it. We have an issue open to allow a surface to have multiple planes, but nothing has come of it yet.

Hmm strangely the person who wrote the example also uses SDL_TEXTURE_STATIC flag while creating the texture, which is contradictory if I understand the flag correctly.

That’s a bug (that’s probably unrelated to this one) that we haven’t had time to deal with yet. Sorry about that!

And locking/unlocking the surface doesn’t help. Also SDL_MUSTLOCK evaluates to 0 confirming that locking is not necessary here.

And this is the kind of image I get if I keep a white sheet in front of the camera. image