6 * Portable Network Graphics (PNG) format
10 FILE_LICENCE ( GPL2_OR_LATER );
14 #include <ipxe/image.h>
16 /** A PNG file signature */
17 struct png_signature {
18 /** Signature bytes */
20 } __attribute__ (( packed ));
22 /** PNG file signature */
23 #define PNG_SIGNATURE { { 0x89, 'P', 'N', 'G', '\r', '\n', 0x1a, '\n' } }
25 /** A PNG chunk header */
26 struct png_chunk_header {
27 /** Length of the chunk (excluding header and footer) */
31 } __attribute__ (( packed ));
33 /** A PNG chunk footer */
34 struct png_chunk_footer {
37 } __attribute__ (( packed ));
39 /** PNG chunk type property bits */
40 enum png_chunk_type_bits {
41 /** Chunk is ancillary */
42 PNG_CHUNK_ANCILLARY = 0x20000000UL,
43 /** Chunk is private */
44 PNG_CHUNK_PRIVATE = 0x00200000UL,
46 PNG_CHUNK_RESERVED = 0x00002000UL,
47 /** Chunk is safe to copy */
48 PNG_CHUNK_SAFE = 0x00000020UL,
52 * Canonicalise PNG chunk type
54 * @v type Raw chunk type
55 * @ret type Canonicalised chunk type (excluding property bits)
57 static inline __attribute__ (( always_inline )) uint32_t
58 png_canonical_type ( uint32_t type ) {
59 return ( type & ~( htonl ( PNG_CHUNK_ANCILLARY | PNG_CHUNK_PRIVATE |
60 PNG_CHUNK_RESERVED | PNG_CHUNK_SAFE ) ) );
64 * Define a canonical PNG chunk type
66 * @v first First letter (in upper case)
67 * @v second Second letter (in upper case)
68 * @v third Third letter (in upper case)
69 * @v fourth Fourth letter (in upper case)
70 * @ret type Canonical chunk type
72 #define PNG_TYPE( first, second, third, fourth ) \
73 ( ( (first) << 24 ) | ( (second) << 16 ) | ( (third) << 8 ) | (fourth) )
75 /** PNG image header chunk type */
76 #define PNG_TYPE_IHDR PNG_TYPE ( 'I', 'H', 'D', 'R' )
78 /** A PNG image header */
79 struct png_image_header {
88 /** Compression method */
92 /** Interlace method */
94 } __attribute__ (( packed ));
96 /** PNG colour type bits */
97 enum png_colour_type {
98 /** Palette is used */
99 PNG_COLOUR_TYPE_PALETTE = 0x01,
100 /** RGB colour is used */
101 PNG_COLOUR_TYPE_RGB = 0x02,
102 /** Alpha channel is used */
103 PNG_COLOUR_TYPE_ALPHA = 0x04,
106 /** PNG colour type mask */
107 #define PNG_COLOUR_TYPE_MASK 0x07
109 /** PNG compression methods */
110 enum png_compression_method {
111 /** DEFLATE compression with 32kB sliding window */
112 PNG_COMPRESSION_DEFLATE = 0x00,
113 /** First unknown compression method */
114 PNG_COMPRESSION_UNKNOWN = 0x01,
117 /** PNG filter methods */
118 enum png_filter_method {
119 /** Adaptive filtering with five basic types */
120 PNG_FILTER_BASIC = 0x00,
121 /** First unknown filter method */
122 PNG_FILTER_UNKNOWN = 0x01,
125 /** PNG interlace methods */
126 enum png_interlace_method {
127 /** No interlacing */
128 PNG_INTERLACE_NONE = 0x00,
129 /** Adam7 interlacing */
130 PNG_INTERLACE_ADAM7 = 0x01,
131 /** First unknown interlace method */
132 PNG_INTERLACE_UNKNOWN = 0x02,
135 /** PNG palette chunk type */
136 #define PNG_TYPE_PLTE PNG_TYPE ( 'P', 'L', 'T', 'E' )
138 /** A PNG palette entry */
139 struct png_palette_entry {
146 } __attribute__ (( packed ));
148 /** A PNG palette chunk */
150 /** Palette entries */
151 struct png_palette_entry entries[0];
152 } __attribute__ (( packed ));
154 /** Maximum number of PNG palette entries */
155 #define PNG_PALETTE_COUNT 256
157 /** PNG image data chunk type */
158 #define PNG_TYPE_IDAT PNG_TYPE ( 'I', 'D', 'A', 'T' )
160 /** PNG basic filter types */
161 enum png_basic_filter_type {
163 PNG_FILTER_BASIC_NONE = 0,
164 /** Left byte used as predictor */
165 PNG_FILTER_BASIC_SUB = 1,
166 /** Above byte used as predictor */
167 PNG_FILTER_BASIC_UP = 2,
168 /** Above and left bytes used as predictors */
169 PNG_FILTER_BASIC_AVERAGE = 3,
171 PNG_FILTER_BASIC_PAETH = 4,
174 /** PNG image end chunk type */
175 #define PNG_TYPE_IEND PNG_TYPE ( 'I', 'E', 'N', 'D' )
177 extern struct image_type png_image_type __image_type ( PROBE_NORMAL );
179 #endif /* _IPXE_PNG_H */