Fork 0

68 lines
2.1 KiB

* \file hvif-light.h
* \author Hans-Jörg Schurr
* \brief Parse \a hvif images.
* This library provides functions for parsing Haiku Vector Icon
* files. The parser should be able to parse any files generated by Haiku
* as of April 2020. It is, however, wholly untested and should not be
* used. It most likely contains horrible bugs. During parsing some
* basic checks for consistency of the image data are performed. But
* not everything is checked. For example, paths might be invalid.
#ifndef HVIF_LIGHT_H
#define HVIF_LIGHT_H
#include <stdbool.h>
#include <stdio.h>
/** \typedef The result of parsing an image. */
typedef enum hvif_status
SUCCESS = 0, /**< The image has been parsed into memory. */
ERROR_EOF, /**< The file ended before parsing finished. */
ERROR_NOMEM, /**< Not enough memory could be allocated. */
ERROR_MAGIC, /**< The magic number of the file is wrong. */
ERROR_STYLE, /**< Parsing a style failed. */
ERROR_PATH, /**< Parsing a path failed. */
ERROR_SHAPE /**< Parsing a shape failed. */
} hvif_status;
* \typedef Opaque structure to reference a parsed image.
* An API to inspect the image will be provided later.
typedef struct hvif_image hvif_image;
* \typedef Captures the result of parsing: a status code together with the
* image.
typedef struct hvif_result hvif_result;
struct hvif_result
hvif_status status; /**< Indicates success or an error in parsing. */
hvif_image* image; /**< The image structure. NULL if parsing failed. */
* \brief Parses a \a hvif image from a file.
* \param[in] file A valid file handler.
* \return A `hvif_result` structure. A status other then SUCCESS indicates
* an error. In this case the image is NULL. Otherwise the image needs
* to be freed. A success does not indicate that the image is renderable.
hvif_result hvif_from_file(FILE* file);
* \brief Frees the memory of the image datastructures.
* \param[in] image An image pointer returned by a previous call to
* `hvif_from_file`. Can be NULL.
void hvif_free(hvif_image* image);
#endif /* HVIF_LIGHT_H */