SDL_SoftStretch: add a check for input pixel format and function re-naming
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
diff --git a/src/video/SDL_stretch.c b/src/video/SDL_stretch.c
index c69ff87..f34b595 100644
--- a/src/video/SDL_stretch.c
+++ b/src/video/SDL_stretch.c
@@ -197,8 +197,8 @@ copy_row3(Uint8 * src, int src_w, Uint8 * dst, int dst_w)
}
}
-static int SDL_SoftStretchLowerNearest(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
-static int SDL_SoftStretchLowerLinear(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
+static int SDL_LowerSoftStretchNearest(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
+static int SDL_LowerSoftStretchLinear(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
static int SDL_UpperSoftStretch(SDL_Surface * src, const SDL_Rect * srcrect, SDL_Surface * dst, const SDL_Rect * dstrect, SDL_ScaleMode scaleMode);
/* Perform a stretch blit between two surfaces of the same format.
@@ -232,6 +232,12 @@ SDL_UpperSoftStretch(SDL_Surface * src, const SDL_Rect * srcrect,
return SDL_SetError("Only works with same format surfaces");
}
+ if (scaleMode != SDL_ScaleModeNearest) {
+ if (src->format->BytesPerPixel != 4 || src->format->format == SDL_PIXELFORMAT_ARGB2101010) {
+ return SDL_SetError("Wrong format");
+ }
+ }
+
/* Verify the blit rectangles */
if (srcrect) {
if ((srcrect->x < 0) || (srcrect->y < 0) ||
@@ -285,9 +291,9 @@ SDL_UpperSoftStretch(SDL_Surface * src, const SDL_Rect * srcrect,
}
if (scaleMode == SDL_ScaleModeNearest) {
- ret = SDL_SoftStretchLowerNearest(src, srcrect, dst, dstrect);
+ ret = SDL_LowerSoftStretchNearest(src, srcrect, dst, dstrect);
} else {
- ret = SDL_SoftStretchLowerLinear(src, srcrect, dst, dstrect);
+ ret = SDL_LowerSoftStretchLinear(src, srcrect, dst, dstrect);
}
/* We need to unlock the surfaces if they're locked */
@@ -303,7 +309,7 @@ SDL_UpperSoftStretch(SDL_Surface * src, const SDL_Rect * srcrect,
int
-SDL_SoftStretchLowerNearest(SDL_Surface *src, const SDL_Rect *srcrect,
+SDL_LowerSoftStretchNearest(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_Surface *dst, const SDL_Rect *dstrect)
{
int pos, inc;
@@ -1066,7 +1072,7 @@ scale_mat_NEON(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *d
#endif
int
-SDL_SoftStretchLowerLinear(SDL_Surface *s, const SDL_Rect *srcrect,
+SDL_LowerSoftStretchLinear(SDL_Surface *s, const SDL_Rect *srcrect,
SDL_Surface *d, const SDL_Rect *dstrect)
{
int ret = -1;