aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Rodrigues Lordello <[email protected]>2026-10-12 00:12:59 +0200
committerNicholas Rodrigues Lordello <[email protected]>2026-10-12 00:12:59 +0200
commit88aedb9414800d2e0002430d2d260ea77a60ea8c (patch)
tree8e74e020ee421c1b354ef6d056e93bcf65a76324
parentef58362bfc5df3173de96a6a56d0d3982d5f1ddc (diff)
Fix Minor Scaling Issues
-rw-r--r--src/config.c15
-rw-r--r--src/fb.c4
-rw-r--r--src/picow.c5
-rw-r--r--src/scale.c8
4 files changed, 18 insertions, 14 deletions
diff --git a/src/config.c b/src/config.c
index 56d6bac..d841739 100644
--- a/src/config.c
+++ b/src/config.c
@@ -14,14 +14,14 @@
static void usage(char const *name) {
printf("Usage: %s [-c <carts>] [-S <mode>] [-v[v[v]]]\n"
- " -c <carts> Carts directory. Defaults to 'carts'.\n"
+ " -c <carts> Carts directory.\n"
" -S <mode> Scale mode: 'pp' (default), 'fill' or 'stretch'.\n"
" -v[v[v]] Increasingly verbose logging.\n",
pw_basename(name));
}
static void print_err(char const *name, char const *err) {
- if (err) {
+ if (err && *err) {
fprintf(stderr, "%s: %s\n", pw_basename(name), err);
}
}
@@ -100,8 +100,12 @@ static void parse_config_ini(struct pw_config *config) {
}
pos += n;
- if (SDL_sscanf(line, " %31[^= \t] = %991s", key, value) != 2) {
- SDL_LogWarn(0, "invalid configuation line '%s'", line);
+ if (*line == '#') {
+ continue;
+ }
+
+ if (SDL_sscanf(line, " %31[^= \t] = %991[^\r\n]", key, value) != 2) {
+ SDL_LogWarn(0, "invalid configuration line '%s'", line);
continue;
}
@@ -128,7 +132,7 @@ static void parse_config_ini(struct pw_config *config) {
error:
// We are very permissive with configuration loading, where we just log a
- // warning and continue without propogating an error.
+ // warning and continue without propagating an error.
SDL_LogWarn(0, "failed to read config.ini: %s", SDL_GetError());
SDL_ClearError();
return;
@@ -163,6 +167,7 @@ struct pw_config *pw_config_load(int argc, char **argv) {
#if defined(_POSIX_VERSION)
int c;
+ optind = 1;
while ((c = getopt(argc, argv, ":hc:S:v")) != -1) {
switch (c) {
case 'h':
diff --git a/src/fb.c b/src/fb.c
index 6a82fde..f52f0c0 100644
--- a/src/fb.c
+++ b/src/fb.c
@@ -64,6 +64,10 @@ bool pw_fb_iterate(struct pw_framebuffer *fb) {
static uint8_t project_component(float r, float start, float size,
uint8_t dim) {
+ if (SDL_fabsf(size) < 1.) {
+ 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));
diff --git a/src/picow.c b/src/picow.c
index 79cd0ed..e61607d 100644
--- a/src/picow.c
+++ b/src/picow.c
@@ -61,8 +61,9 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) {
state->config = pw_config_load(argc, argv);
if (!state->config) {
- if (SDL_GetError()) {
- return failf("failed to load configuration");
+ char const *err = SDL_GetError();
+ if (err && *err) {
+ return SDL_APP_FAILURE;
} else {
return SDL_APP_SUCCESS;
}
diff --git a/src/scale.c b/src/scale.c
index da35e63..f435395 100644
--- a/src/scale.c
+++ b/src/scale.c
@@ -1,16 +1,10 @@
#include "scale.h"
-#include "SDL3/SDL_error.h"
-#include "SDL3/SDL_render.h"
-#include "SDL3/SDL_stdinc.h"
static SDL_ScaleMode scale_pixel_perfect(float twf, float thf, int rw, int rh,
SDL_FRect *target) {
int tw = (int)twf;
int th = (int)thf;
int scale = SDL_min(rw / tw, rh / th);
- if (!scale) {
- return SDL_SCALEMODE_INVALID;
- }
int w = scale * tw;
int h = scale * th;
@@ -100,7 +94,7 @@ bool pw_scale(enum pw_scale_mode mode, SDL_Texture *texture,
SDL_FRect t;
SDL_ScaleMode m = scalefn(twf, thf, rw, rh, &t);
- if (m == SDL_SCALEMODE_INVALID || !SDL_SetTextureScaleMode(texture, m)) {
+ if (!SDL_SetTextureScaleMode(texture, m)) {
return false;
}