From 284dc8f0722ed711ab9a1eece6a07fdd1a665cc0 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 24 Nov 2008 23:25:36 +0000 Subject: [PATCH] Added software fallback for YUV overlay code when YUV textures aren't available. --- VisualC/tests/testoverlay/testoverlay.dsp | 102 ++++++++ VisualC/tests/testoverlay/testoverlay.vcproj | 217 ++++++++++++++++++ VisualC/tests/testoverlay2/testoverlay2.dsp | 102 ++++++++ .../tests/testoverlay2/testoverlay2.vcproj | 217 ++++++++++++++++++ VisualC/tests/tests.dsw | 24 ++ VisualC/tests/tests.sln | 12 + src/SDL_compat.c | 49 +++- src/stdlib/SDL_stdlib.c | 1 - src/video/SDL_renderer_sw.c | 2 +- src/video/SDL_yuv_sw.c | 65 +++--- src/video/SDL_yuv_sw_c.h | 2 +- src/video/win32/SDL_gdirender.c | 2 +- 12 files changed, 751 insertions(+), 44 deletions(-) create mode 100644 VisualC/tests/testoverlay/testoverlay.dsp create mode 100644 VisualC/tests/testoverlay/testoverlay.vcproj create mode 100644 VisualC/tests/testoverlay2/testoverlay2.dsp create mode 100644 VisualC/tests/testoverlay2/testoverlay2.vcproj diff --git a/VisualC/tests/testoverlay/testoverlay.dsp b/VisualC/tests/testoverlay/testoverlay.dsp new file mode 100644 index 000000000..c525ec36b --- /dev/null +++ b/VisualC/tests/testoverlay/testoverlay.dsp @@ -0,0 +1,102 @@ +# Microsoft Developer Studio Project File - Name="testoverlay" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 5.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Application" 0x0101 + +CFG=testoverlay - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "testoverlay.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "testoverlay.mak" CFG="testoverlay - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "testoverlay - Win32 Release" (based on "Win32 (x86) Application") +!MESSAGE "testoverlay - Win32 Debug" (based on "Win32 (x86) Application") +!MESSAGE + +# Begin Project +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "testoverlay - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386 + +!ELSEIF "$(CFG)" == "testoverlay - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "testoverlay - Win32 Release" +# Name "testoverlay - Win32 Debug" +# Begin Source File + +SOURCE=..\..\Sdl\Debug\SDL.lib +# End Source File +# Begin Source File + +SOURCE=..\..\SDLmain\Debug\SDLmain.lib +# End Source File +# Begin Source File + +SOURCE=..\..\..\test\testoverlay.c +# End Source File +# End Target +# End Project diff --git a/VisualC/tests/testoverlay/testoverlay.vcproj b/VisualC/tests/testoverlay/testoverlay.vcproj new file mode 100644 index 000000000..e5b80cac4 --- /dev/null +++ b/VisualC/tests/testoverlay/testoverlay.vcproj @@ -0,0 +1,217 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/VisualC/tests/testoverlay2/testoverlay2.dsp b/VisualC/tests/testoverlay2/testoverlay2.dsp new file mode 100644 index 000000000..c8da92bdb --- /dev/null +++ b/VisualC/tests/testoverlay2/testoverlay2.dsp @@ -0,0 +1,102 @@ +# Microsoft Developer Studio Project File - Name="testoverlay2" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 5.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Application" 0x0101 + +CFG=testoverlay2 - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "testoverlay2.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "testoverlay2.mak" CFG="testoverlay2 - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "testoverlay2 - Win32 Release" (based on "Win32 (x86) Application") +!MESSAGE "testoverlay2 - Win32 Debug" (based on "Win32 (x86) Application") +!MESSAGE + +# Begin Project +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "testoverlay2 - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386 + +!ELSEIF "$(CFG)" == "testoverlay2 - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "testoverlay2 - Win32 Release" +# Name "testoverlay2 - Win32 Debug" +# Begin Source File + +SOURCE=..\..\Sdl\Debug\SDL.lib +# End Source File +# Begin Source File + +SOURCE=..\..\SDLmain\Debug\SDLmain.lib +# End Source File +# Begin Source File + +SOURCE=..\..\..\test\testoverlay2.c +# End Source File +# End Target +# End Project diff --git a/VisualC/tests/testoverlay2/testoverlay2.vcproj b/VisualC/tests/testoverlay2/testoverlay2.vcproj new file mode 100644 index 000000000..1cd1e44da --- /dev/null +++ b/VisualC/tests/testoverlay2/testoverlay2.vcproj @@ -0,0 +1,217 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/VisualC/tests/tests.dsw b/VisualC/tests/tests.dsw index 8437fc15b..9fb1f5ea0 100644 --- a/VisualC/tests/tests.dsw +++ b/VisualC/tests/tests.dsw @@ -99,6 +99,30 @@ Package=<4> ############################################################################### +Project: "testoverlay"=".\testoverlay\testoverlay.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "testoverlay2"=".\testoverlay2\testoverlay2.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + Project: "testpalette"=".\testpalette\testpalette.dsp" - Package Owner=<4> Package=<5> diff --git a/VisualC/tests/tests.sln b/VisualC/tests/tests.sln index d953140a2..f60a5162c 100644 --- a/VisualC/tests/tests.sln +++ b/VisualC/tests/tests.sln @@ -28,6 +28,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testgl2", "testgl2\testgl2. EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "checkkeys", "checkkeys\checkkeys.vcproj", "{26828762-C95D-4637-9CB1-7F0979523813}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testoverlay", "testoverlay\testoverlay.vcproj", "{9E320A14-B443-4DD7-8725-B7020DCFF730}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testoverlay2", "testoverlay2\testoverlay2.vcproj", "{B51E0D74-F0A2-45A2-BD2A-8B7D95B8204A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -90,6 +94,14 @@ Global {26828762-C95D-4637-9CB1-7F0979523813}.Debug|Win32.Build.0 = Debug|Win32 {26828762-C95D-4637-9CB1-7F0979523813}.Release|Win32.ActiveCfg = Release|Win32 {26828762-C95D-4637-9CB1-7F0979523813}.Release|Win32.Build.0 = Release|Win32 + {9E320A14-B443-4DD7-8725-B7020DCFF730}.Debug|Win32.ActiveCfg = Debug|Win32 + {9E320A14-B443-4DD7-8725-B7020DCFF730}.Debug|Win32.Build.0 = Debug|Win32 + {9E320A14-B443-4DD7-8725-B7020DCFF730}.Release|Win32.ActiveCfg = Release|Win32 + {9E320A14-B443-4DD7-8725-B7020DCFF730}.Release|Win32.Build.0 = Release|Win32 + {B51E0D74-F0A2-45A2-BD2A-8B7D95B8204A}.Debug|Win32.ActiveCfg = Debug|Win32 + {B51E0D74-F0A2-45A2-BD2A-8B7D95B8204A}.Debug|Win32.Build.0 = Debug|Win32 + {B51E0D74-F0A2-45A2-BD2A-8B7D95B8204A}.Release|Win32.ActiveCfg = Release|Win32 + {B51E0D74-F0A2-45A2-BD2A-8B7D95B8204A}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/SDL_compat.c b/src/SDL_compat.c index b210a6c04..80e74d36b 100644 --- a/src/SDL_compat.c +++ b/src/SDL_compat.c @@ -28,6 +28,7 @@ #include "video/SDL_sysvideo.h" #include "video/SDL_pixels_c.h" +#include "video/SDL_yuv_sw_c.h" static SDL_WindowID SDL_VideoWindow = 0; static SDL_RendererInfo SDL_VideoRendererInfo; @@ -1349,6 +1350,8 @@ struct private_yuvhwdata Uint16 pitches[3]; Uint8 *planes[3]; + SDL_SW_YUVTexture *sw; + SDL_TextureID textureID; }; @@ -1431,7 +1434,20 @@ SDL_CreateYUVOverlay(int w, int h, Uint32 format, SDL_Surface * display) overlay->hwdata->textureID = SDL_CreateTexture(texture_format, SDL_TEXTUREACCESS_STREAMING, w, h); - if (!overlay->hwdata->textureID) { + if (overlay->hwdata->textureID) { + overlay->hwdata->sw = NULL; + } else { + overlay->hwdata->sw = SDL_SW_CreateYUVTexture(texture_format, w, h); + if (!overlay->hwdata->sw) { + SDL_FreeYUVOverlay(overlay); + return NULL; + } + + /* Create a supported RGB format texture for display */ + overlay->hwdata->textureID = + SDL_CreateTexture(SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, w, h); + } + if (!overlay->hwdata->textureID) { SDL_FreeYUVOverlay(overlay); return NULL; } @@ -1449,10 +1465,16 @@ SDL_LockYUVOverlay(SDL_Overlay * overlay) SDL_SetError("Passed a NULL overlay"); return -1; } - if (SDL_LockTexture(overlay->hwdata->textureID, NULL, 1, &pixels, &pitch) - < 0) { - return -1; - } + if (overlay->hwdata->sw) { + if (SDL_SW_QueryYUVTexturePixels(overlay->hwdata->sw, &pixels, &pitch) < 0) { + return -1; + } + } else { + if (SDL_LockTexture(overlay->hwdata->textureID, NULL, 1, &pixels, &pitch) + < 0) { + return -1; + } + } overlay->pixels[0] = (Uint8 *) pixels; overlay->pitches[0] = pitch; switch (overlay->format) { @@ -1479,7 +1501,22 @@ SDL_UnlockYUVOverlay(SDL_Overlay * overlay) if (!overlay) { return; } - SDL_UnlockTexture(overlay->hwdata->textureID); + if (overlay->hwdata->sw) { + void *pixels; + int pitch; + if (SDL_LockTexture(overlay->hwdata->textureID, NULL, 1, &pixels, &pitch) == 0) { + SDL_Rect srcrect; + + srcrect.x = 0; + srcrect.y = 0; + srcrect.w = overlay->w; + srcrect.h = overlay->h; + SDL_SW_CopyYUVToRGB(overlay->hwdata->sw, &srcrect, SDL_PIXELFORMAT_RGB888, overlay->w, overlay->h, pixels, pitch); + SDL_UnlockTexture(overlay->hwdata->textureID); + } + } else { + SDL_UnlockTexture(overlay->hwdata->textureID); + } } int diff --git a/src/stdlib/SDL_stdlib.c b/src/stdlib/SDL_stdlib.c index 168b9ad27..206cce575 100644 --- a/src/stdlib/SDL_stdlib.c +++ b/src/stdlib/SDL_stdlib.c @@ -90,7 +90,6 @@ __declspec(selectany) } void -__declspec(naked) _ftol2_sse() { _ftol(); diff --git a/src/video/SDL_renderer_sw.c b/src/video/SDL_renderer_sw.c index a0aef99bf..679d75ce2 100644 --- a/src/video/SDL_renderer_sw.c +++ b/src/video/SDL_renderer_sw.c @@ -361,7 +361,7 @@ static int SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) { if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { - texture->driverdata = SDL_SW_CreateYUVTexture(texture); + texture->driverdata = SDL_SW_CreateYUVTexture(texture->format, texture->w, texture->h); } else { int bpp; Uint32 Rmask, Gmask, Bmask, Amask; diff --git a/src/video/SDL_yuv_sw.c b/src/video/SDL_yuv_sw.c index 3f349bb65..035458812 100644 --- a/src/video/SDL_yuv_sw.c +++ b/src/video/SDL_yuv_sw.c @@ -91,9 +91,9 @@ struct SDL_SW_YUVTexture { - SDL_Texture *texture; - + Uint32 format; Uint32 target_format; + int w, h; Uint8 *pixels; int *colortab; Uint32 *rgb_2_pix; @@ -974,7 +974,7 @@ SDL_SW_SetupYUVDisplay(SDL_SW_YUVTexture * swdata, Uint32 target_format) } /* You have chosen wisely... */ - switch (swdata->texture->format) { + switch (swdata->format) { case SDL_PIXELFORMAT_YV12: case SDL_PIXELFORMAT_IYUV: if (SDL_BYTESPERPIXEL(target_format) == 2) { @@ -982,7 +982,7 @@ SDL_SW_SetupYUVDisplay(SDL_SW_YUVTexture * swdata, Uint32 target_format) /* inline assembly functions */ if (SDL_HasMMX() && (Rmask == 0xF800) && (Gmask == 0x07E0) && (Bmask == 0x001F) - && (swdata->texture->w & 15) == 0) { + && (swdata->w & 15) == 0) { /*printf("Using MMX 16-bit 565 dither\n");*/ swdata->Display1X = Color565DitherYV12MMX1X; } else { @@ -1003,7 +1003,7 @@ SDL_SW_SetupYUVDisplay(SDL_SW_YUVTexture * swdata, Uint32 target_format) /* inline assembly functions */ if (SDL_HasMMX() && (Rmask == 0x00FF0000) && (Gmask == 0x0000FF00) && - (Bmask == 0x000000FF) && (swdata->texture->w & 15) == 0) { + (Bmask == 0x000000FF) && (swdata->w & 15) == 0) { /*printf("Using MMX 32-bit dither\n");*/ swdata->Display1X = ColorRGBDitherYV12MMX1X; } else { @@ -1045,7 +1045,7 @@ SDL_SW_SetupYUVDisplay(SDL_SW_YUVTexture * swdata, Uint32 target_format) } SDL_SW_YUVTexture * -SDL_SW_CreateYUVTexture(SDL_Texture * texture) +SDL_SW_CreateYUVTexture(Uint32 format, int w, int h) { SDL_SW_YUVTexture *swdata; int *Cr_r_tab; @@ -1061,7 +1061,7 @@ SDL_SW_CreateYUVTexture(SDL_Texture * texture) return NULL; } - switch (texture->format) { + switch (format) { case SDL_PIXELFORMAT_YV12: case SDL_PIXELFORMAT_IYUV: case SDL_PIXELFORMAT_YUY2: @@ -1073,9 +1073,11 @@ SDL_SW_CreateYUVTexture(SDL_Texture * texture) return NULL; } - swdata->texture = texture; + swdata->format = format; swdata->target_format = SDL_PIXELFORMAT_UNKNOWN; - swdata->pixels = (Uint8 *) SDL_malloc(texture->w * texture->h * 2); + swdata->w = w; + swdata->h = h; + swdata->pixels = (Uint8 *) SDL_malloc(w * h * 2); swdata->colortab = (int *) SDL_malloc(4 * 256 * sizeof(int)); swdata->rgb_2_pix = (Uint32 *) SDL_malloc(3 * 768 * sizeof(Uint32)); if (!swdata->pixels || !swdata->colortab || !swdata->rgb_2_pix) { @@ -1101,22 +1103,22 @@ SDL_SW_CreateYUVTexture(SDL_Texture * texture) } /* Find the pitch and offset values for the overlay */ - switch (texture->format) { + switch (format) { case SDL_PIXELFORMAT_YV12: case SDL_PIXELFORMAT_IYUV: - swdata->pitches[0] = texture->w; + swdata->pitches[0] = w; swdata->pitches[1] = swdata->pitches[0] / 2; swdata->pitches[2] = swdata->pitches[0] / 2; swdata->planes[0] = swdata->pixels; swdata->planes[1] = - swdata->planes[0] + swdata->pitches[0] * texture->h; + swdata->planes[0] + swdata->pitches[0] * h; swdata->planes[2] = - swdata->planes[1] + swdata->pitches[1] * texture->h / 2; + swdata->planes[1] + swdata->pitches[1] * h / 2; break; case SDL_PIXELFORMAT_YUY2: case SDL_PIXELFORMAT_UYVY: case SDL_PIXELFORMAT_YVYU: - swdata->pitches[0] = texture->w * 2; + swdata->pitches[0] = w * 2; swdata->planes[0] = swdata->pixels; break; default: @@ -1141,19 +1143,17 @@ int SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect, const void *pixels, int pitch) { - SDL_Texture *texture = swdata->texture; - - switch (texture->format) { + switch (swdata->format) { case SDL_PIXELFORMAT_YV12: case SDL_PIXELFORMAT_IYUV: if (rect - && (rect->x != 0 || rect->y != 0 || rect->w != texture->w - || rect->h != texture->h)) { + && (rect->x != 0 || rect->y != 0 || rect->w != swdata->w + || rect->h != swdata->h)) { SDL_SetError ("YV12 and IYUV textures only support full surface updates"); return -1; } - SDL_memcpy(swdata->pixels, pixels, texture->h * texture->w * 2); + SDL_memcpy(swdata->pixels, pixels, swdata->h * swdata->w * 2); break; case SDL_PIXELFORMAT_YUY2: case SDL_PIXELFORMAT_UYVY: @@ -1183,14 +1183,12 @@ int SDL_SW_LockYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect, int markDirty, void **pixels, int *pitch) { - SDL_Texture *texture = swdata->texture; - - switch (texture->format) { + switch (swdata->format) { case SDL_PIXELFORMAT_YV12: case SDL_PIXELFORMAT_IYUV: if (rect - && (rect->x != 0 || rect->y != 0 || rect->w != texture->w - || rect->h != texture->h)) { + && (rect->x != 0 || rect->y != 0 || rect->w != swdata->w + || rect->h != swdata->h)) { SDL_SetError ("YV12 and IYUV textures only support full surface locks"); return -1; @@ -1213,7 +1211,6 @@ SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture * swdata, const SDL_Rect * srcrect, Uint32 target_format, int w, int h, void *pixels, int pitch) { - SDL_Texture *texture = swdata->texture; int stretch; int scale_2x; Uint8 *lum, *Cr, *Cb; @@ -1228,8 +1225,8 @@ SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture * swdata, const SDL_Rect * srcrect, stretch = 0; scale_2x = 0; - if (srcrect->x || srcrect->y || srcrect->w < texture->w - || srcrect->h < texture->h) { + if (srcrect->x || srcrect->y || srcrect->w < swdata->w + || srcrect->h < swdata->h) { /* The source rectangle has been clipped. Using a scratch surface is easier than adding clipped source support to all the blitters, plus that would @@ -1268,7 +1265,7 @@ SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture * swdata, const SDL_Rect * srcrect, SDL_PixelFormatEnumToMasks(target_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask); swdata->stretch = - SDL_CreateRGBSurface(0, texture->w, texture->h, bpp, Rmask, + SDL_CreateRGBSurface(0, swdata->w, swdata->h, bpp, Rmask, Gmask, Bmask, Amask); if (!swdata->stretch) { return (-1); @@ -1277,7 +1274,7 @@ SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture * swdata, const SDL_Rect * srcrect, pixels = swdata->stretch->pixels; pitch = swdata->stretch->pitch; } - switch (texture->format) { + switch (swdata->format) { case SDL_PIXELFORMAT_YV12: lum = swdata->planes[0]; Cr = swdata->planes[1]; @@ -1310,13 +1307,13 @@ SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture * swdata, const SDL_Rect * srcrect, mod = (pitch / SDL_BYTESPERPIXEL(target_format)); if (scale_2x) { - mod -= (texture->w * 2); + mod -= (swdata->w * 2); swdata->Display2X(swdata->colortab, swdata->rgb_2_pix, - lum, Cr, Cb, pixels, texture->h, texture->w, mod); + lum, Cr, Cb, pixels, swdata->h, swdata->w, mod); } else { - mod -= texture->w; + mod -= swdata->w; swdata->Display1X(swdata->colortab, swdata->rgb_2_pix, - lum, Cr, Cb, pixels, texture->h, texture->w, mod); + lum, Cr, Cb, pixels, swdata->h, swdata->w, mod); } if (stretch) { SDL_Rect rect = *srcrect; diff --git a/src/video/SDL_yuv_sw_c.h b/src/video/SDL_yuv_sw_c.h index 739679b9c..3f896e067 100644 --- a/src/video/SDL_yuv_sw_c.h +++ b/src/video/SDL_yuv_sw_c.h @@ -28,7 +28,7 @@ typedef struct SDL_SW_YUVTexture SDL_SW_YUVTexture; -SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(SDL_Texture * texture); +SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(Uint32 format, int w, int h); int SDL_SW_QueryYUVTexturePixels(SDL_SW_YUVTexture * swdata, void **pixels, int *pitch); int SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect, diff --git a/src/video/win32/SDL_gdirender.c b/src/video/win32/SDL_gdirender.c index b32a90e48..31d07dbaf 100644 --- a/src/video/win32/SDL_gdirender.c +++ b/src/video/win32/SDL_gdirender.c @@ -294,7 +294,7 @@ GDI_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) texture->driverdata = data; if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { - data->yuv = SDL_SW_CreateYUVTexture(texture); + data->yuv = SDL_SW_CreateYUVTexture(texture->format, texture->w, texture->h); if (!data->yuv) { return -1; }