stlb_read: remove typedef for function pointers, also simplify hookds
This commit is contained in:
parent
966359881e
commit
7f13b9248f
@ -72,6 +72,7 @@ int foug_stlb_read(foug_stlb_geom_input_t* geom,
|
|||||||
{
|
{
|
||||||
const foug_endianness_t host_byte_order = foug_host_endianness();
|
const foug_endianness_t host_byte_order = foug_host_endianness();
|
||||||
foug_readwrite_helper rparams;
|
foug_readwrite_helper rparams;
|
||||||
|
uint8_t header_data[FOUG_STLB_HEADER_SIZE];
|
||||||
uint32_t total_facet_count = 0; /* Count of facets as declared in the stream */
|
uint32_t total_facet_count = 0; /* Count of facets as declared in the stream */
|
||||||
int error = FOUG_DATAX_NO_ERROR; /* Helper variable to store function result error code */
|
int error = FOUG_DATAX_NO_ERROR; /* Helper variable to store function result error code */
|
||||||
|
|
||||||
@ -86,15 +87,10 @@ int foug_stlb_read(foug_stlb_geom_input_t* geom,
|
|||||||
rparams.fix_endian_func = foug_stlb_triangle_bswap;
|
rparams.fix_endian_func = foug_stlb_triangle_bswap;
|
||||||
|
|
||||||
/* Read header */
|
/* Read header */
|
||||||
|
if (foug_stream_read(&trsf->stream, header_data, 1, FOUG_STLB_HEADER_SIZE)
|
||||||
|
!= FOUG_STLB_HEADER_SIZE)
|
||||||
{
|
{
|
||||||
uint8_t header_data[FOUG_STLB_HEADER_SIZE];
|
return FOUG_STLB_READ_HEADER_WRONG_SIZE_ERROR;
|
||||||
if (foug_stream_read(&trsf->stream, header_data, 1, FOUG_STLB_HEADER_SIZE)
|
|
||||||
!= FOUG_STLB_HEADER_SIZE)
|
|
||||||
{
|
|
||||||
return FOUG_STLB_READ_HEADER_WRONG_SIZE_ERROR;
|
|
||||||
}
|
|
||||||
if (geom != NULL && geom->process_header_func != NULL)
|
|
||||||
geom->process_header_func(geom->cookie, header_data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read facet count */
|
/* Read facet count */
|
||||||
@ -104,17 +100,19 @@ int foug_stlb_read(foug_stlb_geom_input_t* geom,
|
|||||||
memcpy(&total_facet_count, trsf->buffer, sizeof(uint32_t));
|
memcpy(&total_facet_count, trsf->buffer, sizeof(uint32_t));
|
||||||
if (host_byte_order != byte_order)
|
if (host_byte_order != byte_order)
|
||||||
total_facet_count = foug_uint32_bswap(total_facet_count);
|
total_facet_count = foug_uint32_bswap(total_facet_count);
|
||||||
|
|
||||||
|
/* Callback to notify triangle count and header data */
|
||||||
if (geom != NULL && geom->begin_triangles_func != NULL)
|
if (geom != NULL && geom->begin_triangles_func != NULL)
|
||||||
geom->begin_triangles_func(geom->cookie, total_facet_count);
|
geom->begin_triangles_func(geom->cookie, total_facet_count, header_data);
|
||||||
|
|
||||||
/* Read triangles */
|
/* Read triangles */
|
||||||
while (foug_datax_no_error(error)
|
while (foug_datax_no_error(error)
|
||||||
&& rparams.i_facet_offset < total_facet_count)
|
&& rparams.i_facet_offset < total_facet_count)
|
||||||
{
|
{
|
||||||
rparams.facet_count = foug_stream_read(&trsf->stream,
|
rparams.facet_count = foug_stream_read(&trsf->stream,
|
||||||
trsf->buffer,
|
trsf->buffer,
|
||||||
FOUG_STLB_TRIANGLE_RAWSIZE,
|
FOUG_STLB_TRIANGLE_RAWSIZE,
|
||||||
trsf->buffer_size / FOUG_STLB_TRIANGLE_RAWSIZE);
|
trsf->buffer_size / FOUG_STLB_TRIANGLE_RAWSIZE);
|
||||||
if (foug_stream_error(&trsf->stream) != 0)
|
if (foug_stream_error(&trsf->stream) != 0)
|
||||||
error = FOUG_DATAX_STREAM_ERROR;
|
error = FOUG_DATAX_STREAM_ERROR;
|
||||||
else if (rparams.facet_count > 0)
|
else if (rparams.facet_count > 0)
|
||||||
|
@ -11,13 +11,10 @@ typedef struct
|
|||||||
{
|
{
|
||||||
void* cookie;
|
void* cookie;
|
||||||
/* All function pointers can be safely set to NULL */
|
/* All function pointers can be safely set to NULL */
|
||||||
void (*process_header_func) (void*, const uint8_t*);
|
void (*begin_triangles_func) (void*, uint32_t, const uint8_t*);
|
||||||
void (*begin_triangles_func) (void*, uint32_t);
|
|
||||||
void (*process_triangle_func)(void*, uint32_t, const foug_stl_triangle_t*, uint16_t);
|
void (*process_triangle_func)(void*, uint32_t, const foug_stl_triangle_t*, uint16_t);
|
||||||
void (*end_triangles_func) (void*);
|
void (*end_triangles_func) (void*);
|
||||||
} foug_stlb_geom_input_t;
|
} foug_stlb_geom_input_t;
|
||||||
typedef void (*foug_stlb_begin_triangles_func_t)(void*, uint32_t);
|
|
||||||
typedef void (*foug_stlb_process_triangle_func_t)(void*, uint32_t, const foug_stl_triangle_t*, uint16_t);
|
|
||||||
|
|
||||||
/* 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,
|
||||||
|
Loading…
Reference in New Issue
Block a user