Spreadsheet: display byte colors as scene linear floats

The compression as sRGB is mostly an implementation detail and showing the
integers does not make it clear what the actual values are that will be used
for computations in geometry nodes. This follows the general convention that
colors in Blender are displayed and edited in scene linear floats.

The raw sRGB bytes can still be viewed as a tooltip.

Ref T99205

Differential Revision: https://developer.blender.org/D15322
This commit is contained in:
Brecht Van Lommel 2022-06-29 13:01:38 +02:00
parent 6dd8ceef2a
commit 6b508eb012
Notes: blender-bot 2023-02-14 08:42:53 +01:00
Referenced by issue #99205, Geometry nodes: vertex color read by named attribute node is in sRGB
6 changed files with 38 additions and 36 deletions

View File

@ -298,7 +298,6 @@ static float get_default_column_width(const ColumnValues &values)
return values.default_width;
}
static const float float_width = 3;
static const float int_width = 2;
switch (values.type()) {
case SPREADSHEET_VALUE_TYPE_BOOL:
return 2.0f;
@ -312,13 +311,12 @@ static float get_default_column_width(const ColumnValues &values)
case SPREADSHEET_VALUE_TYPE_FLOAT3:
return 3.0f * float_width;
case SPREADSHEET_VALUE_TYPE_COLOR:
case SPREADSHEET_VALUE_TYPE_BYTE_COLOR:
return 4.0f * float_width;
case SPREADSHEET_VALUE_TYPE_INSTANCES:
return 8.0f;
case SPREADSHEET_VALUE_TYPE_STRING:
return 5.0f;
case SPREADSHEET_VALUE_TYPE_BYTE_COLOR:
return 4.0f * int_width;
case SPREADSHEET_VALUE_TYPE_UNKNOWN:
return 2.0f;
}

View File

