Skip to content

Commit ef0a54f

Browse files
committed
pam: add PAM_PITCH_CONTINUOUS placeholder for pitch
If the value of pitch is "default", it ti actually a bit tricky to set the value explicitly. Also the value was set incorrectly in HEAD^^ - pitch equals width only for single channel + 8-bit. added doxy
1 parent f210236 commit ef0a54f

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

src/utils/pam.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ bool pam_write(const char *filename, unsigned int width, unsigned int pitch,
275275
const size_t len = width * linesize;
276276
errno = 0;
277277
size_t bytes_written = 0;
278-
if (width == pitch) {
278+
if (pitch == PAM_PITCH_CONTINUOUS || width == pitch) {
279279
bytes_written = fwrite((const char *) data, 1, len, file);
280280
} else {
281281
for (unsigned y = 0; y < height; ++y) {

src/utils/pam.h

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,50 @@
4949
extern "C" {
5050
#endif
5151

52+
/// metadata read from file
5253
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
5964
};
6065

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+
*/
6176
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+
*/
6296
bool pam_write(const char *filename, unsigned int width, unsigned int pitch,
6397
unsigned int height, int ch_count, int maxval,
6498
const unsigned char *data, bool pnm);

src/video_frame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ bool save_video_frame_as_pnm(struct video_frame *frame, const char *name)
481481
return false;
482482
}
483483

484-
pam_write(name, tile->width, tile->width, tile->height, 3,
484+
pam_write(name, tile->width, PAM_PITCH_CONTINUOUS, tile->height, 3,
485485
(1 << get_bits_per_component(frame->color_spec)) - 1, data,
486486
true);
487487
free(tmp_data);

0 commit comments

Comments
 (0)