Add API to inspect paths
This commit is contained in:
parent
50305e7f5e
commit
f4b8574728
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#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 */
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in New Issue