@ -19,6 +19,8 @@
#include "BLF_api.h"
#include "BLT_translation.h"
namespace blender::ed::spreadsheet {
class SpreadsheetLayoutDrawer : public SpreadsheetDrawer {
@ -193,7 +195,7 @@ class SpreadsheetLayoutDrawer : public SpreadsheetDrawer {
}
else if (data.type().is<ColorGeometry4b>()) {
const ColorGeometry4b value = data.get<ColorGeometry4b>(real_index);
this->draw_int_vector(params, {value.r, value.g, value.b, value.a});
this->draw_byte_color(params, value);
}
else if (data.type().is<InstanceReference>()) {
const InstanceReference value = data.get<InstanceReference>(real_index);
@ -308,13 +310,16 @@ class SpreadsheetLayoutDrawer : public SpreadsheetDrawer {
}
}
void draw_int_vector(const CellDrawParams &params, const Span<int> values) const
void draw_byte_color(const CellDrawParams &params, const ColorGeometry4b color) const
{
BLI_assert(!values.is_empty());
const ColorGeometry4f float_color = color.decode();
Span<float> values(&float_color.r, 4);
const float segment_width = (float)params.width / values.size();
for (const int i : values.index_range()) {
const int value = values[i];
const std::string value_str = std::to_string(value);
std::stringstream ss;
const float value = values[i];
ss << std::fixed << std::setprecision(3) << value;
const std::string value_str = ss.str();
uiBut *but = uiDefIconTextBut(params.block,
UI_BTYPE_LABEL,
0,
@ -330,9 +335,24 @@ class SpreadsheetLayoutDrawer : public SpreadsheetDrawer {
0,
0,
nullptr);
/* Right-align Ints. */
/* Right-align Floats. */
UI_but_drawflag_disable(but, UI_BUT_TEXT_LEFT);
UI_but_drawflag_enable(but, UI_BUT_TEXT_RIGHT);
/* Tooltip showing raw byte values. Encode values in pointer to avoid memory allocation. */
UI_but_func_tooltip_set(
but,
[](bContext *C, void *argN, const char *UNUSED(tip)) {
const uint32_t uint_color = POINTER_AS_UINT(argN);
ColorGeometry4b color = *(ColorGeometry4b *)&uint_color;
return BLI_sprintfN(TIP_("Byte Color (sRGB encoded):\n%3d %3d %3d %3d"),
color.r,
color.g,
color.b,
color.a);
},
POINTER_FROM_UINT(*(uint32_t *)&color),
nullptr);
}
}

View File

@ -230,7 +230,7 @@ static void apply_row_filter(const SpreadsheetRowFilter &row_filter,
}
}
else if (column_data.type().is<ColorGeometry4b>()) {
const ColorGeometry4b value = row_filter.value_byte_color;
const ColorGeometry4f value = row_filter.value_color;
switch (row_filter.operation) {
case SPREADSHEET_ROW_FILTER_EQUAL: {
const float4 value_floats = {
@ -238,7 +238,8 @@ static void apply_row_filter(const SpreadsheetRowFilter &row_filter,
const float threshold_sq = pow2f(row_filter.threshold);
apply_filter_operation(
column_data.typed<ColorGeometry4b>(),
[&](const ColorGeometry4b cell) {
[&](const ColorGeometry4b cell_bytes) {
const ColorGeometry4f cell = cell_bytes.decode();
const float4 cell_floats = {
(float)cell.r, (float)cell.g, (float)cell.b, (float)cell.a};
return len_squared_v4v4(value_floats, cell_floats) <= threshold_sq;
@ -250,7 +251,8 @@ static void apply_row_filter(const SpreadsheetRowFilter &row_filter,
case SPREADSHEET_ROW_FILTER_GREATER: {
apply_filter_operation(
column_data.typed<ColorGeometry4b>(),
[&](const ColorGeometry4b cell) {
[&](const ColorGeometry4b cell_bytes) {
const ColorGeometry4f cell = cell_bytes.decode();
return cell.r > value.r && cell.g > value.g && cell.b > value.b && cell.a > value.a;
},
prev_mask,
@ -260,7 +262,8 @@ static void apply_row_filter(const SpreadsheetRowFilter &row_filter,
case SPREADSHEET_ROW_FILTER_LESS: {
apply_filter_operation(
column_data.typed<ColorGeometry4b>(),
[&](const ColorGeometry4b cell) {
[&](const ColorGeometry4b cell_bytes) {
const ColorGeometry4f cell = cell_bytes.decode();
return cell.r < value.r && cell.g < value.g && cell.b < value.b && cell.a < value.a;
},
prev_mask,

View File

@ -90,7 +90,8 @@ static std::string value_string(const SpreadsheetRowFilter &row_filter,
return row_filter.value_string;
}
return "";
case SPREADSHEET_VALUE_TYPE_COLOR: {
case SPREADSHEET_VALUE_TYPE_COLOR:
case SPREADSHEET_VALUE_TYPE_BYTE_COLOR: {
std::ostringstream result;
result.precision(3);
result << std::fixed << "(" << row_filter.value_color[0] << ", " << row_filter.value_color[1]
@ -99,14 +100,6 @@ static std::string value_string(const SpreadsheetRowFilter &row_filter,
}
case SPREADSHEET_VALUE_TYPE_STRING:
return row_filter.value_string;
case SPREADSHEET_VALUE_TYPE_BYTE_COLOR: {
std::ostringstream result;
result.precision(3);
result << std::fixed << "(" << (int)row_filter.value_byte_color[0] << ", "
<< (int)row_filter.value_byte_color[1] << ", " << (int)row_filter.value_byte_color[2]
<< ", " << (int)row_filter.value_byte_color[3] << ")";
return result.str();
}
case SPREADSHEET_VALUE_TYPE_UNKNOWN:
return "";
}
@ -233,6 +226,7 @@ static void spreadsheet_filter_panel_draw(const bContext *C, Panel *panel)
uiItemR(layout, filter_ptr, "value_string", 0, IFACE_("Value"), ICON_NONE);
break;
case SPREADSHEET_VALUE_TYPE_COLOR:
case SPREADSHEET_VALUE_TYPE_BYTE_COLOR:
uiItemR(layout, filter_ptr, "operation", 0, nullptr, ICON_NONE);
uiItemR(layout, filter_ptr, "value_color", 0, IFACE_("Value"), ICON_NONE);
if (operation == SPREADSHEET_ROW_FILTER_EQUAL) {
@ -242,13 +236,6 @@ static void spreadsheet_filter_panel_draw(const bContext *C, Panel *panel)
case SPREADSHEET_VALUE_TYPE_STRING:
uiItemR(layout, filter_ptr, "value_string", 0, IFACE_("Value"), ICON_NONE);
break;
case SPREADSHEET_VALUE_TYPE_BYTE_COLOR:
uiItemR(layout, filter_ptr, "operation", 0, nullptr, ICON_NONE);
uiItemR(layout, filter_ptr, "value_byte_color", 0, IFACE_("Value"), ICON_NONE);
if (operation == SPREADSHEET_ROW_FILTER_EQUAL) {
uiItemR(layout, filter_ptr, "threshold", 0, nullptr, ICON_NONE);
}
break;
case SPREADSHEET_VALUE_TYPE_UNKNOWN:
uiItemL(layout, IFACE_("Unknown column type"), ICON_ERROR);
break;

View File

@ -1977,7 +1977,7 @@ typedef struct SpreadsheetRowFilter {
float value_float2[2];
float value_float3[3];
float value_color[4];
uint8_t value_byte_color[4];
char _pad1[4];
} SpreadsheetRowFilter;
typedef enum eSpaceSpreadsheet_RowFilterFlag {

View File

@ -7805,12 +7805,6 @@ static void rna_def_spreadsheet_row_filter(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Color Value", "");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_SPREADSHEET, NULL);
prop = RNA_def_property(srna, "value_byte_color", PROP_INT, PROP_NONE);
RNA_def_property_array(prop, 4);
RNA_def_property_range(prop, 0, 255);
RNA_def_property_ui_text(prop, "Byte Color Value", "");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_SPREADSHEET, NULL);
prop = RNA_def_property(srna, "value_string", PROP_STRING, PROP_NONE);
RNA_def_property_ui_text(prop, "Text Value", "");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_SPREADSHEET, NULL);