47 lines
1.7 KiB
C
47 lines
1.7 KiB
C
/*
|
|
* png_test.c - testa tinyblocks-png (libpng): round-trip RGBA e os blocos.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <tinyblocks/tinyblocks.h>
|
|
#include <tb_png.h>
|
|
|
|
static int fails = 0;
|
|
#define CHECK(c, m) do { if (c) printf("ok %s\n", m); else { printf("FAIL %s\n", m); fails++; } } while (0)
|
|
|
|
int main(void) {
|
|
TinyBlocks_Image* img = tb_image_new(4, 4, 4);
|
|
tb_image_set_pixel(img, 0, 0, 255, 0, 0, 255);
|
|
tb_image_set_pixel(img, 3, 3, 0, 128, 255, 255);
|
|
tb_image_set_pixel(img, 2, 1, 0, 255, 0, 128); /* com alpha */
|
|
CHECK(tb_png_save(img, "build/png_test_out.png"), "tb_png_save grava PNG");
|
|
|
|
TinyBlocks_Image* rd = tb_png_load("build/png_test_out.png");
|
|
CHECK(rd && tb_image_width(rd) == 4 && tb_image_height(rd) == 4, "tb_png_load le 4x4");
|
|
if (rd) {
|
|
uint8_t r, g, b, a;
|
|
tb_image_get_pixel(rd, 3, 3, &r, &g, &b, &a);
|
|
CHECK(r == 0 && g == 128 && b == 255 && a == 255, "pixel azul preservado");
|
|
tb_image_get_pixel(rd, 2, 1, &r, &g, &b, &a);
|
|
CHECK(r == 0 && g == 255 && b == 0 && a == 128, "canal alpha preservado");
|
|
}
|
|
remove("build/png_test_out.png");
|
|
if (rd) tb_image_release(rd);
|
|
tb_image_release(img);
|
|
|
|
CHECK(tb_png_load("build/nao_existe.png") == NULL, "load de ausente -> NULL");
|
|
CHECK(strlen(tb_png_last_error()) > 0, "mensagem de erro presente");
|
|
|
|
TinyBlocks* rt;
|
|
tinyblocks_init(&rt, NULL);
|
|
tb_library_register(rt, tb_png_get_library());
|
|
CHECK(tb_rt_find_type(rt, "PNG.Load") && tb_rt_find_type(rt, "PNG.Save"),
|
|
"blocos PNG.Load/Save registrados");
|
|
tinyblocks_deinit(&rt);
|
|
|
|
if (fails) printf("\n%d FALHA(S)\n", fails);
|
|
else printf("\nTUDO OK\n");
|
|
return fails != 0;
|
|
}
|