Adiciona tinyblocks-bmp e tinyblocks-png (libpng)
This commit is contained in:
1 parent
959a4027c3
commit
fca7aa2f63
11 files changed
+574
-6
No files matched your search
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* bmp_test.c - testa tinyblocks-bmp: round-trip de gravacao/leitura BMP 24 bits
|
||||
* e os blocos BMP.Load / BMP.Save.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
#include <tb_bmp.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)
|
||||
|
||||
static void set_txt(TinyBlocks_Block* b, uint32_t i, const char* s) {
|
||||
TinyBlocks_Value vv = tb_value_text(s);
|
||||
tb_block_set_default(b, i, vv);
|
||||
tb_value_free(&vv);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
TinyBlocks_Image* img = tb_image_new(3, 2, 3);
|
||||
tb_image_set_pixel(img, 0, 0, 255, 0, 0, 255);
|
||||
tb_image_set_pixel(img, 2, 0, 0, 0, 255, 255);
|
||||
tb_image_set_pixel(img, 1, 1, 0, 255, 0, 255);
|
||||
tb_image_set_pixel(img, 2, 1, 255, 255, 255, 255);
|
||||
CHECK(tb_bmp_save(img, "build/bmp_test_out.bmp"), "tb_bmp_save grava");
|
||||
|
||||
TinyBlocks_Image* rd = tb_bmp_load("build/bmp_test_out.bmp");
|
||||
CHECK(rd && tb_image_width(rd) == 3 && tb_image_height(rd) == 2, "tb_bmp_load le 3x2");
|
||||
if (rd) {
|
||||
uint8_t r, g, b, a;
|
||||
tb_image_get_pixel(rd, 2, 1, &r, &g, &b, &a);
|
||||
CHECK(r == 255 && g == 255 && b == 255, "pixel branco preservado");
|
||||
tb_image_get_pixel(rd, 0, 0, &r, &g, &b, &a);
|
||||
CHECK(r == 255 && g == 0 && b == 0, "pixel vermelho preservado");
|
||||
}
|
||||
remove("build/bmp_test_out.bmp");
|
||||
if (rd) tb_image_release(rd);
|
||||
tb_image_release(img);
|
||||
|
||||
CHECK(tb_bmp_load("build/nao_existe.bmp") == NULL, "load de ausente -> NULL");
|
||||
CHECK(strlen(tb_bmp_last_error()) > 0, "mensagem de erro presente");
|
||||
|
||||
/* -- Blocos --- */
|
||||
TinyBlocks* rt;
|
||||
tinyblocks_init(&rt, NULL);
|
||||
tb_library_register(rt, tb_bmp_get_library());
|
||||
CHECK(tb_rt_find_type(rt, "BMP.Load") && tb_rt_find_type(rt, "BMP.Save"),
|
||||
"blocos BMP.Load/Save registrados");
|
||||
|
||||
TinyBlocks_Block* bl = tb_block_create(rt, tb_rt_find_type(rt, "BMP.Load"));
|
||||
set_txt(bl, 0, "build/nao_existe.bmp");
|
||||
tb_block_eval(bl, rt);
|
||||
CHECK(bl->outputs[0].kind == TB_VALUE_NONE, "BMP.Load invalido nao devolve imagem");
|
||||
|
||||
tb_block_destroy(bl, rt);
|
||||
tinyblocks_deinit(&rt);
|
||||
|
||||
if (fails) printf("\n%d FALHA(S)\n", fails);
|
||||
else printf("\nTUDO OK\n");
|
||||
return fails != 0;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
Reference in new issue
Block a user