Adiciona tipo imagem (core) + tinyblocks-ppm e previa de imagem no balao

This commit is contained in:
mguinhos committed 2026-10-20 21:04:41 -03:00
1 parent f794d8b8c7
commit 959a4027c3
16 files changed
+721 -10

No files matched your search

+41
View File
@@ -320,6 +320,47 @@ static void sdl2_execute(SDL_Renderer* ren,
SDL_RenderSetClipRect(ren, NULL);
break;
case TB_DRAW_IMAGE:
if (cmd->image) {
int iw = tb_image_width(cmd->image);
int ih = tb_image_height(cmd->image);
int ch = tb_image_channels(cmd->image);
const uint8_t* px = tb_image_data_const(cmd->image);
if (iw > 0 && ih > 0 && px) {
SDL_Surface* surf = NULL;
uint8_t* tmp = NULL;
if (ch == 4) {
surf = SDL_CreateRGBSurfaceWithFormatFrom((void*)px, iw, ih, 32, iw*4,
SDL_PIXELFORMAT_RGBA32);
} else if (ch == 3) {
surf = SDL_CreateRGBSurfaceWithFormatFrom((void*)px, iw, ih, 24, iw*3,
SDL_PIXELFORMAT_RGB24);
} else if (ch == 1) {
tmp = (uint8_t*)malloc((size_t)iw * (size_t)ih * 4);
if (tmp) {
size_t n = (size_t)iw * (size_t)ih;
for (size_t k = 0; k < n; k++) {
tmp[k*4+0] = tmp[k*4+1] = tmp[k*4+2] = px[k];
tmp[k*4+3] = 255;
}
surf = SDL_CreateRGBSurfaceWithFormatFrom(tmp, iw, ih, 32, iw*4,
SDL_PIXELFORMAT_RGBA32);
}
}
if (surf) {
SDL_Texture* tex = SDL_CreateTextureFromSurface(ren, surf);
if (tex) {
SDL_Rect dst = {(int)cmd->x, (int)cmd->y, (int)cmd->w, (int)cmd->h};
SDL_RenderCopy(ren, tex, NULL, &dst);
SDL_DestroyTexture(tex);
}
SDL_FreeSurface(surf);
}
free(tmp);
}
}
break;
case TB_DRAW_TEXT:
if (cmd->text[0]) {
TTF_Font* font = get_font((int)cmd->font_size);