From f4b8574728a5b0ac84705cd0213ca306b622eb2c Mon Sep 17 00:00:00 2001 From: Hans-Joerg Schurr Date: Mon, 26 Apr 2021 22:56:57 +0200 Subject: [PATCH] Add API to inspect paths --- src/hvif-light.c | 36 +++++++++++++++++++++++++++++------- src/hvif-light.h | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 7 deletions(-) diff --git a/src/hvif-light.c b/src/hvif-light.c index f595e99..2ab3ac2 100644 --- a/src/hvif-light.c +++ b/src/hvif-light.c @@ -3,6 +3,7 @@ #include #include +#include #ifdef DEBUG void @@ -91,13 +92,6 @@ typedef enum hvif_line_cap #define MATRIX_TRANSLATION(P) \ (hvif_matrix) { 1.0, 0.0, 0.0, 1.0, P.x, P.y } -typedef struct hvif_point hvif_point; -struct hvif_point -{ - float x; - float y; -}; - #define POINT_ORIGIN \ (hvif_point) { 0.0, 0.0 } @@ -843,4 +837,32 @@ hvif_style_transformation( return SUCCESS; } +hvif_status hvif_path_num_points( + hvif_image* image, uint8_t path, uint8_t* points) { + if (image == NULL) return ERROR_PATH; + if (path >= image->num_paths) return ERROR_PATH; + *points = image->paths[path].num_points; + return SUCCESS; +} + +hvif_status hvif_path_closed( + hvif_image* image, uint8_t path, bool* closed) { + if (image == NULL) return ERROR_PATH; + if (path >= image->num_paths) return ERROR_PATH; + *closed = image->paths[path].closed; + return SUCCESS; +} + +hvif_status hvif_path_points( + hvif_image* image, uint8_t path, hvif_point** points) { + if (image == NULL) return ERROR_PATH; + if (path >= image->num_paths) return ERROR_PATH; + size_t total_points = 3 * image->paths[path].num_points; + hvif_point* p = calloc(total_points, sizeof(hvif_point)); + if (!p) return ERROR_NOMEM; + memcpy(p, image->paths[path].points, total_points * sizeof(hvif_point)); + *points = p; + return SUCCESS; +} + #endif /* INTERNAL_DATASTRUCTURES */ diff --git a/src/hvif-light.h b/src/hvif-light.h index 24dbda2..30963b5 100644 --- a/src/hvif-light.h +++ b/src/hvif-light.h @@ -175,6 +175,47 @@ struct hvif_matrix hvif_status hvif_style_transformation( hvif_image* image, uint8_t style, hvif_matrix* transformation); +/** + * \brief Returns the number of poins in a path. + * \param[in] file A valid image. + * \param[in] path The index of the path. + * \param[out] points The number of points. + * \return ERROR_PATH if this path does not exist. + */ +hvif_status hvif_path_num_points( + hvif_image* image, uint8_t path, uint8_t* points); + +/** + * \brief Checks if the path is closed. + * \param[in] file A valid image. + * \param[in] path The index of the path. + * \param[out] closed If the path is a closed path. + * \return ERROR_PATH if this path does not exist. + */ +hvif_status hvif_path_closed( + hvif_image* image, uint8_t path, bool* closed); + +/** \typedef A 2D point. */ +typedef struct hvif_point hvif_point; +struct hvif_point +{ + float x; + float y; +}; + +/** + * \brief Returns a copy of the poins in a path including the control points. + * \param[in] file A valid image. + * \param[in] path The index of the path. + * \param[out] points The points and control points. + * \return ERROR_PATH if this path does not exist. ERROR_NOMEM if points + * list could not be allocated. + * \remark There are two control point per point. Hence the length + * of the array is 3 * num_points. + */ +hvif_status hvif_path_points( + hvif_image* image, uint8_t path, hvif_point** points); + /**@}*/ #endif /* HVIF_LIGHT_H */