Define datatypes and functions for working with an image sequence
This commit is contained in:
parent
6c286b65a8
commit
d75bd4850b
17
include/img_seq.h
Normal file
17
include/img_seq.h
Normal 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
17
src/img_seq.c
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user