This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository legacy-imlib2.

View the commit online.

commit 3828e440abd4c0f0867baa083f3e08f51862ae2f
Author: NRK <n...@disroot.org>
AuthorDate: Wed Mar 5 19:47:49 2025 +0000

    Y4M Loader: replace fps_{den,num} with frametime_us
    
    also round up when converting from us to ms
---
 src/modules/loaders/loader_y4m.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/modules/loaders/loader_y4m.c b/src/modules/loaders/loader_y4m.c
index 2f4af14..8586e5d 100644
--- a/src/modules/loaders/loader_y4m.c
+++ b/src/modules/loaders/loader_y4m.c
@@ -36,7 +36,7 @@ enum Y4mParseStatus {
 
 typedef struct {
     ptrdiff_t       w, h;
-    ptrdiff_t       fps_num, fps_den;
+    int64_t         frametime_us;       /* frametime in micro-seconds */
     enum {
         Y4M_PARSE_CS_UNSUPPORTED = -1,
         Y4M_PARSE_CS_420,       /* default picked from ffmpeg */
@@ -120,14 +120,14 @@ y4m__match(const char *match, ptrdiff_t mlen,
 static enum Y4mParseStatus
 y4m__parse_params(Y4mParse *res, const uint8_t **start, const uint8_t *end)
 {
+    ptrdiff_t       number_of_frames, seconds;
     const uint8_t  *p = *start;
     const uint8_t  *peek;
 
     // default values
     res->range = Y4M_PARSE_RANGE_UNSPECIFIED;
     res->depth = 8;
-    res->fps_num = 1;
-    res->fps_den = 1;
+    res->frametime_us = 1000000;        /* 1 fps */
 
     for (;;)
     {
@@ -144,8 +144,7 @@ y4m__parse_params(Y4mParse *res, const uint8_t **start, const uint8_t *end)
             break;
         case '\n':
             *start = p;
-            if (res->w <= 0 || res->h <= 0 ||
-                res->fps_num <= 0 || res->fps_den <= 0)
+            if (res->w <= 0 || res->h <= 0 || res->frametime_us <= 0)
                 return Y4M_PARSE_CORRUPTED;
             return Y4M_PARSE_OK;
         case 'W':
@@ -157,9 +156,10 @@ y4m__parse_params(Y4mParse *res, const uint8_t **start, const uint8_t *end)
                 return Y4M_PARSE_CORRUPTED;
             break;
         case 'F':
-            if (!y4m__int(&res->fps_num, &p, end) ||
+            if (!y4m__int(&number_of_frames, &p, end) ||
                 !y4m__match(":", 1, &p, end) ||
-                !y4m__int(&res->fps_den, &p, end))
+                !y4m__int(&seconds, &p, end) ||
+                number_of_frames == 0 || seconds == 0)
             {
 #if IMLIB2_DEBUG
                 char            str[1024];
@@ -168,6 +168,8 @@ y4m__parse_params(Y4mParse *res, const uint8_t **start, const uint8_t *end)
 #endif
                 return Y4M_PARSE_CORRUPTED;
             }
+            res->frametime_us =
+                ((int64_t) seconds * 1000000) / number_of_frames;
             break;
         case 'I':
             if (y4m__match("p", 1, &p, end))
@@ -502,7 +504,9 @@ _load(ImlibImage *im, int load_data)
     {
         pf->canvas_w = im->w;
         pf->canvas_h = im->h;
-        pf->frame_delay = (1000 * y4m.fps_den) / y4m.fps_num;
+        pf->frame_delay = y4m.frametime_us / 1000;
+        if (y4m.frametime_us % 1000 >= 500)     /* round up */
+            ++pf->frame_delay;
     }
 
     if (!load_data)

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to