From 8fe3c75339aee016f61af5c62bae6e82ac345471 Mon Sep 17 00:00:00 2001 From: George Sokianos Date: Sat, 5 Feb 2022 13:31:40 +0000 Subject: [PATCH] Fixes on renderer to address wrong colors with opacity smaller than 1 and wrong surface size, like mentioned at #803 issue at lite-xl repo --- .gitignore | 2 ++ src/renderer.c | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 4d202f57..b629c7d4 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,6 @@ LiteXL* lite .config/ *.lha +release_files +*.o diff --git a/src/renderer.c b/src/renderer.c index b0e17f58..43c94b28 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -331,18 +332,28 @@ void ren_draw_rect(RenRect rect, RenColor color) { y2 = y2 > clip.y + clip.height ? clip.y + clip.height : y2; SDL_Surface *surface = renwin_get_surface(&window_renderer); - RenColor *d = (RenColor*) surface->pixels; + uint32_t *d = surface->pixels; + + #ifdef __amigaos4__ + d += x1 + y1 * surface->pitch/sizeof(uint32_t); + int dr = surface->pitch/sizeof(uint32_t) - (x2 - x1); + #else d += x1 + y1 * surface->w; int dr = surface->w - (x2 - x1); - unsigned int translated = SDL_MapRGB(surface->format, color.r, color.g, color.b); + #endif if (color.a == 0xff) { + uint32_t translated = SDL_MapRGB(surface->format, color.r, color.g, color.b); SDL_Rect rect = { x1, y1, x2 - x1, y2 - y1 }; SDL_FillRect(surface, &rect, translated); } else { - RenColor translated_color = (RenColor){ translated & 0xFF, (translated >> 8) & 0xFF, (translated >> 16) & 0xFF, color.a }; + RenColor current_color; + RenColor blended_color; for (int j = y1; j < y2; j++) { - for (int i = x1; i < x2; i++, d++) - *d = blend_pixel(*d, translated_color); + for (int i = x1; i < x2; i++, d++) { + SDL_GetRGB(*d, surface->format, ¤t_color.r, ¤t_color.g, ¤t_color.b); + blended_color = blend_pixel(current_color, color); + *d = SDL_MapRGB(surface->format, blended_color.r, blended_color.g, blended_color.b); + } d += dr; } }