Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
blaar
blibs
blc_core
Commits
daeae39d
Commit
daeae39d
authored
Nov 22, 2016
by
Arnaud Blanchard
Browse files
Add graph for blc_mem and blc_array
parent
69a10b66
Changes
3
Hide whitespace changes
Inline
Side-by-side
include/blc_array.h
View file @
daeae39d
...
...
@@ -81,7 +81,7 @@ typedef struct blc_array
void
fprint_tsv
(
FILE
*
file
);
void
save_tsv_file
(
char
const
*
filename
);
void
fprint_surface_uchars
(
FILE
*
file
);
void
fprint_surface_uchars
(
FILE
*
file
,
int
ansi_terminal
=
0
);
#else
{
blc_mem
mem
;
...
...
src/blc_array.cpp
View file @
daeae39d
...
...
@@ -25,6 +25,12 @@
#include
<signal.h>
#include
<stdio.h>
//fopen
//This is for graph
static
blc_mem
console_buffer
;
static
char
*
ansi_texts
=
NULL
;
char
*
uchar_bar_colors
=
NULL
;
char
*
file_texts
=
NULL
;
blc_array
::
blc_array
()
:
dims
(
NULL
),
dims_nb
(
0
){}
...
...
@@ -445,31 +451,81 @@ void blc_array::save_tsv_file(char const *filename){
fclose
(
file
);
}
void
blc_array
::
fprint_surface_uchars
(
FILE
*
file
){
static
void
fprint_3Dmatrix
(
FILE
*
file
,
blc_mem
*
mem
,
int
offset
,
int
step0
,
int
length0
,
int
step1
,
int
width
,
int
step2
,
int
height
,
int
ansi_terminal
)
{
char
*
data
;
char
tmp_string
[
8
];
int
color_id
,
previous_color_id
=-
1
;
int
i
,
j
,
k
;
uchar
value
;
int
color_id
;
int
i
,
j
,
width
,
height
;
width
=
dims
[
0
].
length
;
height
=
dims
[
1
].
length
;
FOR
(
j
,
height
)
{
FOR
(
i
,
width
)
{
value
=
uchars
[
j
*
dims
[
1
].
step
+
i
*
dims
[
0
].
step
]
*
100
/
256
;
if
(
value
<
20
)
color_id
=
BLC_BRIGHT_BLUE
;
else
if
(
value
<
35
)
color_id
=
BLC_BLUE
;
else
if
(
value
<
45
)
color_id
=
BLC_GREY
;
else
if
(
value
<
55
)
color_id
=
BLC_WHITE
;
else
if
(
value
<
65
)
color_id
=
BLC_BRIGHT_WHITE
;
else
if
(
value
<
80
)
color_id
=
BLC_RED
;
else
color_id
=
BLC_BRIGHT_RED
;
color_fprintf
(
color_id
,
file
,
"%2d "
,
value
);
/// else fprintf(file, "%2d ", value);
size_t
console_size
;
if
(
ansi_terminal
){
console_size
=
length0
*
width
*
height
*
8
+
height
;
//8 bytes per pixel for colors + return char for each line.
if
(
!
ansi_texts
)
{
ansi_texts
=
MANY_ALLOCATIONS
(
256
*
2
,
char
);
uchar_bar_colors
=
MANY_ALLOCATIONS
(
256
,
char
);
FOR
(
i
,
256
)
{
sprintf
(
tmp_string
,
"%.2d "
,
i
%
100
);
memcpy
(
ansi_texts
+
i
*
2
,
tmp_string
,
2
);
uchar_bar_colors
[
i
]
=
blc_bar_colors
[
i
*
BLC_BAR_COLORS_NB
/
256
];
}
}
fprintf
(
file
,
"
\n
"
);
}
else
console_size
=
length0
*
width
*
height
*
4
+
height
;
//4 bytes per pixel for colors + return char for each line.
console_buffer
.
allocate_min
(
console_size
);
console_size
=
0
;
data
=
mem
->
chars
+
offset
;
FOR
(
j
,
height
){
FOR
(
i
,
width
){
FOR
(
k
,
length0
){
value
=
*
data
;
if
(
ansi_terminal
){
color_id
=
uchar_bar_colors
[
value
];
if
(
color_id
!=
previous_color_id
){
console_buffer
.
chars
[
console_size
++
]
=
27
;
//ESC
console_buffer
.
chars
[
console_size
++
]
=
'['
;
if
(
color_id
&
BLC_BRIGHT
)
{
console_buffer
.
chars
[
console_size
++
]
=
'9'
;
console_buffer
.
chars
[
console_size
++
]
=
color_id
+
40
;
}
else
{
console_buffer
.
chars
[
console_size
++
]
=
'3'
;
console_buffer
.
chars
[
console_size
++
]
=
color_id
+
48
;
}
console_buffer
.
chars
[
console_size
++
]
=
'm'
;
}
console_buffer
.
chars
[
console_size
++
]
=
ansi_texts
[
value
*
2
];
console_buffer
.
chars
[
console_size
++
]
=
ansi_texts
[
value
*
2
+
1
];
// console_buffer.data[console_size++]=' ';
previous_color_id
=
color_id
;
}
else
fprintf
(
file
,
"%3d "
,
value
);
data
+=
step0
;
}
data
+=
step1
-
step0
*
length0
;
}
data
+=
step2
-
step1
*
width
;
if
(
ansi_terminal
){
if
(
j
!=
height
-
1
)
console_buffer
.
chars
[
console_size
++
]
=
'\n'
;
}
else
fprintf
(
file
,
"
\n
"
);
//White line to separate the data
}
fwrite
(
console_buffer
.
data
,
console_size
,
1
,
file
);
fprint_stop_color
(
file
);
fflush
(
file
);
}
void
blc_array
::
fprint_surface_uchars
(
FILE
*
file
,
int
ansi_terminal
){
fprint_3Dmatrix
(
file
,
this
,
0
,
1
,
1
,
dims
[
0
].
step
,
dims
[
0
].
length
,
dims
[
1
].
step
,
dims
[
1
].
length
,
ansi_terminal
);
}
/* C wrapper */
...
...
src/blc_mem.cpp
View file @
daeae39d
...
...
@@ -165,7 +165,7 @@ void blc_mems_fprint_graph_uchars(blc_mem *const*mems, int mems_nb, FILE *file,
}
FOR
(
graph_id
,
mems_nb
){
for
(
i
=
fprintf
(
file
,
"0%%(%d) %s "
,
min
,
abscissa_name
);
i
<
mems
[
graph_id
]
->
size
*
3
;
++
i
)
for
(
i
=
fprintf
(
file
,
"
0%%(%d) %s "
,
min
,
abscissa_name
);
i
<
mems
[
graph_id
]
->
size
*
3
;
++
i
)
fputc
(
'-'
,
file
);
fputc
(
'>'
,
file
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment