TJBench: Strictly check all non-boolean arguments

+ document that the value of -yuvpad must be a power of 2 (refer to
d260858395)
This commit is contained in:
DRC
2023-01-18 15:31:04 -06:00
parent fb15efe94f
commit 28c2e60770
2 changed files with 12 additions and 4 deletions

View File

@@ -717,7 +717,8 @@ final class TJBench {
System.out.println("-quiet = Output results in tabular rather than verbose format");
System.out.println("-yuv = Compress from/decompress to intermediate planar YUV images");
System.out.println("-yuvpad <p> = The number of bytes by which each row in each plane of an");
System.out.println(" intermediate YUV image is evenly divisible [default = 1]");
System.out.println(" intermediate YUV image is evenly divisible (must be a power of 2)");
System.out.println(" [default = 1]");
System.out.println("-scale M/N = When decompressing, scale the width/height of the JPEG image by a");
System.out.print(" factor of M/N (M/N = ");
for (i = 0; i < nsf; i++) {
@@ -907,8 +908,10 @@ final class TJBench {
try {
temp = Integer.parseInt(argv[++i]);
} catch (NumberFormatException e) {}
if (temp >= 1)
if (temp >= 1 && (temp & (temp - 1)) == 0)
yuvAlign = temp;
else
usage();
} else if (argv[i].equalsIgnoreCase("-subsamp") &&
i < argv.length - 1) {
i++;
@@ -924,6 +927,8 @@ final class TJBench {
subsamp = TJ.SAMP_420;
else if (argv[i].equals("411"))
subsamp = TJ.SAMP_411;
else
usage();
} else if (argv[i].equalsIgnoreCase("-componly"))
compOnly = true;
else if (argv[i].equalsIgnoreCase("-nowrite"))

View File

@@ -775,7 +775,8 @@ static void usage(char *progName)
printf("-quiet = Output results in tabular rather than verbose format\n");
printf("-yuv = Compress from/decompress to intermediate planar YUV images\n");
printf("-yuvpad <p> = The number of bytes by which each row in each plane of an\n");
printf(" intermediate YUV image is evenly divisible [default = 1]\n");
printf(" intermediate YUV image is evenly divisible (must be a power of 2)\n");
printf(" [default = 1]\n");
printf("-scale M/N = When decompressing, scale the width/height of the JPEG image by a\n");
printf(" factor of M/N (M/N = ");
for (i = 0; i < nsf; i++) {
@@ -940,7 +941,8 @@ int main(int argc, char *argv[])
} else if (!strcasecmp(argv[i], "-yuvpad") && i < argc - 1) {
int tempi = atoi(argv[++i]);
if (tempi >= 1) yuvAlign = tempi;
if (tempi >= 1 && (tempi & (tempi - 1)) == 0) yuvAlign = tempi;
else usage(argv[0]);
} else if (!strcasecmp(argv[i], "-subsamp") && i < argc - 1) {
i++;
if (toupper(argv[i][0]) == 'G') subsamp = TJSAMP_GRAY;
@@ -953,6 +955,7 @@ int main(int argc, char *argv[])
case 440: subsamp = TJSAMP_440; break;
case 420: subsamp = TJSAMP_420; break;
case 411: subsamp = TJSAMP_411; break;
default: usage(argv[0]);
}
}
} else if (!strcasecmp(argv[i], "-componly"))