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