README.md 5.21 KB
Newer Older
1
BLC core : Core of Basic Libraries for C/C++ 
Arnaud Blanchard's avatar
Arnaud Blanchard committed
2
============================================
Arnaud Blanchard's avatar
Arnaud Blanchard committed
3

Arnaud Blanchard's avatar
Arnaud Blanchard committed
4
Core functions used by almost all the projects of BLAAR
Arnaud Blanchard's avatar
Arnaud Blanchard committed
5

Arnaud Blanchard's avatar
Arnaud Blanchard committed
6
7
8
9
10
- **[blc_text](include/blc_text.h)** manage ASCII terminals (colors, cursor, sizes)
- **[blc_tools](include/blc_tools.h)** macros and functions to simplify coding and memory management
- **[blc_mem](include/blc_mem.h)** a memory structure (data pointer and size) essentially to manage dynamic memory buffers
- **[blc_array](include/blc_array.h)** a structure to manage n-dimensional arrays. It also manage type and format of the data
- **[blc_realtime](include/blc_realtime.h)** few helpers to use time, POSIX semaphore and pthreads
Arnaud Blanchard's avatar
Arnaud Blanchard committed
11

12
<<<<<<< HEAD
Arnaud Blanchard's avatar
Arnaud Blanchard committed
13
14
15
16
Exemples
========
Text
----
17
=======
Arnaud Blanchard's avatar
Arnaud Blanchard committed
18
19
20
21
22
23
24
25
26
27
Install
=======

This library is installed with any configuration of blaar. However, independently of blaar, you can [manually build the library](INSTALL.md)

Tutorials
=========

Exemple of simple text functions
===============================
28
>>>>>>> d1000141b12042d1facef6cb1eeb175f554d52f6
Arnaud Blanchard's avatar
Arnaud Blanchard committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

```c
 #include "blc_core.h"

 int main(int argc, char **argv){
    int rows_nb, columns_nb;
    float values[3]={1.3, 4.2, 5.5};
 
    color_printf(BLC_BLUE, "\nWriting in blue\n\n");
    underline_printf('=', "Writing with inlining with '='");
//printing 3 floats of the array values
    fprint_tsv_floats(stderr, values, 3);
//Getting the size in characters of the current terminal
    blc_terminal_get_size(&columns_nb, &rows_nb);
    printf("\nSize of the terminal  %dx%d\n", columns_nb, rows_nb);
//Writing size in human readable format
    fprint_human_size(stdout, 1000456670); //1Kb = 1024b
    printf("\n");
    return EXIT_SUCCESS;
 }
```

Arnaud Blanchard's avatar
Arnaud Blanchard committed
51
52
text graphs
-----------
Arnaud Blanchard's avatar
Arnaud Blanchard committed
53

54
<<<<<<< HEAD
Arnaud Blanchard's avatar
Arnaud Blanchard committed
55
![image not found](t_array_1.png)
56
=======
Arnaud Blanchard's avatar
Arnaud Blanchard committed
57
![illustration vector](t_array_1.png)
58
>>>>>>> d1000141b12042d1facef6cb1eeb175f554d52f6
Arnaud Blanchard's avatar
Arnaud Blanchard committed
59

Arnaud Blanchard's avatar
Arnaud Blanchard committed
60
This is the output of **blc_core/t_array** see the [code](t_array/main.cpp) and the [cmake config file](t_array/CMakeLists.txt)
Arnaud Blanchard's avatar
Arnaud Blanchard committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

You can modify the code to dynamically refresh the graph with something like:

```c++
...
//We display 100 times the graph with the sinusoid shifted each time
for(shift =0;  shift <100; shift ++){
   // We set a sinusoid in the vector (converting [-1f, 1f] -> [0, 255]) and we  shift it
   for(i=0; i!=vector.size; i++) vector.uchars[i]=128+127*sinf(i/2.f+ shift);
   //If it is not the first time we erase the previous graph by putting back (ANSI escape code) the cursor 16 lines (height of the graph) up. 'sprint' stand for fprint on stderr
   if (shift != 0) blc_eprint_cursor_up(16); //blc_text.h function
   /*We graph the vector, with title "vector test", the height of 16 chars, the limit max 256 and limit min 0.
   Text on abscissa "position" and text on ordinate "intensity"*/
   vector.fprint_graph_uchars(stderr, "Vector test", 16, 256, 0, "position", "intensity");
   //We stop 100ms to let time to the user to see the graph.
   usleep(100000);
}
...
```
Which produces :
![blc_core sinusoid video](http://www.etis.ensea.fr/neurocyber/blaar/videos/blc_core_sinusoid.mp4)

Manipulating **blc_array** 2D matrix
==============================

86
<<<<<<< HEAD
Arnaud Blanchard's avatar
Arnaud Blanchard committed
87
![image not found](t_array_2.png)
88
=======
Arnaud Blanchard's avatar
Arnaud Blanchard committed
89
![illustration array 2D](t_array_2.png)
90
>>>>>>> d1000141b12042d1facef6cb1eeb175f554d52f6
Arnaud Blanchard's avatar
Arnaud Blanchard committed
91

Arnaud Blanchard's avatar
Arnaud Blanchard committed
92
93
These displays could be dynamical as well

Arnaud Blanchard's avatar
Arnaud Blanchard committed
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
Structures
==========

blc_mem
-------

A blc_mem is a memory with a pointer of an union (i.e. a memory that can be automatically casted) and a size.

    blc_mem mem(8*sizeof(float)); // Allocates 32 bytes for 8 floats
    mem.floats[3]=4.3f; //Allocate the fourth float
    
The possible elements are: 

    void *data; char *chars; uchar *uchars;
    int16_t *ints16; uint16_t *uints16; 
    int32_t *ints32; uint32_t *uints32;
    float *floats; double *doubles;
    
blc_array
---------

This is a blc_mem which contains information about the structure of the data (types, format, dimensions, ...).

The types are a four bytes uint32_t integer representing four ASCII chars ( comparaison are much faster and easier than char[4] ). They are used to allocate the right amount of memory for each element.

    'UIN8': .uchars[i], 'INT8' .chars[i]: 1 byte
    'UI16': .uints16[i], 'IN16' .ints16[i]: 2 bytes
    'UI32': .uints32[i], 'IN32' .ints32[i], 'FL32' .floats[i]: 4 bytes
    'FL64': .doubles[i] : 8 bytes 
    
- **format** describe how to interpret data. They follow the [fourcc](https://www.fourcc.org) convention but you can use your own format.

-
    'NDEF' : not defined (default), 
    'TEXT', 'UTF8' : interpret as strings, 
    'Y800' : black and white image, 'RGB3' image in RGB, 'YUV2',...
    'LPCM' : Linear Pulse Code Modulation, sound in non compressed format, ...

- **dims_nb** represent the type of strutcture: 1 for vector, 2 for matrix, 3 for cubes, ...

- **dims** is an array of **blc_dim** containing the number of elements of each dim (**length**) and the **step** to use to go from one element of the dim to the next one. Usually **step** is the product of the length of the previous dimensions. For example an image 800x600 of 3 components of colors would be:

-
    dims_nb=3;
    dims[0].length=3;
    dims[0].step=1;
    dims[1].length=800;
    dims[1].step=3;
    dims[2].length=600;
    dims[2].step=2400; //1x3x800

For the complete API use `./doc_api.sh blibs/blc_core`    


Arnaud Blanchard's avatar
Arnaud Blanchard committed
148