mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-30 09:52:13 +00:00
Initial support for sixel graphics ##cons
This commit is contained in:
parent
4a7a3e2aa0
commit
2ccd118e87
1
doc/images/logo.sixel
Normal file
1
doc/images/logo.sixel
Normal file
@ -0,0 +1 @@
|
||||
Pq"1;1;57;57#0;2;5;3;4#1;2;5;3;4#2;2;7;4;5#3;2;7;5;5#4;2;9;7;7#5;2;9;7;7#6;2;9;7;8#7;2;10;8;8#8;2;11;9;9#9;2;12;10;11#10;2;13;10;11#11;2;13;11;11#12;2;13;11;11#13;2;14;12;13#14;2;14;12;13#15;2;15;13;14#16;2;15;14;14#17;2;16;14;14#18;2;16;15;15#19;2;17;15;16#20;2;17;16;16#21;2;18;17;17#22;2;20;17;18#23;2;20;18;19#24;2;23;21;22#25;2;26;24;25#26;2;26;25;25#27;2;32;31;31#28;2;35;34;34#29;2;36;34;35#30;2;36;35;36#31;2;37;36;36#32;2;37;36;36#33;2;38;36;36#34;2;39;38;38#35;2;40;39;39#36;2;42;41;41#37;2;44;43;44#38;2;45;44;44#39;2;46;45;45#40;2;47;45;45#41;2;46;45;46#42;2;47;45;46#43;2;49;47;47#44;2;51;50;50#45;2;52;51;51#46;2;53;52;52#47;2;55;53;54#48;2;55;54;55#49;2;56;55;55#50;2;58;58;58#51;2;59;58;58#52;2;59;58;58#53;2;63;62;62#54;2;64;63;63#55;2;67;66;66#56;2;68;67;67#57;2;69;68;68#58;2;71;70;71#59;2;75;74;75#60;2;81;80;81#61;2;82;82;82#62;2;86;86;86#63;2;88;87;87#64;2;89;89;89#65;2;89;89;89#66;2;92;91;91#67;2;94;94;94#68;2;94;94;94#69;2;94;94;94#70;2;96;96;96#71;2;97;97;97#72;2;95;98;99#73;2;96;98;99#74;2;97;99;100#75;2;98;98;98#76;2;98;99;100#77;2;100;100;100#77!56~b$#76!56?[-#77!57~-!57~-!4~F!7Bf@@!6Bzz!4~^^NNFFBB@@!5~^^NNFFBBB@!5~$#59!4?_!8?C#3C#15!4?C#19o#27C#44C#66!4?_#37_#4_#12_?OG#11G#0C#75}!9?G#12O??{#56C$#61!4?O#12oGC?_w!6?C#20??G#64!8?O#41O#65G???A#69!6?_#47_#9_!4?G#57?w$#75!4?G#21G#14owwW!4?_www{w!11?__oo#2w#67!8?O#11_#14__oo#64?A$#69!5?C#25C#9?C!6?C#3!15?O#33G#63C#28C#50!10?O#5O#38G#18G#41C$#11!9?C!6?C#70!31?C$#18!10?C!9?C$#28!11?_?O#4G$#23!11?G#34G#22_#7O$#39!11?O#54O#60G#66A$#52!11?C#70?A-#77!4~}{!5w{~!8?vr``#12IE`Q#1!6?C#77Crb`@#11A#12_Q!6?~#57~#77!5~$#67!4?@#13@#14@BBB!4?E!5~!4?GCW]l!6~!4?GK[]l!6~$#32!5?A#9A#26C#22C#36C#6A#43@#35?@#15x#20!5?C?G#9GCO#11_#2!8?r#53G#24G#22CO#16A#48@$#54!6?C#12???@#66A#42?}#18!6?G#46G#37C?A#50_#30@#4!8?G#75r#45C#8G#9CO_@$#62!10?C#19!9?r#17??C#16O#75@#56!12?O#49A#58_$#49!23?O$#67!23?A-#77!11~NN!8?NN~~~}}{{wwooo__!4~}}{{{wwoo__!5~$#70!11?!11_#75_!7?C!5?^!4?@#57@?A!6?N$#22!11?O#12OO!7?O!7?@?A#18C#40G#1?G#20!7?@#9@!5?G#55O$#42!13?N#14O!5^O!9?@@BBN#2F#71!7?A#14?@?BBD#49O$#15!14?N#19!5?N#31?O#69???@#48@#9@!4?C#29?O#15!9?A#12@??AF$#68!28?A#51A#7A#39C#70G#10!13?A#22C#7C#16G$#47!46?C#52?G-#77!57~-!57~-!44~NNN!10~$#76!44?oOo$#73!45?_-#77!28FB!14F@???!10F$#76!28?C!14?E@?E$#73!44?AF#74@$#72!44?C-\
|
@ -69,6 +69,19 @@ static int rgb(int r, int g, int b) {
|
||||
return 16 + (r * 36) + (g * 6) + b;
|
||||
}
|
||||
|
||||
static void render_sixel(PrintfCallback cb_printf, const ut8 *c, const ut8 *d) {
|
||||
int r = (c[0] * 100 / 255);
|
||||
int g = (c[1] * 100 / 255);
|
||||
int b = (c[2] * 100 / 255);
|
||||
cb_printf ("#0;2;%d;%d;%d", r, g, b); // bg is black
|
||||
r = (d[1] * 100 / 255);
|
||||
g = (d[2] * 100 / 255);
|
||||
b = (d[3] * 100 / 255);
|
||||
cb_printf ("#1;2;%d;%d;%d", r, g, b); // fg is color
|
||||
// cb_printf ("#%d!6%c", 1, 0x3f); // 6x6 pixel block
|
||||
cb_printf ("#%d~~~~~~", 1, 0x3f); // 6x6 pixel block
|
||||
}
|
||||
|
||||
static void render_256(PrintfCallback cb_printf, const ut8 *c, const ut8 *d) {
|
||||
cb_printf ("\x1b[%d;5;%dm", 38, rgb (c[0], c[1], c[2]));
|
||||
cb_printf ("\x1b[%d;5;%dm", 48, rgb (d[0], d[1], d[2]));
|
||||
@ -110,6 +123,22 @@ static void render_ascii(PrintfCallback cb_printf, const ut8 *c, const ut8 *d) {
|
||||
static void do_render(Renderer renderer, PrintfCallback cb_printf, const ut8 *buf, int len, int w, int h) {
|
||||
const ut8 *c, *d;
|
||||
int x, y;
|
||||
if (renderer == render_sixel) {
|
||||
cb_printf ("\x1bPq");
|
||||
for (y = 0; y < h; y += 6) {
|
||||
for (x = 0; x < w; x+=3) {
|
||||
c = XY (buf, x, y);
|
||||
d = XY (buf, x, y + 1);
|
||||
if (d + 3 > (buf + len)) {
|
||||
break;
|
||||
}
|
||||
render_sixel (cb_printf, c, d);
|
||||
}
|
||||
cb_printf ("$-");
|
||||
}
|
||||
cb_printf ("\x1b\\\n");
|
||||
return;
|
||||
}
|
||||
for (y = 0; y < h; y += 2) {
|
||||
for (x = 0; x < w; x++) {
|
||||
c = XY (buf, x, y);
|
||||
@ -134,6 +163,8 @@ static Renderer select_renderer(int mode) {
|
||||
return render_ansi;
|
||||
case 'g':
|
||||
return render_greyscale;
|
||||
case 's':
|
||||
return render_sixel;
|
||||
case '2':
|
||||
return render_256;
|
||||
default:
|
||||
@ -142,7 +173,7 @@ static Renderer select_renderer(int mode) {
|
||||
}
|
||||
|
||||
R_API void r_cons_image(const ut8 *buf, int bufsz, int width, int mode) {
|
||||
int height = (bufsz / width) / 3;
|
||||
const int height = (bufsz / width) / 3;
|
||||
Renderer renderer = select_renderer (mode);
|
||||
do_render (renderer, r_cons_printf, buf, bufsz, width, height);
|
||||
}
|
||||
|
@ -7069,6 +7069,9 @@ static int cmd_print(void *data, const char *input) {
|
||||
cmd_printmsg (core, input + 4);
|
||||
} else if (input[2] == '1') {
|
||||
bitimage (core, 1);
|
||||
} else if (input[2] == 's') {
|
||||
int cols = r_config_get_i (core->config, "hex.cols");
|
||||
r_cons_image (core->block, core->blocksize, cols, 's');
|
||||
} else {
|
||||
// TODO: do colormap and palette conversions here
|
||||
int mode = r_config_get_i (core->config, "scr.color")? 0: 'a';
|
||||
|
Loading…
x
Reference in New Issue
Block a user