Просмотр исходного кода

video: add more direct mjpeg to yuv conversions

(cherry picked from commit 998159fa954993693774449df5c129cb415461d4)
Green Sky 1 день назад
Родитель
Сommit
4b8fcb468b
1 измененных файлов с 32 добавлено и 2 удалено
  1. 32 2
      src/video/SDL_stb.c

+ 32 - 2
src/video/SDL_stb.c

@@ -22,6 +22,7 @@
 
 
 #include "SDL_stb_c.h"
 #include "SDL_stb_c.h"
 #include "SDL_surface_c.h"
 #include "SDL_surface_c.h"
+#include "SDL_yuv_c.h"
 
 
 /* STB image conversion */
 /* STB image conversion */
 #ifndef SDL_DISABLE_STB
 #ifndef SDL_DISABLE_STB
@@ -114,8 +115,37 @@ bool SDL_ConvertPixels_STB(int width, int height,
                            SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch)
                            SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch)
 {
 {
 #ifdef SDL_HAVE_STB
 #ifdef SDL_HAVE_STB
-    if (src_format == SDL_PIXELFORMAT_MJPG && dst_format == SDL_PIXELFORMAT_NV12) {
-        return SDL_ConvertPixels_MJPG_to_NV12(width, height, src, src_pitch, dst, dst_pitch);
+    if (src_format == SDL_PIXELFORMAT_MJPG) {
+        if (dst_format == SDL_PIXELFORMAT_NV12) {
+            return SDL_ConvertPixels_MJPG_to_NV12(width, height, src, src_pitch, dst, dst_pitch);
+        } else if (
+            dst_format == SDL_PIXELFORMAT_YV12 ||
+            dst_format == SDL_PIXELFORMAT_IYUV ||
+            dst_format == SDL_PIXELFORMAT_YUY2 ||
+            dst_format == SDL_PIXELFORMAT_UYVY ||
+            dst_format == SDL_PIXELFORMAT_YVYU ||
+            dst_format == SDL_PIXELFORMAT_NV21 ||
+            dst_format == SDL_PIXELFORMAT_P010
+        ) {
+            size_t temp_size = 0;
+            size_t temp_pitch = 0;
+            if (!SDL_CalculateYUVSize(dst_format, width, height, &temp_size, &temp_pitch)) {
+                return false;
+            }
+            void *temp_pixels = SDL_malloc(temp_size);
+            if (!temp_pixels) {
+                return false;
+            }
+
+            if (!SDL_ConvertPixels_MJPG_to_NV12(width, height, src, src_pitch, temp_pixels, (int)temp_pitch)) {
+                SDL_free(temp_pixels);
+                return false;
+            }
+
+            bool result = SDL_ConvertPixelsAndColorspace(width, height, SDL_PIXELFORMAT_NV12, src_colorspace, 0 /*props*/, temp_pixels, (int)temp_pitch, dst_format, dst_colorspace, dst_properties, dst, dst_pitch);
+            SDL_free(temp_pixels);
+            return result;
+        }
     }
     }
 
 
     bool result;
     bool result;