Improve colors in webui and fix ans256 to rgb

- added fname and fdelimiters in disasm views
- fix r2 ansi256 to rgb conversion
- clean color string, no leading whitespaces, trash anything after color
This commit is contained in:
Alvaro Muñoz 2014-12-10 12:04:30 +01:00 committed by pancake
parent 155997598f
commit db09c38b9d
7 changed files with 87 additions and 70 deletions

View File

@ -81,17 +81,19 @@ struct {
{ NULL, NULL, NULL }
};
static inline ut8 rgbnum (const char ch) {
ut8 r = 0;
r_hex_to_byte (&r, ch);
return r*16;
static inline ut8 rgbnum (const char ch, const char cl) {
ut8 h = 0;
ut8 l = 0;
r_hex_to_byte (&h, ch);
r_hex_to_byte (&l, cl);
return h*16+l;
}
R_API void r_cons_pal_random() {
RCons *cons = r_cons_singleton ();
ut8 r, g, b;
char val[32];
const char *k;
const char *k;
int i;
for (i=0;;i++) {
k = r_cons_pal_get_i (i);
@ -111,31 +113,29 @@ R_API char *r_cons_pal_parse(const char *str) {
int i;
ut8 r, g, b;
char out[128];
char *s = strdup (str);
char *p = strchr (s+1, ' ');
char *s = r_str_trim_head_tail (strdup (str));
r_str_split (s, ' ');
int length = strlen (s);
out[0] = 0;
if (p) *p++ = 0;
if (!strcmp (str, "random")) {
free (s);
return r_cons_color_random (0);
}
if (!strncmp (s, "rgb:", 4)) {
r = rgbnum (s[4]);
g = rgbnum (s[5]);
b = rgbnum (s[6]);
if (length == 7) {
r = rgbnum (s[4],s[4]);
g = rgbnum (s[5],s[5]);
b = rgbnum (s[6],s[6]);
} else if (length == 10) {
r = rgbnum(s[4],s[5]);
g = rgbnum(s[6],s[7]);
b = rgbnum(s[8],s[9]);
}
r_cons_rgb_str (out, r, g, b, 0);
}
if (p && !strncmp (p, "rgb:", 4)) {
r = rgbnum (p[4]);
g = rgbnum (p[5]);
b = rgbnum (p[6]);
r_cons_rgb_str (out+strlen (out), r, g, b, 1);
}
for (i=0; colors[i].name; i++) {
if (!strcmp (s, colors[i].name))
strcat (out, colors[i].code);
if (p && !strcmp (p, colors[i].name))
strcat (out, colors[i].bgcode);
}
free (s);
return *out? strdup (out): NULL;
@ -291,10 +291,10 @@ R_API void r_cons_pal_list (int rad) {
r_cons_rgb_parse (*color, &r, &g, &b, NULL);
rgbstr[0] = 0;
r_cons_rgb_str (rgbstr, r, g, b, 0);
r >>= 4;
g >>= 4;
b >>= 4;
r_cons_printf ("ec %s rgb:%x%x%x\n",
// r >>= 4;
// g >>= 4;
// b >>= 4;
r_cons_printf ("ec %s rgb:%02x%02x%02x\n",
keys[i].name, r, g, b);
break;
default:

View File

@ -4,7 +4,38 @@
#include <r_cons.h>
static void unrgb(int color, int *r, int *g, int *b);
int color_table[256] = { 0 };
int value_range[6] = { 0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff};
static void init_color_table() {
int i, r, g, b;
color_table[0] = 0x000000;
color_table[1] = 0x800000;
color_table[2] = 0x008000;
color_table[3] = 0x808000;
color_table[4] = 0x000080;
color_table[5] = 0x800080;
color_table[6] = 0x008080;
color_table[7] = 0xc0c0c0;
color_table[8] = 0x808080;
color_table[9] = 0xff0000;
color_table[10] = 0x00ff00;
color_table[11] = 0xffff00;
color_table[12] = 0x0000ff;
color_table[13] = 0xff00ff;
color_table[14] = 0x00ffff;
color_table[15] = 0xffffff;
for (i=0; i < 216; i++) {
r = value_range[(i/36) % 6];
g = value_range[(i/6) % 6];
b = value_range[i % 6];
color_table[i + 16] = ((r << 16) & 0xffffff) + ((g << 8) & 0xffff) + (b & 0xff);
}
for (i=0; i < 24; i++) {
r = 8 + (i * 10);
color_table[i + 232] = ((r << 16) & 0xffffff) + ((r << 8) & 0xffff) + (r & 0xff);
}
}
static int gs (int rgb) {
return 232 + (double)rgb/(255/24.1);
@ -15,7 +46,7 @@ static int rgb(int r, int g, int b) {
int grey = 0;
if (r > 0 && r < 255 && r == g && r == b) grey = 1;
if (grey > 0) {
return 232 + (int)r*3/33.0;
return gs(r);
} else {
r = R_DIM (r/k, 0, 6);
g = R_DIM (g/k, 0, 6);
@ -25,29 +56,11 @@ static int rgb(int r, int g, int b) {
}
static void unrgb(int color, int *r, int *g, int *b) {
int rc, gc, bc;
if (color > 16 && color < 232) {
for (rc = 0; rc < 256; rc+=51) {
for (gc = 0; gc < 256; gc+=51) {
for (bc = 0; bc < 256; bc+=51) {
int i = rgb(rc, gc, bc);
if(color == i) {
*r = rc; *g = gc; *b = bc;
return;
}
}
}
}
} else if(color > 231 && color < 256) {
*r = *g = *b = (int)(color - 232)*33.0/3;
return;
}
// const double k = (256.0/6.0);
// int R, G, B;
// color -= 16;
// B = (color/1) & 7; if (b) *b = (B*k); color -= B;
// G = (color/6) & 7; if (g) *g = (G*k); color -= G;
// R = (color/36)& 7; if (r) *r = (R*k); color -= R;
if (color_table[255] == 0) init_color_table();
int rgb = color_table[color];
*r = (rgb >> 16) & 0xff;
*g = (rgb >> 8) & 0xff;
*b = rgb & 0xff;
}
static inline void rgbinit(int r, int g, int b) {

File diff suppressed because one or more lines are too long

View File

@ -137,7 +137,7 @@ function render_graph(x) {
}
var dom = document.createElement('div');
dom.id = "bb_" + addr;
dom.className = "basicblock enyo-selectable ec_background ec_border";
dom.className = "basicblock enyo-selectable ec_gui_background ec_gui_border";
dom.innerHTML = idump;
graph.addVertex(addr, cnt, dom);
if (bb.fail > 0) {
@ -197,7 +197,7 @@ function render_instructions(instructions) {
line.color = r2ui.colors[".ec_flow"];
line.dashed = false;
} else if (ins.type == "cjmp") {
line.color = r2ui.colors[".ec_cflow"];
line.color = r2ui.colors[".ec_gui_cflow"];
line.dashed = true;
}
line.to_start = true;
@ -349,8 +349,11 @@ function html_for_instruction(ins) {
var asm_xrefs = (r2.settings["asm.xrefs"]);
var asm_cmtright = (r2.settings["asm.cmtright"]);
if (ins.offset === "0x"+ins.fcn_addr.toString(16) && r2ui._dis.display == "flat") {
idump += '<div class="ec_flow">; -----------------------------------------------------------</div>';
if (ins.offset === "0x"+ins.fcn_addr.toString(16)) {
if (r2ui._dis.display == "flat") idump += '<div class="ec_flow">; -----------------------------------------------------------</div>';
r2.cmdj("afj " + ins.offset, function(x){
idump += '<div class="ec_fname">(fcn) ' + x[0].name + '</div>';
});
}
if (asm_flags) {
var flags;

View File

@ -2,7 +2,7 @@ enyo.kind ({
name: "Disassembler",
kind: "Scroller",
tag: "div",
classes:"ec_background",
classes:"ec_gui_background",
style:"margin:0px;",
draggable: false,
data: null,
@ -273,12 +273,12 @@ enyo.kind ({
display_graph: function() {
this.display = "graph";
var panel = document.getElementById("radareApp_mp_panels_pageDisassembler");
if (panel !== undefined && panel !== null) panel.className = panel.className.replace("ec_background", "ec_alt_background");
if (panel !== undefined && panel !== null) panel.className = panel.className.replace("ec_gui_background", "ec_gui_alt_background");
},
display_flat: function() {
this.display = "flat";
var panel = document.getElementById("radareApp_mp_panels_pageDisassembler");
if (panel !== undefined && panel !== null) panel.className = panel.className.replace("ec_alt_background", "ec_background");
if (panel !== undefined && panel !== null) panel.className = panel.className.replace("ec_gui_alt_background", "ec_gui_background");
},
less: function() {
var text = this.$.text;
@ -307,7 +307,7 @@ enyo.kind ({
if (this.display === "graph") {
text.setContent("");
r2.cmd ("agj " + addr, function(x) {
text.setContent("<div id='bb_canvas' class='bbcanvas enyo-selectable ec_background'></div>");
text.setContent("<div id='bb_canvas' class='bbcanvas enyo-selectable ec_gui_background'></div>");
// If render fails (address does not belong to function) then switch to flat view
if (render_graph(x) === false) error = true;
});
@ -316,7 +316,7 @@ enyo.kind ({
if (this.display === "flat") {
this.min = this.max = 0;
r2.get_disasm_before_after(addr, -0.5*this.block, this.block, function(x) {
text.setContent("<div id='flat_canvas' class='flatcanvas enyo-selectable ec_background'></div>");
text.setContent("<div id='flat_canvas' class='flatcanvas enyo-selectable ec_gui_background'></div>");
render_instructions(x);
});
}

View File

@ -19,11 +19,12 @@ r2ui.load_colors = function () {
for (var j in myrules) {
if (myrules[j].selectorText !== undefined && myrules[j].selectorText !== null) {
if (myrules[j].selectorText.toLowerCase().indexOf(".ec_") === 0) {
var sel = myrules[j].selectorText.toLowerCase().replace("gui.","gui_");
var sel = myrules[j].selectorText; //.toLowerCase().replace("gui.","gui_");
var color = r2ui.colors[sel];
if (color !== undefined && color !== null) {
if (sel == ".ec_gui_background" || sel == ".ec_gui_alt_background") myrules[j].style.backgroundColor = color;
else if (sel == ".ec_border") myrules[j].style.borderColor = color;
if (sel == ".ec_gui_background" || sel == ".ec_gui_alt_background") {
myrules[j].style.backgroundColor = color;
} else if (sel == ".ec_border") myrules[j].style.borderColor = color;
else myrules[j].style.color = color;
} else {
if (sel == ".ec_gui_background" || sel == ".ec_gui_alt_background") r2ui.colors[sel] = myrules[j].style.backgroundColor;

View File

@ -19,7 +19,7 @@ DisasmPanel.prototype.seek = function(addr, scroll) {
if (this.display === "graph") {
panel.innerHTML = "";
r2.cmd("agj " + addr, function(x) {
panel.innerHTML = "<div id='bb_canvas' class='bbcanvas enyo-selectable ec_background'></div>";
panel.innerHTML = "<div id='bb_canvas' class='bbcanvas enyo-selectable ec_gui_background'></div>";
// If render fails (address does not belong to function) then switch to flat view
if (render_graph(x) === false) error = true;
});
@ -28,7 +28,7 @@ DisasmPanel.prototype.seek = function(addr, scroll) {
if (this.display === "flat") {
this.min = this.max = 0;
r2.get_disasm_before_after(addr, -0.5*this.block, this.block, function(x) {
panel.innerHTML = "<div id='flat_canvas' class='flatcanvas enyo-selectable ec_background'></div>";
panel.innerHTML = "<div id='flat_canvas' class='flatcanvas enyo-selectable ec_gui_background'></div>";
render_instructions(x);
});
}
@ -41,19 +41,19 @@ DisasmPanel.prototype.seek = function(addr, scroll) {
};
DisasmPanel.prototype.display_graph = function() {
this.display = "graph";
$("#main_panel").removeClass("ec_background");
$("#main_panel").addClass("ec_alt_background");
$("#main_panel").removeClass("ec_gui_background");
$("#main_panel").addClass("ec_gui_alt_background");
};
DisasmPanel.prototype.display_flat = function() {
this.display = "flat";
$("#main_panel").removeClass("ec_alt_background");
$("#main_panel").addClass("ec_background");
$("#main_panel").removeClass("ec_gui_alt_background");
$("#main_panel").addClass("ec_gui_background");
};
DisasmPanel.prototype.goToAddress = function() {
if (this.renaming === null && this.selected !== null && (this.selected.className.indexOf(" addr ") > -1)) {
var address = get_address_from_class(this.selected);
if (this.selected.className.indexOf("ec_dataoffset") > -1) {
if (this.selected.className.indexOf("ec_gui_dataoffset") > -1) {
// address is located in not executable memory, switching to hex view
r2ui.openpage(address, 2);
return;