Commit 025705cb authored by Arnaud Blanchard's avatar Arnaud Blanchard
Browse files

Add functions to create blc_dims

parent 3136afaf
......@@ -33,8 +33,15 @@
typedef struct blc_dim {
size_t length; ///<number of element for the dimension
size_t step; ///< shift in bytes to do to pass from one element of this dimension to the next one
} blc_dim;
START_EXTERN_C
blc_dim *vcreate_blc_dims(size_t *size, uint32_t type, int dims_nb, int length, va_list arguments);
blc_dim *create_blc_dims(size_t *size, uint32_t type, int dims_nb, int length0, ...);
END_EXTERN_C
///Description of a n-dimensional array with type and format
typedef struct blc_array
......@@ -138,10 +145,10 @@ typedef struct blc_array
{
blc_mem mem; ///< raw memory of the array
#endif
blc_dim * dims; ///< array of dimentions of the blc_array
int dims_nb; ///< number of dimension of the blc_array
uint32_t type; ///< type of data in the memory as a unsigned int of 4 bytes. Possibilities are 'UIN8' uchar, 'INT8' char, 'UI16' uint16_t, 'IN16' int16_t, 'UI32' uint32_t, 'IN32' int32_t, 'FL32' float, 'FL64' double
uint32_t format; ///< describes how the data should be interpreted. 'NDEF' (no specification), 'TEXT' for strings, 'Y800' black and white image, 'RGB3' image in RGB, 'LPCM' sound in non compressed format, ...
blc_dim * dims; ///< array of dimentions of the blc_array
int dims_nb; ///< number of dimension of the blc_array
size_t total_length; ///<Total number of elements in the array. This differ of size if an element is bigger than one byte.
} blc_array;
......
......@@ -24,6 +24,35 @@
#include <signal.h> //raise
#include <stdio.h> //fopen
START_EXTERN_C
blc_dim *vcreate_blc_dims(size_t *size, uint32_t type, int dims_nb, int length, va_list arguments){
blc_dim *dim, *dims;
dims=MANY_ALLOCATIONS(dims_nb, blc_dim);
*size=blc_get_type_size(type);
FOR_EACH(dim, dims, dims_nb){
dim->step=*size;
(*size)*=length;
dim->length=length;
length=va_arg(arguments, int);
}
return dims;
}
blc_dim *create_blc_dims(size_t *size, uint32_t type, int dims_nb, int length0, ...){
blc_dim *dims;
va_list arguments;
va_start(arguments, length0);
dims=vcreate_blc_dims(size, type, dims_nb, length0, arguments);
va_end(arguments);
return dims;
}
END_EXTERN_C
blc_array::blc_array():type('NDEF'), format('NDEF'), dims(NULL), dims_nb(0), total_length(0){}
blc_array::blc_array(uint32_t type, uint32_t format, int dims_nb, int length0, ...){
......@@ -40,23 +69,11 @@ blc_array::~blc_array(){
}
void blc_array::vdef_array(uint32_t type, uint32_t format, int dims_nb, int length, va_list arguments){
blc_dim *dim;
total_length=1;
this->dims_nb=dims_nb;
this->type=type;
this->format=format;
dims=MANY_ALLOCATIONS(dims_nb, blc_dim);
size=get_type_size();
FOR_EACH(dim, dims, dims_nb)
{
dim->step=size;
size*=length;
dim->length=length;
length=va_arg(arguments, int);
}
dims=vcreate_blc_dims(&size, type, dims_nb, length, arguments);
total_length=size/get_type_size();
}
......@@ -543,6 +560,10 @@ void blc_array::fprint_surface_uchars(FILE *file, int ansi_terminal){
/* C wrapper */
START_EXTERN_C
void blc_array_def(blc_array *array, uint32_t type, uint32_t format, int dims_nb, int length0, ...){
va_list arguments;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment