diff options
Diffstat (limited to 'src/fb.c')
| -rw-r--r-- | src/fb.c | 36 |
1 files changed, 22 insertions, 14 deletions
@@ -1,5 +1,7 @@ #include "fb.h" +static bool is_normal(float f) { return !SDL_isinff(f) && !SDL_isnanf(f); } + struct pw_framebuffer *pw_fb_init(SDL_Renderer *renderer, enum pw_scale_mode mode) { if (!renderer) { @@ -56,30 +58,34 @@ void pw_fb_free(struct pw_framebuffer *fb) { bool pw_fb_iterate(struct pw_framebuffer *fb) { if (!fb) { - SDL_InvalidParamError("fb"); - return false; + return SDL_InvalidParamError("fb"); } return pw_scale(fb->mode, fb->texture, &fb->target); } -static uint8_t project_component(float r, float start, float size, - uint8_t dim) { - if (SDL_isnan(r) || SDL_isnan(start) || SDL_isnan(size) || - SDL_fabsf(size) < 1.) { - return 0; +static float project_component(float r, float start, float size, float dim) { + if (!(int32_t)size) { + return 0.; } - float dimf = (float)dim; - float df = SDL_floorf(((r - start) * dimf) / size); - return (uint8_t)SDL_clamp(df, 0.0, (float)(dim - 1)); + float f = ((r - start) * dim) / size; + return SDL_clamp(f, -PW_MAX_SAFE_INT, PW_MAX_SAFE_INT); } bool pw_fb_coordinates(struct pw_framebuffer *fb, float wx, float wy, struct pw_coordinates *coords) { if (!fb) { - SDL_InvalidParamError("fb"); - return false; + return SDL_InvalidParamError("fb"); + } + if (!is_normal(wx)) { + return SDL_InvalidParamError("wx"); + } + if (!is_normal(wy)) { + return SDL_InvalidParamError("wy"); + } + if (!coords) { + return SDL_InvalidParamError("coords"); } SDL_Renderer *renderer = SDL_GetRendererFromTexture(fb->texture); @@ -91,6 +97,9 @@ bool pw_fb_coordinates(struct pw_framebuffer *fb, float wx, float wy, if (!SDL_RenderCoordinatesFromWindow(renderer, wx, wy, &rx, &ry)) { return false; } + if (!is_normal(rx) || !is_normal(ry)) { + return SDL_SetError("unreasonable render coordinates"); + } coords->x = project_component(rx, fb->target.x, fb->target.w, PW_FB_WIDTH); coords->y = project_component(ry, fb->target.y, fb->target.h, PW_FB_HEIGHT); @@ -129,8 +138,7 @@ void pw_fb_unlock(struct pw_framebuffer *fb) { bool pw_fb_render(struct pw_framebuffer *fb) { if (!fb) { - SDL_InvalidParamError("fb"); - return false; + return SDL_InvalidParamError("fb"); } SDL_Renderer *renderer = SDL_GetRendererFromTexture(fb->texture); |
