Adiciona tipo imagem (core) + tinyblocks-ppm e previa de imagem no balao
This commit is contained in:
1 parent
f794d8b8c7
commit
959a4027c3
16 files changed
+721
-10
No files matched your search
@@ -28,6 +28,7 @@ typedef struct TinyBlocks_VectorBlock TinyBlocks_VectorBlock;
|
||||
typedef struct TinyBlocks_VectorData TinyBlocks_VectorData;
|
||||
typedef struct TinyBlocks_RenderableBlock TinyBlocks_RenderableBlock;
|
||||
typedef struct TinyBlocks_JsonValue TinyBlocks_JsonValue;
|
||||
typedef struct TinyBlocks_Image TinyBlocks_Image;
|
||||
|
||||
/* -- Kinds de bloco --- */
|
||||
typedef enum TinyBlocks_BlockKind {
|
||||
@@ -49,6 +50,7 @@ typedef enum TinyBlocks_ValueKind {
|
||||
TB_VALUE_BLOCK = 4, /* referência a qualquer bloco (handle opaco) */
|
||||
TB_VALUE_VECTOR = 5, /* dados de vetor 2D (ref-counted) */
|
||||
TB_VALUE_JSON = 6, /* valor JSON (ref-counted) */
|
||||
TB_VALUE_IMAGE = 7, /* imagem RGBA/cinza (ref-counted) */
|
||||
} TinyBlocks_ValueKind;
|
||||
|
||||
/* -- Valor com tag (flui entre slots) --- */
|
||||
@@ -61,6 +63,7 @@ typedef struct TinyBlocks_Value {
|
||||
TinyBlocks_Block* block; /* ponteiro não-owning */
|
||||
TinyBlocks_VectorData* vector; /* ref-counted (retain/release) */
|
||||
TinyBlocks_JsonValue* json; /* ref-counted (retain/release) */
|
||||
TinyBlocks_Image* image; /* ref-counted (retain/release) */
|
||||
} as;
|
||||
} TinyBlocks_Value;
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* TinyBlocks - tb_image.h
|
||||
* TinyBlocks_Image: mapa de pixels ref-counted que flui como valor entre
|
||||
* blocos (TB_VALUE_IMAGE). Suporta 1 canal (cinza), 3 (RGB) e 4 (RGBA).
|
||||
*/
|
||||
#ifndef TINYBLOCKS_IMAGE_H
|
||||
#define TINYBLOCKS_IMAGE_H
|
||||
|
||||
#include "tb_block.h"
|
||||
|
||||
/* -- Ciclo de vida --- */
|
||||
/* Cria uma imagem w*h com o numero de canais informado (1, 3 ou 4).
|
||||
* Os pixels começam zerados (preto transparente/opaco conforme canais). */
|
||||
TB_API TinyBlocks_Image* tb_image_new(int w, int h, int channels);
|
||||
TB_API void tb_image_retain (TinyBlocks_Image* img);
|
||||
TB_API void tb_image_release(TinyBlocks_Image* img);
|
||||
|
||||
/* Cria uma cópia independente (mesmos pixels). */
|
||||
TB_API TinyBlocks_Image* tb_image_clone(const TinyBlocks_Image* img);
|
||||
|
||||
/* -- Inspeção --- */
|
||||
TB_API int tb_image_width (const TinyBlocks_Image* img);
|
||||
TB_API int tb_image_height (const TinyBlocks_Image* img);
|
||||
TB_API int tb_image_channels(const TinyBlocks_Image* img);
|
||||
TB_API uint8_t* tb_image_data (TinyBlocks_Image* img); /* ponteiro mutável */
|
||||
TB_API const uint8_t* tb_image_data_const(const TinyBlocks_Image* img);
|
||||
|
||||
/* -- Pixels (RGBA sempre; converte de/para o formato de origem) --- */
|
||||
TB_API bool tb_image_set_pixel(TinyBlocks_Image* img, int x, int y,
|
||||
uint8_t r, uint8_t g, uint8_t b, uint8_t a);
|
||||
TB_API bool tb_image_get_pixel(const TinyBlocks_Image* img, int x, int y,
|
||||
uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a);
|
||||
|
||||
/* -- Helpers para TinyBlocks_Value --- */
|
||||
TB_API TinyBlocks_Value tb_value_image (TinyBlocks_Image* img); /* retém ref */
|
||||
TB_API TinyBlocks_Image* tb_value_as_image(TinyBlocks_Value v);
|
||||
|
||||
#endif /* TINYBLOCKS_IMAGE_H */
|
||||
@@ -34,6 +34,7 @@ typedef enum {
|
||||
TB_DRAW_SET_CLIP, /* define rect de clip (coordenadas tela) */
|
||||
TB_DRAW_CLEAR_CLIP, /* remove clip */
|
||||
TB_DRAW_TEXT, /* texto (x,y=baseline-left; font_size em px) */
|
||||
TB_DRAW_IMAGE, /* imagem escalada em (x,y,w,h); ver field image */
|
||||
} TinyBlocks_DrawCmdKind;
|
||||
|
||||
typedef struct {
|
||||
@@ -43,6 +44,7 @@ typedef struct {
|
||||
float param; /* radius (rrect/circle), espessura (linha/stroke) */
|
||||
float font_size; /* tamanho da fonte em pixels (TB_DRAW_TEXT) */
|
||||
char text[128]; /* conteúdo do texto (TB_DRAW_TEXT) */
|
||||
const TinyBlocks_Image* image; /* pixels (TB_DRAW_IMAGE, não-owning) */
|
||||
} TinyBlocks_DrawCmd;
|
||||
|
||||
/* -- RenderableBlock --- */
|
||||
@@ -103,6 +105,13 @@ TB_API void tb_draw_text (TinyBlocks_RenderableBlock* rb,
|
||||
float x, float y, const char* text, float font_size,
|
||||
float r, float g, float b, float a);
|
||||
|
||||
/* Desenha a imagem escalada para o retângulo (x,y,w,h). A imagem é
|
||||
* ref-counted; o comando apenas guarda um ponteiro não-owning, portanto a
|
||||
* imagem precisa continuar viva até o backend renderizar o frame. */
|
||||
TB_API void tb_draw_image (TinyBlocks_RenderableBlock* rb,
|
||||
float x, float y, float w, float h,
|
||||
const TinyBlocks_Image* image);
|
||||
|
||||
/* Mescla src em dst deslocando todas as coordenadas por (dx, dy).
|
||||
Usado pelo editor para incorporar sub-renderables de blocos com on_draw. */
|
||||
TB_API void tb_draw_merge_offset(TinyBlocks_RenderableBlock* dst,
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "tb_real_block.h"
|
||||
#include "tb_vector_block.h"
|
||||
#include "tb_json_block.h"
|
||||
#include "tb_image.h"
|
||||
|
||||
/* -- Runtime --- */
|
||||
struct TinyBlocks {
|
||||
|
||||
Reference in new issue
Block a user