iPXE
png.h
Go to the documentation of this file.
1 #ifndef _IPXE_PNG_H
2 #define _IPXE_PNG_H
3 
4 /** @file
5  *
6  * Portable Network Graphics (PNG) format
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 #include <stdint.h>
13 #include <byteswap.h>
14 #include <ipxe/image.h>
15 
16 /** A PNG file signature */
17 struct png_signature {
18  /** Signature bytes */
20 } __attribute__ (( packed ));
21 
22 /** PNG file signature */
23 #define PNG_SIGNATURE { { 0x89, 'P', 'N', 'G', '\r', '\n', 0x1a, '\n' } }
24 
25 /** A PNG chunk header */
27  /** Length of the chunk (excluding header and footer) */
29  /** Chunk type */
31 } __attribute__ (( packed ));
32 
33 /** A PNG chunk footer */
35  /** CRC */
37 } __attribute__ (( packed ));
38 
39 /** PNG chunk type property bits */
41  /** Chunk is ancillary */
42  PNG_CHUNK_ANCILLARY = 0x20000000UL,
43  /** Chunk is private */
44  PNG_CHUNK_PRIVATE = 0x00200000UL,
45  /** Reserved */
46  PNG_CHUNK_RESERVED = 0x00002000UL,
47  /** Chunk is safe to copy */
48  PNG_CHUNK_SAFE = 0x00000020UL,
49 };
50 
51 /**
52  * Canonicalise PNG chunk type
53  *
54  * @v type Raw chunk type
55  * @ret type Canonicalised chunk type (excluding property bits)
56  */
57 static inline __attribute__ (( always_inline )) uint32_t
61 }
62 
63 /**
64  * Define a canonical PNG chunk type
65  *
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
71  */
72 #define PNG_TYPE( first, second, third, fourth ) \
73  ( ( (first) << 24 ) | ( (second) << 16 ) | ( (third) << 8 ) | (fourth) )
74 
75 /** PNG image header chunk type */
76 #define PNG_TYPE_IHDR PNG_TYPE ( 'I', 'H', 'D', 'R' )
77 
78 /** A PNG image header */
80  /** Width */
82  /** Height */
84  /** Bit depth */
86  /** Colour type */
88  /** Compression method */
90  /** Filter method */
92  /** Interlace method */
94 } __attribute__ (( packed ));
95 
96 /** PNG colour type bits */
98  /** Palette is used */
100  /** RGB colour is used */
102  /** Alpha channel is used */
104 };
105 
106 /** PNG colour type mask */
107 #define PNG_COLOUR_TYPE_MASK 0x07
108 
109 /** PNG compression methods */
111  /** DEFLATE compression with 32kB sliding window */
113  /** First unknown compression method */
115 };
116 
117 /** PNG filter methods */
119  /** Adaptive filtering with five basic types */
121  /** First unknown filter method */
123 };
124 
125 /** PNG interlace methods */
127  /** No interlacing */
129  /** Adam7 interlacing */
131  /** First unknown interlace method */
133 };
134 
135 /** PNG palette chunk type */
136 #define PNG_TYPE_PLTE PNG_TYPE ( 'P', 'L', 'T', 'E' )
137 
138 /** A PNG palette entry */
140  /** Red */
142  /** Green */
144  /** Blue */
146 } __attribute__ (( packed ));
147 
148 /** A PNG palette chunk */
149 struct png_palette {
150  /** Palette entries */
152 } __attribute__ (( packed ));
153 
154 /** Maximum number of PNG palette entries */
155 #define PNG_PALETTE_COUNT 256
156 
157 /** PNG image data chunk type */
158 #define PNG_TYPE_IDAT PNG_TYPE ( 'I', 'D', 'A', 'T' )
159 
160 /** PNG basic filter types */
162  /** No filtering */
164  /** Left byte used as predictor */
166  /** Above byte used as predictor */
168  /** Above and left bytes used as predictors */
170  /** Paeth filter */
172 };
173 
174 /** PNG image end chunk type */
175 #define PNG_TYPE_IEND PNG_TYPE ( 'I', 'E', 'N', 'D' )
176 
177 extern struct image_type png_image_type __image_type ( PROBE_NORMAL );
178 
179 #endif /* _IPXE_PNG_H */
#define __attribute__(x)
Definition: compiler.h:10
RGB colour is used.
Definition: png.h:101
Chunk is ancillary.
Definition: png.h:42
static uint32_t png_canonical_type(uint32_t type)
Canonicalise PNG chunk type.
Definition: png.h:58
uint32_t height
Height.
Definition: png.h:83
DEFLATE compression with 32kB sliding window.
Definition: png.h:112
uint8_t blue
Blue.
Definition: png.h:145
Alpha channel is used.
Definition: png.h:103
png_chunk_type_bits
PNG chunk type property bits.
Definition: png.h:40
uint32_t width
Width.
Definition: png.h:81
An executable image type.
Definition: image.h:76
#define PROBE_NORMAL
Normal image probe priority.
Definition: image.h:137
uint32_t type
Chunk type.
Definition: png.h:30
No filtering.
Definition: png.h:163
#define htonl(value)
Definition: byteswap.h:133
Above byte used as predictor.
Definition: png.h:167
struct image_type png_image_type __image_type(PROBE_NORMAL)
First unknown filter method.
Definition: png.h:122
A PNG image header.
Definition: png.h:79
Adam7 interlacing.
Definition: png.h:130
struct png_palette_entry entries[0]
Palette entries.
Definition: png.h:151
Executable images.
uint8_t colour_type
Colour type.
Definition: png.h:87
uint32_t len
Length of the chunk (excluding header and footer)
Definition: png.h:28
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
Palette is used.
Definition: png.h:99
Above and left bytes used as predictors.
Definition: png.h:169
Reserved.
Definition: png.h:46
Paeth filter.
Definition: png.h:171
unsigned char uint8_t
Definition: stdint.h:10
A PNG palette chunk.
Definition: png.h:149
unsigned int uint32_t
Definition: stdint.h:12
png_basic_filter_type
PNG basic filter types.
Definition: png.h:161
Left byte used as predictor.
Definition: png.h:165
uint8_t compression
Compression method.
Definition: png.h:89
png_filter_method
PNG filter methods.
Definition: png.h:118
uint32_t type
Operating system type.
Definition: ena.h:12
png_colour_type
PNG colour type bits.
Definition: png.h:97
No interlacing.
Definition: png.h:128
First unknown interlace method.
Definition: png.h:132
First unknown compression method.
Definition: png.h:114
A PNG palette entry.
Definition: png.h:139
uint8_t interlace
Interlace method.
Definition: png.h:93
uint8_t bytes[8]
Signature bytes.
Definition: png.h:19
Adaptive filtering with five basic types.
Definition: png.h:120
uint8_t filter
Filter method.
Definition: png.h:91
png_interlace_method
PNG interlace methods.
Definition: png.h:126
Chunk is private.
Definition: png.h:44
A PNG file signature.
Definition: png.h:17
uint8_t depth
Bit depth.
Definition: png.h:85
A PNG chunk header.
Definition: png.h:26
Chunk is safe to copy.
Definition: png.h:48
uint8_t green
Green.
Definition: png.h:143
uint8_t red
Red.
Definition: png.h:141
png_compression_method
PNG compression methods.
Definition: png.h:110