Added support for Motion JPEG camera capture

Fixes https://github.com/libsdl-org/SDL/issues/12183
This commit is contained in:
Sam Lantinga 2025-02-07 08:27:37 -08:00
parent 3bc53b9ade
commit 84b0c13c44
16 changed files with 8267 additions and 59 deletions

View file

@ -1282,7 +1282,14 @@ static SDL_PixelFormat GetClosestSupportedFormat(SDL_Renderer *renderer, SDL_Pix
{
int i;
if (SDL_ISPIXELFORMAT_FOURCC(format)) {
if (format == SDL_PIXELFORMAT_MJPG) {
// We'll decode to SDL_PIXELFORMAT_RGBA32
for (i = 0; i < renderer->num_texture_formats; ++i) {
if (renderer->texture_formats[i] == SDL_PIXELFORMAT_RGBA32) {
return renderer->texture_formats[i];
}
}
} else if (SDL_ISPIXELFORMAT_FOURCC(format)) {
// Look for an exact match
for (i = 0; i < renderer->num_texture_formats; ++i) {
if (renderer->texture_formats[i] == format) {
@ -1444,7 +1451,9 @@ SDL_Texture *SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_Propert
texture->next = texture->native;
renderer->textures = texture;
if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
if (texture->format == SDL_PIXELFORMAT_MJPG) {
// We have a custom decode + upload path for this
} else if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
#ifdef SDL_HAVE_YUV
texture->yuv = SDL_SW_CreateYUVTexture(texture->format, texture->colorspace, w, h);
#else
@ -2030,9 +2039,9 @@ static bool SDL_UpdateTextureNative(SDL_Texture *texture, const SDL_Rect *rect,
if (!SDL_LockTexture(native, rect, &native_pixels, &native_pitch)) {
return false;
}
SDL_ConvertPixels(rect->w, rect->h,
texture->format, pixels, pitch,
native->format, native_pixels, native_pitch);
SDL_ConvertPixelsAndColorspace(rect->w, rect->h,
texture->format, texture->colorspace, 0, pixels, pitch,
native->format, native->colorspace, 0, native_pixels, native_pitch);
SDL_UnlockTexture(native);
} else {
// Use a temporary buffer for updating
@ -2043,9 +2052,9 @@ static bool SDL_UpdateTextureNative(SDL_Texture *texture, const SDL_Rect *rect,
if (!temp_pixels) {
return false;
}
SDL_ConvertPixels(rect->w, rect->h,
texture->format, pixels, pitch,
native->format, temp_pixels, temp_pitch);
SDL_ConvertPixelsAndColorspace(rect->w, rect->h,
texture->format, texture->colorspace, 0, pixels, pitch,
native->format, native->colorspace, 0, temp_pixels, temp_pitch);
SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch);
SDL_free(temp_pixels);
}