Skip to content

Commit

Permalink
Add SDL_SoftStrech, SDL_SoftStrechLinear
Browse files Browse the repository at this point in the history
  • Loading branch information
1bsyl committed Dec 7, 2023
1 parent ab347e7 commit 6442020
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 13 deletions.
79 changes: 79 additions & 0 deletions src/sdl2_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -7275,6 +7275,85 @@ SDL_AndroidGetExternalStorageState(void)
}
#endif

static int SoftStretch(SDL_Surface * src,
const SDL_Rect * srcrect,
SDL_Surface * dst,
const SDL_Rect * dstrect, SDL_bool nearest)
{
int ret;
int has_colorkey = 0;
Uint32 colorkey;
Uint8 r, g, b;
Uint8 alpha;
SDL_BlendMode blendMode;
SDL_Rect rect;
SDL_Rect *prect = NULL;

SDL3_zero(rect);

if (dstrect) {
prect = ▭
*prect = *dstrect;
}

if (!src) {
return -1;
}

/* Save source infos */
if (src->format->palette) {
if (SDL_HasColorKey(src)) {
has_colorkey = 1;
SDL_GetColorKey(src, &colorkey);
SDL_SetColorKey(src, SDL_FALSE, 0);
}
}

SDL3_GetSurfaceColorMod(src, &r, &g, &b);
SDL3_GetSurfaceAlphaMod(src, &alpha);
SDL3_GetSurfaceBlendMode(src, &blendMode);

SDL3_SetSurfaceColorMod(src, 0xFF, 0xFF, 0xFF);
SDL3_SetSurfaceAlphaMod(src, 0xFF);
SDL3_SetSurfaceBlendMode(src, SDL_BLENDMODE_NONE);

if (nearest) {
ret = SDL3_BlitSurfaceScaled(src, srcrect, dst, prect);
} else {
ret = SDL3_BlitSurfaceScaledLinear(src, srcrect, dst, prect);
}

SDL3_SetSurfaceColorMod(src, r, g, b);
SDL3_SetSurfaceAlphaMod(src, alpha);
SDL3_SetSurfaceBlendMode(src, blendMode);

if (src->format->palette) {
if (has_colorkey) {
SDL_SetColorKey(src, SDL_FALSE, colorkey);
}
}

return ret;
}

DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface * src,
const SDL_Rect * srcrect,
SDL_Surface * dst,
const SDL_Rect * dstrect)
{
return SoftStretch(src, srcrect, dst, dstrect, SDL_TRUE);
}



DECLSPEC int SDLCALL SDL_SoftStretchLinear(SDL_Surface * src,
const SDL_Rect * srcrect,
SDL_Surface * dst,
const SDL_Rect * dstrect)
{
return SoftStretch(src, srcrect, dst, dstrect, SDL_FALSE);
}

#ifdef __cplusplus
}
#endif
Expand Down
10 changes: 0 additions & 10 deletions src/sdl3_include_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,6 @@
#define SDL_ShowSimpleMessageBox IGNORE_THIS_VERSION_OF_SDL_ShowSimpleMessageBox
#define SDL_ShowWindow IGNORE_THIS_VERSION_OF_SDL_ShowWindow
#define SDL_SignalCondition IGNORE_THIS_VERSION_OF_SDL_SignalCondition
#define SDL_SoftStretch IGNORE_THIS_VERSION_OF_SDL_SoftStretch
#define SDL_SoftStretchLinear IGNORE_THIS_VERSION_OF_SDL_SoftStretchLinear
#define SDL_StartTextInput IGNORE_THIS_VERSION_OF_SDL_StartTextInput
#define SDL_StopTextInput IGNORE_THIS_VERSION_OF_SDL_StopTextInput
#define SDL_SurfaceHasColorKey IGNORE_THIS_VERSION_OF_SDL_SurfaceHasColorKey
Expand Down Expand Up @@ -3449,14 +3447,6 @@
#undef SDL_SignalCondition
#endif

#ifdef SDL_SoftStretch
#undef SDL_SoftStretch
#endif

#ifdef SDL_SoftStretchLinear
#undef SDL_SoftStretchLinear
#endif

#ifdef SDL_StartTextInput
#undef SDL_StartTextInput
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/sdl3_syms.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,10 @@ SDL3_SYM_RENAMED(int,FillRect,FillSurfaceRect,(SDL_Surface *a, const SDL_Rect *b
SDL3_SYM_RENAMED(int,FillRects,FillSurfaceRects,(SDL_Surface *a, const SDL_Rect *b, int c, Uint32 d),(a,b,c,d),return)
SDL3_SYM_RENAMED(int,UpperBlit,BlitSurface,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, SDL_Rect *d),(a,b,c,d),return)
SDL3_SYM(int,BlitSurfaceUnchecked,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, const SDL_Rect *d),(a,b,c,d),return)
SDL3_SYM_PASSTHROUGH(int,SoftStretch,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, const SDL_Rect *d),(a,b,c,d),return)
SDL3_SYM_RENAMED(int,UpperBlitScaled,BlitSurfaceScaled,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, SDL_Rect *d),(a,b,c,d),return)
SDL3_SYM(int,BlitSurfaceScaledLinear,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, SDL_Rect *d),(a,b,c,d),return)
SDL3_SYM(int,BlitSurfaceUncheckedScaled,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, const SDL_Rect *d),(a,b,c,d),return)
SDL3_SYM(int,BlitSurfaceUncheckedScaledLinear,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, const SDL_Rect *d),(a,b,c,d),return)
SDL3_SYM_PASSTHROUGH(const char*,GetThreadName,(SDL_Thread *a),(a),return)
SDL3_SYM_PASSTHROUGH(SDL_threadID,ThreadID,(void),(),return)
SDL3_SYM_PASSTHROUGH(SDL_threadID,GetThreadID,(SDL_Thread *a),(a),return)
Expand Down Expand Up @@ -692,7 +693,6 @@ SDL3_SYM_PASSTHROUGH(double,round,(double a),(a),return)
SDL3_SYM_PASSTHROUGH(float,roundf,(float a),(a),return)
SDL3_SYM_PASSTHROUGH(long,lround,(double a),(a),return)
SDL3_SYM_PASSTHROUGH(long,lroundf,(float a),(a),return)
SDL3_SYM_PASSTHROUGH(int,SoftStretchLinear,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, const SDL_Rect *d),(a,b,c,d),return)
SDL3_SYM_PASSTHROUGH(int,UpdateNVTexture,(SDL_Texture *a, const SDL_Rect *b, const Uint8 *c, int d, const Uint8 *e, int f),(a,b,c,d,e,f),return)
SDL3_SYM(int,SetWindowKeyboardGrab,(SDL_Window *a, SDL_bool b),(a,b),return)
SDL3_SYM(int,SetWindowMouseGrab,(SDL_Window *a, SDL_bool b),(a,b),return)
Expand Down
2 changes: 1 addition & 1 deletion test/testautomation_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ int platform_testSetErrorEmptyInput(void *arg)
int platform_testSetErrorInvalidInput(void *arg)
{
int result;
const char *invalidError = NULL;
const char *invalidError = "";
const char *probeError = "Testing";
char *lastError;
size_t len;
Expand Down

0 comments on commit 6442020

Please sign in to comment.