1 #ifndef _IPXE_PNM_H 2 #define _IPXE_PNM_H 3 4 /** @file 5 * 6 * Portable anymap format (PNM) 7 * 8 */ 9 10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); 11 12 #include <stdint.h> 13 #include <ipxe/uaccess.h> 14 #include <ipxe/image.h> 15 16 /** PNM signature */ 17 struct pnm_signature { 18 /** Magic byte ('P') */ 19 char magic; 20 /** PNM type */ 21 char type; 22 /** Whitespace */ 23 char space; 24 } __attribute__ (( packed )); 25 26 /** PNM magic byte */ 27 #define PNM_MAGIC 'P' 28 29 /** PNM context */ 30 struct pnm_context { 31 /** PNM type */ 32 struct pnm_type *type; 33 /** Current byte offset */ 34 size_t offset; 35 /** Maximum length of ASCII values */ 36 size_t ascii_len; 37 /** Maximum pixel value */ 38 unsigned int max; 39 }; 40 41 /** Default maximum length of ASCII values */ 42 #define PNM_ASCII_LEN 16 43 44 /** PNM type */ 45 struct pnm_type { 46 /** PNM type */ 47 char type; 48 /** Number of scalar values per pixel */ 49 uint8_t depth; 50 /** Number of pixels per composite value */ 51 uint8_t packing; 52 /** Flags */ 53 uint8_t flags; 54 /** Extract scalar value 55 * 56 * @v image PNM image 57 * @v pnm PNM context 58 * @ret value Value, or negative error 59 */ 60 int ( * scalar ) ( struct image *image, struct pnm_context *pnm ); 61 /** Convert composite value to 24-bit RGB 62 * 63 * @v composite Composite value 64 * @v index Pixel index within this composite value 65 * @ret rgb 24-bit RGB value 66 */ 67 uint32_t ( * rgb ) ( uint32_t composite, unsigned int index ); 68 }; 69 70 /** PNM flags */ 71 enum pnm_flags { 72 /** Bitmap format 73 * 74 * If set, this flag indicates that: 75 * 76 * - the maximum scalar value is predefined as being equal to 77 * (2^packing-1), and is not present within the file, and 78 * 79 * - the maximum length of ASCII values is 1. 80 */ 81 PNM_BITMAP = 0x01, 82 }; 83 84 extern struct image_type pnm_image_type __image_type ( PROBE_NORMAL ); 85 86 #endif /* _IPXE_PNM_H */ 87