Skip to content

Commit 9e43f74

Browse files
committed
PAM: rename depth to ch_count
The depth (DEPTH field of PAM) is actually channel count, which may be slightly misleading - use rather ch_count instead.
1 parent 484a5a0 commit 9e43f74

File tree

4 files changed

+29
-26
lines changed

4 files changed

+29
-26
lines changed

src/capture_filter/logo.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Martin Pulec <[email protected]>
44
*/
55
/*
6-
* Copyright (c) 2013-2024 CESNET
6+
* Copyright (c) 2013-2025 CESNET
77
* All rights reserved.
88
*
99
* Redistribution and use in source and binary forms, with or without
@@ -79,13 +79,16 @@ static bool load_logo_data_from_file(struct state_capture_filter_logo *s, const
7979
}
8080
s->width = info.width;
8181
s->height = info.height;
82-
if (info.depth != 3 && info.depth != 4) {
83-
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Unsupported depth %d in PAM file.\n", info.depth);
82+
if (info.ch_count != 3 && info.ch_count != 4) {
83+
log_msg(LOG_LEVEL_ERROR,
84+
MOD_NAME
85+
"Unsupported channel count %d in PAM file.\n",
86+
info.ch_count);
8487
free(data);
8588
return false;
8689
}
87-
rgb = info.depth == 3;
88-
int datalen = info.depth * s->width * s->height;
90+
rgb = info.ch_count == 3;
91+
int datalen = info.ch_count * s->width * s->height;
8992
if (rgb) {
9093
datalen = 4 * s->width * s->height;
9194
unsigned char * tmp = malloc(datalen);

src/utils/pam.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* This file is part of GPUJPEG.
99
*/
1010
/*
11-
* Copyright (c) 2013-2023, CESNET z.s.p.o.
11+
* Copyright (c) 2013-2025, CESNET
1212
*
1313
* All rights reserved.
1414
*
@@ -64,7 +64,7 @@ static bool parse_pam(FILE *file, struct pam_metadata *info) {
6464
} else if (strcmp(key, "HEIGHT") == 0) {
6565
info->height = atoi(val);
6666
} else if (strcmp(key, "DEPTH") == 0) {
67-
info->depth = atoi(val);
67+
info->ch_count = atoi(val);
6868
} else if (strcmp(key, "MAXVAL") == 0) {
6969
info->maxval = atoi(val);
7070
} else if (strcmp(key, "TUPLTYPE") == 0) {
@@ -92,15 +92,15 @@ static bool parse_pnm(FILE *file, char pnm_id, struct pam_metadata *info) {
9292
fprintf(stderr, "Plain (ASCII) PNM are not supported, input is P%c\n", pnm_id);
9393
return false;
9494
case '4':
95-
info->depth = 1;
95+
info->ch_count = 1;
9696
info->maxval = 1;
9797
info->bitmap_pbm = true;
9898
break;
9999
case '5':
100-
info->depth = 1;
100+
info->ch_count = 1;
101101
break;
102102
case '6':
103-
info->depth = 3;
103+
info->ch_count = 3;
104104
break;
105105
default:
106106
fprintf(stderr, "Wrong PNM type P%c\n", pnm_id);
@@ -166,8 +166,8 @@ bool pam_read(const char *filename, struct pam_metadata *info, unsigned char **d
166166
fprintf(stderr, "Unspecified/incorrect size %dx%d!\n", info->width, info->height);
167167
parse_rc = false;
168168
}
169-
if (info->depth <= 0) {
170-
fprintf(stderr, "Unspecified/incorrect depth %d!\n", info->depth);
169+
if (info->ch_count <= 0) {
170+
fprintf(stderr, "Unspecified/incorrect channel count %d!\n", info->ch_count);
171171
parse_rc = false;
172172
}
173173
if (info->maxval <= 0 || info->maxval > 65535) {
@@ -178,15 +178,15 @@ bool pam_read(const char *filename, struct pam_metadata *info, unsigned char **d
178178
fclose(file);
179179
return parse_rc;
180180
}
181-
size_t datalen = (size_t) info->depth * info->width * info->height;
181+
size_t datalen = (size_t) info->ch_count * info->width * info->height;
182182
if (info->maxval == 1 && info->bitmap_pbm) {
183183
datalen = (info->width + 7) / 8 * info->height;
184184
} else if (info->maxval > 255) {
185185
datalen *= 2;
186186
}
187187
*data = (unsigned char *) allocator(datalen);
188188
if (!*data) {
189-
fprintf(stderr, "Unspecified depth header field!\n");
189+
fprintf(stderr, "Failed to allocate data!\n");
190190
fclose(file);
191191
return false;
192192
}
@@ -201,32 +201,32 @@ bool pam_read(const char *filename, struct pam_metadata *info, unsigned char **d
201201
return true;
202202
}
203203

204-
bool pam_write(const char *filename, unsigned int width, unsigned int height, int depth, int maxval, const unsigned char *data, bool pnm) {
204+
bool pam_write(const char *filename, unsigned int width, unsigned int height, int ch_count, int maxval, const unsigned char *data, bool pnm) {
205205
errno = 0;
206206
FILE *file = fopen(filename, "wb");
207207
if (!file) {
208208
fprintf(stderr, "Failed to open %s for writing: %s\n", filename, strerror(errno));
209209
return false;
210210
}
211211
if (pnm) {
212-
if (depth != 1 && depth != 3) {
212+
if (ch_count != 1 && ch_count != 3) {
213213
fprintf(stderr, "Only 1 or 3 channels supported for PNM!\n");
214214
fclose(file);
215215
return false;
216216
}
217217
fprintf(file, "P%d\n"
218218
"%u %u\n"
219219
"%d\n",
220-
depth == 1 ? 5 : 6,
220+
ch_count == 1 ? 5 : 6,
221221
width, height, maxval);
222222
} else {
223223
const char *tuple_type = "INVALID";
224-
switch (depth) {
224+
switch (ch_count) {
225225
case 4: tuple_type = "RGB_ALPHA"; break;
226226
case 3: tuple_type = "RGB"; break;
227227
case 2: tuple_type = "GRAYSCALE_ALPHA"; break;
228228
case 1: tuple_type = "GRAYSCALE"; break;
229-
default: fprintf(stderr, "Wrong depth: %d\n", depth);
229+
default: fprintf(stderr, "Wrong channel count: %d\n", ch_count);
230230
}
231231
fprintf(file, "P7\n"
232232
"WIDTH %u\n"
@@ -235,9 +235,9 @@ bool pam_write(const char *filename, unsigned int width, unsigned int height, in
235235
"MAXVAL %d\n"
236236
"TUPLTYPE %s\n"
237237
"ENDHDR\n",
238-
width, height, depth, maxval, tuple_type);
238+
width, height, ch_count, maxval, tuple_type);
239239
}
240-
size_t len = (size_t) width * height * depth * (maxval <= 255 ? 1 : 2);
240+
size_t len = (size_t) width * height * ch_count * (maxval <= 255 ? 1 : 2);
241241
errno = 0;
242242
size_t bytes_written = fwrite((const char *) data, 1, len, file);
243243
if (bytes_written != len) {

src/utils/pam.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* This file is part of GPUJPEG.
99
*/
1010
/*
11-
* Copyright (c) 2013-2023, CESNET z.s.p.o.
11+
* Copyright (c) 2013-2025, CESNET
1212
*
1313
* All rights reserved.
1414
*
@@ -52,7 +52,7 @@ extern "C" {
5252
struct pam_metadata {
5353
int width;
5454
int height;
55-
int depth; // == channel count
55+
int ch_count;
5656
int maxval;
5757
bool bitmap_pbm; // bitmap data is stored in PBM format (1 bit per pixel, line aligned to whole byte, 1 is black /"ink on"/),
5858
// otherwise 1 byte per pixel, 1 is white "light on"); if .depth != 1 || .maxval != 1, this value is undefined

src/video_capture/testcard.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
/*
1414
* Copyright (c) 2005-2006 University of Glasgow
15-
* Copyright (c) 2005-2024 CESNET z.s.p.o.
15+
* Copyright (c) 2005-2025 CESNET
1616
*
1717
* Redistribution and use in source and binary forms, with or without
1818
* modification, is permitted provided that the following conditions
@@ -317,15 +317,15 @@ static size_t testcard_load_from_file_pam(const char *filename, struct video_des
317317
if (pam_read(filename, &info, &data, malloc) == 0) {
318318
return false;
319319
}
320-
switch (info.depth) {
320+
switch (info.ch_count) {
321321
case 3:
322322
desc->color_spec = info.maxval == 255 ? RGB : RG48;
323323
break;
324324
case 4:
325325
desc->color_spec = RGBA;
326326
break;
327327
default:
328-
log_msg(LOG_LEVEL_ERROR, "Unsupported PAM/PNM channel count %d!\n", info.depth);
328+
log_msg(LOG_LEVEL_ERROR, "Unsupported PAM/PNM channel count %d!\n", info.ch_count);
329329
return 0;
330330
}
331331
desc->width = info.width;

0 commit comments

Comments
 (0)