TJExample.java: Don't ignore mistyped args

This commit is contained in:
DRC
2017-11-15 19:33:06 -06:00
parent 5abf2536f6
commit 468f2fed27

View File

@@ -1,5 +1,6 @@
/* /*
* Copyright (C)2011-2012, 2014-2015 D. R. Commander. All Rights Reserved. * Copyright (C)2011-2012, 2014-2015, 2017 D. R. Commander.
* All Rights Reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@@ -117,11 +118,13 @@ public class TJExample implements TJCustomFilter {
int outSubsamp = -1, outQual = 95; int outSubsamp = -1, outQual = 95;
boolean display = false; boolean display = false;
if (argv.length > 1) { if (argv[1].substring(0, 2).equalsIgnoreCase("-d"))
for (int i = 1; i < argv.length; i++) { display = true;
for (int i = 2; i < argv.length; i++) {
if (argv[i].length() < 2) if (argv[i].length() < 2)
continue; continue;
if (argv[i].length() > 2 && else if (argv[i].length() > 2 &&
argv[i].substring(0, 3).equalsIgnoreCase("-sc")) { argv[i].substring(0, 3).equalsIgnoreCase("-sc")) {
int match = 0; int match = 0;
if (i < argv.length - 1) { if (i < argv.length - 1) {
@@ -141,9 +144,7 @@ public class TJExample implements TJCustomFilter {
} }
if (match != 1) usage(); if (match != 1) usage();
} }
if (argv[i].equalsIgnoreCase("-h") || argv[i].equalsIgnoreCase("-?")) else if (argv[i].length() > 2 &&
usage();
if (argv[i].length() > 2 &&
argv[i].substring(0, 3).equalsIgnoreCase("-sa")) { argv[i].substring(0, 3).equalsIgnoreCase("-sa")) {
if (i < argv.length - 1) { if (i < argv.length - 1) {
i++; i++;
@@ -160,7 +161,7 @@ public class TJExample implements TJCustomFilter {
} else } else
usage(); usage();
} }
if (argv[i].substring(0, 2).equalsIgnoreCase("-q")) { else if (argv[i].substring(0, 2).equalsIgnoreCase("-q")) {
if (i < argv.length - 1) { if (i < argv.length - 1) {
int qual = Integer.parseInt(argv[++i]); int qual = Integer.parseInt(argv[++i]);
if (qual >= 1 && qual <= 100) if (qual >= 1 && qual <= 100)
@@ -170,23 +171,23 @@ public class TJExample implements TJCustomFilter {
} else } else
usage(); usage();
} }
if (argv[i].substring(0, 2).equalsIgnoreCase("-g")) else if (argv[i].substring(0, 2).equalsIgnoreCase("-g"))
xform.options |= TJTransform.OPT_GRAY; xform.options |= TJTransform.OPT_GRAY;
if (argv[i].equalsIgnoreCase("-hflip")) else if (argv[i].equalsIgnoreCase("-hflip"))
xform.op = TJTransform.OP_HFLIP; xform.op = TJTransform.OP_HFLIP;
if (argv[i].equalsIgnoreCase("-vflip")) else if (argv[i].equalsIgnoreCase("-vflip"))
xform.op = TJTransform.OP_VFLIP; xform.op = TJTransform.OP_VFLIP;
if (argv[i].equalsIgnoreCase("-transpose")) else if (argv[i].equalsIgnoreCase("-transpose"))
xform.op = TJTransform.OP_TRANSPOSE; xform.op = TJTransform.OP_TRANSPOSE;
if (argv[i].equalsIgnoreCase("-transverse")) else if (argv[i].equalsIgnoreCase("-transverse"))
xform.op = TJTransform.OP_TRANSVERSE; xform.op = TJTransform.OP_TRANSVERSE;
if (argv[i].equalsIgnoreCase("-rot90")) else if (argv[i].equalsIgnoreCase("-rot90"))
xform.op = TJTransform.OP_ROT90; xform.op = TJTransform.OP_ROT90;
if (argv[i].equalsIgnoreCase("-rot180")) else if (argv[i].equalsIgnoreCase("-rot180"))
xform.op = TJTransform.OP_ROT180; xform.op = TJTransform.OP_ROT180;
if (argv[i].equalsIgnoreCase("-rot270")) else if (argv[i].equalsIgnoreCase("-rot270"))
xform.op = TJTransform.OP_ROT270; xform.op = TJTransform.OP_ROT270;
if (argv[i].equalsIgnoreCase("-custom")) else if (argv[i].equalsIgnoreCase("-custom"))
xform.cf = new TJExample(); xform.cf = new TJExample();
else if (argv[i].length() > 2 && else if (argv[i].length() > 2 &&
argv[i].substring(0, 2).equalsIgnoreCase("-c")) { argv[i].substring(0, 2).equalsIgnoreCase("-c")) {
@@ -210,21 +211,21 @@ public class TJExample implements TJCustomFilter {
xform.height = temph; xform.height = temph;
xform.options |= TJTransform.OPT_CROP; xform.options |= TJTransform.OPT_CROP;
} }
if (argv[i].substring(0, 2).equalsIgnoreCase("-d")) else if (argv[i].substring(0, 2).equalsIgnoreCase("-d"))
display = true; display = true;
if (argv[i].equalsIgnoreCase("-fastupsample")) { else if (argv[i].equalsIgnoreCase("-fastupsample")) {
System.out.println("Using fast upsampling code"); System.out.println("Using fast upsampling code");
flags |= TJ.FLAG_FASTUPSAMPLE; flags |= TJ.FLAG_FASTUPSAMPLE;
} }
if (argv[i].equalsIgnoreCase("-fastdct")) { else if (argv[i].equalsIgnoreCase("-fastdct")) {
System.out.println("Using fastest DCT/IDCT algorithm"); System.out.println("Using fastest DCT/IDCT algorithm");
flags |= TJ.FLAG_FASTDCT; flags |= TJ.FLAG_FASTDCT;
} }
if (argv[i].equalsIgnoreCase("-accuratedct")) { else if (argv[i].equalsIgnoreCase("-accuratedct")) {
System.out.println("Using most accurate DCT/IDCT algorithm"); System.out.println("Using most accurate DCT/IDCT algorithm");
flags |= TJ.FLAG_ACCURATEDCT; flags |= TJ.FLAG_ACCURATEDCT;
} }
} else usage();
} }
String[] inFileTokens = argv[0].split("\\."); String[] inFileTokens = argv[0].split("\\.");
if (inFileTokens.length > 1) if (inFileTokens.length > 1)