UI: Improved Gray scale Values for Rendered SVG Bitmaps
This PR corrects some mistakes in the conversion between RGBA bitmaps created when rasterizing SVG icons and the monochrome coverage maps when displaying these in a single color. This only occurs when we need a bitmap from an icon for About screen and for dialogs. The bitmap from NanoSVG is already premultiplied so don't do it again. When converting from coverage map to RGBA use map value for all components rather than FFF for colors. When converting to coverage map from RGBA use perceptual grayscale level of color, not just alpha value. Pull Request: https://projects.blender.org/blender/blender/pulls/126192
This commit is contained in:
committed by
Harley Acheson
parent
1c98cdbc52
commit
c3377a3498
@@ -586,7 +586,7 @@ blender::Array<uchar> blf_svg_icon_bitmap(
|
||||
|
||||
*r_width = g->dims[0];
|
||||
*r_height = g->dims[1];
|
||||
blender::Array<uchar> bitmap(g->dims[0] * g->dims[1] * 4, 255);
|
||||
blender::Array<uchar> bitmap(g->dims[0] * g->dims[1] * 4);
|
||||
|
||||
if (g->num_channels == 4) {
|
||||
memcpy(bitmap.data(), g->bitmap, size_t(bitmap.size()));
|
||||
@@ -595,6 +595,9 @@ blender::Array<uchar> blf_svg_icon_bitmap(
|
||||
for (int64_t y = 0; y < int64_t(g->dims[1]); y++) {
|
||||
for (int64_t x = 0; x < int64_t(g->dims[0]); x++) {
|
||||
int64_t offs_in = (y * int64_t(g->pitch)) + x;
|
||||
bitmap[int64_t(offs_in * 4)] = g->bitmap[offs_in];
|
||||
bitmap[int64_t(offs_in * 4 + 1)] = g->bitmap[offs_in];
|
||||
bitmap[int64_t(offs_in * 4 + 2)] = g->bitmap[offs_in];
|
||||
bitmap[int64_t(offs_in * 4 + 3)] = g->bitmap[offs_in];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "BLI_listbase.h"
|
||||
#include "BLI_math_color.h"
|
||||
#include "BLI_rect.h"
|
||||
#include "BLI_string.h"
|
||||
#include "BLI_threads.h"
|
||||
@@ -425,8 +426,8 @@ static GlyphBLF *blf_glyph_cache_add_svg(GlyphCacheBLF *gc, uint charcode, bool
|
||||
for (int64_t x = 0; x < int64_t(g->dims[0]); x++) {
|
||||
int64_t offs_in = (y * int64_t(dest_w) * 4) + (x * 4);
|
||||
int64_t offs_out = (y * int64_t(g->dims[0]) + x);
|
||||
/* Just using the alpha since this is monochrome. */
|
||||
g->bitmap[offs_out] = render_bmp[int64_t(offs_in + 3)];
|
||||
g->bitmap[offs_out] = uchar(float(rgb_to_grayscale_byte(&render_bmp[int64_t(offs_in)])) *
|
||||
(float(render_bmp[int64_t(offs_in + 3)]) / 255.0f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1889,7 +1889,6 @@ ImBuf *UI_icon_alert_imbuf_get(eAlertIcon icon, float size)
|
||||
}
|
||||
ImBuf *ibuf = IMB_allocFromBuffer(bitmap.data(), nullptr, width, height, 4);
|
||||
IMB_flipy(ibuf);
|
||||
IMB_premultiply_alpha(ibuf);
|
||||
return ibuf;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -324,7 +324,6 @@ static uiBlock *wm_block_about_create(bContext *C, ARegion *region, void * /*arg
|
||||
|
||||
if (ibuf) {
|
||||
IMB_flipy(ibuf);
|
||||
IMB_premultiply_alpha(ibuf);
|
||||
|
||||
bTheme *btheme = UI_GetTheme();
|
||||
const uchar *color = btheme->tui.wcol_menu_back.text_sel;
|
||||
|
||||
Reference in New Issue
Block a user