TinyRaytracer 0.1
A simple C++ raytracer
Loading...
Searching...
No Matches
libpng.h
1
7#ifndef _PNG_H
8#define _PNG_H
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14#include <stdint.h>
15
23typedef union {
24 uint8_t p[4];
25 struct { uint8_t r, g, b, a; };
26 struct { uint8_t red, green, blue, alpha; };
27} pixel_t;
28
33typedef struct {
34 uint32_t height, width;
35 pixel_t *rgba;
36} image_t;
37
38
39
53image_t *load_image(const char *filename);
54
63void save_image(image_t *img, const char *filename);
64
81image_t *new_image(uint32_t width, uint32_t height);
82
86void free_image(image_t *img);
87
88
89#ifdef __cplusplus
90} // end extern "C"
91#endif
92
93
94
95#ifdef __cplusplus
114class Image {
115 public:
117 Image(uint32_t width, uint32_t height) : data(new_image(width, height)) {}
122 Image(const char *filename) : data(load_image(filename)) { }
123
124 Image() : data(nullptr) {}
126 ~Image() { if(!data) free_image(data);}
127
129 pixel_t* operator[](uint32_t y) { return &(data->rgba[data->width * y]); }
130
132 void save(const char *filename) const {
133 save_image(data, filename);
134 }
135
137 uint32_t width() const { return data->width; }
138
140 uint32_t height() const { return data->height; }
141
142 bool empty() const {return data == nullptr;}
143 private:
144 image_t* data;
145};
146#else
152#define pixel_xy(img,x,y) (img)->rgba[(x) + (y)*(img)->width]
153#endif
154
155#endif
Definition: libpng.h:33
Definition: libpng.h:23