The argument to enable parsing multiple frames from a single file (-n) was accidentally removed in 2012 in commit [1], and only fixed in 2025 by commit [2]. This feature makes it harder to fix other issues found in raw2rgbpnm and since it have been dead for ~13 years without anybody noticing likely have no users, remove it instead of trying to rework it. 1. Commit 5b6e56e54a93 ("Sort option names alphabetically and rename -r to -f") 2. Commit b0a28987d2e3 ("Add missing option to getopt()") Signed-off-by: Niklas Söderlund <niklas.soderlund@xxxxxxxxxxxx> --- Hello, For what it's worth when I found and fixed this issue in [2] I was working on something else and the missing n to optarg poped out. I have no use-case for this feature so please don't count me fixing this in Jan as somebody is using this feature. --- raw2rgbpnm.c | 55 ++++++++++++++++------------------------------------ 1 file changed, 17 insertions(+), 38 deletions(-) diff --git a/raw2rgbpnm.c b/raw2rgbpnm.c index 4cdef563e3c0..e5ed0af99070 100644 --- a/raw2rgbpnm.c +++ b/raw2rgbpnm.c @@ -146,17 +146,14 @@ static const int resolutions[][2] = { /* Read and return raw image data at given bits per pixel (bpp) depth. * size should be set correctly before calling this function. * If set to {-1,-1}, try to guess image file resolution. - * If framenum is set to nonnegative value, assume that input file contains - * multiple frames and return the given frame. In that case frame size must be given. */ -static unsigned char *read_raw_data(char *filename, int framenum, int size[2], int bpp) +static unsigned char *read_raw_data(char *filename, int size[2], int bpp) { /* Get file size */ unsigned int line_length; unsigned int padding = 0; unsigned char *b = NULL; unsigned int i; - int offset; FILE *f = fopen(filename, "rb"); if (!f) error("fopen failed"); int r = fseek(f, 0, SEEK_END); @@ -168,7 +165,6 @@ static unsigned char *read_raw_data(char *filename, int framenum, int size[2], i /* Check image resolution */ if (size[0]<=0 || size[1]<=0) { - if (framenum>=0) error("can not automatically detect frame size with multiple frames"); for (i=0; i<SIZE(resolutions); i++) if (resolutions[i][0]*resolutions[i][1]*bpp==file_size*8) break; if (i >= SIZE(resolutions)) error("can't guess raw image file resolution"); @@ -176,9 +172,9 @@ static unsigned char *read_raw_data(char *filename, int framenum, int size[2], i size[1] = resolutions[i][1]; } - if (framenum<0 && (file_size*8 < size[0]*size[1]*bpp)) error("out of input data"); - if (framenum<0 && (file_size*8 > size[0]*size[1]*bpp)) printf("warning: too large image file\n"); - if (framenum < 0 && (file_size % size[1] == 0)) { + if (file_size*8 < size[0]*size[1]*bpp) error("out of input data"); + if (file_size*8 > size[0]*size[1]*bpp) printf("warning: too large image file\n"); + if (file_size % size[1] == 0) { line_length = size[0] * bpp / 8; padding = file_size / size[1] - line_length; printf("%u padding bytes detected at end of line\n", padding); @@ -186,14 +182,6 @@ static unsigned char *read_raw_data(char *filename, int framenum, int size[2], i printf("warning: input size not multiple of frame size\n"); } - /* Go to the correct position in the file */ - if (framenum>=0) printf("Reading frame %i...\n", framenum); - if (framenum<0) framenum = 0; - offset = framenum*size[0]*size[1]*bpp/8; - r = fseek(f, offset, SEEK_SET); - if (r!=0) error("fseek"); - if ((file_size-offset)*8 < size[0]*size[1]*bpp) goto out; - /* Read data */ b = xalloc((size[0]*size[1]*bpp+7)/8); if (padding == 0) { @@ -210,7 +198,7 @@ static unsigned char *read_raw_data(char *filename, int framenum, int size[2], i error("fseek"); } } -out: fclose(f); + fclose(f); return b; } @@ -693,15 +681,13 @@ int main(int argc, char *argv[]) int size[2] = {-1,-1}; unsigned char *src, *dst; char *file_in = NULL, *file_out = NULL; - char multi_file_out[NAME_MAX]; int format = V4L2_PIX_FMT_UYVY; const struct format_info *info; int r; char *algorithm_name = NULL; - int n = 0, multiple = 0; for (;;) { - int c = getopt(argc, argv, "a:b:f:ghns:w"); + int c = getopt(argc, argv, "a:b:f:ghs:w"); if (c==-1) break; switch (c) { case 'a': @@ -747,13 +733,9 @@ int main(int argc, char *argv[]) "-f <format> Specify input file format format (-f ? for list, default UYVY)\n" "-g Use high bits for Bayer RAW 10 data\n" "-h Show this help\n" - "-n Assume multiple input frames, extract several PNM files\n" "-s <XxY> Specify image size\n" "-w Swap R and B channels\n", progname, argv[0]); exit(0); - case 'n': - multiple = 1; - break; case 's': if (parse_format(optarg, &size[0], &size[1]) < 0) { error("bad size"); @@ -780,23 +762,20 @@ int main(int argc, char *argv[]) } /* Read, convert, and save image */ - src = read_raw_data(file_in, multiple ? 0 : -1, size, info->bpp); + src = read_raw_data(file_in, size, info->bpp); printf("Image size: %ix%i, bytes per pixel: %i, format: %s\n", size[0], size[1], info->bpp, info->name); dst = xalloc(size[0]*size[1]*3); - do { - raw_to_rgb(info, src, size, dst); - sprintf(multi_file_out, "%s-%03i.pnm", file_out, n); - printf("Writing to file `%s'...\n", multiple ? multi_file_out : file_out); - f = fopen(multiple ? multi_file_out : file_out, "wb"); - if (!f) error("file open failed"); - fprintf(f, "P6\n%i %i\n255\n", size[0], size[1]); - r = fwrite(dst, size[0]*size[1]*3, 1, f); - if (r!=1) error("write failed"); - fclose(f); - if (!multiple) break; - src = read_raw_data(file_in, ++n, size, info->bpp); - } while (src != NULL); + + raw_to_rgb(info, src, size, dst); + printf("Writing to file `%s'...\n", file_out); + f = fopen(file_out, "wb"); + if (!f) error("file open failed"); + fprintf(f, "P6\n%i %i\n255\n", size[0], size[1]); + r = fwrite(dst, size[0]*size[1]*3, 1, f); + if (r!=1) error("write failed"); + fclose(f); + free(src); free(dst); return 0; -- 2.48.1