Added SDL_SetRenderDrawColorspace() and SDL_GetRenderDrawColorspace()

main
Sam Lantinga 2024-01-31 21:46:02 -08:00
parent 9c8b47b726
commit dd28ab0489
5 changed files with 64 additions and 1 deletions

View File

@ -1361,7 +1361,40 @@ extern DECLSPEC int SDLCALL SDL_SetRenderScale(SDL_Renderer *renderer, float sca
extern DECLSPEC int SDLCALL SDL_GetRenderScale(SDL_Renderer *renderer, float *scaleX, float *scaleY);
/**
* Set the color used for drawing operations (Rect, Line and Clear).
* Set the colorspace used for drawing operations
*
* The default colorspace for drawing operations is SDL_COLORSPACE_SRGB, but you can change it to other colorspaces such as SDL_COLORSPACE_SCRGB for HDR rendering.
*
* This does not affect the colorspace of textures, which is specified via properties when the texture is created and does not change.
*
* \param renderer the rendering context
* \param colorspace an SDL_ColorSpace value describing the colorspace for drawing operations
* \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_GetRenderDrawColorspace
*/
extern DECLSPEC int SDLCALL SDL_SetRenderDrawColorspace(SDL_Renderer *renderer, SDL_Colorspace colorspace);
/**
* Get the colorspace used for drawing operations
*
* \param renderer the rendering context
* \param colorspace a pointer filled in with an SDL_ColorSpace value describing the colorspace for drawing operations
* \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_SetRenderDrawColorspace
*/
extern DECLSPEC int SDLCALL SDL_GetRenderDrawColorspace(SDL_Renderer *renderer, SDL_Colorspace *colorspace);
/**
* Set the color used for drawing operations.
*
* Set the color for drawing or filling rectangles, lines, and points, and for
* SDL_RenderClear().

View File

@ -969,6 +969,8 @@ SDL3_0.0.0 {
SDL_SetSurfaceColorspace;
SDL_GetSurfaceColorspace;
SDL_ConvertSurfaceFormatAndColorspace;
SDL_SetRenderDrawColorspace;
SDL_GetRenderDrawColorspace;
# extra symbols go here (don't modify this line)
local: *;
};

View File

@ -994,3 +994,5 @@
#define SDL_SetSurfaceColorspace SDL_SetSurfaceColorspace_REAL
#define SDL_GetSurfaceColorspace SDL_GetSurfaceColorspace_REAL
#define SDL_ConvertSurfaceFormatAndColorspace SDL_ConvertSurfaceFormatAndColorspace_REAL
#define SDL_SetRenderDrawColorspace SDL_SetRenderDrawColorspace_REAL
#define SDL_GetRenderDrawColorspace SDL_GetRenderDrawColorspace_REAL

View File

@ -1019,3 +1019,5 @@ SDL_DYNAPI_PROC(int,SDL_ConvertPixelsAndColorspace,(int a, int b, Uint32 c, SDL_
SDL_DYNAPI_PROC(int,SDL_SetSurfaceColorspace,(SDL_Surface *a, SDL_Colorspace b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetSurfaceColorspace,(SDL_Surface *a, SDL_Colorspace *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_Surface*,SDL_ConvertSurfaceFormatAndColorspace,(SDL_Surface *a, Uint32 b, SDL_Colorspace c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_SetRenderDrawColorspace,(SDL_Renderer *a, SDL_Colorspace b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetRenderDrawColorspace,(SDL_Renderer *a, SDL_Colorspace *b),(a,b),return)

View File

@ -2757,6 +2757,30 @@ int SDL_GetRenderScale(SDL_Renderer *renderer, float *scaleX, float *scaleY)
return 0;
}
int SDL_SetRenderDrawColorspace(SDL_Renderer *renderer, SDL_Colorspace colorspace)
{
CHECK_RENDERER_MAGIC(renderer, -1);
if (colorspace != SDL_COLORSPACE_SRGB &&
colorspace != SDL_COLORSPACE_SCRGB) {
return SDL_SetError("Unsupported colorspace");
}
renderer->input_colorspace = colorspace;
return 0;
}
int SDL_GetRenderDrawColorspace(SDL_Renderer *renderer, SDL_Colorspace *colorspace)
{
CHECK_RENDERER_MAGIC(renderer, -1);
if (colorspace) {
*colorspace = renderer->input_colorspace;
}
return 0;
}
int SDL_SetRenderDrawColor(SDL_Renderer *renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
const float fR = (float)r / 255.0f;