summaryrefslogtreecommitdiffstats
path: root/qemu/roms/ipxe/src/include/ipxe/pnm.h
blob: 536c14d5f0da17155c9df139d69f61855c76221f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef _IPXE_PNM_H
#define _IPXE_PNM_H

/** @file
 *
 * Portable anymap format (PNM)
 *
 */

FILE_LICENCE ( GPL2_OR_LATER );

#include <stdint.h>
#include <ipxe/uaccess.h>
#include <ipxe/image.h>

/** PNM signature */
struct pnm_signature {
	/** Magic byte ('P') */
	char magic;
	/** PNM type */
	char type;
	/** Whitespace */
	char space;
} __attribute__ (( packed ));

/** PNM magic byte */
#define PNM_MAGIC 'P'

/** PNM context */
struct pnm_context {
	/** PNM type */
	struct pnm_type *type;
	/** Current byte offset */
	size_t offset;
	/** Maximum length of ASCII values */
	size_t ascii_len;
	/** Maximum pixel value */
	unsigned int max;
};

/** Default maximum length of ASCII values */
#define PNM_ASCII_LEN 16

/** PNM type */
struct pnm_type {
	/** PNM type */
	char type;
	/** Number of scalar values per pixel */
	uint8_t depth;
	/** Number of pixels per composite value */
	uint8_t packing;
	/** Flags */
	uint8_t flags;
	/** Extract scalar value
	 *
	 * @v image		PNM image
	 * @v pnm		PNM context
	 * @ret value		Value, or negative error
	 */
	int ( * scalar ) ( struct image *image, struct pnm_context *pnm );
	/** Convert composite value to 24-bit RGB
	 *
	 * @v composite		Composite value
	 * @v index		Pixel index within this composite value
	 * @ret rgb		24-bit RGB value
	 */
	uint32_t ( * rgb ) ( uint32_t composite, unsigned int index );
};

/** PNM flags */
enum pnm_flags {
	/** Bitmap format
	 *
	 * If set, this flag indicates that:
	 *
	 * - the maximum scalar value is predefined as being equal to
	 *   (2^packing-1), and is not present within the file, and
	 *
	 * - the maximum length of ASCII values is 1.
	 */
	PNM_BITMAP = 0x01,
};

extern struct image_type pnm_image_type __image_type ( PROBE_NORMAL );

#endif /* _IPXE_PNM_H */