Define datatypes and functions for working with an image sequence

This commit is contained in:
Abdelrahman Said 2024-01-07 02:21:17 +00:00
parent 6c286b65a8
commit d75bd4850b
2 changed files with 34 additions and 0 deletions

17
include/img_seq.h Normal file
View File

@ -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

17
src/img_seq.c Normal file
View File

@ -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;
}
}