38#define ALLEGRO_UNSTABLE 1
48#include "allegro5/allegro_image.h"
49#include "allegro5/allegro_memfile.h"
62static void expect_eqf(
const char* label,
float got,
float want) {
76static unsigned char*
make_png(
int w,
int h,
size_t* out_len) {
77 ALLEGRO_BITMAP* bmp = NULL;
78 ALLEGRO_FILE* mf = NULL;
79 unsigned char* buf = NULL;
80 size_t cap = 256 * 1024;
83 al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
84 bmp = al_create_bitmap(w, h);
88 al_set_target_bitmap(bmp);
89 al_clear_to_color(al_map_rgb(10, 20, 30));
90 al_set_target_bitmap(NULL);
94 al_destroy_bitmap(bmp);
97 mf = al_open_memfile(buf, (int64_t)cap,
"w");
98 if (!mf || !al_save_bitmap_f(mf,
".png", bmp)) {
102 al_destroy_bitmap(bmp);
108 al_destroy_bitmap(bmp);
113 (*out_len) = (size_t)n;
119 unsigned char* png = NULL;
121 float sx = 0.0f, sy = 0.0f, sw = 0.0f, sh = 0.0f;
129 al_init_image_addon();
132 expect_true(
"png encoded", png != NULL && png_len > 0);
172 expect_eqf(
"regridded cell w = 32", sw, 32.0f);
177 expect_true(
"destroy nulls the handle", atlas == NULL);
186 printf(
"ex_atlas: all checks passed\n");
static void expect_eqf(const char *label, float got, float want)
static unsigned char * make_png(int w, int h, size_t *out_len)
static void expect_true(const char *label, int cond)
int n_atlas_max_bitmap_size(void)
get the largest bitmap dimension this display can hold
int n_atlas_set_page(N_ATLAS *atlas, size_t page, const void *bytes, size_t len, const char *ext, uint16_t cols, uint16_t rows)
decode bytes into one atlas page
void n_atlas_destroy(N_ATLAS **atlas)
destroy an atlas and every bitmap it owns
int n_atlas_page_ready(const N_ATLAS *atlas, size_t page)
test whether a page holds a usable bitmap
int n_atlas_cell_rect(const N_ATLAS *atlas, size_t page, size_t index, float *sx, float *sy, float *sw, float *sh)
compute the source rectangle of one cell
N_ATLAS * new_n_atlas(size_t npages)
allocate an atlas holding npages empty pages
a set of atlas pages addressed as (page, cell index)
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_ERR
error conditions
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL ).
#define LOG_INFO
informational
Multi-page sprite atlas: random-access cell blitting from a grid.
Common headers and low-level functions & define.