Sfoglia il codice sorgente

[png] Add support for PNG images

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 anni fa
parent
commit
c6c8078964
7 ha cambiato i file con 3185 aggiunte e 0 eliminazioni
  1. 3
    0
      src/config/config.c
  2. 1
    0
      src/config/general.h
  3. 1007
    0
      src/image/png.c
  4. 1
    0
      src/include/ipxe/errfile.h
  5. 179
    0
      src/include/ipxe/png.h
  6. 1993
    0
      src/tests/png_test.c
  7. 1
    0
      src/tests/tests.c

+ 3
- 0
src/config/config.c Vedi File

@@ -200,6 +200,9 @@ REQUIRE_OBJECT ( sdi );
200 200
 #ifdef IMAGE_PNM
201 201
 REQUIRE_OBJECT ( pnm );
202 202
 #endif
203
+#ifdef IMAGE_PNG
204
+REQUIRE_OBJECT ( png );
205
+#endif
203 206
 
204 207
 /*
205 208
  * Drag in all requested commands

+ 1
- 0
src/config/general.h Vedi File

@@ -104,6 +104,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
104 104
 //#define	IMAGE_EFI		/* EFI image support */
105 105
 //#define	IMAGE_SDI		/* SDI image support */
106 106
 //#define	IMAGE_PNM		/* PNM image support */
107
+//#define	IMAGE_PNG		/* PNG image support */
107 108
 
108 109
 /*
109 110
  * Command-line commands to include

+ 1007
- 0
src/image/png.c
File diff soppresso perché troppo grande
Vedi File


+ 1
- 0
src/include/ipxe/errfile.h Vedi File

@@ -231,6 +231,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
231 231
 #define ERRFILE_efi_image	      ( ERRFILE_IMAGE | 0x00040000 )
232 232
 #define ERRFILE_embedded	      ( ERRFILE_IMAGE | 0x00050000 )
233 233
 #define ERRFILE_pnm		      ( ERRFILE_IMAGE | 0x00060000 )
234
+#define ERRFILE_png		      ( ERRFILE_IMAGE | 0x00070000 )
234 235
 
235 236
 #define ERRFILE_asn1		      ( ERRFILE_OTHER | 0x00000000 )
236 237
 #define ERRFILE_chap		      ( ERRFILE_OTHER | 0x00010000 )

+ 179
- 0
src/include/ipxe/png.h Vedi File

@@ -0,0 +1,179 @@
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 );
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 */
19
+	uint8_t bytes[8];
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 */
26
+struct png_chunk_header {
27
+	/** Length of the chunk (excluding header and footer) */
28
+	uint32_t len;
29
+	/** Chunk type */
30
+	uint32_t type;
31
+} __attribute__ (( packed ));
32
+
33
+/** A PNG chunk footer */
34
+struct png_chunk_footer {
35
+	/** CRC */
36
+	uint32_t crc;
37
+} __attribute__ (( packed ));
38
+
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,
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
58
+png_canonical_type ( uint32_t type ) {
59
+	return ( type & ~( htonl ( PNG_CHUNK_ANCILLARY | PNG_CHUNK_PRIVATE |
60
+				   PNG_CHUNK_RESERVED | PNG_CHUNK_SAFE ) ) );
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 */
79
+struct png_image_header {
80
+	/** Width */
81
+	uint32_t width;
82
+	/** Height */
83
+	uint32_t height;
84
+	/** Bit depth */
85
+	uint8_t depth;
86
+	/** Colour type */
87
+	uint8_t colour_type;
88
+	/** Compression method */
89
+	uint8_t compression;
90
+	/** Filter method */
91
+	uint8_t filter;
92
+	/** Interlace method */
93
+	uint8_t interlace;
94
+} __attribute__ (( packed ));
95
+
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,
104
+};
105
+
106
+/** PNG colour type mask */
107
+#define PNG_COLOUR_TYPE_MASK 0x07
108
+
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,
115
+};
116
+
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,
123
+};
124
+
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,
133
+};
134
+
135
+/** PNG palette chunk type */
136
+#define PNG_TYPE_PLTE PNG_TYPE ( 'P', 'L', 'T', 'E' )
137
+
138
+/** A PNG palette entry */
139
+struct png_palette_entry {
140
+	/** Red */
141
+	uint8_t red;
142
+	/** Green */
143
+	uint8_t green;
144
+	/** Blue */
145
+	uint8_t blue;
146
+} __attribute__ (( packed ));
147
+
148
+/** A PNG palette chunk */
149
+struct png_palette {
150
+	/** Palette entries */
151
+	struct png_palette_entry entries[0];
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 */
161
+enum png_basic_filter_type {
162
+	/** No filtering */
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,
170
+	/** Paeth filter */
171
+	PNG_FILTER_BASIC_PAETH = 4,
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 */

+ 1993
- 0
src/tests/png_test.c
File diff soppresso perché troppo grande
Vedi File


+ 1
- 0
src/tests/tests.c Vedi File

@@ -51,3 +51,4 @@ REQUIRE_OBJECT ( ocsp_test );
51 51
 REQUIRE_OBJECT ( cms_test );
52 52
 REQUIRE_OBJECT ( pnm_test );
53 53
 REQUIRE_OBJECT ( deflate_test );
54
+REQUIRE_OBJECT ( png_test );

Loading…
Annulla
Salva