-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.h
73 lines (66 loc) · 1.84 KB
/
types.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef TYPES_H
#define TYPES_H
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <libmng.h>
#include <png.h>
#if (CHAR_BIT != 8)
# error "8-bit bytes are required."
#endif
typedef unsigned char byte;
// represents a single pixel.
// it is an array with predefined indices instead of a structure with named
// fields due to the fact that the actual order (in memory) of structure fields
// is not defined.
typedef byte pixel[4];
enum px_index {
PX_RED = 0,
PX_GREEN = 1,
PX_BLUE = 2,
PX_ALPHA = 3,
};
// information defining the structure of the file e.g. its resolution.
// normally obtained before reading pixel data.
struct metadata {
size_t height;
size_t width;
};
// structure holding all data necessary to reconstruct an image.
struct image {
struct metadata md;
pixel **pixel_rows;
};
// data needed to read an MNG file.
struct mngfile {
FILE *fp;
mng_handle mh;
struct image *imgp; // ptr to image to be written to.
// ticks starts at 0 and only increments to a value that libmng asks for
// to draw the next frame since we're "reading" frames instead of
// actually displaying them.
mng_uint32 ticks;
// metadata might want to be obtained a second time, but the
// processheader() callback is only called once and thus can only fill a
// single metadata object.
// this is circumvented by caching the metadata and just assigning this
// value to any requested memory location.
struct metadata cached_md;
// libmng has a separate function mng_display_resume() to be called
// after you've started displaying with mng_display() for some reason.
// this flag tells the file which function to call.
bool has_started_displaying : 1;
bool is_eof : 1;
};
enum mngf_retcode {
MNGF_OK,
MNGF_ERR,
MNGF_EOF,
};
// data needed to write a PNG file.
struct pngfile {
FILE *fp;
png_structp write_ptr;
png_infop info_ptr;
};
#endif