veles icon indicating copy to clipboard operation
veles copied to clipboard

Change byte display gradient in Hex Edit

Open janczer opened this issue 8 years ago • 4 comments

Also I added color picker to option. #255


This change is Reviewable

janczer avatar Sep 14 '17 18:09 janczer

Fixes #325.

mkow avatar Sep 15 '17 13:09 mkow

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);

hsv

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

hsl40-2301

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

hsl_s150-255_v60-2301

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

hsl_s100-255_v40-2301

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

hsl_s200-255_v60-2301

I'm not sure what option choose.

janczer avatar Sep 25 '17 19:09 janczer

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 rename settings::font() to settings::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:
    unsigned limit = 127;
    unsigned brightness = byte > limit ? byte - limit : 0;
    return QColor(/*r=*/brightness, /*g=*/(byte / 2) + 0x5d, /*b=*/0x3c + brightness);
    
    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 scheme 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.

mkow avatar Jan 26 '18 15:01 mkow

Also: the third scheme suggested by @janczer also looks well on the black background with disabled anti-aliasing.

mkow avatar Jan 26 '18 15:01 mkow