|
49 | 49 | extern "C" {
|
50 | 50 | #endif
|
51 | 51 |
|
| 52 | +/// metadata read from file |
52 | 53 | struct pam_metadata {
|
53 |
| - int width; |
54 |
| - int height; |
55 |
| - int ch_count; |
56 |
| - int maxval; |
57 |
| - bool bitmap_pbm; // bitmap data is stored in PBM format (1 bit per pixel, line aligned to whole byte, 1 is black /"ink on"/), |
58 |
| - // otherwise 1 byte per pixel, 1 is white "light on"); if .depth != 1 || .maxval != 1, this value is undefined |
| 54 | + int width; ///< image width |
| 55 | + int height; ///< image height |
| 56 | + int ch_count; ///< number of channels |
| 57 | + int maxval; ///< sample maximal value (typically but not necessarily |
| 58 | + ///< 255) |
| 59 | + bool bitmap_pbm; ///< bitmap data is stored in PBM format (1 bit per |
| 60 | + ///< pixel, line aligned to whole byte, 1 is black |
| 61 | + ///< /"ink on"/), otherwise 1 byte per pixel, 1 is |
| 62 | + ///< white "light on"); if .depth != 1 || .maxval != 1, |
| 63 | + ///< this value is undefined |
59 | 64 | };
|
60 | 65 |
|
| 66 | +/** |
| 67 | + * read PAM/PNM file |
| 68 | + * |
| 69 | + * @param filename file name |
| 70 | + * @param[out] info pointer to metadata struct |
| 71 | + * @param[out] data pointer to byte array, can be 0, in which case no data |
| 72 | + * are written (only metadata read ) |
| 73 | + * @param[out] allocaltor allocator to alloc @ref data; if 0, no data are |
| 74 | + * read/allocated, only @ref info set |
| 75 | + */ |
61 | 76 | bool pam_read(const char *filename, struct pam_metadata *info, unsigned char **data, void *(*allocator)(size_t));
|
| 77 | + |
| 78 | +enum { |
| 79 | + PAM_PITCH_CONTINUOUS = 0, |
| 80 | +}; |
| 81 | + |
| 82 | +/** |
| 83 | + * write PAM or PNM file |
| 84 | + * |
| 85 | + * @param filename file name to be written to |
| 86 | + * @param width image width |
| 87 | + * @param pitch input line pitch in bytes; PAM_PITCH_CONTINUOUS can be used |
| 88 | + * if input pitch == width * ch_count * (maxval <= 255 ? 1 : 2) |
| 89 | + * @param height image height |
| 90 | + * @param ch_count image channel count (1-4 for output PAM, 1 or 3 for PNM, see |
| 91 | + * @ref pnm) |
| 92 | + * @param maxval maximal sample value, typically 255 for 8-bit |
| 93 | + * @param data bytes to be written |
| 94 | + * @param pnm use PNM file (instead of PAM) |
| 95 | + */ |
62 | 96 | bool pam_write(const char *filename, unsigned int width, unsigned int pitch,
|
63 | 97 | unsigned int height, int ch_count, int maxval,
|
64 | 98 | const unsigned char *data, bool pnm);
|
|
0 commit comments