defocus-modules/include/defocus/defocus.h

94 lines
1.9 KiB
C
Raw Normal View History

#ifndef DEFOCUS_H
#define DEFOCUS_H
#include <stdint.h>
#ifdef __cplusplus
#ifdef _MSC_VER
#define DF_API extern "C" __declspec(dllexport)
#else
#define DF_API extern "C"
#endif
#else
#ifdef _MSC_VER
#define DF_API __declspec(dllexport)
#else
#define DF_API
#endif
#endif /* __cplusplus */
#define DF_EPSF32 0.00001f
#define DF_ARRAY_COUNT(A) (sizeof((A)) / sizeof((A)[0]))
/* Images */
typedef unsigned int df_image_handle;
DF_API df_image_handle df_load_image(const char *path, int *w, int *h);
/* Settings for the basic ray tracing function. */
typedef struct
{
/* Width needs to be divisible by 4! */
int image_width;
int image_height;
/* Distance between lense and image plane */
float focal_length;
float lens_radius;
} df_trace_rays_settings;
/* Sphere shape */
typedef struct
{
float center_x;
float center_y;
float center_z;
float radius;
} df_sphere;
typedef struct
{
float base_x;
float base_y;
float base_z;
float normal_x;
float normal_y;
float normal_z;
/* Coordinates on the plane */
float img_p0_x;
float img_p0_y;
float img_p0_z;
2023-06-19 17:29:28 +02:00
float img_w;
float img_h;
/* TODO(Kevin): These could be calculated from p0 and p1... */
float img_ax0_x;
float img_ax0_y;
float img_ax0_z;
float img_ax1_x;
float img_ax1_y;
float img_ax1_z;
df_image_handle image;
} df_plane;
DF_API float df_max_f32(const float *list, unsigned int count);
/* Core function, implements raytracing.
*
* The result buffer receives RGB pixels, with 8 bits per channel stored in RGB order.
* It is allocated via malloc().
*
* Returns 1 on success, 0 if allocating the result image failed.
*/
DF_API int df_trace_rays(df_trace_rays_settings settings, const df_sphere *spheres, unsigned int sphere_count,
const df_plane *planes, unsigned int plane_count, uint8_t **result);
#endif