Entradas convertidas no core: fim dos helpers de conversão repetidos
- tb_block_input_text / _number / _integer / _truthy: a entrada do bloco
já convertida, despachando pela classe do valor. O texto de um valor
que não é texto fica em cache na conexão (sem buffers nos blocos).
- Saída com nome terminado em '?' vira o traço TB_SLOT_BOOLEAN na criação
do tipo (a convenção mora num lugar só; o editor só lê traços).
- Removidas ~35 funções locais (in_text, in_real, in_int, num, as_num,
input_name, value_num, value_truthy, value_to_str, item_text) em 22
libraries e no editor. Inteiros que truncavam (coordenadas de pixel)
continuam truncando; um número ligado a um campo de texto agora vira
texto ("42") em vez de "".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a5e36b3eed
commit
5ffc1741c2
27 files changed
+217
-416
No files matched your search
@@ -79,18 +79,6 @@ TinyBlocks_Image* tb_imglib_scale(const TinyBlocks_Image* img,
|
||||
|
||||
/* -- Helpers de entrada -------------------------------------------------- */
|
||||
|
||||
static const char* in_text(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) {
|
||||
TinyBlocks_Value v = tb_block_get_input(self, rt, i);
|
||||
return (v.kind == TB_VALUE_TEXT && v.as.text) ? v.as.text : "";
|
||||
}
|
||||
static double in_real(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) {
|
||||
TinyBlocks_Value v = tb_block_get_input(self, rt, i);
|
||||
if (v.kind == TB_VALUE_REAL) return v.as.real;
|
||||
if (v.kind == TB_VALUE_INTEGER) return (double)v.as.integer;
|
||||
if (v.kind == TB_VALUE_TEXT && v.as.text) return atof(v.as.text);
|
||||
return 0.0;
|
||||
}
|
||||
static int in_int(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) { return (int)in_real(self, rt, i); }
|
||||
static TinyBlocks_Image* in_img(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t i) {
|
||||
TinyBlocks_Value v = tb_block_get_input(self, rt, i);
|
||||
return v.kind == TB_VALUE_IMAGE ? v.as.image : NULL;
|
||||
@@ -107,11 +95,11 @@ static void out_img(TinyBlocks_Block* self, TinyBlocks_Image* img) {
|
||||
/* -- Blocos -------------------------------------------------------------- */
|
||||
|
||||
static void eval_new(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
int w = in_int(self, rt, 0), h = in_int(self, rt, 1);
|
||||
int w = (int)tb_block_input_number(self, rt, 0, 0), h = (int)tb_block_input_number(self, rt, 1, 0);
|
||||
TinyBlocks_Image* img = tb_image_new(w > 0 ? w : 1, h > 0 ? h : 1, 4);
|
||||
if (!img) { tinyblocks_set_error(rt, "sem memoria"); self->dirty = false; return; }
|
||||
tb_imglib_fill(img, clamp8(in_real(self,rt,2)), clamp8(in_real(self,rt,3)),
|
||||
clamp8(in_real(self,rt,4)), 255);
|
||||
tb_imglib_fill(img, clamp8(tb_block_input_number(self,rt,2, 0)), clamp8(tb_block_input_number(self,rt,3, 0)),
|
||||
clamp8(tb_block_input_number(self,rt,4, 0)), 255);
|
||||
out_img(self, img);
|
||||
}
|
||||
static void eval_width (TinyBlocks_Block* self, TinyBlocks* rt) { tb_block_set_output(self,0,tb_value_integer(tb_image_width (in_img(self,rt,0)))); self->dirty = false; }
|
||||
@@ -119,7 +107,7 @@ static void eval_height(TinyBlocks_Block* self, TinyBlocks* rt) { tb_block_set_o
|
||||
|
||||
static void eval_getpixel(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
uint8_t r=0,g=0,b=0,a=0;
|
||||
tb_image_get_pixel(in_img(self,rt,0), in_int(self,rt,1), in_int(self,rt,2), &r,&g,&b,&a);
|
||||
tb_image_get_pixel(in_img(self,rt,0), (int)tb_block_input_number(self,rt,1, 0), (int)tb_block_input_number(self,rt,2, 0), &r,&g,&b,&a);
|
||||
TinyBlocks_JsonValue* arr = tb_json_array();
|
||||
tb_json_array_push(arr, tb_json_number(r));
|
||||
tb_json_array_push(arr, tb_json_number(g));
|
||||
@@ -131,26 +119,26 @@ static void eval_getpixel(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
}
|
||||
static void eval_setpixel(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
TinyBlocks_Image* img = in_img(self,rt,0);
|
||||
if (img) tb_image_set_pixel(img, in_int(self,rt,1), in_int(self,rt,2),
|
||||
clamp8(in_real(self,rt,3)), clamp8(in_real(self,rt,4)),
|
||||
clamp8(in_real(self,rt,5)), 255);
|
||||
if (img) tb_image_set_pixel(img, (int)tb_block_input_number(self,rt,1, 0), (int)tb_block_input_number(self,rt,2, 0),
|
||||
clamp8(tb_block_input_number(self,rt,3, 0)), clamp8(tb_block_input_number(self,rt,4, 0)),
|
||||
clamp8(tb_block_input_number(self,rt,5, 0)), 255);
|
||||
self->dirty = false;
|
||||
}
|
||||
static void eval_fill(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
tb_imglib_fill(in_img(self,rt,0), clamp8(in_real(self,rt,1)),
|
||||
clamp8(in_real(self,rt,2)), clamp8(in_real(self,rt,3)), 255);
|
||||
tb_imglib_fill(in_img(self,rt,0), clamp8(tb_block_input_number(self,rt,1, 0)),
|
||||
clamp8(tb_block_input_number(self,rt,2, 0)), clamp8(tb_block_input_number(self,rt,3, 0)), 255);
|
||||
self->dirty = false;
|
||||
}
|
||||
static void eval_clone(TinyBlocks_Block* self, TinyBlocks* rt) { out_img(self, tb_image_clone(in_img(self,rt,0))); }
|
||||
static void eval_crop(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
out_img(self, tb_imglib_crop(in_img(self,rt,0), in_int(self,rt,1), in_int(self,rt,2),
|
||||
in_int(self,rt,3), in_int(self,rt,4)));
|
||||
out_img(self, tb_imglib_crop(in_img(self,rt,0), (int)tb_block_input_number(self,rt,1, 0), (int)tb_block_input_number(self,rt,2, 0),
|
||||
(int)tb_block_input_number(self,rt,3, 0), (int)tb_block_input_number(self,rt,4, 0)));
|
||||
}
|
||||
static void eval_scale(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
out_img(self, tb_imglib_scale(in_img(self,rt,0), in_int(self,rt,1), in_int(self,rt,2), true));
|
||||
out_img(self, tb_imglib_scale(in_img(self,rt,0), (int)tb_block_input_number(self,rt,1, 0), (int)tb_block_input_number(self,rt,2, 0), true));
|
||||
}
|
||||
static void eval_load(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
const char* path = in_text(self, rt, 0);
|
||||
const char* path = tb_block_input_text(self, rt, 0);
|
||||
TinyBlocks_Image* img = tb_image_load(path);
|
||||
if (!img) { tinyblocks_set_error(rt, "nao carregou '%s' (formato?)", path); self->dirty = false; return; }
|
||||
/* A imagem carregada ganha nome (nome do arquivo) e numero no armazem,
|
||||
@@ -162,8 +150,8 @@ static void eval_load(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
}
|
||||
static void eval_save(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
TinyBlocks_Image* img = in_img(self,rt,0);
|
||||
if (!img || !tb_image_save(img, in_text(self,rt,1)))
|
||||
tinyblocks_set_error(rt, "nao gravou '%s' (formato?)", in_text(self,rt,1));
|
||||
if (!img || !tb_image_save(img, tb_block_input_text(self,rt,1)))
|
||||
tinyblocks_set_error(rt, "nao gravou '%s' (formato?)", tb_block_input_text(self,rt,1));
|
||||
self->dirty = false;
|
||||
}
|
||||
|
||||
@@ -218,7 +206,7 @@ static TinyBlocks_JsonValue* in_json_list(TinyBlocks_Block* self, TinyBlocks* rt
|
||||
/* "imagem de largura (w) com os pixels (lista)": cada pixel e [r,g,b],
|
||||
[r,g,b,a] ou um numero (cinza); a altura sai do tamanho da lista */
|
||||
static void eval_from_list(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
int w = (int)in_int(self, rt, 0);
|
||||
int w = (int)(int)tb_block_input_number(self, rt, 0, 0);
|
||||
TinyBlocks_JsonValue* list = in_json_list(self, rt, 1);
|
||||
uint32_t n = list ? tb_json_array_length(list) : 0;
|
||||
if (w <= 0 || !n) {
|
||||
@@ -278,7 +266,7 @@ static void eval_gray(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
static void eval_to_text(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
static const char ramp[] = " .:-=+*#%@"; /* claro -> escuro */
|
||||
TinyBlocks_Image* img = in_img(self, rt, 0);
|
||||
int cols = (int)in_int(self, rt, 1);
|
||||
int cols = (int)(int)tb_block_input_number(self, rt, 1, 0);
|
||||
int w = tb_image_width(img), h = tb_image_height(img);
|
||||
if (!img || w <= 0 || h <= 0) { tb_block_set_output(self, 0, tb_value_text("")); self->dirty = false; return; }
|
||||
if (cols <= 0 || cols > w) cols = w;
|
||||
|
||||
Reference in new issue
Block a user