Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/blender/blenkernel/BKE_icons.h5
-rw-r--r--source/blender/blenkernel/intern/icons.c4
-rw-r--r--source/blender/blenkernel/intern/icons_rasterize.c14
-rw-r--r--source/blender/editors/interface/interface_icons.c11
4 files changed, 29 insertions, 5 deletions
diff --git a/source/blender/blenkernel/BKE_icons.h b/source/blender/blenkernel/BKE_icons.h
index 417591e03c5..27d7f45e480 100644
--- a/source/blender/blenkernel/BKE_icons.h
+++ b/source/blender/blenkernel/BKE_icons.h
@@ -62,8 +62,8 @@ struct Icon_Geom {
int icon_id;
int coords_len;
int coords_range[2];
- const unsigned char (*coords)[2];
- const unsigned char (*colors)[4];
+ unsigned char (*coords)[2];
+ unsigned char (*colors)[4];
/* when not NULL, the memory of coords and colors is a sub-region of this pointer. */
const void *mem;
};
@@ -160,6 +160,7 @@ struct Icon_Geom *BKE_icon_geom_from_file(const char *filename);
struct ImBuf *BKE_icon_geom_rasterize(const struct Icon_Geom *geom,
const unsigned int size_x,
const unsigned int size_y);
+void BKE_icon_geom_invert_lightness(struct Icon_Geom *geom);
int BKE_icon_ensure_studio_light(struct StudioLight *sl, int id_type);
diff --git a/source/blender/blenkernel/intern/icons.c b/source/blender/blenkernel/intern/icons.c
index 7b8a0a8894f..6363a23de6c 100644
--- a/source/blender/blenkernel/intern/icons.c
+++ b/source/blender/blenkernel/intern/icons.c
@@ -842,8 +842,8 @@ struct Icon_Geom *BKE_icon_geom_from_memory(const uchar *data, size_t data_len)
p += 2;
geom->coords_len = coords_len;
- geom->coords = (const void *)p;
- geom->colors = (const void *)(p + (data_len / 3));
+ geom->coords = (void *)p;
+ geom->colors = (void *)(p + (data_len / 3));
geom->icon_id = 0;
geom->mem = data;
return geom;
diff --git a/source/blender/blenkernel/intern/icons_rasterize.c b/source/blender/blenkernel/intern/icons_rasterize.c
index e87180ce732..f731285e029 100644
--- a/source/blender/blenkernel/intern/icons_rasterize.c
+++ b/source/blender/blenkernel/intern/icons_rasterize.c
@@ -139,3 +139,17 @@ ImBuf *BKE_icon_geom_rasterize(const struct Icon_Geom *geom,
IMB_scaleImBuf(ibuf, size_x, size_y);
return ibuf;
}
+
+void BKE_icon_geom_invert_lightness(struct Icon_Geom *geom)
+{
+ const int length = 3 * geom->coords_len;
+
+ for (int i = 0; i < length; i++) {
+ float rgb[3], hsl[3];
+
+ rgb_uchar_to_float(rgb, geom->colors[i]);
+ rgb_to_hsl_v(rgb, hsl);
+ hsl_to_rgb(hsl[0], hsl[1], 1.0f - hsl[2], &rgb[0], &rgb[1], &rgb[2]);
+ rgb_float_to_uchar(geom->colors[i], rgb);
+ }
+}
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index 41606fce915..c1018a67fb3 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -119,6 +119,7 @@ typedef struct DrawInfo {
} vector;
struct {
ImBuf *image_cache;
+ bool inverted;
} geom;
struct {
IconImage *image;
@@ -1833,15 +1834,23 @@ static void icon_draw_size(float x,
}
#endif
+ /* If the theme is light, we will adjust the icon colors. */
+ const bool invert = (rgb_to_grayscale_byte(btheme->tui.wcol_toolbar_item.inner) > 128);
+ const bool geom_inverted = di->data.geom.inverted;
+
/* This could re-generate often if rendered at different sizes in the one interface.
* TODO(campbell): support caching multiple sizes. */
ImBuf *ibuf = di->data.geom.image_cache;
- if ((ibuf == NULL) || (ibuf->x != w) || (ibuf->y != h)) {
+ if ((ibuf == NULL) || (ibuf->x != w) || (ibuf->y != h) || (invert != geom_inverted)) {
if (ibuf) {
IMB_freeImBuf(ibuf);
}
+ if (invert != geom_inverted) {
+ BKE_icon_geom_invert_lightness(icon->obj);
+ }
ibuf = BKE_icon_geom_rasterize(icon->obj, w, h);
di->data.geom.image_cache = ibuf;
+ di->data.geom.inverted = invert;
}
GPU_blend_set_func_separate(