veles
veles copied to clipboard
Change byte display gradient in Hex Edit
Fixes #325.
I was playing with representation color of bytes and @mkow proposed use HSV or HSL and I'm trying change value in HSV and saturation with lightness in HSL:
return QColor::fromHsv(color.hue(), color.saturation(), 40 + byte * (230 - 50) / 256);

return QColor::fromHsl(color.hue(), color.saturation(), 40 + byte * (230 - 50) / 256);

return QColor::fromHsl(color.hue(), 150 + byte * (255 - 200) / 256, 60 + byte * (230 - 50) / 256);

return QColor::fromHsl(color.hue(), 100 + byte * (255 - 200) / 256, 40 + byte * (230 - 50) / 256);

return QColor::fromHsl(color.hue(), 200 + byte * (255 - 200) / 256, 60 + byte * (230 - 50) / 256);

I'm not sure what option choose.
I did some more experiments and it seems that:
- The background for the hex and ASCII columns should be black (this increases contrast, so the low-value bytes are still readable).
- We should disable anti-aliasing for hex and ASCII view (this can be achieved by
font.setStyleStrategy(QFont::NoAntialias)). Not sure if it's a good idea on Ultra-HD displays, so it should be changeable in options. IMO it would be the best to implement this in a separate PR (it should also renamesettings::font()tosettings::fixed_width_font()). - The selection color should be changed, the current one makes selected text unreadable.
- It would be nice to leave the old hex coloring scheme selectable as a non-default option (it's less practical but it looks nice, so maybe some users will prefer it).
- I looked at Hexplorer source code and they use the following expression for their default color scheme:
It looks nice, IMO we should play a bit more with it. The general idea here is to not just interpolate between two colors, but to sum two linear gradients (where one starts in the middle of the scale). If we decide to use this idea we should leave some credit for the original authors (e.g. name this schemeunsigned limit = 127; unsigned brightness = byte > limit ? byte - limit : 0; return QColor(/*r=*/brightness, /*g=*/(byte / 2) + 0x5d, /*b=*/0x3c + brightness);Matrix (Hexplorer-like)).
Some technical remarks:
- The code should be able to handle byte values > 255 well (this strange feature isn't exposed yet in the UI, but it's implemented internally; it's intended for some exotic non 8-bits-per-byte architectures/file formats and possibly a WORD/DWORD/QWORD view mode). We can deal with it later, because it's not a priority now.
Also: the third scheme suggested by @janczer also looks well on the black background with disabled anti-aliasing.