From d75bd4850b55bfa6851559ea471e15ac28ba0efa Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Sun, 7 Jan 2024 02:21:17 +0000 Subject: [PATCH] Define datatypes and functions for working with an image sequence --- include/img_seq.h | 17 +++++++++++++++++ src/img_seq.c | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 include/img_seq.h create mode 100644 src/img_seq.c diff --git a/include/img_seq.h b/include/img_seq.h new file mode 100644 index 0000000..2920ee8 --- /dev/null +++ b/include/img_seq.h @@ -0,0 +1,17 @@ +#ifndef IMG_SEQ_H +#define IMG_SEQ_H + +#include "SDL_render.h" +#include "aliases/aliases.h" + +typedef struct { + u64 pos; + u64 length; + SDL_Texture *frames[]; +} img_seq_t; + +img_seq_t *create_sequence(u64 frame_count); +SDL_Texture *current_frame(img_seq_t *seq); +void next_frame(img_seq_t *seq); + +#endif // !IMG_SEQ_H diff --git a/src/img_seq.c b/src/img_seq.c new file mode 100644 index 0000000..896c8fa --- /dev/null +++ b/src/img_seq.c @@ -0,0 +1,17 @@ +#include "img_seq.h" +#include "aliases/aliases.h" + +img_seq_t *create_sequence(u64 frame_count) { + return (img_seq_t *)malloc( + (sizeof(img_seq_t) + frame_count * sizeof(SDL_Texture *))); +} + +SDL_Texture *current_frame(img_seq_t *seq) { return seq->frames[seq->pos]; } + +void next_frame(img_seq_t *seq) { + ++(seq->pos); + + if (seq->pos >= seq->length) { + seq->pos = 0; + } +}