stlb: introduce 'byte_order' parameter (for now only little-endian is supported)
This commit is contained in:
parent
e983afe159
commit
4924de91cb
@ -25,7 +25,9 @@ static void foug_stlb_read_facets(foug_stlb_geom_input_t* geom,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int foug_stlb_read(foug_stlb_geom_input_t* geom, foug_transfer_t* trsf)
|
int foug_stlb_read(foug_stlb_geom_input_t* geom,
|
||||||
|
foug_transfer_t* trsf,
|
||||||
|
foug_endianness_t byte_order)
|
||||||
{
|
{
|
||||||
uint32_t total_facet_count;
|
uint32_t total_facet_count;
|
||||||
size_t accum_facet_count_read;
|
size_t accum_facet_count_read;
|
||||||
@ -35,6 +37,8 @@ int foug_stlb_read(foug_stlb_geom_input_t* geom, foug_transfer_t* trsf)
|
|||||||
return FOUG_DATAX_NULL_BUFFER_ERROR;
|
return FOUG_DATAX_NULL_BUFFER_ERROR;
|
||||||
if (trsf->buffer_size < FOUG_STLB_MIN_CONTENTS_SIZE)
|
if (trsf->buffer_size < FOUG_STLB_MIN_CONTENTS_SIZE)
|
||||||
return FOUG_DATAX_INVALID_BUFFER_SIZE_ERROR;
|
return FOUG_DATAX_INVALID_BUFFER_SIZE_ERROR;
|
||||||
|
if (byte_order != FOUG_LITTLE_ENDIAN)
|
||||||
|
return FOUG_STLB_READ_UNSUPPORTED_BYTE_ORDER;
|
||||||
|
|
||||||
/* Read header */
|
/* Read header */
|
||||||
{
|
{
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "stl_global.h"
|
#include "stl_global.h"
|
||||||
#include "stlb_triangle.h"
|
#include "stlb_triangle.h"
|
||||||
|
#include "../endian.h"
|
||||||
#include "../transfer.h"
|
#include "../transfer.h"
|
||||||
|
|
||||||
/* foug_stlb_geom_input */
|
/* foug_stlb_geom_input */
|
||||||
@ -18,10 +19,12 @@ struct foug_stlb_geom_input
|
|||||||
|
|
||||||
/* foug_stlb_read() */
|
/* foug_stlb_read() */
|
||||||
FOUG_DATAX_LIBSTL_EXPORT int foug_stlb_read(foug_stlb_geom_input_t* geom,
|
FOUG_DATAX_LIBSTL_EXPORT int foug_stlb_read(foug_stlb_geom_input_t* geom,
|
||||||
foug_transfer_t* trsf);
|
foug_transfer_t* trsf,
|
||||||
|
foug_endianness_t byte_order);
|
||||||
|
|
||||||
/* Specific error codes returned by foug_stlb_read() */
|
/* Specific error codes returned by foug_stlb_read() */
|
||||||
#define FOUG_STLB_READ_HEADER_WRONG_SIZE_ERROR 1
|
#define FOUG_STLB_READ_HEADER_WRONG_SIZE_ERROR 1
|
||||||
#define FOUG_STLB_READ_FACET_COUNT_ERROR 2
|
#define FOUG_STLB_READ_FACET_COUNT_ERROR 2
|
||||||
|
#define FOUG_STLB_READ_UNSUPPORTED_BYTE_ORDER 3
|
||||||
|
|
||||||
#endif /* FOUG_DATAX_C_LIBSTL_STLB_READ_H */
|
#endif /* FOUG_DATAX_C_LIBSTL_STLB_READ_H */
|
||||||
|
@ -25,7 +25,8 @@ static void foug_stlb_write_facets(const foug_stlb_geom_output_t* geom,
|
|||||||
} /* end for */
|
} /* end for */
|
||||||
}
|
}
|
||||||
|
|
||||||
int foug_stlb_write(const foug_stlb_geom_output_t* geom, foug_transfer_t* trsf)
|
int foug_stlb_write(const foug_stlb_geom_output_t* geom,
|
||||||
|
foug_transfer_t* trsf, foug_endianness_t byte_order)
|
||||||
{
|
{
|
||||||
uint32_t facet_count;
|
uint32_t facet_count;
|
||||||
uint32_t i_facet;
|
uint32_t i_facet;
|
||||||
@ -41,6 +42,8 @@ int foug_stlb_write(const foug_stlb_geom_output_t* geom, foug_transfer_t* trsf)
|
|||||||
return FOUG_STLB_WRITE_NULL_GET_TRIANGLE_COUNT_FUNC;
|
return FOUG_STLB_WRITE_NULL_GET_TRIANGLE_COUNT_FUNC;
|
||||||
if (geom == NULL || geom->get_triangle_func == NULL)
|
if (geom == NULL || geom->get_triangle_func == NULL)
|
||||||
return FOUG_STLB_WRITE_NULL_GET_TRIANGLE_FUNC;
|
return FOUG_STLB_WRITE_NULL_GET_TRIANGLE_FUNC;
|
||||||
|
if (byte_order != FOUG_LITTLE_ENDIAN/* && byte_order != FOUG_BIG_ENDIAN*/)
|
||||||
|
return FOUG_STLB_WRITE_UNSUPPORTED_BYTE_ORDER;
|
||||||
|
|
||||||
/* Write header */
|
/* Write header */
|
||||||
{
|
{
|
||||||
@ -56,7 +59,10 @@ int foug_stlb_write(const foug_stlb_geom_output_t* geom, foug_transfer_t* trsf)
|
|||||||
|
|
||||||
/* Write facet count */
|
/* Write facet count */
|
||||||
facet_count = geom->get_triangle_count_func(geom);
|
facet_count = geom->get_triangle_count_func(geom);
|
||||||
foug_encode_uint32_le(facet_count, trsf->buffer);
|
if (byte_order == FOUG_LITTLE_ENDIAN)
|
||||||
|
foug_encode_uint32_le(facet_count, trsf->buffer);
|
||||||
|
else
|
||||||
|
foug_encode_uint32_be(facet_count, trsf->buffer);
|
||||||
if (foug_stream_write(&trsf->stream, trsf->buffer, sizeof(uint32_t), 1) != 1)
|
if (foug_stream_write(&trsf->stream, trsf->buffer, sizeof(uint32_t), 1) != 1)
|
||||||
return FOUG_DATAX_STREAM_ERROR;
|
return FOUG_DATAX_STREAM_ERROR;
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "stl_global.h"
|
#include "stl_global.h"
|
||||||
#include "stlb_triangle.h"
|
#include "stlb_triangle.h"
|
||||||
|
#include "../endian.h"
|
||||||
#include "../transfer.h"
|
#include "../transfer.h"
|
||||||
|
|
||||||
/* foug_stlb_geom_output */
|
/* foug_stlb_geom_output */
|
||||||
@ -10,17 +11,19 @@ typedef struct foug_stlb_geom_output foug_stlb_geom_output_t;
|
|||||||
struct foug_stlb_geom_output
|
struct foug_stlb_geom_output
|
||||||
{
|
{
|
||||||
void* cookie;
|
void* cookie;
|
||||||
void (*get_header_func) (const foug_stlb_geom_output_t*, uint8_t*);
|
void (*get_header_func) (const foug_stlb_geom_output_t*, uint8_t*); /* Optional */
|
||||||
uint32_t (*get_triangle_count_func)(const foug_stlb_geom_output_t*);
|
uint32_t (*get_triangle_count_func)(const foug_stlb_geom_output_t*);
|
||||||
void (*get_triangle_func) (const foug_stlb_geom_output_t*, uint32_t, foug_stlb_triangle_t*);
|
void (*get_triangle_func) (const foug_stlb_geom_output_t*, uint32_t, foug_stlb_triangle_t*);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* foug_stlb_write() */
|
/* foug_stlb_write() */
|
||||||
FOUG_DATAX_LIBSTL_EXPORT int foug_stlb_write(const foug_stlb_geom_output_t* geom,
|
FOUG_DATAX_LIBSTL_EXPORT int foug_stlb_write(const foug_stlb_geom_output_t* geom,
|
||||||
foug_transfer_t* trsf);
|
foug_transfer_t* trsf,
|
||||||
|
foug_endianness_t byte_order);
|
||||||
|
|
||||||
/* Specific error codes returned by foug_stlb_write() */
|
/* Specific error codes returned by foug_stlb_write() */
|
||||||
#define FOUG_STLB_WRITE_NULL_GET_TRIANGLE_COUNT_FUNC 1
|
#define FOUG_STLB_WRITE_NULL_GET_TRIANGLE_COUNT_FUNC 1
|
||||||
#define FOUG_STLB_WRITE_NULL_GET_TRIANGLE_FUNC 2
|
#define FOUG_STLB_WRITE_NULL_GET_TRIANGLE_FUNC 2
|
||||||
|
#define FOUG_STLB_WRITE_UNSUPPORTED_BYTE_ORDER 3
|
||||||
|
|
||||||
#endif /* FOUG_DATAX_C_LIBSTL_STLB_WRITE_H */
|
#endif /* FOUG_DATAX_C_LIBSTL_STLB_WRITE_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user