Remove unnecessary calls to strlower in drawalpha option

This commit is contained in:
Unknown 2019-02-17 11:07:48 +01:00
parent a3051223f2
commit 32f081c27a
2 changed files with 13 additions and 16 deletions

View File

@ -430,27 +430,27 @@ int Mapper::start(int argc, char *argv[]) {
generator.verboseReadColors++; generator.verboseReadColors++;
} }
break; break;
case 'e': case 'e': {
// Todo: Unnecessary calls to strlower. Optimize
generator.setDrawAlpha(true); generator.setDrawAlpha(true);
if (!ps.optarg || !*ps.optarg) const string optarg = strlower(ps.optarg);
if (optarg.empty())
PixelAttribute::setMixMode(PixelAttribute::AlphaMixAverage); PixelAttribute::setMixMode(PixelAttribute::AlphaMixAverage);
else if (string(ps.optarg) == "cumulative" || strlower(ps.optarg) == "nodarken") else if (optarg == "cumulative" || optarg == "nodarken")
// "nodarken" is supported for backwards compatibility // "nodarken" is supported for backwards compatibility
PixelAttribute::setMixMode(PixelAttribute::AlphaMixCumulative); PixelAttribute::setMixMode(PixelAttribute::AlphaMixCumulative);
else if (string(ps.optarg) == "darken" || strlower(ps.optarg) == "cumulative-darken") else if (optarg == "darken" || optarg == "cumulative-darken")
// "darken" is supported for backwards compatibility // "darken" is supported for backwards compatibility
PixelAttribute::setMixMode(PixelAttribute::AlphaMixCumulativeDarken); PixelAttribute::setMixMode(PixelAttribute::AlphaMixCumulativeDarken);
else if (strlower(ps.optarg) == "average") else if (optarg == "average")
PixelAttribute::setMixMode(PixelAttribute::AlphaMixAverage); PixelAttribute::setMixMode(PixelAttribute::AlphaMixAverage);
else if (strlower(ps.optarg) == "none") else if (optarg == "none")
generator.setDrawAlpha(false); generator.setDrawAlpha(false);
else { else {
std::cerr << "Invalid parameter to '" << long_options[option_index].name << "': '" << ps.optarg << "'" << std::endl; cerr << "Invalid parameter to '" << long_options[option_index].name << "': '" << ps.optarg << "'" << endl;
usage(); usage();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
break; } break;
case OPT_DRAWAIR: case OPT_DRAWAIR:
generator.setDrawAir(true); generator.setDrawAir(true);
break; break;
@ -1112,7 +1112,8 @@ bool Mapper::parseNodeCoordinate(istream & is, int & coord, bool & isBlockCoord,
} }
if (is.fail()) if (is.fail())
return false; return false;
coord = i; coord = i; // TODO: Find out what i is doing an what it schould do.
//i is uninitialized if c == 42 && wildcard == false && is->fail == false
isBlockCoord = false; isBlockCoord = false;
if (validStreamAtEof(is)) if (validStreamAtEof(is))
return true; return true;

View File

@ -1,6 +1,4 @@
#pragma once
#ifndef _UTIL_H_
#define _UTIL_H_
#include <cstring> #include <cstring>
@ -12,5 +10,3 @@ inline std::string strlower(const std::string &s)
sl[i] = tolower(sl[i]); sl[i] = tolower(sl[i]);
return sl; return sl;
} }
#endif // _UTIL_H_