defocus-modules/include/defocus/image.h

63 lines
1.5 KiB
C
Raw Normal View History

#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
*/
df_result df_create_image(int w, int h, df_image **out_image);
/** @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
*/
df_result df_load_image(const char *path, int *out_w, int *out_h, df_image **out_image);
/** @brief Write an image to a PNG file
* @param img the image
* @param path the path
*/
df_result df_write_image(df_image *img, const char *path);
/** @brief Free an image.
*
* Any pointer to the image will be invalid after this.
* @param img the image
*/
void df_release_image(df_image *img);
/** @brief Returns the dimensions of the image */
void df_get_image_size(const df_image *image, int *w, int *h);
/** @brief Returns the color value at pixel coordinates x, y
*
* Returns black for coordinates outside the image.
*/
df_color df_get_image_pixel(const df_image *image, int x, int y);
/** @brief Set the color value at pixel coordinates x, y.
*
* Does nothing for coordinates outside the image.
*/
void df_set_image_pixel(df_image *image, int x, int y, df_color c);
#endif