-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlgpng.h
99 lines (87 loc) · 2.12 KB
/
lgpng.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* Copyright (c) 2018 Tristan Le Guern <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef LGPNG_H__
#define LGPNG_H__
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
enum chunktype {
CHUNK_TYPE_IHDR,
CHUNK_TYPE_PLTE,
CHUNK_TYPE_IDAT,
CHUNK_TYPE_IEND,
CHUNK_TYPE_tRNS,
CHUNK_TYPE_cHRM,
CHUNK_TYPE_gAMA,
CHUNK_TYPE_iCCP,
CHUNK_TYPE_sBIT,
CHUNK_TYPE_sRGB,
CHUNK_TYPE_iTXt,
CHUNK_TYPE_tEXt,
CHUNK_TYPE_zTXt,
CHUNK_TYPE_bKGB,
CHUNK_TYPE_hIST,
CHUNK_TYPE_pHYs,
CHUNK_TYPE_sPLT,
CHUNK_TYPE_tIME,
CHUNK_TYPE__MAX,
};
/* IHDR chunk */
enum colourtype {
COLOUR_TYPE_GREYSCALE,
COLOUR_TYPE_FILLER1,
COLOUR_TYPE_TRUECOLOUR,
COLOUR_TYPE_INDEXED,
COLOUR_TYPE_GREYSCALE_ALPHA,
COLOUR_TYPE_FILLER5,
COLOUR_TYPE_TRUECOLOUR_ALPHA,
COLOUR_TYPE__MAX,
};
enum compressiontype {
COMPRESSION_TYPE_DEFLATE,
COMPRESSION_TYPE__MAX,
};
enum filtertype {
FILTER_TYPE_ADAPTIVE,
FILTER_TYPE__MAX,
};
enum interlace_method {
INTERLACE_METHOD_STANDARD,
INTERLACE_METHOD_ADAM7,
INTERLACE_METHOD__MAX,
};
struct IHDR {
uint32_t width;
uint32_t height;
int8_t bitdepth;
int8_t colourtype;
int8_t compression;
int8_t filter;
int8_t interlace;
} __attribute__((packed));
struct rgb8 {
uint8_t red;
uint8_t green;
uint8_t blue;
};
struct PLTE {
size_t entriesz;
struct rgb8 *entries;
};
size_t write_png_sig(uint8_t *);
size_t write_IHDR(uint8_t *, size_t, int, enum colourtype);
size_t write_IEND(uint8_t *);
#endif