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
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_SECBOOT ( PERMITTED );
12
13#include <stdint.h>
14#include <byteswap.h>
15#include <ipxe/image.h>
16
17/** A PNG file 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 */
58static inline __attribute__ (( always_inline )) uint32_t
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 */
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
178extern struct image_type png_image_type __image_type ( PROBE_NORMAL );
179
180#endif /* _IPXE_PNG_H */
unsigned int uint32_t
Definition stdint.h:12
unsigned char uint8_t
Definition stdint.h:10
uint32_t type
Operating system type.
Definition ena.h:1
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
Executable images.
#define PROBE_NORMAL
Normal image probe priority.
Definition image.h:156
#define __image_type(probe_order)
An executable image type.
Definition image.h:170
#define htonl(value)
Definition byteswap.h:134
#define __attribute__(x)
Definition compiler.h:10
png_chunk_type_bits
PNG chunk type property bits.
Definition png.h:41
@ PNG_CHUNK_RESERVED
Reserved.
Definition png.h:47
@ PNG_CHUNK_ANCILLARY
Chunk is ancillary.
Definition png.h:43
@ PNG_CHUNK_PRIVATE
Chunk is private.
Definition png.h:45
@ PNG_CHUNK_SAFE
Chunk is safe to copy.
Definition png.h:49
png_filter_method
PNG filter methods.
Definition png.h:119
@ PNG_FILTER_BASIC
Adaptive filtering with five basic types.
Definition png.h:121
@ PNG_FILTER_UNKNOWN
First unknown filter method.
Definition png.h:123
png_interlace_method
PNG interlace methods.
Definition png.h:127
@ PNG_INTERLACE_NONE
No interlacing.
Definition png.h:129
@ PNG_INTERLACE_UNKNOWN
First unknown interlace method.
Definition png.h:133
@ PNG_INTERLACE_ADAM7
Adam7 interlacing.
Definition png.h:131
png_basic_filter_type
PNG basic filter types.
Definition png.h:162
@ PNG_FILTER_BASIC_SUB
Left byte used as predictor.
Definition png.h:166
@ PNG_FILTER_BASIC_UP
Above byte used as predictor.
Definition png.h:168
@ PNG_FILTER_BASIC_PAETH
Paeth filter.
Definition png.h:172
@ PNG_FILTER_BASIC_AVERAGE
Above and left bytes used as predictors.
Definition png.h:170
@ PNG_FILTER_BASIC_NONE
No filtering.
Definition png.h:164
png_colour_type
PNG colour type bits.
Definition png.h:98
@ PNG_COLOUR_TYPE_ALPHA
Alpha channel is used.
Definition png.h:104
@ PNG_COLOUR_TYPE_PALETTE
Palette is used.
Definition png.h:100
@ PNG_COLOUR_TYPE_RGB
RGB colour is used.
Definition png.h:102
png_compression_method
PNG compression methods.
Definition png.h:111
@ PNG_COMPRESSION_UNKNOWN
First unknown compression method.
Definition png.h:115
@ PNG_COMPRESSION_DEFLATE
DEFLATE compression with 32kB sliding window.
Definition png.h:113
static uint32_t png_canonical_type(uint32_t type)
Canonicalise PNG chunk type.
Definition png.h:59
An executable image type.
Definition image.h:95
A PNG chunk header.
Definition png.h:27
uint32_t len
Length of the chunk (excluding header and footer)
Definition png.h:29
uint32_t type
Chunk type.
Definition png.h:31
A PNG image header.
Definition png.h:80
uint8_t filter
Filter method.
Definition png.h:92
uint8_t colour_type
Colour type.
Definition png.h:88
uint8_t depth
Bit depth.
Definition png.h:86
uint8_t compression
Compression method.
Definition png.h:90
uint32_t height
Height.
Definition png.h:84
uint32_t width
Width.
Definition png.h:82
uint8_t interlace
Interlace method.
Definition png.h:94
A PNG palette entry.
Definition png.h:140
uint8_t red
Red.
Definition png.h:142
uint8_t green
Green.
Definition png.h:144
uint8_t blue
Blue.
Definition png.h:146
A PNG palette chunk.
Definition png.h:150
struct png_palette_entry entries[0]
Palette entries.
Definition png.h:152
A PNG file signature.
Definition png.h:18
uint8_t bytes[8]
Signature bytes.
Definition png.h:20