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:
authorMatt Ebb <matt@mke3.net>2010-03-15 05:30:53 +0300
committerMatt Ebb <matt@mke3.net>2010-03-15 05:30:53 +0300
commit72cc38e05d5ab11c4b14161df451e6266725b025 (patch)
tree78580a13ec527fb04614c6e2873b6bcddaf90426 /source/blender/editors/interface/interface_regions.c
parent352754d355590c7e513ca00b5b0aa8cb1800e57c (diff)
Make Hex field in colour picker work in gamma corrected space - means that copying Hex values to
and from other apps like Photoshop works as expected.
Diffstat (limited to 'source/blender/editors/interface/interface_regions.c')
-rw-r--r--source/blender/editors/interface/interface_regions.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c
index bc03be84b65..e29a6703bb8 100644
--- a/source/blender/editors/interface/interface_regions.c
+++ b/source/blender/editors/interface/interface_regions.c
@@ -1568,9 +1568,19 @@ void ui_update_block_buts_rgb(uiBlock *block, float *rgb)
}
else if(strcmp(bt->str, "Hex: ")==0) {
+ float rgb_gamma[3];
char col[16];
- sprintf(col, "%02X%02X%02X", (unsigned int)(rgb[0]*255.0), (unsigned int)(rgb[1]*255.0), (unsigned int)(rgb[2]*255.0));
+ /* Hex code is assumed to be in sRGB space (coming from other applications, web, etc) */
+
+ if (block->color_profile == BLI_PR_NONE) {
+ copy_v3_v3(rgb_gamma, rgb);
+ } else {
+ /* make an sRGB version, for Hex code */
+ linearrgb_to_srgb_v3_v3(rgb_gamma, rgb);
+ }
+
+ sprintf(col, "%02X%02X%02X", (unsigned int)(rgb_gamma[0]*255.0), (unsigned int)(rgb_gamma[1]*255.0), (unsigned int)(rgb_gamma[2]*255.0));
strcpy(bt->poin, col);
}
@@ -1640,6 +1650,12 @@ static void do_hex_rna_cb(bContext *C, void *bt1, void *hexcl)
hex_to_rgb(hexcol, rgb, rgb+1, rgb+2);
+ /* Hex code is assumed to be in sRGB space (coming from other applications, web, etc) */
+ if (but->block->color_profile != BLI_PR_NONE) {
+ /* so we need to linearise it for Blender */
+ srgb_to_linearrgb_v3_v3(rgb, rgb);
+ }
+
ui_update_block_buts_rgb(but->block, rgb);
if(popup)
@@ -1662,6 +1678,13 @@ static void picker_new_hide_reveal(uiBlock *block, short colormode)
/* tag buttons */
for(bt= block->buttons.first; bt; bt= bt->next) {
+ if (bt->type == LABEL) {
+ if( bt->str[1]=='G') {
+ if(colormode==2) bt->flag &= ~UI_HIDDEN;
+ else bt->flag |= UI_HIDDEN;
+ }
+ }
+
if(bt->type==NUMSLI || bt->type==TEX) {
if( bt->str[1]=='e') {
if(colormode==2) bt->flag &= ~UI_HIDDEN;
@@ -1735,16 +1758,21 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR
static char tip[50];
static float hsv[3];
static char hexcol[128];
+ float rgb_gamma[3];
const char *propname = RNA_property_identifier(prop);
width= PICKER_TOTAL_W;
butwidth = width - UI_UNIT_X - 10;
/* existence of profile means storage is in linear colour space, with display correction */
- if (block->color_profile == BLI_PR_NONE)
+ if (block->color_profile == BLI_PR_NONE) {
sprintf(tip, "Value in Display Color Space");
- else
+ copy_v3_v3(rgb_gamma, rgb);
+ } else {
sprintf(tip, "Value in Linear RGB Color Space");
+ /* make an sRGB version, for Hex code */
+ linearrgb_to_srgb_v3_v3(rgb_gamma, rgb);
+ }
RNA_property_float_get_array(ptr, prop, rgb);
rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
@@ -1799,10 +1827,12 @@ static void uiBlockPicker(uiBlock *block, float *rgb, PointerRNA *ptr, PropertyR
uiBlockEndAlign(block);
rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
- sprintf(hexcol, "%02X%02X%02X", (unsigned int)(rgb[0]*255.0), (unsigned int)(rgb[1]*255.0), (unsigned int)(rgb[2]*255.0));
+
+ sprintf(hexcol, "%02X%02X%02X", (unsigned int)(rgb_gamma[0]*255.0), (unsigned int)(rgb_gamma[1]*255.0), (unsigned int)(rgb_gamma[2]*255.0));
bt= uiDefBut(block, TEX, 0, "Hex: ", 0, -60, butwidth, UI_UNIT_Y, hexcol, 0, 8, 0, 0, "Hex triplet for color (#RRGGBB)");
uiButSetFunc(bt, do_hex_rna_cb, bt, hexcol);
+ uiDefBut(block, LABEL, 0, "(Gamma Corrected)", 0, -80, butwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
picker_new_hide_reveal(block, colormode);
}