diff --git a/VisualC-GDK/SDL/SDL.vcxproj b/VisualC-GDK/SDL/SDL.vcxproj
index 28fdc639ff8f26..e136005281e9d1 100644
--- a/VisualC-GDK/SDL/SDL.vcxproj
+++ b/VisualC-GDK/SDL/SDL.vcxproj
@@ -558,6 +558,7 @@
+
@@ -863,4 +864,4 @@
-
\ No newline at end of file
+
diff --git a/VisualC-GDK/SDL/SDL.vcxproj.filters b/VisualC-GDK/SDL/SDL.vcxproj.filters
index 069e3bd14afd76..4260bfcd900a96 100644
--- a/VisualC-GDK/SDL/SDL.vcxproj.filters
+++ b/VisualC-GDK/SDL/SDL.vcxproj.filters
@@ -436,6 +436,7 @@
+
@@ -462,4 +463,4 @@
-
\ No newline at end of file
+
diff --git a/VisualC-WinRT/SDL-UWP.vcxproj b/VisualC-WinRT/SDL-UWP.vcxproj
index 32966b4fedbc6d..a80d0924bab2ab 100644
--- a/VisualC-WinRT/SDL-UWP.vcxproj
+++ b/VisualC-WinRT/SDL-UWP.vcxproj
@@ -185,6 +185,7 @@
+
@@ -917,4 +918,4 @@
-
\ No newline at end of file
+
diff --git a/VisualC-WinRT/SDL-UWP.vcxproj.filters b/VisualC-WinRT/SDL-UWP.vcxproj.filters
index 46d67b14598783..e57ee7174426e6 100644
--- a/VisualC-WinRT/SDL-UWP.vcxproj.filters
+++ b/VisualC-WinRT/SDL-UWP.vcxproj.filters
@@ -438,6 +438,9 @@
Source Files
+
+ Source Files
+
Source Files
@@ -973,4 +976,4 @@
Source Files
-
\ No newline at end of file
+
diff --git a/VisualC/SDL/SDL.vcxproj b/VisualC/SDL/SDL.vcxproj
index 879c607e8dd80a..3a7f523d9f9077 100644
--- a/VisualC/SDL/SDL.vcxproj
+++ b/VisualC/SDL/SDL.vcxproj
@@ -464,6 +464,7 @@
+
diff --git a/VisualC/SDL/SDL.vcxproj.filters b/VisualC/SDL/SDL.vcxproj.filters
index faa6a9d55598dc..24579a58ebcb08 100644
--- a/VisualC/SDL/SDL.vcxproj.filters
+++ b/VisualC/SDL/SDL.vcxproj.filters
@@ -615,6 +615,9 @@
video
+
+ video
+
video
@@ -1554,4 +1557,4 @@
-
\ No newline at end of file
+
diff --git a/build-scripts/SDL_migration.cocci b/build-scripts/SDL_migration.cocci
index fef3d353644c90..67fa06af3d87e3 100644
--- a/build-scripts/SDL_migration.cocci
+++ b/build-scripts/SDL_migration.cocci
@@ -1566,7 +1566,7 @@ typedef SDL_GameControllerButton, SDL_GamepadButton;
@@
@@
- SDL_AllocFormat
-+ SDL_CreatePixelFormat
++ SDL_GetPixelFormatDetails
(...)
@@
@@
@@ -1575,23 +1575,18 @@ typedef SDL_GameControllerButton, SDL_GamepadButton;
(...)
@@
@@
-- SDL_FreeFormat
-+ SDL_DestroyPixelFormat
- (...)
-@@
-@@
- SDL_FreePalette
+ SDL_DestroyPalette
(...)
@@
@@
- SDL_MasksToPixelFormatEnum
-+ SDL_GetPixelFormatEnumForMasks
++ SDL_GetPixelFormatForMasks
(...)
@@
@@
- SDL_PixelFormatEnumToMasks
-+ SDL_GetMasksForPixelFormatEnum
++ SDL_GetMasksForPixelFormat
(...)
@@
@@
@@ -3488,3 +3483,21 @@ typedef SDL_Colour, SDL_Color;
@@
- SDLK_z
+ SDLK_Z
+@@
+typedef SDL_PixelFormat, SDL_PackedPixelDetails;
+@@
+- SDL_PixelFormat
++ SDL_PixelFormatDetails
+@@
+@@
+- SDL_ConvertSurfaceFormat
++ SDL_ConvertSurface
+ (...)
+@@
+@@
+- SDL_PREALLOC
++ SDL_SURFACE_PREALLOCATED
+@@
+@@
+- SDL_SIMD_ALIGNED
++ SDL_SURFACE_SIMD_ALIGNED
diff --git a/docs/README-migration.md b/docs/README-migration.md
index 61411ded21e6ec..526b4e15b44358 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -1092,19 +1092,22 @@ The following symbols have been renamed:
## SDL_pixels.h
-SDL_CalculateGammaRamp has been removed, because SDL_SetWindowGammaRamp has been removed as well due to poor support in modern operating systems (see [SDL_video.h](#sdl_videoh)).
+SDL_PixelFormat has been renamed SDL_PixelFormatDetails and just describes the pixel format, it does not include a palette for indexed pixel types.
+
+SDL_PixelFormatEnum has been renamed SDL_PixelFormat and is used instead of Uint32 for API functions that refer to pixel format by enumerated value.
-The BitsPerPixel and BytesPerPixel fields of SDL_PixelFormat have been renamed bits_per_pixel and bytes_per_pixel.
+SDL_MapRGB(), SDL_MapRGBA(), SDL_GetRGB(), and SDL_GetRGBA() take an optional palette parameter for indexed color lookups.
-SDL_PixelFormatEnum is used instead of Uint32 for API functions that refer to pixel format by enumerated value.
+SDL_GetMasksForPixelFormat() now returns the standard int error code.
+
+SDL_CalculateGammaRamp has been removed, because SDL_SetWindowGammaRamp has been removed as well due to poor support in modern operating systems (see [SDL_video.h](#sdl_videoh)).
The following functions have been renamed:
-* SDL_AllocFormat() => SDL_CreatePixelFormat()
+* SDL_AllocFormat() => SDL_GetPixelFormatDetails()
* SDL_AllocPalette() => SDL_CreatePalette()
-* SDL_FreeFormat() => SDL_DestroyPixelFormat()
* SDL_FreePalette() => SDL_DestroyPalette()
-* SDL_MasksToPixelFormatEnum() => SDL_GetPixelFormatEnumForMasks()
-* SDL_PixelFormatEnumToMasks() => SDL_GetMasksForPixelFormatEnum()
+* SDL_MasksToPixelFormatEnum() => SDL_GetPixelFormatForMasks()
+* SDL_PixelFormatEnumToMasks() => SDL_GetMasksForPixelFormat()
The following symbols have been renamed:
* SDL_PIXELFORMAT_BGR444 => SDL_PIXELFORMAT_XBGR4444
@@ -1114,9 +1117,16 @@ The following symbols have been renamed:
* SDL_PIXELFORMAT_RGB555 => SDL_PIXELFORMAT_XRGB1555
* SDL_PIXELFORMAT_RGB888 => SDL_PIXELFORMAT_XRGB8888
+The following functions have been removed:
+* SDL_FreeFormat()
+* SDL_SetPixelFormatPalette()
+
The following macros have been removed:
* SDL_Colour - use SDL_Color instead
+The following structures have been renamed:
+* SDL_PixelFormat => SDL_PixelFormatDetails
+
## SDL_platform.h
The following platform preprocessor macros have been renamed:
@@ -1598,19 +1608,23 @@ The following functions have been removed:
## SDL_surface.h
+SDL_Surface has been simplified and internal details are no longer in the public structure.
+
+The `format` member of SDL_Surface is now an enumerated pixel format value. You can get the full details of the pixel format by calling `SDL_GetPixelFormatDetails(surface->format)`. You can get the palette associated with the surface by calling SDL_GetSurfacePalette(). You can get the clip rectangle by calling SDL_GetSurfaceClipRect().
+
The userdata member of SDL_Surface has been replaced with a more general properties interface, which can be queried with SDL_GetSurfaceProperties()
-Removed unused 'flags' parameter from SDL_ConvertSurface and SDL_ConvertSurfaceFormat.
+Removed the unused 'flags' parameter from SDL_ConvertSurface.
SDL_CreateRGBSurface() and SDL_CreateRGBSurfaceWithFormat() have been combined into a new function SDL_CreateSurface().
-SDL_CreateRGBSurfaceFrom() and SDL_CreateRGBSurfaceWithFormatFrom() have been combined into a new function SDL_CreateSurfaceFrom().
+SDL_CreateRGBSurfaceFrom() and SDL_CreateRGBSurfaceWithFormatFrom() have been combined into a new function SDL_CreateSurfaceFrom(), and the parameter order has changed for consistency with SDL_CreateSurface().
You can implement the old functions in your own code easily:
```c
SDL_Surface *SDL_CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
{
return SDL_CreateSurface(width, height,
- SDL_GetPixelFormatEnumForMasks(depth, Rmask, Gmask, Bmask, Amask));
+ SDL_GetPixelFormatForMasks(depth, Rmask, Gmask, Bmask, Amask));
}
SDL_Surface *SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth, Uint32 format)
@@ -1620,13 +1634,14 @@ SDL_Surface *SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height,
SDL_Surface *SDL_CreateRGBSurfaceFrom(void *pixels, int width, int height, int depth, int pitch, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
{
- return SDL_CreateSurfaceFrom(pixels, width, height, pitch,
- SDL_GetPixelFormatEnumForMasks(depth, Rmask, Gmask, Bmask, Amask));
+ return SDL_CreateSurfaceFrom(width, height,
+ SDL_GetPixelFormatForMasks(depth, Rmask, Gmask, Bmask, Amask),
+ pixels, pitch);
}
SDL_Surface *SDL_CreateRGBSurfaceWithFormatFrom(void *pixels, int width, int height, int depth, int pitch, Uint32 format)
{
- return SDL_CreateSurfaceFrom(pixels, width, height, pitch, format);
+ return SDL_CreateSurfaceFrom(width, height, format, pixels, pitch);
}
```
@@ -1645,10 +1660,15 @@ SDL_BlitSurfaceScaled() and SDL_BlitSurfaceUncheckedScaled() now take a scale pa
SDL_SoftStretch() now takes a scale paramater.
-SDL_PixelFormatEnum is used instead of Uint32 for API functions that refer to pixel format by enumerated value.
+SDL_PixelFormat is used instead of Uint32 for API functions that refer to pixel format by enumerated value.
+
+SDL_SetSurfaceColorKey() takes an SDL_bool to enable and disable colorkey. RLE acceleration isn't controlled by the parameter, you should use SDL_SetSurfaceRLE() to change that separately.
+
+SDL_SetSurfaceRLE() takes an SDL_bool to enable and disable RLE acceleration.
The following functions have been renamed:
* SDL_BlitScaled() => SDL_BlitSurfaceScaled()
+* SDL_ConvertSurfaceFormat() => SDL_ConvertSurface()
* SDL_FillRect() => SDL_FillSurfaceRect()
* SDL_FillRects() => SDL_FillSurfaceRects()
* SDL_FreeSurface() => SDL_DestroySurface()
@@ -1669,11 +1689,16 @@ The following symbols have been removed:
* SDL_SWSURFACE
The following functions have been removed:
+* SDL_FreeFormat()
* SDL_GetYUVConversionMode()
* SDL_GetYUVConversionModeForResolution()
* SDL_SetYUVConversionMode() - use SDL_SetSurfaceColorspace() to set the surface colorspace and SDL_PROP_TEXTURE_CREATE_COLORSPACE_NUMBER with SDL_CreateTextureWithProperties() to set the texture colorspace. The default colorspace for YUV pixel formats is SDL_COLORSPACE_JPEG.
* SDL_SoftStretchLinear() - use SDL_SoftStretch() with SDL_SCALEMODE_LINEAR
+The following symbols have been renamed:
+* SDL_PREALLOC => SDL_SURFACE_PREALLOCATED
+* SDL_SIMD_ALIGNED => SDL_SURFACE_SIMD_ALIGNED
+
## SDL_system.h
SDL_WindowsMessageHook has changed signatures so the message may be modified and it can block further message processing.
@@ -1835,7 +1860,7 @@ The callback passed to SDL_AddTimer() has changed parameters to:
Uint32 SDLCALL TimerCallback(void *userdata, SDL_TimerID timerID, Uint32 interval);
````
-The return value of SDL_RemoveTimer() has changed to the standard int error code.
+SDL_RemoveTimer() now returns the standard int error code.
## SDL_touch.h
diff --git a/include/SDL3/SDL_camera.h b/include/SDL3/SDL_camera.h
index de8e1358b96eb4..f7468426f46506 100644
--- a/include/SDL3/SDL_camera.h
+++ b/include/SDL3/SDL_camera.h
@@ -78,7 +78,7 @@ typedef struct SDL_Camera SDL_Camera;
*/
typedef struct SDL_CameraSpec
{
- SDL_PixelFormatEnum format; /**< Frame format */
+ SDL_PixelFormat format; /**< Frame format */
SDL_Colorspace colorspace; /**< Frame colorspace */
int width; /**< Frame width */
int height; /**< Frame height */
diff --git a/include/SDL3/SDL_oldnames.h b/include/SDL3/SDL_oldnames.h
index 7d1bf8360e0e46..c9abf8147633ed 100644
--- a/include/SDL3/SDL_oldnames.h
+++ b/include/SDL3/SDL_oldnames.h
@@ -453,19 +453,18 @@
#define SDL_sem SDL_Semaphore
/* ##SDL_pixels.h */
-#define SDL_AllocFormat SDL_CreatePixelFormat
+#define SDL_AllocFormat SDL_GetPixelFormatDetails
#define SDL_AllocPalette SDL_CreatePalette
#define SDL_Colour SDL_Color
-#define SDL_FreeFormat SDL_DestroyPixelFormat
#define SDL_FreePalette SDL_DestroyPalette
-#define SDL_MasksToPixelFormatEnum SDL_GetPixelFormatEnumForMasks
+#define SDL_MasksToPixelFormatEnum SDL_GetPixelFormatForMasks
#define SDL_PIXELFORMAT_BGR444 SDL_PIXELFORMAT_XBGR4444
#define SDL_PIXELFORMAT_BGR555 SDL_PIXELFORMAT_XBGR1555
#define SDL_PIXELFORMAT_BGR888 SDL_PIXELFORMAT_XBGR8888
#define SDL_PIXELFORMAT_RGB444 SDL_PIXELFORMAT_XRGB4444
#define SDL_PIXELFORMAT_RGB555 SDL_PIXELFORMAT_XRGB1555
#define SDL_PIXELFORMAT_RGB888 SDL_PIXELFORMAT_XRGB8888
-#define SDL_PixelFormatEnumToMasks SDL_GetMasksForPixelFormatEnum
+#define SDL_PixelFormatEnumToMasks SDL_GetMasksForPixelFormat
/* ##SDL_rect.h */
#define SDL_EncloseFPoints SDL_GetRectEnclosingPointsFloat
@@ -580,6 +579,7 @@
/* ##SDL_surface.h */
#define SDL_BlitScaled SDL_BlitSurfaceScaled
+#define SDL_ConvertSurfaceFormat SDL_ConvertSurface
#define SDL_FillRect SDL_FillSurfaceRect
#define SDL_FillRects SDL_FillSurfaceRects
#define SDL_FreeSurface SDL_DestroySurface
@@ -590,6 +590,8 @@
#define SDL_LoadBMP_RW SDL_LoadBMP_IO
#define SDL_LowerBlit SDL_BlitSurfaceUnchecked
#define SDL_LowerBlitScaled SDL_BlitSurfaceUncheckedScaled
+#define SDL_PREALLOC SDL_SURFACE_PREALLOCATED
+#define SDL_SIMD_ALIGNED SDL_SURFACE_SIMD_ALIGNED
#define SDL_SaveBMP_RW SDL_SaveBMP_IO
#define SDL_SetClipRect SDL_SetSurfaceClipRect
#define SDL_SetColorKey SDL_SetSurfaceColorKey
@@ -1048,19 +1050,18 @@
#define SDL_sem SDL_sem_renamed_SDL_Semaphore
/* ##SDL_pixels.h */
-#define SDL_AllocFormat SDL_AllocFormat_renamed_SDL_CreatePixelFormat
+#define SDL_AllocFormat SDL_AllocFormat_renamed_SDL_GetPixelFormatDetails
#define SDL_AllocPalette SDL_AllocPalette_renamed_SDL_CreatePalette
#define SDL_Colour SDL_Colour_renamed_SDL_Color
-#define SDL_FreeFormat SDL_FreeFormat_renamed_SDL_DestroyPixelFormat
#define SDL_FreePalette SDL_FreePalette_renamed_SDL_DestroyPalette
-#define SDL_MasksToPixelFormatEnum SDL_MasksToPixelFormatEnum_renamed_SDL_GetPixelFormatEnumForMasks
+#define SDL_MasksToPixelFormatEnum SDL_MasksToPixelFormatEnum_renamed_SDL_GetPixelFormatForMasks
#define SDL_PIXELFORMAT_BGR444 SDL_PIXELFORMAT_BGR444_renamed_SDL_PIXELFORMAT_XBGR4444
#define SDL_PIXELFORMAT_BGR555 SDL_PIXELFORMAT_BGR555_renamed_SDL_PIXELFORMAT_XBGR1555
#define SDL_PIXELFORMAT_BGR888 SDL_PIXELFORMAT_BGR888_renamed_SDL_PIXELFORMAT_XBGR8888
#define SDL_PIXELFORMAT_RGB444 SDL_PIXELFORMAT_RGB444_renamed_SDL_PIXELFORMAT_XRGB4444
#define SDL_PIXELFORMAT_RGB555 SDL_PIXELFORMAT_RGB555_renamed_SDL_PIXELFORMAT_XRGB1555
#define SDL_PIXELFORMAT_RGB888 SDL_PIXELFORMAT_RGB888_renamed_SDL_PIXELFORMAT_XRGB8888
-#define SDL_PixelFormatEnumToMasks SDL_PixelFormatEnumToMasks_renamed_SDL_GetMasksForPixelFormatEnum
+#define SDL_PixelFormatEnumToMasks SDL_PixelFormatEnumToMasks_renamed_SDL_GetMasksForPixelFormat
/* ##SDL_rect.h */
#define SDL_EncloseFPoints SDL_EncloseFPoints_renamed_SDL_GetRectEnclosingPointsFloat
@@ -1175,6 +1176,7 @@
/* ##SDL_surface.h */
#define SDL_BlitScaled SDL_BlitScaled_renamed_SDL_BlitSurfaceScaled
+#define SDL_ConvertSurfaceFormat SDL_ConvertSurfaceFormat_renamed_SDL_ConvertSurface
#define SDL_FillRect SDL_FillRect_renamed_SDL_FillSurfaceRect
#define SDL_FillRects SDL_FillRects_renamed_SDL_FillSurfaceRects
#define SDL_FreeSurface SDL_FreeSurface_renamed_SDL_DestroySurface
@@ -1185,6 +1187,8 @@
#define SDL_LoadBMP_RW SDL_LoadBMP_RW_renamed_SDL_LoadBMP_IO
#define SDL_LowerBlit SDL_LowerBlit_renamed_SDL_BlitSurfaceUnchecked
#define SDL_LowerBlitScaled SDL_LowerBlitScaled_renamed_SDL_BlitSurfaceUncheckedScaled
+#define SDL_PREALLOC SDL_PREALLOC_renamed_SDL_SURFACE_PREALLOCATED
+#define SDL_SIMD_ALIGNED SDL_SIMD_ALIGNED_renamed_SDL_SURFACE_SIMD_ALIGNED
#define SDL_SaveBMP_RW SDL_SaveBMP_RW_renamed_SDL_SaveBMP_IO
#define SDL_SetClipRect SDL_SetClipRect_renamed_SDL_SetSurfaceClipRect
#define SDL_SetColorKey SDL_SetColorKey_renamed_SDL_SetSurfaceColorKey
diff --git a/include/SDL3/SDL_pixels.h b/include/SDL3/SDL_pixels.h
index ec758d8d82fb1f..2d14292c2acc08 100644
--- a/include/SDL3/SDL_pixels.h
+++ b/include/SDL3/SDL_pixels.h
@@ -133,7 +133,8 @@ typedef enum SDL_PackedLayout
#define SDL_PIXELTYPE(X) (((X) >> 24) & 0x0F)
#define SDL_PIXELORDER(X) (((X) >> 20) & 0x0F)
#define SDL_PIXELLAYOUT(X) (((X) >> 16) & 0x0F)
-#define SDL_BITSPERPIXEL(X) (((X) >> 8) & 0xFF)
+#define SDL_BITSPERPIXEL(X) \
+ (SDL_ISPIXELFORMAT_FOURCC(X) ? 0 : (((X) >> 8) & 0xFF))
#define SDL_BYTESPERPIXEL(X) \
(SDL_ISPIXELFORMAT_FOURCC(X) ? \
((((X) == SDL_PIXELFORMAT_YUY2) || \
@@ -222,7 +223,7 @@ typedef enum SDL_PackedLayout
*
* \since This enum is available since SDL 3.0.0.
*/
-typedef enum SDL_PixelFormatEnum
+typedef enum SDL_PixelFormat
{
SDL_PIXELFORMAT_UNKNOWN,
SDL_PIXELFORMAT_INDEX1LSB =
@@ -426,7 +427,7 @@ typedef enum SDL_PixelFormatEnum
SDL_DEFINE_PIXELFOURCC('P', '0', '1', '0'),
SDL_PIXELFORMAT_EXTERNAL_OES = /**< Android video texture format */
SDL_DEFINE_PIXELFOURCC('O', 'E', 'S', ' ')
-} SDL_PixelFormatEnum;
+} SDL_PixelFormat;
/**
* Pixels are a representation of a color in a particular color space.
@@ -721,7 +722,6 @@ typedef struct SDL_FColor
*
* \since This struct is available since SDL 3.0.0.
*
- * \sa SDL_PixelFormat
* \sa SDL_SetPaletteColors
*/
typedef struct SDL_Palette
@@ -735,15 +735,11 @@ typedef struct SDL_Palette
/**
* Details about the format of a pixel.
*
- * Generally this is used with SDL_Surface, and covers many possible
- * configurations, including paletted data and various bit patterns.
- *
* \since This struct is available since SDL 3.0.0.
*/
-typedef struct SDL_PixelFormat
+typedef struct SDL_PixelFormatDetails
{
- SDL_PixelFormatEnum format;
- SDL_Palette *palette;
+ SDL_PixelFormat format;
Uint8 bits_per_pixel;
Uint8 bytes_per_pixel;
Uint8 padding[2];
@@ -751,17 +747,15 @@ typedef struct SDL_PixelFormat
Uint32 Gmask;
Uint32 Bmask;
Uint32 Amask;
- Uint8 Rloss;
- Uint8 Gloss;
- Uint8 Bloss;
- Uint8 Aloss;
+ Uint8 Rbits;
+ Uint8 Gbits;
+ Uint8 Bbits;
+ Uint8 Abits;
Uint8 Rshift;
Uint8 Gshift;
Uint8 Bshift;
Uint8 Ashift;
- int refcount;
- struct SDL_PixelFormat *next;
-} SDL_PixelFormat;
+} SDL_PixelFormatDetails;
/**
* Get the human readable name of a pixel format.
@@ -774,30 +768,25 @@ typedef struct SDL_PixelFormat
*
* \since This function is available since SDL 3.0.0.
*/
-extern SDL_DECLSPEC const char* SDLCALL SDL_GetPixelFormatName(SDL_PixelFormatEnum format);
+extern SDL_DECLSPEC const char* SDLCALL SDL_GetPixelFormatName(SDL_PixelFormat format);
/**
* Convert one of the enumerated pixel formats to a bpp value and RGBA masks.
*
- * \param format one of the SDL_PixelFormatEnum values.
+ * \param format one of the SDL_PixelFormat values.
* \param bpp a bits per pixel value; usually 15, 16, or 32.
* \param Rmask a pointer filled in with the red mask for the format.
* \param Gmask a pointer filled in with the green mask for the format.
* \param Bmask a pointer filled in with the blue mask for the format.
* \param Amask a pointer filled in with the alpha mask for the format.
- * \returns SDL_TRUE on success or SDL_FALSE if the conversion wasn't
- * possible; call SDL_GetError() for more information.
+ * \returns 0 on success or a negative error code on failure; call
+ * SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
- * \sa SDL_GetPixelFormatEnumForMasks
+ * \sa SDL_GetPixelFormatForMasks
*/
-extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetMasksForPixelFormatEnum(SDL_PixelFormatEnum format,
- int *bpp,
- Uint32 * Rmask,
- Uint32 * Gmask,
- Uint32 * Bmask,
- Uint32 * Amask);
+extern SDL_DECLSPEC int SDLCALL SDL_GetMasksForPixelFormat(SDL_PixelFormat format, int *bpp, Uint32 *Rmask, Uint32 *Gmask, Uint32 *Bmask, Uint32 *Amask);
/**
* Convert a bpp value and RGBA masks to an enumerated pixel format.
@@ -810,47 +799,29 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetMasksForPixelFormatEnum(SDL_PixelFor
* \param Gmask the green mask for the format.
* \param Bmask the blue mask for the format.
* \param Amask the alpha mask for the format.
- * \returns the SDL_PixelFormatEnum value corresponding to the format masks,
+ * \returns the SDL_PixelFormat value corresponding to the format masks,
* or SDL_PIXELFORMAT_UNKNOWN if there isn't a match.
*
* \since This function is available since SDL 3.0.0.
*
- * \sa SDL_GetMasksForPixelFormatEnum
+ * \sa SDL_GetMasksForPixelFormat
*/
-extern SDL_DECLSPEC SDL_PixelFormatEnum SDLCALL SDL_GetPixelFormatEnumForMasks(int bpp,
- Uint32 Rmask,
- Uint32 Gmask,
- Uint32 Bmask,
- Uint32 Amask);
+extern SDL_DECLSPEC SDL_PixelFormat SDLCALL SDL_GetPixelFormatForMasks(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
/**
- * Create an SDL_PixelFormat structure corresponding to a pixel format.
+ * Create an SDL_PixelFormatDetails structure corresponding to a pixel format.
*
* Returned structure may come from a shared global cache (i.e. not newly
* allocated), and hence should not be modified, especially the palette. Weird
* errors such as `Blit combination not supported` may occur.
*
- * \param pixel_format one of the SDL_PixelFormatEnum values.
- * \returns the new SDL_PixelFormat structure or NULL on failure; call
+ * \param format one of the SDL_PixelFormat values.
+ * \returns a pointer to a SDL_PixelFormatDetails structure or NULL on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
- *
- * \sa SDL_DestroyPixelFormat
- * \sa SDL_SetPixelFormatPalette
*/
-extern SDL_DECLSPEC SDL_PixelFormat * SDLCALL SDL_CreatePixelFormat(SDL_PixelFormatEnum pixel_format);
-
-/**
- * Free an SDL_PixelFormat structure allocated by SDL_CreatePixelFormat().
- *
- * \param format the SDL_PixelFormat structure to free.
- *
- * \since This function is available since SDL 3.0.0.
- *
- * \sa SDL_CreatePixelFormat
- */
-extern SDL_DECLSPEC void SDLCALL SDL_DestroyPixelFormat(SDL_PixelFormat *format);
+extern SDL_DECLSPEC const SDL_PixelFormatDetails * SDLCALL SDL_GetPixelFormatDetails(SDL_PixelFormat format);
/**
* Create a palette structure with the specified number of color entries.
@@ -866,23 +837,10 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyPixelFormat(SDL_PixelFormat *format)
*
* \sa SDL_DestroyPalette
* \sa SDL_SetPaletteColors
- * \sa SDL_SetPixelFormatPalette
+ * \sa SDL_SetSurfacePalette
*/
extern SDL_DECLSPEC SDL_Palette *SDLCALL SDL_CreatePalette(int ncolors);
-/**
- * Set the palette for a pixel format structure.
- *
- * \param format the SDL_PixelFormat structure that will use the palette.
- * \param palette the SDL_Palette structure that will be used.
- * \returns 0 on success or a negative error code on failure; call
- * SDL_GetError() for more information.
- *
- * \since This function is available since SDL 3.0.0.
- */
-extern SDL_DECLSPEC int SDLCALL SDL_SetPixelFormatPalette(SDL_PixelFormat * format,
- SDL_Palette *palette);
-
/**
* Set a range of colors in a palette.
*
@@ -895,9 +853,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetPixelFormatPalette(SDL_PixelFormat * form
*
* \since This function is available since SDL 3.0.0.
*/
-extern SDL_DECLSPEC int SDLCALL SDL_SetPaletteColors(SDL_Palette * palette,
- const SDL_Color * colors,
- int firstcolor, int ncolors);
+extern SDL_DECLSPEC int SDLCALL SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, int firstcolor, int ncolors);
/**
* Free a palette created with SDL_CreatePalette().
@@ -908,7 +864,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetPaletteColors(SDL_Palette * palette,
*
* \sa SDL_CreatePalette
*/
-extern SDL_DECLSPEC void SDLCALL SDL_DestroyPalette(SDL_Palette * palette);
+extern SDL_DECLSPEC void SDLCALL SDL_DestroyPalette(SDL_Palette *palette);
/**
* Map an RGB triple to an opaque pixel value for a given pixel format.
@@ -928,7 +884,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyPalette(SDL_Palette * palette);
* format the return value can be assigned to a Uint16, and similarly a Uint8
* for an 8-bpp format).
*
- * \param format an SDL_PixelFormat structure describing the pixel format.
+ * \param format one of the enumerated values in SDL_PixelFormat.
+ * \param palette an optional palette for indexed formats, may be NULL.
* \param r the red component of the pixel in the range 0-255.
* \param g the green component of the pixel in the range 0-255.
* \param b the blue component of the pixel in the range 0-255.
@@ -940,8 +897,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyPalette(SDL_Palette * palette);
* \sa SDL_GetRGBA
* \sa SDL_MapRGBA
*/
-extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapRGB(const SDL_PixelFormat * format,
- Uint8 r, Uint8 g, Uint8 b);
+extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapRGB(SDL_PixelFormat format, SDL_Palette *palette, Uint8 r, Uint8 g, Uint8 b);
/**
* Map an RGBA quadruple to a pixel value for a given pixel format.
@@ -961,8 +917,8 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapRGB(const SDL_PixelFormat * format,
* format the return value can be assigned to a Uint16, and similarly a Uint8
* for an 8-bpp format).
*
- * \param format an SDL_PixelFormat structure describing the format of the
- * pixel.
+ * \param format one of the enumerated values in SDL_PixelFormat.
+ * \param palette an optional palette for indexed formats, may be NULL.
* \param r the red component of the pixel in the range 0-255.
* \param g the green component of the pixel in the range 0-255.
* \param b the blue component of the pixel in the range 0-255.
@@ -975,9 +931,7 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapRGB(const SDL_PixelFormat * format,
* \sa SDL_GetRGBA
* \sa SDL_MapRGB
*/
-extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapRGBA(const SDL_PixelFormat * format,
- Uint8 r, Uint8 g, Uint8 b,
- Uint8 a);
+extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapRGBA(SDL_PixelFormat format, SDL_Palette *palette, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/**
* Get RGB values from a pixel in the specified format.
@@ -988,8 +942,8 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapRGBA(const SDL_PixelFormat * format,
* 0xff, 0xff] not [0xf8, 0xfc, 0xf8]).
*
* \param pixel a pixel value.
- * \param format an SDL_PixelFormat structure describing the format of the
- * pixel.
+ * \param format format one of the enumerated values in SDL_PixelFormat describing the format of the pixel.
+ * \param palette an optional palette for indexed formats, may be NULL.
* \param r a pointer filled in with the red component.
* \param g a pointer filled in with the green component.
* \param b a pointer filled in with the blue component.
@@ -1000,9 +954,7 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapRGBA(const SDL_PixelFormat * format,
* \sa SDL_MapRGB
* \sa SDL_MapRGBA
*/
-extern SDL_DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel,
- const SDL_PixelFormat * format,
- Uint8 * r, Uint8 * g, Uint8 * b);
+extern SDL_DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel, SDL_PixelFormat format, SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b);
/**
* Get RGBA values from a pixel in the specified format.
@@ -1016,8 +968,8 @@ extern SDL_DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel,
* (100% opaque).
*
* \param pixel a pixel value.
- * \param format an SDL_PixelFormat structure describing the format of the
- * pixel.
+ * \param format format one of the enumerated values in SDL_PixelFormat describing the format of the pixel.
+ * \param palette an optional palette for indexed formats, may be NULL.
* \param r a pointer filled in with the red component.
* \param g a pointer filled in with the green component.
* \param b a pointer filled in with the blue component.
@@ -1029,10 +981,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel,
* \sa SDL_MapRGB
* \sa SDL_MapRGBA
*/
-extern SDL_DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel,
- const SDL_PixelFormat * format,
- Uint8 * r, Uint8 * g, Uint8 * b,
- Uint8 * a);
+extern SDL_DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel, SDL_PixelFormat format, SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
/* Ends C function definitions when using C++ */
diff --git a/include/SDL3/SDL_render.h b/include/SDL3/SDL_render.h
index f33cdf906f175f..4b08b0b11264ea 100644
--- a/include/SDL3/SDL_render.h
+++ b/include/SDL3/SDL_render.h
@@ -350,8 +350,7 @@ extern SDL_DECLSPEC const char *SDLCALL SDL_GetRendererName(SDL_Renderer *render
* - `SDL_PROP_RENDERER_VSYNC_NUMBER`: the current vsync setting
* - `SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER`: the maximum texture width
* and height
- * - `SDL_PROP_RENDERER_TEXTURE_FORMATS_POINTER`: a (const SDL_PixelFormatEnum
- * *) array of pixel formats, terminated with SDL_PIXELFORMAT_UNKNOWN,
+ * - `SDL_PROP_RENDERER_TEXTURE_FORMATS_POINTER`: a (const SDL_PixelFormat *) array of pixel formats, terminated with SDL_PIXELFORMAT_UNKNOWN,
* representing the available texture formats for this renderer.
* - `SDL_PROP_RENDERER_OUTPUT_COLORSPACE_NUMBER`: an SDL_ColorSpace value
* describing the colorspace for output to the display, defaults to
@@ -485,7 +484,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetCurrentRenderOutputSize(SDL_Renderer *ren
* Create a texture for a rendering context.
*
* \param renderer the rendering context.
- * \param format one of the enumerated values in SDL_PixelFormatEnum.
+ * \param format one of the enumerated values in SDL_PixelFormat.
* \param access one of the enumerated values in SDL_TextureAccess.
* \param w the width of the texture in pixels.
* \param h the height of the texture in pixels.
@@ -501,7 +500,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetCurrentRenderOutputSize(SDL_Renderer *ren
* \sa SDL_GetTextureSize
* \sa SDL_UpdateTexture
*/
-extern SDL_DECLSPEC SDL_Texture *SDLCALL SDL_CreateTexture(SDL_Renderer *renderer, SDL_PixelFormatEnum format, int access, int w, int h);
+extern SDL_DECLSPEC SDL_Texture *SDLCALL SDL_CreateTexture(SDL_Renderer *renderer, SDL_PixelFormat format, int access, int w, int h);
/**
* Create a texture from an existing surface.
@@ -540,7 +539,7 @@ extern SDL_DECLSPEC SDL_Texture *SDLCALL SDL_CreateTextureFromSurface(SDL_Render
* SDL_COLORSPACE_SRGB for other RGB textures and SDL_COLORSPACE_JPEG for
* YUV textures.
* - `SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER`: one of the enumerated values in
- * SDL_PixelFormatEnum, defaults to the best RGBA format for the renderer
+ * SDL_PixelFormat, defaults to the best RGBA format for the renderer
* - `SDL_PROP_TEXTURE_CREATE_ACCESS_NUMBER`: one of the enumerated values in
* SDL_TextureAccess, defaults to SDL_TEXTUREACCESS_STATIC
* - `SDL_PROP_TEXTURE_CREATE_WIDTH_NUMBER`: the width of the texture in
@@ -672,7 +671,7 @@ extern SDL_DECLSPEC SDL_Texture *SDLCALL SDL_CreateTextureWithProperties(SDL_Ren
* - `SDL_PROP_TEXTURE_COLORSPACE_NUMBER`: an SDL_ColorSpace value describing
* the texture colorspace.
* - `SDL_PROP_TEXTURE_FORMAT_NUMBER`: one of the enumerated values in
- * SDL_PixelFormatEnum.
+ * SDL_PixelFormat.
* - `SDL_PROP_TEXTURE_ACCESS_NUMBER`: one of the enumerated values in
* SDL_TextureAccess.
* - `SDL_PROP_TEXTURE_WIDTH_NUMBER`: the width of the texture in pixels.
diff --git a/include/SDL3/SDL_surface.h b/include/SDL3/SDL_surface.h
index 5df03c465cebb7..fb6b044c5b5944 100644
--- a/include/SDL3/SDL_surface.h
+++ b/include/SDL3/SDL_surface.h
@@ -45,24 +45,23 @@ extern "C" {
/**
* The flags on an SDL_Surface.
*
- * These are generally meant to be considered read-only.
+ * These are generally considered read-only.
*
* \since This datatype is available since SDL 3.0.0.
*/
typedef Uint32 SDL_SurfaceFlags;
-#define SDL_PREALLOC 0x00000001u /**< Surface uses preallocated memory */
-#define SDL_RLEACCEL 0x00000002u /**< Surface is RLE encoded */
-#define SDL_DONTFREE 0x00000004u /**< Surface is referenced internally */
-#define SDL_SIMD_ALIGNED 0x00000008u /**< Surface uses aligned memory */
-#define SDL_SURFACE_USES_PROPERTIES 0x00000010u /**< Surface uses properties */
+#define SDL_SURFACE_PREALLOCATED 0x00000001u /**< Surface uses preallocated pixel memory */
+#define SDL_SURFACE_LOCK_NEEDED 0x00000002u /**< Surface needs to be locked to access pixels */
+#define SDL_SURFACE_LOCKED 0x00000004u /**< Surface is currently locked */
+#define SDL_SURFACE_SIMD_ALIGNED 0x00000008u /**< Surface uses pixel memory allocated with SDL_aligned_alloc() */
/**
* Evaluates to true if the surface needs to be locked before access.
*
* \since This macro is available since SDL 3.0.0.
*/
-#define SDL_MUSTLOCK(S) (((S)->flags & SDL_RLEACCEL) != 0)
+#define SDL_MUSTLOCK(S) (((S)->flags & (SDL_SURFACE_LOCK_NEEDED | SDL_SURFACE_LOCKED)) == SDL_SURFACE_LOCK_NEEDED)
/**
* An opaque type used in SDL_Surface.
@@ -98,6 +97,9 @@ typedef enum SDL_FlipMode
SDL_FLIP_VERTICAL /**< flip vertically */
} SDL_FlipMode;
+/* Internal surface data */
+typedef struct SDL_SurfaceData SDL_SurfaceData;
+
/**
* A collection of pixels used in software blitting.
*
@@ -118,36 +120,24 @@ typedef enum SDL_FlipMode
typedef struct SDL_Surface
{
SDL_SurfaceFlags flags; /**< Read-only */
- SDL_PixelFormat *format; /**< Read-only */
+ SDL_PixelFormat format; /**< Read-only */
int w, h; /**< Read-only */
int pitch; /**< Read-only */
- void *pixels; /**< Read-write */
-
- void *reserved; /**< Private */
-
- /** information needed for surfaces requiring locks */
- int locked; /**< Read-only */
+ void *pixels; /**< Read-only pointer, writable pixels if non-NULL */
- /** list of BlitMap that hold a reference to this surface */
- void *list_blitmap; /**< Private */
+ int refcount; /**< Application reference count, used when freeing surface */
- /** clipping information */
- SDL_Rect clip_rect; /**< Read-only */
+ SDL_SurfaceData *internal; /**< Private */
- /** info for fast blit mapping to other surfaces */
- SDL_BlitMap *map; /**< Private */
-
- /** Reference count -- used when freeing surface */
- int refcount; /**< Read-mostly */
} SDL_Surface;
/**
- * Allocate a new RGB surface with a specific pixel format.
+ * Allocate a new surface with a specific pixel format.
*
* \param width the width of the surface.
* \param height the height of the surface.
- * \param format the SDL_PixelFormatEnum for the new surface's pixel format.
+ * \param format the SDL_PixelFormat for the new surface's pixel format.
* \returns the new SDL_Surface structure that is created or NULL if it fails;
* call SDL_GetError() for more information.
*
@@ -156,11 +146,10 @@ typedef struct SDL_Surface
* \sa SDL_CreateSurfaceFrom
* \sa SDL_DestroySurface
*/
-extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_CreateSurface(int width, int height, SDL_PixelFormatEnum format);
+extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_CreateSurface(int width, int height, SDL_PixelFormat format);
/**
- * Allocate a new RGB surface with a specific pixel format and existing pixel
- * data.
+ * Allocate a new surface with a specific pixel format and existing pixel data.
*
* No copy is made of the pixel data. Pixel data is not managed automatically;
* you must free the surface before you free the pixel data.
@@ -171,11 +160,11 @@ extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_CreateSurface(int width, int height
* You may pass NULL for pixels and 0 for pitch to create a surface that you
* will fill in with valid values later.
*
- * \param pixels a pointer to existing pixel data.
* \param width the width of the surface.
* \param height the height of the surface.
+ * \param format the SDL_PixelFormat for the new surface's pixel format.
+ * \param pixels a pointer to existing pixel data.
* \param pitch the number of bytes between each row, including padding.
- * \param format the SDL_PixelFormatEnum for the new surface's pixel format.
* \returns the new SDL_Surface structure that is created or NULL if it fails;
* call SDL_GetError() for more information.
*
@@ -184,10 +173,10 @@ extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_CreateSurface(int width, int height
* \sa SDL_CreateSurface
* \sa SDL_DestroySurface
*/
-extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_CreateSurfaceFrom(void *pixels, int width, int height, int pitch, SDL_PixelFormatEnum format);
+extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_CreateSurfaceFrom(int width, int height, SDL_PixelFormat format, void *pixels, int pitch);
/**
- * Free an RGB surface.
+ * Free a surface.
*
* It is safe to pass NULL to this function.
*
@@ -195,6 +184,7 @@ extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_CreateSurfaceFrom(void *pixels, int
*
* \since This function is available since SDL 3.0.0.
*
+ * \sa SDL_CreateStackSurface
* \sa SDL_CreateSurface
* \sa SDL_CreateSurfaceFrom
*/
@@ -254,6 +244,8 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetSurfaceProperties(SDL_Surfac
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
+ *
+ * \sa SDL_GetSurfaceColorspace
*/
extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceColorspace(SDL_Surface *surface, SDL_Colorspace colorspace);
@@ -265,14 +257,13 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceColorspace(SDL_Surface *surface, S
* other RGB surfaces and SDL_COLORSPACE_BT709_FULL for YUV textures.
*
* \param surface the SDL_Surface structure to query.
- * \param colorspace a pointer filled in with an SDL_ColorSpace value
- * describing the surface colorspace.
- * \returns 0 on success or a negative error code on failure; call
- * SDL_GetError() for more information.
+ * \returns the colorspace used by the surface, or SDL_COLORSPACE_UNKNOWN if the surface is NULL.
*
* \since This function is available since SDL 3.0.0.
+ *
+ * \sa SDL_SetSurfaceColorspace
*/
-extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceColorspace(SDL_Surface *surface, SDL_Colorspace *colorspace);
+extern SDL_DECLSPEC SDL_Colorspace SDLCALL SDL_GetSurfaceColorspace(SDL_Surface *surface);
/**
* Set the palette used by a surface.
@@ -285,9 +276,24 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceColorspace(SDL_Surface *surface, S
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
+ *
+ * \sa SDL_CreatePalette
+ * \sa SDL_GetSurfacePalette
*/
extern SDL_DECLSPEC int SDLCALL SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette);
+/**
+ * Get the palette used by a surface.
+ *
+ * \param surface the SDL_Surface structure to query.
+ * \returns a pointer to the palette used by the surface, or NULL if there is no palette used.
+ *
+ * \since This function is available since SDL 3.0.0.
+ *
+ * \sa SDL_SetSurfacePalette
+ */
+extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_GetSurfacePalette(SDL_Surface *surface);
+
/**
* Set up a surface for directly accessing the pixels.
*
@@ -411,7 +417,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SaveBMP(SDL_Surface *surface, const char *fi
* the surface must be locked before directly accessing the pixels.
*
* \param surface the SDL_Surface structure to optimize.
- * \param flag 0 to disable, non-zero to enable RLE acceleration.
+ * \param enabled SDL_TRUE to enable RLE acceleration, SDL_FALSE to disable it.
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
@@ -421,7 +427,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SaveBMP(SDL_Surface *surface, const char *fi
* \sa SDL_LockSurface
* \sa SDL_UnlockSurface
*/
-extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface *surface, int flag);
+extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface *surface, SDL_bool enabled);
/**
* Returns whether the surface is RLE enabled.
@@ -447,11 +453,8 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SurfaceHasRLE(SDL_Surface *surface);
* It is a pixel of the format used by the surface, as generated by
* SDL_MapRGB().
*
- * RLE acceleration can substantially speed up blitting of images with large
- * horizontal runs of transparent pixels. See SDL_SetSurfaceRLE() for details.
- *
* \param surface the SDL_Surface structure to update.
- * \param flag SDL_TRUE to enable color key, SDL_FALSE to disable color key.
+ * \param enabled SDL_TRUE to enable color key, SDL_FALSE to disable color key.
* \param key the transparent pixel.
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
@@ -459,9 +462,10 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SurfaceHasRLE(SDL_Surface *surface);
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetSurfaceColorKey
+ * \sa SDL_SetSurfaceRLE
* \sa SDL_SurfaceHasColorKey
*/
-extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceColorKey(SDL_Surface *surface, int flag, Uint32 key);
+extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceColorKey(SDL_Surface *surface, SDL_bool enabled, Uint32 key);
/**
* Returns whether the surface has a color key.
@@ -682,40 +686,16 @@ extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_DuplicateSurface(SDL_Surface *surfa
* future blits, making them faster.
*
* \param surface the existing SDL_Surface structure to convert.
- * \param format the SDL_PixelFormat structure that the new surface is
- * optimized for.
- * \returns the new SDL_Surface structure that is created or NULL if it fails;
- * call SDL_GetError() for more information.
- *
- * \since This function is available since SDL 3.0.0.
- *
- * \sa SDL_ConvertSurfaceFormat
- * \sa SDL_ConvertSurfaceFormatAndColorspace
- * \sa SDL_CreatePixelFormat
- * \sa SDL_DestroySurface
- */
-extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface(SDL_Surface *surface, const SDL_PixelFormat *format);
-
-/**
- * Copy an existing surface to a new surface of the specified format.
- *
- * This function operates just like SDL_ConvertSurface(), but accepts an
- * SDL_PixelFormatEnum value instead of an SDL_PixelFormat structure. As such,
- * it might be easier to call but it doesn't have access to palette
- * information for the destination surface, in case that would be important.
- *
- * \param surface the existing SDL_Surface structure to convert.
- * \param pixel_format the new pixel format.
+ * \param format the new pixel format.
* \returns the new SDL_Surface structure that is created or NULL if it fails;
* call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
- * \sa SDL_ConvertSurface
- * \sa SDL_ConvertSurfaceFormatAndColorspace
+ * \sa SDL_ConvertSurfaceAndColorspace
* \sa SDL_DestroySurface
*/
-extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceFormat(SDL_Surface *surface, SDL_PixelFormatEnum pixel_format);
+extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface(SDL_Surface *surface, SDL_PixelFormat format);
/**
* Copy an existing surface to a new surface of the specified format and
@@ -726,7 +706,7 @@ extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceFormat(SDL_Surface *s
* colorspace conversion needed.
*
* \param surface the existing SDL_Surface structure to convert.
- * \param pixel_format the new pixel format.
+ * \param format the new pixel format.
* \param colorspace the new colorspace.
* \param props an SDL_PropertiesID with additional color properties, or 0.
* \returns the new SDL_Surface structure that is created or NULL if it fails;
@@ -735,20 +715,20 @@ extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceFormat(SDL_Surface *s
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_ConvertSurface
- * \sa SDL_ConvertSurfaceFormat
+ * \sa SDL_ConvertSurface
* \sa SDL_DestroySurface
*/
-extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceFormatAndColorspace(SDL_Surface *surface, SDL_PixelFormatEnum pixel_format, SDL_Colorspace colorspace, SDL_PropertiesID props);
+extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceAndColorspace(SDL_Surface *surface, SDL_PixelFormat format, SDL_Colorspace colorspace, SDL_PropertiesID props);
/**
* Copy a block of pixels of one format to another format.
*
* \param width the width of the block to copy, in pixels.
* \param height the height of the block to copy, in pixels.
- * \param src_format an SDL_PixelFormatEnum value of the `src` pixels format.
+ * \param src_format an SDL_PixelFormat value of the `src` pixels format.
* \param src a pointer to the source pixels.
* \param src_pitch the pitch of the source pixels, in bytes.
- * \param dst_format an SDL_PixelFormatEnum value of the `dst` pixels format.
+ * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
* \param dst a pointer to be filled in with new pixel data.
* \param dst_pitch the pitch of the destination pixels, in bytes.
* \returns 0 on success or a negative error code on failure; call
@@ -758,7 +738,7 @@ extern SDL_DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceFormatAndColorspace(S
*
* \sa SDL_ConvertPixelsAndColorspace
*/
-extern SDL_DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height, SDL_PixelFormatEnum src_format, const void *src, int src_pitch, SDL_PixelFormatEnum dst_format, void *dst, int dst_pitch);
+extern SDL_DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height, SDL_PixelFormat src_format, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch);
/**
* Copy a block of pixels of one format and colorspace to another format and
@@ -766,14 +746,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height, SDL_Pix
*
* \param width the width of the block to copy, in pixels.
* \param height the height of the block to copy, in pixels.
- * \param src_format an SDL_PixelFormatEnum value of the `src` pixels format.
+ * \param src_format an SDL_PixelFormat value of the `src` pixels format.
* \param src_colorspace an SDL_ColorSpace value describing the colorspace of
* the `src` pixels.
* \param src_properties an SDL_PropertiesID with additional source color
* properties, or 0.
* \param src a pointer to the source pixels.
* \param src_pitch the pitch of the source pixels, in bytes.
- * \param dst_format an SDL_PixelFormatEnum value of the `dst` pixels format.
+ * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
* \param dst_colorspace an SDL_ColorSpace value describing the colorspace of
* the `dst` pixels.
* \param dst_properties an SDL_PropertiesID with additional destination color
@@ -787,7 +767,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height, SDL_Pix
*
* \sa SDL_ConvertPixels
*/
-extern SDL_DECLSPEC int SDLCALL SDL_ConvertPixelsAndColorspace(int width, int height, SDL_PixelFormatEnum src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormatEnum dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch);
+extern SDL_DECLSPEC int SDLCALL SDL_ConvertPixelsAndColorspace(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch);
/**
* Premultiply the alpha on a block of pixels.
@@ -798,10 +778,10 @@ extern SDL_DECLSPEC int SDLCALL SDL_ConvertPixelsAndColorspace(int width, int he
*
* \param width the width of the block to convert, in pixels.
* \param height the height of the block to convert, in pixels.
- * \param src_format an SDL_PixelFormatEnum value of the `src` pixels format.
+ * \param src_format an SDL_PixelFormat value of the `src` pixels format.
* \param src a pointer to the source pixels.
* \param src_pitch the pitch of the source pixels, in bytes.
- * \param dst_format an SDL_PixelFormatEnum value of the `dst` pixels format.
+ * \param dst_format an SDL_PixelFormat value of the `dst` pixels format.
* \param dst a pointer to be filled in with premultiplied pixel data.
* \param dst_pitch the pitch of the destination pixels, in bytes.
* \returns 0 on success or a negative error code on failure; call
@@ -809,7 +789,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_ConvertPixelsAndColorspace(int width, int he
*
* \since This function is available since SDL 3.0.0.
*/
-extern SDL_DECLSPEC int SDLCALL SDL_PremultiplyAlpha(int width, int height, SDL_PixelFormatEnum src_format, const void *src, int src_pitch, SDL_PixelFormatEnum dst_format, void *dst, int dst_pitch);
+extern SDL_DECLSPEC int SDLCALL SDL_PremultiplyAlpha(int width, int height, SDL_PixelFormat src_format, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch);
/**
* Perform a fast fill of a rectangle with a specific color.
diff --git a/include/SDL3/SDL_video.h b/include/SDL3/SDL_video.h
index bd0d726dd972d8..5dcee6694ddb31 100644
--- a/include/SDL3/SDL_video.h
+++ b/include/SDL3/SDL_video.h
@@ -88,7 +88,7 @@ typedef enum SDL_SystemTheme
typedef struct SDL_DisplayMode
{
SDL_DisplayID displayID; /**< the display this mode is associated with */
- SDL_PixelFormatEnum format; /**< pixel format */
+ SDL_PixelFormat format; /**< pixel format */
int w; /**< width */
int h; /**< height */
float pixel_density; /**< scale converting size to pixels (e.g. a 1920x1080 mode with 2.0 scale would have 3840x2160 pixels) */
diff --git a/src/SDL.c b/src/SDL.c
index 2957787244963a..9c6cd58cbff78f 100644
--- a/src/SDL.c
+++ b/src/SDL.c
@@ -50,6 +50,7 @@
#include "render/SDL_sysrender.h"
#include "sensor/SDL_sensor_c.h"
#include "stdlib/SDL_getenv_c.h"
+#include "video/SDL_pixels_c.h"
#include "video/SDL_video_c.h"
#define SDL_INIT_EVERYTHING ~0U
@@ -549,6 +550,8 @@ void SDL_Quit(void)
SDL_ClearHints();
SDL_AssertionsQuit();
+ SDL_QuitPixelFormatDetails();
+
SDL_QuitCPUInfo();
SDL_QuitProperties();
diff --git a/src/SDL_hashtable.c b/src/SDL_hashtable.c
index fc7a44791c9a4b..d2a50c99ea2c1b 100644
--- a/src/SDL_hashtable.c
+++ b/src/SDL_hashtable.c
@@ -312,3 +312,8 @@ SDL_bool SDL_KeyMatchID(const void *a, const void *b, void *unused)
}
return SDL_FALSE;
}
+
+void SDL_NukeFreeValue(const void *key, const void *value, void *unused)
+{
+ SDL_free((void *)value);
+}
diff --git a/src/SDL_hashtable.h b/src/SDL_hashtable.h
index ef0945ee0c47b3..4c3f74dfa73665 100644
--- a/src/SDL_hashtable.h
+++ b/src/SDL_hashtable.h
@@ -29,30 +29,32 @@ typedef Uint32 (*SDL_HashTable_HashFn)(const void *key, void *data);
typedef SDL_bool (*SDL_HashTable_KeyMatchFn)(const void *a, const void *b, void *data);
typedef void (*SDL_HashTable_NukeFn)(const void *key, const void *value, void *data);
-SDL_HashTable *SDL_CreateHashTable(void *data,
- const Uint32 num_buckets,
- const SDL_HashTable_HashFn hashfn,
- const SDL_HashTable_KeyMatchFn keymatchfn,
- const SDL_HashTable_NukeFn nukefn,
- const SDL_bool stackable);
-
-void SDL_EmptyHashTable(SDL_HashTable *table);
-void SDL_DestroyHashTable(SDL_HashTable *table);
-SDL_bool SDL_InsertIntoHashTable(SDL_HashTable *table, const void *key, const void *value);
-SDL_bool SDL_RemoveFromHashTable(SDL_HashTable *table, const void *key);
-SDL_bool SDL_FindInHashTable(const SDL_HashTable *table, const void *key, const void **_value);
-SDL_bool SDL_HashTableEmpty(SDL_HashTable *table);
+extern SDL_HashTable *SDL_CreateHashTable(void *data,
+ const Uint32 num_buckets,
+ const SDL_HashTable_HashFn hashfn,
+ const SDL_HashTable_KeyMatchFn keymatchfn,
+ const SDL_HashTable_NukeFn nukefn,
+ const SDL_bool stackable);
+
+extern void SDL_EmptyHashTable(SDL_HashTable *table);
+extern void SDL_DestroyHashTable(SDL_HashTable *table);
+extern SDL_bool SDL_InsertIntoHashTable(SDL_HashTable *table, const void *key, const void *value);
+extern SDL_bool SDL_RemoveFromHashTable(SDL_HashTable *table, const void *key);
+extern SDL_bool SDL_FindInHashTable(const SDL_HashTable *table, const void *key, const void **_value);
+extern SDL_bool SDL_HashTableEmpty(SDL_HashTable *table);
// iterate all values for a specific key. This only makes sense if the hash is stackable. If not-stackable, just use SDL_FindInHashTable().
-SDL_bool SDL_IterateHashTableKey(const SDL_HashTable *table, const void *key, const void **_value, void **iter);
+extern SDL_bool SDL_IterateHashTableKey(const SDL_HashTable *table, const void *key, const void **_value, void **iter);
// iterate all key/value pairs in a hash (stackable hashes can have duplicate keys with multiple values).
-SDL_bool SDL_IterateHashTable(const SDL_HashTable *table, const void **_key, const void **_value, void **iter);
+extern SDL_bool SDL_IterateHashTable(const SDL_HashTable *table, const void **_key, const void **_value, void **iter);
-Uint32 SDL_HashString(const void *key, void *unused);
-SDL_bool SDL_KeyMatchString(const void *a, const void *b, void *unused);
+extern Uint32 SDL_HashString(const void *key, void *unused);
+extern SDL_bool SDL_KeyMatchString(const void *a, const void *b, void *unused);
-Uint32 SDL_HashID(const void *key, void *unused);
-SDL_bool SDL_KeyMatchID(const void *a, const void *b, void *unused);
+extern Uint32 SDL_HashID(const void *key, void *unused);
+extern SDL_bool SDL_KeyMatchID(const void *a, const void *b, void *unused);
+
+extern void SDL_NukeFreeValue(const void *key, const void *value, void *unused);
#endif /* SDL_hashtable_h_ */
diff --git a/src/camera/SDL_camera.c b/src/camera/SDL_camera.c
index b919948706de6d..260323afddc00a 100644
--- a/src/camera/SDL_camera.c
+++ b/src/camera/SDL_camera.c
@@ -84,7 +84,7 @@ char *SDL_GetCameraThreadName(SDL_CameraDevice *device, char *buf, size_t buflen
return buf;
}
-int SDL_AddCameraFormat(CameraFormatAddData *data, SDL_PixelFormatEnum format, SDL_Colorspace colorspace, int w, int h, int framerate_numerator, int framerate_denominator)
+int SDL_AddCameraFormat(CameraFormatAddData *data, SDL_PixelFormat format, SDL_Colorspace colorspace, int w, int h, int framerate_numerator, int framerate_denominator)
{
SDL_assert(data != NULL);
if (data->allocated_specs <= data->num_specs) {
@@ -130,7 +130,7 @@ static size_t GetFrameBufLen(const SDL_CameraSpec *spec)
const size_t w = (const size_t) spec->width;
const size_t h = (const size_t) spec->height;
const size_t wxh = w * h;
- const SDL_PixelFormatEnum fmt = spec->format;
+ const SDL_PixelFormat fmt = spec->format;
switch (fmt) {
// Some YUV formats have a larger Y plane than their U or V planes.
@@ -367,8 +367,8 @@ static int SDLCALL CameraSpecCmp(const void *vpa, const void *vpb)
SDL_assert(b->width > 0);
SDL_assert(b->height > 0);
- const SDL_PixelFormatEnum afmt = a->format;
- const SDL_PixelFormatEnum bfmt = b->format;
+ const SDL_PixelFormat afmt = a->format;
+ const SDL_PixelFormat bfmt = b->format;
if (SDL_ISPIXELFORMAT_FOURCC(afmt) && !SDL_ISPIXELFORMAT_FOURCC(bfmt)) {
return -1;
} else if (!SDL_ISPIXELFORMAT_FOURCC(afmt) && SDL_ISPIXELFORMAT_FOURCC(bfmt)) {
@@ -879,8 +879,8 @@ SDL_bool SDL_CameraThreadIterate(SDL_CameraDevice *device)
if (device->needs_conversion) {
SDL_Surface *dstsurf = (device->needs_scaling == 1) ? device->conversion_surface : output_surface;
SDL_ConvertPixels(srcsurf->w, srcsurf->h,
- srcsurf->format->format, srcsurf->pixels, srcsurf->pitch,
- dstsurf->format->format, dstsurf->pixels, dstsurf->pitch);
+ srcsurf->format, srcsurf->pixels, srcsurf->pitch,
+ dstsurf->format, dstsurf->pixels, dstsurf->pitch);
srcsurf = dstsurf;
}
if (device->needs_scaling == 1) { // upscaling? Do it last. -1: downscale, 0: no scaling, 1: upscale
@@ -1005,8 +1005,8 @@ static void ChooseBestCameraSpec(SDL_CameraDevice *device, const SDL_CameraSpec
SDL_assert(closest->height > 0);
// okay, we have what we think is the best resolution, now we just need the best format that supports it...
- const SDL_PixelFormatEnum wantfmt = spec->format;
- SDL_PixelFormatEnum best_format = SDL_PIXELFORMAT_UNKNOWN;
+ const SDL_PixelFormat wantfmt = spec->format;
+ SDL_PixelFormat best_format = SDL_PIXELFORMAT_UNKNOWN;
SDL_Colorspace best_colorspace = SDL_COLORSPACE_UNKNOWN;
for (int i = 0; i < num_specs; i++) {
const SDL_CameraSpec *thisspec = &device->all_specs[i];
@@ -1124,7 +1124,7 @@ SDL_Camera *SDL_OpenCameraDevice(SDL_CameraDeviceID instance_id, const SDL_Camer
device->needs_conversion = (closest.format != device->spec.format);
- device->acquire_surface = SDL_CreateSurfaceFrom(NULL, closest.width, closest.height, 0, closest.format);
+ device->acquire_surface = SDL_CreateSurfaceFrom(closest.width, closest.height, closest.format, NULL, 0);
if (!device->acquire_surface) {
ClosePhysicalCameraDevice(device);
ReleaseCameraDevice(device);
@@ -1136,7 +1136,7 @@ SDL_Camera *SDL_OpenCameraDevice(SDL_CameraDeviceID instance_id, const SDL_Camer
if (device->needs_scaling && device->needs_conversion) {
const SDL_bool downsampling_first = (device->needs_scaling < 0);
const SDL_CameraSpec *s = downsampling_first ? &device->spec : &closest;
- const SDL_PixelFormatEnum fmt = downsampling_first ? closest.format : device->spec.format;
+ const SDL_PixelFormat fmt = downsampling_first ? closest.format : device->spec.format;
device->conversion_surface = SDL_CreateSurface(s->width, s->height, fmt);
if (!device->conversion_surface) {
ClosePhysicalCameraDevice(device);
@@ -1160,7 +1160,7 @@ SDL_Camera *SDL_OpenCameraDevice(SDL_CameraDeviceID instance_id, const SDL_Camer
if (device->needs_scaling || device->needs_conversion) {
surf = SDL_CreateSurface(device->spec.width, device->spec.height, device->spec.format);
} else {
- surf = SDL_CreateSurfaceFrom(NULL, device->spec.width, device->spec.height, 0, device->spec.format);
+ surf = SDL_CreateSurfaceFrom(device->spec.width, device->spec.height, device->spec.format, NULL, 0);
}
if (!surf) {
ClosePhysicalCameraDevice(device);
diff --git a/src/camera/SDL_syscamera.h b/src/camera/SDL_syscamera.h
index 6ad966381e49c5..40ed83a8aed236 100644
--- a/src/camera/SDL_syscamera.h
+++ b/src/camera/SDL_syscamera.h
@@ -64,7 +64,7 @@ typedef struct CameraFormatAddData
int allocated_specs;
} CameraFormatAddData;
-int SDL_AddCameraFormat(CameraFormatAddData *data, SDL_PixelFormatEnum format, SDL_Colorspace colorspace, int w, int h, int framerate_numerator, int framerate_denominator);
+int SDL_AddCameraFormat(CameraFormatAddData *data, SDL_PixelFormat format, SDL_Colorspace colorspace, int w, int h, int framerate_numerator, int framerate_denominator);
typedef struct SurfaceList
{
diff --git a/src/camera/android/SDL_camera_android.c b/src/camera/android/SDL_camera_android.c
index 7dbe251eb6ef08..ad3863f90360e2 100644
--- a/src/camera/android/SDL_camera_android.c
+++ b/src/camera/android/SDL_camera_android.c
@@ -252,7 +252,7 @@ static void DestroyCameraManager(void)
}
}
-static void format_android_to_sdl(Uint32 fmt, SDL_PixelFormatEnum *format, SDL_Colorspace *colorspace)
+static void format_android_to_sdl(Uint32 fmt, SDL_PixelFormat *format, SDL_Colorspace *colorspace)
{
switch (fmt) {
#define CASE(x, y, z) case x: *format = y; *colorspace = z; return
@@ -274,7 +274,7 @@ static void format_android_to_sdl(Uint32 fmt, SDL_PixelFormatEnum *format, SDL_C
*colorspace = SDL_COLORSPACE_UNKNOWN;
}
-static Uint32 format_sdl_to_android(SDL_PixelFormatEnum fmt)
+static Uint32 format_sdl_to_android(SDL_PixelFormat fmt)
{
switch (fmt) {
#define CASE(x, y) case y: return x
@@ -632,7 +632,7 @@ static void GatherCameraSpecs(const char *devid, CameraFormatAddData *add_data,
const int w = (int) i32ptr[1];
const int h = (int) i32ptr[2];
const int32_t type = i32ptr[3];
- SDL_PixelFormatEnum sdlfmt = SDL_PIXELFORMAT_UNKNOWN;
+ SDL_PixelFormat sdlfmt = SDL_PIXELFORMAT_UNKNOWN;
SDL_Colorspace colorspace = SDL_COLORSPACE_UNKNOWN;
if (type == ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_INPUT) {
diff --git a/src/camera/coremedia/SDL_camera_coremedia.m b/src/camera/coremedia/SDL_camera_coremedia.m
index 6e407ea4cdf12c..133dc2b45a4e1d 100644
--- a/src/camera/coremedia/SDL_camera_coremedia.m
+++ b/src/camera/coremedia/SDL_camera_coremedia.m
@@ -41,7 +41,7 @@
* com.apple.security.device.camera
*/
-static void CoreMediaFormatToSDL(FourCharCode fmt, SDL_PixelFormatEnum *pixel_format, SDL_Colorspace *colorspace)
+static void CoreMediaFormatToSDL(FourCharCode fmt, SDL_PixelFormat *pixel_format, SDL_Colorspace *colorspace)
{
switch (fmt) {
#define CASE(x, y, z) case x: *pixel_format = y; *colorspace = z; return
@@ -260,7 +260,7 @@ static int COREMEDIA_OpenDevice(SDL_CameraDevice *device, const SDL_CameraSpec *
NSArray *formats = [avdevice formats];
for (AVCaptureDeviceFormat *format in formats) {
CMFormatDescriptionRef formatDescription = [format formatDescription];
- SDL_PixelFormatEnum device_format = SDL_PIXELFORMAT_UNKNOWN;
+ SDL_PixelFormat device_format = SDL_PIXELFORMAT_UNKNOWN;
SDL_Colorspace device_colorspace = SDL_COLORSPACE_UNKNOWN;
CoreMediaFormatToSDL(CMFormatDescriptionGetMediaSubType(formatDescription), &device_format, &device_colorspace);
if (device_format != spec->format || device_colorspace != spec->colorspace) {
@@ -384,7 +384,7 @@ static void GatherCameraSpecs(AVCaptureDevice *device, CameraFormatAddData *add_
}
//NSLog(@"Available camera format: %@\n", fmt);
- SDL_PixelFormatEnum device_format = SDL_PIXELFORMAT_UNKNOWN;
+ SDL_PixelFormat device_format = SDL_PIXELFORMAT_UNKNOWN;
SDL_Colorspace device_colorspace = SDL_COLORSPACE_UNKNOWN;
CoreMediaFormatToSDL(CMFormatDescriptionGetMediaSubType(fmt.formatDescription), &device_format, &device_colorspace);
if (device_format == SDL_PIXELFORMAT_UNKNOWN) {
diff --git a/src/camera/mediafoundation/SDL_camera_mediafoundation.c b/src/camera/mediafoundation/SDL_camera_mediafoundation.c
index 0421b5b664df80..7776d1e3b3e9f0 100644
--- a/src/camera/mediafoundation/SDL_camera_mediafoundation.c
+++ b/src/camera/mediafoundation/SDL_camera_mediafoundation.c
@@ -85,7 +85,7 @@ SDL_DEFINE_MEDIATYPE_GUID(MFVideoFormat_NV21, FCC('NV21'));
static const struct
{
const GUID *guid;
- SDL_PixelFormatEnum format;
+ SDL_PixelFormat format;
SDL_Colorspace colorspace;
} fmtmappings[] = {
// This is not every possible format, just popular ones that SDL can reasonably handle.
@@ -281,7 +281,7 @@ static SDL_Colorspace GetMediaTypeColorspace(IMFMediaType *mediatype, SDL_Colors
return colorspace;
}
-static void MediaTypeToSDLFmt(IMFMediaType *mediatype, SDL_PixelFormatEnum *format, SDL_Colorspace *colorspace)
+static void MediaTypeToSDLFmt(IMFMediaType *mediatype, SDL_PixelFormat *format, SDL_Colorspace *colorspace)
{
HRESULT ret;
GUID type;
@@ -300,7 +300,7 @@ static void MediaTypeToSDLFmt(IMFMediaType *mediatype, SDL_PixelFormatEnum *form
*colorspace = SDL_COLORSPACE_UNKNOWN;
}
-static const GUID *SDLFmtToMFVidFmtGuid(SDL_PixelFormatEnum format)
+static const GUID *SDLFmtToMFVidFmtGuid(SDL_PixelFormat format)
{
for (size_t i = 0; i < SDL_arraysize(fmtmappings); i++) {
if (fmtmappings[i].format == format) {
@@ -930,7 +930,7 @@ static void GatherCameraSpecs(IMFMediaSource *source, CameraFormatAddData *add_d
GUID type;
ret = IMFMediaType_GetGUID(mediatype, &SDL_MF_MT_MAJOR_TYPE, &type);
if (SUCCEEDED(ret) && WIN_IsEqualGUID(&type, &SDL_MFMediaType_Video)) {
- SDL_PixelFormatEnum sdlfmt = SDL_PIXELFORMAT_UNKNOWN;
+ SDL_PixelFormat sdlfmt = SDL_PIXELFORMAT_UNKNOWN;
SDL_Colorspace colorspace = SDL_COLORSPACE_UNKNOWN;
MediaTypeToSDLFmt(mediatype, &sdlfmt, &colorspace);
if (sdlfmt != SDL_PIXELFORMAT_UNKNOWN) {
diff --git a/src/camera/pipewire/SDL_camera_pipewire.c b/src/camera/pipewire/SDL_camera_pipewire.c
index 4bf35ec3f404e9..3b297c37ba84c0 100644
--- a/src/camera/pipewire/SDL_camera_pipewire.c
+++ b/src/camera/pipewire/SDL_camera_pipewire.c
@@ -357,7 +357,7 @@ static void param_update(struct spa_list *param_list, struct spa_list *pending_l
}
static struct sdl_video_format {
- SDL_PixelFormatEnum format;
+ SDL_PixelFormat format;
SDL_Colorspace colorspace;
uint32_t id;
} sdl_video_formats[] = {
@@ -389,7 +389,7 @@ static struct sdl_video_format {
#endif
};
-static uint32_t sdl_format_to_id(SDL_PixelFormatEnum format)
+static uint32_t sdl_format_to_id(SDL_PixelFormat format)
{
struct sdl_video_format *f;
SPA_FOR_EACH_ELEMENT(sdl_video_formats, f) {
@@ -399,7 +399,7 @@ static uint32_t sdl_format_to_id(SDL_PixelFormatEnum format)
return SPA_VIDEO_FORMAT_UNKNOWN;
}
-static void id_to_sdl_format(uint32_t id, SDL_PixelFormatEnum *format, SDL_Colorspace *colorspace)
+static void id_to_sdl_format(uint32_t id, SDL_PixelFormat *format, SDL_Colorspace *colorspace)
{
struct sdl_video_format *f;
SPA_FOR_EACH_ELEMENT(sdl_video_formats, f) {
@@ -603,7 +603,7 @@ static void PIPEWIRECAMERA_ReleaseFrame(SDL_CameraDevice *device, SDL_Surface *f
PIPEWIRE_pw_thread_loop_unlock(hotplug.loop);
}
-static void collect_rates(CameraFormatAddData *data, struct param *p, SDL_PixelFormatEnum sdlfmt, SDL_Colorspace colorspace, const struct spa_rectangle *size)
+static void collect_rates(CameraFormatAddData *data, struct param *p, SDL_PixelFormat sdlfmt, SDL_Colorspace colorspace, const struct spa_rectangle *size)
{
const struct spa_pod_prop *prop;
struct spa_pod * values;
@@ -636,7 +636,7 @@ static void collect_rates(CameraFormatAddData *data, struct param *p, SDL_PixelF
}
}
-static void collect_size(CameraFormatAddData *data, struct param *p, SDL_PixelFormatEnum sdlfmt, SDL_Colorspace colorspace)
+static void collect_size(CameraFormatAddData *data, struct param *p, SDL_PixelFormat sdlfmt, SDL_Colorspace colorspace)
{
const struct spa_pod_prop *prop;
struct spa_pod * values;
@@ -670,7 +670,7 @@ static void collect_size(CameraFormatAddData *data, struct param *p, SDL_PixelFo
static void collect_format(CameraFormatAddData *data, struct param *p)
{
const struct spa_pod_prop *prop;
- SDL_PixelFormatEnum sdlfmt;
+ SDL_PixelFormat sdlfmt;
SDL_Colorspace colorspace;
struct spa_pod * values;
uint32_t i, n_vals, choice, *ids;
diff --git a/src/camera/v4l2/SDL_camera_v4l2.c b/src/camera/v4l2/SDL_camera_v4l2.c
index 7debf296761ae4..ed320e7deb7e7e 100644
--- a/src/camera/v4l2/SDL_camera_v4l2.c
+++ b/src/camera/v4l2/SDL_camera_v4l2.c
@@ -391,7 +391,7 @@ static int AllocBufferUserPtr(SDL_CameraDevice *device, size_t buffer_size)
return 0;
}
-static void format_v4l2_to_sdl(Uint32 fmt, SDL_PixelFormatEnum *format, SDL_Colorspace *colorspace)
+static void format_v4l2_to_sdl(Uint32 fmt, SDL_PixelFormat *format, SDL_Colorspace *colorspace)
{
switch (fmt) {
#define CASE(x, y, z) case x: *format = y; *colorspace = z; return
@@ -407,7 +407,7 @@ static void format_v4l2_to_sdl(Uint32 fmt, SDL_PixelFormatEnum *format, SDL_Colo
*colorspace = SDL_COLORSPACE_UNKNOWN;
}
-static Uint32 format_sdl_to_v4l2(SDL_PixelFormatEnum fmt)
+static Uint32 format_sdl_to_v4l2(SDL_PixelFormat fmt)
{
switch (fmt) {
#define CASE(y, x) case x: return y
@@ -645,7 +645,7 @@ static SDL_bool FindV4L2CameraDeviceByBusInfoCallback(SDL_CameraDevice *device,
return (SDL_strcmp(handle->bus_info, (const char *) userdata) == 0);
}
-static int AddCameraFormat(const int fd, CameraFormatAddData *data, SDL_PixelFormatEnum sdlfmt, SDL_Colorspace colorspace, Uint32 v4l2fmt, int w, int h)
+static int AddCameraFormat(const int fd, CameraFormatAddData *data, SDL_PixelFormat sdlfmt, SDL_Colorspace colorspace, Uint32 v4l2fmt, int w, int h)
{
struct v4l2_frmivalenum frmivalenum;
SDL_zero(frmivalenum);
@@ -729,7 +729,7 @@ static void MaybeAddDevice(const char *path)
SDL_zero(fmtdesc);
fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
while (ioctl(fd, VIDIOC_ENUM_FMT, &fmtdesc) == 0) {
- SDL_PixelFormatEnum sdlfmt = SDL_PIXELFORMAT_UNKNOWN;
+ SDL_PixelFormat sdlfmt = SDL_PIXELFORMAT_UNKNOWN;
SDL_Colorspace colorspace = SDL_COLORSPACE_UNKNOWN;
format_v4l2_to_sdl(fmtdesc.pixelformat, &sdlfmt, &colorspace);
diff --git a/src/dynapi/SDL_dynapi.sym b/src/dynapi/SDL_dynapi.sym
index 284d1bda56b16b..2d3504d979a794 100644
--- a/src/dynapi/SDL_dynapi.sym
+++ b/src/dynapi/SDL_dynapi.sym
@@ -58,8 +58,7 @@ SDL3_0.0.0 {
SDL_ConvertPixels;
SDL_ConvertPixelsAndColorspace;
SDL_ConvertSurface;
- SDL_ConvertSurfaceFormat;
- SDL_ConvertSurfaceFormatAndColorspace;
+ SDL_ConvertSurfaceAndColorspace;
SDL_CopyProperties;
SDL_CreateAudioStream;
SDL_CreateColorCursor;
@@ -330,7 +329,7 @@ SDL3_0.0.0 {
SDL_GetKeyboards;
SDL_GetLogOutputFunction;
SDL_GetLogPriority;
- SDL_GetMasksForPixelFormatEnum;
+ SDL_GetMasksForPixelFormat;
SDL_GetMaxHapticEffects;
SDL_GetMaxHapticEffectsPlaying;
SDL_GetMemoryFunctions;
@@ -364,7 +363,7 @@ SDL3_0.0.0 {
SDL_GetPens;
SDL_GetPerformanceCounter;
SDL_GetPerformanceFrequency;
- SDL_GetPixelFormatEnumForMasks;
+ SDL_GetPixelFormatForMasks;
SDL_GetPixelFormatName;
SDL_GetPlatform;
SDL_GetPowerInfo;
@@ -436,6 +435,7 @@ SDL3_0.0.0 {
SDL_GetSurfaceColorKey;
SDL_GetSurfaceColorMod;
SDL_GetSurfaceColorspace;
+ SDL_GetSurfacePalette;
SDL_GetSurfaceProperties;
SDL_GetSystemRAM;
SDL_GetSystemTheme;
@@ -724,7 +724,6 @@ SDL3_0.0.0 {
SDL_SetModState;
SDL_SetNumberProperty;
SDL_SetPaletteColors;
- SDL_SetPixelFormatPalette;
SDL_SetPrimarySelectionText;
SDL_SetProperty;
SDL_SetPropertyWithCleanup;
diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h
index 701d5fe3291ccc..59d54d66eb1d9f 100644
--- a/src/dynapi/SDL_dynapi_overrides.h
+++ b/src/dynapi/SDL_dynapi_overrides.h
@@ -83,8 +83,7 @@
#define SDL_ConvertPixels SDL_ConvertPixels_REAL
#define SDL_ConvertPixelsAndColorspace SDL_ConvertPixelsAndColorspace_REAL
#define SDL_ConvertSurface SDL_ConvertSurface_REAL
-#define SDL_ConvertSurfaceFormat SDL_ConvertSurfaceFormat_REAL
-#define SDL_ConvertSurfaceFormatAndColorspace SDL_ConvertSurfaceFormatAndColorspace_REAL
+#define SDL_ConvertSurfaceAndColorspace SDL_ConvertSurfaceAndColorspace_REAL
#define SDL_CopyProperties SDL_CopyProperties_REAL
#define SDL_CreateAudioStream SDL_CreateAudioStream_REAL
#define SDL_CreateColorCursor SDL_CreateColorCursor_REAL
@@ -94,7 +93,6 @@
#define SDL_CreateHapticEffect SDL_CreateHapticEffect_REAL
#define SDL_CreateMutex SDL_CreateMutex_REAL
#define SDL_CreatePalette SDL_CreatePalette_REAL
-#define SDL_CreatePixelFormat SDL_CreatePixelFormat_REAL
#define SDL_CreatePopupWindow SDL_CreatePopupWindow_REAL
#define SDL_CreateProperties SDL_CreateProperties_REAL
#define SDL_CreateRWLock SDL_CreateRWLock_REAL
@@ -191,8 +189,8 @@
#define SDL_GetAndroidSDKVersion SDL_GetAndroidSDKVersion_REAL
#define SDL_GetAssertionHandler SDL_GetAssertionHandler_REAL
#define SDL_GetAssertionReport SDL_GetAssertionReport_REAL
-#define SDL_GetAudioDeviceGain SDL_GetAudioDeviceGain_REAL
#define SDL_GetAudioDeviceFormat SDL_GetAudioDeviceFormat_REAL
+#define SDL_GetAudioDeviceGain SDL_GetAudioDeviceGain_REAL
#define SDL_GetAudioDeviceName SDL_GetAudioDeviceName_REAL
#define SDL_GetAudioDriver SDL_GetAudioDriver_REAL
#define SDL_GetAudioPlaybackDevices SDL_GetAudioPlaybackDevices_REAL
@@ -355,7 +353,7 @@
#define SDL_GetKeyboards SDL_GetKeyboards_REAL
#define SDL_GetLogOutputFunction SDL_GetLogOutputFunction_REAL
#define SDL_GetLogPriority SDL_GetLogPriority_REAL
-#define SDL_GetMasksForPixelFormatEnum SDL_GetMasksForPixelFormatEnum_REAL
+#define SDL_GetMasksForPixelFormat SDL_GetMasksForPixelFormat_REAL
#define SDL_GetMaxHapticEffects SDL_GetMaxHapticEffects_REAL
#define SDL_GetMaxHapticEffectsPlaying SDL_GetMaxHapticEffectsPlaying_REAL
#define SDL_GetMemoryFunctions SDL_GetMemoryFunctions_REAL
@@ -389,7 +387,8 @@
#define SDL_GetPens SDL_GetPens_REAL
#define SDL_GetPerformanceCounter SDL_GetPerformanceCounter_REAL
#define SDL_GetPerformanceFrequency SDL_GetPerformanceFrequency_REAL
-#define SDL_GetPixelFormatEnumForMasks SDL_GetPixelFormatEnumForMasks_REAL
+#define SDL_GetPixelFormatDetails SDL_GetPixelFormatDetails_REAL
+#define SDL_GetPixelFormatForMasks SDL_GetPixelFormatForMasks_REAL
#define SDL_GetPixelFormatName SDL_GetPixelFormatName_REAL
#define SDL_GetPlatform SDL_GetPlatform_REAL
#define SDL_GetPowerInfo SDL_GetPowerInfo_REAL
@@ -461,6 +460,7 @@
#define SDL_GetSurfaceColorKey SDL_GetSurfaceColorKey_REAL
#define SDL_GetSurfaceColorMod SDL_GetSurfaceColorMod_REAL
#define SDL_GetSurfaceColorspace SDL_GetSurfaceColorspace_REAL
+#define SDL_GetSurfacePalette SDL_GetSurfacePalette_REAL
#define SDL_GetSurfaceProperties SDL_GetSurfaceProperties_REAL
#define SDL_GetSystemRAM SDL_GetSystemRAM_REAL
#define SDL_GetSystemTheme SDL_GetSystemTheme_REAL
@@ -749,7 +749,6 @@
#define SDL_SetModState SDL_SetModState_REAL
#define SDL_SetNumberProperty SDL_SetNumberProperty_REAL
#define SDL_SetPaletteColors SDL_SetPaletteColors_REAL
-#define SDL_SetPixelFormatPalette SDL_SetPixelFormatPalette_REAL
#define SDL_SetPrimarySelectionText SDL_SetPrimarySelectionText_REAL
#define SDL_SetProperty SDL_SetProperty_REAL
#define SDL_SetPropertyWithCleanup SDL_SetPropertyWithCleanup_REAL
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 75fd300e191831..b8aef8c8a3660b 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -100,11 +100,10 @@ SDL_DYNAPI_PROC(int,SDL_CloseStorage,(SDL_Storage *a),(a),return)
SDL_DYNAPI_PROC(SDL_BlendMode,SDL_ComposeCustomBlendMode,(SDL_BlendFactor a, SDL_BlendFactor b, SDL_BlendOperation c, SDL_BlendFactor d, SDL_BlendFactor e, SDL_BlendOperation f),(a,b,c,d,e,f),return)
SDL_DYNAPI_PROC(int,SDL_ConvertAudioSamples,(const SDL_AudioSpec *a, const Uint8 *b, int c, const SDL_AudioSpec *d, Uint8 **e, int *f),(a,b,c,d,e,f),return)
SDL_DYNAPI_PROC(int,SDL_ConvertEventToRenderCoordinates,(SDL_Renderer *a, SDL_Event *b),(a,b),return)
-SDL_DYNAPI_PROC(int,SDL_ConvertPixels,(int a, int b, SDL_PixelFormatEnum c, const void *d, int e, SDL_PixelFormatEnum f, void *g, int h),(a,b,c,d,e,f,g,h),return)
-SDL_DYNAPI_PROC(int,SDL_ConvertPixelsAndColorspace,(int a, int b, SDL_PixelFormatEnum c, SDL_Colorspace d, SDL_PropertiesID e, const void *f, int g, SDL_PixelFormatEnum h, SDL_Colorspace i, SDL_PropertiesID j, void *k, int l),(a,b,c,d,e,f,g,h,i,j,k,l),return)
-SDL_DYNAPI_PROC(SDL_Surface*,SDL_ConvertSurface,(SDL_Surface *a, const SDL_PixelFormat *b),(a,b),return)
-SDL_DYNAPI_PROC(SDL_Surface*,SDL_ConvertSurfaceFormat,(SDL_Surface *a, SDL_PixelFormatEnum b),(a,b),return)
-SDL_DYNAPI_PROC(SDL_Surface*,SDL_ConvertSurfaceFormatAndColorspace,(SDL_Surface *a, SDL_PixelFormatEnum b, SDL_Colorspace c, SDL_PropertiesID d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(int,SDL_ConvertPixels,(int a, int b, SDL_PixelFormat c, const void *d, int e, SDL_PixelFormat f, void *g, int h),(a,b,c,d,e,f,g,h),return)
+SDL_DYNAPI_PROC(int,SDL_ConvertPixelsAndColorspace,(int a, int b, SDL_PixelFormat c, SDL_Colorspace d, SDL_PropertiesID e, const void *f, int g, SDL_PixelFormat h, SDL_Colorspace i, SDL_PropertiesID j, void *k, int l),(a,b,c,d,e,f,g,h,i,j,k,l),return)
+SDL_DYNAPI_PROC(SDL_Surface*,SDL_ConvertSurface,(SDL_Surface *a, SDL_PixelFormat b),(a,b),return)
+SDL_DYNAPI_PROC(SDL_Surface*,SDL_ConvertSurfaceAndColorspace,(SDL_Surface *a, SDL_PixelFormat b, SDL_Colorspace c, SDL_PropertiesID d),(a,b,c,d),return)
SDL_DYNAPI_PROC(int,SDL_CopyProperties,(SDL_PropertiesID a, SDL_PropertiesID b),(a,b),return)
SDL_DYNAPI_PROC(SDL_AudioStream*,SDL_CreateAudioStream,(const SDL_AudioSpec *a, const SDL_AudioSpec *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_Cursor*,SDL_CreateColorCursor,(SDL_Surface *a, int b, int c),(a,b,c),return)
@@ -114,7 +113,6 @@ SDL_DYNAPI_PROC(int,SDL_CreateDirectory,(const char *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_CreateHapticEffect,(SDL_Haptic *a, const SDL_HapticEffect *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_Mutex*,SDL_CreateMutex,(void),(),return)
SDL_DYNAPI_PROC(SDL_Palette*,SDL_CreatePalette,(int a),(a),return)
-SDL_DYNAPI_PROC(SDL_PixelFormat*,SDL_CreatePixelFormat,(SDL_PixelFormatEnum a),(a),return)
SDL_DYNAPI_PROC(SDL_Window*,SDL_CreatePopupWindow,(SDL_Window *a, int b, int c, int d, int e, SDL_WindowFlags f),(a,b,c,d,e,f),return)
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_CreateProperties,(void),(),return)
SDL_DYNAPI_PROC(SDL_RWLock*,SDL_CreateRWLock,(void),(),return)
@@ -123,11 +121,11 @@ SDL_DYNAPI_PROC(SDL_Renderer*,SDL_CreateRendererWithProperties,(SDL_PropertiesID
SDL_DYNAPI_PROC(SDL_Semaphore*,SDL_CreateSemaphore,(Uint32 a),(a),return)
SDL_DYNAPI_PROC(SDL_Renderer*,SDL_CreateSoftwareRenderer,(SDL_Surface *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_CreateStorageDirectory,(SDL_Storage *a, const char *b),(a,b),return)
-SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateSurface,(int a, int b, SDL_PixelFormatEnum c),(a,b,c),return)
-SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateSurfaceFrom,(void *a, int b, int c, int d, SDL_PixelFormatEnum e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateSurface,(int a, int b, SDL_PixelFormat c),(a,b,c),return)
+SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateSurfaceFrom,(int a, int b, SDL_PixelFormat c, void *d, int e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(SDL_Cursor*,SDL_CreateSystemCursor,(SDL_SystemCursor a),(a),return)
SDL_DYNAPI_PROC(SDL_TLSID,SDL_CreateTLS,(void),(),return)
-SDL_DYNAPI_PROC(SDL_Texture*,SDL_CreateTexture,(SDL_Renderer *a, SDL_PixelFormatEnum b, int c, int d, int e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(SDL_Texture*,SDL_CreateTexture,(SDL_Renderer *a, SDL_PixelFormat b, int c, int d, int e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(SDL_Texture*,SDL_CreateTextureFromSurface,(SDL_Renderer *a, SDL_Surface *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_Texture*,SDL_CreateTextureWithProperties,(SDL_Renderer *a, SDL_PropertiesID b),(a,b),return)
SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThreadRuntime,(SDL_ThreadFunction a, const char *b, void *c, SDL_FunctionPointer d, SDL_FunctionPointer e),(a,b,c,d,e),return)
@@ -148,7 +146,6 @@ SDL_DYNAPI_PROC(void,SDL_DestroyCursor,(SDL_Cursor *a),(a),)
SDL_DYNAPI_PROC(void,SDL_DestroyHapticEffect,(SDL_Haptic *a, int b),(a,b),)
SDL_DYNAPI_PROC(void,SDL_DestroyMutex,(SDL_Mutex *a),(a),)
SDL_DYNAPI_PROC(void,SDL_DestroyPalette,(SDL_Palette *a),(a),)
-SDL_DYNAPI_PROC(void,SDL_DestroyPixelFormat,(SDL_PixelFormat *a),(a),)
SDL_DYNAPI_PROC(void,SDL_DestroyProperties,(SDL_PropertiesID a),(a),)
SDL_DYNAPI_PROC(void,SDL_DestroyRWLock,(SDL_RWLock *a),(a),)
SDL_DYNAPI_PROC(void,SDL_DestroyRenderer,(SDL_Renderer *a),(a),)
@@ -375,7 +372,7 @@ SDL_DYNAPI_PROC(const Uint8*,SDL_GetKeyboardState,(int *a),(a),return)
SDL_DYNAPI_PROC(SDL_KeyboardID*,SDL_GetKeyboards,(int *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_GetLogOutputFunction,(SDL_LogOutputFunction *a, void **b),(a,b),)
SDL_DYNAPI_PROC(SDL_LogPriority,SDL_GetLogPriority,(int a),(a),return)
-SDL_DYNAPI_PROC(SDL_bool,SDL_GetMasksForPixelFormatEnum,(SDL_PixelFormatEnum a, int *b, Uint32 *c, Uint32 *d, Uint32 *e, Uint32 *f),(a,b,c,d,e,f),return)
+SDL_DYNAPI_PROC(int,SDL_GetMasksForPixelFormat,(SDL_PixelFormat a, int *b, Uint32 *c, Uint32 *d, Uint32 *e, Uint32 *f),(a,b,c,d,e,f),return)
SDL_DYNAPI_PROC(int,SDL_GetMaxHapticEffects,(SDL_Haptic *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetMaxHapticEffectsPlaying,(SDL_Haptic *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_GetMemoryFunctions,(SDL_malloc_func *a, SDL_calloc_func *b, SDL_realloc_func *c, SDL_free_func *d),(a,b,c,d),)
@@ -409,8 +406,9 @@ SDL_DYNAPI_PROC(SDL_PenSubtype,SDL_GetPenType,(SDL_PenID a),(a),return)
SDL_DYNAPI_PROC(SDL_PenID*,SDL_GetPens,(int *a),(a),return)
SDL_DYNAPI_PROC(Uint64,SDL_GetPerformanceCounter,(void),(),return)
SDL_DYNAPI_PROC(Uint64,SDL_GetPerformanceFrequency,(void),(),return)
-SDL_DYNAPI_PROC(SDL_PixelFormatEnum,SDL_GetPixelFormatEnumForMasks,(int a, Uint32 b, Uint32 c, Uint32 d, Uint32 e),(a,b,c,d,e),return)
-SDL_DYNAPI_PROC(const char*,SDL_GetPixelFormatName,(SDL_PixelFormatEnum a),(a),return)
+SDL_DYNAPI_PROC(const SDL_PixelFormatDetails*,SDL_GetPixelFormatDetails,(SDL_PixelFormat a),(a),return)
+SDL_DYNAPI_PROC(SDL_PixelFormat,SDL_GetPixelFormatForMasks,(int a, Uint32 b, Uint32 c, Uint32 d, Uint32 e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(const char*,SDL_GetPixelFormatName,(SDL_PixelFormat a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetPlatform,(void),(),return)
SDL_DYNAPI_PROC(SDL_PowerState,SDL_GetPowerInfo,(int *a, int *b),(a,b),return)
SDL_DYNAPI_PROC(char*,SDL_GetPrefPath,(const char *a, const char *b),(a,b),return)
@@ -419,8 +417,8 @@ SDL_DYNAPI_PROC(SDL_DisplayID,SDL_GetPrimaryDisplay,(void),(),return)
SDL_DYNAPI_PROC(char*,SDL_GetPrimarySelectionText,(void),(),return)
SDL_DYNAPI_PROC(void*,SDL_GetProperty,(SDL_PropertiesID a, const char *b, void *c),(a,b,c),return)
SDL_DYNAPI_PROC(SDL_PropertyType,SDL_GetPropertyType,(SDL_PropertiesID a, const char *b),(a,b),return)
-SDL_DYNAPI_PROC(void,SDL_GetRGB,(Uint32 a, const SDL_PixelFormat *b, Uint8 *c, Uint8 *d, Uint8 *e),(a,b,c,d,e),)
-SDL_DYNAPI_PROC(void,SDL_GetRGBA,(Uint32 a, const SDL_PixelFormat *b, Uint8 *c, Uint8 *d, Uint8 *e, Uint8 *f),(a,b,c,d,e,f),)
+SDL_DYNAPI_PROC(void,SDL_GetRGB,(Uint32 a, SDL_PixelFormat b, SDL_Palette *c, Uint8 *d, Uint8 *e, Uint8 *f),(a,b,c,d,e,f),)
+SDL_DYNAPI_PROC(void,SDL_GetRGBA,(Uint32 a, SDL_PixelFormat b, SDL_Palette *c, Uint8 *d, Uint8 *e, Uint8 *f, Uint8 *g),(a,b,c,d,e,f,g),)
SDL_DYNAPI_PROC(SDL_GamepadType,SDL_GetRealGamepadInstanceType,(SDL_JoystickID a),(a),return)
SDL_DYNAPI_PROC(SDL_GamepadType,SDL_GetRealGamepadType,(SDL_Gamepad *a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GetRectAndLineIntersection,(const SDL_Rect *a, int *b, int *c, int *d, int *e),(a,b,c,d,e),return)
@@ -480,7 +478,8 @@ SDL_DYNAPI_PROC(int,SDL_GetSurfaceBlendMode,(SDL_Surface *a, SDL_BlendMode *b),(
SDL_DYNAPI_PROC(int,SDL_GetSurfaceClipRect,(SDL_Surface *a, SDL_Rect *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetSurfaceColorKey,(SDL_Surface *a, Uint32 *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetSurfaceColorMod,(SDL_Surface *a, Uint8 *b, Uint8 *c, Uint8 *d),(a,b,c,d),return)
-SDL_DYNAPI_PROC(int,SDL_GetSurfaceColorspace,(SDL_Surface *a, SDL_Colorspace *b),(a,b),return)
+SDL_DYNAPI_PROC(SDL_Colorspace,SDL_GetSurfaceColorspace,(SDL_Surface *a),(a),return)
+SDL_DYNAPI_PROC(SDL_Palette*,SDL_GetSurfacePalette,(SDL_Surface *a),(a),return)
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetSurfaceProperties,(SDL_Surface *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetSystemRAM,(void),(),return)
SDL_DYNAPI_PROC(SDL_SystemTheme,SDL_GetSystemTheme,(void),(),return)
@@ -602,8 +601,8 @@ SDL_DYNAPI_PROC(int,SDL_LockSurface,(SDL_Surface *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_LockTexture,(SDL_Texture *a, const SDL_Rect *b, void **c, int *d),(a,b,c,d),return)
SDL_DYNAPI_PROC(int,SDL_LockTextureToSurface,(SDL_Texture *a, const SDL_Rect *b, SDL_Surface **c),(a,b,c),return)
SDL_DYNAPI_PROC(void,SDL_LogMessageV,(int a, SDL_LogPriority b, SDL_PRINTF_FORMAT_STRING const char *c, va_list d),(a,b,c,d),)
-SDL_DYNAPI_PROC(Uint32,SDL_MapRGB,(const SDL_PixelFormat *a, Uint8 b, Uint8 c, Uint8 d),(a,b,c,d),return)
-SDL_DYNAPI_PROC(Uint32,SDL_MapRGBA,(const SDL_PixelFormat *a, Uint8 b, Uint8 c, Uint8 d, Uint8 e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(Uint32,SDL_MapRGB,(SDL_PixelFormat a, SDL_Palette *b, Uint8 c, Uint8 d, Uint8 e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(Uint32,SDL_MapRGBA,(SDL_PixelFormat a, SDL_Palette *b, Uint8 c, Uint8 d, Uint8 e, Uint8 f),(a,b,c,d,e,f),return)
SDL_DYNAPI_PROC(int,SDL_MaximizeWindow,(SDL_Window *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_MemoryBarrierAcquireFunction,(void),(),)
SDL_DYNAPI_PROC(void,SDL_MemoryBarrierReleaseFunction,(void),(),)
@@ -643,7 +642,7 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_PenConnected,(SDL_PenID a),(a),return)
SDL_DYNAPI_PROC(int,SDL_PlayHapticRumble,(SDL_Haptic *a, float b, Uint32 c),(a,b,c),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_PollEvent,(SDL_Event *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_PostSemaphore,(SDL_Semaphore *a),(a),return)
-SDL_DYNAPI_PROC(int,SDL_PremultiplyAlpha,(int a, int b, SDL_PixelFormatEnum c, const void *d, int e, SDL_PixelFormatEnum f, void *g, int h),(a,b,c,d,e,f,g,h),return)
+SDL_DYNAPI_PROC(int,SDL_PremultiplyAlpha,(int a, int b, SDL_PixelFormat c, const void *d, int e, SDL_PixelFormat f, void *g, int h),(a,b,c,d,e,f,g,h),return)
SDL_DYNAPI_PROC(void,SDL_PumpEvents,(void),(),)
SDL_DYNAPI_PROC(int,SDL_PushEvent,(SDL_Event *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_PutAudioStreamData,(SDL_AudioStream *a, const void *b, int c),(a,b,c),return)
@@ -759,7 +758,6 @@ SDL_DYNAPI_PROC(int,SDL_SetMemoryFunctions,(SDL_malloc_func a, SDL_calloc_func b
SDL_DYNAPI_PROC(void,SDL_SetModState,(SDL_Keymod a),(a),)
SDL_DYNAPI_PROC(int,SDL_SetNumberProperty,(SDL_PropertiesID a, const char *b, Sint64 c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_SetPaletteColors,(SDL_Palette *a, const SDL_Color *b, int c, int d),(a,b,c,d),return)
-SDL_DYNAPI_PROC(int,SDL_SetPixelFormatPalette,(SDL_PixelFormat *a, SDL_Palette *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_SetPrimarySelectionText,(const char *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_SetProperty,(SDL_PropertiesID a, const char *b, void *c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_SetPropertyWithCleanup,(SDL_PropertiesID a, const char *b, void *c, SDL_CleanupPropertyCallback d, void *e),(a,b,c,d,e),return)
@@ -783,7 +781,7 @@ SDL_DYNAPI_PROC(int,SDL_SetSurfaceColorKey,(SDL_Surface *a, int b, Uint32 c),(a,
SDL_DYNAPI_PROC(int,SDL_SetSurfaceColorMod,(SDL_Surface *a, Uint8 b, Uint8 c, Uint8 d),(a,b,c,d),return)
SDL_DYNAPI_PROC(int,SDL_SetSurfaceColorspace,(SDL_Surface *a, SDL_Colorspace b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_SetSurfacePalette,(SDL_Surface *a, SDL_Palette *b),(a,b),return)
-SDL_DYNAPI_PROC(int,SDL_SetSurfaceRLE,(SDL_Surface *a, int b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_SetSurfaceRLE,(SDL_Surface *a, SDL_bool b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_SetTLS,(SDL_TLSID a, const void *b, SDL_TLSDestructorCallback c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_SetTextInputArea,(SDL_Window *a, const SDL_Rect *b, int c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_SetTextureAlphaMod,(SDL_Texture *a, Uint8 b),(a,b),return)
diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c
index 13ef1e9a93b7b7..d7959f8774dcb3 100644
--- a/src/events/SDL_mouse.c
+++ b/src/events/SDL_mouse.c
@@ -1493,8 +1493,8 @@ SDL_Cursor *SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y)
return NULL;
}
- if (surface->format->format != SDL_PIXELFORMAT_ARGB8888) {
- temp = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ARGB8888);
+ if (surface->format != SDL_PIXELFORMAT_ARGB8888) {
+ temp = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_ARGB8888);
if (!temp) {
return NULL;
}
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index b880f6fba5f833..a35b9e554aa9c0 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -142,9 +142,9 @@ void SDL_QuitRender(void)
}
}
-int SDL_AddSupportedTextureFormat(SDL_Renderer *renderer, SDL_PixelFormatEnum format)
+int SDL_AddSupportedTextureFormat(SDL_Renderer *renderer, SDL_PixelFormat format)
{
- SDL_PixelFormatEnum *texture_formats = (SDL_PixelFormatEnum *)SDL_realloc((void *)renderer->texture_formats, (renderer->num_texture_formats + 2) * sizeof(SDL_PixelFormatEnum));
+ SDL_PixelFormat *texture_formats = (SDL_PixelFormat *)SDL_realloc((void *)renderer->texture_formats, (renderer->num_texture_formats + 2) * sizeof(SDL_PixelFormat));
if (!texture_formats) {
return -1;
}
@@ -1244,7 +1244,7 @@ static SDL_bool IsSupportedBlendMode(SDL_Renderer *renderer, SDL_BlendMode blend
}
}
-static SDL_bool IsSupportedFormat(SDL_Renderer *renderer, SDL_PixelFormatEnum format)
+static SDL_bool IsSupportedFormat(SDL_Renderer *renderer, SDL_PixelFormat format)
{
int i;
@@ -1256,7 +1256,7 @@ static SDL_bool IsSupportedFormat(SDL_Renderer *renderer, SDL_PixelFormatEnum fo
return SDL_FALSE;
}
-static Uint32 GetClosestSupportedFormat(SDL_Renderer *renderer, SDL_PixelFormatEnum format)
+static Uint32 GetClosestSupportedFormat(SDL_Renderer *renderer, SDL_PixelFormat format)
{
int i;
@@ -1297,7 +1297,7 @@ static Uint32 GetClosestSupportedFormat(SDL_Renderer *renderer, SDL_PixelFormatE
SDL_Texture *SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_PropertiesID props)
{
SDL_Texture *texture;
- SDL_PixelFormatEnum format = (SDL_PixelFormatEnum)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER, SDL_PIXELFORMAT_UNKNOWN);
+ SDL_PixelFormat format = (SDL_PixelFormat)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER, SDL_PIXELFORMAT_UNKNOWN);
int access = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_ACCESS_NUMBER, SDL_TEXTUREACCESS_STATIC);
int w = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_WIDTH_NUMBER, 0);
int h = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_HEIGHT_NUMBER, 0);
@@ -1451,7 +1451,7 @@ SDL_Texture *SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_Propert
return texture;
}
-SDL_Texture *SDL_CreateTexture(SDL_Renderer *renderer, SDL_PixelFormatEnum format, int access, int w, int h)
+SDL_Texture *SDL_CreateTexture(SDL_Renderer *renderer, SDL_PixelFormat format, int access, int w, int h)
{
SDL_Texture *texture;
SDL_PropertiesID props = SDL_CreateProperties();
@@ -1466,56 +1466,53 @@ SDL_Texture *SDL_CreateTexture(SDL_Renderer *renderer, SDL_PixelFormatEnum forma
SDL_Texture *SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *surface)
{
- const SDL_PixelFormat *fmt;
SDL_bool needAlpha;
SDL_bool direct_update;
int i;
- SDL_PixelFormatEnum format = SDL_PIXELFORMAT_UNKNOWN;
+ SDL_PixelFormat format = SDL_PIXELFORMAT_UNKNOWN;
+ SDL_Palette *palette;
SDL_Texture *texture;
- SDL_PropertiesID surface_props, props;
+ SDL_PropertiesID props;
SDL_Colorspace surface_colorspace = SDL_COLORSPACE_UNKNOWN;
SDL_Colorspace texture_colorspace = SDL_COLORSPACE_UNKNOWN;
CHECK_RENDERER_MAGIC(renderer, NULL);
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
SDL_InvalidParamError("SDL_CreateTextureFromSurface(): surface");
return NULL;
}
/* See what the best texture format is */
- fmt = surface->format;
- if (fmt->Amask || SDL_SurfaceHasColorKey(surface)) {
+ if (SDL_ISPIXELFORMAT_ALPHA(surface->format) || SDL_SurfaceHasColorKey(surface)) {
needAlpha = SDL_TRUE;
} else {
needAlpha = SDL_FALSE;
}
/* If Palette contains alpha values, promotes to alpha format */
- if (fmt->palette) {
+ palette = SDL_GetSurfacePalette(surface);
+ if (palette) {
SDL_bool is_opaque, has_alpha_channel;
- SDL_DetectPalette(fmt->palette, &is_opaque, &has_alpha_channel);
+ SDL_DetectPalette(palette, &is_opaque, &has_alpha_channel);
if (!is_opaque) {
needAlpha = SDL_TRUE;
}
}
- if (SDL_GetSurfaceColorspace(surface, &surface_colorspace) < 0) {
- return NULL;
- }
- texture_colorspace = surface_colorspace;
+ texture_colorspace = SDL_GetSurfaceColorspace(surface);
/* Try to have the best pixel format for the texture */
/* No alpha, but a colorkey => promote to alpha */
- if (!fmt->Amask && SDL_SurfaceHasColorKey(surface)) {
- if (fmt->format == SDL_PIXELFORMAT_XRGB8888) {
+ if (!SDL_ISPIXELFORMAT_ALPHA(surface->format) && SDL_SurfaceHasColorKey(surface)) {
+ if (surface->format == SDL_PIXELFORMAT_XRGB8888) {
for (i = 0; i < renderer->num_texture_formats; ++i) {
if (renderer->texture_formats[i] == SDL_PIXELFORMAT_ARGB8888) {
format = SDL_PIXELFORMAT_ARGB8888;
break;
}
}
- } else if (fmt->format == SDL_PIXELFORMAT_XBGR8888) {
+ } else if (surface->format == SDL_PIXELFORMAT_XBGR8888) {
for (i = 0; i < renderer->num_texture_formats; ++i) {
if (renderer->texture_formats[i] == SDL_PIXELFORMAT_ABGR8888) {
format = SDL_PIXELFORMAT_ABGR8888;
@@ -1526,15 +1523,15 @@ SDL_Texture *SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *s
} else {
/* Exact match would be fine */
for (i = 0; i < renderer->num_texture_formats; ++i) {
- if (renderer->texture_formats[i] == fmt->format) {
- format = fmt->format;
+ if (renderer->texture_formats[i] == surface->format) {
+ format = surface->format;
break;
}
}
}
/* Look for 10-bit pixel formats if needed */
- if (format == SDL_PIXELFORMAT_UNKNOWN && SDL_ISPIXELFORMAT_10BIT(fmt->format)) {
+ if (format == SDL_PIXELFORMAT_UNKNOWN && SDL_ISPIXELFORMAT_10BIT(surface->format)) {
for (i = 0; i < renderer->num_texture_formats; ++i) {
if (SDL_ISPIXELFORMAT_10BIT(renderer->texture_formats[i])) {
format = renderer->texture_formats[i];
@@ -1545,7 +1542,7 @@ SDL_Texture *SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *s
/* Look for floating point pixel formats if needed */
if (format == SDL_PIXELFORMAT_UNKNOWN &&
- (SDL_ISPIXELFORMAT_10BIT(fmt->format) || SDL_ISPIXELFORMAT_FLOAT(fmt->format))) {
+ (SDL_ISPIXELFORMAT_10BIT(surface->format) || SDL_ISPIXELFORMAT_FLOAT(surface->format))) {
for (i = 0; i < renderer->num_texture_formats; ++i) {
if (SDL_ISPIXELFORMAT_FLOAT(renderer->texture_formats[i])) {
format = renderer->texture_formats[i];
@@ -1577,8 +1574,8 @@ SDL_Texture *SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *s
}
}
- if (format == surface->format->format && texture_colorspace == surface_colorspace) {
- if (surface->format->Amask && SDL_SurfaceHasColorKey(surface)) {
+ if (format == surface->format && texture_colorspace == surface_colorspace) {
+ if (SDL_ISPIXELFORMAT_ALPHA(surface->format) && SDL_SurfaceHasColorKey(surface)) {
/* Surface and Renderer formats are identical.
* Intermediate conversion is needed to convert color key to alpha (SDL_ConvertColorkeyToAlpha()). */
direct_update = SDL_FALSE;
@@ -1591,12 +1588,6 @@ SDL_Texture *SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *s
direct_update = SDL_FALSE;
}
- if (surface->flags & SDL_SURFACE_USES_PROPERTIES) {
- surface_props = SDL_GetSurfaceProperties(surface);
- } else {
- surface_props = 0;
- }
-
props = SDL_CreateProperties();
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_COLORSPACE_NUMBER, texture_colorspace);
if (surface_colorspace == texture_colorspace) {
@@ -1627,7 +1618,7 @@ SDL_Texture *SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *s
SDL_Surface *temp = NULL;
/* Set up a destination surface for the texture update */
- temp = SDL_ConvertSurfaceFormatAndColorspace(surface, format, texture_colorspace, surface_props);
+ temp = SDL_ConvertSurfaceAndColorspace(surface, format, texture_colorspace, surface->internal->props);
if (temp) {
SDL_UpdateTexture(texture, NULL, temp->pixels, temp->pitch);
SDL_DestroySurface(temp);
@@ -2283,7 +2274,7 @@ int SDL_LockTextureToSurface(SDL_Texture *texture, const SDL_Rect *rect, SDL_Sur
return ret;
}
- texture->locked_surface = SDL_CreateSurfaceFrom(pixels, real_rect.w, real_rect.h, pitch, texture->format);
+ texture->locked_surface = SDL_CreateSurfaceFrom(real_rect.w, real_rect.h, texture->format, pixels, pitch);
if (!texture->locked_surface) {
SDL_UnlockTexture(texture);
return -1;
diff --git a/src/render/SDL_sysrender.h b/src/render/SDL_sysrender.h
index 8d7cb758e36744..a33791d8de8ca5 100644
--- a/src/render/SDL_sysrender.h
+++ b/src/render/SDL_sysrender.h
@@ -65,7 +65,7 @@ struct SDL_Texture
SDL_Colorspace colorspace; /**< The colorspace of the texture */
float SDR_white_point; /**< The SDR white point for this content */
float HDR_headroom; /**< The HDR headroom needed by this content */
- SDL_PixelFormatEnum format; /**< The pixel format of the texture */
+ SDL_PixelFormat format; /**< The pixel format of the texture */
int access; /**< SDL_TextureAccess */
int w; /**< The width of the texture */
int h; /**< The height of the texture */
@@ -217,7 +217,7 @@ struct SDL_Renderer
/* The current renderer info */
const char *name;
- SDL_PixelFormatEnum *texture_formats;
+ SDL_PixelFormat *texture_formats;
int num_texture_formats;
SDL_bool software;
@@ -320,7 +320,7 @@ extern SDL_RenderDriver VITA_GXM_RenderDriver;
extern void SDL_QuitRender(void);
/* Add a supported texture format to a renderer */
-extern int SDL_AddSupportedTextureFormat(SDL_Renderer *renderer, SDL_PixelFormatEnum format);
+extern int SDL_AddSupportedTextureFormat(SDL_Renderer *renderer, SDL_PixelFormat format);
/* Setup colorspace conversion */
extern void SDL_SetupRendererColorspace(SDL_Renderer *renderer, SDL_PropertiesID props);
diff --git a/src/render/SDL_yuv_sw.c b/src/render/SDL_yuv_sw.c
index 8fa532d895ae7b..7f8091eaab3457 100644
--- a/src/render/SDL_yuv_sw.c
+++ b/src/render/SDL_yuv_sw.c
@@ -27,7 +27,7 @@
#include "SDL_yuv_sw_c.h"
#include "../video/SDL_yuv_c.h"
-SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(SDL_PixelFormatEnum format, int w, int h)
+SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(SDL_PixelFormat format, int w, int h)
{
SDL_SW_YUVTexture *swdata;
@@ -336,7 +336,7 @@ void SDL_SW_UnlockYUVTexture(SDL_SW_YUVTexture *swdata)
}
int SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture *swdata, const SDL_Rect *srcrect,
- SDL_PixelFormatEnum target_format, int w, int h, void *pixels,
+ SDL_PixelFormat target_format, int w, int h, void *pixels,
int pitch)
{
int stretch;
@@ -365,7 +365,7 @@ int SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture *swdata, const SDL_Rect *srcrect,
swdata->display->pixels = pixels;
swdata->display->pitch = pitch;
} else {
- swdata->display = SDL_CreateSurfaceFrom(pixels, w, h, pitch, target_format);
+ swdata->display = SDL_CreateSurfaceFrom(w, h, target_format, pixels, pitch);
if (!swdata->display) {
return -1;
}
diff --git a/src/render/SDL_yuv_sw_c.h b/src/render/SDL_yuv_sw_c.h
index 25972d4ca57426..5d2830ada64f89 100644
--- a/src/render/SDL_yuv_sw_c.h
+++ b/src/render/SDL_yuv_sw_c.h
@@ -28,8 +28,8 @@
struct SDL_SW_YUVTexture
{
- SDL_PixelFormatEnum format;
- SDL_PixelFormatEnum target_format;
+ SDL_PixelFormat format;
+ SDL_PixelFormat target_format;
int w, h;
Uint8 *pixels;
@@ -44,7 +44,7 @@ struct SDL_SW_YUVTexture
typedef struct SDL_SW_YUVTexture SDL_SW_YUVTexture;
-SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(SDL_PixelFormatEnum format, int w, int h);
+SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(SDL_PixelFormat 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,
@@ -60,7 +60,7 @@ int SDL_SW_LockYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect,
void **pixels, int *pitch);
void SDL_SW_UnlockYUVTexture(SDL_SW_YUVTexture *swdata);
int SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture *swdata, const SDL_Rect *srcrect,
- SDL_PixelFormatEnum target_format, int w, int h, void *pixels,
+ SDL_PixelFormat target_format, int w, int h, void *pixels,
int pitch);
void SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture *swdata);
diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c
index b5cf4513d78c74..33fb54e65b0917 100644
--- a/src/render/direct3d/SDL_render_d3d.c
+++ b/src/render/direct3d/SDL_render_d3d.c
@@ -209,7 +209,7 @@ static D3DFORMAT PixelFormatToD3DFMT(Uint32 format)
}
}
-static SDL_PixelFormatEnum D3DFMTToPixelFormat(D3DFORMAT format)
+static SDL_PixelFormat D3DFMTToPixelFormat(D3DFORMAT format)
{
switch (format) {
case D3DFMT_R5G6B5:
diff --git a/src/render/direct3d11/SDL_render_d3d11.c b/src/render/direct3d11/SDL_render_d3d11.c
index 42ae0be1ee17af..07ae882169c552 100644
--- a/src/render/direct3d11/SDL_render_d3d11.c
+++ b/src/render/direct3d11/SDL_render_d3d11.c
@@ -244,7 +244,7 @@ static const GUID SDL_DXGI_DEBUG_ALL = { 0xe48ae283, 0xda80, 0x490b, { 0x87, 0xe
#pragma GCC diagnostic pop
#endif
-SDL_PixelFormatEnum D3D11_DXGIFormatToSDLPixelFormat(DXGI_FORMAT dxgiFormat)
+SDL_PixelFormat D3D11_DXGIFormatToSDLPixelFormat(DXGI_FORMAT dxgiFormat)
{
switch (dxgiFormat) {
case DXGI_FORMAT_B8G8R8A8_UNORM:
diff --git a/src/render/direct3d12/SDL_render_d3d12.c b/src/render/direct3d12/SDL_render_d3d12.c
index c8340cc15853a0..a37834a9a802ce 100644
--- a/src/render/direct3d12/SDL_render_d3d12.c
+++ b/src/render/direct3d12/SDL_render_d3d12.c
@@ -361,7 +361,7 @@ static UINT D3D12_Align(UINT location, UINT alignment)
return (location + (alignment - 1)) & ~(alignment - 1);
}
-static SDL_PixelFormatEnum D3D12_DXGIFormatToSDLPixelFormat(DXGI_FORMAT dxgiFormat)
+static SDL_PixelFormat D3D12_DXGIFormatToSDLPixelFormat(DXGI_FORMAT dxgiFormat)
{
switch (dxgiFormat) {
case DXGI_FORMAT_B8G8R8A8_UNORM:
diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c
index 5f09a2dec726e2..6c6399ddcf14ce 100644
--- a/src/render/opengl/SDL_render_gl.c
+++ b/src/render/opengl/SDL_render_gl.c
@@ -1450,7 +1450,7 @@ static int GL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
static SDL_Surface *GL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect)
{
GL_RenderData *data = (GL_RenderData *)renderer->driverdata;
- SDL_PixelFormatEnum format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ARGB8888;
+ SDL_PixelFormat format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ARGB8888;
GLint internalFormat;
GLenum targetFormat, type;
int w, h;
diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c
index 5be26b1763dc70..cdfa9faed7cbc8 100644
--- a/src/render/opengles2/SDL_render_gles2.c
+++ b/src/render/opengles2/SDL_render_gles2.c
@@ -1966,7 +1966,7 @@ static void GLES2_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
static SDL_Surface *GLES2_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect)
{
GLES2_RenderData *data = (GLES2_RenderData *)renderer->driverdata;
- SDL_PixelFormatEnum format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_RGBA32;
+ SDL_PixelFormat format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_RGBA32;
int w, h;
SDL_Surface *surface;
diff --git a/src/render/software/SDL_blendfillrect.c b/src/render/software/SDL_blendfillrect.c
index 6ea4821eb0a096..45c32f96bda5a5 100644
--- a/src/render/software/SDL_blendfillrect.c
+++ b/src/render/software/SDL_blendfillrect.c
@@ -128,7 +128,7 @@ static int SDL_BlendFillRect_ARGB8888(SDL_Surface *dst, const SDL_Rect *rect,
static int SDL_BlendFillRect_RGB(SDL_Surface *dst, const SDL_Rect *rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
- SDL_PixelFormat *fmt = dst->format;
+ const SDL_PixelFormatDetails *fmt = dst->internal->format;
unsigned inva = 0xff - a;
switch (fmt->bytes_per_pixel) {
@@ -178,7 +178,7 @@ static int SDL_BlendFillRect_RGB(SDL_Surface *dst, const SDL_Rect *rect,
static int SDL_BlendFillRect_RGBA(SDL_Surface *dst, const SDL_Rect *rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
- SDL_PixelFormat *fmt = dst->format;
+ const SDL_PixelFormatDetails *fmt = dst->internal->format;
unsigned inva = 0xff - a;
switch (fmt->bytes_per_pixel) {
@@ -211,24 +211,24 @@ int SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect,
{
SDL_Rect clipped;
- if (!dst) {
+ if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_BlendFillRect(): dst");
}
/* This function doesn't work on surfaces < 8 bpp */
- if (dst->format->bits_per_pixel < 8) {
+ if (SDL_BITSPERPIXEL(dst->format) < 8) {
return SDL_SetError("SDL_BlendFillRect(): Unsupported surface format");
}
/* If 'rect' == NULL, then fill the whole surface */
if (rect) {
/* Perform clipping */
- if (!SDL_GetRectIntersection(rect, &dst->clip_rect, &clipped)) {
+ if (!SDL_GetRectIntersection(rect, &dst->internal->clip_rect, &clipped)) {
return 0;
}
rect = &clipped;
} else {
- rect = &dst->clip_rect;
+ rect = &dst->internal->clip_rect;
}
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
@@ -237,23 +237,23 @@ int SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect,
b = DRAW_MUL(b, a);
}
- switch (dst->format->bits_per_pixel) {
+ switch (dst->internal->format->bits_per_pixel) {
case 15:
- switch (dst->format->Rmask) {
+ switch (dst->internal->format->Rmask) {
case 0x7C00:
return SDL_BlendFillRect_RGB555(dst, rect, blendMode, r, g, b, a);
}
break;
case 16:
- switch (dst->format->Rmask) {
+ switch (dst->internal->format->Rmask) {
case 0xF800:
return SDL_BlendFillRect_RGB565(dst, rect, blendMode, r, g, b, a);
}
break;
case 32:
- switch (dst->format->Rmask) {
+ switch (dst->internal->format->Rmask) {
case 0x00FF0000:
- if (!dst->format->Amask) {
+ if (!dst->internal->format->Amask) {
return SDL_BlendFillRect_XRGB8888(dst, rect, blendMode, r, g, b, a);
} else {
return SDL_BlendFillRect_ARGB8888(dst, rect, blendMode, r, g, b, a);
@@ -265,7 +265,7 @@ int SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect,
break;
}
- if (!dst->format->Amask) {
+ if (!dst->internal->format->Amask) {
return SDL_BlendFillRect_RGB(dst, rect, blendMode, r, g, b, a);
} else {
return SDL_BlendFillRect_RGBA(dst, rect, blendMode, r, g, b, a);
@@ -281,12 +281,12 @@ int SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
int status = 0;
- if (!dst) {
+ if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_BlendFillRects(): dst");
}
/* This function doesn't work on surfaces < 8 bpp */
- if (dst->format->bits_per_pixel < 8) {
+ if (dst->internal->format->bits_per_pixel < 8) {
return SDL_SetError("SDL_BlendFillRects(): Unsupported surface format");
}
@@ -297,23 +297,23 @@ int SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
}
/* FIXME: Does this function pointer slow things down significantly? */
- switch (dst->format->bits_per_pixel) {
+ switch (dst->internal->format->bits_per_pixel) {
case 15:
- switch (dst->format->Rmask) {
+ switch (dst->internal->format->Rmask) {
case 0x7C00:
func = SDL_BlendFillRect_RGB555;
}
break;
case 16:
- switch (dst->format->Rmask) {
+ switch (dst->internal->format->Rmask) {
case 0xF800:
func = SDL_BlendFillRect_RGB565;
}
break;
case 32:
- switch (dst->format->Rmask) {
+ switch (dst->internal->format->Rmask) {
case 0x00FF0000:
- if (!dst->format->Amask) {
+ if (!dst->internal->format->Amask) {
func = SDL_BlendFillRect_XRGB8888;
} else {
func = SDL_BlendFillRect_ARGB8888;
@@ -326,7 +326,7 @@ int SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
}
if (!func) {
- if (!dst->format->Amask) {
+ if (!dst->internal->format->Amask) {
func = SDL_BlendFillRect_RGB;
} else {
func = SDL_BlendFillRect_RGBA;
@@ -335,7 +335,7 @@ int SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
for (i = 0; i < count; ++i) {
/* Perform clipping */
- if (!SDL_GetRectIntersection(&rects[i], &dst->clip_rect, &rect)) {
+ if (!SDL_GetRectIntersection(&rects[i], &dst->internal->clip_rect, &rect)) {
continue;
}
status = func(dst, &rect, blendMode, r, g, b, a);
diff --git a/src/render/software/SDL_blendline.c b/src/render/software/SDL_blendline.c
index f3371576540be3..4098280797c3b5 100644
--- a/src/render/software/SDL_blendline.c
+++ b/src/render/software/SDL_blendline.c
@@ -30,7 +30,7 @@ static void SDL_BlendLine_RGB2(SDL_Surface *dst, int x1, int y1, int x2, int y2,
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
SDL_bool draw_end)
{
- const SDL_PixelFormat *fmt = dst->format;
+ const SDL_PixelFormatDetails *fmt = dst->internal->format;
unsigned r, g, b, a, inva;
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
@@ -343,7 +343,7 @@ static void SDL_BlendLine_RGB4(SDL_Surface *dst, int x1, int y1, int x2, int y2,
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
SDL_bool draw_end)
{
- const SDL_PixelFormat *fmt = dst->format;
+ const SDL_PixelFormatDetails *fmt = dst->internal->format;
unsigned r, g, b, a, inva;
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
@@ -448,7 +448,7 @@ static void SDL_BlendLine_RGBA4(SDL_Surface *dst, int x1, int y1, int x2, int y2
SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
SDL_bool draw_end)
{
- const SDL_PixelFormat *fmt = dst->format;
+ const SDL_PixelFormatDetails *fmt = dst->internal->format;
unsigned r, g, b, a, inva;
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
@@ -763,7 +763,7 @@ typedef void (*BlendLineFunc)(SDL_Surface *dst,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
SDL_bool draw_end);
-static BlendLineFunc SDL_CalculateBlendLineFunc(const SDL_PixelFormat *fmt)
+static BlendLineFunc SDL_CalculateBlendLineFunc(const SDL_PixelFormatDetails *fmt)
{
switch (fmt->bytes_per_pixel) {
case 2:
@@ -798,18 +798,18 @@ int SDL_BlendLine(SDL_Surface *dst, int x1, int y1, int x2, int y2,
{
BlendLineFunc func;
- if (!dst) {
+ if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_BlendLine(): dst");
}
- func = SDL_CalculateBlendLineFunc(dst->format);
+ func = SDL_CalculateBlendLineFunc(dst->internal->format);
if (!func) {
return SDL_SetError("SDL_BlendLine(): Unsupported surface format");
}
/* Perform clipping */
/* FIXME: We don't actually want to clip, as it may change line slope */
- if (!SDL_GetRectAndLineIntersection(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
+ if (!SDL_GetRectAndLineIntersection(&dst->internal->clip_rect, &x1, &y1, &x2, &y2)) {
return 0;
}
@@ -826,11 +826,11 @@ int SDL_BlendLines(SDL_Surface *dst, const SDL_Point *points, int count,
SDL_bool draw_end;
BlendLineFunc func;
- if (!dst) {
+ if (!SDL_SurfaceValid(dst)) {
return SDL_SetError("SDL_BlendLines(): Passed NULL destination surface");
}
- func = SDL_CalculateBlendLineFunc(dst->format);
+ func = SDL_CalculateBlendLineFunc(dst->internal->format);
if (!func) {
return SDL_SetError("SDL_BlendLines(): Unsupported surface format");
}
@@ -843,7 +843,7 @@ int SDL_BlendLines(SDL_Surface *dst, const SDL_Point *points, int count,
/* Perform clipping */
/* FIXME: We don't actually want to clip, as it may change line slope */
- if (!SDL_GetRectAndLineIntersection(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
+ if (!SDL_GetRectAndLineIntersection(&dst->internal->clip_rect, &x1, &y1, &x2, &y2)) {
continue;
}
diff --git a/src/render/software/SDL_blendpoint.c b/src/render/software/SDL_blendpoint.c
index 3435f43dfb1836..db325ab94a3f91 100644
--- a/src/render/software/SDL_blendpoint.c
+++ b/src/render/software/SDL_blendpoint.c
@@ -128,7 +128,7 @@ static int SDL_BlendPoint_ARGB8888(SDL_Surface *dst, int x, int y, SDL_BlendMode
static int SDL_BlendPoint_RGB(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
{
- SDL_PixelFormat *fmt = dst->format;
+ const SDL_PixelFormatDetails *fmt = dst->internal->format;
unsigned inva = 0xff - a;
switch (fmt->bytes_per_pixel) {
@@ -178,7 +178,7 @@ static int SDL_BlendPoint_RGB(SDL_Surface *dst, int x, int y, SDL_BlendMode blen
static int SDL_BlendPoint_RGBA(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
{
- SDL_PixelFormat *fmt = dst->format;
+ const SDL_PixelFormatDetails *fmt = dst->internal->format;
unsigned inva = 0xff - a;
switch (fmt->bytes_per_pixel) {
@@ -209,19 +209,19 @@ static int SDL_BlendPoint_RGBA(SDL_Surface *dst, int x, int y, SDL_BlendMode ble
int SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
{
- if (!dst) {
+ if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_BlendPoint(): dst");
}
/* This function doesn't work on surfaces < 8 bpp */
- if (dst->format->bits_per_pixel < 8) {
+ if (SDL_BITSPERPIXEL(dst->format) < 8) {
return SDL_SetError("SDL_BlendPoint(): Unsupported surface format");
}
/* Perform clipping */
- if (x < dst->clip_rect.x || y < dst->clip_rect.y ||
- x >= (dst->clip_rect.x + dst->clip_rect.w) ||
- y >= (dst->clip_rect.y + dst->clip_rect.h)) {
+ if (x < dst->internal->clip_rect.x || y < dst->internal->clip_rect.y ||
+ x >= (dst->internal->clip_rect.x + dst->internal->clip_rect.w) ||
+ y >= (dst->internal->clip_rect.y + dst->internal->clip_rect.h)) {
return 0;
}
@@ -231,23 +231,23 @@ int SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint
b = DRAW_MUL(b, a);
}
- switch (dst->format->bits_per_pixel) {
+ switch (dst->internal->format->bits_per_pixel) {
case 15:
- switch (dst->format->Rmask) {
+ switch (dst->internal->format->Rmask) {
case 0x7C00:
return SDL_BlendPoint_RGB555(dst, x, y, blendMode, r, g, b, a);
}
break;
case 16:
- switch (dst->format->Rmask) {
+ switch (dst->internal->format->Rmask) {
case 0xF800:
return SDL_BlendPoint_RGB565(dst, x, y, blendMode, r, g, b, a);
}
break;
case 32:
- switch (dst->format->Rmask) {
+ switch (dst->internal->format->Rmask) {
case 0x00FF0000:
- if (!dst->format->Amask) {
+ if (!dst->internal->format->Amask) {
return SDL_BlendPoint_XRGB8888(dst, x, y, blendMode, r, g, b, a);
} else {
return SDL_BlendPoint_ARGB8888(dst, x, y, blendMode, r, g, b, a);
@@ -259,7 +259,7 @@ int SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint
break;
}
- if (!dst->format->Amask) {
+ if (!dst->internal->format->Amask) {
return SDL_BlendPoint_RGB(dst, x, y, blendMode, r, g, b, a);
} else {
return SDL_BlendPoint_RGBA(dst, x, y, blendMode, r, g, b, a);
@@ -277,12 +277,12 @@ int SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
int status = 0;
- if (!dst) {
+ if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_BlendPoints(): dst");
}
/* This function doesn't work on surfaces < 8 bpp */
- if (dst->format->bits_per_pixel < 8) {
+ if (dst->internal->format->bits_per_pixel < 8) {
return SDL_SetError("SDL_BlendPoints(): Unsupported surface format");
}
@@ -293,25 +293,25 @@ int SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count,
}
/* FIXME: Does this function pointer slow things down significantly? */
- switch (dst->format->bits_per_pixel) {
+ switch (dst->internal->format->bits_per_pixel) {
case 15:
- switch (dst->format->Rmask) {
+ switch (dst->internal->format->Rmask) {
case 0x7C00:
func = SDL_BlendPoint_RGB555;
break;
}
break;
case 16:
- switch (dst->format->Rmask) {
+ switch (dst->internal->format->Rmask) {
case 0xF800:
func = SDL_BlendPoint_RGB565;
break;
}
break;
case 32:
- switch (dst->format->Rmask) {
+ switch (dst->internal->format->Rmask) {
case 0x00FF0000:
- if (!dst->format->Amask) {
+ if (!dst->internal->format->Amask) {
func = SDL_BlendPoint_XRGB8888;
} else {
func = SDL_BlendPoint_ARGB8888;
@@ -324,17 +324,17 @@ int SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count,
}
if (!func) {
- if (!dst->format->Amask) {
+ if (!dst->internal->format->Amask) {
func = SDL_BlendPoint_RGB;
} else {
func = SDL_BlendPoint_RGBA;
}
}
- minx = dst->clip_rect.x;
- maxx = dst->clip_rect.x + dst->clip_rect.w - 1;
- miny = dst->clip_rect.y;
- maxy = dst->clip_rect.y + dst->clip_rect.h - 1;
+ minx = dst->internal->clip_rect.x;
+ maxx = dst->internal->clip_rect.x + dst->internal->clip_rect.w - 1;
+ miny = dst->internal->clip_rect.y;
+ maxy = dst->internal->clip_rect.y + dst->internal->clip_rect.h - 1;
for (i = 0; i < count; ++i) {
x = points[i].x;
diff --git a/src/render/software/SDL_draw.h b/src/render/software/SDL_draw.h
index 6e3eb76b27ef39..56df78d3643209 100644
--- a/src/render/software/SDL_draw.h
+++ b/src/render/software/SDL_draw.h
@@ -364,7 +364,7 @@
#define HLINE(type, op, draw_end) \
{ \
int length; \
- int pitch = (dst->pitch / dst->format->bytes_per_pixel); \
+ int pitch = (dst->pitch / dst->internal->format->bytes_per_pixel); \
type *pixel; \
if (x1 <= x2) { \
pixel = (type *)dst->pixels + y1 * pitch + x1; \
@@ -386,7 +386,7 @@
#define VLINE(type, op, draw_end) \
{ \
int length; \
- int pitch = (dst->pitch / dst->format->bytes_per_pixel); \
+ int pitch = (dst->pitch / dst->internal->format->bytes_per_pixel); \
type *pixel; \
if (y1 <= y2) { \
pixel = (type *)dst->pixels + y1 * pitch + x1; \
@@ -408,7 +408,7 @@
#define DLINE(type, op, draw_end) \
{ \
int length; \
- int pitch = (dst->pitch / dst->format->bytes_per_pixel); \
+ int pitch = (dst->pitch / dst->internal->format->bytes_per_pixel); \
type *pixel; \
if (y1 <= y2) { \
pixel = (type *)dst->pixels + y1 * pitch + x1; \
@@ -628,7 +628,7 @@
do { \
int width = rect->w; \
int height = rect->h; \
- int pitch = (dst->pitch / dst->format->bytes_per_pixel); \
+ int pitch = (dst->pitch / dst->internal->format->bytes_per_pixel); \
int skip = pitch - width; \
type *pixel = (type *)dst->pixels + rect->y * pitch + rect->x; \
while (height--) { \
diff --git a/src/render/software/SDL_drawline.c b/src/render/software/SDL_drawline.c
index 06e099735262d2..78eb5801686027 100644
--- a/src/render/software/SDL_drawline.c
+++ b/src/render/software/SDL_drawline.c
@@ -31,7 +31,7 @@ static void SDL_DrawLine1(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint
{
if (y1 == y2) {
int length;
- int pitch = (dst->pitch / dst->format->bytes_per_pixel);
+ int pitch = (dst->pitch / dst->internal->format->bytes_per_pixel);
Uint8 *pixel;
if (x1 <= x2) {
pixel = (Uint8 *)dst->pixels + y1 * pitch + x1;
@@ -64,8 +64,8 @@ static void SDL_DrawLine2(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint
DLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
} else {
Uint8 _r, _g, _b, _a;
- const SDL_PixelFormat *fmt = dst->format;
- SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a);
+ const SDL_PixelFormatDetails *fmt = dst->internal->format;
+ SDL_GetRGBA(color, dst->format, dst->internal->palette, &_r, &_g, &_b, &_a);
if (fmt->Rmask == 0x7C00) {
AALINE(x1, y1, x2, y2,
DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY_BLEND_RGB555,
@@ -93,8 +93,8 @@ static void SDL_DrawLine4(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint
DLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
} else {
Uint8 _r, _g, _b, _a;
- const SDL_PixelFormat *fmt = dst->format;
- SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a);
+ const SDL_PixelFormatDetails *fmt = dst->internal->format;
+ SDL_GetRGBA(color, dst->format, dst->internal->palette, &_r, &_g, &_b, &_a);
if (fmt->Rmask == 0x00FF0000) {
if (!fmt->Amask) {
AALINE(x1, y1, x2, y2,
@@ -117,7 +117,7 @@ typedef void (*DrawLineFunc)(SDL_Surface *dst,
int x1, int y1, int x2, int y2,
Uint32 color, SDL_bool draw_end);
-static DrawLineFunc SDL_CalculateDrawLineFunc(const SDL_PixelFormat *fmt)
+static DrawLineFunc SDL_CalculateDrawLineFunc(const SDL_PixelFormatDetails *fmt)
{
switch (fmt->bytes_per_pixel) {
case 1:
@@ -137,18 +137,18 @@ int SDL_DrawLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color)
{
DrawLineFunc func;
- if (!dst) {
+ if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_DrawLine(): dst");
}
- func = SDL_CalculateDrawLineFunc(dst->format);
+ func = SDL_CalculateDrawLineFunc(dst->internal->format);
if (!func) {
return SDL_SetError("SDL_DrawLine(): Unsupported surface format");
}
/* Perform clipping */
/* FIXME: We don't actually want to clip, as it may change line slope */
- if (!SDL_GetRectAndLineIntersection(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
+ if (!SDL_GetRectAndLineIntersection(&dst->internal->clip_rect, &x1, &y1, &x2, &y2)) {
return 0;
}
@@ -165,11 +165,11 @@ int SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count,
SDL_bool draw_end;
DrawLineFunc func;
- if (!dst) {
+ if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_DrawLines(): dst");
}
- func = SDL_CalculateDrawLineFunc(dst->format);
+ func = SDL_CalculateDrawLineFunc(dst->internal->format);
if (!func) {
return SDL_SetError("SDL_DrawLines(): Unsupported surface format");
}
@@ -182,7 +182,7 @@ int SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count,
/* Perform clipping */
/* FIXME: We don't actually want to clip, as it may change line slope */
- if (!SDL_GetRectAndLineIntersection(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
+ if (!SDL_GetRectAndLineIntersection(&dst->internal->clip_rect, &x1, &y1, &x2, &y2)) {
continue;
}
diff --git a/src/render/software/SDL_drawpoint.c b/src/render/software/SDL_drawpoint.c
index fa272a8798d22b..89174487a44c81 100644
--- a/src/render/software/SDL_drawpoint.c
+++ b/src/render/software/SDL_drawpoint.c
@@ -27,23 +27,23 @@
int SDL_DrawPoint(SDL_Surface *dst, int x, int y, Uint32 color)
{
- if (!dst) {
+ if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_DrawPoint(): dst");
}
/* This function doesn't work on surfaces < 8 bpp */
- if (dst->format->bits_per_pixel < 8) {
+ if (dst->internal->format->bits_per_pixel < 8) {
return SDL_SetError("SDL_DrawPoint(): Unsupported surface format");
}
/* Perform clipping */
- if (x < dst->clip_rect.x || y < dst->clip_rect.y ||
- x >= (dst->clip_rect.x + dst->clip_rect.w) ||
- y >= (dst->clip_rect.y + dst->clip_rect.h)) {
+ if (x < dst->internal->clip_rect.x || y < dst->internal->clip_rect.y ||
+ x >= (dst->internal->clip_rect.x + dst->internal->clip_rect.w) ||
+ y >= (dst->internal->clip_rect.y + dst->internal->clip_rect.h)) {
return 0;
}
- switch (dst->format->bytes_per_pixel) {
+ switch (dst->internal->format->bytes_per_pixel) {
case 1:
DRAW_FASTSETPIXELXY1(x, y);
break;
@@ -67,19 +67,19 @@ int SDL_DrawPoints(SDL_Surface *dst, const SDL_Point *points, int count,
int i;
int x, y;
- if (!dst) {
+ if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_DrawPoints(): dst");
}
/* This function doesn't work on surfaces < 8 bpp */
- if (dst->format->bits_per_pixel < 8) {
+ if (dst->internal->format->bits_per_pixel < 8) {
return SDL_SetError("SDL_DrawPoints(): Unsupported surface format");
}
- minx = dst->clip_rect.x;
- maxx = dst->clip_rect.x + dst->clip_rect.w - 1;
- miny = dst->clip_rect.y;
- maxy = dst->clip_rect.y + dst->clip_rect.h - 1;
+ minx = dst->internal->clip_rect.x;
+ maxx = dst->internal->clip_rect.x + dst->internal->clip_rect.w - 1;
+ miny = dst->internal->clip_rect.y;
+ maxy = dst->internal->clip_rect.y + dst->internal->clip_rect.h - 1;
for (i = 0; i < count; ++i) {
x = points[i].x;
@@ -89,7 +89,7 @@ int SDL_DrawPoints(SDL_Surface *dst, const SDL_Point *points, int count,
continue;
}
- switch (dst->format->bytes_per_pixel) {
+ switch (dst->internal->format->bytes_per_pixel) {
case 1:
DRAW_FASTSETPIXELXY1(x, y);
break;
diff --git a/src/render/software/SDL_render_sw.c b/src/render/software/SDL_render_sw.c
index 17bddccf87150e..372c0d520d525c 100644
--- a/src/render/software/SDL_render_sw.c
+++ b/src/render/software/SDL_render_sw.c
@@ -104,7 +104,7 @@ static int SW_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Pr
SDL_Surface *surface = SDL_CreateSurface(texture->w, texture->h, texture->format);
Uint8 r, g, b, a;
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
return SDL_SetError("Cannot create surface");
}
texture->driverdata = surface;
@@ -119,7 +119,7 @@ static int SW_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Pr
/* Only RLE encode textures without an alpha channel since the RLE coder
* discards the color values of pixels with an alpha value of zero.
*/
- if (texture->access == SDL_TEXTUREACCESS_STATIC && !surface->format->Amask) {
+ if (texture->access == SDL_TEXTUREACCESS_STATIC && !SDL_ISPIXELFORMAT_ALPHA(surface->format)) {
SDL_SetSurfaceRLE(surface, 1);
}
@@ -140,8 +140,8 @@ static int SW_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
src = (Uint8 *)pixels;
dst = (Uint8 *)surface->pixels +
rect->y * surface->pitch +
- rect->x * surface->format->bytes_per_pixel;
- length = (size_t)rect->w * surface->format->bytes_per_pixel;
+ rect->x * surface->internal->format->bytes_per_pixel;
+ length = (size_t)rect->w * surface->internal->format->bytes_per_pixel;
for (row = 0; row < rect->h; ++row) {
SDL_memcpy(dst, src, length);
src += pitch;
@@ -160,7 +160,7 @@ static int SW_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
*pixels =
(void *)((Uint8 *)surface->pixels + rect->y * surface->pitch +
- rect->x * surface->format->bytes_per_pixel);
+ rect->x * surface->internal->format->bytes_per_pixel);
*pitch = surface->pitch;
return 0;
}
@@ -328,7 +328,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
int blitRequired = SDL_FALSE;
int isOpaque = SDL_FALSE;
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
return -1;
}
@@ -347,7 +347,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
/* Clone the source surface but use its pixel buffer directly.
* The original source surface must be treated as read-only.
*/
- src_clone = SDL_CreateSurfaceFrom(src->pixels, src->w, src->h, src->pitch, src->format->format);
+ src_clone = SDL_CreateSurfaceFrom(src->w, src->h, src->format, src->pixels, src->pitch);
if (!src_clone) {
if (SDL_MUSTLOCK(src)) {
SDL_UnlockSurface(src);
@@ -360,7 +360,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
SDL_GetSurfaceColorMod(src, &rMod, &gMod, &bMod);
/* SDLgfx_rotateSurface only accepts 32-bit surfaces with a 8888 layout. Everything else has to be converted. */
- if (src->format->bits_per_pixel != 32 || SDL_PIXELLAYOUT(src->format->format) != SDL_PACKEDLAYOUT_8888 || !src->format->Amask) {
+ if (src->internal->format->bits_per_pixel != 32 || SDL_PIXELLAYOUT(src->format) != SDL_PACKEDLAYOUT_8888 || !SDL_ISPIXELFORMAT_ALPHA(src->format)) {
blitRequired = SDL_TRUE;
}
@@ -382,7 +382,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
}
/* Opaque surfaces are much easier to handle with the NONE blend mode. */
- if (blendmode == SDL_BLENDMODE_NONE && !src->format->Amask && alphaMod == 255) {
+ if (blendmode == SDL_BLENDMODE_NONE && !SDL_ISPIXELFORMAT_ALPHA(src->format) && alphaMod == 255) {
isOpaque = SDL_TRUE;
}
@@ -482,15 +482,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
* mode modulates the colors with the alpha channel, a surface without an alpha mask needs
* to be created. This makes all source pixels opaque and the colors get copied correctly.
*/
- SDL_Surface *src_rotated_rgb;
- SDL_PixelFormatEnum f = SDL_GetPixelFormatEnumForMasks(src_rotated->format->bits_per_pixel,
- src_rotated->format->Rmask,
- src_rotated->format->Gmask,
- src_rotated->format->Bmask,
- 0);
-
- src_rotated_rgb = SDL_CreateSurfaceFrom(src_rotated->pixels, src_rotated->w, src_rotated->h,
- src_rotated->pitch, f);
+ SDL_Surface *src_rotated_rgb = SDL_CreateSurfaceFrom(src_rotated->w, src_rotated->h, src_rotated->format, src_rotated->pixels, src_rotated->pitch);
if (!src_rotated_rgb) {
retval = -1;
} else {
@@ -680,7 +672,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
SDL_Surface *surface = SW_ActivateRenderer(renderer);
SW_DrawStateCache drawstate;
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
return -1;
}
@@ -725,7 +717,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
const Uint8 a = (Uint8)SDL_roundf(SDL_clamp(cmd->data.color.color.a, 0.0f, 1.0f) * 255.0f);
/* By definition the clear ignores the clip rect */
SDL_SetSurfaceClipRect(surface, NULL);
- SDL_FillSurfaceRect(surface, NULL, SDL_MapRGBA(surface->format, r, g, b, a));
+ SDL_FillSurfaceRect(surface, NULL, SDL_MapRGBA(surface->format, surface->internal->palette, r, g, b, a));
drawstate.surface_cliprect_dirty = SDL_TRUE;
break;
}
@@ -751,7 +743,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
}
if (blend == SDL_BLENDMODE_NONE) {
- SDL_DrawPoints(surface, verts, count, SDL_MapRGBA(surface->format, r, g, b, a));
+ SDL_DrawPoints(surface, verts, count, SDL_MapRGBA(surface->format, surface->internal->palette, r, g, b, a));
} else {
SDL_BlendPoints(surface, verts, count, blend, r, g, b, a);
}
@@ -779,7 +771,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
}
if (blend == SDL_BLENDMODE_NONE) {
- SDL_DrawLines(surface, verts, count, SDL_MapRGBA(surface->format, r, g, b, a));
+ SDL_DrawLines(surface, verts, count, SDL_MapRGBA(surface->format, surface->internal->palette, r, g, b, a));
} else {
SDL_BlendLines(surface, verts, count, blend, r, g, b, a);
}
@@ -807,7 +799,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
}
if (blend == SDL_BLENDMODE_NONE) {
- SDL_FillSurfaceRects(surface, verts, count, SDL_MapRGBA(surface->format, r, g, b, a));
+ SDL_FillSurfaceRects(surface, verts, count, SDL_MapRGBA(surface->format, surface->internal->palette, r, g, b, a));
} else {
SDL_BlendFillRects(surface, verts, count, blend, r, g, b, a);
}
@@ -842,7 +834,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
/* Prevent to do scaling + clipping on viewport boundaries as it may lose proportion */
if (dstrect->x < 0 || dstrect->y < 0 || dstrect->x + dstrect->w > surface->w || dstrect->y + dstrect->h > surface->h) {
- SDL_Surface *tmp = SDL_CreateSurface(dstrect->w, dstrect->h, src->format->format);
+ SDL_Surface *tmp = SDL_CreateSurface(dstrect->w, dstrect->h, src->format);
/* Scale to an intermediate surface, then blit */
if (tmp) {
SDL_Rect r;
@@ -971,7 +963,7 @@ static SDL_Surface *SW_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *
SDL_Surface *surface = SW_ActivateRenderer(renderer);
void *pixels;
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
return NULL;
}
@@ -987,9 +979,9 @@ static SDL_Surface *SW_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *
pixels = (void *)((Uint8 *)surface->pixels +
rect->y * surface->pitch +
- rect->x * surface->format->bytes_per_pixel);
+ rect->x * surface->internal->format->bytes_per_pixel);
- return SDL_DuplicatePixels(rect->w, rect->h, surface->format->format, SDL_COLORSPACE_SRGB, pixels, surface->pitch);
+ return SDL_DuplicatePixels(rect->w, rect->h, surface->format, SDL_COLORSPACE_SRGB, pixels, surface->pitch);
}
static int SW_RenderPresent(SDL_Renderer *renderer)
@@ -1020,7 +1012,7 @@ static void SW_DestroyRenderer(SDL_Renderer *renderer)
SDL_free(data);
}
-static void SW_SelectBestFormats(SDL_Renderer *renderer, SDL_PixelFormatEnum format)
+static void SW_SelectBestFormats(SDL_Renderer *renderer, SDL_PixelFormat format)
{
/* Prefer the format used by the framebuffer by default. */
SDL_AddSupportedTextureFormat(renderer, format);
@@ -1119,7 +1111,7 @@ int SW_CreateRendererForSurface(SDL_Renderer *renderer, SDL_Surface *surface, SD
{
SW_RenderData *data;
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
return SDL_InvalidParamError("surface");
}
@@ -1160,7 +1152,7 @@ int SW_CreateRendererForSurface(SDL_Renderer *renderer, SDL_Surface *surface, SD
renderer->name = SW_RenderDriver.name;
- SW_SelectBestFormats(renderer, surface->format->format);
+ SW_SelectBestFormats(renderer, surface->format);
SDL_SetupRendererColorspace(renderer, create_props);
@@ -1193,7 +1185,7 @@ static int SW_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pro
SDL_SetHint(SDL_HINT_RENDER_VSYNC, "");
}
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
return -1;
}
diff --git a/src/render/software/SDL_rotate.c b/src/render/software/SDL_rotate.c
index 448cfa8dfa937f..69117150a6f923 100644
--- a/src/render/software/SDL_rotate.c
+++ b/src/render/software/SDL_rotate.c
@@ -36,11 +36,10 @@ Andreas Schiffler -- aschiffler at ferzkopp dot net
#include "../../core/windows/SDL_windows.h"
#endif
-#include
-#include
-
#include "SDL_rotate.h"
+#include "../../video/SDL_surface_c.h"
+
/* ---- Internally used structures */
/**
@@ -491,14 +490,13 @@ SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, in
{
SDL_Surface *rz_dst;
int is8bit, angle90;
- int i;
SDL_BlendMode blendmode;
Uint32 colorkey = 0;
int colorKeyAvailable = SDL_FALSE;
double sangleinv, cangleinv;
/* Sanity check */
- if (!src) {
+ if (!SDL_SurfaceValid(src)) {
return NULL;
}
@@ -508,8 +506,8 @@ SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, in
}
}
/* This function requires a 32-bit surface or 8-bit surface with a colorkey */
- is8bit = src->format->bits_per_pixel == 8 && colorKeyAvailable;
- if (!(is8bit || (src->format->bits_per_pixel == 32 && src->format->Amask))) {
+ is8bit = src->internal->format->bits_per_pixel == 8 && colorKeyAvailable;
+ if (!(is8bit || (src->internal->format->bits_per_pixel == 32 && SDL_ISPIXELFORMAT_ALPHA(src->format)))) {
return NULL;
}
@@ -521,18 +519,13 @@ SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, in
rz_dst = NULL;
if (is8bit) {
/* Target surface is 8 bit */
- rz_dst = SDL_CreateSurface(rect_dest->w, rect_dest->h + GUARD_ROWS, src->format->format);
+ rz_dst = SDL_CreateSurface(rect_dest->w, rect_dest->h + GUARD_ROWS, src->format);
if (rz_dst) {
- if (src->format->palette) {
- for (i = 0; i < src->format->palette->ncolors; i++) {
- rz_dst->format->palette->colors[i] = src->format->palette->colors[i];
- }
- rz_dst->format->palette->ncolors = src->format->palette->ncolors;
- }
+ SDL_SetSurfacePalette(rz_dst, src->internal->palette);
}
} else {
/* Target surface is 32 bit with source RGBA ordering */
- rz_dst = SDL_CreateSurface(rect_dest->w, rect_dest->h + GUARD_ROWS, src->format->format);
+ rz_dst = SDL_CreateSurface(rect_dest->w, rect_dest->h + GUARD_ROWS, src->format);
}
/* Check target */
@@ -555,7 +548,7 @@ SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, in
/* Without a colorkey, the target texture has to be white for the MOD and MUL blend mode so
* that the pixels outside the rotated area don't affect the destination surface.
*/
- colorkey = SDL_MapRGBA(rz_dst->format, 255, 255, 255, 0);
+ colorkey = SDL_MapRGBA(rz_dst->format, rz_dst->internal->palette, 255, 255, 255, 0);
SDL_FillSurfaceRect(rz_dst, NULL, colorkey);
/* Setting a white colorkey for the destination surface makes the final blit discard
* all pixels outside of the rotated area. This doesn't interfere with anything because
diff --git a/src/render/software/SDL_triangle.c b/src/render/software/SDL_triangle.c
index 95a5ddd392eb54..0610823611cc96 100644
--- a/src/render/software/SDL_triangle.c
+++ b/src/render/software/SDL_triangle.c
@@ -190,7 +190,7 @@ static void bounding_rect(const SDL_Point *a, const SDL_Point *b, const SDL_Poin
Uint8 g = (Uint8)(((Sint64)w0 * c0.g + (Sint64)w1 * c1.g + (Sint64)w2 * c2.g) / area); \
Uint8 b = (Uint8)(((Sint64)w0 * c0.b + (Sint64)w1 * c1.b + (Sint64)w2 * c2.b) / area); \
Uint8 a = (Uint8)(((Sint64)w0 * c0.a + (Sint64)w1 * c1.a + (Sint64)w2 * c2.a) / area); \
- Uint32 color = SDL_MapRGBA(format, r, g, b, a);
+ Uint32 color = SDL_MapRGBA(format, palette, r, g, b, a);
#define TRIANGLE_GET_COLOR \
int r = (int)(((Sint64)w0 * c0.r + (Sint64)w1 * c1.r + (Sint64)w2 * c2.r) / area); \
@@ -235,7 +235,7 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
SDL_Surface *tmp = NULL;
- if (!dst) {
+ if (!SDL_SurfaceValid(dst)) {
return -1;
}
@@ -278,10 +278,10 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
}
if (blend != SDL_BLENDMODE_NONE) {
- SDL_PixelFormatEnum format = dst->format->format;
+ SDL_PixelFormat format = dst->format;
/* need an alpha format */
- if (!dst->format->Amask) {
+ if (!SDL_ISPIXELFORMAT_ALPHA(format)) {
format = SDL_PIXELFORMAT_ARGB8888;
}
@@ -293,19 +293,19 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
}
if (blend == SDL_BLENDMODE_MOD) {
- Uint32 c = SDL_MapRGBA(tmp->format, 255, 255, 255, 255);
+ Uint32 c = SDL_MapRGBA(tmp->format, tmp->internal->palette, 255, 255, 255, 255);
SDL_FillSurfaceRect(tmp, NULL, c);
}
SDL_SetSurfaceBlendMode(tmp, blend);
- dstbpp = tmp->format->bytes_per_pixel;
+ dstbpp = tmp->internal->format->bytes_per_pixel;
dst_ptr = (Uint8 *)tmp->pixels;
dst_pitch = tmp->pitch;
} else {
/* Write directly to destination surface */
- dstbpp = dst->format->bytes_per_pixel;
+ dstbpp = dst->internal->format->bytes_per_pixel;
dst_ptr = (Uint8 *)dst->pixels + dstrect.x * dstbpp + dstrect.y * dst->pitch;
dst_pitch = dst->pitch;
}
@@ -359,9 +359,9 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
if (is_uniform) {
Uint32 color;
if (tmp) {
- color = SDL_MapRGBA(tmp->format, c0.r, c0.g, c0.b, c0.a);
+ color = SDL_MapRGBA(tmp->format, tmp->internal->palette, c0.r, c0.g, c0.b, c0.a);
} else {
- color = SDL_MapRGBA(dst->format, c0.r, c0.g, c0.b, c0.a);
+ color = SDL_MapRGBA(dst->format, dst->internal->palette, c0.r, c0.g, c0.b, c0.a);
}
if (dstbpp == 4) {
@@ -393,9 +393,14 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
TRIANGLE_END_LOOP
}
} else {
- SDL_PixelFormat *format = dst->format;
+ SDL_PixelFormat format;
+ SDL_Palette *palette;
if (tmp) {
format = tmp->format;
+ palette = tmp->internal->palette;
+ } else {
+ format = dst->format;
+ palette = dst->internal->palette;
}
if (dstbpp == 4) {
TRIANGLE_BEGIN_LOOP
@@ -481,10 +486,10 @@ int SDL_SW_BlitTriangle(
int has_modulation;
- if (!src) {
+ if (!SDL_SurfaceValid(src)) {
return SDL_InvalidParamError("src");
}
- if (!src) {
+ if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("dst");
}
@@ -578,7 +583,7 @@ int SDL_SW_BlitTriangle(
}
/* Set destination pointer */
- dstbpp = dst->format->bytes_per_pixel;
+ dstbpp = dst->internal->format->bytes_per_pixel;
dst_ptr = (Uint8 *)dst->pixels + dstrect.x * dstbpp + dstrect.y * dst->pitch;
dst_pitch = dst->pitch;
@@ -653,16 +658,16 @@ int SDL_SW_BlitTriangle(
goto end;
}
- if (blend != SDL_BLENDMODE_NONE || src->format->format != dst->format->format || has_modulation || !is_uniform) {
+ if (blend != SDL_BLENDMODE_NONE || src->format != dst->format || has_modulation || !is_uniform) {
/* Use SDL_BlitTriangle_Slow */
- SDL_BlitInfo *info = &src->map->info;
+ SDL_BlitInfo *info = &src->internal->map->info;
SDL_BlitInfo tmp_info;
SDL_zero(tmp_info);
- tmp_info.src_fmt = src->format;
- tmp_info.dst_fmt = dst->format;
+ tmp_info.src_fmt = src->internal->format;
+ tmp_info.dst_fmt = dst->internal->format;
tmp_info.flags = info->flags;
/*
tmp_info.r = info->r;
@@ -766,7 +771,7 @@ int SDL_SW_BlitTriangle(
#define FORMAT_2101010 1
#define FORMAT_HAS_ALPHA(format) format == 0
#define FORMAT_HAS_NO_ALPHA(format) format < 0
-static int detect_format(SDL_PixelFormat *pf)
+static int detect_format(const SDL_PixelFormatDetails *pf)
{
if (pf->format == SDL_PIXELFORMAT_ARGB2101010) {
return FORMAT_2101010;
@@ -792,8 +797,8 @@ static void SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
Uint32 srcR, srcG, srcB, srcA;
Uint32 dstpixel;
Uint32 dstR, dstG, dstB, dstA;
- SDL_PixelFormat *src_fmt = info->src_fmt;
- SDL_PixelFormat *dst_fmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *src_fmt = info->src_fmt;
+ const SDL_PixelFormatDetails *dst_fmt = info->dst_fmt;
int srcbpp = src_fmt->bytes_per_pixel;
int dstbpp = dst_fmt->bytes_per_pixel;
int srcfmt_val;
diff --git a/src/render/vulkan/SDL_render_vulkan.c b/src/render/vulkan/SDL_render_vulkan.c
index 0454e80ad99de4..688a0d1d107885 100644
--- a/src/render/vulkan/SDL_render_vulkan.c
+++ b/src/render/vulkan/SDL_render_vulkan.c
@@ -367,7 +367,7 @@ typedef struct
SDL_bool issueBatch;
} VULKAN_RenderData;
-static SDL_PixelFormatEnum VULKAN_VkFormatToSDLPixelFormat(VkFormat vkFormat)
+static SDL_PixelFormat VULKAN_VkFormatToSDLPixelFormat(VkFormat vkFormat)
{
switch (vkFormat) {
case VK_FORMAT_B8G8R8A8_UNORM:
diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c
index 584c06c3777f62..916f64bdab36a7 100644
--- a/src/test/SDL_test_common.c
+++ b/src/test/SDL_test_common.c
@@ -1038,14 +1038,14 @@ static void SDLTest_PrintRenderer(SDL_Renderer *renderer)
int i;
char text[1024];
int max_texture_size;
- const SDL_PixelFormatEnum *texture_formats;
+ const SDL_PixelFormat *texture_formats;
name = SDL_GetRendererName(renderer);
SDL_Log(" Renderer %s:\n", name);
SDL_Log(" VSync: %d\n", (int)SDL_GetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_VSYNC_NUMBER, 0));
- texture_formats = (const SDL_PixelFormatEnum *)SDL_GetProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_TEXTURE_FORMATS_POINTER, NULL);
+ texture_formats = (const SDL_PixelFormat *)SDL_GetProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_TEXTURE_FORMATS_POINTER, NULL);
if (texture_formats) {
(void)SDL_snprintf(text, sizeof(text), " Texture formats: ");
for (i = 0; texture_formats[i]; ++i) {
@@ -1074,7 +1074,7 @@ static SDL_Surface *SDLTest_LoadIcon(const char *file)
return NULL;
}
- if (icon->format->palette) {
+ if (icon->format == SDL_PIXELFORMAT_INDEX8) {
/* Set the colorkey */
SDL_SetSurfaceColorKey(icon, 1, *((Uint8 *)icon->pixels));
}
@@ -1218,7 +1218,7 @@ SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
SDL_Log("Usable bounds: %dx%d at %d,%d\n", usablebounds.w, usablebounds.h, usablebounds.x, usablebounds.y);
mode = SDL_GetDesktopDisplayMode(displayID);
- SDL_GetMasksForPixelFormatEnum(mode->format, &bpp, &Rmask, &Gmask,
+ SDL_GetMasksForPixelFormat(mode->format, &bpp, &Rmask, &Gmask,
&Bmask, &Amask);
SDL_Log(" Desktop mode: %dx%d@%gx %gHz, %d bits-per-pixel (%s)\n",
mode->w, mode->h, mode->pixel_density, mode->refresh_rate, bpp,
@@ -1240,7 +1240,7 @@ SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
SDL_Log(" Fullscreen video modes:\n");
for (j = 0; j < m; ++j) {
mode = modes[j];
- SDL_GetMasksForPixelFormatEnum(mode->format, &bpp, &Rmask,
+ SDL_GetMasksForPixelFormat(mode->format, &bpp, &Rmask,
&Gmask, &Bmask, &Amask);
SDL_Log(" Mode %d: %dx%d@%gx %gHz, %d bits-per-pixel (%s)\n",
j, mode->w, mode->h, mode->pixel_density, mode->refresh_rate, bpp,
diff --git a/src/test/SDL_test_compare.c b/src/test/SDL_test_compare.c
index db2fd047720722..1a696ad4ce74db 100644
--- a/src/test/SDL_test_compare.c
+++ b/src/test/SDL_test_compare.c
@@ -33,17 +33,6 @@
/* Counter for _CompareSurface calls; used for filename creation when comparisons fail */
static int _CompareSurfaceCount = 0;
-static void
-LogErrorFormat(const char *name, const SDL_PixelFormat *format)
-{
- SDLTest_LogError("%s: %08d %s, %u bits/%u bytes per pixel", name, format->format, SDL_GetPixelFormatName(format->format),
- format->bits_per_pixel, format->bytes_per_pixel);
- SDLTest_LogError("%s: R mask %08" SDL_PRIx32 ", loss %u, shift %u", name, format->Rmask, format->Rloss, format->Rshift);
- SDLTest_LogError("%s: G mask %08" SDL_PRIx32 ", loss %u, shift %u", name, format->Gmask, format->Gloss, format->Gshift);
- SDLTest_LogError("%s: B mask %08" SDL_PRIx32 ", loss %u, shift %u", name, format->Bmask, format->Bloss, format->Bshift);
- SDLTest_LogError("%s: A mask %08" SDL_PRIx32 ", loss %u, shift %u", name, format->Amask, format->Aloss, format->Ashift);
-}
-
/* Compare surfaces */
int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface, int allowable_error)
{
@@ -135,8 +124,8 @@ int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface,
_CompareSurfaceCount++;
if (ret != 0) {
SDLTest_LogError("Comparison of pixels with allowable error of %i failed %i times.", allowable_error, ret);
- LogErrorFormat("Reference surface format", referenceSurface->format);
- LogErrorFormat("Actual surface format ", surface->format);
+ SDLTest_LogError("Reference surface format: %s", SDL_GetPixelFormatName(referenceSurface->format));
+ SDLTest_LogError("Actual surface format: %s", SDL_GetPixelFormatName(surface->format));
SDLTest_LogError("First detected occurrence at position %i,%i with a squared RGB-difference of %i.", sampleErrorX, sampleErrorY, sampleDist);
SDLTest_LogError("Reference pixel: R=%u G=%u B=%u A=%u", sampleReference.r, sampleReference.g, sampleReference.b, sampleReference.a);
SDLTest_LogError("Actual pixel : R=%u G=%u B=%u A=%u", sampleActual.r, sampleActual.g, sampleActual.b, sampleActual.a);
diff --git a/src/video/SDL_RLEaccel.c b/src/video/SDL_RLEaccel.c
index 3d6830408000b2..47fde29f8ccef5 100644
--- a/src/video/SDL_RLEaccel.c
+++ b/src/video/SDL_RLEaccel.c
@@ -62,7 +62,7 @@
*
* Encoding of surfaces with per-pixel alpha:
*
- * The sequence begins with a struct RLEDestFormat describing the target
+ * The sequence begins with a struct SDL_PixelFormatDetails describing the target
* pixel format, to provide reliable un-encoding.
*
* Each scan line is encoded twice: First all completely opaque pixels,
@@ -375,9 +375,9 @@
*/
#define RLEPIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a) \
{ \
- Pixel = ((r >> fmt->Rloss) << fmt->Rshift) | \
- ((g >> fmt->Gloss) << fmt->Gshift) | \
- ((b >> fmt->Bloss) << fmt->Bshift) | \
+ Pixel = ((r >> (8 - fmt->Rbits)) << fmt->Rshift) | \
+ ((g >> (8 - fmt->Gbits)) << fmt->Gshift) | \
+ ((b >> (8 - fmt->Bbits)) << fmt->Bshift) | \
(a << 24); \
}
@@ -434,7 +434,7 @@
static void RLEClipBlit(int w, Uint8 *srcbuf, SDL_Surface *surf_dst,
Uint8 *dstbuf, const SDL_Rect *srcrect, unsigned alpha)
{
- SDL_PixelFormat *fmt = surf_dst->format;
+ const SDL_PixelFormatDetails *fmt = surf_dst->internal->format;
CHOOSE_BLIT(RLECLIPBLIT, alpha, fmt);
}
@@ -461,8 +461,8 @@ static int SDLCALL SDL_RLEBlit(SDL_Surface *surf_src, const SDL_Rect *srcrect,
/* Set up the source and destination pointers */
x = dstrect->x;
y = dstrect->y;
- dstbuf = (Uint8 *)surf_dst->pixels + y * surf_dst->pitch + x * surf_src->format->bytes_per_pixel;
- srcbuf = (Uint8 *)surf_src->map->data;
+ dstbuf = (Uint8 *)surf_dst->pixels + y * surf_dst->pitch + x * surf_src->internal->format->bytes_per_pixel;
+ srcbuf = (Uint8 *)surf_src->internal->map->data;
{
/* skip lines at the top if necessary */
@@ -488,7 +488,7 @@ static int SDLCALL SDL_RLEBlit(SDL_Surface *surf_src, const SDL_Rect *srcrect,
} \
}
- switch (surf_src->format->bytes_per_pixel) {
+ switch (surf_src->internal->format->bytes_per_pixel) {
case 1:
RLESKIP(1, Uint8);
break;
@@ -507,12 +507,12 @@ static int SDLCALL SDL_RLEBlit(SDL_Surface *surf_src, const SDL_Rect *srcrect,
}
}
- alpha = surf_src->map->info.a;
+ alpha = surf_src->internal->map->info.a;
/* if left or right edge clipping needed, call clip blit */
if (srcrect->x || srcrect->w != surf_src->w) {
RLEClipBlit(w, srcbuf, surf_dst, dstbuf, srcrect, alpha);
} else {
- SDL_PixelFormat *fmt = surf_src->format;
+ const SDL_PixelFormatDetails *fmt = surf_src->internal->format;
#define RLEBLIT(bpp, Type, do_blit) \
do { \
@@ -604,31 +604,11 @@ static int SDLCALL SDL_RLEBlit(SDL_Surface *surf_src, const SDL_Rect *srcrect,
dst = (Uint16)(d | d >> 16); \
} while (0)
-/* used to save the destination format in the encoding. Designed to be
- macro-compatible with SDL_PixelFormat but without the unneeded fields */
-typedef struct
-{
- Uint8 bytes_per_pixel;
- Uint8 padding[3];
- Uint32 Rmask;
- Uint32 Gmask;
- Uint32 Bmask;
- Uint32 Amask;
- Uint8 Rloss;
- Uint8 Gloss;
- Uint8 Bloss;
- Uint8 Aloss;
- Uint8 Rshift;
- Uint8 Gshift;
- Uint8 Bshift;
- Uint8 Ashift;
-} RLEDestFormat;
-
/* blit a pixel-alpha RLE surface clipped at the right and/or left edges */
static void RLEAlphaClipBlit(int w, Uint8 *srcbuf, SDL_Surface *surf_dst,
Uint8 *dstbuf, const SDL_Rect *srcrect)
{
- SDL_PixelFormat *df = surf_dst->format;
+ const SDL_PixelFormatDetails *df = surf_dst->internal->format;
/*
* clipped blitter: Ptype is the destination pixel type,
* Ctype the translucent count type, and do_blend the macro
@@ -723,7 +703,7 @@ static int SDLCALL SDL_RLEAlphaBlit(SDL_Surface *surf_src, const SDL_Rect *srcre
int x, y;
int w = surf_src->w;
Uint8 *srcbuf, *dstbuf;
- SDL_PixelFormat *df = surf_dst->format;
+ const SDL_PixelFormatDetails *df = surf_dst->internal->format;
/* Lock the destination if necessary */
if (SDL_MUSTLOCK(surf_dst)) {
@@ -735,7 +715,7 @@ static int SDLCALL SDL_RLEAlphaBlit(SDL_Surface *surf_src, const SDL_Rect *srcre
x = dstrect->x;
y = dstrect->y;
dstbuf = (Uint8 *)surf_dst->pixels + y * surf_dst->pitch + x * df->bytes_per_pixel;
- srcbuf = (Uint8 *)surf_src->map->data + sizeof(RLEDestFormat);
+ srcbuf = (Uint8 *)surf_src->internal->map->data + sizeof(SDL_PixelFormatDetails);
{
/* skip lines at the top if necessary */
@@ -884,7 +864,7 @@ static int SDLCALL SDL_RLEAlphaBlit(SDL_Surface *surf_src, const SDL_Rect *srcre
/* encode 32bpp rgb + a into 16bpp rgb, losing alpha */
static int copy_opaque_16(void *dst, const Uint32 *src, int n,
- SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
+ const SDL_PixelFormatDetails *sfmt, const SDL_PixelFormatDetails *dfmt)
{
int i;
Uint16 *d = (Uint16 *)dst;
@@ -900,7 +880,7 @@ static int copy_opaque_16(void *dst, const Uint32 *src, int n,
/* decode opaque pixels from 16bpp to 32bpp rgb + a */
static int uncopy_opaque_16(Uint32 *dst, const void *src, int n,
- RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
+ const SDL_PixelFormatDetails *sfmt, const SDL_PixelFormatDetails *dfmt)
{
int i;
const Uint16 *s = (const Uint16 *)src;
@@ -917,7 +897,7 @@ static int uncopy_opaque_16(Uint32 *dst, const void *src, int n,
/* encode 32bpp rgb + a into 32bpp G0RAB format for blitting into 565 */
static int copy_transl_565(void *dst, const Uint32 *src, int n,
- SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
+ const SDL_PixelFormatDetails *sfmt, const SDL_PixelFormatDetails *dfmt)
{
int i;
Uint32 *d = (Uint32 *)dst;
@@ -935,7 +915,7 @@ static int copy_transl_565(void *dst, const Uint32 *src, int n,
/* encode 32bpp rgb + a into 32bpp G0RAB format for blitting into 555 */
static int copy_transl_555(void *dst, const Uint32 *src, int n,
- SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
+ const SDL_PixelFormatDetails *sfmt, const SDL_PixelFormatDetails *dfmt)
{
int i;
Uint32 *d = (Uint32 *)dst;
@@ -953,7 +933,7 @@ static int copy_transl_555(void *dst, const Uint32 *src, int n,
/* decode translucent pixels from 32bpp GORAB to 32bpp rgb + a */
static int uncopy_transl_16(Uint32 *dst, const void *src, int n,
- RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
+ const SDL_PixelFormatDetails *sfmt, const SDL_PixelFormatDetails *dfmt)
{
int i;
const Uint32 *s = (const Uint32 *)src;
@@ -971,7 +951,7 @@ static int uncopy_transl_16(Uint32 *dst, const void *src, int n,
/* encode 32bpp rgba into 32bpp rgba, keeping alpha (dual purpose) */
static int copy_32(void *dst, const Uint32 *src, int n,
- SDL_PixelFormat *sfmt, SDL_PixelFormat *dfmt)
+ const SDL_PixelFormatDetails *sfmt, const SDL_PixelFormatDetails *dfmt)
{
int i;
Uint32 *d = (Uint32 *)dst;
@@ -987,7 +967,7 @@ static int copy_32(void *dst, const Uint32 *src, int n,
/* decode 32bpp rgba into 32bpp rgba, keeping alpha (dual purpose) */
static int uncopy_32(Uint32 *dst, const void *src, int n,
- RLEDestFormat *sfmt, SDL_PixelFormat *dfmt)
+ SDL_PixelFormatDetails *sfmt, const SDL_PixelFormatDetails *dfmt)
{
int i;
const Uint32 *s = (const Uint32 *)src;
@@ -1011,23 +991,23 @@ static int uncopy_32(Uint32 *dst, const void *src, int n,
static int RLEAlphaSurface(SDL_Surface *surface)
{
SDL_Surface *dest;
- SDL_PixelFormat *df;
+ const SDL_PixelFormatDetails *df;
int maxsize = 0;
int max_opaque_run;
int max_transl_run = 65535;
unsigned masksum;
Uint8 *rlebuf, *dst;
int (*copy_opaque)(void *, const Uint32 *, int,
- SDL_PixelFormat *, SDL_PixelFormat *);
+ const SDL_PixelFormatDetails *, const SDL_PixelFormatDetails *);
int (*copy_transl)(void *, const Uint32 *, int,
- SDL_PixelFormat *, SDL_PixelFormat *);
+ const SDL_PixelFormatDetails *, const SDL_PixelFormatDetails *);
- dest = surface->map->dst;
+ dest = surface->internal->map->dst;
if (!dest) {
return -1;
}
- df = dest->format;
- if (surface->format->bits_per_pixel != 32) {
+ df = dest->internal->format;
+ if (surface->internal->format->bits_per_pixel != 32) {
return -1; /* only 32bpp source supported */
}
@@ -1078,35 +1058,23 @@ static int RLEAlphaSurface(SDL_Surface *surface)
return -1; /* anything else unsupported right now */
}
- maxsize += sizeof(RLEDestFormat);
+ maxsize += sizeof(SDL_PixelFormatDetails);
rlebuf = (Uint8 *)SDL_malloc(maxsize);
if (!rlebuf) {
return -1;
}
{
/* save the destination format so we can undo the encoding later */
- RLEDestFormat *r = (RLEDestFormat *)rlebuf;
- r->bytes_per_pixel = df->bytes_per_pixel;
- r->Rmask = df->Rmask;
- r->Gmask = df->Gmask;
- r->Bmask = df->Bmask;
- r->Amask = df->Amask;
- r->Rloss = df->Rloss;
- r->Gloss = df->Gloss;
- r->Bloss = df->Bloss;
- r->Aloss = df->Aloss;
- r->Rshift = df->Rshift;
- r->Gshift = df->Gshift;
- r->Bshift = df->Bshift;
- r->Ashift = df->Ashift;
+ SDL_PixelFormatDetails *r = (SDL_PixelFormatDetails *)rlebuf;
+ SDL_copyp(r, df);
}
- dst = rlebuf + sizeof(RLEDestFormat);
+ dst = rlebuf + sizeof(SDL_PixelFormatDetails);
/* Do the actual encoding */
{
int x, y;
int h = surface->h, w = surface->w;
- SDL_PixelFormat *sf = surface->format;
+ const SDL_PixelFormatDetails *sf = surface->internal->format;
Uint32 *src = (Uint32 *)surface->pixels;
Uint8 *lastline = dst; /* end of last non-blank line */
@@ -1213,10 +1181,10 @@ static int RLEAlphaSurface(SDL_Surface *surface)
#undef ADD_TRANSL_COUNTS
/* Now that we have it encoded, release the original pixels */
- if (!(surface->flags & SDL_PREALLOC)) {
- if (surface->flags & SDL_SIMD_ALIGNED) {
+ if (!(surface->flags & SDL_SURFACE_PREALLOCATED)) {
+ if (surface->flags & SDL_SURFACE_SIMD_ALIGNED) {
SDL_aligned_free(surface->pixels);
- surface->flags &= ~SDL_SIMD_ALIGNED;
+ surface->flags &= ~SDL_SURFACE_SIMD_ALIGNED;
} else {
SDL_free(surface->pixels);
}
@@ -1229,7 +1197,7 @@ static int RLEAlphaSurface(SDL_Surface *surface)
if (!p) {
p = rlebuf;
}
- surface->map->data = p;
+ surface->internal->map->data = p;
}
return 0;
@@ -1272,7 +1240,7 @@ static int RLEColorkeySurface(SDL_Surface *surface)
int y;
Uint8 *srcbuf, *lastline;
int maxsize = 0;
- const int bpp = surface->format->bytes_per_pixel;
+ const int bpp = surface->internal->format->bytes_per_pixel;
getpix_func getpix;
Uint32 ckey, rgbmask;
int w, h;
@@ -1307,8 +1275,8 @@ static int RLEColorkeySurface(SDL_Surface *surface)
srcbuf = (Uint8 *)surface->pixels;
maxn = bpp == 4 ? 65535 : 255;
dst = rlebuf;
- rgbmask = ~surface->format->Amask;
- ckey = surface->map->info.colorkey & rgbmask;
+ rgbmask = ~surface->internal->format->Amask;
+ ckey = surface->internal->map->info.colorkey & rgbmask;
lastline = dst;
getpix = getpixes[bpp - 1];
w = surface->w;
@@ -1380,10 +1348,10 @@ static int RLEColorkeySurface(SDL_Surface *surface)
#undef ADD_COUNTS
/* Now that we have it encoded, release the original pixels */
- if (!(surface->flags & SDL_PREALLOC)) {
- if (surface->flags & SDL_SIMD_ALIGNED) {
+ if (!(surface->flags & SDL_SURFACE_PREALLOCATED)) {
+ if (surface->flags & SDL_SURFACE_SIMD_ALIGNED) {
SDL_aligned_free(surface->pixels);
- surface->flags &= ~SDL_SIMD_ALIGNED;
+ surface->flags &= ~SDL_SURFACE_SIMD_ALIGNED;
} else {
SDL_free(surface->pixels);
}
@@ -1397,7 +1365,7 @@ static int RLEColorkeySurface(SDL_Surface *surface)
if (!p) {
p = rlebuf;
}
- surface->map->data = p;
+ surface->internal->map->data = p;
}
return 0;
@@ -1408,12 +1376,12 @@ int SDL_RLESurface(SDL_Surface *surface)
int flags;
/* Clear any previous RLE conversion */
- if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
- SDL_UnRLESurface(surface, 1);
+ if (surface->internal->flags & SDL_INTERNAL_SURFACE_RLEACCEL) {
+ SDL_UnRLESurface(surface, SDL_TRUE);
}
/* We don't support RLE encoding of bitmaps */
- if (surface->format->bits_per_pixel < 8) {
+ if (SDL_BITSPERPIXEL(surface->format) < 8) {
return -1;
}
@@ -1422,10 +1390,10 @@ int SDL_RLESurface(SDL_Surface *surface)
return -1;
}
- flags = surface->map->info.flags;
+ flags = surface->internal->map->info.flags;
if (flags & SDL_COPY_COLORKEY) {
/* ok */
- } else if ((flags & SDL_COPY_BLEND) && surface->format->Amask) {
+ } else if ((flags & SDL_COPY_BLEND) && SDL_ISPIXELFORMAT_ALPHA(surface->format)) {
/* ok */
} else {
/* If we don't have colorkey or blending, nothing to do... */
@@ -1434,32 +1402,33 @@ int SDL_RLESurface(SDL_Surface *surface)
/* Pass on combinations not supported */
if ((flags & SDL_COPY_MODULATE_COLOR) ||
- ((flags & SDL_COPY_MODULATE_ALPHA) && surface->format->Amask) ||
+ ((flags & SDL_COPY_MODULATE_ALPHA) && SDL_ISPIXELFORMAT_ALPHA(surface->format)) ||
(flags & (SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_MUL)) ||
(flags & SDL_COPY_NEAREST)) {
return -1;
}
/* Encode and set up the blit */
- if (!surface->format->Amask || !(flags & SDL_COPY_BLEND)) {
- if (!surface->map->identity) {
+ if (!SDL_ISPIXELFORMAT_ALPHA(surface->format) || !(flags & SDL_COPY_BLEND)) {
+ if (!surface->internal->map->identity) {
return -1;
}
if (RLEColorkeySurface(surface) < 0) {
return -1;
}
- surface->map->blit = SDL_RLEBlit;
- surface->map->info.flags |= SDL_COPY_RLE_COLORKEY;
+ surface->internal->map->blit = SDL_RLEBlit;
+ surface->internal->map->info.flags |= SDL_COPY_RLE_COLORKEY;
} else {
if (RLEAlphaSurface(surface) < 0) {
return -1;
}
- surface->map->blit = SDL_RLEAlphaBlit;
- surface->map->info.flags |= SDL_COPY_RLE_ALPHAKEY;
+ surface->internal->map->blit = SDL_RLEAlphaBlit;
+ surface->internal->map->info.flags |= SDL_COPY_RLE_ALPHAKEY;
}
/* The surface is now accelerated */
- surface->flags |= SDL_RLEACCEL;
+ surface->internal->flags |= SDL_INTERNAL_SURFACE_RLEACCEL;
+ SDL_UpdateSurfaceLockFlag(surface);
return 0;
}
@@ -1474,12 +1443,12 @@ static SDL_bool UnRLEAlpha(SDL_Surface *surface)
{
Uint8 *srcbuf;
Uint32 *dst;
- SDL_PixelFormat *sf = surface->format;
- RLEDestFormat *df = (RLEDestFormat *)surface->map->data;
+ const SDL_PixelFormatDetails *sf = surface->internal->format;
+ SDL_PixelFormatDetails *df = (SDL_PixelFormatDetails *)surface->internal->map->data;
int (*uncopy_opaque)(Uint32 *, const void *, int,
- RLEDestFormat *, SDL_PixelFormat *);
+ SDL_PixelFormatDetails *, const SDL_PixelFormatDetails *);
int (*uncopy_transl)(Uint32 *, const void *, int,
- RLEDestFormat *, SDL_PixelFormat *);
+ SDL_PixelFormatDetails *, const SDL_PixelFormatDetails *);
int w = surface->w;
int bpp = df->bytes_per_pixel;
size_t size;
@@ -1499,7 +1468,7 @@ static SDL_bool UnRLEAlpha(SDL_Surface *surface)
if (!surface->pixels) {
return SDL_FALSE;
}
- surface->flags |= SDL_SIMD_ALIGNED;
+ surface->flags |= SDL_SURFACE_SIMD_ALIGNED;
/* fill background with transparent pixels */
SDL_memset(surface->pixels, 0, (size_t)surface->h * surface->pitch);
@@ -1551,32 +1520,35 @@ static SDL_bool UnRLEAlpha(SDL_Surface *surface)
return SDL_TRUE;
}
-void SDL_UnRLESurface(SDL_Surface *surface, int recode)
+void SDL_UnRLESurface(SDL_Surface *surface, SDL_bool recode)
{
- if (surface->flags & SDL_RLEACCEL) {
- surface->flags &= ~SDL_RLEACCEL;
+ if (surface->internal->flags & SDL_INTERNAL_SURFACE_RLEACCEL) {
+ surface->internal->flags &= ~SDL_INTERNAL_SURFACE_RLEACCEL;
+ SDL_UpdateSurfaceLockFlag(surface);
- if (recode && !(surface->flags & SDL_PREALLOC)) {
- if (surface->map->info.flags & SDL_COPY_RLE_COLORKEY) {
+ if (recode && !(surface->flags & SDL_SURFACE_PREALLOCATED)) {
+ if (surface->internal->map->info.flags & SDL_COPY_RLE_COLORKEY) {
SDL_Rect full;
size_t size;
/* re-create the original surface */
if (SDL_size_mul_overflow(surface->h, surface->pitch, &size)) {
/* Memory corruption? */
- surface->flags |= SDL_RLEACCEL;
+ surface->internal->flags |= SDL_INTERNAL_SURFACE_RLEACCEL;
+ SDL_UpdateSurfaceLockFlag(surface);
return;
}
surface->pixels = SDL_aligned_alloc(SDL_GetSIMDAlignment(), size);
if (!surface->pixels) {
/* Oh crap... */
- surface->flags |= SDL_RLEACCEL;
+ surface->internal->flags |= SDL_INTERNAL_SURFACE_RLEACCEL;
+ SDL_UpdateSurfaceLockFlag(surface);
return;
}
- surface->flags |= SDL_SIMD_ALIGNED;
+ surface->flags |= SDL_SURFACE_SIMD_ALIGNED;
/* fill it with the background color */
- SDL_FillSurfaceRect(surface, NULL, surface->map->info.colorkey);
+ SDL_FillSurfaceRect(surface, NULL, surface->internal->map->info.colorkey);
/* now render the encoded surface */
full.x = full.y = 0;
@@ -1586,16 +1558,17 @@ void SDL_UnRLESurface(SDL_Surface *surface, int recode)
} else {
if (!UnRLEAlpha(surface)) {
/* Oh crap... */
- surface->flags |= SDL_RLEACCEL;
+ surface->internal->flags |= SDL_INTERNAL_SURFACE_RLEACCEL;
+ SDL_UpdateSurfaceLockFlag(surface);
return;
}
}
}
- surface->map->info.flags &=
+ surface->internal->map->info.flags &=
~(SDL_COPY_RLE_COLORKEY | SDL_COPY_RLE_ALPHAKEY);
- SDL_free(surface->map->data);
- surface->map->data = NULL;
+ SDL_free(surface->internal->map->data);
+ surface->internal->map->data = NULL;
}
}
diff --git a/src/video/SDL_blit.c b/src/video/SDL_blit.c
index 4297976312b92f..c64b9943896e29 100644
--- a/src/video/SDL_blit.c
+++ b/src/video/SDL_blit.c
@@ -61,7 +61,7 @@ static int SDLCALL SDL_SoftBlit(SDL_Surface *src, const SDL_Rect *srcrect,
/* Set up source and destination buffer pointers, and BLIT! */
if (okay && !SDL_RectEmpty(srcrect)) {
SDL_BlitFunc RunBlit;
- SDL_BlitInfo *info = &src->map->info;
+ SDL_BlitInfo *info = &src->internal->map->info;
/* Set up the blit information */
info->src = (Uint8 *)src->pixels +
@@ -80,7 +80,7 @@ static int SDLCALL SDL_SoftBlit(SDL_Surface *src, const SDL_Rect *srcrect,
info->dst_pitch = dst->pitch;
info->dst_skip =
info->dst_pitch - info->dst_w * info->dst_fmt->bytes_per_pixel;
- RunBlit = (SDL_BlitFunc)src->map->data;
+ RunBlit = (SDL_BlitFunc)src->internal->map->data;
/* Run the actual software blit */
RunBlit(info);
@@ -122,7 +122,7 @@ static SDL_bool SDL_UseAltivecPrefetch(void)
}
#endif /* SDL_PLATFORM_MACOS */
-static SDL_BlitFunc SDL_ChooseBlitFunc(Uint32 src_format, Uint32 dst_format, int flags,
+static SDL_BlitFunc SDL_ChooseBlitFunc(SDL_PixelFormat src_format, SDL_PixelFormat dst_format, int flags,
SDL_BlitFuncEntry *entries)
{
int i, flagcheck = (flags & (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_MUL | SDL_COPY_COLORKEY | SDL_COPY_NEAREST));
@@ -179,37 +179,39 @@ static SDL_BlitFunc SDL_ChooseBlitFunc(Uint32 src_format, Uint32 dst_format, int
int SDL_CalculateBlit(SDL_Surface *surface)
{
SDL_BlitFunc blit = NULL;
- SDL_BlitMap *map = surface->map;
+ SDL_BlitMap *map = surface->internal->map;
SDL_Surface *dst = map->dst;
- SDL_Colorspace src_colorspace = SDL_COLORSPACE_UNKNOWN;
- SDL_Colorspace dst_colorspace = SDL_COLORSPACE_UNKNOWN;
+ SDL_Colorspace src_colorspace = SDL_GetSurfaceColorspace(surface);
+ SDL_Colorspace dst_colorspace = SDL_GetSurfaceColorspace(dst);
- if (SDL_GetSurfaceColorspace(surface, &src_colorspace) < 0) {
+ if (src_colorspace == SDL_COLORSPACE_UNKNOWN) {
return -1;
}
- if (SDL_GetSurfaceColorspace(dst, &dst_colorspace) < 0) {
+ if (dst_colorspace == SDL_COLORSPACE_UNKNOWN) {
return -1;
}
/* We don't currently support blitting to < 8 bpp surfaces */
- if (dst->format->bits_per_pixel < 8) {
+ if (SDL_BITSPERPIXEL(dst->format) < 8) {
SDL_InvalidateMap(map);
return SDL_SetError("Blit combination not supported");
}
#if SDL_HAVE_RLE
/* Clean everything out to start */
- if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
- SDL_UnRLESurface(surface, 1);
+ if (surface->flags & SDL_INTERNAL_SURFACE_RLEACCEL) {
+ SDL_UnRLESurface(surface, SDL_TRUE);
}
#endif
map->blit = SDL_SoftBlit;
map->info.src_surface = surface;
- map->info.src_fmt = surface->format;
+ map->info.src_fmt = surface->internal->format;
+ map->info.src_pal = surface->internal->palette;
map->info.src_pitch = surface->pitch;
map->info.dst_surface = dst;
- map->info.dst_fmt = dst->format;
+ map->info.dst_fmt = dst->internal->format;
+ map->info.dst_pal = dst->internal->palette;
map->info.dst_pitch = dst->pitch;
#if SDL_HAVE_RLE
@@ -224,26 +226,27 @@ int SDL_CalculateBlit(SDL_Surface *surface)
/* Choose a standard blit function */
if (!blit) {
if (src_colorspace != dst_colorspace ||
- surface->format->bytes_per_pixel > 4 ||
- dst->format->bytes_per_pixel > 4) {
+ SDL_BYTESPERPIXEL(surface->format) > 4 ||
+ SDL_BYTESPERPIXEL(dst->format) > 4) {
blit = SDL_Blit_Slow_Float;
}
}
if (!blit) {
if (map->identity && !(map->info.flags & ~SDL_COPY_RLE_DESIRED)) {
blit = SDL_BlitCopy;
- } else if (surface->format->Rloss > 8 || dst->format->Rloss > 8) {
+ } else if (SDL_ISPIXELFORMAT_10BIT(surface->format) ||
+ SDL_ISPIXELFORMAT_10BIT(dst->format)) {
blit = SDL_Blit_Slow;
}
#if SDL_HAVE_BLIT_0
- else if (surface->format->bits_per_pixel < 8 &&
- SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) {
+ else if (SDL_BITSPERPIXEL(surface->format) < 8 &&
+ SDL_ISPIXELFORMAT_INDEXED(surface->format)) {
blit = SDL_CalculateBlit0(surface);
}
#endif
#if SDL_HAVE_BLIT_1
- else if (surface->format->bytes_per_pixel == 1 &&
- SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) {
+ else if (SDL_BYTESPERPIXEL(surface->format) == 1 &&
+ SDL_ISPIXELFORMAT_INDEXED(surface->format)) {
blit = SDL_CalculateBlit1(surface);
}
#endif
@@ -260,8 +263,8 @@ int SDL_CalculateBlit(SDL_Surface *surface)
}
#if SDL_HAVE_BLIT_AUTO
if (!blit) {
- Uint32 src_format = surface->format->format;
- Uint32 dst_format = dst->format->format;
+ SDL_PixelFormat src_format = surface->format;
+ SDL_PixelFormat dst_format = dst->format;
blit =
SDL_ChooseBlitFunc(src_format, dst_format, map->info.flags,
@@ -273,8 +276,8 @@ int SDL_CalculateBlit(SDL_Surface *surface)
if (!blit)
#endif
{
- Uint32 src_format = surface->format->format;
- Uint32 dst_format = dst->format->format;
+ SDL_PixelFormat src_format = surface->format;
+ SDL_PixelFormat dst_format = dst->format;
if (!SDL_ISPIXELFORMAT_INDEXED(src_format) &&
!SDL_ISPIXELFORMAT_FOURCC(src_format) &&
diff --git a/src/video/SDL_blit.h b/src/video/SDL_blit.h
index 5facdd51594068..3a8b2acac9642e 100644
--- a/src/video/SDL_blit.h
+++ b/src/video/SDL_blit.h
@@ -23,6 +23,8 @@
#ifndef SDL_blit_h_
#define SDL_blit_h_
+#include "SDL_surface_c.h"
+
/* Table to do pixel byte expansion */
extern const Uint8 *SDL_expand_byte[9];
extern const Uint16 SDL_expand_byte_10[];
@@ -61,8 +63,10 @@ typedef struct
int dst_w, dst_h;
int dst_pitch;
int dst_skip;
- SDL_PixelFormat *src_fmt;
- SDL_PixelFormat *dst_fmt;
+ const SDL_PixelFormatDetails *src_fmt;
+ const SDL_Palette *src_pal;
+ const SDL_PixelFormatDetails *dst_fmt;
+ const SDL_Palette *dst_pal;
Uint8 *table;
int flags;
Uint32 colorkey;
@@ -73,8 +77,8 @@ typedef void (*SDL_BlitFunc)(SDL_BlitInfo *info);
typedef struct
{
- Uint32 src_format;
- Uint32 dst_format;
+ SDL_PixelFormat src_format;
+ SDL_PixelFormat dst_format;
int flags;
unsigned int cpu;
SDL_BlitFunc func;
@@ -83,8 +87,7 @@ typedef struct
typedef int (SDLCALL *SDL_Blit) (struct SDL_Surface *src, const SDL_Rect *srcrect, struct SDL_Surface *dst, const SDL_Rect *dstrect);
/* Blit mapping definition */
-/* typedef'ed in SDL_surface.h */
-struct SDL_BlitMap
+typedef struct SDL_BlitMap
{
SDL_Surface *dst;
int identity;
@@ -96,7 +99,7 @@ struct SDL_BlitMap
an invalid mapping */
Uint32 dst_palette_version;
Uint32 src_palette_version;
-};
+} SDL_BlitMap;
/* Functions found in SDL_blit.c */
extern int SDL_CalculateBlit(SDL_Surface *surface);
@@ -122,9 +125,9 @@ extern SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface *surface);
/* Load pixel of the specified format from a buffer and get its R-G-B values */
#define RGB_FROM_PIXEL(Pixel, fmt, r, g, b) \
{ \
- r = SDL_expand_byte[fmt->Rloss][((Pixel & fmt->Rmask) >> fmt->Rshift)]; \
- g = SDL_expand_byte[fmt->Gloss][((Pixel & fmt->Gmask) >> fmt->Gshift)]; \
- b = SDL_expand_byte[fmt->Bloss][((Pixel & fmt->Bmask) >> fmt->Bshift)]; \
+ r = SDL_expand_byte[fmt->Rbits][((Pixel & fmt->Rmask) >> fmt->Rshift)]; \
+ g = SDL_expand_byte[fmt->Gbits][((Pixel & fmt->Gmask) >> fmt->Gshift)]; \
+ b = SDL_expand_byte[fmt->Bbits][((Pixel & fmt->Bmask) >> fmt->Bshift)]; \
}
#define RGB_FROM_RGB565(Pixel, r, g, b) \
{ \
@@ -216,12 +219,12 @@ extern SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface *surface);
} while (0)
/* Assemble R-G-B values into a specified pixel format and store them */
-#define PIXEL_FROM_RGB(Pixel, fmt, r, g, b) \
- { \
- Pixel = ((r >> fmt->Rloss) << fmt->Rshift) | \
- ((g >> fmt->Gloss) << fmt->Gshift) | \
- ((b >> fmt->Bloss) << fmt->Bshift) | \
- fmt->Amask; \
+#define PIXEL_FROM_RGB(Pixel, fmt, r, g, b) \
+ { \
+ Pixel = ((r >> (8 - fmt->Rbits)) << fmt->Rshift) | \
+ ((g >> (8 - fmt->Gbits)) << fmt->Gshift) | \
+ ((b >> (8 - fmt->Bbits)) << fmt->Bshift) | \
+ fmt->Amask; \
}
#define RGB565_FROM_RGB(Pixel, r, g, b) \
{ \
@@ -334,10 +337,10 @@ extern SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface *surface);
/* FIXME: Should we rescale alpha into 0..255 here? */
#define RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a) \
{ \
- r = SDL_expand_byte[fmt->Rloss][((Pixel & fmt->Rmask) >> fmt->Rshift)]; \
- g = SDL_expand_byte[fmt->Gloss][((Pixel & fmt->Gmask) >> fmt->Gshift)]; \
- b = SDL_expand_byte[fmt->Bloss][((Pixel & fmt->Bmask) >> fmt->Bshift)]; \
- a = SDL_expand_byte[fmt->Aloss][((Pixel & fmt->Amask) >> fmt->Ashift)]; \
+ r = SDL_expand_byte[fmt->Rbits][((Pixel & fmt->Rmask) >> fmt->Rshift)]; \
+ g = SDL_expand_byte[fmt->Gbits][((Pixel & fmt->Gmask) >> fmt->Gshift)]; \
+ b = SDL_expand_byte[fmt->Bbits][((Pixel & fmt->Bmask) >> fmt->Bshift)]; \
+ a = SDL_expand_byte[fmt->Abits][((Pixel & fmt->Amask) >> fmt->Ashift)]; \
}
#define RGBA_FROM_8888(Pixel, fmt, r, g, b, a) \
{ \
@@ -444,12 +447,12 @@ extern SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface *surface);
} while (0)
/* FIXME: this isn't correct, especially for Alpha (maximum != 255) */
-#define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a) \
- { \
- Pixel = ((r >> fmt->Rloss) << fmt->Rshift) | \
- ((g >> fmt->Gloss) << fmt->Gshift) | \
- ((b >> fmt->Bloss) << fmt->Bshift) | \
- ((a >> fmt->Aloss) << fmt->Ashift); \
+#define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a) \
+ { \
+ Pixel = ((r >> (8 - fmt->Rbits)) << fmt->Rshift) | \
+ ((g >> (8 - fmt->Gbits)) << fmt->Gshift) | \
+ ((b >> (8 - fmt->Bbits)) << fmt->Bshift) | \
+ ((a >> (8 - fmt->Abits)) << fmt->Ashift); \
}
#define ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a) \
{ \
diff --git a/src/video/SDL_blit_0.c b/src/video/SDL_blit_0.c
index b2b2014e1df5cb..e2806b615eef13 100644
--- a/src/video/SDL_blit_0.c
+++ b/src/video/SDL_blit_0.c
@@ -615,8 +615,8 @@ SDL_FORCE_INLINE void BlitBtoNAlpha(SDL_BlitInfo *info, const Uint32 srcbpp)
Uint8 *dst = info->dst;
int srcskip = info->src_skip;
int dstskip = info->dst_skip;
- const SDL_Color *srcpal = info->src_fmt->palette->colors;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_Color *srcpal = info->src_pal->colors;
+ const SDL_PixelFormatDetails *dstfmt = info->dst_fmt;
int dstbpp;
int c;
Uint32 pixel;
@@ -691,9 +691,8 @@ SDL_FORCE_INLINE void BlitBtoNAlphaKey(SDL_BlitInfo *info, const Uint32 srcbpp)
Uint8 *dst = info->dst;
int srcskip = info->src_skip;
int dstskip = info->dst_skip;
- SDL_PixelFormat *srcfmt = info->src_fmt;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
- const SDL_Color *srcpal = srcfmt->palette->colors;
+ const SDL_PixelFormatDetails *dstfmt = info->dst_fmt;
+ const SDL_Color *srcpal = info->src_pal->colors;
int dstbpp;
int c;
Uint32 pixel;
@@ -920,14 +919,14 @@ SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface *surface)
{
int which;
- if (surface->map->dst->format->bits_per_pixel < 8) {
+ if (SDL_BITSPERPIXEL(surface->internal->map->dst->format) < 8) {
which = 0;
} else {
- which = surface->map->dst->format->bytes_per_pixel;
+ which = SDL_BYTESPERPIXEL(surface->internal->map->dst->format);
}
- if (SDL_PIXELTYPE(surface->format->format) == SDL_PIXELTYPE_INDEX1) {
- switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) {
+ if (SDL_PIXELTYPE(surface->format) == SDL_PIXELTYPE_INDEX1) {
+ switch (surface->internal->map->info.flags & ~SDL_COPY_RLE_MASK) {
case 0:
return bitmap_blit_1b[which];
@@ -943,8 +942,8 @@ SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface *surface)
return NULL;
}
- if (SDL_PIXELTYPE(surface->format->format) == SDL_PIXELTYPE_INDEX2) {
- switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) {
+ if (SDL_PIXELTYPE(surface->format) == SDL_PIXELTYPE_INDEX2) {
+ switch (surface->internal->map->info.flags & ~SDL_COPY_RLE_MASK) {
case 0:
return bitmap_blit_2b[which];
@@ -960,8 +959,8 @@ SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface *surface)
return NULL;
}
- if (SDL_PIXELTYPE(surface->format->format) == SDL_PIXELTYPE_INDEX4) {
- switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) {
+ if (SDL_PIXELTYPE(surface->format) == SDL_PIXELTYPE_INDEX4) {
+ switch (surface->internal->map->info.flags & ~SDL_COPY_RLE_MASK) {
case 0:
return bitmap_blit_4b[which];
diff --git a/src/video/SDL_blit_1.c b/src/video/SDL_blit_1.c
index 6048dec5dfc563..9ed0bc37cdbc61 100644
--- a/src/video/SDL_blit_1.c
+++ b/src/video/SDL_blit_1.c
@@ -431,8 +431,8 @@ static void Blit1toNAlpha(SDL_BlitInfo *info)
int srcskip = info->src_skip;
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
- const SDL_Color *srcpal = info->src_fmt->palette->colors;
+ const SDL_PixelFormatDetails *dstfmt = info->dst_fmt;
+ const SDL_Color *srcpal = info->src_pal->colors;
int dstbpp;
Uint32 pixel;
unsigned sR, sG, sB, sA;
@@ -471,8 +471,8 @@ static void Blit1toNAlphaKey(SDL_BlitInfo *info)
int srcskip = info->src_skip;
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
- const SDL_Color *srcpal = info->src_fmt->palette->colors;
+ const SDL_PixelFormatDetails *dstfmt = info->dst_fmt;
+ const SDL_Color *srcpal = info->src_pal->colors;
Uint32 ckey = info->colorkey;
int dstbpp;
Uint32 pixel;
@@ -517,15 +517,14 @@ static const SDL_BlitFunc one_blitkey[] = {
SDL_BlitFunc SDL_CalculateBlit1(SDL_Surface *surface)
{
int which;
- SDL_PixelFormat *dstfmt;
- dstfmt = surface->map->dst->format;
- if (dstfmt->bits_per_pixel < 8) {
+ if (SDL_BITSPERPIXEL(surface->internal->map->dst->format) < 8) {
which = 0;
} else {
- which = dstfmt->bytes_per_pixel;
+ which = SDL_BYTESPERPIXEL(surface->internal->map->dst->format);
}
- switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) {
+
+ switch (surface->internal->map->info.flags & ~SDL_COPY_RLE_MASK) {
case 0:
return one_blit[which];
@@ -533,7 +532,7 @@ SDL_BlitFunc SDL_CalculateBlit1(SDL_Surface *surface)
return one_blitkey[which];
case SDL_COPY_COLORKEY | SDL_COPY_BLEND: /* this is not super-robust but handles a specific case we found sdl12-compat. */
- return (surface->map->info.a == 255) ? one_blitkey[which] :
+ return (surface->internal->map->info.a == 255) ? one_blitkey[which] :
which >= 2 ? Blit1toNAlphaKey : (SDL_BlitFunc)NULL;
case SDL_COPY_BLEND:
diff --git a/src/video/SDL_blit_A.c b/src/video/SDL_blit_A.c
index d87e752478a72a..87478299ad3db5 100644
--- a/src/video/SDL_blit_A.c
+++ b/src/video/SDL_blit_A.c
@@ -36,8 +36,8 @@ static void BlitNto1SurfaceAlpha(SDL_BlitInfo *info)
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
Uint8 *palmap = info->table;
- SDL_PixelFormat *srcfmt = info->src_fmt;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
+ const SDL_Color *dstpal = info->dst_pal->colors;
int srcbpp = srcfmt->bytes_per_pixel;
Uint32 Pixel;
unsigned sR, sG, sB;
@@ -49,9 +49,9 @@ static void BlitNto1SurfaceAlpha(SDL_BlitInfo *info)
DUFFS_LOOP4(
{
DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
- dR = dstfmt->palette->colors[*dst].r;
- dG = dstfmt->palette->colors[*dst].g;
- dB = dstfmt->palette->colors[*dst].b;
+ dR = dstpal[*dst].r;
+ dG = dstpal[*dst].g;
+ dB = dstpal[*dst].b;
ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB);
dR &= 0xff;
dG &= 0xff;
@@ -82,8 +82,8 @@ static void BlitNto1PixelAlpha(SDL_BlitInfo *info)
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
Uint8 *palmap = info->table;
- SDL_PixelFormat *srcfmt = info->src_fmt;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
+ const SDL_Color *dstpal = info->dst_pal->colors;
int srcbpp = srcfmt->bytes_per_pixel;
Uint32 Pixel;
unsigned sR, sG, sB, sA;
@@ -94,9 +94,9 @@ static void BlitNto1PixelAlpha(SDL_BlitInfo *info)
DUFFS_LOOP4(
{
DISEMBLE_RGBA(src,srcbpp,srcfmt,Pixel,sR,sG,sB,sA);
- dR = dstfmt->palette->colors[*dst].r;
- dG = dstfmt->palette->colors[*dst].g;
- dB = dstfmt->palette->colors[*dst].b;
+ dR = dstpal[*dst].r;
+ dG = dstpal[*dst].g;
+ dB = dstpal[*dst].b;
ALPHA_BLEND_RGB(sR, sG, sB, sA, dR, dG, dB);
dR &= 0xff;
dG &= 0xff;
@@ -127,8 +127,8 @@ static void BlitNto1SurfaceAlphaKey(SDL_BlitInfo *info)
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
Uint8 *palmap = info->table;
- SDL_PixelFormat *srcfmt = info->src_fmt;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
+ const SDL_Color *dstpal = info->dst_pal->colors;
int srcbpp = srcfmt->bytes_per_pixel;
Uint32 ckey = info->colorkey;
Uint32 Pixel;
@@ -142,9 +142,9 @@ static void BlitNto1SurfaceAlphaKey(SDL_BlitInfo *info)
{
DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
if ( Pixel != ckey ) {
- dR = dstfmt->palette->colors[*dst].r;
- dG = dstfmt->palette->colors[*dst].g;
- dB = dstfmt->palette->colors[*dst].b;
+ dR = dstpal[*dst].r;
+ dG = dstpal[*dst].g;
+ dB = dstpal[*dst].b;
ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB);
dR &= 0xff;
dG &= 0xff;
@@ -864,8 +864,8 @@ static void BlitNtoNSurfaceAlpha(SDL_BlitInfo *info)
int srcskip = info->src_skip;
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
- SDL_PixelFormat *srcfmt = info->src_fmt;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
+ const SDL_PixelFormatDetails *dstfmt = info->dst_fmt;
int srcbpp = srcfmt->bytes_per_pixel;
int dstbpp = dstfmt->bytes_per_pixel;
Uint32 Pixel;
@@ -902,8 +902,8 @@ static void BlitNtoNSurfaceAlphaKey(SDL_BlitInfo *info)
int srcskip = info->src_skip;
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
- SDL_PixelFormat *srcfmt = info->src_fmt;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
+ const SDL_PixelFormatDetails *dstfmt = info->dst_fmt;
Uint32 ckey = info->colorkey;
int srcbpp = srcfmt->bytes_per_pixel;
int dstbpp = dstfmt->bytes_per_pixel;
@@ -942,7 +942,7 @@ static void Blit8888to8888PixelAlpha(SDL_BlitInfo *info)
int srcskip = info->src_skip;
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
- SDL_PixelFormat *srcfmt = info->src_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
while (height--) {
int i = 0;
@@ -970,8 +970,8 @@ static void Blit8888to8888PixelAlphaSwizzle(SDL_BlitInfo *info)
int srcskip = info->src_skip;
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
- SDL_PixelFormat *srcfmt = info->src_fmt;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
+ const SDL_PixelFormatDetails *dstfmt = info->dst_fmt;
while (height--) {
int i = 0;
@@ -1000,8 +1000,8 @@ static void SDL_TARGETING("sse4.1") Blit8888to8888PixelAlphaSwizzleSSE41(SDL_Bli
int srcskip = info->src_skip;
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
- SDL_PixelFormat *srcfmt = info->src_fmt;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
+ const SDL_PixelFormatDetails *dstfmt = info->dst_fmt;
// The byte offsets for the start of each pixel
const __m128i mask_offsets = _mm_set_epi8(
@@ -1092,8 +1092,8 @@ static void SDL_TARGETING("avx2") Blit8888to8888PixelAlphaSwizzleAVX2(SDL_BlitIn
int srcskip = info->src_skip;
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
- SDL_PixelFormat *srcfmt = info->src_fmt;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
+ const SDL_PixelFormatDetails *dstfmt = info->dst_fmt;
// The byte offsets for the start of each pixel
const __m256i mask_offsets = _mm256_set_epi8(
@@ -1183,8 +1183,8 @@ static void BlitNtoNPixelAlpha(SDL_BlitInfo *info)
int srcskip = info->src_skip;
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
- SDL_PixelFormat *srcfmt = info->src_fmt;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
+ const SDL_PixelFormatDetails *dstfmt = info->dst_fmt;
int srcbpp;
int dstbpp;
Uint32 Pixel;
@@ -1216,15 +1216,15 @@ static void BlitNtoNPixelAlpha(SDL_BlitInfo *info)
SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface *surface)
{
- SDL_PixelFormat *sf = surface->format;
- SDL_PixelFormat *df = surface->map->dst->format;
+ const SDL_PixelFormatDetails *sf = surface->internal->format;
+ const SDL_PixelFormatDetails *df = surface->internal->map->dst->internal->format;
- switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) {
+ switch (surface->internal->map->info.flags & ~SDL_COPY_RLE_MASK) {
case SDL_COPY_BLEND:
/* Per-pixel alpha blits */
switch (df->bytes_per_pixel) {
case 1:
- if (df->palette) {
+ if (surface->internal->map->info.dst_pal) {
return BlitNto1PixelAlpha;
} else {
/* RGB332 has no palette ! */
@@ -1273,7 +1273,7 @@ SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface *surface)
/* Per-surface alpha blits */
switch (df->bytes_per_pixel) {
case 1:
- if (df->palette) {
+ if (surface->internal->map->info.dst_pal) {
return BlitNto1SurfaceAlpha;
} else {
/* RGB332 has no palette ! */
@@ -1281,7 +1281,7 @@ SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface *surface)
}
case 2:
- if (surface->map->identity) {
+ if (surface->internal->map->identity) {
if (df->Gmask == 0x7e0) {
#ifdef SDL_MMX_INTRINSICS
if (SDL_HasMMX()) {
@@ -1328,7 +1328,7 @@ SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface *surface)
if (sf->Amask == 0) {
if (df->bytes_per_pixel == 1) {
- if (df->palette) {
+ if (surface->internal->map->info.dst_pal) {
return BlitNto1SurfaceAlphaKey;
} else {
/* RGB332 has no palette ! */
diff --git a/src/video/SDL_blit_N.c b/src/video/SDL_blit_N.c
index 64a051e1489d38..fede0c6f56d986 100644
--- a/src/video/SDL_blit_N.c
+++ b/src/video/SDL_blit_N.c
@@ -117,7 +117,7 @@ static size_t GetL3CacheSize(void)
: vec_add(vec_lvsl(8, src), vec_splat_u8(8)))
/* Calculate the permute vector used for 32->32 swizzling */
-static vector unsigned char calc_swizzle32(const SDL_PixelFormat *srcfmt, const SDL_PixelFormat *dstfmt)
+static vector unsigned char calc_swizzle32(const const SDL_PixelFormatDetails *srcfmt, const const SDL_PixelFormatDetails *dstfmt)
{
/*
* We have to assume that the bits that aren't used by other
@@ -201,7 +201,7 @@ static void Blit_XRGB8888_RGB565Altivec(SDL_BlitInfo *info)
int srcskip = info->src_skip;
Uint8 *dst = (Uint8 *)info->dst;
int dstskip = info->dst_skip;
- SDL_PixelFormat *srcfmt = info->src_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
vector unsigned char valpha = vec_splat_u8(0);
vector unsigned char vpermute = calc_swizzle32(srcfmt, NULL);
vector unsigned char vgmerge = VECUINT8_LITERAL(0x00, 0x02, 0x00, 0x06,
@@ -302,8 +302,8 @@ static void Blit_RGB565_32Altivec(SDL_BlitInfo *info)
int srcskip = info->src_skip;
Uint8 *dst = (Uint8 *)info->dst;
int dstskip = info->dst_skip;
- SDL_PixelFormat *srcfmt = info->src_fmt;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
+ const SDL_PixelFormatDetails *dstfmt = info->dst_fmt;
unsigned alpha;
vector unsigned char valpha;
vector unsigned char vpermute;
@@ -440,8 +440,8 @@ static void Blit_RGB555_32Altivec(SDL_BlitInfo *info)
int srcskip = info->src_skip;
Uint8 *dst = (Uint8 *)info->dst;
int dstskip = info->dst_skip;
- SDL_PixelFormat *srcfmt = info->src_fmt;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
+ const SDL_PixelFormatDetails *dstfmt = info->dst_fmt;
unsigned alpha;
vector unsigned char valpha;
vector unsigned char vpermute;
@@ -580,9 +580,9 @@ static void Blit32to32KeyAltivec(SDL_BlitInfo *info)
int srcskip = info->src_skip / 4;
Uint32 *dstp = (Uint32 *)info->dst;
int dstskip = info->dst_skip / 4;
- SDL_PixelFormat *srcfmt = info->src_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
int srcbpp = srcfmt->bytes_per_pixel;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *dstfmt = info->dst_fmt;
int dstbpp = dstfmt->bytes_per_pixel;
int copy_alpha = (srcfmt->Amask && dstfmt->Amask);
unsigned alpha = dstfmt->Amask ? info->a : 0;
@@ -702,8 +702,8 @@ static void ConvertAltivec32to32_noprefetch(SDL_BlitInfo *info)
int srcskip = info->src_skip / 4;
Uint32 *dst = (Uint32 *)info->dst;
int dstskip = info->dst_skip / 4;
- SDL_PixelFormat *srcfmt = info->src_fmt;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
+ const SDL_PixelFormatDetails *dstfmt = info->dst_fmt;
vector unsigned int vzero = vec_splat_u32(0);
vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt);
if (dstfmt->Amask && !srcfmt->Amask) {
@@ -788,8 +788,8 @@ static void ConvertAltivec32to32_prefetch(SDL_BlitInfo *info)
int srcskip = info->src_skip / 4;
Uint32 *dst = (Uint32 *)info->dst;
int dstskip = info->dst_skip / 4;
- SDL_PixelFormat *srcfmt = info->src_fmt;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
+ const SDL_PixelFormatDetails *dstfmt = info->dst_fmt;
vector unsigned int vzero = vec_splat_u32(0);
vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt);
if (dstfmt->Amask && !srcfmt->Amask) {
@@ -2064,9 +2064,9 @@ static void Blit_RGB555_ARGB1555(SDL_BlitInfo *info)
int srcskip = info->src_skip;
Uint16 *dst = (Uint16 *)info->dst;
int dstskip = info->dst_skip;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *dstfmt = info->dst_fmt;
- Uint16 mask = ((Uint32)info->a >> dstfmt->Aloss) << dstfmt->Ashift;
+ Uint16 mask = ((Uint32)info->a >> (8 - dstfmt->Abits)) << dstfmt->Ashift;
while (height--) {
/* *INDENT-OFF* */ /* clang-format off */
@@ -2096,7 +2096,7 @@ static void BlitNto1(SDL_BlitInfo *info)
int srcbpp;
Uint32 Pixel;
int sR, sG, sB;
- SDL_PixelFormat *srcfmt;
+ const SDL_PixelFormatDetails *srcfmt;
/* Set up some basic variables */
width = info->dst_w;
@@ -2183,12 +2183,12 @@ static void Blit4to4MaskAlpha(SDL_BlitInfo *info)
int srcskip = info->src_skip;
Uint32 *dst = (Uint32 *)info->dst;
int dstskip = info->dst_skip;
- SDL_PixelFormat *srcfmt = info->src_fmt;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
+ const SDL_PixelFormatDetails *dstfmt = info->dst_fmt;
if (dstfmt->Amask) {
/* RGB->RGBA, SET_ALPHA */
- Uint32 mask = ((Uint32)info->a >> dstfmt->Aloss) << dstfmt->Ashift;
+ Uint32 mask = ((Uint32)info->a >> (8 - dstfmt->Abits)) << dstfmt->Ashift;
while (height--) {
/* *INDENT-OFF* */ /* clang-format off */
@@ -2224,7 +2224,7 @@ static void Blit4to4MaskAlpha(SDL_BlitInfo *info)
}
/* permutation for mapping srcfmt to dstfmt, overloading or not the alpha channel */
-static void get_permutation(SDL_PixelFormat *srcfmt, SDL_PixelFormat *dstfmt,
+static void get_permutation(const SDL_PixelFormatDetails *srcfmt, const SDL_PixelFormatDetails *dstfmt,
int *_p0, int *_p1, int *_p2, int *_p3, int *_alpha_channel)
{
int alpha_channel = 0, p0, p1, p2, p3;
@@ -2318,9 +2318,9 @@ static void BlitNtoN(SDL_BlitInfo *info)
int srcskip = info->src_skip;
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
- SDL_PixelFormat *srcfmt = info->src_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
int srcbpp = srcfmt->bytes_per_pixel;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *dstfmt = info->dst_fmt;
int dstbpp = dstfmt->bytes_per_pixel;
unsigned alpha = dstfmt->Amask ? info->a : 0;
@@ -2436,9 +2436,9 @@ static void BlitNtoNCopyAlpha(SDL_BlitInfo *info)
int srcskip = info->src_skip;
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
- SDL_PixelFormat *srcfmt = info->src_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
int srcbpp = srcfmt->bytes_per_pixel;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *dstfmt = info->dst_fmt;
int dstbpp = dstfmt->bytes_per_pixel;
int c;
@@ -2493,7 +2493,7 @@ static void BlitNto1Key(SDL_BlitInfo *info)
int srcskip = info->src_skip;
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
- SDL_PixelFormat *srcfmt = info->src_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
const Uint8 *palmap = info->table;
Uint32 ckey = info->colorkey;
Uint32 rgbmask = ~srcfmt->Amask;
@@ -2592,8 +2592,8 @@ static void BlitNtoNKey(SDL_BlitInfo *info)
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
Uint32 ckey = info->colorkey;
- SDL_PixelFormat *srcfmt = info->src_fmt;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
+ const SDL_PixelFormatDetails *dstfmt = info->dst_fmt;
int srcbpp = srcfmt->bytes_per_pixel;
int dstbpp = dstfmt->bytes_per_pixel;
unsigned alpha = dstfmt->Amask ? info->a : 0;
@@ -2863,8 +2863,8 @@ static void BlitNtoNKeyCopyAlpha(SDL_BlitInfo *info)
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
Uint32 ckey = info->colorkey;
- SDL_PixelFormat *srcfmt = info->src_fmt;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
+ const SDL_PixelFormatDetails *dstfmt = info->dst_fmt;
Uint32 rgbmask = ~srcfmt->Amask;
Uint8 srcbpp;
@@ -2965,7 +2965,7 @@ static void Blit2101010toN(SDL_BlitInfo *info)
int srcskip = info->src_skip;
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *dstfmt = info->dst_fmt;
int dstbpp = dstfmt->bytes_per_pixel;
Uint32 Pixel;
unsigned sR, sG, sB, sA;
@@ -2996,7 +2996,7 @@ static void BlitNto2101010(SDL_BlitInfo *info)
int srcskip = info->src_skip;
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
- SDL_PixelFormat *srcfmt = info->src_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
int srcbpp = srcfmt->bytes_per_pixel;
Uint32 Pixel;
unsigned sR, sG, sB, sA;
@@ -3027,9 +3027,9 @@ static void Blit_3or4_to_3or4__same_rgb(SDL_BlitInfo *info)
int srcskip = info->src_skip;
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
- SDL_PixelFormat *srcfmt = info->src_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
int srcbpp = srcfmt->bytes_per_pixel;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *dstfmt = info->dst_fmt;
int dstbpp = dstfmt->bytes_per_pixel;
if (dstfmt->Amask) {
@@ -3100,9 +3100,9 @@ static void Blit_3or4_to_3or4__inversed_rgb(SDL_BlitInfo *info)
int srcskip = info->src_skip;
Uint8 *dst = info->dst;
int dstskip = info->dst_skip;
- SDL_PixelFormat *srcfmt = info->src_fmt;
+ const SDL_PixelFormatDetails *srcfmt = info->src_fmt;
int srcbpp = srcfmt->bytes_per_pixel;
- SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *dstfmt = info->dst_fmt;
int dstbpp = dstfmt->bytes_per_pixel;
if (dstfmt->Amask) {
@@ -3336,22 +3336,22 @@ static const struct blit_table *const normal_blit[] = {
SDL_BlitFunc SDL_CalculateBlitN(SDL_Surface *surface)
{
- SDL_PixelFormat *srcfmt;
- SDL_PixelFormat *dstfmt;
+ const SDL_PixelFormatDetails *srcfmt;
+ const SDL_PixelFormatDetails *dstfmt;
const struct blit_table *table;
int which;
SDL_BlitFunc blitfun;
/* Set up data for choosing the blit */
- srcfmt = surface->format;
- dstfmt = surface->map->dst->format;
+ srcfmt = surface->internal->format;
+ dstfmt = surface->internal->map->dst->internal->format;
/* We don't support destinations less than 8-bits */
if (dstfmt->bits_per_pixel < 8) {
return NULL;
}
- switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) {
+ switch (surface->internal->map->info.flags & ~SDL_COPY_RLE_MASK) {
case 0:
blitfun = NULL;
if (dstfmt->bits_per_pixel == 8) {
@@ -3427,7 +3427,7 @@ SDL_BlitFunc SDL_CalculateBlitN(SDL_Surface *surface)
because RLE is the preferred fast way to deal with this.
If a particular case turns out to be useful we'll add it. */
- if (srcfmt->bytes_per_pixel == 2 && surface->map->identity != 0) {
+ if (srcfmt->bytes_per_pixel == 2 && surface->internal->map->identity != 0) {
return Blit2to2Key;
} else if (dstfmt->bytes_per_pixel == 1) {
return BlitNto1Key;
diff --git a/src/video/SDL_blit_slow.c b/src/video/SDL_blit_slow.c
index 31eb1ae974dc80..7bdb090dc60a12 100644
--- a/src/video/SDL_blit_slow.c
+++ b/src/video/SDL_blit_slow.c
@@ -32,13 +32,13 @@ typedef enum
SlowBlitPixelAccess_Large,
} SlowBlitPixelAccess;
-static SlowBlitPixelAccess GetPixelAccessMethod(SDL_PixelFormat *pf)
+static SlowBlitPixelAccess GetPixelAccessMethod(SDL_PixelFormat format)
{
- if (pf->bytes_per_pixel > 4) {
+ if (SDL_BYTESPERPIXEL(format) > 4) {
return SlowBlitPixelAccess_Large;
- } else if (SDL_ISPIXELFORMAT_10BIT(pf->format)) {
+ } else if (SDL_ISPIXELFORMAT_10BIT(format)) {
return SlowBlitPixelAccess_10Bit;
- } else if (pf->Amask) {
+ } else if (SDL_ISPIXELFORMAT_ALPHA(format)) {
return SlowBlitPixelAccess_RGBA;
} else {
return SlowBlitPixelAccess_RGB;
@@ -62,8 +62,8 @@ void SDL_Blit_Slow(SDL_BlitInfo *info)
Uint64 srcy, srcx;
Uint64 posy, posx;
Uint64 incy, incx;
- SDL_PixelFormat *src_fmt = info->src_fmt;
- SDL_PixelFormat *dst_fmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *src_fmt = info->src_fmt;
+ const SDL_PixelFormatDetails *dst_fmt = info->dst_fmt;
int srcbpp = src_fmt->bytes_per_pixel;
int dstbpp = dst_fmt->bytes_per_pixel;
SlowBlitPixelAccess src_access;
@@ -71,8 +71,8 @@ void SDL_Blit_Slow(SDL_BlitInfo *info)
Uint32 rgbmask = ~src_fmt->Amask;
Uint32 ckey = info->colorkey & rgbmask;
- src_access = GetPixelAccessMethod(src_fmt);
- dst_access = GetPixelAccessMethod(dst_fmt);
+ src_access = GetPixelAccessMethod(src_fmt->format);
+ dst_access = GetPixelAccessMethod(dst_fmt->format);
incy = ((Uint64)info->src_h << 16) / info->dst_h;
incx = ((Uint64)info->src_w << 16) / info->dst_w;
@@ -370,7 +370,7 @@ static Uint16 float_to_half(float a)
return ir;
}
-static void ReadFloatPixel(Uint8 *pixels, SlowBlitPixelAccess access, SDL_PixelFormat *fmt, SDL_Colorspace colorspace, float SDR_white_point,
+static void ReadFloatPixel(Uint8 *pixels, SlowBlitPixelAccess access, const SDL_PixelFormatDetails *fmt, SDL_Colorspace colorspace, float SDR_white_point,
float *outR, float *outG, float *outB, float *outA)
{
Uint32 pixel;
@@ -525,7 +525,7 @@ static void ReadFloatPixel(Uint8 *pixels, SlowBlitPixelAccess access, SDL_PixelF
*outA = fA;
}
-static void WriteFloatPixel(Uint8 *pixels, SlowBlitPixelAccess access, SDL_PixelFormat *fmt, SDL_Colorspace colorspace, float SDR_white_point,
+static void WriteFloatPixel(Uint8 *pixels, SlowBlitPixelAccess access, const SDL_PixelFormatDetails *fmt, SDL_Colorspace colorspace, float SDR_white_point,
float fR, float fG, float fB, float fA)
{
Uint32 R, G, B, A;
@@ -755,8 +755,8 @@ void SDL_Blit_Slow_Float(SDL_BlitInfo *info)
Uint64 srcy, srcx;
Uint64 posy, posx;
Uint64 incy, incx;
- SDL_PixelFormat *src_fmt = info->src_fmt;
- SDL_PixelFormat *dst_fmt = info->dst_fmt;
+ const SDL_PixelFormatDetails *src_fmt = info->src_fmt;
+ const SDL_PixelFormatDetails *dst_fmt = info->dst_fmt;
int srcbpp = src_fmt->bytes_per_pixel;
int dstbpp = dst_fmt->bytes_per_pixel;
SlowBlitPixelAccess src_access;
@@ -772,8 +772,10 @@ void SDL_Blit_Slow_Float(SDL_BlitInfo *info)
float src_headroom;
SDL_TonemapContext tonemap;
- if (SDL_GetSurfaceColorspace(info->src_surface, &src_colorspace) < 0 ||
- SDL_GetSurfaceColorspace(info->dst_surface, &dst_colorspace) < 0) {
+ src_colorspace = SDL_GetSurfaceColorspace(info->src_surface);
+ dst_colorspace = SDL_GetSurfaceColorspace(info->dst_surface);
+ if (src_colorspace == SDL_COLORSPACE_UNKNOWN ||
+ dst_colorspace == SDL_COLORSPACE_UNKNOWN) {
return;
}
src_primaries = SDL_COLORSPACEPRIMARIES(src_colorspace);
@@ -821,8 +823,8 @@ void SDL_Blit_Slow_Float(SDL_BlitInfo *info)
color_primaries_matrix = SDL_GetColorPrimariesConversionMatrix(src_primaries, dst_primaries);
}
- src_access = GetPixelAccessMethod(src_fmt);
- dst_access = GetPixelAccessMethod(dst_fmt);
+ src_access = GetPixelAccessMethod(src_fmt->format);
+ dst_access = GetPixelAccessMethod(dst_fmt->format);
incy = ((Uint64)info->src_h << 16) / info->dst_h;
incx = ((Uint64)info->src_w << 16) / info->dst_w;
diff --git a/src/video/SDL_bmp.c b/src/video/SDL_bmp.c
index 1d80cbd13c3d4e..ebdef5ed904f3c 100644
--- a/src/video/SDL_bmp.c
+++ b/src/video/SDL_bmp.c
@@ -427,10 +427,10 @@ SDL_Surface *SDL_LoadBMP_IO(SDL_IOStream *src, SDL_bool closeio)
/* Create a compatible surface, note that the colors are RGB ordered */
{
- SDL_PixelFormatEnum format;
+ SDL_PixelFormat format;
/* Get the pixel format */
- format = SDL_GetPixelFormatEnumForMasks(biBitCount, Rmask, Gmask, Bmask, Amask);
+ format = SDL_GetPixelFormatForMasks(biBitCount, Rmask, Gmask, Bmask, Amask);
surface = SDL_CreateSurface(biWidth, biHeight, format);
if (!surface) {
@@ -439,7 +439,7 @@ SDL_Surface *SDL_LoadBMP_IO(SDL_IOStream *src, SDL_bool closeio)
}
/* Load the palette, if any */
- palette = (surface->format)->palette;
+ palette = SDL_GetSurfacePalette(surface);
if (palette) {
if (SDL_SeekIO(src, fp_offset + 14 + biSize, SDL_IO_SEEK_SET) < 0) {
SDL_SetError("Error seeking in datastream");
@@ -632,42 +632,42 @@ int SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, SDL_bool closeio)
/* Make sure we have somewhere to save */
intermediate_surface = NULL;
if (dst) {
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
SDL_InvalidParamError("surface");
goto done;
}
#ifdef SAVE_32BIT_BMP
/* We can save alpha information in a 32-bit BMP */
- if (surface->format->bits_per_pixel >= 8 &&
- (surface->format->Amask != 0 ||
- surface->map->info.flags & SDL_COPY_COLORKEY)) {
+ if (SDL_BITSPERPIXEL(surface->format) >= 8 &&
+ (SDL_ISPIXELFORMAT_ALPHA(surface->format) ||
+ surface->internal->map->info.flags & SDL_COPY_COLORKEY)) {
save32bit = SDL_TRUE;
}
#endif /* SAVE_32BIT_BMP */
- if (surface->format->palette && !save32bit) {
- if (surface->format->bits_per_pixel == 8) {
+ if (surface->internal->palette && !save32bit) {
+ if (SDL_BITSPERPIXEL(surface->format) == 8) {
intermediate_surface = surface;
} else {
SDL_SetError("%u bpp BMP files not supported",
- surface->format->bits_per_pixel);
+ SDL_BITSPERPIXEL(surface->format));
goto done;
}
- } else if ((surface->format->bits_per_pixel == 24) && !save32bit &&
+ } else if ((SDL_BITSPERPIXEL(surface->format) == 24) && !save32bit &&
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
- (surface->format->Rmask == 0x00FF0000) &&
- (surface->format->Gmask == 0x0000FF00) &&
- (surface->format->Bmask == 0x000000FF)
+ (surface->internal->format->Rmask == 0x00FF0000) &&
+ (surface->internal->format->Gmask == 0x0000FF00) &&
+ (surface->internal->format->Bmask == 0x000000FF)
#else
- (surface->format->Rmask == 0x000000FF) &&
- (surface->format->Gmask == 0x0000FF00) &&
- (surface->format->Bmask == 0x00FF0000)
+ (surface->internal->format->Rmask == 0x000000FF) &&
+ (surface->internal->format->Gmask == 0x0000FF00) &&
+ (surface->internal->format->Bmask == 0x00FF0000)
#endif
) {
intermediate_surface = surface;
} else {
- SDL_PixelFormatEnum pixel_format;
+ SDL_PixelFormat pixel_format;
/* If the surface has a colorkey or alpha channel we'll save a
32-bit BMP with alpha channel, otherwise save a 24-bit BMP. */
@@ -676,7 +676,7 @@ int SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, SDL_bool closeio)
} else {
pixel_format = SDL_PIXELFORMAT_BGR24;
}
- intermediate_surface = SDL_ConvertSurfaceFormat(surface, pixel_format);
+ intermediate_surface = SDL_ConvertSurface(surface, pixel_format);
if (!intermediate_surface) {
SDL_SetError("Couldn't convert image to %d bpp",
(int)SDL_BITSPERPIXEL(pixel_format));
@@ -694,7 +694,7 @@ int SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, SDL_bool closeio)
}
if (SDL_LockSurface(intermediate_surface) == 0) {
- const size_t bw = intermediate_surface->w * intermediate_surface->format->bytes_per_pixel;
+ const size_t bw = intermediate_surface->w * intermediate_surface->internal->format->bytes_per_pixel;
/* Set the BMP file header values */
bfSize = 0; /* We'll write this when we're done */
@@ -720,13 +720,13 @@ int SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, SDL_bool closeio)
biWidth = intermediate_surface->w;
biHeight = intermediate_surface->h;
biPlanes = 1;
- biBitCount = intermediate_surface->format->bits_per_pixel;
+ biBitCount = intermediate_surface->internal->format->bits_per_pixel;
biCompression = BI_RGB;
biSizeImage = intermediate_surface->h * intermediate_surface->pitch;
biXPelsPerMeter = 0;
biYPelsPerMeter = 0;
- if (intermediate_surface->format->palette) {
- biClrUsed = intermediate_surface->format->palette->ncolors;
+ if (intermediate_surface->internal->palette) {
+ biClrUsed = intermediate_surface->internal->palette->ncolors;
} else {
biClrUsed = 0;
}
@@ -784,12 +784,12 @@ int SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, SDL_bool closeio)
}
/* Write the palette (in BGR color order) */
- if (intermediate_surface->format->palette) {
+ if (intermediate_surface->internal->palette) {
SDL_Color *colors;
int ncolors;
- colors = intermediate_surface->format->palette->colors;
- ncolors = intermediate_surface->format->palette->ncolors;
+ colors = intermediate_surface->internal->palette->colors;
+ ncolors = intermediate_surface->internal->palette->ncolors;
for (i = 0; i < ncolors; ++i) {
if (!SDL_WriteU8(dst, colors[i].b) ||
!SDL_WriteU8(dst, colors[i].g) ||
diff --git a/src/video/SDL_fillrect.c b/src/video/SDL_fillrect.c
index f47572032405dc..f0eb67d108e798 100644
--- a/src/video/SDL_fillrect.c
+++ b/src/video/SDL_fillrect.c
@@ -231,13 +231,13 @@ static void SDL_FillSurfaceRect4(Uint8 *pixels, int pitch, Uint32 color, int w,
*/
int SDL_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color)
{
- if (!dst) {
+ if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_FillSurfaceRect(): dst");
}
/* If 'rect' == NULL, then fill the whole surface */
if (!rect) {
- rect = &dst->clip_rect;
+ rect = &dst->internal->clip_rect;
/* Don't attempt to fill if the surface's clip_rect is empty */
if (SDL_RectEmpty(rect)) {
return 0;
@@ -256,7 +256,7 @@ int SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
void (*fill_function)(Uint8 * pixels, int pitch, Uint32 color, int w, int h) = NULL;
int i;
- if (!dst) {
+ if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_FillSurfaceRects(): dst");
}
@@ -277,11 +277,11 @@ int SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
/* This function doesn't usually work on surfaces < 8 bpp
* Except: support for 4bits, when filling full size.
*/
- if (dst->format->bits_per_pixel < 8) {
+ if (SDL_BITSPERPIXEL(dst->format) < 8) {
if (count == 1) {
const SDL_Rect *r = &rects[0];
if (r->x == 0 && r->y == 0 && r->w == dst->w && r->h == dst->h) {
- if (dst->format->bits_per_pixel == 4) {
+ if (SDL_BITSPERPIXEL(dst->format) == 4) {
Uint8 b = (((Uint8)color << 4) | (Uint8)color);
SDL_memset(dst->pixels, b, (size_t)dst->h * dst->pitch);
return 1;
@@ -292,7 +292,7 @@ int SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
}
if (fill_function == NULL) {
- switch (dst->format->bytes_per_pixel) {
+ switch (SDL_BYTESPERPIXEL(dst->format)) {
case 1:
{
color |= (color << 8);
@@ -347,13 +347,13 @@ int SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
for (i = 0; i < count; ++i) {
rect = &rects[i];
/* Perform clipping */
- if (!SDL_GetRectIntersection(rect, &dst->clip_rect, &clipped)) {
+ if (!SDL_GetRectIntersection(rect, &dst->internal->clip_rect, &clipped)) {
continue;
}
rect = &clipped;
pixels = (Uint8 *)dst->pixels + rect->y * dst->pitch +
- rect->x * dst->format->bytes_per_pixel;
+ rect->x * SDL_BYTESPERPIXEL(dst->format);
fill_function(pixels, dst->pitch, color, rect->w, rect->h);
}
diff --git a/src/video/SDL_pixels.c b/src/video/SDL_pixels.c
index 0e06737a5d94ec..41f4769a74cc59 100644
--- a/src/video/SDL_pixels.c
+++ b/src/video/SDL_pixels.c
@@ -26,24 +26,25 @@
#include "SDL_blit.h"
#include "SDL_pixels_c.h"
#include "SDL_RLEaccel_c.h"
+#include "../SDL_hashtable.h"
#include "../SDL_list.h"
/* Lookup tables to expand partial bytes to the full 0..255 range */
static const Uint8 lookup_0[] = {
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
+ 255
};
static const Uint8 lookup_1[] = {
- 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194, 196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 255
+ 0, 255
};
static const Uint8 lookup_2[] = {
- 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 85, 89, 93, 97, 101, 105, 109, 113, 117, 121, 125, 129, 133, 137, 141, 145, 149, 153, 157, 161, 165, 170, 174, 178, 182, 186, 190, 194, 198, 202, 206, 210, 214, 218, 222, 226, 230, 234, 238, 242, 246, 250, 255
+ 0, 85, 170, 255
};
static const Uint8 lookup_3[] = {
- 0, 8, 16, 24, 32, 41, 49, 57, 65, 74, 82, 90, 98, 106, 115, 123, 131, 139, 148, 156, 164, 172, 180, 189, 197, 205, 213, 222, 230, 238, 246, 255
+ 0, 36, 72, 109, 145, 182, 218, 255
};
static const Uint8 lookup_4[] = {
@@ -51,19 +52,19 @@ static const Uint8 lookup_4[] = {
};
static const Uint8 lookup_5[] = {
- 0, 36, 72, 109, 145, 182, 218, 255
+ 0, 8, 16, 24, 32, 41, 49, 57, 65, 74, 82, 90, 98, 106, 115, 123, 131, 139, 148, 156, 164, 172, 180, 189, 197, 205, 213, 222, 230, 238, 246, 255
};
static const Uint8 lookup_6[] = {
- 0, 85, 170, 255
+ 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 85, 89, 93, 97, 101, 105, 109, 113, 117, 121, 125, 129, 133, 137, 141, 145, 149, 153, 157, 161, 165, 170, 174, 178, 182, 186, 190, 194, 198, 202, 206, 210, 214, 218, 222, 226, 230, 234, 238, 242, 246, 250, 255
};
static const Uint8 lookup_7[] = {
- 0, 255
+ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194, 196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 255
};
static const Uint8 lookup_8[] = {
- 255
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
};
const Uint8 *SDL_expand_byte[9] = {
@@ -91,7 +92,7 @@ SDL_COMPILE_TIME_ASSERT(SDL_expand_byte_10_size, SDL_arraysize(SDL_expand_byte_1
#define CASE(X) \
case X: \
return #X;
-const char *SDL_GetPixelFormatName(SDL_PixelFormatEnum format)
+const char *SDL_GetPixelFormatName(SDL_PixelFormat format)
{
switch (format) {
@@ -165,8 +166,7 @@ const char *SDL_GetPixelFormatName(SDL_PixelFormatEnum format)
}
#undef CASE
-SDL_bool SDL_GetMasksForPixelFormatEnum(SDL_PixelFormatEnum format, int *bpp, Uint32 *Rmask,
- Uint32 *Gmask, Uint32 *Bmask, Uint32 *Amask)
+int SDL_GetMasksForPixelFormat(SDL_PixelFormat format, int *bpp, Uint32 *Rmask, Uint32 *Gmask, Uint32 *Bmask, Uint32 *Amask)
{
Uint32 masks[4];
@@ -185,12 +185,11 @@ SDL_bool SDL_GetMasksForPixelFormatEnum(SDL_PixelFormatEnum format, int *bpp, Ui
default:
*bpp = 0; // oh well.
}
- return SDL_TRUE;
+ return 0;
}
#else
if (SDL_ISPIXELFORMAT_FOURCC(format)) {
- SDL_SetError("SDL not built with YUV support");
- return SDL_FALSE;
+ return SDL_SetError("SDL not built with YUV support");
}
#endif
@@ -212,7 +211,7 @@ SDL_bool SDL_GetMasksForPixelFormatEnum(SDL_PixelFormatEnum format, int *bpp, Ui
*Gmask = 0x0000FF00;
*Bmask = 0x00FF0000;
#endif
- return SDL_TRUE;
+ return 0;
}
if (format == SDL_PIXELFORMAT_BGR24) {
@@ -225,14 +224,14 @@ SDL_bool SDL_GetMasksForPixelFormatEnum(SDL_PixelFormatEnum format, int *bpp, Ui
*Gmask = 0x0000FF00;
*Bmask = 0x000000FF;
#endif
- return SDL_TRUE;
+ return 0;
}
if (SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED8 &&
SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED16 &&
SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED32) {
/* Not a format that uses masks */
- return SDL_TRUE;
+ return 0;
}
switch (SDL_PIXELLAYOUT(format)) {
@@ -285,8 +284,7 @@ SDL_bool SDL_GetMasksForPixelFormatEnum(SDL_PixelFormatEnum format, int *bpp, Ui
masks[3] = 0x00000003;
break;
default:
- SDL_SetError("Unknown pixel format");
- return SDL_FALSE;
+ return SDL_SetError("Unknown pixel format");
}
switch (SDL_PIXELORDER(format)) {
@@ -335,13 +333,12 @@ SDL_bool SDL_GetMasksForPixelFormatEnum(SDL_PixelFormatEnum format, int *bpp, Ui
*Rmask = masks[3];
break;
default:
- SDL_SetError("Unknown pixel format");
- return SDL_FALSE;
+ return SDL_SetError("Unknown pixel format");
}
- return SDL_TRUE;
+ return 0;
}
-SDL_PixelFormatEnum SDL_GetPixelFormatEnumForMasks(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
+SDL_PixelFormat SDL_GetPixelFormatForMasks(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
{
switch (bpp) {
case 1:
@@ -579,156 +576,117 @@ SDL_PixelFormatEnum SDL_GetPixelFormatEnumForMasks(int bpp, Uint32 Rmask, Uint32
return SDL_PIXELFORMAT_UNKNOWN;
}
-static SDL_PixelFormat *formats;
-static SDL_SpinLock formats_lock = 0;
-
-SDL_PixelFormat *SDL_CreatePixelFormat(SDL_PixelFormatEnum pixel_format)
-{
- SDL_PixelFormat *format;
-
- SDL_LockSpinlock(&formats_lock);
-
- /* Look it up in our list of previously allocated formats */
- for (format = formats; format; format = format->next) {
- if (pixel_format == format->format) {
- ++format->refcount;
- SDL_UnlockSpinlock(&formats_lock);
- return format;
- }
- }
-
- /* Allocate an empty pixel format structure, and initialize it */
- format = (SDL_PixelFormat *)SDL_malloc(sizeof(*format));
- if (!format) {
- SDL_UnlockSpinlock(&formats_lock);
- return NULL;
- }
- if (SDL_InitFormat(format, pixel_format) < 0) {
- SDL_UnlockSpinlock(&formats_lock);
- SDL_free(format);
- return NULL;
- }
+static SDL_HashTable *SDL_format_details;
- if (!SDL_ISPIXELFORMAT_INDEXED(pixel_format)) {
- /* Cache the RGB formats */
- format->next = formats;
- formats = format;
- }
-
- SDL_UnlockSpinlock(&formats_lock);
-
- return format;
-}
-
-int SDL_InitFormat(SDL_PixelFormat *format, SDL_PixelFormatEnum pixel_format)
+static int SDL_InitPixelFormatDetails(SDL_PixelFormatDetails *details, SDL_PixelFormat format)
{
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
Uint32 mask;
- if (!SDL_GetMasksForPixelFormatEnum(pixel_format, &bpp,
- &Rmask, &Gmask, &Bmask, &Amask)) {
+ if (SDL_GetMasksForPixelFormat(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask) < 0) {
return -1;
}
/* Set up the format */
- SDL_zerop(format);
- format->format = pixel_format;
- format->bits_per_pixel = (Uint8)bpp;
- format->bytes_per_pixel = (Uint8)((bpp + 7) / 8);
-
- format->Rmask = Rmask;
- format->Rshift = 0;
- format->Rloss = 8;
+ SDL_zerop(details);
+ details->format = format;
+ details->bits_per_pixel = (Uint8)bpp;
+ SDL_assert(SDL_BITSPERPIXEL(format) == details->bits_per_pixel);
+ details->bytes_per_pixel = (Uint8)((bpp + 7) / 8);
+ SDL_assert(SDL_BYTESPERPIXEL(format) == details->bytes_per_pixel);
+
+ details->Rmask = Rmask;
+ details->Rshift = 0;
+ details->Rbits = 0;
if (Rmask) {
for (mask = Rmask; !(mask & 0x01); mask >>= 1) {
- ++format->Rshift;
+ ++details->Rshift;
}
- for (; (mask & 0x01) && format->Rloss; mask >>= 1) {
- --format->Rloss;
+ for (; (mask & 0x01); mask >>= 1) {
+ ++details->Rbits;
}
}
- format->Gmask = Gmask;
- format->Gshift = 0;
- format->Gloss = 8;
+ details->Gmask = Gmask;
+ details->Gshift = 0;
+ details->Gbits = 0;
if (Gmask) {
for (mask = Gmask; !(mask & 0x01); mask >>= 1) {
- ++format->Gshift;
+ ++details->Gshift;
}
- for (; (mask & 0x01) && format->Gloss; mask >>= 1) {
- --format->Gloss;
+ for (; (mask & 0x01); mask >>= 1) {
+ ++details->Gbits;
}
}
- format->Bmask = Bmask;
- format->Bshift = 0;
- format->Bloss = 8;
+ details->Bmask = Bmask;
+ details->Bshift = 0;
+ details->Bbits = 0;
if (Bmask) {
for (mask = Bmask; !(mask & 0x01); mask >>= 1) {
- ++format->Bshift;
+ ++details->Bshift;
}
- for (; (mask & 0x01) && format->Bloss; mask >>= 1) {
- --format->Bloss;
+ for (; (mask & 0x01); mask >>= 1) {
+ ++details->Bbits;
}
}
- format->Amask = Amask;
- format->Ashift = 0;
- format->Aloss = 8;
+ details->Amask = Amask;
+ details->Ashift = 0;
+ details->Abits = 0;
if (Amask) {
for (mask = Amask; !(mask & 0x01); mask >>= 1) {
- ++format->Ashift;
+ ++details->Ashift;
}
- for (; (mask & 0x01) && format->Aloss; mask >>= 1) {
- --format->Aloss;
+ for (; (mask & 0x01); mask >>= 1) {
+ ++details->Abits;
}
}
- format->palette = NULL;
- format->refcount = 1;
- format->next = NULL;
-
return 0;
}
-void SDL_DestroyPixelFormat(SDL_PixelFormat *format)
+const SDL_PixelFormatDetails *SDL_GetPixelFormatDetails(SDL_PixelFormat format)
{
- SDL_PixelFormat *prev;
+ SDL_PixelFormatDetails *details;
- if (!format) {
- return;
+ if (!SDL_format_details) {
+ SDL_format_details = SDL_CreateHashTable(NULL, 8, SDL_HashID, SDL_KeyMatchID, SDL_NukeFreeValue, SDL_FALSE);
}
- SDL_LockSpinlock(&formats_lock);
+ if (SDL_FindInHashTable(SDL_format_details, (const void *)(uintptr_t)format, (const void **)&details)) {
+ return details;
+ }
- if (--format->refcount > 0) {
- SDL_UnlockSpinlock(&formats_lock);
- return;
+ /* Allocate an empty pixel format structure, and initialize it */
+ details = (SDL_PixelFormatDetails *)SDL_malloc(sizeof(*details));
+ if (!details) {
+ return NULL;
}
- /* Remove this format from our list */
- if (format == formats) {
- formats = format->next;
- } else if (formats) {
- for (prev = formats; prev->next; prev = prev->next) {
- if (prev->next == format) {
- prev->next = format->next;
- break;
- }
- }
+ if (SDL_InitPixelFormatDetails(details, format) < 0) {
+ SDL_free(details);
+ return NULL;
}
- SDL_UnlockSpinlock(&formats_lock);
+ if (!SDL_InsertIntoHashTable(SDL_format_details, (const void *)(uintptr_t)format, (void *)details)) {
+ SDL_free(details);
+ return NULL;
+ }
- if (format->palette) {
- SDL_DestroyPalette(format->palette);
+ return details;
+}
+
+void SDL_QuitPixelFormatDetails(void)
+{
+ if (SDL_format_details) {
+ SDL_DestroyHashTable(SDL_format_details);
+ SDL_format_details = NULL;
}
- SDL_free(format);
- return;
}
-SDL_Colorspace SDL_GetDefaultColorspaceForFormat(SDL_PixelFormatEnum format)
+SDL_Colorspace SDL_GetDefaultColorspaceForFormat(SDL_PixelFormat format)
{
if (SDL_ISPIXELFORMAT_FOURCC(format)) {
if (format == SDL_PIXELFORMAT_P010) {
@@ -1065,33 +1023,6 @@ SDL_Palette *SDL_CreatePalette(int ncolors)
return palette;
}
-int SDL_SetPixelFormatPalette(SDL_PixelFormat *format, SDL_Palette *palette)
-{
- if (!format) {
- return SDL_InvalidParamError("SDL_SetPixelFormatPalette(): format");
- }
-
- if (palette && palette->ncolors > (1 << format->bits_per_pixel)) {
- return SDL_SetError("SDL_SetPixelFormatPalette() passed a palette that doesn't match the format");
- }
-
- if (format->palette == palette) {
- return 0;
- }
-
- if (format->palette) {
- SDL_DestroyPalette(format->palette);
- }
-
- format->palette = palette;
-
- if (format->palette) {
- ++format->palette->refcount;
- }
-
- return 0;
-}
-
int SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors,
int firstcolor, int ncolors)
{
@@ -1161,7 +1092,7 @@ void SDL_DitherColors(SDL_Color *colors, int bpp)
/*
* Match an RGB value to a particular palette index
*/
-Uint8 SDL_FindColor(SDL_Palette *pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+Uint8 SDL_FindColor(const SDL_Palette *pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
/* Do colorspace distance matching */
unsigned int smallest;
@@ -1189,7 +1120,7 @@ Uint8 SDL_FindColor(SDL_Palette *pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
}
/* Tell whether palette is opaque, and if it has an alpha_channel */
-void SDL_DetectPalette(SDL_Palette *pal, SDL_bool *is_opaque, SDL_bool *has_alpha_channel)
+void SDL_DetectPalette(const SDL_Palette *pal, SDL_bool *is_opaque, SDL_bool *has_alpha_channel)
{
int i;
@@ -1235,111 +1166,140 @@ void SDL_DetectPalette(SDL_Palette *pal, SDL_bool *is_opaque, SDL_bool *has_alph
}
/* Find the opaque pixel value corresponding to an RGB triple */
-Uint32 SDL_MapRGB(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b)
+Uint32 SDL_MapRGB(SDL_PixelFormat format, SDL_Palette *palette, Uint8 r, Uint8 g, Uint8 b)
{
- if (!format) {
+ if (palette) {
+ return SDL_FindColor(palette, r, g, b, SDL_ALPHA_OPAQUE);
+ }
+
+ const SDL_PixelFormatDetails *fmt = SDL_GetPixelFormatDetails(format);
+ if (!fmt) {
SDL_InvalidParamError("format");
return 0;
}
- if (format->palette) {
- return SDL_FindColor(format->palette, r, g, b, SDL_ALPHA_OPAQUE);
- } else if (SDL_ISPIXELFORMAT_10BIT(format->format)) {
- return (((Uint32)SDL_expand_byte_10[r]) << format->Rshift) |
- (((Uint32)SDL_expand_byte_10[g]) << format->Gshift) |
- (((Uint32)SDL_expand_byte_10[b]) << format->Bshift) |
- format->Amask;
+
+ if (SDL_ISPIXELFORMAT_10BIT(format)) {
+ return (((Uint32)SDL_expand_byte_10[r]) << fmt->Rshift) |
+ (((Uint32)SDL_expand_byte_10[g]) << fmt->Gshift) |
+ (((Uint32)SDL_expand_byte_10[b]) << fmt->Bshift) |
+ fmt->Amask;
} else {
- return (r >> format->Rloss) << format->Rshift | (g >> format->Gloss) << format->Gshift | (b >> format->Bloss) << format->Bshift | format->Amask;
+ return ((Uint32)(r >> (8 - fmt->Rbits))) << fmt->Rshift |
+ ((Uint32)(g >> (8 - fmt->Gbits))) << fmt->Gshift |
+ ((Uint32)(b >> (8 - fmt->Bbits))) << fmt->Bshift |
+ fmt->Amask;
}
}
/* Find the pixel value corresponding to an RGBA quadruple */
-Uint32 SDL_MapRGBA(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b,
- Uint8 a)
+Uint32 SDL_MapRGBA(SDL_PixelFormat format, SDL_Palette *palette, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
- if (!format) {
+ if (palette) {
+ return SDL_FindColor(palette, r, g, b, a);
+ }
+
+ const SDL_PixelFormatDetails *fmt = SDL_GetPixelFormatDetails(format);
+ if (!fmt) {
SDL_InvalidParamError("format");
return 0;
}
- if (format->palette) {
- return SDL_FindColor(format->palette, r, g, b, a);
- } else if (SDL_ISPIXELFORMAT_10BIT(format->format)) {
- return (((Uint32)SDL_expand_byte_10[r]) << format->Rshift) |
- (((Uint32)SDL_expand_byte_10[g]) << format->Gshift) |
- (((Uint32)SDL_expand_byte_10[b]) << format->Bshift) |
- ((Uint32)(a >> format->Aloss) << format->Ashift & format->Amask);
+
+ if (SDL_ISPIXELFORMAT_10BIT(format)) {
+ return (((Uint32)SDL_expand_byte_10[r]) << fmt->Rshift) |
+ (((Uint32)SDL_expand_byte_10[g]) << fmt->Gshift) |
+ (((Uint32)SDL_expand_byte_10[b]) << fmt->Bshift) |
+ ((((Uint32)(a >> (8 - fmt->Abits))) << fmt->Ashift) & fmt->Amask);
} else {
- return (r >> format->Rloss) << format->Rshift | (g >> format->Gloss) << format->Gshift | (b >> format->Bloss) << format->Bshift | ((Uint32)(a >> format->Aloss) << format->Ashift & format->Amask);
+ return ((Uint32)(r >> (8 - fmt->Rbits))) << fmt->Rshift |
+ ((Uint32)(g >> (8 - fmt->Gbits))) << fmt->Gshift |
+ ((Uint32)(b >> (8 - fmt->Bbits))) << fmt->Bshift |
+ ((((Uint32)(a >> (8 - fmt->Abits))) << fmt->Ashift) & fmt->Amask);
}
}
-void SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat *format, Uint8 *r, Uint8 *g,
- Uint8 *b)
+void SDL_GetRGB(Uint32 pixel, SDL_PixelFormat format, SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b)
{
- if (format->palette) {
- if (pixel < (unsigned)format->palette->ncolors) {
- *r = format->palette->colors[pixel].r;
- *g = format->palette->colors[pixel].g;
- *b = format->palette->colors[pixel].b;
+ if (palette) {
+ if (pixel < (unsigned)palette->ncolors) {
+ *r = palette->colors[pixel].r;
+ *g = palette->colors[pixel].g;
+ *b = palette->colors[pixel].b;
} else {
*r = *g = *b = 0;
}
- } else if (SDL_ISPIXELFORMAT_10BIT(format->format)) {
+ return;
+ }
+
+ const SDL_PixelFormatDetails *fmt = SDL_GetPixelFormatDetails(format);
+ if (!fmt) {
+ *r = *g = *b = 0;
+ return;
+ }
+
+ if (SDL_ISPIXELFORMAT_10BIT(format)) {
unsigned v;
- v = (pixel & format->Rmask) >> format->Rshift;
+ v = (pixel & fmt->Rmask) >> fmt->Rshift;
*r = (Uint8)(v >> 2);
- v = (pixel & format->Gmask) >> format->Gshift;
+ v = (pixel & fmt->Gmask) >> fmt->Gshift;
*g = (Uint8)(v >> 2);
- v = (pixel & format->Bmask) >> format->Bshift;
+ v = (pixel & fmt->Bmask) >> fmt->Bshift;
*b = (Uint8)(v >> 2);
} else {
unsigned v;
- v = (pixel & format->Rmask) >> format->Rshift;
- *r = SDL_expand_byte[format->Rloss][v];
- v = (pixel & format->Gmask) >> format->Gshift;
- *g = SDL_expand_byte[format->Gloss][v];
- v = (pixel & format->Bmask) >> format->Bshift;
- *b = SDL_expand_byte[format->Bloss][v];
+ v = (pixel & fmt->Rmask) >> fmt->Rshift;
+ *r = SDL_expand_byte[fmt->Rbits][v];
+ v = (pixel & fmt->Gmask) >> fmt->Gshift;
+ *g = SDL_expand_byte[fmt->Gbits][v];
+ v = (pixel & fmt->Bmask) >> fmt->Bshift;
+ *b = SDL_expand_byte[fmt->Bbits][v];
}
}
-void SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat *format,
- Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
+void SDL_GetRGBA(Uint32 pixel, SDL_PixelFormat format, SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
{
- if (format->palette) {
- if (pixel < (unsigned)format->palette->ncolors) {
- *r = format->palette->colors[pixel].r;
- *g = format->palette->colors[pixel].g;
- *b = format->palette->colors[pixel].b;
- *a = format->palette->colors[pixel].a;
+ if (palette) {
+ if (pixel < (unsigned)palette->ncolors) {
+ *r = palette->colors[pixel].r;
+ *g = palette->colors[pixel].g;
+ *b = palette->colors[pixel].b;
+ *a = palette->colors[pixel].a;
} else {
*r = *g = *b = *a = 0;
}
- } else if (SDL_ISPIXELFORMAT_10BIT(format->format)) {
+ return;
+ }
+
+ const SDL_PixelFormatDetails *fmt = SDL_GetPixelFormatDetails(format);
+ if (!fmt) {
+ *r = *g = *b = 0;
+ return;
+ }
+
+ if (SDL_ISPIXELFORMAT_10BIT(format)) {
unsigned v;
- v = (pixel & format->Rmask) >> format->Rshift;
+ v = (pixel & fmt->Rmask) >> fmt->Rshift;
*r = (Uint8)(v >> 2);
- v = (pixel & format->Gmask) >> format->Gshift;
+ v = (pixel & fmt->Gmask) >> fmt->Gshift;
*g = (Uint8)(v >> 2);
- v = (pixel & format->Bmask) >> format->Bshift;
+ v = (pixel & fmt->Bmask) >> fmt->Bshift;
*b = (Uint8)(v >> 2);
- v = (pixel & format->Amask) >> format->Ashift;
- *a = SDL_expand_byte[format->Aloss][v];
+ v = (pixel & fmt->Amask) >> fmt->Ashift;
+ *a = SDL_expand_byte[fmt->Abits][v];
} else {
unsigned v;
- v = (pixel & format->Rmask) >> format->Rshift;
- *r = SDL_expand_byte[format->Rloss][v];
- v = (pixel & format->Gmask) >> format->Gshift;
- *g = SDL_expand_byte[format->Gloss][v];
- v = (pixel & format->Bmask) >> format->Bshift;
- *b = SDL_expand_byte[format->Bloss][v];
- v = (pixel & format->Amask) >> format->Ashift;
- *a = SDL_expand_byte[format->Aloss][v];
+ v = (pixel & fmt->Rmask) >> fmt->Rshift;
+ *r = SDL_expand_byte[fmt->Rbits][v];
+ v = (pixel & fmt->Gmask) >> fmt->Gshift;
+ *g = SDL_expand_byte[fmt->Gbits][v];
+ v = (pixel & fmt->Bmask) >> fmt->Bshift;
+ *b = SDL_expand_byte[fmt->Bbits][v];
+ v = (pixel & fmt->Amask) >> fmt->Ashift;
+ *a = SDL_expand_byte[fmt->Abits][v];
}
}
/* Map from Palette to Palette */
-static Uint8 *Map1to1(SDL_Palette *src, SDL_Palette *dst, int *identical)
+static Uint8 *Map1to1(const SDL_Palette *src, const SDL_Palette *dst, int *identical)
{
Uint8 *map;
int i;
@@ -1369,15 +1329,13 @@ static Uint8 *Map1to1(SDL_Palette *src, SDL_Palette *dst, int *identical)
}
/* Map from Palette to BitField */
-static Uint8 *Map1toN(SDL_PixelFormat *src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod, Uint8 Amod,
- SDL_PixelFormat *dst)
+static Uint8 *Map1toN(const SDL_Palette *pal, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod, Uint8 Amod, const SDL_PixelFormatDetails *dst)
{
Uint8 *map;
int i;
int bpp;
- SDL_Palette *pal = src->palette;
- bpp = ((dst->bytes_per_pixel == 3) ? 4 : dst->bytes_per_pixel);
+ bpp = ((SDL_BYTESPERPIXEL(dst->format) == 3) ? 4 : SDL_BYTESPERPIXEL(dst->format));
map = (Uint8 *)SDL_calloc(256, bpp);
if (!map) {
return NULL;
@@ -1389,19 +1347,18 @@ static Uint8 *Map1toN(SDL_PixelFormat *src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod,
Uint8 G = (Uint8)((pal->colors[i].g * Gmod) / 255);
Uint8 B = (Uint8)((pal->colors[i].b * Bmod) / 255);
Uint8 A = (Uint8)((pal->colors[i].a * Amod) / 255);
- ASSEMBLE_RGBA(&map[i * bpp], dst->bytes_per_pixel, dst, (Uint32)R,
+ ASSEMBLE_RGBA(&map[i * bpp], SDL_BYTESPERPIXEL(dst->format), dst, (Uint32)R,
(Uint32)G, (Uint32)B, (Uint32)A);
}
return map;
}
/* Map from BitField to Dithered-Palette to Palette */
-static Uint8 *MapNto1(SDL_PixelFormat *src, SDL_PixelFormat *dst, int *identical)
+static Uint8 *MapNto1(const SDL_PixelFormatDetails *src, const SDL_Palette *pal, int *identical)
{
/* Generate a 256 color dither palette */
SDL_Palette dithered;
SDL_Color colors[256];
- SDL_Palette *pal = dst->palette;
dithered.ncolors = 256;
SDL_DitherColors(colors, 8);
@@ -1429,9 +1386,9 @@ SDL_BlitMap *SDL_AllocBlitMap(void)
void SDL_InvalidateAllBlitMap(SDL_Surface *surface)
{
- SDL_ListNode *l = (SDL_ListNode *)surface->list_blitmap;
+ SDL_ListNode *l = surface->internal->list_blitmap;
- surface->list_blitmap = NULL;
+ surface->internal->list_blitmap = NULL;
while (l) {
SDL_ListNode *tmp = l;
@@ -1448,7 +1405,7 @@ void SDL_InvalidateMap(SDL_BlitMap *map)
}
if (map->dst) {
/* Un-register from the destination surface */
- SDL_ListRemove((SDL_ListNode **)&(map->dst->list_blitmap), map);
+ SDL_ListRemove(&map->dst->internal->list_blitmap, map);
}
map->dst = NULL;
map->src_palette_version = 0;
@@ -1459,28 +1416,32 @@ void SDL_InvalidateMap(SDL_BlitMap *map)
int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst)
{
- SDL_PixelFormat *srcfmt;
- SDL_PixelFormat *dstfmt;
+ const SDL_PixelFormatDetails *srcfmt;
+ const SDL_Palette *srcpal;
+ const SDL_PixelFormatDetails *dstfmt;
+ const SDL_Palette *dstpal;
SDL_BlitMap *map;
/* Clear out any previous mapping */
- map = src->map;
+ map = src->internal->map;
#if SDL_HAVE_RLE
- if ((src->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
- SDL_UnRLESurface(src, 1);
+ if (src->internal->flags & SDL_INTERNAL_SURFACE_RLEACCEL) {
+ SDL_UnRLESurface(src, SDL_TRUE);
}
#endif
SDL_InvalidateMap(map);
/* Figure out what kind of mapping we're doing */
map->identity = 0;
- srcfmt = src->format;
- dstfmt = dst->format;
+ srcfmt = src->internal->format;
+ srcpal = src->internal->palette;
+ dstfmt = dst->internal->format;
+ dstpal = dst->internal->palette;
if (SDL_ISPIXELFORMAT_INDEXED(srcfmt->format)) {
if (SDL_ISPIXELFORMAT_INDEXED(dstfmt->format)) {
/* Palette --> Palette */
map->info.table =
- Map1to1(srcfmt->palette, dstfmt->palette, &map->identity);
+ Map1to1(srcpal, dstpal, &map->identity);
if (!map->identity) {
if (!map->info.table) {
return -1;
@@ -1492,8 +1453,8 @@ int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst)
} else {
/* Palette --> BitField */
map->info.table =
- Map1toN(srcfmt, src->map->info.r, src->map->info.g,
- src->map->info.b, src->map->info.a, dstfmt);
+ Map1toN(srcpal, src->internal->map->info.r, src->internal->map->info.g,
+ src->internal->map->info.b, src->internal->map->info.a, dstfmt);
if (!map->info.table) {
return -1;
}
@@ -1501,7 +1462,7 @@ int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst)
} else {
if (SDL_ISPIXELFORMAT_INDEXED(dstfmt->format)) {
/* BitField --> Palette */
- map->info.table = MapNto1(srcfmt, dstfmt, &map->identity);
+ map->info.table = MapNto1(srcfmt, dstpal, &map->identity);
if (!map->identity) {
if (!map->info.table) {
return -1;
@@ -1520,17 +1481,17 @@ int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst)
if (map->dst) {
/* Register BlitMap to the destination surface, to be invalidated when needed */
- SDL_ListAdd((SDL_ListNode **)&(map->dst->list_blitmap), map);
+ SDL_ListAdd(&map->dst->internal->list_blitmap, map);
}
- if (dstfmt->palette) {
- map->dst_palette_version = dstfmt->palette->version;
+ if (dstpal) {
+ map->dst_palette_version = dstpal->version;
} else {
map->dst_palette_version = 0;
}
- if (srcfmt->palette) {
- map->src_palette_version = srcfmt->palette->version;
+ if (srcpal) {
+ map->src_palette_version = srcpal->version;
} else {
map->src_palette_version = 0;
}
diff --git a/src/video/SDL_pixels_c.h b/src/video/SDL_pixels_c.h
index 40eacf8dd3439e..a43c448e5002b5 100644
--- a/src/video/SDL_pixels_c.h
+++ b/src/video/SDL_pixels_c.h
@@ -28,10 +28,11 @@
#include "SDL_blit.h"
+
/* Pixel format functions */
-extern int SDL_InitFormat(SDL_PixelFormat *format, SDL_PixelFormatEnum pixel_format);
-extern int SDL_CalculateSurfaceSize(SDL_PixelFormatEnum format, int width, int height, size_t *size, size_t *pitch, SDL_bool minimalPitch);
-extern SDL_Colorspace SDL_GetDefaultColorspaceForFormat(SDL_PixelFormatEnum pixel_format);
+extern int SDL_CalculateSurfaceSize(SDL_PixelFormat format, int width, int height, size_t *size, size_t *pitch, SDL_bool minimalPitch);
+extern SDL_Colorspace SDL_GetDefaultColorspaceForFormat(SDL_PixelFormat pixel_format);
+extern void SDL_QuitPixelFormatDetails(void);
/* Colorspace conversion functions */
extern float SDL_sRGBtoLinear(float v);
@@ -50,16 +51,10 @@ extern void SDL_FreeBlitMap(SDL_BlitMap *map);
extern void SDL_InvalidateAllBlitMap(SDL_Surface *surface);
-/* Surface functions */
-extern float SDL_GetDefaultSDRWhitePoint(SDL_Colorspace colorspace);
-extern float SDL_GetSurfaceSDRWhitePoint(SDL_Surface *surface, SDL_Colorspace colorspace);
-extern float SDL_GetDefaultHDRHeadroom(SDL_Colorspace colorspace);
-extern float SDL_GetSurfaceHDRHeadroom(SDL_Surface *surface, SDL_Colorspace colorspace);
-
/* Miscellaneous functions */
extern void SDL_DitherColors(SDL_Color *colors, int bpp);
-extern Uint8 SDL_FindColor(SDL_Palette *pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
-extern void SDL_DetectPalette(SDL_Palette *pal, SDL_bool *is_opaque, SDL_bool *has_alpha_channel);
-extern SDL_Surface *SDL_DuplicatePixels(int width, int height, SDL_PixelFormatEnum format, SDL_Colorspace colorspace, void *pixels, int pitch);
+extern Uint8 SDL_FindColor(const SDL_Palette *pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
+extern void SDL_DetectPalette(const SDL_Palette *pal, SDL_bool *is_opaque, SDL_bool *has_alpha_channel);
+extern SDL_Surface *SDL_DuplicatePixels(int width, int height, SDL_PixelFormat format, SDL_Colorspace colorspace, void *pixels, int pitch);
#endif /* SDL_pixels_c_h_ */
diff --git a/src/video/SDL_stretch.c b/src/video/SDL_stretch.c
index 1778ccc0403f27..6f34670794baec 100644
--- a/src/video/SDL_stretch.c
+++ b/src/video/SDL_stretch.c
@@ -42,9 +42,9 @@ int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect,
return SDL_InvalidParamError("dst");
}
- if (src->format->format != dst->format->format) {
+ if (src->format != dst->format) {
// Slow!
- SDL_Surface *src_tmp = SDL_ConvertSurfaceFormat(src, dst->format->format);
+ SDL_Surface *src_tmp = SDL_ConvertSurface(src, dst->format);
if (!src_tmp) {
return -1;
}
@@ -53,7 +53,7 @@ int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect,
return ret;
}
- if (SDL_ISPIXELFORMAT_FOURCC(src->format->format)) {
+ if (SDL_ISPIXELFORMAT_FOURCC(src->format)) {
// Slow!
if (!dstrect) {
full_dst.x = 0;
@@ -63,18 +63,17 @@ int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect,
dstrect = &full_dst;
}
- SDL_Surface *src_tmp = SDL_ConvertSurfaceFormat(src, SDL_PIXELFORMAT_XRGB8888);
+ SDL_Surface *src_tmp = SDL_ConvertSurface(src, SDL_PIXELFORMAT_XRGB8888);
SDL_Surface *dst_tmp = SDL_CreateSurface(dstrect->w, dstrect->h, SDL_PIXELFORMAT_XRGB8888);
if (src_tmp && dst_tmp) {
ret = SDL_SoftStretch(src_tmp, srcrect, dst_tmp, NULL, scaleMode);
if (ret == 0) {
- SDL_Colorspace dst_colorspace = SDL_COLORSPACE_UNKNOWN;
- SDL_GetSurfaceColorspace(dst, &dst_colorspace);
+ SDL_Colorspace dst_colorspace = SDL_GetSurfaceColorspace(dst);
SDL_ConvertPixelsAndColorspace(dstrect->w, dstrect->h,
- dst_tmp->format->format, SDL_COLORSPACE_SRGB, 0,
+ dst_tmp->format, SDL_COLORSPACE_SRGB, 0,
dst_tmp->pixels, dst_tmp->pitch,
- dst->format->format, dst_colorspace, SDL_GetSurfaceProperties(dst),
- (Uint8 *)dst->pixels + dstrect->y * dst->pitch + dstrect->x * dst->format->bytes_per_pixel, dst->pitch);
+ dst->format, dst_colorspace, SDL_GetSurfaceProperties(dst),
+ (Uint8 *)dst->pixels + dstrect->y * dst->pitch + dstrect->x * SDL_BYTESPERPIXEL(dst->format), dst->pitch);
}
} else {
ret = -1;
@@ -93,7 +92,7 @@ int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect,
}
if (scaleMode == SDL_SCALEMODE_LINEAR) {
- if (src->format->bytes_per_pixel != 4 || src->format->format == SDL_PIXELFORMAT_ARGB2101010) {
+ if (SDL_BYTESPERPIXEL(src->format) != 4 || src->format == SDL_PIXELFORMAT_ARGB2101010) {
return SDL_SetError("Wrong format");
}
}
@@ -972,8 +971,7 @@ int SDL_LowerSoftStretchNearest(SDL_Surface *s, const SDL_Rect *srcrect,
int dst_h = dstrect->h;
int src_pitch = s->pitch;
int dst_pitch = d->pitch;
-
- const int bpp = d->format->bytes_per_pixel;
+ int bpp = SDL_BYTESPERPIXEL(d->format);
Uint32 *src = (Uint32 *)((Uint8 *)s->pixels + srcrect->x * bpp + srcrect->y * src_pitch);
Uint32 *dst = (Uint32 *)((Uint8 *)d->pixels + dstrect->x * bpp + dstrect->y * dst_pitch);
diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c
index 24ebf4b3009b15..f971ab1ec0d60c 100644
--- a/src/video/SDL_surface.c
+++ b/src/video/SDL_surface.c
@@ -27,8 +27,9 @@
#include "SDL_pixels_c.h"
#include "SDL_yuv_c.h"
#include "../render/SDL_sysrender.h"
-#include "../video/SDL_pixels_c.h"
-#include "../video/SDL_yuv_c.h"
+
+#include "SDL_surface_c.h"
+
/* Check to make sure we can safely check multiplication of surface w and pitch and it won't overflow size_t */
SDL_COMPILE_TIME_ASSERT(surface_size_assumptions,
@@ -38,6 +39,20 @@ SDL_COMPILE_TIME_ASSERT(can_indicate_overflow, SDL_SIZE_MAX > SDL_MAX_SINT32);
/* Public routines */
+SDL_bool SDL_SurfaceValid(SDL_Surface *surface)
+{
+ return surface && surface->internal;
+}
+
+void SDL_UpdateSurfaceLockFlag(SDL_Surface *surface)
+{
+ if (surface->internal->flags & SDL_INTERNAL_SURFACE_RLEACCEL) {
+ surface->flags |= SDL_SURFACE_LOCK_NEEDED;
+ } else {
+ surface->flags &= ~SDL_SURFACE_LOCK_NEEDED;
+ }
+}
+
/*
* Calculate the pad-aligned scanline width of a surface.
* Return SDL_SIZE_MAX on overflow.
@@ -74,7 +89,7 @@ static int SDL_CalculateRGBSize(Uint32 format, size_t width, size_t height, size
return 0;
}
-int SDL_CalculateSurfaceSize(SDL_PixelFormatEnum format, int width, int height, size_t *size, size_t *pitch, SDL_bool minimalPitch)
+int SDL_CalculateSurfaceSize(SDL_PixelFormat format, int width, int height, size_t *size, size_t *pitch, SDL_bool minimalPitch)
{
size_t p = 0, sz = 0;
@@ -113,7 +128,7 @@ int SDL_CalculateSurfaceSize(SDL_PixelFormatEnum format, int width, int height,
* Create an empty RGB surface of the appropriate depth using the given
* enum SDL_PIXELFORMAT_* format
*/
-SDL_Surface *SDL_CreateSurface(int width, int height, SDL_PixelFormatEnum format)
+SDL_Surface *SDL_CreateSurface(int width, int height, SDL_PixelFormat format)
{
size_t pitch, size;
SDL_Surface *surface;
@@ -139,19 +154,36 @@ SDL_Surface *SDL_CreateSurface(int width, int height, SDL_PixelFormatEnum format
return NULL;
}
- surface->format = SDL_CreatePixelFormat(format);
- if (!surface->format) {
- SDL_DestroySurface(surface);
- return NULL;
- }
+ surface->format = format;
surface->w = width;
surface->h = height;
surface->pitch = (int)pitch;
- SDL_SetSurfaceClipRect(surface, NULL);
- if (SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) {
- SDL_Palette *palette =
- SDL_CreatePalette((1 << surface->format->bits_per_pixel));
+ surface->internal = (SDL_SurfaceData *)SDL_calloc(1, sizeof(*surface->internal));
+ if (!surface->internal) {
+ SDL_DestroySurface(surface);
+ return NULL;
+ }
+
+ surface->internal->format = SDL_GetPixelFormatDetails(format);
+ if (!surface->internal->format) {
+ SDL_DestroySurface(surface);
+ return NULL;
+ }
+
+ /* Initialize the clip rect */
+ surface->internal->clip_rect.w = width;
+ surface->internal->clip_rect.h = height;
+
+ /* Allocate an empty mapping */
+ surface->internal->map = SDL_AllocBlitMap();
+ if (!surface->internal->map) {
+ SDL_DestroySurface(surface);
+ return NULL;
+ }
+
+ if (SDL_ISPIXELFORMAT_INDEXED(surface->format)) {
+ SDL_Palette *palette = SDL_CreatePalette((1 << SDL_BITSPERPIXEL(surface->format)));
if (!palette) {
SDL_DestroySurface(surface);
return NULL;
@@ -176,20 +208,13 @@ SDL_Surface *SDL_CreateSurface(int width, int height, SDL_PixelFormatEnum format
SDL_DestroySurface(surface);
return NULL;
}
- surface->flags |= SDL_SIMD_ALIGNED;
+ surface->flags |= SDL_SURFACE_SIMD_ALIGNED;
/* This is important for bitmaps */
SDL_memset(surface->pixels, 0, size);
}
- /* Allocate an empty mapping */
- surface->map = SDL_AllocBlitMap();
- if (!surface->map) {
- SDL_DestroySurface(surface);
- return NULL;
- }
-
/* By default surface with an alpha mask are set up for blending */
- if (surface->format->Amask) {
+ if (SDL_ISPIXELFORMAT_ALPHA(surface->format)) {
SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND);
}
@@ -202,7 +227,7 @@ SDL_Surface *SDL_CreateSurface(int width, int height, SDL_PixelFormatEnum format
* Create an RGB surface from an existing memory buffer using the given
* enum SDL_PIXELFORMAT_* format
*/
-SDL_Surface *SDL_CreateSurfaceFrom(void *pixels, int width, int height, int pitch, SDL_PixelFormatEnum format)
+SDL_Surface *SDL_CreateSurfaceFrom(int width, int height, SDL_PixelFormat format, void *pixels, int pitch)
{
SDL_Surface *surface;
@@ -234,7 +259,7 @@ SDL_Surface *SDL_CreateSurfaceFrom(void *pixels, int width, int height, int pitc
surface = SDL_CreateSurface(0, 0, format);
if (surface) {
- surface->flags |= SDL_PREALLOC;
+ surface->flags |= SDL_SURFACE_PREALLOCATED;
surface->pixels = pixels;
surface->w = width;
surface->h = height;
@@ -246,61 +271,42 @@ SDL_Surface *SDL_CreateSurfaceFrom(void *pixels, int width, int height, int pitc
SDL_PropertiesID SDL_GetSurfaceProperties(SDL_Surface *surface)
{
- SDL_PropertiesID props;
-
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
SDL_InvalidParamError("surface");
return 0;
}
- if (surface->flags & SDL_SURFACE_USES_PROPERTIES) {
- props = (SDL_PropertiesID)(uintptr_t)surface->reserved;
- } else {
- if (surface->reserved != NULL) {
- SDL_SetError("Surface has userdata, incompatible with properties");
- return 0;
- }
-
- props = SDL_CreateProperties();
- if (props) {
- surface->reserved = (void *)(uintptr_t)props;
- surface->flags |= SDL_SURFACE_USES_PROPERTIES;
- }
+ if (!surface->internal->props) {
+ surface->internal->props = SDL_CreateProperties();
}
- return props;
+ return surface->internal->props;
}
int SDL_SetSurfaceColorspace(SDL_Surface *surface, SDL_Colorspace colorspace)
{
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
return SDL_InvalidParamError("surface");
}
- if (colorspace == SDL_GetDefaultColorspaceForFormat(surface->format->format)) {
+ if (colorspace == SDL_GetDefaultColorspaceForFormat(surface->format)) {
return 0;
}
return SDL_SetNumberProperty(SDL_GetSurfaceProperties(surface), SDL_PROP_SURFACE_COLORSPACE_NUMBER, colorspace);
}
-int SDL_GetSurfaceColorspace(SDL_Surface *surface, SDL_Colorspace *colorspace)
+SDL_Colorspace SDL_GetSurfaceColorspace(SDL_Surface *surface)
{
- SDL_Colorspace surface_colorspace = SDL_COLORSPACE_UNKNOWN;
-
- if (!surface) {
- return SDL_InvalidParamError("surface");
- }
+ SDL_Colorspace colorspace;
- if (surface->flags & SDL_SURFACE_USES_PROPERTIES) {
- surface_colorspace = (SDL_Colorspace)SDL_GetNumberProperty(SDL_GetSurfaceProperties(surface), SDL_PROP_SURFACE_COLORSPACE_NUMBER, SDL_COLORSPACE_UNKNOWN);
- }
- if (surface_colorspace == SDL_COLORSPACE_UNKNOWN) {
- surface_colorspace = SDL_GetDefaultColorspaceForFormat(surface->format->format);
+ if (!SDL_SurfaceValid(surface)) {
+ return SDL_COLORSPACE_UNKNOWN;
}
- if (colorspace) {
- *colorspace = surface_colorspace;
+ colorspace = (SDL_Colorspace)SDL_GetNumberProperty(surface->internal->props, SDL_PROP_SURFACE_COLORSPACE_NUMBER, SDL_COLORSPACE_UNKNOWN);
+ if (colorspace == SDL_COLORSPACE_UNKNOWN) {
+ colorspace = SDL_GetDefaultColorspaceForFormat(surface->format);
}
- return 0;
+ return colorspace;
}
float SDL_GetDefaultSDRWhitePoint(SDL_Colorspace colorspace)
@@ -317,8 +323,8 @@ float SDL_GetSurfaceSDRWhitePoint(SDL_Surface *surface, SDL_Colorspace colorspac
SDL_PropertiesID props;
float default_value = 1.0f;
- if (surface && surface->flags & SDL_SURFACE_USES_PROPERTIES) {
- props = SDL_GetSurfaceProperties(surface);
+ if (SDL_SurfaceValid(surface)) {
+ props = surface->internal->props;
} else {
props = 0;
}
@@ -350,8 +356,8 @@ float SDL_GetSurfaceHDRHeadroom(SDL_Surface *surface, SDL_Colorspace colorspace)
SDL_PropertiesID props;
float default_value = 0.0f;
- if (surface && surface->flags & SDL_SURFACE_USES_PROPERTIES) {
- props = SDL_GetSurfaceProperties(surface);
+ if (SDL_SurfaceValid(surface)) {
+ props = surface->internal->props;
} else {
props = 0;
}
@@ -362,75 +368,96 @@ float SDL_GetSurfaceHDRHeadroom(SDL_Surface *surface, SDL_Colorspace colorspace)
int SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette)
{
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
return SDL_InvalidParamError("surface");
}
- if (SDL_SetPixelFormatPalette(surface->format, palette) < 0) {
- return -1;
+
+ if (palette && palette->ncolors > (1 << SDL_BITSPERPIXEL(surface->format))) {
+ return SDL_SetError("SDL_SetSurfacePalette() passed a palette that doesn't match the surface format");
+ }
+
+ if (palette == surface->internal->palette) {
+ return 0;
+ }
+
+ if (surface->internal->palette) {
+ SDL_DestroyPalette(surface->internal->palette);
+ }
+
+ surface->internal->palette = palette;
+
+ if (surface->internal->palette) {
+ ++surface->internal->palette->refcount;
}
- SDL_InvalidateMap(surface->map);
+
+ SDL_InvalidateMap(surface->internal->map);
return 0;
}
-int SDL_SetSurfaceRLE(SDL_Surface *surface, int flag)
+SDL_Palette *SDL_GetSurfacePalette(SDL_Surface *surface)
+{
+ if (!SDL_SurfaceValid(surface)) {
+ return SDL_COLORSPACE_UNKNOWN;
+ }
+
+ return surface->internal->palette;
+}
+
+int SDL_SetSurfaceRLE(SDL_Surface *surface, SDL_bool enabled)
{
int flags;
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
return SDL_InvalidParamError("surface");
}
- flags = surface->map->info.flags;
- if (flag) {
- surface->map->info.flags |= SDL_COPY_RLE_DESIRED;
+ flags = surface->internal->map->info.flags;
+ if (enabled) {
+ surface->internal->map->info.flags |= SDL_COPY_RLE_DESIRED;
} else {
- surface->map->info.flags &= ~SDL_COPY_RLE_DESIRED;
+ surface->internal->map->info.flags &= ~SDL_COPY_RLE_DESIRED;
}
- if (surface->map->info.flags != flags) {
- SDL_InvalidateMap(surface->map);
+ if (surface->internal->map->info.flags != flags) {
+ SDL_InvalidateMap(surface->internal->map);
}
return 0;
}
SDL_bool SDL_SurfaceHasRLE(SDL_Surface *surface)
{
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
return SDL_FALSE;
}
- if (!(surface->map->info.flags & SDL_COPY_RLE_DESIRED)) {
+ if (!(surface->internal->map->info.flags & SDL_COPY_RLE_DESIRED)) {
return SDL_FALSE;
}
return SDL_TRUE;
}
-int SDL_SetSurfaceColorKey(SDL_Surface *surface, int flag, Uint32 key)
+int SDL_SetSurfaceColorKey(SDL_Surface *surface, SDL_bool enabled, Uint32 key)
{
int flags;
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
return SDL_InvalidParamError("surface");
}
- if (surface->format->palette && key >= ((Uint32)surface->format->palette->ncolors)) {
+ if (surface->internal->palette && key >= ((Uint32)surface->internal->palette->ncolors)) {
return SDL_InvalidParamError("key");
}
- if (flag & SDL_RLEACCEL) {
- SDL_SetSurfaceRLE(surface, 1);
- }
-
- flags = surface->map->info.flags;
- if (flag) {
- surface->map->info.flags |= SDL_COPY_COLORKEY;
- surface->map->info.colorkey = key;
+ flags = surface->internal->map->info.flags;
+ if (enabled) {
+ surface->internal->map->info.flags |= SDL_COPY_COLORKEY;
+ surface->internal->map->info.colorkey = key;
} else {
- surface->map->info.flags &= ~SDL_COPY_COLORKEY;
+ surface->internal->map->info.flags &= ~SDL_COPY_COLORKEY;
}
- if (surface->map->info.flags != flags) {
- SDL_InvalidateMap(surface->map);
+ if (surface->internal->map->info.flags != flags) {
+ SDL_InvalidateMap(surface->internal->map);
}
return 0;
@@ -438,11 +465,11 @@ int SDL_SetSurfaceColorKey(SDL_Surface *surface, int flag, Uint32 key)
SDL_bool SDL_SurfaceHasColorKey(SDL_Surface *surface)
{
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
return SDL_FALSE;
}
- if (!(surface->map->info.flags & SDL_COPY_COLORKEY)) {
+ if (!(surface->internal->map->info.flags & SDL_COPY_COLORKEY)) {
return SDL_FALSE;
}
@@ -451,16 +478,16 @@ SDL_bool SDL_SurfaceHasColorKey(SDL_Surface *surface)
int SDL_GetSurfaceColorKey(SDL_Surface *surface, Uint32 *key)
{
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
return SDL_InvalidParamError("surface");
}
- if (!(surface->map->info.flags & SDL_COPY_COLORKEY)) {
+ if (!(surface->internal->map->info.flags & SDL_COPY_COLORKEY)) {
return SDL_SetError("Surface doesn't have a colorkey");
}
if (key) {
- *key = surface->map->info.colorkey;
+ *key = surface->internal->map->info.colorkey;
}
return 0;
}
@@ -471,23 +498,23 @@ static void SDL_ConvertColorkeyToAlpha(SDL_Surface *surface, SDL_bool ignore_alp
{
int x, y, bpp;
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
return;
}
- if (!(surface->map->info.flags & SDL_COPY_COLORKEY) ||
- !surface->format->Amask) {
+ if (!(surface->internal->map->info.flags & SDL_COPY_COLORKEY) ||
+ !SDL_ISPIXELFORMAT_ALPHA(surface->format)) {
return;
}
- bpp = surface->format->bytes_per_pixel;
+ bpp = SDL_BYTESPERPIXEL(surface->format);
SDL_LockSurface(surface);
if (bpp == 2) {
Uint16 *row, *spot;
- Uint16 ckey = (Uint16)surface->map->info.colorkey;
- Uint16 mask = (Uint16)(~surface->format->Amask);
+ Uint16 ckey = (Uint16)surface->internal->map->info.colorkey;
+ Uint16 mask = (Uint16)(~surface->internal->format->Amask);
/* Ignore, or not, alpha in colorkey comparison */
if (ignore_alpha) {
@@ -518,8 +545,8 @@ static void SDL_ConvertColorkeyToAlpha(SDL_Surface *surface, SDL_bool ignore_alp
}
} else if (bpp == 4) {
Uint32 *row, *spot;
- Uint32 ckey = surface->map->info.colorkey;
- Uint32 mask = ~surface->format->Amask;
+ Uint32 ckey = surface->internal->map->info.colorkey;
+ Uint32 mask = ~surface->internal->format->Amask;
/* Ignore, or not, alpha in colorkey comparison */
if (ignore_alpha) {
@@ -560,40 +587,40 @@ int SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b)
{
int flags;
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
return SDL_InvalidParamError("surface");
}
- surface->map->info.r = r;
- surface->map->info.g = g;
- surface->map->info.b = b;
+ surface->internal->map->info.r = r;
+ surface->internal->map->info.g = g;
+ surface->internal->map->info.b = b;
- flags = surface->map->info.flags;
+ flags = surface->internal->map->info.flags;
if (r != 0xFF || g != 0xFF || b != 0xFF) {
- surface->map->info.flags |= SDL_COPY_MODULATE_COLOR;
+ surface->internal->map->info.flags |= SDL_COPY_MODULATE_COLOR;
} else {
- surface->map->info.flags &= ~SDL_COPY_MODULATE_COLOR;
+ surface->internal->map->info.flags &= ~SDL_COPY_MODULATE_COLOR;
}
- if (surface->map->info.flags != flags) {
- SDL_InvalidateMap(surface->map);
+ if (surface->internal->map->info.flags != flags) {
+ SDL_InvalidateMap(surface->internal->map);
}
return 0;
}
int SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b)
{
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
return SDL_InvalidParamError("surface");
}
if (r) {
- *r = surface->map->info.r;
+ *r = surface->internal->map->info.r;
}
if (g) {
- *g = surface->map->info.g;
+ *g = surface->internal->map->info.g;
}
if (b) {
- *b = surface->map->info.b;
+ *b = surface->internal->map->info.b;
}
return 0;
}
@@ -602,32 +629,32 @@ int SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha)
{
int flags;
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
return SDL_InvalidParamError("surface");
}
- surface->map->info.a = alpha;
+ surface->internal->map->info.a = alpha;
- flags = surface->map->info.flags;
+ flags = surface->internal->map->info.flags;
if (alpha != 0xFF) {
- surface->map->info.flags |= SDL_COPY_MODULATE_ALPHA;
+ surface->internal->map->info.flags |= SDL_COPY_MODULATE_ALPHA;
} else {
- surface->map->info.flags &= ~SDL_COPY_MODULATE_ALPHA;
+ surface->internal->map->info.flags &= ~SDL_COPY_MODULATE_ALPHA;
}
- if (surface->map->info.flags != flags) {
- SDL_InvalidateMap(surface->map);
+ if (surface->internal->map->info.flags != flags) {
+ SDL_InvalidateMap(surface->internal->map);
}
return 0;
}
int SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha)
{
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
return SDL_InvalidParamError("surface");
}
if (alpha) {
- *alpha = surface->map->info.a;
+ *alpha = surface->internal->map->info.a;
}
return 0;
}
@@ -636,36 +663,36 @@ int SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode)
{
int flags, status;
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
return SDL_InvalidParamError("surface");
}
status = 0;
- flags = surface->map->info.flags;
- surface->map->info.flags &=
+ flags = surface->internal->map->info.flags;
+ surface->internal->map->info.flags &=
~(SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_MUL);
switch (blendMode) {
case SDL_BLENDMODE_NONE:
break;
case SDL_BLENDMODE_BLEND:
- surface->map->info.flags |= SDL_COPY_BLEND;
+ surface->internal->map->info.flags |= SDL_COPY_BLEND;
break;
case SDL_BLENDMODE_ADD:
- surface->map->info.flags |= SDL_COPY_ADD;
+ surface->internal->map->info.flags |= SDL_COPY_ADD;
break;
case SDL_BLENDMODE_MOD:
- surface->map->info.flags |= SDL_COPY_MOD;
+ surface->internal->map->info.flags |= SDL_COPY_MOD;
break;
case SDL_BLENDMODE_MUL:
- surface->map->info.flags |= SDL_COPY_MUL;
+ surface->internal->map->info.flags |= SDL_COPY_MUL;
break;
default:
status = SDL_Unsupported();
break;
}
- if (surface->map->info.flags != flags) {
- SDL_InvalidateMap(surface->map);
+ if (surface->internal->map->info.flags != flags) {
+ SDL_InvalidateMap(surface->internal->map);
}
return status;
@@ -673,7 +700,7 @@ int SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode)
int SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode)
{
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
return SDL_InvalidParamError("surface");
}
@@ -681,7 +708,7 @@ int SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode)
return 0;
}
- switch (surface->map->info.flags & (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_MUL)) {
+ switch (surface->internal->map->info.flags & (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_MUL)) {
case SDL_COPY_BLEND:
*blendMode = SDL_BLENDMODE_BLEND;
break;
@@ -706,7 +733,7 @@ SDL_bool SDL_SetSurfaceClipRect(SDL_Surface *surface, const SDL_Rect *rect)
SDL_Rect full_rect;
/* Don't do anything if there's no surface to act on */
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
return SDL_FALSE;
}
@@ -718,21 +745,21 @@ SDL_bool SDL_SetSurfaceClipRect(SDL_Surface *surface, const SDL_Rect *rect)
/* Set the clipping rectangle */
if (!rect) {
- surface->clip_rect = full_rect;
+ surface->internal->clip_rect = full_rect;
return SDL_TRUE;
}
- return SDL_GetRectIntersection(rect, &full_rect, &surface->clip_rect);
+ return SDL_GetRectIntersection(rect, &full_rect, &surface->internal->clip_rect);
}
int SDL_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect)
{
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
return SDL_InvalidParamError("surface");
}
if (!rect) {
return SDL_InvalidParamError("rect");
}
- *rect = surface->clip_rect;
+ *rect = surface->internal->clip_rect;
return 0;
}
@@ -751,21 +778,21 @@ int SDL_BlitSurfaceUnchecked(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_Surface *dst, const SDL_Rect *dstrect)
{
/* Check to make sure the blit mapping is valid */
- if ((src->map->dst != dst) ||
- (dst->format->palette &&
- src->map->dst_palette_version != dst->format->palette->version) ||
- (src->format->palette &&
- src->map->src_palette_version != src->format->palette->version)) {
+ if ((src->internal->map->dst != dst) ||
+ (dst->internal->palette &&
+ src->internal->map->dst_palette_version != dst->internal->palette->version) ||
+ (src->internal->palette &&
+ src->internal->map->src_palette_version != src->internal->palette->version)) {
if (SDL_MapSurface(src, dst) < 0) {
return -1;
}
/* just here for debugging */
/* printf */
- /* ("src = 0x%08X src->flags = %08X src->map->info.flags = %08x\ndst = 0x%08X dst->flags = %08X dst->map->info.flags = %08X\nsrc->map->blit = 0x%08x\n", */
- /* src, dst->flags, src->map->info.flags, dst, dst->flags, */
- /* dst->map->info.flags, src->map->blit); */
+ /* ("src = 0x%08X src->flags = %08X src->internal->map->info.flags = %08x\ndst = 0x%08X dst->flags = %08X dst->internal->map->info.flags = %08X\nsrc->internal->map->blit = 0x%08x\n", */
+ /* src, dst->flags, src->internal->map->info.flags, dst, dst->flags, */
+ /* dst->internal->map->info.flags, src->internal->map->blit); */
}
- return src->map->blit(src, srcrect, dst, dstrect);
+ return src->internal->map->blit(src, srcrect, dst, dstrect);
}
int SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect,
@@ -774,11 +801,11 @@ int SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_Rect r_src, r_dst;
/* Make sure the surfaces aren't locked */
- if (!src) {
+ if (!SDL_SurfaceValid(src)) {
return SDL_InvalidParamError("src");
- } else if (!dst) {
+ } else if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("dst");
- } else if (src->locked || dst->locked) {
+ } else if ((src->flags & SDL_SURFACE_LOCKED) || (dst->flags & SDL_SURFACE_LOCKED)) {
return SDL_SetError("Surfaces must not be locked during blit");
}
@@ -818,7 +845,7 @@ int SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect,
/* clip the destination rectangle against the clip rectangle */
{
SDL_Rect tmp;
- if (SDL_GetRectIntersection(&r_dst, &dst->clip_rect, &tmp) == SDL_FALSE) {
+ if (SDL_GetRectIntersection(&r_dst, &dst->internal->clip_rect, &tmp) == SDL_FALSE) {
goto end;
}
@@ -833,9 +860,9 @@ int SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect,
}
/* Switch back to a fast blit if we were previously stretching */
- if (src->map->info.flags & SDL_COPY_NEAREST) {
- src->map->info.flags &= ~SDL_COPY_NEAREST;
- SDL_InvalidateMap(src->map);
+ if (src->internal->map->info.flags & SDL_COPY_NEAREST) {
+ src->internal->map->info.flags &= ~SDL_COPY_NEAREST;
+ SDL_InvalidateMap(src->internal->map);
}
if (r_dst.w > 0 && r_dst.h > 0) {
@@ -856,6 +883,7 @@ int SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect,
SDL_ScaleMode scaleMode)
{
+ SDL_Rect *clip_rect;
double src_x0, src_y0, src_x1, src_y1;
double dst_x0, dst_y0, dst_x1, dst_y1;
SDL_Rect final_src, final_dst;
@@ -864,10 +892,11 @@ int SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect,
int dst_w, dst_h;
/* Make sure the surfaces aren't locked */
- if (!src || !dst) {
- return SDL_InvalidParamError("SDL_BlitSurfaceScaled(): src/dst");
- }
- if (src->locked || dst->locked) {
+ if (!SDL_SurfaceValid(src)) {
+ return SDL_InvalidParamError("src");
+ } else if (!SDL_SurfaceValid(dst)) {
+ return SDL_InvalidParamError("dst");
+ } else if ((src->flags & SDL_SURFACE_LOCKED) || (dst->flags & SDL_SURFACE_LOCKED)) {
return SDL_SetError("Surfaces must not be locked during blit");
}
@@ -942,21 +971,22 @@ int SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect,
}
/* Clip destination rectangle to the clip rectangle */
+ clip_rect = &dst->internal->clip_rect;
/* Translate to clip space for easier calculations */
- dst_x0 -= dst->clip_rect.x;
- dst_x1 -= dst->clip_rect.x;
- dst_y0 -= dst->clip_rect.y;
- dst_y1 -= dst->clip_rect.y;
+ dst_x0 -= clip_rect->x;
+ dst_x1 -= clip_rect->x;
+ dst_y0 -= clip_rect->y;
+ dst_y1 -= clip_rect->y;
if (dst_x0 < 0) {
src_x0 -= dst_x0 / scaling_w;
dst_x0 = 0;
}
- if (dst_x1 > dst->clip_rect.w) {
- src_x1 -= (dst_x1 - dst->clip_rect.w) / scaling_w;
- dst_x1 = dst->clip_rect.w;
+ if (dst_x1 > clip_rect->w) {
+ src_x1 -= (dst_x1 - clip_rect->w) / scaling_w;
+ dst_x1 = clip_rect->w;
}
if (dst_y0 < 0) {
@@ -964,16 +994,16 @@ int SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect,
dst_y0 = 0;
}
- if (dst_y1 > dst->clip_rect.h) {
- src_y1 -= (dst_y1 - dst->clip_rect.h) / scaling_h;
- dst_y1 = dst->clip_rect.h;
+ if (dst_y1 > clip_rect->h) {
+ src_y1 -= (dst_y1 - clip_rect->h) / scaling_h;
+ dst_y1 = clip_rect->h;
}
/* Translate back to surface coordinates */
- dst_x0 += dst->clip_rect.x;
- dst_x1 += dst->clip_rect.x;
- dst_y0 += dst->clip_rect.y;
- dst_y1 += dst->clip_rect.y;
+ dst_x0 += clip_rect->x;
+ dst_x1 += clip_rect->x;
+ dst_y0 += clip_rect->y;
+ dst_y1 += clip_rect->y;
final_src.x = (int)SDL_round(src_x0);
final_src.y = (int)SDL_round(src_y0);
@@ -996,7 +1026,7 @@ int SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect,
}
/* Clip again */
- SDL_GetRectIntersection(&dst->clip_rect, &final_dst, &final_dst);
+ SDL_GetRectIntersection(clip_rect, &final_dst, &final_dst);
if (dstrect) {
*dstrect = final_dst;
@@ -1036,25 +1066,25 @@ int SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect,
return SDL_SetError("Size too large for scaling");
}
- if (!(src->map->info.flags & SDL_COPY_NEAREST)) {
- src->map->info.flags |= SDL_COPY_NEAREST;
- SDL_InvalidateMap(src->map);
+ if (!(src->internal->map->info.flags & SDL_COPY_NEAREST)) {
+ src->internal->map->info.flags |= SDL_COPY_NEAREST;
+ SDL_InvalidateMap(src->internal->map);
}
if (scaleMode == SDL_SCALEMODE_NEAREST) {
- if (!(src->map->info.flags & complex_copy_flags) &&
- src->format->format == dst->format->format &&
- !SDL_ISPIXELFORMAT_INDEXED(src->format->format)) {
+ if (!(src->internal->map->info.flags & complex_copy_flags) &&
+ src->format == dst->format &&
+ !SDL_ISPIXELFORMAT_INDEXED(src->format)) {
return SDL_SoftStretch(src, srcrect, dst, dstrect, SDL_SCALEMODE_NEAREST);
} else {
return SDL_BlitSurfaceUnchecked(src, srcrect, dst, dstrect);
}
} else {
- if (!(src->map->info.flags & complex_copy_flags) &&
- src->format->format == dst->format->format &&
- !SDL_ISPIXELFORMAT_INDEXED(src->format->format) &&
- src->format->bytes_per_pixel == 4 &&
- src->format->format != SDL_PIXELFORMAT_ARGB2101010) {
+ if (!(src->internal->map->info.flags & complex_copy_flags) &&
+ src->format == dst->format &&
+ !SDL_ISPIXELFORMAT_INDEXED(src->format) &&
+ SDL_BYTESPERPIXEL(src->format) == 4 &&
+ src->format != SDL_PIXELFORMAT_ARGB2101010) {
/* fast path */
return SDL_SoftStretch(src, srcrect, dst, dstrect, SDL_SCALEMODE_LINEAR);
} else {
@@ -1062,7 +1092,7 @@ int SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_Surface *tmp1 = NULL;
int ret;
SDL_Rect srcrect2;
- int is_complex_copy_flags = (src->map->info.flags & complex_copy_flags);
+ int is_complex_copy_flags = (src->internal->map->info.flags & complex_copy_flags);
Uint8 r, g, b;
Uint8 alpha;
@@ -1078,15 +1108,15 @@ int SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect,
srcrect2.h = srcrect->h;
/* Change source format if not appropriate for scaling */
- if (src->format->bytes_per_pixel != 4 || src->format->format == SDL_PIXELFORMAT_ARGB2101010) {
+ if (SDL_BYTESPERPIXEL(src->format) != 4 || src->format == SDL_PIXELFORMAT_ARGB2101010) {
SDL_Rect tmprect;
- SDL_PixelFormatEnum fmt;
+ SDL_PixelFormat fmt;
tmprect.x = 0;
tmprect.y = 0;
tmprect.w = src->w;
tmprect.h = src->h;
- if (dst->format->bytes_per_pixel == 4 && dst->format->format != SDL_PIXELFORMAT_ARGB2101010) {
- fmt = dst->format->format;
+ if (SDL_BYTESPERPIXEL(dst->format) == 4 && dst->format != SDL_PIXELFORMAT_ARGB2101010) {
+ fmt = dst->format;
} else {
fmt = SDL_PIXELFORMAT_ARGB8888;
}
@@ -1103,9 +1133,9 @@ int SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect,
}
/* Intermediate scaling */
- if (is_complex_copy_flags || src->format->format != dst->format->format) {
+ if (is_complex_copy_flags || src->format != dst->format) {
SDL_Rect tmprect;
- SDL_Surface *tmp2 = SDL_CreateSurface(dstrect->w, dstrect->h, src->format->format);
+ SDL_Surface *tmp2 = SDL_CreateSurface(dstrect->w, dstrect->h, src->format);
SDL_SoftStretch(src, &srcrect2, tmp2, NULL, SDL_SCALEMODE_LINEAR);
SDL_SetSurfaceColorMod(tmp2, r, g, b);
@@ -1133,18 +1163,24 @@ int SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect,
*/
int SDL_LockSurface(SDL_Surface *surface)
{
- if (!surface->locked) {
+ if (!SDL_SurfaceValid(surface)) {
+ return SDL_InvalidParamError("surface");
+ }
+
+ if (!surface->internal->locked) {
#if SDL_HAVE_RLE
/* Perform the lock */
- if (surface->flags & SDL_RLEACCEL) {
- SDL_UnRLESurface(surface, 1);
- surface->flags |= SDL_RLEACCEL; /* save accel'd state */
+ if (surface->internal->flags & SDL_INTERNAL_SURFACE_RLEACCEL) {
+ SDL_UnRLESurface(surface, SDL_TRUE);
+ surface->internal->flags |= SDL_INTERNAL_SURFACE_RLEACCEL; /* save accel'd state */
+ SDL_UpdateSurfaceLockFlag(surface);
}
#endif
}
/* Increment the surface lock count, for recursive locks */
- ++surface->locked;
+ ++surface->internal->locked;
+ surface->flags |= SDL_SURFACE_LOCKED;
/* Ready to go.. */
return 0;
@@ -1155,18 +1191,24 @@ int SDL_LockSurface(SDL_Surface *surface)
*/
void SDL_UnlockSurface(SDL_Surface *surface)
{
+ if (!SDL_SurfaceValid(surface)) {
+ return;
+ }
+
/* Only perform an unlock if we are locked */
- if (!surface->locked || (--surface->locked > 0)) {
+ if (!surface->internal->locked || (--surface->internal->locked > 0)) {
return;
}
#if SDL_HAVE_RLE
/* Update RLE encoded surface with new data */
- if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
- surface->flags &= ~SDL_RLEACCEL; /* stop lying */
+ if (surface->internal->flags & SDL_INTERNAL_SURFACE_RLEACCEL) {
+ surface->internal->flags &= ~SDL_INTERNAL_SURFACE_RLEACCEL; /* stop lying */
SDL_RLESurface(surface);
}
#endif
+
+ surface->flags &= ~SDL_SURFACE_LOCKED;
}
static int SDL_FlipSurfaceHorizontal(SDL_Surface *surface)
@@ -1175,7 +1217,7 @@ static int SDL_FlipSurfaceHorizontal(SDL_Surface *surface)
Uint8 *row, *a, *b, *tmp;
int i, j, bpp;
- if (surface->format->bits_per_pixel < 8) {
+ if (SDL_BITSPERPIXEL(surface->format) < 8) {
/* We could implement this if needed, but we'd have to flip sets of bits within a byte */
return SDL_Unsupported();
}
@@ -1188,7 +1230,7 @@ static int SDL_FlipSurfaceHorizontal(SDL_Surface *surface)
return 0;
}
- bpp = surface->format->bytes_per_pixel;
+ bpp = SDL_BYTESPERPIXEL(surface->format);
row = (Uint8 *)surface->pixels;
tmp = SDL_small_alloc(Uint8, surface->pitch, &isstack);
for (i = surface->h; i--; ) {
@@ -1250,7 +1292,7 @@ int SDL_FlipSurface(SDL_Surface *surface, SDL_FlipMode flip)
}
}
-static SDL_Surface *SDL_ConvertSurfaceWithPixelFormatAndColorspace(SDL_Surface *surface, const SDL_PixelFormat *format, SDL_Colorspace colorspace, SDL_PropertiesID props)
+static SDL_Surface *SDL_ConvertSurfaceInternal(SDL_Surface *surface, SDL_PixelFormat format, SDL_Palette *palette, SDL_Colorspace colorspace, SDL_PropertiesID props)
{
SDL_Surface *convert;
SDL_Colorspace src_colorspace;
@@ -1265,41 +1307,35 @@ static SDL_Surface *SDL_ConvertSurfaceWithPixelFormatAndColorspace(SDL_Surface *
Uint8 *palette_saved_alpha = NULL;
int palette_saved_alpha_ncolors = 0;
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
SDL_InvalidParamError("surface");
return NULL;
}
- if (!format) {
+
+ if (format == SDL_PIXELFORMAT_UNKNOWN) {
SDL_InvalidParamError("format");
return NULL;
}
/* Check for empty destination palette! (results in empty image) */
- if (format->palette) {
+ if (palette) {
int i;
- for (i = 0; i < format->palette->ncolors; ++i) {
- if ((format->palette->colors[i].r != 0xFF) || (format->palette->colors[i].g != 0xFF) || (format->palette->colors[i].b != 0xFF)) {
+ for (i = 0; i < palette->ncolors; ++i) {
+ if ((palette->colors[i].r != 0xFF) || (palette->colors[i].g != 0xFF) || (palette->colors[i].b != 0xFF)) {
break;
}
}
- if (i == format->palette->ncolors) {
+ if (i == palette->ncolors) {
SDL_SetError("Empty destination palette");
return NULL;
}
}
- if (SDL_GetSurfaceColorspace(surface, &src_colorspace) < 0) {
- return NULL;
- }
-
- if (surface->flags & SDL_SURFACE_USES_PROPERTIES) {
- src_properties = SDL_GetSurfaceProperties(surface);
- } else {
- src_properties = 0;
- }
+ src_colorspace = SDL_GetSurfaceColorspace(surface);
+ src_properties = surface->internal->props;
/* Create a new surface with the desired format */
- convert = SDL_CreateSurface(surface->w, surface->h, format->format);
+ convert = SDL_CreateSurface(surface->w, surface->h, format);
if (!convert) {
return NULL;
}
@@ -1309,38 +1345,38 @@ static SDL_Surface *SDL_ConvertSurfaceWithPixelFormatAndColorspace(SDL_Surface *
}
SDL_SetSurfaceColorspace(convert, colorspace);
- if (SDL_ISPIXELFORMAT_FOURCC(format->format) || SDL_ISPIXELFORMAT_FOURCC(surface->format->format)) {
- if (SDL_ConvertPixelsAndColorspace(surface->w, surface->h, surface->format->format, src_colorspace, src_properties, surface->pixels, surface->pitch, convert->format->format, colorspace, props, convert->pixels, convert->pitch) < 0) {
+ if (SDL_ISPIXELFORMAT_FOURCC(format) || SDL_ISPIXELFORMAT_FOURCC(surface->format)) {
+ if (SDL_ConvertPixelsAndColorspace(surface->w, surface->h, surface->format, src_colorspace, src_properties, surface->pixels, surface->pitch, convert->format, colorspace, props, convert->pixels, convert->pitch) < 0) {
SDL_DestroySurface(convert);
return NULL;
}
/* Save the original copy flags */
- copy_flags = surface->map->info.flags;
+ copy_flags = surface->internal->map->info.flags;
goto end;
}
/* Copy the palette if any */
- if (format->palette && convert->format->palette) {
- SDL_memcpy(convert->format->palette->colors,
- format->palette->colors,
- format->palette->ncolors * sizeof(SDL_Color));
- convert->format->palette->ncolors = format->palette->ncolors;
+ if (palette && convert->internal->palette) {
+ SDL_memcpy(convert->internal->palette->colors,
+ palette->colors,
+ palette->ncolors * sizeof(SDL_Color));
+ convert->internal->palette->ncolors = palette->ncolors;
}
/* Save the original copy flags */
- copy_flags = surface->map->info.flags;
- copy_color.r = surface->map->info.r;
- copy_color.g = surface->map->info.g;
- copy_color.b = surface->map->info.b;
- copy_color.a = surface->map->info.a;
- surface->map->info.r = 0xFF;
- surface->map->info.g = 0xFF;
- surface->map->info.b = 0xFF;
- surface->map->info.a = 0xFF;
- surface->map->info.flags = (copy_flags & (SDL_COPY_RLE_COLORKEY | SDL_COPY_RLE_ALPHAKEY));
- SDL_InvalidateMap(surface->map);
+ copy_flags = surface->internal->map->info.flags;
+ copy_color.r = surface->internal->map->info.r;
+ copy_color.g = surface->internal->map->info.g;
+ copy_color.b = surface->internal->map->info.b;
+ copy_color.a = surface->internal->map->info.a;
+ surface->internal->map->info.r = 0xFF;
+ surface->internal->map->info.g = 0xFF;
+ surface->internal->map->info.b = 0xFF;
+ surface->internal->map->info.a = 0xFF;
+ surface->internal->map->info.flags = (copy_flags & (SDL_COPY_RLE_COLORKEY | SDL_COPY_RLE_ALPHAKEY));
+ SDL_InvalidateMap(surface->internal->map);
/* Copy over the image data */
bounds.x = 0;
@@ -1351,11 +1387,11 @@ static SDL_Surface *SDL_ConvertSurfaceWithPixelFormatAndColorspace(SDL_Surface *
/* Source surface has a palette with no real alpha (0 or OPAQUE).
* Destination format has alpha.
* -> set alpha channel to be opaque */
- if (surface->format->palette && format->Amask) {
+ if (surface->internal->palette && SDL_ISPIXELFORMAT_ALPHA(format)) {
SDL_bool set_opaque = SDL_FALSE;
SDL_bool is_opaque, has_alpha_channel;
- SDL_DetectPalette(surface->format->palette, &is_opaque, &has_alpha_channel);
+ SDL_DetectPalette(surface->internal->palette, &is_opaque, &has_alpha_channel);
if (is_opaque) {
if (!has_alpha_channel) {
@@ -1368,12 +1404,12 @@ static SDL_Surface *SDL_ConvertSurfaceWithPixelFormatAndColorspace(SDL_Surface *
/* Set opaque and backup palette alpha values */
if (set_opaque) {
int i;
- palette_saved_alpha_ncolors = surface->format->palette->ncolors;
+ palette_saved_alpha_ncolors = surface->internal->palette->ncolors;
if (palette_saved_alpha_ncolors > 0) {
palette_saved_alpha = SDL_stack_alloc(Uint8, palette_saved_alpha_ncolors);
for (i = 0; i < palette_saved_alpha_ncolors; i++) {
- palette_saved_alpha[i] = surface->format->palette->colors[i].a;
- surface->format->palette->colors[i].a = SDL_ALPHA_OPAQUE;
+ palette_saved_alpha[i] = surface->internal->palette->colors[i].a;
+ surface->internal->palette->colors[i].a = SDL_ALPHA_OPAQUE;
}
}
}
@@ -1381,11 +1417,11 @@ static SDL_Surface *SDL_ConvertSurfaceWithPixelFormatAndColorspace(SDL_Surface *
/* Transform colorkey to alpha. for cases where source palette has duplicate values, and colorkey is one of them */
if (copy_flags & SDL_COPY_COLORKEY) {
- if (surface->format->palette && !format->palette) {
+ if (surface->internal->palette && !palette) {
palette_ck_transform = SDL_TRUE;
palette_has_alpha = SDL_TRUE;
- palette_ck_value = surface->format->palette->colors[surface->map->info.colorkey].a;
- surface->format->palette->colors[surface->map->info.colorkey].a = SDL_ALPHA_TRANSPARENT;
+ palette_ck_value = surface->internal->palette->colors[surface->internal->map->info.colorkey].a;
+ surface->internal->palette->colors[surface->internal->map->info.colorkey].a = SDL_ALPHA_TRANSPARENT;
}
}
@@ -1393,33 +1429,33 @@ static SDL_Surface *SDL_ConvertSurfaceWithPixelFormatAndColorspace(SDL_Surface *
/* Restore colorkey alpha value */
if (palette_ck_transform) {
- surface->format->palette->colors[surface->map->info.colorkey].a = palette_ck_value;
+ surface->internal->palette->colors[surface->internal->map->info.colorkey].a = palette_ck_value;
}
/* Restore palette alpha values */
if (palette_saved_alpha) {
int i;
for (i = 0; i < palette_saved_alpha_ncolors; i++) {
- surface->format->palette->colors[i].a = palette_saved_alpha[i];
+ surface->internal->palette->colors[i].a = palette_saved_alpha[i];
}
SDL_stack_free(palette_saved_alpha);
}
/* Clean up the original surface, and update converted surface */
- convert->map->info.r = copy_color.r;
- convert->map->info.g = copy_color.g;
- convert->map->info.b = copy_color.b;
- convert->map->info.a = copy_color.a;
- convert->map->info.flags =
+ convert->internal->map->info.r = copy_color.r;
+ convert->internal->map->info.g = copy_color.g;
+ convert->internal->map->info.b = copy_color.b;
+ convert->internal->map->info.a = copy_color.a;
+ convert->internal->map->info.flags =
(copy_flags &
~(SDL_COPY_COLORKEY | SDL_COPY_BLEND | SDL_COPY_RLE_DESIRED | SDL_COPY_RLE_COLORKEY |
SDL_COPY_RLE_ALPHAKEY));
- surface->map->info.r = copy_color.r;
- surface->map->info.g = copy_color.g;
- surface->map->info.b = copy_color.b;
- surface->map->info.a = copy_color.a;
- surface->map->info.flags = copy_flags;
- SDL_InvalidateMap(surface->map);
+ surface->internal->map->info.r = copy_color.r;
+ surface->internal->map->info.g = copy_color.g;
+ surface->internal->map->info.b = copy_color.b;
+ surface->internal->map->info.a = copy_color.a;
+ surface->internal->map->info.flags = copy_flags;
+ SDL_InvalidateMap(surface->internal->map);
/* SDL_BlitSurfaceUnchecked failed, and so the conversion */
if (ret < 0) {
@@ -1431,15 +1467,15 @@ static SDL_Surface *SDL_ConvertSurfaceWithPixelFormatAndColorspace(SDL_Surface *
SDL_bool set_colorkey_by_color = SDL_FALSE;
SDL_bool convert_colorkey = SDL_TRUE;
- if (surface->format->palette) {
- if (format->palette &&
- surface->format->palette->ncolors <= format->palette->ncolors &&
- (SDL_memcmp(surface->format->palette->colors, format->palette->colors,
- surface->format->palette->ncolors * sizeof(SDL_Color)) == 0)) {
+ if (surface->internal->palette) {
+ if (palette &&
+ surface->internal->palette->ncolors <= palette->ncolors &&
+ (SDL_memcmp(surface->internal->palette->colors, palette->colors,
+ surface->internal->palette->ncolors * sizeof(SDL_Color)) == 0)) {
/* The palette is identical, just set the same colorkey */
- SDL_SetSurfaceColorKey(convert, 1, surface->map->info.colorkey);
- } else if (!format->palette) {
- if (format->Amask) {
+ SDL_SetSurfaceColorKey(convert, 1, surface->internal->map->info.colorkey);
+ } else if (!palette) {
+ if (SDL_ISPIXELFORMAT_ALPHA(format)) {
/* No need to add the colorkey, transparency is in the alpha channel*/
} else {
/* Only set the colorkey information */
@@ -1459,23 +1495,23 @@ static SDL_Surface *SDL_ConvertSurfaceWithPixelFormatAndColorspace(SDL_Surface *
int converted_colorkey = 0;
/* Create a dummy surface to get the colorkey converted */
- tmp = SDL_CreateSurface(1, 1, surface->format->format);
+ tmp = SDL_CreateSurface(1, 1, surface->format);
if (!tmp) {
SDL_DestroySurface(convert);
return NULL;
}
/* Share the palette, if any */
- if (surface->format->palette) {
- SDL_SetSurfacePalette(tmp, surface->format->palette);
+ if (surface->internal->palette) {
+ SDL_SetSurfacePalette(tmp, surface->internal->palette);
}
- SDL_FillSurfaceRect(tmp, NULL, surface->map->info.colorkey);
+ SDL_FillSurfaceRect(tmp, NULL, surface->internal->map->info.colorkey);
- tmp->map->info.flags &= ~SDL_COPY_COLORKEY;
+ tmp->internal->map->info.flags &= ~SDL_COPY_COLORKEY;
/* Conversion of the colorkey */
- tmp2 = SDL_ConvertSurfaceWithPixelFormatAndColorspace(tmp, format, colorspace, props);
+ tmp2 = SDL_ConvertSurfaceAndColorspace(tmp, format, colorspace, props);
if (!tmp2) {
SDL_DestroySurface(tmp);
SDL_DestroySurface(convert);
@@ -1483,7 +1519,7 @@ static SDL_Surface *SDL_ConvertSurfaceWithPixelFormatAndColorspace(SDL_Surface *
}
/* Get the converted colorkey */
- SDL_memcpy(&converted_colorkey, tmp2->pixels, tmp2->format->bytes_per_pixel);
+ SDL_memcpy(&converted_colorkey, tmp2->pixels, tmp2->internal->format->bytes_per_pixel);
SDL_DestroySurface(tmp);
SDL_DestroySurface(tmp2);
@@ -1500,17 +1536,17 @@ static SDL_Surface *SDL_ConvertSurfaceWithPixelFormatAndColorspace(SDL_Surface *
end:
- SDL_SetSurfaceClipRect(convert, &surface->clip_rect);
+ SDL_SetSurfaceClipRect(convert, &surface->internal->clip_rect);
/* Enable alpha blending by default if the new surface has an
* alpha channel or alpha modulation */
- if ((surface->format->Amask && format->Amask) ||
- (palette_has_alpha && format->Amask) ||
+ if ((SDL_ISPIXELFORMAT_ALPHA(surface->format) && SDL_ISPIXELFORMAT_ALPHA(format)) ||
+ (palette_has_alpha && SDL_ISPIXELFORMAT_ALPHA(format)) ||
(copy_flags & SDL_COPY_MODULATE_ALPHA)) {
SDL_SetSurfaceBlendMode(convert, SDL_BLENDMODE_BLEND);
}
if (copy_flags & SDL_COPY_RLE_DESIRED) {
- SDL_SetSurfaceRLE(convert, SDL_RLEACCEL);
+ SDL_SetSurfaceRLE(convert, SDL_TRUE);
}
/* We're ready to go! */
@@ -1519,82 +1555,41 @@ static SDL_Surface *SDL_ConvertSurfaceWithPixelFormatAndColorspace(SDL_Surface *
SDL_Surface *SDL_DuplicateSurface(SDL_Surface *surface)
{
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
SDL_InvalidParamError("surface");
return NULL;
}
- return SDL_ConvertSurfaceWithPixelFormatAndColorspace(surface, surface->format, SDL_COLORSPACE_UNKNOWN, 0);
+ return SDL_ConvertSurfaceInternal(surface, surface->format, surface->internal->palette, SDL_GetSurfaceColorspace(surface), surface->internal->props);
}
-SDL_Surface *SDL_ConvertSurface(SDL_Surface *surface, const SDL_PixelFormat *format)
+SDL_Surface *SDL_ConvertSurface(SDL_Surface *surface, SDL_PixelFormat format)
{
- SDL_Colorspace colorspace;
-
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
SDL_InvalidParamError("surface");
return NULL;
}
- if (!format) {
- SDL_InvalidParamError("format");
- return NULL;
- }
-
- colorspace = SDL_GetDefaultColorspaceForFormat(format->format);
-
- return SDL_ConvertSurfaceWithPixelFormatAndColorspace(surface, format, colorspace, 0);
+ return SDL_ConvertSurfaceInternal(surface, format, NULL, SDL_GetDefaultColorspaceForFormat(format), surface->internal->props);
}
-SDL_Surface *SDL_ConvertSurfaceFormat(SDL_Surface *surface, SDL_PixelFormatEnum pixel_format)
+SDL_Surface *SDL_ConvertSurfaceAndColorspace(SDL_Surface *surface, SDL_PixelFormat format, SDL_Colorspace colorspace, SDL_PropertiesID props)
{
- SDL_Colorspace colorspace;
- SDL_PropertiesID props;
-
- if (!surface) {
- SDL_InvalidParamError("surface");
- return NULL;
- }
-
- colorspace = SDL_GetDefaultColorspaceForFormat(pixel_format);
-
- if (surface->flags & SDL_SURFACE_USES_PROPERTIES) {
- props = SDL_GetSurfaceProperties(surface);
- } else {
- props = 0;
- }
-
- return SDL_ConvertSurfaceFormatAndColorspace(surface, pixel_format, colorspace, props);
-}
-
-SDL_Surface *SDL_ConvertSurfaceFormatAndColorspace(SDL_Surface *surface, SDL_PixelFormatEnum pixel_format, SDL_Colorspace colorspace, SDL_PropertiesID props)
-{
- SDL_PixelFormat *format;
- SDL_Surface *convert = NULL;
-
- format = SDL_CreatePixelFormat(pixel_format);
- if (format) {
- convert = SDL_ConvertSurfaceWithPixelFormatAndColorspace(surface, format, colorspace, props);
- SDL_DestroyPixelFormat(format);
- }
- return convert;
+ return SDL_ConvertSurfaceInternal(surface, format, NULL, colorspace, props);
}
/*
* Create a surface on the stack for quick blit operations
*/
-static SDL_bool SDL_CreateSurfaceOnStack(int width, int height, SDL_PixelFormatEnum pixel_format, SDL_Colorspace colorspace, SDL_PropertiesID props, void *pixels, int pitch, SDL_Surface *surface, SDL_PixelFormat *format, SDL_BlitMap *blitmap)
+static SDL_bool SDL_CreateSurfaceOnStack(int width, int height, SDL_PixelFormat format, SDL_Colorspace colorspace, SDL_PropertiesID props, void *pixels, int pitch, SDL_Surface *surface, SDL_BlitMap *blitmap)
{
- if (SDL_ISPIXELFORMAT_INDEXED(pixel_format)) {
+ if (SDL_ISPIXELFORMAT_INDEXED(format)) {
SDL_SetError("Indexed pixel formats not supported");
return SDL_FALSE;
}
- if (SDL_InitFormat(format, pixel_format) < 0) {
- return SDL_FALSE;
- }
SDL_zerop(surface);
- surface->flags = SDL_PREALLOC;
+ surface->flags = SDL_SURFACE_PREALLOCATED;
surface->format = format;
surface->pixels = pixels;
surface->w = width;
@@ -1609,7 +1604,7 @@ static SDL_bool SDL_CreateSurfaceOnStack(int width, int height, SDL_PixelFormatE
blitmap->info.g = 0xFF;
blitmap->info.b = 0xFF;
blitmap->info.a = 0xFF;
- surface->map = blitmap;
+ surface->internal->map = blitmap;
SDL_SetSurfaceColorspace(surface, colorspace);
@@ -1628,14 +1623,14 @@ static SDL_bool SDL_CreateSurfaceOnStack(int width, int height, SDL_PixelFormatE
static void SDL_DestroySurfaceOnStack(SDL_Surface *surface)
{
/* Free blitmap reference, after blitting between stack'ed surfaces */
- SDL_InvalidateMap(surface->map);
+ SDL_InvalidateMap(surface->internal->map);
- if (surface->flags & SDL_SURFACE_USES_PROPERTIES) {
- SDL_DestroyProperties(SDL_GetSurfaceProperties(surface));
+ if (surface->internal->props) {
+ SDL_DestroyProperties(surface->internal->props);
}
}
-SDL_Surface *SDL_DuplicatePixels(int width, int height, SDL_PixelFormatEnum format, SDL_Colorspace colorspace, void *pixels, int pitch)
+SDL_Surface *SDL_DuplicatePixels(int width, int height, SDL_PixelFormat format, SDL_Colorspace colorspace, void *pixels, int pitch)
{
SDL_Surface *surface = SDL_CreateSurface(width, height, format);
if (surface) {
@@ -1655,11 +1650,10 @@ SDL_Surface *SDL_DuplicatePixels(int width, int height, SDL_PixelFormatEnum form
}
int SDL_ConvertPixelsAndColorspace(int width, int height,
- SDL_PixelFormatEnum src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch,
- SDL_PixelFormatEnum dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch)
+ SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch,
+ SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch)
{
SDL_Surface src_surface, dst_surface;
- SDL_PixelFormat src_fmt, dst_fmt;
SDL_BlitMap src_blitmap, dst_blitmap;
SDL_Rect rect;
void *nonconst_src = (void *)src;
@@ -1712,11 +1706,11 @@ int SDL_ConvertPixelsAndColorspace(int width, int height,
return 0;
}
- if (!SDL_CreateSurfaceOnStack(width, height, src_format, src_colorspace, src_properties, nonconst_src, src_pitch, &src_surface, &src_fmt, &src_blitmap)) {
+ if (!SDL_CreateSurfaceOnStack(width, height, src_format, src_colorspace, src_properties, nonconst_src, src_pitch, &src_surface, &src_blitmap)) {
return -1;
}
- if (!SDL_CreateSurfaceOnStack(width, height, dst_format, dst_colorspace, dst_properties, dst, dst_pitch, &dst_surface, &dst_fmt, &dst_blitmap)) {
+ if (!SDL_CreateSurfaceOnStack(width, height, dst_format, dst_colorspace, dst_properties, dst, dst_pitch, &dst_surface, &dst_blitmap)) {
return -1;
}
@@ -1734,8 +1728,8 @@ int SDL_ConvertPixelsAndColorspace(int width, int height,
}
int SDL_ConvertPixels(int width, int height,
- SDL_PixelFormatEnum src_format, const void *src, int src_pitch,
- SDL_PixelFormatEnum dst_format, void *dst, int dst_pitch)
+ SDL_PixelFormat src_format, const void *src, int src_pitch,
+ SDL_PixelFormat dst_format, void *dst, int dst_pitch)
{
return SDL_ConvertPixelsAndColorspace(width, height,
src_format, SDL_COLORSPACE_UNKNOWN, 0, src, src_pitch,
@@ -1752,8 +1746,8 @@ int SDL_ConvertPixels(int width, int height,
* https://developer.arm.com/documentation/101964/0201/Pre-multiplied-alpha-channel-data
*/
int SDL_PremultiplyAlpha(int width, int height,
- SDL_PixelFormatEnum src_format, const void *src, int src_pitch,
- SDL_PixelFormatEnum dst_format, void *dst, int dst_pitch)
+ SDL_PixelFormat src_format, const void *src, int src_pitch,
+ SDL_PixelFormat dst_format, void *dst, int dst_pitch)
{
int c;
Uint32 srcpixel;
@@ -1841,7 +1835,7 @@ int SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g,
a = &unused;
}
- bytes_per_pixel = surface->format->bytes_per_pixel;
+ bytes_per_pixel = SDL_BYTESPERPIXEL(surface->format);
if (SDL_MUSTLOCK(surface)) {
SDL_LockSurface(surface);
@@ -1852,10 +1846,9 @@ int SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g,
if (bytes_per_pixel > sizeof(pixel)) {
/* This is really slow, but it gets the job done */
Uint8 rgba[4];
- SDL_Colorspace colorspace;
+ SDL_Colorspace colorspace = SDL_GetSurfaceColorspace(surface);
- if (SDL_GetSurfaceColorspace(surface, &colorspace) == 0 &&
- SDL_ConvertPixelsAndColorspace(1, 1, surface->format->format, colorspace, SDL_GetSurfaceProperties(surface), p, surface->pitch, SDL_PIXELFORMAT_RGBA32, SDL_COLORSPACE_SRGB, 0, rgba, sizeof(rgba)) == 0) {
+ if (SDL_ConvertPixelsAndColorspace(1, 1, surface->format, colorspace, surface->internal->props, p, surface->pitch, SDL_PIXELFORMAT_RGBA32, SDL_COLORSPACE_SRGB, 0, rgba, sizeof(rgba)) == 0) {
*r = rgba[0];
*g = rgba[1];
*b = rgba[2];
@@ -1870,7 +1863,7 @@ int SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g,
#else
SDL_memcpy(&pixel, p, bytes_per_pixel);
#endif
- SDL_GetRGBA(pixel, surface->format, r, g, b, a);
+ SDL_GetRGBA(pixel, surface->format, surface->internal->palette, r, g, b, a);
result = 0;
}
@@ -1885,48 +1878,41 @@ int SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g,
*/
void SDL_DestroySurface(SDL_Surface *surface)
{
- if (!surface) {
+ if (!SDL_SurfaceValid(surface)) {
return;
}
- if (surface->flags & SDL_DONTFREE) {
+ if (surface->internal->flags & SDL_INTERNAL_SURFACE_DONTFREE) {
return;
}
if (--surface->refcount > 0) {
return;
}
- if (surface->flags & SDL_SURFACE_USES_PROPERTIES) {
- SDL_PropertiesID props = (SDL_PropertiesID)(uintptr_t)surface->reserved;
- SDL_DestroyProperties(props);
- }
+ SDL_DestroyProperties(surface->internal->props);
- SDL_InvalidateMap(surface->map);
+ SDL_InvalidateMap(surface->internal->map);
SDL_InvalidateAllBlitMap(surface);
- while (surface->locked > 0) {
+ while (surface->internal->locked > 0) {
SDL_UnlockSurface(surface);
}
#if SDL_HAVE_RLE
- if (surface->flags & SDL_RLEACCEL) {
+ if (surface->internal->flags & SDL_INTERNAL_SURFACE_RLEACCEL) {
SDL_UnRLESurface(surface, 0);
}
#endif
- if (surface->format) {
- SDL_SetSurfacePalette(surface, NULL);
- SDL_DestroyPixelFormat(surface->format);
- surface->format = NULL;
- }
- if (surface->flags & SDL_PREALLOC) {
+ SDL_SetSurfacePalette(surface, NULL);
+
+ if (surface->flags & SDL_SURFACE_PREALLOCATED) {
/* Don't free */
- } else if (surface->flags & SDL_SIMD_ALIGNED) {
+ } else if (surface->flags & SDL_SURFACE_SIMD_ALIGNED) {
/* Free aligned */
SDL_aligned_free(surface->pixels);
} else {
/* Normal */
SDL_free(surface->pixels);
}
- if (surface->map) {
- SDL_FreeBlitMap(surface->map);
- }
+ SDL_free(surface->internal);
+ surface->internal = NULL;
SDL_free(surface);
}
diff --git a/src/video/SDL_surface_c.h b/src/video/SDL_surface_c.h
new file mode 100644
index 00000000000000..bd958b142d9d72
--- /dev/null
+++ b/src/video/SDL_surface_c.h
@@ -0,0 +1,74 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2024 Sam Lantinga
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_surface_c_h_
+#define SDL_surface_c_h_
+
+#include "SDL_internal.h"
+
+/* Useful functions and variables from SDL_surface.c */
+
+#include "SDL_blit.h"
+#include "../SDL_list.h"
+
+/* Surface internal flags */
+typedef Uint32 SDL_SurfaceDataFlags;
+
+#define SDL_INTERNAL_SURFACE_RLEACCEL 0x00000001u /**< Surface is RLE encoded */
+#define SDL_INTERNAL_SURFACE_DONTFREE 0x00000002u /**< Surface is referenced internally */
+
+/* Surface internal data definition */
+struct SDL_SurfaceData
+{
+ /** flags for this surface */
+ SDL_SurfaceDataFlags flags;
+
+ /** properties for this surface */
+ SDL_PropertiesID props;
+
+ /** detailed format for this surface */
+ const SDL_PixelFormatDetails *format;
+
+ /** palette for indexed surfaces */
+ SDL_Palette *palette;
+
+ /** information needed for surfaces requiring locks */
+ int locked;
+
+ /** clipping information */
+ SDL_Rect clip_rect;
+
+ /** info for fast blit mapping to other surfaces */
+ SDL_BlitMap *map;
+
+ /** list of BlitMap that hold a reference to this surface */
+ SDL_ListNode *list_blitmap;
+};
+
+/* Surface functions */
+extern SDL_bool SDL_SurfaceValid(SDL_Surface *surface);
+extern void SDL_UpdateSurfaceLockFlag(SDL_Surface *surface);
+extern float SDL_GetDefaultSDRWhitePoint(SDL_Colorspace colorspace);
+extern float SDL_GetSurfaceSDRWhitePoint(SDL_Surface *surface, SDL_Colorspace colorspace);
+extern float SDL_GetDefaultHDRHeadroom(SDL_Colorspace colorspace);
+extern float SDL_GetSurfaceHDRHeadroom(SDL_Surface *surface, SDL_Colorspace colorspace);
+
+#endif /* SDL_surface_c_h_ */
diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h
index 0a5e7b56b7a1bb..f648fd0e222ff0 100644
--- a/src/video/SDL_sysvideo.h
+++ b/src/video/SDL_sysvideo.h
@@ -268,7 +268,7 @@ struct SDL_VideoDevice
int (*SetWindowMouseGrab)(SDL_VideoDevice *_this, SDL_Window *window, SDL_bool grabbed);
int (*SetWindowKeyboardGrab)(SDL_VideoDevice *_this, SDL_Window *window, SDL_bool grabbed);
void (*DestroyWindow)(SDL_VideoDevice *_this, SDL_Window *window);
- int (*CreateWindowFramebuffer)(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormatEnum *format, void **pixels, int *pitch);
+ int (*CreateWindowFramebuffer)(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch);
int (*SetWindowFramebufferVSync)(SDL_VideoDevice *_this, SDL_Window *window, int vsync);
int (*GetWindowFramebufferVSync)(SDL_VideoDevice *_this, SDL_Window *window, int *vsync);
int (*UpdateWindowFramebuffer)(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects);
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index e4939cd2da2c06..82de50bd8d3843 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -284,14 +284,14 @@ static void SDLCALL SDL_CleanupWindowTextureData(void *userdata, void *value)
SDL_free(data);
}
-static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormatEnum *format, void **pixels, int *pitch)
+static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch)
{
SDL_PropertiesID props = SDL_GetWindowProperties(window);
SDL_WindowTextureData *data = (SDL_WindowTextureData *)SDL_GetProperty(props, SDL_PROP_WINDOW_TEXTUREDATA_POINTER, NULL);
const SDL_bool transparent = (window->flags & SDL_WINDOW_TRANSPARENT) ? SDL_TRUE : SDL_FALSE;
int i;
int w, h;
- const SDL_PixelFormatEnum *texture_formats;
+ const SDL_PixelFormat *texture_formats;
SDL_GetWindowSizeInPixels(window, &w, &h);
@@ -355,7 +355,7 @@ static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, S
data->renderer = renderer;
}
- texture_formats = (const SDL_PixelFormatEnum *)SDL_GetProperty(SDL_GetRendererProperties(data->renderer), SDL_PROP_RENDERER_TEXTURE_FORMATS_POINTER, NULL);
+ texture_formats = (const SDL_PixelFormat *)SDL_GetProperty(SDL_GetRendererProperties(data->renderer), SDL_PROP_RENDERER_TEXTURE_FORMATS_POINTER, NULL);
if (!texture_formats) {
return -1;
}
@@ -372,7 +372,7 @@ static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, S
*format = texture_formats[0];
for (i = 0; texture_formats[i] != SDL_PIXELFORMAT_UNKNOWN; ++i) {
- SDL_PixelFormatEnum texture_format = texture_formats[i];
+ SDL_PixelFormat texture_format = texture_formats[i];
if (!SDL_ISPIXELFORMAT_FOURCC(texture_format) &&
!SDL_ISPIXELFORMAT_10BIT(texture_format) &&
!SDL_ISPIXELFORMAT_FLOAT(texture_format) &&
@@ -2657,7 +2657,7 @@ int SDL_SetWindowIcon(SDL_Window *window, SDL_Surface *icon)
SDL_DestroySurface(window->icon);
/* Convert the icon into ARGB8888 */
- window->icon = SDL_ConvertSurfaceFormat(icon, SDL_PIXELFORMAT_ARGB8888);
+ window->icon = SDL_ConvertSurface(icon, SDL_PIXELFORMAT_ARGB8888);
if (!window->icon) {
return -1;
}
@@ -3292,7 +3292,7 @@ static SDL_bool ShouldAttemptTextureFramebuffer(void)
static SDL_Surface *SDL_CreateWindowFramebuffer(SDL_Window *window)
{
- SDL_PixelFormatEnum format = SDL_PIXELFORMAT_UNKNOWN;
+ SDL_PixelFormat format = SDL_PIXELFORMAT_UNKNOWN;
void *pixels = NULL;
int pitch = 0;
SDL_bool created_framebuffer = SDL_FALSE;
@@ -3343,7 +3343,7 @@ static SDL_Surface *SDL_CreateWindowFramebuffer(SDL_Window *window)
return window->surface;
}
- return SDL_CreateSurfaceFrom(pixels, w, h, pitch, format);
+ return SDL_CreateSurfaceFrom(w, h, format, pixels, pitch);
}
SDL_bool SDL_WindowHasSurface(SDL_Window *window)
@@ -3359,7 +3359,7 @@ SDL_Surface *SDL_GetWindowSurface(SDL_Window *window)
if (!window->surface_valid) {
if (window->surface) {
- window->surface->flags &= ~SDL_DONTFREE;
+ window->surface->internal->flags &= ~SDL_INTERNAL_SURFACE_DONTFREE;
SDL_DestroySurface(window->surface);
window->surface = NULL;
}
@@ -3367,7 +3367,7 @@ SDL_Surface *SDL_GetWindowSurface(SDL_Window *window)
window->surface = SDL_CreateWindowFramebuffer(window);
if (window->surface) {
window->surface_valid = SDL_TRUE;
- window->surface->flags |= SDL_DONTFREE;
+ window->surface->internal->flags |= SDL_INTERNAL_SURFACE_DONTFREE;
}
}
return window->surface;
@@ -3425,7 +3425,7 @@ int SDL_DestroyWindowSurface(SDL_Window *window)
CHECK_WINDOW_MAGIC(window, -1);
if (window->surface) {
- window->surface->flags &= ~SDL_DONTFREE;
+ window->surface->internal->flags &= ~SDL_INTERNAL_SURFACE_DONTFREE;
SDL_DestroySurface(window->surface);
window->surface = NULL;
window->surface_valid = SDL_FALSE;
@@ -4949,7 +4949,7 @@ static void CreateMaskFromColorKeyOrAlpha(SDL_Surface *icon, Uint8 *mask, int fl
mask[(y * ((icon->w + 7) / 8)) + (x / 8)] &= ~(0x01 << (7 - (x % 8)))
colorkey = icon->format->colorkey;
- switch (icon->format->bytes_per_pixel) {
+ switch (SDL_BYTESPERPIXEL(icon->format)) {
case 1:
{
Uint8 *pixels;
@@ -5370,7 +5370,7 @@ int SDL_SetWindowShape(SDL_Window *window, SDL_Surface *shape)
return -1;
}
- surface = SDL_ConvertSurfaceFormat(shape, SDL_PIXELFORMAT_ARGB32);
+ surface = SDL_ConvertSurface(shape, SDL_PIXELFORMAT_ARGB32);
if (!surface) {
return -1;
}
diff --git a/src/video/SDL_yuv.c b/src/video/SDL_yuv.c
index ca5c14e340f8e0..818a661ff9c701 100644
--- a/src/video/SDL_yuv.c
+++ b/src/video/SDL_yuv.c
@@ -27,7 +27,7 @@
#if SDL_HAVE_YUV
-static SDL_bool IsPlanar2x2Format(SDL_PixelFormatEnum format);
+static SDL_bool IsPlanar2x2Format(SDL_PixelFormat format);
#endif
/*
@@ -36,7 +36,7 @@ static SDL_bool IsPlanar2x2Format(SDL_PixelFormatEnum format);
*
* return 0 on success, -1 on error
*/
-int SDL_CalculateYUVSize(SDL_PixelFormatEnum format, int w, int h, size_t *size, size_t *pitch)
+int SDL_CalculateYUVSize(SDL_PixelFormat format, int w, int h, size_t *size, size_t *pitch)
{
#if SDL_HAVE_YUV
int sz_plane = 0, sz_plane_chroma = 0, sz_plane_packed = 0;
@@ -187,7 +187,7 @@ static int GetYUVConversionType(SDL_Colorspace colorspace, YCbCrType *yuv_type)
return SDL_SetError("Unsupported YUV colorspace");
}
-static SDL_bool IsPlanar2x2Format(SDL_PixelFormatEnum format)
+static SDL_bool IsPlanar2x2Format(SDL_PixelFormat format)
{
return format == SDL_PIXELFORMAT_YV12 || format == SDL_PIXELFORMAT_IYUV || format == SDL_PIXELFORMAT_NV12 || format == SDL_PIXELFORMAT_NV21 || format == SDL_PIXELFORMAT_P010;
}
@@ -197,7 +197,7 @@ static SDL_bool IsPacked4Format(Uint32 format)
return format == SDL_PIXELFORMAT_YUY2 || format == SDL_PIXELFORMAT_UYVY || format == SDL_PIXELFORMAT_YVYU;
}
-static int GetYUVPlanes(int width, int height, SDL_PixelFormatEnum format, const void *yuv, int yuv_pitch,
+static int GetYUVPlanes(int width, int height, SDL_PixelFormat format, const void *yuv, int yuv_pitch,
const Uint8 **y, const Uint8 **u, const Uint8 **v, Uint32 *y_stride, Uint32 *uv_stride)
{
const Uint8 *planes[3] = { NULL, NULL, NULL };
@@ -304,7 +304,7 @@ static int GetYUVPlanes(int width, int height, SDL_PixelFormatEnum format, const
#ifdef SDL_SSE2_INTRINSICS
static SDL_bool SDL_TARGETING("sse2") yuv_rgb_sse(
- SDL_PixelFormatEnum src_format, SDL_PixelFormatEnum dst_format,
+ SDL_PixelFormat src_format, SDL_PixelFormat dst_format,
Uint32 width, Uint32 height,
const Uint8 *y, const Uint8 *u, const Uint8 *v, Uint32 y_stride, Uint32 uv_stride,
Uint8 *rgb, Uint32 rgb_stride,
@@ -411,7 +411,7 @@ static SDL_bool SDL_TARGETING("sse2") yuv_rgb_sse(
}
#else
static SDL_bool yuv_rgb_sse(
- SDL_PixelFormatEnum src_format, SDL_PixelFormatEnum dst_format,
+ SDL_PixelFormat src_format, SDL_PixelFormat dst_format,
Uint32 width, Uint32 height,
const Uint8 *y, const Uint8 *u, const Uint8 *v, Uint32 y_stride, Uint32 uv_stride,
Uint8 *rgb, Uint32 rgb_stride,
@@ -423,7 +423,7 @@ static SDL_bool yuv_rgb_sse(
#ifdef SDL_LSX_INTRINSICS
static SDL_bool yuv_rgb_lsx(
- SDL_PixelFormatEnum src_format, SDL_PixelFormatEnum dst_format,
+ SDL_PixelFormat src_format, SDL_PixelFormat dst_format,
Uint32 width, Uint32 height,
const Uint8 *y, const Uint8 *u, const Uint8 *v, Uint32 y_stride, Uint32 uv_stride,
Uint8 *rgb, Uint32 rgb_stride,
@@ -463,7 +463,7 @@ static SDL_bool yuv_rgb_lsx(
}
#else
static SDL_bool yuv_rgb_lsx(
- SDL_PixelFormatEnum src_format, SDL_PixelFormatEnum dst_format,
+ SDL_PixelFormat src_format, SDL_PixelFormat dst_format,
Uint32 width, Uint32 height,
const Uint8 *y, const Uint8 *u, const Uint8 *v, Uint32 y_stride, Uint32 uv_stride,
Uint8 *rgb, Uint32 rgb_stride,
@@ -474,7 +474,7 @@ static SDL_bool yuv_rgb_lsx(
#endif
static SDL_bool yuv_rgb_std(
- SDL_PixelFormatEnum src_format, SDL_PixelFormatEnum dst_format,
+ SDL_PixelFormat src_format, SDL_PixelFormat dst_format,
Uint32 width, Uint32 height,
const Uint8 *y, const Uint8 *u, const Uint8 *v, Uint32 y_stride, Uint32 uv_stride,
Uint8 *rgb, Uint32 rgb_stride,
@@ -587,8 +587,8 @@ static SDL_bool yuv_rgb_std(
}
int SDL_ConvertPixels_YUV_to_RGB(int width, int height,
- SDL_PixelFormatEnum src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch,
- SDL_PixelFormatEnum dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch)
+ SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch,
+ SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch)
{
const Uint8 *y = NULL;
const Uint8 *u = NULL;
@@ -709,7 +709,7 @@ static struct RGB2YUVFactors RGB2YUVFactorTables[] = {
},
};
-static int SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void *src, int src_pitch, SDL_PixelFormatEnum dst_format, void *dst, int dst_pitch, YCbCrType yuv_type)
+static int SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch, YCbCrType yuv_type)
{
const int src_pitch_x_2 = src_pitch * 2;
const int height_half = height / 2;
@@ -1000,7 +1000,7 @@ static int SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void *
return 0;
}
-static int SDL_ConvertPixels_XBGR2101010_to_P010(int width, int height, const void *src, int src_pitch, SDL_PixelFormatEnum dst_format, void *dst, int dst_pitch, YCbCrType yuv_type)
+static int SDL_ConvertPixels_XBGR2101010_to_P010(int width, int height, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch, YCbCrType yuv_type)
{
const int src_pitch_x_2 = src_pitch * 2;
const int height_half = height / 2;
@@ -1123,8 +1123,8 @@ static int SDL_ConvertPixels_XBGR2101010_to_P010(int width, int height, const vo
}
int SDL_ConvertPixels_RGB_to_YUV(int width, int height,
- SDL_PixelFormatEnum src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch,
- SDL_PixelFormatEnum dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch)
+ SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch,
+ SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch)
{
YCbCrType yuv_type = YCBCR_601_LIMITED;
@@ -1210,7 +1210,7 @@ int SDL_ConvertPixels_RGB_to_YUV(int width, int height,
}
}
-static int SDL_ConvertPixels_YUV_to_YUV_Copy(int width, int height, SDL_PixelFormatEnum format,
+static int SDL_ConvertPixels_YUV_to_YUV_Copy(int width, int height, SDL_PixelFormat format,
const void *src, int src_pitch, void *dst, int dst_pitch)
{
int i;
@@ -1677,8 +1677,8 @@ static int SDL_ConvertPixels_SwapNV(int width, int height, const void *src, int
}
static int SDL_ConvertPixels_Planar2x2_to_Planar2x2(int width, int height,
- SDL_PixelFormatEnum src_format, const void *src, int src_pitch,
- SDL_PixelFormatEnum dst_format, void *dst, int dst_pitch)
+ SDL_PixelFormat src_format, const void *src, int src_pitch,
+ SDL_PixelFormat dst_format, void *dst, int dst_pitch)
{
if (src != dst) {
/* Copy Y plane */
@@ -2235,8 +2235,8 @@ static int SDL_ConvertPixels_YVYU_to_UYVY(int width, int height, const void *src
}
static int SDL_ConvertPixels_Packed4_to_Packed4(int width, int height,
- SDL_PixelFormatEnum src_format, const void *src, int src_pitch,
- SDL_PixelFormatEnum dst_format, void *dst, int dst_pitch)
+ SDL_PixelFormat src_format, const void *src, int src_pitch,
+ SDL_PixelFormat dst_format, void *dst, int dst_pitch)
{
switch (src_format) {
case SDL_PIXELFORMAT_YUY2:
@@ -2277,8 +2277,8 @@ static int SDL_ConvertPixels_Packed4_to_Packed4(int width, int height,
}
static int SDL_ConvertPixels_Planar2x2_to_Packed4(int width, int height,
- SDL_PixelFormatEnum src_format, const void *src, int src_pitch,
- SDL_PixelFormatEnum dst_format, void *dst, int dst_pitch)
+ SDL_PixelFormat src_format, const void *src, int src_pitch,
+ SDL_PixelFormat dst_format, void *dst, int dst_pitch)
{
int x, y;
const Uint8 *srcY1, *srcY2, *srcU, *srcV;
@@ -2419,8 +2419,8 @@ static int SDL_ConvertPixels_Planar2x2_to_Packed4(int width, int height,
}
static int SDL_ConvertPixels_Packed4_to_Planar2x2(int width, int height,
- SDL_PixelFormatEnum src_format, const void *src, int src_pitch,
- SDL_PixelFormatEnum dst_format, void *dst, int dst_pitch)
+ SDL_PixelFormat src_format, const void *src, int src_pitch,
+ SDL_PixelFormat dst_format, void *dst, int dst_pitch)
{
int x, y;
const Uint8 *srcY1, *srcY2, *srcU1, *srcU2, *srcV1, *srcV2;
@@ -2552,8 +2552,8 @@ static int SDL_ConvertPixels_Packed4_to_Planar2x2(int width, int height,
#endif /* SDL_HAVE_YUV */
int SDL_ConvertPixels_YUV_to_YUV(int width, int height,
- SDL_PixelFormatEnum src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch,
- SDL_PixelFormatEnum dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch)
+ SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch,
+ SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch)
{
#if SDL_HAVE_YUV
if (src_colorspace != dst_colorspace) {
diff --git a/src/video/SDL_yuv_c.h b/src/video/SDL_yuv_c.h
index 1bdf7278b39e46..47dac3b2566c00 100644
--- a/src/video/SDL_yuv_c.h
+++ b/src/video/SDL_yuv_c.h
@@ -26,11 +26,11 @@
/* YUV conversion functions */
-extern int SDL_ConvertPixels_YUV_to_RGB(int width, int height, SDL_PixelFormatEnum src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormatEnum dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch);
-extern int SDL_ConvertPixels_RGB_to_YUV(int width, int height, SDL_PixelFormatEnum src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormatEnum dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch);
-extern int SDL_ConvertPixels_YUV_to_YUV(int width, int height, SDL_PixelFormatEnum src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormatEnum dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch);
+extern int SDL_ConvertPixels_YUV_to_RGB(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch);
+extern int SDL_ConvertPixels_RGB_to_YUV(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch);
+extern int SDL_ConvertPixels_YUV_to_YUV(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch);
-extern int SDL_CalculateYUVSize(SDL_PixelFormatEnum format, int w, int h, size_t *size, size_t *pitch);
+extern int SDL_CalculateYUVSize(SDL_PixelFormat format, int w, int h, size_t *size, size_t *pitch);
#endif /* SDL_yuv_c_h_ */
diff --git a/src/video/android/SDL_androidmouse.c b/src/video/android/SDL_androidmouse.c
index 2cc50e279a3d72..afee511d403748 100644
--- a/src/video/android/SDL_androidmouse.c
+++ b/src/video/android/SDL_androidmouse.c
@@ -84,7 +84,7 @@ static SDL_Cursor *Android_CreateCursor(SDL_Surface *surface, int hot_x, int hot
int custom_cursor;
SDL_Surface *converted;
- converted = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ARGB8888);
+ converted = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_ARGB8888);
if (!converted) {
return NULL;
}
diff --git a/src/video/cocoa/SDL_cocoavideo.m b/src/video/cocoa/SDL_cocoavideo.m
index c9cb9043d25c9d..9012633074ea59 100644
--- a/src/video/cocoa/SDL_cocoavideo.m
+++ b/src/video/cocoa/SDL_cocoavideo.m
@@ -256,7 +256,7 @@ SDL_SystemTheme Cocoa_GetSystemTheme(void)
int i;
NSImage *img;
- converted = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_RGBA32);
+ converted = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_RGBA32);
if (!converted) {
return nil;
}
diff --git a/src/video/dummy/SDL_nullframebuffer.c b/src/video/dummy/SDL_nullframebuffer.c
index 79b29991acf785..862c36c7e3d831 100644
--- a/src/video/dummy/SDL_nullframebuffer.c
+++ b/src/video/dummy/SDL_nullframebuffer.c
@@ -29,10 +29,10 @@
#define DUMMY_SURFACE "SDL.internal.window.surface"
-int SDL_DUMMY_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormatEnum *format, void **pixels, int *pitch)
+int SDL_DUMMY_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch)
{
SDL_Surface *surface;
- const SDL_PixelFormatEnum surface_format = SDL_PIXELFORMAT_XRGB8888;
+ const SDL_PixelFormat surface_format = SDL_PIXELFORMAT_XRGB8888;
int w, h;
/* Create a new framebuffer */
diff --git a/src/video/dummy/SDL_nullframebuffer_c.h b/src/video/dummy/SDL_nullframebuffer_c.h
index 78e4ebfa0ade96..01644418f43592 100644
--- a/src/video/dummy/SDL_nullframebuffer_c.h
+++ b/src/video/dummy/SDL_nullframebuffer_c.h
@@ -24,7 +24,7 @@
#include "SDL_internal.h"
-extern int SDL_DUMMY_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormatEnum *format, void **pixels, int *pitch);
+extern int SDL_DUMMY_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch);
extern int SDL_DUMMY_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects);
extern void SDL_DUMMY_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window);
diff --git a/src/video/emscripten/SDL_emscriptenframebuffer.c b/src/video/emscripten/SDL_emscriptenframebuffer.c
index 377d6d536d46b3..a7cae059def3fc 100644
--- a/src/video/emscripten/SDL_emscriptenframebuffer.c
+++ b/src/video/emscripten/SDL_emscriptenframebuffer.c
@@ -27,10 +27,10 @@
#include
-int Emscripten_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormatEnum *format, void **pixels, int *pitch)
+int Emscripten_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch)
{
SDL_Surface *surface;
- const SDL_PixelFormatEnum surface_format = SDL_PIXELFORMAT_XBGR8888;
+ const SDL_PixelFormat surface_format = SDL_PIXELFORMAT_XBGR8888;
int w, h;
/* Free the old framebuffer surface */
diff --git a/src/video/emscripten/SDL_emscriptenframebuffer.h b/src/video/emscripten/SDL_emscriptenframebuffer.h
index 94c84b55cb78fc..2e0df3d0d1e071 100644
--- a/src/video/emscripten/SDL_emscriptenframebuffer.h
+++ b/src/video/emscripten/SDL_emscriptenframebuffer.h
@@ -23,7 +23,7 @@
#ifndef SDL_emscriptenframebuffer_h_
#define SDL_emscriptenframebuffer_h_
-extern int Emscripten_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormatEnum *format, void **pixels, int *pitch);
+extern int Emscripten_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch);
extern int Emscripten_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects);
extern void Emscripten_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window);
diff --git a/src/video/emscripten/SDL_emscriptenmouse.c b/src/video/emscripten/SDL_emscriptenmouse.c
index 0593fc63684523..17a5952800cde7 100644
--- a/src/video/emscripten/SDL_emscriptenmouse.c
+++ b/src/video/emscripten/SDL_emscriptenmouse.c
@@ -72,7 +72,7 @@ static SDL_Cursor *Emscripten_CreateCursor(SDL_Surface *surface, int hot_x, int
const char *cursor_url = NULL;
SDL_Surface *conv_surf;
- conv_surf = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ABGR8888);
+ conv_surf = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_ABGR8888);
if (!conv_surf) {
return NULL;
diff --git a/src/video/haiku/SDL_bframebuffer.cc b/src/video/haiku/SDL_bframebuffer.cc
index ac90d5ab5f853d..70bfff7dc1b7bb 100644
--- a/src/video/haiku/SDL_bframebuffer.cc
+++ b/src/video/haiku/SDL_bframebuffer.cc
@@ -44,7 +44,7 @@ static SDL_INLINE SDL_BLooper *_GetBeLooper() {
}
int HAIKU_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window,
- SDL_PixelFormatEnum * format,
+ SDL_PixelFormat * format,
void ** pixels, int *pitch) {
SDL_BWin *bwin = _ToBeWin(window);
BScreen bscreen;
diff --git a/src/video/haiku/SDL_bframebuffer.h b/src/video/haiku/SDL_bframebuffer.h
index 65ce6ce872a101..fcb6bcd811b15c 100644
--- a/src/video/haiku/SDL_bframebuffer.h
+++ b/src/video/haiku/SDL_bframebuffer.h
@@ -31,7 +31,7 @@ extern "C" {
#include "../SDL_sysvideo.h"
extern int HAIKU_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window,
- SDL_PixelFormatEnum *format,
+ SDL_PixelFormat *format,
void **pixels, int *pitch);
extern int HAIKU_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window,
const SDL_Rect *rects, int numrects);
diff --git a/src/video/haiku/SDL_bmodes.cc b/src/video/haiku/SDL_bmodes.cc
index 09e1e84dd015b8..c44729e4d00837 100644
--- a/src/video/haiku/SDL_bmodes.cc
+++ b/src/video/haiku/SDL_bmodes.cc
@@ -132,7 +132,7 @@ void _SpoutModeData(display_mode *bmode) {
-SDL_PixelFormatEnum HAIKU_ColorSpaceToSDLPxFormat(uint32 colorspace)
+SDL_PixelFormat HAIKU_ColorSpaceToSDLPxFormat(uint32 colorspace)
{
switch (colorspace) {
case B_CMAP8:
diff --git a/src/video/haiku/SDL_bmodes.h b/src/video/haiku/SDL_bmodes.h
index d8b4b493a9ce23..bb57a06a24e7d8 100644
--- a/src/video/haiku/SDL_bmodes.h
+++ b/src/video/haiku/SDL_bmodes.h
@@ -28,7 +28,7 @@ extern "C" {
#include "../SDL_sysvideo.h"
-extern SDL_PixelFormatEnum HAIKU_ColorSpaceToSDLPxFormat(uint32 colorspace);
+extern SDL_PixelFormat HAIKU_ColorSpaceToSDLPxFormat(uint32 colorspace);
extern int HAIKU_InitModes(SDL_VideoDevice *_this);
extern int HAIKU_QuitModes(SDL_VideoDevice *_this);
diff --git a/src/video/haiku/SDL_bvideo.cc b/src/video/haiku/SDL_bvideo.cc
index f4ed4c8ba9207f..cbbd554bea1ae2 100644
--- a/src/video/haiku/SDL_bvideo.cc
+++ b/src/video/haiku/SDL_bvideo.cc
@@ -179,7 +179,7 @@ static SDL_Cursor * HAIKU_CreateCursor(SDL_Surface * surface, int hot_x, int hot
SDL_Cursor *cursor;
SDL_Surface *converted;
- converted = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ARGB8888);
+ converted = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_ARGB8888);
if (!converted) {
return NULL;
}
diff --git a/src/video/n3ds/SDL_n3dsframebuffer.c b/src/video/n3ds/SDL_n3dsframebuffer.c
index 02408e9de582b7..4ad3781c2c790a 100644
--- a/src/video/n3ds/SDL_n3dsframebuffer.c
+++ b/src/video/n3ds/SDL_n3dsframebuffer.c
@@ -42,7 +42,7 @@ static int GetSourceOffset(int x, int y, int source_width);
static void FlushN3DSBuffer(const void *buffer, u32 bufsize, gfxScreen_t screen);
-int SDL_N3DS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormatEnum *format, void **pixels, int *pitch)
+int SDL_N3DS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch)
{
SDL_Surface *framebuffer;
const SDL_DisplayMode *mode;
diff --git a/src/video/n3ds/SDL_n3dsframebuffer_c.h b/src/video/n3ds/SDL_n3dsframebuffer_c.h
index f316f92c1d4d0d..c471b2d9d6178f 100644
--- a/src/video/n3ds/SDL_n3dsframebuffer_c.h
+++ b/src/video/n3ds/SDL_n3dsframebuffer_c.h
@@ -24,7 +24,7 @@
#include "SDL_internal.h"
-int SDL_N3DS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormatEnum *format, void **pixels, int *pitch);
+int SDL_N3DS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch);
int SDL_N3DS_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects);
void SDL_N3DS_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window);
diff --git a/src/video/n3ds/SDL_n3dsvideo.c b/src/video/n3ds/SDL_n3dsvideo.c
index 69ff218638984e..b9e34eb3889b5d 100644
--- a/src/video/n3ds/SDL_n3dsvideo.c
+++ b/src/video/n3ds/SDL_n3dsvideo.c
@@ -53,7 +53,7 @@ struct SDL_DisplayModeData
static const struct
{
- SDL_PixelFormatEnum pixfmt;
+ SDL_PixelFormat pixfmt;
GSPGPU_FramebufferFormat gspfmt;
} format_map[] = {
{ SDL_PIXELFORMAT_RGBA8888, GSP_RGBA8_OES },
diff --git a/src/video/ngage/SDL_ngageframebuffer.cpp b/src/video/ngage/SDL_ngageframebuffer.cpp
index 143ad50d2a5bf5..df42a831763f5b 100644
--- a/src/video/ngage/SDL_ngageframebuffer.cpp
+++ b/src/video/ngage/SDL_ngageframebuffer.cpp
@@ -44,11 +44,11 @@ void DrawBackground(SDL_VideoDevice *_this);
void DirectDraw(SDL_VideoDevice *_this, int numrects, SDL_Rect *rects, TUint16 *screenBuffer);
void RedrawWindowL(SDL_VideoDevice *_this);
-int SDL_NGAGE_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormatEnum *format, void **pixels, int *pitch)
+int SDL_NGAGE_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch)
{
SDL_VideoData *phdata = _this->driverdata;
SDL_Surface *surface;
- const SDL_PixelFormatEnum surface_format = SDL_PIXELFORMAT_XRGB4444;
+ const SDL_PixelFormat surface_format = SDL_PIXELFORMAT_XRGB4444;
int w, h;
/* Free the old framebuffer surface */
diff --git a/src/video/ngage/SDL_ngageframebuffer_c.h b/src/video/ngage/SDL_ngageframebuffer_c.h
index e7fed1327144a8..6358ff9bf3f272 100644
--- a/src/video/ngage/SDL_ngageframebuffer_c.h
+++ b/src/video/ngage/SDL_ngageframebuffer_c.h
@@ -21,7 +21,7 @@
#include "SDL_internal.h"
-extern int SDL_NGAGE_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormatEnum *format, void **pixels, int *pitch);
+extern int SDL_NGAGE_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch);
extern int SDL_NGAGE_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects);
extern void SDL_NGAGE_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window);
diff --git a/src/video/offscreen/SDL_offscreenframebuffer.c b/src/video/offscreen/SDL_offscreenframebuffer.c
index 5c17c5c7399b21..89d7e83d7478a6 100644
--- a/src/video/offscreen/SDL_offscreenframebuffer.c
+++ b/src/video/offscreen/SDL_offscreenframebuffer.c
@@ -29,10 +29,10 @@
#define OFFSCREEN_SURFACE "SDL.internal.window.surface"
-int SDL_OFFSCREEN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormatEnum *format, void **pixels, int *pitch)
+int SDL_OFFSCREEN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch)
{
SDL_Surface *surface;
- const SDL_PixelFormatEnum surface_format = SDL_PIXELFORMAT_XRGB8888;
+ const SDL_PixelFormat surface_format = SDL_PIXELFORMAT_XRGB8888;
int w, h;
/* Create a new framebuffer */
diff --git a/src/video/offscreen/SDL_offscreenframebuffer_c.h b/src/video/offscreen/SDL_offscreenframebuffer_c.h
index bccd3649eb7b35..a45f9afe467e00 100644
--- a/src/video/offscreen/SDL_offscreenframebuffer_c.h
+++ b/src/video/offscreen/SDL_offscreenframebuffer_c.h
@@ -20,6 +20,6 @@
*/
#include "SDL_internal.h"
-extern int SDL_OFFSCREEN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormatEnum *format, void **pixels, int *pitch);
+extern int SDL_OFFSCREEN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch);
extern int SDL_OFFSCREEN_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects);
extern void SDL_OFFSCREEN_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window);
diff --git a/src/video/qnx/SDL_qnxvideo.c b/src/video/qnx/SDL_qnxvideo.c
index 6a646832b5362c..5d6c5efd20a1da 100644
--- a/src/video/qnx/SDL_qnxvideo.c
+++ b/src/video/qnx/SDL_qnxvideo.c
@@ -152,7 +152,7 @@ static int createWindow(SDL_VideoDevice *_this, SDL_Window *window)
* @param[out] pitch Holds the number of bytes per line
* @return 0 if successful, -1 on error
*/
-static int createWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window, SDL_PixelFormatEnum * format,
+static int createWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window, SDL_PixelFormat * format,
void ** pixels, int *pitch)
{
window_impl_t *impl = (window_impl_t *)window->driverdata;
diff --git a/src/video/riscos/SDL_riscosframebuffer.c b/src/video/riscos/SDL_riscosframebuffer.c
index 0bc0ea9095ffc1..bef7443bc211e0 100644
--- a/src/video/riscos/SDL_riscosframebuffer.c
+++ b/src/video/riscos/SDL_riscosframebuffer.c
@@ -30,7 +30,7 @@
#include
#include
-int RISCOS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormatEnum *format, void **pixels, int *pitch)
+int RISCOS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch)
{
SDL_WindowData *driverdata = window->driverdata;
const char *sprite_name = "display";
diff --git a/src/video/riscos/SDL_riscosframebuffer_c.h b/src/video/riscos/SDL_riscosframebuffer_c.h
index b556a72be8e15f..20b9dad59520ed 100644
--- a/src/video/riscos/SDL_riscosframebuffer_c.h
+++ b/src/video/riscos/SDL_riscosframebuffer_c.h
@@ -24,7 +24,7 @@
#include "SDL_internal.h"
-extern int RISCOS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormatEnum *format, void **pixels, int *pitch);
+extern int RISCOS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch);
extern int RISCOS_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects);
extern void RISCOS_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window);
diff --git a/src/video/riscos/SDL_riscosmodes.c b/src/video/riscos/SDL_riscosmodes.c
index 8640163f94a1c4..066dfebe067bda 100644
--- a/src/video/riscos/SDL_riscosmodes.c
+++ b/src/video/riscos/SDL_riscosmodes.c
@@ -45,7 +45,7 @@ enum
static const struct
{
- SDL_PixelFormatEnum pixel_format;
+ SDL_PixelFormat pixel_format;
int modeflags, ncolour, log2bpp;
} mode_to_pixelformat[] = {
/* { SDL_PIXELFORMAT_INDEX1LSB, 0, 1, 0 }, */
@@ -70,7 +70,7 @@ static const struct
{ SDL_PIXELFORMAT_ARGB8888, MODE_FLAG_ARGB, -1, 5 }
};
-static SDL_PixelFormatEnum RISCOS_ModeToPixelFormat(int ncolour, int modeflags, int log2bpp)
+static SDL_PixelFormat RISCOS_ModeToPixelFormat(int ncolour, int modeflags, int log2bpp)
{
int i;
diff --git a/src/video/vita/SDL_vitaframebuffer.c b/src/video/vita/SDL_vitaframebuffer.c
index 5a696d0023fe5e..872ede91d2624c 100644
--- a/src/video/vita/SDL_vitaframebuffer.c
+++ b/src/video/vita/SDL_vitaframebuffer.c
@@ -63,7 +63,7 @@ void vita_gpu_free(SceUID uid)
sceKernelFreeMemBlock(uid);
}
-int VITA_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormatEnum *format, void **pixels, int *pitch)
+int VITA_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch)
{
SDL_WindowData *data = window->driverdata;
SceDisplayFrameBuf framebuf;
diff --git a/src/video/vita/SDL_vitaframebuffer.h b/src/video/vita/SDL_vitaframebuffer.h
index 9ccdec76964b07..29c10970f01527 100644
--- a/src/video/vita/SDL_vitaframebuffer.h
+++ b/src/video/vita/SDL_vitaframebuffer.h
@@ -20,6 +20,6 @@
*/
#include "SDL_internal.h"
-extern int VITA_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormatEnum *format, void **pixels, int *pitch);
+extern int VITA_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch);
extern int VITA_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects);
extern void VITA_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window);
diff --git a/src/video/windows/SDL_windowsframebuffer.c b/src/video/windows/SDL_windowsframebuffer.c
index e1ef467eaf232e..eb0b06e0f56a24 100644
--- a/src/video/windows/SDL_windowsframebuffer.c
+++ b/src/video/windows/SDL_windowsframebuffer.c
@@ -24,7 +24,7 @@
#include "SDL_windowsvideo.h"
-int WIN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormatEnum *format, void **pixels, int *pitch)
+int WIN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch)
{
SDL_WindowData *data = window->driverdata;
SDL_bool isstack;
@@ -66,7 +66,7 @@ int WIN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_
bpp = info->bmiHeader.biPlanes * info->bmiHeader.biBitCount;
masks = (Uint32 *)((Uint8 *)info + info->bmiHeader.biSize);
- *format = SDL_GetPixelFormatEnumForMasks(bpp, masks[0], masks[1], masks[2], 0);
+ *format = SDL_GetPixelFormatForMasks(bpp, masks[0], masks[1], masks[2], 0);
}
if (*format == SDL_PIXELFORMAT_UNKNOWN) {
/* We'll use RGB format for now */
diff --git a/src/video/windows/SDL_windowsframebuffer.h b/src/video/windows/SDL_windowsframebuffer.h
index 092ac8f497f891..e4ab869c6919f9 100644
--- a/src/video/windows/SDL_windowsframebuffer.h
+++ b/src/video/windows/SDL_windowsframebuffer.h
@@ -20,6 +20,6 @@
*/
#include "SDL_internal.h"
-extern int WIN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormatEnum *format, void **pixels, int *pitch);
+extern int WIN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch);
extern int WIN_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects);
extern void WIN_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window);
diff --git a/src/video/windows/SDL_windowsmouse.c b/src/video/windows/SDL_windowsmouse.c
index 42a5e9923618af..1f46ffb29e482b 100644
--- a/src/video/windows/SDL_windowsmouse.c
+++ b/src/video/windows/SDL_windowsmouse.c
@@ -49,7 +49,7 @@ static SDL_bool IsMonochromeSurface(SDL_Surface *surface)
int x, y;
Uint8 r, g, b, a;
- SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
+ SDL_assert(surface->format == SDL_PIXELFORMAT_ARGB8888);
for (y = 0; y < surface->h; y++) {
for (x = 0; x < surface->w; x++) {
@@ -76,7 +76,7 @@ static HBITMAP CreateColorBitmap(SDL_Surface *surface)
BITMAPINFO bi;
void *pixels;
- SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
+ SDL_assert(surface->format == SDL_PIXELFORMAT_ARGB8888);
SDL_zero(bi);
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
@@ -114,7 +114,7 @@ static HBITMAP CreateMaskBitmap(SDL_Surface *surface, SDL_bool is_monochrome)
const int size = pitch * surface->h;
static const unsigned char masks[] = { 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1 };
- SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
+ SDL_assert(surface->format == SDL_PIXELFORMAT_ARGB8888);
pixels = SDL_small_alloc(Uint8, size * (is_monochrome ? 2 : 1), &isstack);
if (!pixels) {
diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c
index 014a9207ca92bc..80901b70cc23af 100644
--- a/src/video/windows/SDL_windowswindow.c
+++ b/src/video/windows/SDL_windowswindow.c
@@ -851,7 +851,7 @@ int WIN_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *i
bmi->biClrImportant = SDL_Swap32LE(0);
/* Write the pixels upside down into the bitmap buffer */
- SDL_assert(icon->format->format == SDL_PIXELFORMAT_ARGB8888);
+ SDL_assert(icon->format == SDL_PIXELFORMAT_ARGB8888);
dst = &icon_bmp[sizeof(BITMAPINFOHEADER)];
row_len = icon->w * sizeof(Uint32);
y = icon->h;
diff --git a/src/video/winrt/SDL_winrtvideo.cpp b/src/video/winrt/SDL_winrtvideo.cpp
index a2d57318451784..67197787329943 100644
--- a/src/video/winrt/SDL_winrtvideo.cpp
+++ b/src/video/winrt/SDL_winrtvideo.cpp
@@ -246,7 +246,7 @@ int WINRT_VideoInit(SDL_VideoDevice *_this)
return 0;
}
-extern "C" SDL_PixelFormatEnum D3D11_DXGIFormatToSDLPixelFormat(DXGI_FORMAT dxgiFormat);
+extern "C" SDL_PixelFormat D3D11_DXGIFormatToSDLPixelFormat(DXGI_FORMAT dxgiFormat);
static void WINRT_DXGIModeToSDLDisplayMode(const DXGI_MODE_DESC *dxgiMode, SDL_DisplayMode *sdlMode)
{
diff --git a/src/video/x11/SDL_x11framebuffer.c b/src/video/x11/SDL_x11framebuffer.c
index 58dd86a388a6ca..14b870efae7715 100644
--- a/src/video/x11/SDL_x11framebuffer.c
+++ b/src/video/x11/SDL_x11framebuffer.c
@@ -47,7 +47,7 @@ static SDL_bool have_mitshm(Display *dpy)
#endif /* !NO_SHARED_MEMORY */
-int X11_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormatEnum *format,
+int X11_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format,
void **pixels, int *pitch)
{
SDL_WindowData *data = window->driverdata;
diff --git a/src/video/x11/SDL_x11framebuffer.h b/src/video/x11/SDL_x11framebuffer.h
index b749495a8bbe37..a96fb223c32bb5 100644
--- a/src/video/x11/SDL_x11framebuffer.h
+++ b/src/video/x11/SDL_x11framebuffer.h
@@ -25,7 +25,7 @@
#include "SDL_internal.h"
extern int X11_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window,
- SDL_PixelFormatEnum *format,
+ SDL_PixelFormat *format,
void **pixels, int *pitch);
extern int X11_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window,
const SDL_Rect *rects, int numrects);
diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c
index aabcd34f6cc740..850ba2b0acbfcd 100644
--- a/src/video/x11/SDL_x11modes.c
+++ b/src/video/x11/SDL_x11modes.c
@@ -308,7 +308,7 @@ int X11_GetVisualInfoFromVisual(Display *display, Visual *visual, XVisualInfo *v
return -1;
}
-SDL_PixelFormatEnum X11_GetPixelFormatFromVisualInfo(Display *display, XVisualInfo *vinfo)
+SDL_PixelFormat X11_GetPixelFormatFromVisualInfo(Display *display, XVisualInfo *vinfo)
{
if (vinfo->class == DirectColor || vinfo->class == TrueColor) {
int bpp;
@@ -338,7 +338,7 @@ SDL_PixelFormatEnum X11_GetPixelFormatFromVisualInfo(Display *display, XVisualIn
}
}
- return SDL_GetPixelFormatEnumForMasks(bpp, Rmask, Gmask, Bmask, Amask);
+ return SDL_GetPixelFormatForMasks(bpp, Rmask, Gmask, Bmask, Amask);
}
if (vinfo->class == PseudoColor || vinfo->class == StaticColor) {
diff --git a/src/video/x11/SDL_x11modes.h b/src/video/x11/SDL_x11modes.h
index 53e49e8bc059f8..113db3957c3e64 100644
--- a/src/video/x11/SDL_x11modes.h
+++ b/src/video/x11/SDL_x11modes.h
@@ -57,7 +57,7 @@ extern void X11_QuitModes(SDL_VideoDevice *_this);
/* Some utility functions for working with visuals */
extern int X11_GetVisualInfoFromVisual(Display *display, Visual *visual, XVisualInfo *vinfo);
-extern SDL_PixelFormatEnum X11_GetPixelFormatFromVisualInfo(Display *display, XVisualInfo *vinfo);
+extern SDL_PixelFormat X11_GetPixelFormatFromVisualInfo(Display *display, XVisualInfo *vinfo);
extern int X11_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *sdl_display, SDL_Rect *rect);
extern int X11_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *sdl_display, SDL_Rect *rect);
diff --git a/test/testautomation_blit.c b/test/testautomation_blit.c
index d2e7e23d84841f..2eec3b19c4c6ab 100644
--- a/test/testautomation_blit.c
+++ b/test/testautomation_blit.c
@@ -58,14 +58,14 @@ Uint32 *getNextRandomBuffer(const int width, const int height) {
/*
* Generates a small 15 x 15px surface of PRNG pixel data
*/
-SDL_Surface* getRandomBlitChunk(Uint32 *pixels, SDL_PixelFormatEnum format) {
- return SDL_CreateSurfaceFrom(pixels, 15, 15, 15 * 4, format);
+SDL_Surface* getRandomBlitChunk(Uint32 *pixels, SDL_PixelFormat format) {
+ return SDL_CreateSurfaceFrom(15, 15, format, pixels, 15 * 4);
}
/*
* Generates a 800 x 600 surface of PRNG pixel data
*/
-SDL_Surface* getRandomSVGASurface(Uint32 *pixels, SDL_PixelFormatEnum format) {
- return SDL_CreateSurfaceFrom(pixels, 800, 600, 800 * 4, format);
+SDL_Surface* getRandomSVGASurface(Uint32 *pixels, SDL_PixelFormat format) {
+ return SDL_CreateSurfaceFrom(800, 600, format, pixels, 800 * 4);
}
/*
* Calculates the FNV-1a hash of input pixel data
@@ -205,4 +205,4 @@ SDLTest_TestSuiteReference blitTestSuite = {
blitSetUp,
blitTests,
NULL
-};
\ No newline at end of file
+};
diff --git a/test/testautomation_images.c b/test/testautomation_images.c
index 9c19ce021449b8..0ff7d21edd58d1 100644
--- a/test/testautomation_images.c
+++ b/test/testautomation_images.c
@@ -533,10 +533,11 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlit = {
SDL_Surface *SDLTest_ImageBlit(void)
{
SDL_Surface *surface = SDL_CreateSurfaceFrom(
- (void *)SDLTest_imageBlit.pixel_data,
SDLTest_imageBlit.width,
SDLTest_imageBlit.height,
- SDLTest_imageBlit.width * SDLTest_imageBlit.bytes_per_pixel, SDL_PIXELFORMAT_RGB24);
+ SDL_PIXELFORMAT_RGB24,
+ (void *)SDLTest_imageBlit.pixel_data,
+ SDLTest_imageBlit.width * SDLTest_imageBlit.bytes_per_pixel);
return surface;
}
@@ -1005,10 +1006,11 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitColor = {
SDL_Surface *SDLTest_ImageBlitColor(void)
{
SDL_Surface *surface = SDL_CreateSurfaceFrom(
- (void *)SDLTest_imageBlitColor.pixel_data,
SDLTest_imageBlitColor.width,
SDLTest_imageBlitColor.height,
- SDLTest_imageBlitColor.width * SDLTest_imageBlitColor.bytes_per_pixel, SDL_PIXELFORMAT_RGB24);
+ SDL_PIXELFORMAT_RGB24,
+ (void *)SDLTest_imageBlitColor.pixel_data,
+ SDLTest_imageBlitColor.width * SDLTest_imageBlitColor.bytes_per_pixel);
return surface;
}
@@ -1640,10 +1642,11 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitAlpha = {
SDL_Surface *SDLTest_ImageBlitAlpha(void)
{
SDL_Surface *surface = SDL_CreateSurfaceFrom(
- (void *)SDLTest_imageBlitAlpha.pixel_data,
SDLTest_imageBlitAlpha.width,
SDLTest_imageBlitAlpha.height,
- SDLTest_imageBlitAlpha.width * SDLTest_imageBlitAlpha.bytes_per_pixel, SDL_PIXELFORMAT_RGB24);
+ SDL_PIXELFORMAT_RGB24,
+ (void *)SDLTest_imageBlitAlpha.pixel_data,
+ SDLTest_imageBlitAlpha.width * SDLTest_imageBlitAlpha.bytes_per_pixel);
return surface;
}
@@ -2208,10 +2211,11 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendAdd = {
SDL_Surface *SDLTest_ImageBlitBlendAdd(void)
{
SDL_Surface *surface = SDL_CreateSurfaceFrom(
- (void *)SDLTest_imageBlitBlendAdd.pixel_data,
SDLTest_imageBlitBlendAdd.width,
SDLTest_imageBlitBlendAdd.height,
- SDLTest_imageBlitBlendAdd.width * SDLTest_imageBlitBlendAdd.bytes_per_pixel, SDL_PIXELFORMAT_RGB24);
+ SDL_PIXELFORMAT_RGB24,
+ (void *)SDLTest_imageBlitBlendAdd.pixel_data,
+ SDLTest_imageBlitBlendAdd.width * SDLTest_imageBlitBlendAdd.bytes_per_pixel);
return surface;
}
@@ -2797,10 +2801,11 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlend = {
SDL_Surface *SDLTest_ImageBlitBlend(void)
{
SDL_Surface *surface = SDL_CreateSurfaceFrom(
- (void *)SDLTest_imageBlitBlend.pixel_data,
SDLTest_imageBlitBlend.width,
SDLTest_imageBlitBlend.height,
- SDLTest_imageBlitBlend.width * SDLTest_imageBlitBlend.bytes_per_pixel, SDL_PIXELFORMAT_RGB24);
+ SDL_PIXELFORMAT_RGB24,
+ (void *)SDLTest_imageBlitBlend.pixel_data,
+ SDLTest_imageBlitBlend.width * SDLTest_imageBlitBlend.bytes_per_pixel);
return surface;
}
@@ -3216,10 +3221,11 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendMod = {
SDL_Surface *SDLTest_ImageBlitBlendMod(void)
{
SDL_Surface *surface = SDL_CreateSurfaceFrom(
- (void *)SDLTest_imageBlitBlendMod.pixel_data,
SDLTest_imageBlitBlendMod.width,
SDLTest_imageBlitBlendMod.height,
- SDLTest_imageBlitBlendMod.width * SDLTest_imageBlitBlendMod.bytes_per_pixel, SDL_PIXELFORMAT_RGB24);
+ SDL_PIXELFORMAT_RGB24,
+ (void *)SDLTest_imageBlitBlendMod.pixel_data,
+ SDLTest_imageBlitBlendMod.width * SDLTest_imageBlitBlendMod.bytes_per_pixel);
return surface;
}
@@ -4018,10 +4024,11 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendNone = {
SDL_Surface *SDLTest_ImageBlitBlendNone(void)
{
SDL_Surface *surface = SDL_CreateSurfaceFrom(
- (void *)SDLTest_imageBlitBlendNone.pixel_data,
SDLTest_imageBlitBlendNone.width,
SDLTest_imageBlitBlendNone.height,
- SDLTest_imageBlitBlendNone.width * SDLTest_imageBlitBlendNone.bytes_per_pixel, SDL_PIXELFORMAT_RGB24);
+ SDL_PIXELFORMAT_RGB24,
+ (void *)SDLTest_imageBlitBlendNone.pixel_data,
+ SDLTest_imageBlitBlendNone.width * SDLTest_imageBlitBlendNone.bytes_per_pixel);
return surface;
}
@@ -4552,10 +4559,11 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendAll = {
SDL_Surface *SDLTest_ImageBlitBlendAll(void)
{
SDL_Surface *surface = SDL_CreateSurfaceFrom(
- (void *)SDLTest_imageBlitBlendAll.pixel_data,
SDLTest_imageBlitBlendAll.width,
SDLTest_imageBlitBlendAll.height,
- SDLTest_imageBlitBlendAll.width * SDLTest_imageBlitBlendAll.bytes_per_pixel, SDL_PIXELFORMAT_RGB24);
+ SDL_PIXELFORMAT_RGB24,
+ (void *)SDLTest_imageBlitBlendAll.pixel_data,
+ SDLTest_imageBlitBlendAll.width * SDLTest_imageBlitBlendAll.bytes_per_pixel);
return surface;
}
@@ -4763,11 +4771,11 @@ static const SDLTest_SurfaceImage_t SDLTest_imageFace = {
SDL_Surface *SDLTest_ImageFace(void)
{
SDL_Surface *surface = SDL_CreateSurfaceFrom(
- (void *)SDLTest_imageFace.pixel_data,
SDLTest_imageFace.width,
SDLTest_imageFace.height,
- SDLTest_imageFace.width * SDLTest_imageFace.bytes_per_pixel,
- SDL_PIXELFORMAT_RGBA32);
+ SDL_PIXELFORMAT_RGBA32,
+ (void *)SDLTest_imageFace.pixel_data,
+ SDLTest_imageFace.width * SDLTest_imageFace.bytes_per_pixel);
return surface;
}
@@ -5256,10 +5264,11 @@ static const SDLTest_SurfaceImage_t SDLTest_imagePrimitives = {
SDL_Surface *SDLTest_ImagePrimitives(void)
{
SDL_Surface *surface = SDL_CreateSurfaceFrom(
- (void *)SDLTest_imagePrimitives.pixel_data,
SDLTest_imagePrimitives.width,
SDLTest_imagePrimitives.height,
- SDLTest_imagePrimitives.width * SDLTest_imagePrimitives.bytes_per_pixel, SDL_PIXELFORMAT_RGB24);
+ SDL_PIXELFORMAT_RGB24,
+ (void *)SDLTest_imagePrimitives.pixel_data,
+ SDLTest_imagePrimitives.width * SDLTest_imagePrimitives.bytes_per_pixel);
return surface;
}
@@ -5921,10 +5930,11 @@ static const SDLTest_SurfaceImage_t SDLTest_imagePrimitivesBlend = {
SDL_Surface *SDLTest_ImagePrimitivesBlend(void)
{
SDL_Surface *surface = SDL_CreateSurfaceFrom(
- (void *)SDLTest_imagePrimitivesBlend.pixel_data,
SDLTest_imagePrimitivesBlend.width,
SDLTest_imagePrimitivesBlend.height,
- SDLTest_imagePrimitivesBlend.width * SDLTest_imagePrimitivesBlend.bytes_per_pixel, SDL_PIXELFORMAT_RGB24);
+ SDL_PIXELFORMAT_RGB24,
+ (void *)SDLTest_imagePrimitivesBlend.pixel_data,
+ SDLTest_imagePrimitivesBlend.width * SDLTest_imagePrimitivesBlend.bytes_per_pixel);
return surface;
}
@@ -6094,11 +6104,11 @@ static const SDLTest_SurfaceImage_t SDLTest_imageRainbowBackground = {
SDL_Surface *SDLTest_ImageBlendingBackground(void)
{
SDL_Surface *surface = SDL_CreateSurfaceFrom(
- (void *)SDLTest_imageRainbowBackground.pixel_data,
SDLTest_imageRainbowBackground.width,
SDLTest_imageRainbowBackground.height,
- SDLTest_imageRainbowBackground.width * SDLTest_imageRainbowBackground.bytes_per_pixel,
- SDL_PIXELFORMAT_ARGB8888);
+ SDL_PIXELFORMAT_ARGB8888,
+ (void *)SDLTest_imageRainbowBackground.pixel_data,
+ SDLTest_imageRainbowBackground.width * SDLTest_imageRainbowBackground.bytes_per_pixel);
return surface;
}
@@ -6268,10 +6278,10 @@ static const SDLTest_SurfaceImage_t SDLTest_imageTransparentSprite = {
SDL_Surface *SDLTest_ImageBlendingSprite(void)
{
SDL_Surface *surface = SDL_CreateSurfaceFrom(
- (void *)SDLTest_imageTransparentSprite.pixel_data,
SDLTest_imageTransparentSprite.width,
SDLTest_imageTransparentSprite.height,
- SDLTest_imageTransparentSprite.width * SDLTest_imageTransparentSprite.bytes_per_pixel,
- SDL_PIXELFORMAT_ARGB8888);
+ SDL_PIXELFORMAT_ARGB8888,
+ (void *)SDLTest_imageTransparentSprite.pixel_data,
+ SDLTest_imageTransparentSprite.width * SDLTest_imageTransparentSprite.bytes_per_pixel);
return surface;
}
diff --git a/test/testautomation_pixels.c b/test/testautomation_pixels.c
index 6814b66fcc9757..6819451fc90e87 100644
--- a/test/testautomation_pixels.c
+++ b/test/testautomation_pixels.c
@@ -8,7 +8,7 @@
/* Test case functions */
/* Definition of all RGB formats used to test pixel conversions */
-static const SDL_PixelFormatEnum g_AllFormats[] = {
+static const SDL_PixelFormat g_AllFormats[] = {
SDL_PIXELFORMAT_INDEX1LSB,
SDL_PIXELFORMAT_INDEX1MSB,
SDL_PIXELFORMAT_INDEX2LSB,
@@ -115,28 +115,25 @@ static const char *g_invalidPixelFormatsVerbose[] = {
/* Test case functions */
/**
- * Call to SDL_CreatePixelFormat and SDL_DestroyPixelFormat
- *
- * \sa SDL_CreatePixelFormat
- * \sa SDL_DestroyPixelFormat
+ * Call to SDL_GetPixelFormatDetails
*/
-static int pixels_allocFreeFormat(void *arg)
+static int pixels_getPixelFormatDetails(void *arg)
{
const char *unknownFormat = "SDL_PIXELFORMAT_UNKNOWN";
const char *expectedError = "Unknown pixel format";
const char *error;
int i;
- SDL_PixelFormatEnum format;
+ SDL_PixelFormat format;
Uint32 masks;
- SDL_PixelFormat *result;
+ const SDL_PixelFormatDetails *result;
/* Blank/unknown format */
format = SDL_PIXELFORMAT_UNKNOWN;
SDLTest_Log("Pixel Format: %s (%d)", unknownFormat, format);
/* Allocate format */
- result = SDL_CreatePixelFormat(format);
- SDLTest_AssertPass("Call to SDL_CreatePixelFormat()");
+ result = SDL_GetPixelFormatDetails(format);
+ SDLTest_AssertPass("Call to SDL_GetPixelFormatDetails()");
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(result->format == format, "Verify value of result.format; expected: %d, got %d", format, result->format);
@@ -150,7 +147,6 @@ static int pixels_allocFreeFormat(void *arg)
SDLTest_AssertCheck(masks == 0, "Verify value of result.[RGBA]mask combined; expected: 0, got %" SDL_PRIu32, masks);
/* Deallocate again */
- SDL_DestroyPixelFormat(result);
SDLTest_AssertPass("Call to SDL_DestroyPixelFormat()");
}
@@ -160,8 +156,8 @@ static int pixels_allocFreeFormat(void *arg)
SDLTest_Log("Pixel Format: %s (%d)", g_AllFormatsVerbose[i], format);
/* Allocate format */
- result = SDL_CreatePixelFormat(format);
- SDLTest_AssertPass("Call to SDL_CreatePixelFormat()");
+ result = SDL_GetPixelFormatDetails(format);
+ SDLTest_AssertPass("Call to SDL_GetPixelFormatDetails()");
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(result->format == format, "Verify value of result.format; expected: %d, got %d", format, result->format);
@@ -175,12 +171,13 @@ static int pixels_allocFreeFormat(void *arg)
if (!SDL_ISPIXELFORMAT_INDEXED(format)) {
masks = result->Rmask | result->Gmask | result->Bmask | result->Amask;
SDLTest_AssertCheck(masks > 0, "Verify value of result.[RGBA]mask combined; expected: >0, got %" SDL_PRIu32, masks);
+ if (SDL_ISPIXELFORMAT_10BIT(format)) {
+ SDLTest_AssertCheck(result->Rbits == 10 && result->Gbits == 10 && result->Bbits == 10, "Verify value of result.[RGB]bits; expected: 10, got %d/%d/%d", result->Rbits, result->Gbits, result->Bbits);
+ } else if (SDL_BITSPERPIXEL(format) == 32) {
+ SDLTest_AssertCheck(result->Rbits == 8 && result->Gbits == 8 && result->Bbits == 8, "Verify value of result.[RGB]bits; expected: 8, got %d/%d/%d", result->Rbits, result->Gbits, result->Bbits);
+ }
}
}
-
- /* Deallocate again */
- SDL_DestroyPixelFormat(result);
- SDLTest_AssertPass("Call to SDL_DestroyPixelFormat()");
}
}
@@ -191,7 +188,7 @@ static int pixels_allocFreeFormat(void *arg)
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
format = g_invalidPixelFormats[i];
- result = SDL_CreatePixelFormat(format);
+ result = SDL_GetPixelFormatDetails(format);
SDLTest_AssertPass("Call to SDL_CreatePixelFormat(%d)", format);
SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
error = SDL_GetError();
@@ -203,15 +200,6 @@ static int pixels_allocFreeFormat(void *arg)
}
}
- /* Invalid free pointer */
- SDL_ClearError();
- SDLTest_AssertPass("Call to SDL_ClearError()");
- SDL_DestroyPixelFormat(NULL);
- SDLTest_AssertPass("Call to SDL_DestroyPixelFormat(NULL)");
- error = SDL_GetError();
- SDLTest_AssertPass("Call to SDL_GetError()");
- SDLTest_AssertCheck(error == NULL || error[0] == '\0', "Validate that error message is empty");
-
return TEST_COMPLETED;
}
@@ -225,7 +213,7 @@ static int pixels_getPixelFormatName(void *arg)
const char *unknownFormat = "SDL_PIXELFORMAT_UNKNOWN";
const char *error;
int i;
- SDL_PixelFormatEnum format;
+ SDL_PixelFormat format;
const char *result;
/* Blank/undefined format */
@@ -371,7 +359,7 @@ static int pixels_allocFreePalette(void *arg)
/* Pixels test cases */
static const SDLTest_TestCaseReference pixelsTest1 = {
- (SDLTest_TestCaseFp)pixels_allocFreeFormat, "pixels_allocFreeFormat", "Call to SDL_CreatePixelFormat and SDL_DestroyPixelFormat", TEST_ENABLED
+ (SDLTest_TestCaseFp)pixels_getPixelFormatDetails, "pixels_allocFreeFormat", "Call to SDL_CreatePixelFormat and SDL_DestroyPixelFormat", TEST_ENABLED
};
static const SDLTest_TestCaseReference pixelsTest2 = {
diff --git a/test/testautomation_render.c b/test/testautomation_render.c
index ddbb30913ede94..4afff21c52b0d0 100644
--- a/test/testautomation_render.c
+++ b/test/testautomation_render.c
@@ -1335,10 +1335,10 @@ compare(SDL_Surface *referenceSurface, int allowable_error)
return;
}
- testSurface = SDL_ConvertSurfaceFormat(surface, RENDER_COMPARE_FORMAT);
+ testSurface = SDL_ConvertSurface(surface, RENDER_COMPARE_FORMAT);
SDL_DestroySurface(surface);
if (!testSurface) {
- SDLTest_AssertCheck(testSurface != NULL, "Validate result from SDL_ConvertSurfaceFormat, got NULL, %s", SDL_GetError());
+ SDLTest_AssertCheck(testSurface != NULL, "Validate result from SDL_ConvertSurface, got NULL, %s", SDL_GetError());
return;
}
diff --git a/test/testautomation_surface.c b/test/testautomation_surface.c
index 98c9293c40279f..890b001ed972df 100644
--- a/test/testautomation_surface.c
+++ b/test/testautomation_surface.c
@@ -77,7 +77,7 @@ static void clearTestSurface(void)
Uint32 color;
/* Clear surface. */
- color = SDL_MapRGBA(testSurface->format, 0, 0, 0, 0);
+ color = SDL_MapRGBA(testSurface->format, SDL_GetSurfacePalette(testSurface), 0, 0, 0, 0);
SDLTest_AssertPass("Call to SDL_MapRGBA()");
ret = SDL_FillSurfaceRect(testSurface, NULL, color);
SDLTest_AssertPass("Call to SDL_FillSurfaceRect()");
@@ -280,8 +280,8 @@ static int surface_testSurfaceConversion(void *arg)
}
/* Set transparent pixel as the pixel at (0,0) */
- if (face->format->palette) {
- ret = SDL_SetSurfaceColorKey(face, SDL_RLEACCEL, *(Uint8 *)face->pixels);
+ if (SDL_GetSurfacePalette(face)) {
+ ret = SDL_SetSurfaceColorKey(face, SDL_TRUE, *(Uint8 *)face->pixels);
SDLTest_AssertPass("Call to SDL_SetSurfaceColorKey()");
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceColorKey, expected: 0, got: %i", ret);
}
@@ -344,7 +344,7 @@ static int surface_testCompleteSurfaceConversion(void *arg)
#endif
};
SDL_Surface *face = NULL, *cvt1, *cvt2, *final;
- SDL_PixelFormat *fmt1, *fmt2;
+ const SDL_PixelFormatDetails *fmt1, *fmt2;
int i, j, ret = 0;
/* Create sample surface */
@@ -355,33 +355,33 @@ static int surface_testCompleteSurfaceConversion(void *arg)
}
/* Set transparent pixel as the pixel at (0,0) */
- if (face->format->palette) {
- ret = SDL_SetSurfaceColorKey(face, SDL_RLEACCEL, *(Uint8 *)face->pixels);
+ if (SDL_GetSurfacePalette(face)) {
+ ret = SDL_SetSurfaceColorKey(face, SDL_TRUE, *(Uint8 *)face->pixels);
SDLTest_AssertPass("Call to SDL_SetSurfaceColorKey()");
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceColorKey, expected: 0, got: %i", ret);
}
for (i = 0; i < SDL_arraysize(pixel_formats); ++i) {
for (j = 0; j < SDL_arraysize(pixel_formats); ++j) {
- fmt1 = SDL_CreatePixelFormat(pixel_formats[i]);
- SDLTest_AssertCheck(fmt1 != NULL, "SDL_CreatePixelFormat(%s[0x%08" SDL_PRIx32 "]) should return a non-null pixel format",
+ fmt1 = SDL_GetPixelFormatDetails(pixel_formats[i]);
+ SDLTest_AssertCheck(fmt1 != NULL, "SDL_GetPixelFormatDetails(%s[0x%08" SDL_PRIx32 "]) should return a non-null pixel format",
SDL_GetPixelFormatName(pixel_formats[i]), pixel_formats[i]);
- cvt1 = SDL_ConvertSurface(face, fmt1);
+ cvt1 = SDL_ConvertSurface(face, fmt1->format);
SDLTest_AssertCheck(cvt1 != NULL, "SDL_ConvertSurface(..., %s[0x%08" SDL_PRIx32 "]) should return a non-null surface",
SDL_GetPixelFormatName(pixel_formats[i]), pixel_formats[i]);
- fmt2 = SDL_CreatePixelFormat(pixel_formats[j]);
- SDLTest_AssertCheck(fmt2 != NULL, "SDL_CreatePixelFormat(%s[0x%08" SDL_PRIx32 "]) should return a non-null pixel format",
+ fmt2 = SDL_GetPixelFormatDetails(pixel_formats[j]);
+ SDLTest_AssertCheck(fmt2 != NULL, "SDL_GetPixelFormatDetails(%s[0x%08" SDL_PRIx32 "]) should return a non-null pixel format",
SDL_GetPixelFormatName(pixel_formats[i]), pixel_formats[i]);
- cvt2 = SDL_ConvertSurface(cvt1, fmt2);
+ cvt2 = SDL_ConvertSurface(cvt1, fmt2->format);
SDLTest_AssertCheck(cvt2 != NULL, "SDL_ConvertSurface(..., %s[0x%08" SDL_PRIx32 "]) should return a non-null surface",
SDL_GetPixelFormatName(pixel_formats[i]), pixel_formats[i]);
if (fmt1 && fmt2 &&
- fmt1->bytes_per_pixel == face->format->bytes_per_pixel &&
- fmt2->bytes_per_pixel == face->format->bytes_per_pixel &&
- (fmt1->Amask != 0) == (face->format->Amask != 0) &&
- (fmt2->Amask != 0) == (face->format->Amask != 0)) {
+ fmt1->bytes_per_pixel == SDL_BYTESPERPIXEL(face->format) &&
+ fmt2->bytes_per_pixel == SDL_BYTESPERPIXEL(face->format) &&
+ SDL_ISPIXELFORMAT_ALPHA(fmt1->format) == SDL_ISPIXELFORMAT_ALPHA(face->format) &&
+ SDL_ISPIXELFORMAT_ALPHA(fmt2->format) == SDL_ISPIXELFORMAT_ALPHA(face->format)) {
final = SDL_ConvertSurface(cvt2, face->format);
SDL_assert(final != NULL);
@@ -392,9 +392,7 @@ static int surface_testCompleteSurfaceConversion(void *arg)
}
SDL_DestroySurface(cvt1);
- SDL_DestroyPixelFormat(fmt1);
SDL_DestroySurface(cvt2);
- SDL_DestroyPixelFormat(fmt2);
}
}
@@ -605,11 +603,11 @@ static int surface_testOverflow(void *arg)
SDLTest_AssertCheck(surface == NULL, "Should detect negative width");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
- surface = SDL_CreateSurfaceFrom(buf, -1, 1, 4, SDL_PIXELFORMAT_INDEX8);
+ surface = SDL_CreateSurfaceFrom(-1, 1, SDL_PIXELFORMAT_INDEX8, buf, 4);
SDLTest_AssertCheck(surface == NULL, "Should detect negative width");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
- surface = SDL_CreateSurfaceFrom(buf, -1, 1, 4, SDL_PIXELFORMAT_RGBA8888);
+ surface = SDL_CreateSurfaceFrom(-1, 1, SDL_PIXELFORMAT_RGBA8888, buf, 4);
SDLTest_AssertCheck(surface == NULL, "Should detect negative width");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
@@ -619,29 +617,29 @@ static int surface_testOverflow(void *arg)
SDLTest_AssertCheck(surface == NULL, "Should detect negative height");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
- surface = SDL_CreateSurfaceFrom(buf, 1, -1, 4, SDL_PIXELFORMAT_INDEX8);
+ surface = SDL_CreateSurfaceFrom(1, -1, SDL_PIXELFORMAT_INDEX8, buf, 4);
SDLTest_AssertCheck(surface == NULL, "Should detect negative height");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
- surface = SDL_CreateSurfaceFrom(buf, 1, -1, 4, SDL_PIXELFORMAT_RGBA8888);
+ surface = SDL_CreateSurfaceFrom(1, -1, SDL_PIXELFORMAT_RGBA8888, buf, 4);
SDLTest_AssertCheck(surface == NULL, "Should detect negative height");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
expectedError = "Parameter 'pitch' is invalid";
- surface = SDL_CreateSurfaceFrom(buf, 4, 1, -1, SDL_PIXELFORMAT_INDEX8);
+ surface = SDL_CreateSurfaceFrom(4, 1, SDL_PIXELFORMAT_INDEX8, buf, -1);
SDLTest_AssertCheck(surface == NULL, "Should detect negative pitch");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
- surface = SDL_CreateSurfaceFrom(buf, 1, 1, -1, SDL_PIXELFORMAT_RGBA8888);
+ surface = SDL_CreateSurfaceFrom(1, 1, SDL_PIXELFORMAT_RGBA8888, buf, -1);
SDLTest_AssertCheck(surface == NULL, "Should detect negative pitch");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
- surface = SDL_CreateSurfaceFrom(buf, 1, 1, 0, SDL_PIXELFORMAT_RGBA8888);
+ surface = SDL_CreateSurfaceFrom(1, 1, SDL_PIXELFORMAT_RGBA8888, buf, 0);
SDLTest_AssertCheck(surface == NULL, "Should detect zero pitch");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
- surface = SDL_CreateSurfaceFrom(NULL, 1, 1, 0, SDL_PIXELFORMAT_RGBA8888);
+ surface = SDL_CreateSurfaceFrom(1, 1, SDL_PIXELFORMAT_RGBA8888, NULL, 0);
SDLTest_AssertCheck(surface != NULL, "Allow zero pitch for partially set up surfaces: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
@@ -649,104 +647,104 @@ static int surface_testOverflow(void *arg)
/* Less than 1 byte per pixel: the pitch can legitimately be less than
* the width, but it must be enough to hold the appropriate number of
* bits per pixel. SDL_PIXELFORMAT_INDEX4* needs 1 byte per 2 pixels. */
- surface = SDL_CreateSurfaceFrom(buf, 6, 1, 3, SDL_PIXELFORMAT_INDEX4LSB);
+ surface = SDL_CreateSurfaceFrom(6, 1, SDL_PIXELFORMAT_INDEX4LSB, buf, 3);
SDLTest_AssertCheck(surface != NULL, "6px * 4 bits per px fits in 3 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
- surface = SDL_CreateSurfaceFrom(buf, 6, 1, 3, SDL_PIXELFORMAT_INDEX4MSB);
+ surface = SDL_CreateSurfaceFrom(6, 1, SDL_PIXELFORMAT_INDEX4MSB, buf, 3);
SDLTest_AssertCheck(surface != NULL, "6px * 4 bits per px fits in 3 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
- surface = SDL_CreateSurfaceFrom(buf, 7, 1, 3, SDL_PIXELFORMAT_INDEX4LSB);
+ surface = SDL_CreateSurfaceFrom(7, 1, SDL_PIXELFORMAT_INDEX4LSB, buf, 3);
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
- surface = SDL_CreateSurfaceFrom(buf, 7, 1, 3, SDL_PIXELFORMAT_INDEX4MSB);
+ surface = SDL_CreateSurfaceFrom(7, 1, SDL_PIXELFORMAT_INDEX4MSB, buf, 3);
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
- surface = SDL_CreateSurfaceFrom(buf, 7, 1, 4, SDL_PIXELFORMAT_INDEX4LSB);
+ surface = SDL_CreateSurfaceFrom(7, 1, SDL_PIXELFORMAT_INDEX4LSB, buf, 4);
SDLTest_AssertCheck(surface != NULL, "7px * 4 bits per px fits in 4 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
- surface = SDL_CreateSurfaceFrom(buf, 7, 1, 4, SDL_PIXELFORMAT_INDEX4MSB);
+ surface = SDL_CreateSurfaceFrom(7, 1, SDL_PIXELFORMAT_INDEX4MSB, buf, 4);
SDLTest_AssertCheck(surface != NULL, "7px * 4 bits per px fits in 4 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
/* SDL_PIXELFORMAT_INDEX2* needs 1 byte per 4 pixels. */
- surface = SDL_CreateSurfaceFrom(buf, 12, 1, 3, SDL_PIXELFORMAT_INDEX2LSB);
+ surface = SDL_CreateSurfaceFrom(12, 1, SDL_PIXELFORMAT_INDEX2LSB, buf, 3);
SDLTest_AssertCheck(surface != NULL, "12px * 2 bits per px fits in 3 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
- surface = SDL_CreateSurfaceFrom(buf, 12, 1, 3, SDL_PIXELFORMAT_INDEX2MSB);
+ surface = SDL_CreateSurfaceFrom(12, 1, SDL_PIXELFORMAT_INDEX2MSB, buf, 3);
SDLTest_AssertCheck(surface != NULL, "12px * 2 bits per px fits in 3 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
- surface = SDL_CreateSurfaceFrom(buf, 13, 1, 3, SDL_PIXELFORMAT_INDEX2LSB);
+ surface = SDL_CreateSurfaceFrom(13, 1, SDL_PIXELFORMAT_INDEX2LSB, buf, 3);
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp (%d)", surface ? surface->pitch : 0);
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
- surface = SDL_CreateSurfaceFrom(buf, 13, 1, 3, SDL_PIXELFORMAT_INDEX2MSB);
+ surface = SDL_CreateSurfaceFrom(13, 1, SDL_PIXELFORMAT_INDEX2MSB, buf, 3);
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
- surface = SDL_CreateSurfaceFrom(buf, 13, 1, 4, SDL_PIXELFORMAT_INDEX2LSB);
+ surface = SDL_CreateSurfaceFrom(13, 1, SDL_PIXELFORMAT_INDEX2LSB, buf, 4);
SDLTest_AssertCheck(surface != NULL, "13px * 2 bits per px fits in 4 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
- surface = SDL_CreateSurfaceFrom(buf, 13, 1, 4, SDL_PIXELFORMAT_INDEX2MSB);
+ surface = SDL_CreateSurfaceFrom(13, 1, SDL_PIXELFORMAT_INDEX2MSB, buf, 4);
SDLTest_AssertCheck(surface != NULL, "13px * 2 bits per px fits in 4 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
/* SDL_PIXELFORMAT_INDEX1* needs 1 byte per 8 pixels. */
- surface = SDL_CreateSurfaceFrom(buf, 16, 1, 2, SDL_PIXELFORMAT_INDEX1LSB);
+ surface = SDL_CreateSurfaceFrom(16, 1, SDL_PIXELFORMAT_INDEX1LSB, buf, 2);
SDLTest_AssertCheck(surface != NULL, "16px * 1 bit per px fits in 2 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
- surface = SDL_CreateSurfaceFrom(buf, 16, 1, 2, SDL_PIXELFORMAT_INDEX1MSB);
+ surface = SDL_CreateSurfaceFrom(16, 1, SDL_PIXELFORMAT_INDEX1MSB, buf, 2);
SDLTest_AssertCheck(surface != NULL, "16px * 1 bit per px fits in 2 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
- surface = SDL_CreateSurfaceFrom(buf, 17, 1, 2, SDL_PIXELFORMAT_INDEX1LSB);
+ surface = SDL_CreateSurfaceFrom(17, 1, SDL_PIXELFORMAT_INDEX1LSB, buf, 2);
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
- surface = SDL_CreateSurfaceFrom(buf, 17, 1, 2, SDL_PIXELFORMAT_INDEX1MSB);
+ surface = SDL_CreateSurfaceFrom(17, 1, SDL_PIXELFORMAT_INDEX1MSB, buf, 2);
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
- surface = SDL_CreateSurfaceFrom(buf, 17, 1, 3, SDL_PIXELFORMAT_INDEX1LSB);
+ surface = SDL_CreateSurfaceFrom(17, 1, SDL_PIXELFORMAT_INDEX1LSB, buf, 3);
SDLTest_AssertCheck(surface != NULL, "17px * 1 bit per px fits in 3 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
- surface = SDL_CreateSurfaceFrom(buf, 17, 1, 3, SDL_PIXELFORMAT_INDEX1MSB);
+ surface = SDL_CreateSurfaceFrom(17, 1, SDL_PIXELFORMAT_INDEX1MSB, buf, 3);
SDLTest_AssertCheck(surface != NULL, "17px * 1 bit per px fits in 3 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
/* SDL_PIXELFORMAT_INDEX8 and SDL_PIXELFORMAT_RGB332 require 1 byte per pixel. */
- surface = SDL_CreateSurfaceFrom(buf, 5, 1, 5, SDL_PIXELFORMAT_RGB332);
+ surface = SDL_CreateSurfaceFrom(5, 1, SDL_PIXELFORMAT_RGB332, buf, 5);
SDLTest_AssertCheck(surface != NULL, "5px * 8 bits per px fits in 5 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
- surface = SDL_CreateSurfaceFrom(buf, 5, 1, 5, SDL_PIXELFORMAT_INDEX8);
+ surface = SDL_CreateSurfaceFrom(5, 1, SDL_PIXELFORMAT_INDEX8, buf, 5);
SDLTest_AssertCheck(surface != NULL, "5px * 8 bits per px fits in 5 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
- surface = SDL_CreateSurfaceFrom(buf, 6, 1, 5, SDL_PIXELFORMAT_RGB332);
+ surface = SDL_CreateSurfaceFrom(6, 1, SDL_PIXELFORMAT_RGB332, buf, 5);
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
- surface = SDL_CreateSurfaceFrom(buf, 6, 1, 5, SDL_PIXELFORMAT_INDEX8);
+ surface = SDL_CreateSurfaceFrom(6, 1, SDL_PIXELFORMAT_INDEX8, buf, 5);
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
@@ -754,20 +752,20 @@ static int surface_testOverflow(void *arg)
/* Everything else requires more than 1 byte per pixel, and rounds up
* each pixel to an integer number of bytes (e.g. RGB555 is really
* XRGB1555, with 1 bit per pixel wasted). */
- surface = SDL_CreateSurfaceFrom(buf, 3, 1, 6, SDL_PIXELFORMAT_XRGB1555);
+ surface = SDL_CreateSurfaceFrom(3, 1, SDL_PIXELFORMAT_XRGB1555, buf, 6);
SDLTest_AssertCheck(surface != NULL, "3px * 15 (really 16) bits per px fits in 6 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
- surface = SDL_CreateSurfaceFrom(buf, 3, 1, 6, SDL_PIXELFORMAT_XRGB1555);
+ surface = SDL_CreateSurfaceFrom(3, 1, SDL_PIXELFORMAT_XRGB1555, buf, 6);
SDLTest_AssertCheck(surface != NULL, "5px * 15 (really 16) bits per px fits in 6 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
- surface = SDL_CreateSurfaceFrom(buf, 4, 1, 6, SDL_PIXELFORMAT_XRGB1555);
+ surface = SDL_CreateSurfaceFrom(4, 1, SDL_PIXELFORMAT_XRGB1555, buf, 6);
SDLTest_AssertCheck(surface == NULL, "4px * 15 (really 16) bits per px doesn't fit in 6 bytes");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
- surface = SDL_CreateSurfaceFrom(buf, 4, 1, 6, SDL_PIXELFORMAT_XRGB1555);
+ surface = SDL_CreateSurfaceFrom(4, 1, SDL_PIXELFORMAT_XRGB1555, buf, 6);
SDLTest_AssertCheck(surface == NULL, "4px * 15 (really 16) bits per px doesn't fit in 6 bytes");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
@@ -845,7 +843,7 @@ static int surface_testFlip(void *arg)
CHECK_FUNC(SDL_FlipSurface, (surface, SDL_FLIP_HORIZONTAL));
SDLTest_AssertCheck(pixels[offset] == 0x00,
"Expected pixels[%d] == 0x00 got 0x%.2X", offset, pixels[offset]);
- offset += (surface->w - 1) * surface->format->bytes_per_pixel;
+ offset += (surface->w - 1) * SDL_BYTESPERPIXEL(surface->format);
SDLTest_AssertCheck(pixels[offset] == 0xFF,
"Expected pixels[%d] == 0xFF got 0x%.2X", offset, pixels[offset]);
diff --git a/test/testcamera.c b/test/testcamera.c
index e0b99925292d28..6565edeb88f5c8 100644
--- a/test/testcamera.c
+++ b/test/testcamera.c
@@ -274,12 +274,11 @@ int SDL_AppIterate(void *appstate)
SDL_DestroyTexture(texture);
}
- SDL_Colorspace colorspace = SDL_COLORSPACE_UNKNOWN;
- SDL_GetSurfaceColorspace(frame_current, &colorspace);
+ SDL_Colorspace colorspace = SDL_GetSurfaceColorspace(frame_current);
/* Create texture with appropriate format */
SDL_PropertiesID props = SDL_CreateProperties();
- SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER, frame_current->format->format);
+ SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER, frame_current->format);
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_COLORSPACE_NUMBER, colorspace);
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_ACCESS_NUMBER, SDL_TEXTUREACCESS_STREAMING);
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_WIDTH_NUMBER, frame_current->w);
diff --git a/test/testcustomcursor.c b/test/testcustomcursor.c
index 014640cfe39c53..7b7b650402c7a7 100644
--- a/test/testcustomcursor.c
+++ b/test/testcustomcursor.c
@@ -115,15 +115,15 @@ init_color_cursor(const char *file)
SDL_Cursor *cursor = NULL;
SDL_Surface *surface = SDL_LoadBMP(file);
if (surface) {
- if (surface->format->palette) {
- const Uint8 bpp = surface->format->bits_per_pixel;
+ if (SDL_GetSurfacePalette(surface)) {
+ const Uint8 bpp = SDL_BITSPERPIXEL(surface->format);
const Uint8 mask = (1 << bpp) - 1;
- if (SDL_PIXELORDER(surface->format->format) == SDL_BITMAPORDER_4321)
+ if (SDL_PIXELORDER(surface->format) == SDL_BITMAPORDER_4321)
SDL_SetSurfaceColorKey(surface, 1, (*(Uint8 *)surface->pixels) & mask);
else
SDL_SetSurfaceColorKey(surface, 1, ((*(Uint8 *)surface->pixels) >> (8 - bpp)) & mask);
} else {
- switch (surface->format->bits_per_pixel) {
+ switch (SDL_BITSPERPIXEL(surface->format)) {
case 15:
SDL_SetSurfaceColorKey(surface, 1, (*(Uint16 *)surface->pixels) & 0x00007FFF);
break;
diff --git a/test/testffmpeg.c b/test/testffmpeg.c
index 3d9cca6660999e..fc1e7881a7eb09 100644
--- a/test/testffmpeg.c
+++ b/test/testffmpeg.c
@@ -279,7 +279,7 @@ static void MoveSprite(void)
}
}
-static SDL_PixelFormatEnum GetTextureFormat(enum AVPixelFormat format)
+static SDL_PixelFormat GetTextureFormat(enum AVPixelFormat format)
{
switch (format) {
case AV_PIX_FMT_RGB8:
@@ -511,7 +511,7 @@ static SDL_Colorspace GetFrameColorspace(AVFrame *frame)
return colorspace;
}
-static SDL_PropertiesID CreateVideoTextureProperties(AVFrame *frame, SDL_PixelFormatEnum format, int access)
+static SDL_PropertiesID CreateVideoTextureProperties(AVFrame *frame, SDL_PixelFormat format, int access)
{
AVFrameSideData *pSideData;
SDL_PropertiesID props;
@@ -571,12 +571,12 @@ static void SDLCALL FreeSwsContextContainer(void *userdata, void *value)
static SDL_bool GetTextureForMemoryFrame(AVFrame *frame, SDL_Texture **texture)
{
int texture_width = 0, texture_height = 0;
- SDL_PixelFormatEnum texture_format = SDL_PIXELFORMAT_UNKNOWN;
- SDL_PixelFormatEnum frame_format = GetTextureFormat(frame->format);
+ SDL_PixelFormat texture_format = SDL_PIXELFORMAT_UNKNOWN;
+ SDL_PixelFormat frame_format = GetTextureFormat(frame->format);
if (*texture) {
SDL_PropertiesID props = SDL_GetTextureProperties(*texture);
- texture_format = (SDL_PixelFormatEnum)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_FORMAT_NUMBER, SDL_PIXELFORMAT_UNKNOWN);
+ texture_format = (SDL_PixelFormat)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_FORMAT_NUMBER, SDL_PIXELFORMAT_UNKNOWN);
texture_width = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_WIDTH_NUMBER, 0);
texture_height = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_HEIGHT_NUMBER, 0);
}
diff --git a/test/testgles2_sdf.c b/test/testgles2_sdf.c
index af36324367573a..23c11238eada51 100644
--- a/test/testgles2_sdf.c
+++ b/test/testgles2_sdf.c
@@ -600,7 +600,7 @@ int main(int argc, char *argv[])
TTF_CloseFont(font);
TTF_Quit();
#endif
- g_surf_sdf = SDL_ConvertSurfaceFormat(tmp, SDL_PIXELFORMAT_ABGR8888);
+ g_surf_sdf = SDL_ConvertSurface(tmp, SDL_PIXELFORMAT_ABGR8888);
SDL_SetSurfaceBlendMode(g_surf_sdf, SDL_BLENDMODE_BLEND);
}
diff --git a/test/testoverlay.c b/test/testoverlay.c
index d87c292b68bb94..9ef1aaf2e46a80 100644
--- a/test/testoverlay.c
+++ b/test/testoverlay.c
@@ -499,7 +499,7 @@ int main(int argc, char **argv)
}
/* Convert to YUV SDL_Surface */
- MooseYUVSurfaces[i] = SDL_ConvertSurfaceFormat(mooseRGBSurface, yuv_format);
+ MooseYUVSurfaces[i] = SDL_ConvertSurface(mooseRGBSurface, yuv_format);
if (MooseYUVSurfaces[i] == NULL) {
quit(7);
}
diff --git a/test/testshape.c b/test/testshape.c
index 2f226c83b0d928..34553611339d4a 100644
--- a/test/testshape.c
+++ b/test/testshape.c
@@ -86,12 +86,12 @@ int main(int argc, char *argv[])
goto quit;
}
- if (!SDL_ISPIXELFORMAT_ALPHA(shape->format->format)) {
+ if (!SDL_ISPIXELFORMAT_ALPHA(shape->format)) {
/* Set the colorkey to the top-left pixel */
Uint8 r, g, b, a;
SDL_ReadSurfacePixel(shape, 0, 0, &r, &g, &b, &a);
- SDL_SetSurfaceColorKey(shape, 1, SDL_MapRGBA(shape->format, r, g, b, a));
+ SDL_SetSurfaceColorKey(shape, 1, SDL_MapRGBA(shape->format, SDL_GetSurfacePalette(shape), r, g, b, a));
}
if (!resizable) {
diff --git a/test/testspriteminimal.c b/test/testspriteminimal.c
index 41704992dece3e..70fcdfd3d95f83 100644
--- a/test/testspriteminimal.c
+++ b/test/testspriteminimal.c
@@ -42,7 +42,7 @@ static SDL_Texture *CreateTexture(SDL_Renderer *r, unsigned char *data, unsigned
surface = SDL_LoadBMP_IO(src, SDL_TRUE);
if (surface) {
/* Treat white as transparent */
- SDL_SetSurfaceColorKey(surface, SDL_TRUE, SDL_MapRGB(surface->format, 255, 255, 255));
+ SDL_SetSurfaceColorKey(surface, SDL_TRUE, SDL_MapRGB(surface->format, SDL_GetSurfacePalette(surface), 255, 255, 255));
texture = SDL_CreateTextureFromSurface(r, surface);
*w = surface->w;
diff --git a/test/testutils.c b/test/testutils.c
index 863d05061f8344..09dfb726c815c8 100644
--- a/test/testutils.c
+++ b/test/testutils.c
@@ -103,15 +103,15 @@ LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent,
} else {
/* Set transparent pixel as the pixel at (0,0) */
if (transparent) {
- if (temp->format->palette) {
- const Uint8 bpp = temp->format->bits_per_pixel;
+ if (SDL_GetSurfacePalette(temp)) {
+ const Uint8 bpp = SDL_BITSPERPIXEL(temp->format);
const Uint8 mask = (1 << bpp) - 1;
- if (SDL_PIXELORDER(temp->format->format) == SDL_BITMAPORDER_4321)
+ if (SDL_PIXELORDER(temp->format) == SDL_BITMAPORDER_4321)
SDL_SetSurfaceColorKey(temp, SDL_TRUE, (*(Uint8 *)temp->pixels) & mask);
else
SDL_SetSurfaceColorKey(temp, SDL_TRUE, ((*(Uint8 *)temp->pixels) >> (8 - bpp)) & mask);
} else {
- switch (temp->format->bits_per_pixel) {
+ switch (SDL_BITSPERPIXEL(temp->format)) {
case 15:
SDL_SetSurfaceColorKey(temp, SDL_TRUE,
(*(Uint16 *)temp->pixels) & 0x00007FFF);
diff --git a/test/testyuv.c b/test/testyuv.c
index 523e82d8c0b6ad..cf207119da89fe 100644
--- a/test/testyuv.c
+++ b/test/testyuv.c
@@ -77,7 +77,7 @@ static SDL_bool verify_yuv_data(Uint32 format, SDL_Colorspace colorspace, const
return SDL_FALSE;
}
- if (SDL_ConvertPixelsAndColorspace(surface->w, surface->h, format, colorspace, 0, yuv, yuv_pitch, surface->format->format, SDL_COLORSPACE_SRGB, 0, rgb, surface->pitch) == 0) {
+ if (SDL_ConvertPixelsAndColorspace(surface->w, surface->h, format, colorspace, 0, yuv, yuv_pitch, surface->format, SDL_COLORSPACE_SRGB, 0, rgb, surface->pitch) == 0) {
int x, y;
result = SDL_TRUE;
for (y = 0; y < surface->h; ++y) {
@@ -97,7 +97,7 @@ static SDL_bool verify_yuv_data(Uint32 format, SDL_Colorspace colorspace, const
}
}
} else {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(format), SDL_GetPixelFormatName(surface->format->format), SDL_GetError());
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(format), SDL_GetPixelFormatName(surface->format), SDL_GetError());
}
SDL_free(rgb);
@@ -151,8 +151,8 @@ static int run_automated_tests(int pattern_size, int extra_pitch)
/* Verify conversion to YUV formats */
for (i = 0; i < SDL_arraysize(formats); ++i) {
yuv1_pitch = CalculateYUVPitch(formats[i], pattern->w) + extra_pitch;
- if (SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, pattern->format->format, SDL_COLORSPACE_SRGB, 0, pattern->pixels, pattern->pitch, formats[i], colorspace, 0, yuv1, yuv1_pitch) < 0) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(pattern->format->format), SDL_GetPixelFormatName(formats[i]), SDL_GetError());
+ if (SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, pattern->format, SDL_COLORSPACE_SRGB, 0, pattern->pixels, pattern->pitch, formats[i], colorspace, 0, yuv1, yuv1_pitch) < 0) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(pattern->format), SDL_GetPixelFormatName(formats[i]), SDL_GetError());
goto done;
}
if (!verify_yuv_data(formats[i], colorspace, yuv1, yuv1_pitch, pattern, tight_tolerance)) {
@@ -166,8 +166,8 @@ static int run_automated_tests(int pattern_size, int extra_pitch)
for (j = 0; j < SDL_arraysize(formats); ++j) {
yuv1_pitch = CalculateYUVPitch(formats[i], pattern->w) + extra_pitch;
yuv2_pitch = CalculateYUVPitch(formats[j], pattern->w) + extra_pitch;
- if (SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, pattern->format->format, SDL_COLORSPACE_SRGB, 0, pattern->pixels, pattern->pitch, formats[i], colorspace, 0, yuv1, yuv1_pitch) < 0) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(pattern->format->format), SDL_GetPixelFormatName(formats[i]), SDL_GetError());
+ if (SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, pattern->format, SDL_COLORSPACE_SRGB, 0, pattern->pixels, pattern->pitch, formats[i], colorspace, 0, yuv1, yuv1_pitch) < 0) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(pattern->format), SDL_GetPixelFormatName(formats[i]), SDL_GetError());
goto done;
}
if (SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, formats[i], colorspace, 0, yuv1, yuv1_pitch, formats[j], colorspace, 0, yuv2, yuv2_pitch) < 0) {
@@ -191,8 +191,8 @@ static int run_automated_tests(int pattern_size, int extra_pitch)
yuv1_pitch = CalculateYUVPitch(formats[i], pattern->w) + extra_pitch;
yuv2_pitch = CalculateYUVPitch(formats[j], pattern->w) + extra_pitch;
- if (SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, pattern->format->format, SDL_COLORSPACE_SRGB, 0, pattern->pixels, pattern->pitch, formats[i], colorspace, 0, yuv1, yuv1_pitch) < 0) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(pattern->format->format), SDL_GetPixelFormatName(formats[i]), SDL_GetError());
+ if (SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, pattern->format, SDL_COLORSPACE_SRGB, 0, pattern->pixels, pattern->pitch, formats[i], colorspace, 0, yuv1, yuv1_pitch) < 0) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(pattern->format), SDL_GetPixelFormatName(formats[i]), SDL_GetError());
goto done;
}
if (SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, formats[i], colorspace, 0, yuv1, yuv1_pitch, formats[j], colorspace, 0, yuv1, yuv2_pitch) < 0) {
@@ -220,8 +220,8 @@ static int run_automated_tests(int pattern_size, int extra_pitch)
/* The pitch needs to be Uint16 aligned for P010 pixels */
yuv1_pitch = CalculateYUVPitch(SDL_PIXELFORMAT_P010, pattern->w) + ((extra_pitch + 1) & ~1);
- if (SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, pattern->format->format, SDL_COLORSPACE_SRGB, 0, pattern->pixels, pattern->pitch, SDL_PIXELFORMAT_P010, colorspace, 0, yuv1, yuv1_pitch) < 0) {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(pattern->format->format), SDL_GetPixelFormatName(SDL_PIXELFORMAT_P010), SDL_GetError());
+ if (SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, pattern->format, SDL_COLORSPACE_SRGB, 0, pattern->pixels, pattern->pitch, SDL_PIXELFORMAT_P010, colorspace, 0, yuv1, yuv1_pitch) < 0) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(pattern->format), SDL_GetPixelFormatName(SDL_PIXELFORMAT_P010), SDL_GetError());
goto done;
}
/* Going through XRGB2101010 format during P010 conversion is slightly lossy, so use looser tolerance here */
@@ -418,7 +418,7 @@ int main(int argc, char **argv)
filename = GetResourceFilename(filename, "testyuv.bmp");
bmp = SDL_LoadBMP(filename);
- original = SDL_ConvertSurfaceFormat(bmp, SDL_PIXELFORMAT_RGB24);
+ original = SDL_ConvertSurface(bmp, SDL_PIXELFORMAT_RGB24);
SDL_DestroySurface(bmp);
if (!original) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError());