Import files tiff and yuv(raw) (#1316)

This commit is contained in:
Jamaika1 2021-05-06 19:30:34 +02:00 committed by GitHub
parent 5f653ad673
commit 8aaafe6995
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 41 deletions

View File

@ -141,7 +141,7 @@ static void encode_help_display(void)
fprintf(stdout, "-i <file>\n"); fprintf(stdout, "-i <file>\n");
fprintf(stdout, " Input file\n"); fprintf(stdout, " Input file\n");
fprintf(stdout, fprintf(stdout,
" Known extensions are <PBM|PGM|PPM|PNM|PAM|PGX|PNG|BMP|TIF|RAW|RAWL|TGA>\n"); " Known extensions are <PBM|PGM|PPM|PNM|PAM|PGX|PNG|BMP|TIF|TIFF|RAW|YUV|RAWL|TGA>\n");
fprintf(stdout, " If used, '-o <file>' must be provided\n"); fprintf(stdout, " If used, '-o <file>' must be provided\n");
fprintf(stdout, "-o <compressed file>\n"); fprintf(stdout, "-o <compressed file>\n");
fprintf(stdout, " Output file (accepted extensions are j2k or jp2).\n"); fprintf(stdout, " Output file (accepted extensions are j2k or jp2).\n");
@ -153,12 +153,12 @@ static void encode_help_display(void)
fprintf(stdout, " Required only if -ImgDir is used\n"); fprintf(stdout, " Required only if -ImgDir is used\n");
fprintf(stdout, fprintf(stdout,
"-F <width>,<height>,<ncomp>,<bitdepth>,{s,u}@<dx1>x<dy1>:...:<dxn>x<dyn>\n"); "-F <width>,<height>,<ncomp>,<bitdepth>,{s,u}@<dx1>x<dy1>:...:<dxn>x<dyn>\n");
fprintf(stdout, " Characteristics of the raw input image\n"); fprintf(stdout, " Characteristics of the raw or yuv input image\n");
fprintf(stdout, fprintf(stdout,
" If subsampling is omitted, 1x1 is assumed for all components\n"); " If subsampling is omitted, 1x1 is assumed for all components\n");
fprintf(stdout, " Example: -F 512,512,3,8,u@1x1:2x2:2x2\n"); fprintf(stdout, " Example: -F 512,512,3,8,u@1x1:2x2:2x2\n");
fprintf(stdout, fprintf(stdout,
" for raw 512x512 image with 4:2:0 subsampling\n"); " for raw or yuv 512x512 size with 4:2:0 subsampling\n");
fprintf(stdout, " Required only if RAW or RAWL input file is provided.\n"); fprintf(stdout, " Required only if RAW or RAWL input file is provided.\n");
fprintf(stdout, "\n"); fprintf(stdout, "\n");
fprintf(stdout, "Optional Parameters:\n"); fprintf(stdout, "Optional Parameters:\n");
@ -326,7 +326,7 @@ static void encode_help_display(void)
JPWL_MAX_NO_TILESPECS); JPWL_MAX_NO_TILESPECS);
fprintf(stdout, fprintf(stdout,
" p selects the packet error protection (EEP/UEP with EPBs)\n"); " p selects the packet error protection (EEP/UEP with EPBs)\n");
fprintf(stdout, " to be applied to raw data: 'type' can be\n"); fprintf(stdout, " to be applied to raw or yuv data: 'type' can be\n");
fprintf(stdout, fprintf(stdout,
" [0=none 1,absent=predefined 16=CRC-16 32=CRC-32 37-128=RS]\n"); " [0=none 1,absent=predefined 16=CRC-16 32=CRC-32 37-128=RS]\n");
fprintf(stdout, fprintf(stdout,
@ -516,10 +516,10 @@ static int get_file_format(char *filename)
{ {
unsigned int i; unsigned int i;
static const char *extension[] = { static const char *extension[] = {
"pgx", "pnm", "pgm", "ppm", "pbm", "pam", "bmp", "tif", "raw", "rawl", "tga", "png", "j2k", "jp2", "j2c", "jpc" "pgx", "pnm", "pgm", "ppm", "pbm", "pam", "bmp", "tif", "tiff", "raw", "yuv", "rawl", "tga", "png", "j2k", "jp2", "j2c", "jpc"
}; };
static const int format[] = { static const int format[] = {
PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, RAWL_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, J2K_CFMT, J2K_CFMT PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, TIF_DFMT, RAW_DFMT, RAW_DFMT, RAWL_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, J2K_CFMT, J2K_CFMT
}; };
char * ext = strrchr(filename, '.'); char * ext = strrchr(filename, '.');
if (ext == NULL) { if (ext == NULL) {
@ -638,7 +638,7 @@ static int parse_cmdline_encoder(int argc, char **argv,
default: default:
fprintf(stderr, fprintf(stderr,
"[ERROR] Unknown input file format: %s \n" "[ERROR] Unknown input file format: %s \n"
" Known file formats are *.pnm, *.pgm, *.ppm, *.pgx, *png, *.bmp, *.tif, *.raw or *.tga\n", " Known file formats are *.pnm, *.pgm, *.ppm, *.pgx, *png, *.bmp, *.tif(f), *.raw, *.yuv or *.tga\n",
infile); infile);
return 1; return 1;
} }
@ -792,7 +792,7 @@ static int parse_cmdline_encoder(int argc, char **argv,
} }
free(substr1); free(substr1);
if (wrong) { if (wrong) {
fprintf(stderr, "\nError: invalid raw image parameters\n"); fprintf(stderr, "\nError: invalid raw or yuv image parameters\n");
fprintf(stderr, "Please use the Format option -F:\n"); fprintf(stderr, "Please use the Format option -F:\n");
fprintf(stderr, fprintf(stderr,
"-F <width>,<height>,<ncomp>,<bitdepth>,{s,u}@<dx1>x<dy1>:...:<dxn>x<dyn>\n"); "-F <width>,<height>,<ncomp>,<bitdepth>,{s,u}@<dx1>x<dy1>:...:<dxn>x<dyn>\n");
@ -800,7 +800,8 @@ static int parse_cmdline_encoder(int argc, char **argv,
"If subsampling is omitted, 1x1 is assumed for all components\n"); "If subsampling is omitted, 1x1 is assumed for all components\n");
fprintf(stderr, fprintf(stderr,
"Example: -i image.raw -o image.j2k -F 512,512,3,8,u@1x1:2x2:2x2\n"); "Example: -i image.raw -o image.j2k -F 512,512,3,8,u@1x1:2x2:2x2\n");
fprintf(stderr, " for raw 512x512 image with 4:2:0 subsampling\n"); fprintf(stderr,
" for raw or yuv 512x512 size with 4:2:0 subsampling\n");
fprintf(stderr, "Aborting.\n"); fprintf(stderr, "Aborting.\n");
return 1; return 1;
} }
@ -1732,9 +1733,10 @@ static int parse_cmdline_encoder(int argc, char **argv,
} }
} }
if ((parameters->decod_format == RAW_DFMT && raw_cp->rawWidth == 0) if ((parameters->decod_format == RAW_DFMT ||
|| (parameters->decod_format == RAWL_DFMT && raw_cp->rawWidth == 0)) { parameters->decod_format == RAWL_DFMT)
fprintf(stderr, "[ERROR] invalid raw image parameters\n"); && (raw_cp->rawWidth == 0)) {
fprintf(stderr, "[ERROR] invalid raw or yuv image parameters\n");
fprintf(stderr, "Please use the Format option -F:\n"); fprintf(stderr, "Please use the Format option -F:\n");
fprintf(stderr, fprintf(stderr,
"-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n"); "-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n");
@ -1947,18 +1949,12 @@ int main(int argc, char **argv)
switch (parameters.decod_format) { switch (parameters.decod_format) {
case PGX_DFMT: case PGX_DFMT:
break;
case PXM_DFMT: case PXM_DFMT:
break;
case BMP_DFMT: case BMP_DFMT:
break;
case TIF_DFMT: case TIF_DFMT:
break;
case RAW_DFMT: case RAW_DFMT:
case RAWL_DFMT: case RAWL_DFMT:
break;
case TGA_DFMT: case TGA_DFMT:
break;
case PNG_DFMT: case PNG_DFMT:
break; break;
default: default:
@ -2001,7 +1997,7 @@ int main(int argc, char **argv)
case TIF_DFMT: case TIF_DFMT:
image = tiftoimage(parameters.infile, &parameters); image = tiftoimage(parameters.infile, &parameters);
if (!image) { if (!image) {
fprintf(stderr, "Unable to load tiff file\n"); fprintf(stderr, "Unable to load tif(f) file\n");
ret = 1; ret = 1;
goto fin; goto fin;
} }
@ -2011,7 +2007,7 @@ int main(int argc, char **argv)
case RAW_DFMT: case RAW_DFMT:
image = rawtoimage(parameters.infile, &parameters, &raw_cp); image = rawtoimage(parameters.infile, &parameters, &raw_cp);
if (!image) { if (!image) {
fprintf(stderr, "Unable to load raw file\n"); fprintf(stderr, "Unable to load raw or yuv file\n");
ret = 1; ret = 1;
goto fin; goto fin;
} }
@ -2047,7 +2043,7 @@ int main(int argc, char **argv)
#endif /* OPJ_HAVE_LIBPNG */ #endif /* OPJ_HAVE_LIBPNG */
} }
/* Can happen if input file is TIFF or PNG /* Can happen if input file is TIF(F) or PNG
* and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined * and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined
*/ */
if (!image) { if (!image) {

View File

@ -187,7 +187,7 @@ static void decode_help_display(void)
"\n" "\n"
" -ImgDir <directory> \n" " -ImgDir <directory> \n"
" Image file Directory path \n" " Image file Directory path \n"
" -OutFor <PBM|PGM|PPM|PNM|PAM|PGX|PNG|BMP|TIF|RAW|RAWL|TGA>\n" " -OutFor <PBM|PGM|PPM|PNM|PAM|PGX|PNG|BMP|TIF|TIFF|RAW|YUV|RAWL|TGA>\n"
" REQUIRED only if -ImgDir is used\n" " REQUIRED only if -ImgDir is used\n"
" Output format for decompressed images.\n"); " Output format for decompressed images.\n");
fprintf(stdout, " -i <compressed file>\n" fprintf(stdout, " -i <compressed file>\n"
@ -427,8 +427,8 @@ int load_images(dircnt_t *dirptr, char *imgdirpath)
int get_file_format(const char *filename) int get_file_format(const char *filename)
{ {
unsigned int i; unsigned int i;
static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp", "tif", "raw", "rawl", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" }; static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp", "tif", "tiff", "raw", "yuv", "rawl", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" };
static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, RAWL_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT }; static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, TIF_DFMT, RAW_DFMT, RAW_DFMT, RAWL_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT };
const char * ext = strrchr(filename, '.'); const char * ext = strrchr(filename, '.');
if (ext == NULL) { if (ext == NULL) {
return -1; return -1;
@ -628,24 +628,17 @@ int parse_cmdline_decoder(int argc, char **argv,
parameters->cod_format = get_file_format(outfile); parameters->cod_format = get_file_format(outfile);
switch (parameters->cod_format) { switch (parameters->cod_format) {
case PGX_DFMT: case PGX_DFMT:
break;
case PXM_DFMT: case PXM_DFMT:
break;
case BMP_DFMT: case BMP_DFMT:
break;
case TIF_DFMT: case TIF_DFMT:
break;
case RAW_DFMT: case RAW_DFMT:
break;
case RAWL_DFMT: case RAWL_DFMT:
break;
case TGA_DFMT: case TGA_DFMT:
break;
case PNG_DFMT: case PNG_DFMT:
break; break;
default: default:
fprintf(stderr, fprintf(stderr,
"Unknown output format image %s [only *.png, *.pnm, *.pgm, *.ppm, *.pgx, *.bmp, *.tif, *.raw or *.tga]!!\n", "Unknown output format image %s [only *.png, *.pnm, *.pgm, *.ppm, *.pgx, *.bmp, *.tif(f), *.raw, *.yuv or *.tga]!!\n",
outfile); outfile);
return 1; return 1;
} }
@ -692,7 +685,7 @@ int parse_cmdline_decoder(int argc, char **argv,
break; break;
default: default:
fprintf(stderr, fprintf(stderr,
"Unknown output format image %s [only *.png, *.pnm, *.pgm, *.ppm, *.pgx, *.bmp, *.tif, *.raw or *.tga]!!\n", "Unknown output format image %s [only *.png, *.pnm, *.pgm, *.ppm, *.pgx, *.bmp, *.tif(f), *.raw, *.yuv or *.tga]!!\n",
outformat); outformat);
return 1; return 1;
break; break;
@ -903,7 +896,7 @@ int parse_cmdline_decoder(int argc, char **argv,
fprintf(stderr, fprintf(stderr,
"[ERROR] When -ImgDir is used, -OutFor <FORMAT> must be used.\n"); "[ERROR] When -ImgDir is used, -OutFor <FORMAT> must be used.\n");
fprintf(stderr, "Only one format allowed.\n" fprintf(stderr, "Only one format allowed.\n"
"Valid format are PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA.\n"); "Valid format are PGM, PPM, PNM, PGX, BMP, TIF, TIFF, RAW, YUV, and TGA.\n");
return 1; return 1;
} }
if (!((parameters->outfile[0] == 0))) { if (!((parameters->outfile[0] == 0))) {
@ -1705,7 +1698,7 @@ int main(int argc, char **argv)
} }
break; break;
#ifdef OPJ_HAVE_LIBTIFF #ifdef OPJ_HAVE_LIBTIFF
case TIF_DFMT: /* TIFF */ case TIF_DFMT: /* TIF(F) */
if (imagetotif(image, parameters.outfile)) { if (imagetotif(image, parameters.outfile)) {
fprintf(stderr, "[ERROR] Outfile %s not generated\n", parameters.outfile); fprintf(stderr, "[ERROR] Outfile %s not generated\n", parameters.outfile);
failed = 1; failed = 1;
@ -1716,7 +1709,8 @@ int main(int argc, char **argv)
#endif /* OPJ_HAVE_LIBTIFF */ #endif /* OPJ_HAVE_LIBTIFF */
case RAW_DFMT: /* RAW */ case RAW_DFMT: /* RAW */
if (imagetoraw(image, parameters.outfile)) { if (imagetoraw(image, parameters.outfile)) {
fprintf(stderr, "[ERROR] Error generating raw file. Outfile %s not generated\n", fprintf(stderr,
"[ERROR] Error generating raw or yuv file. Outfile %s not generated\n",
parameters.outfile); parameters.outfile);
failed = 1; failed = 1;
} else if (!(parameters.quiet)) { } else if (!(parameters.quiet)) {
@ -1755,7 +1749,7 @@ int main(int argc, char **argv)
} }
break; break;
#endif /* OPJ_HAVE_LIBPNG */ #endif /* OPJ_HAVE_LIBPNG */
/* Can happen if output file is TIFF or PNG /* Can happen if output file is TIF(F) or PNG
* and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined * and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined
*/ */
default: default:

View File

@ -179,8 +179,8 @@ static int load_images(dircnt_t *dirptr, char *imgdirpath)
static int get_file_format(const char *filename) static int get_file_format(const char *filename)
{ {
unsigned int i; unsigned int i;
static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp", "tif", "raw", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" }; static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp", "tif", "tiff", "raw", "yuv", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" };
static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT }; static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, TIF_DFMT, RAW_DFMT, RAW_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT };
const char *ext = strrchr(filename, '.'); const char *ext = strrchr(filename, '.');
if (ext == NULL) { if (ext == NULL) {
return -1; return -1;
@ -395,7 +395,7 @@ static int parse_cmdline_decoder(int argc, char **argv,
fprintf(stderr, fprintf(stderr,
"[ERROR] When -ImgDir is used, -OutFor <FORMAT> must be used.\n"); "[ERROR] When -ImgDir is used, -OutFor <FORMAT> must be used.\n");
fprintf(stderr, "Only one format allowed.\n" fprintf(stderr, "Only one format allowed.\n"
"Valid format are PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA.\n"); "Valid format are PGM, PPM, PNM, PGX, BMP, TIF, TIFF, RAW, YUV and TGA.\n");
return 1; return 1;
} }
if (!(parameters->outfile[0] == 0)) { if (!(parameters->outfile[0] == 0)) {