2023-04-06 18:54:30 +02:00
|
|
|
#ifndef DEFOCUS_IMAGE_H
|
|
|
|
#define DEFOCUS_IMAGE_H
|
|
|
|
|
|
|
|
/** @file image.h
|
|
|
|
* @brief image type and functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "base.h"
|
|
|
|
|
|
|
|
/** @brief Opaque rgba8 image object */
|
|
|
|
typedef struct df_image df_image;
|
|
|
|
|
|
|
|
/** @brief create an image
|
|
|
|
*
|
|
|
|
* The contents of the image will be undefined.
|
|
|
|
* @param w the image width
|
|
|
|
* @param h the image height
|
|
|
|
* @param out_image receives the image object
|
|
|
|
* @return error code
|
|
|
|
*/
|
2023-05-09 13:04:14 +02:00
|
|
|
DF_API df_result df_create_image(int w, int h, df_image **out_image);
|
2023-04-06 18:54:30 +02:00
|
|
|
|
|
|
|
/** @brief load an image file
|
|
|
|
*
|
|
|
|
* The image data will be converted to rgba8
|
|
|
|
*
|
|
|
|
* @param w the image width
|
|
|
|
* @param h the image height
|
|
|
|
* @param out_image receives the image object
|
|
|
|
* @return error code
|
|
|
|
*/
|
2023-05-09 13:04:14 +02:00
|
|
|
DF_API df_result df_load_image(const char *path, int *out_w, int *out_h, df_image **out_image);
|
2023-04-06 18:54:30 +02:00
|
|
|
|
|
|
|
/** @brief Write an image to a PNG file
|
|
|
|
* @param img the image
|
|
|
|
* @param path the path
|
|
|
|
*/
|
2023-05-09 13:04:14 +02:00
|
|
|
DF_API df_result df_write_image(df_image *img, const char *path);
|
2023-04-06 18:54:30 +02:00
|
|
|
|
|
|
|
/** @brief Free an image.
|
|
|
|
*
|
|
|
|
* Any pointer to the image will be invalid after this.
|
|
|
|
* @param img the image
|
|
|
|
*/
|
2023-05-09 13:04:14 +02:00
|
|
|
DF_API void df_release_image(df_image *img);
|
2023-04-06 18:54:30 +02:00
|
|
|
|
|
|
|
/** @brief Returns the dimensions of the image */
|
2023-05-09 13:04:14 +02:00
|
|
|
DF_API void df_get_image_size(const df_image *image, int *w, int *h);
|
2023-04-06 18:54:30 +02:00
|
|
|
|
|
|
|
/** @brief Returns the color value at pixel coordinates x, y
|
|
|
|
*
|
|
|
|
* Returns black for coordinates outside the image.
|
|
|
|
*/
|
2023-05-09 13:04:14 +02:00
|
|
|
DF_API df_color df_get_image_pixel(const df_image *image, int x, int y);
|
2023-04-06 18:54:30 +02:00
|
|
|
|
|
|
|
/** @brief Set the color value at pixel coordinates x, y.
|
|
|
|
*
|
|
|
|
* Does nothing for coordinates outside the image.
|
|
|
|
*/
|
2023-05-09 13:04:14 +02:00
|
|
|
DF_API void df_set_image_pixel(df_image *image, int x, int y, df_color c);
|
2023-04-06 18:54:30 +02:00
|
|
|
|
|
|
|
#endif
|