Repository: sz3/libcimbar
File: src/exe/cimbar/cimbar.cpp (C++)

Code before:
		int bytes = decodefun(img, shouldPreprocess, color_correct);
		if (!bytes)
			err |= 4;
	}
	return err;
}

// see also "decodefun" for non-fountain decodes, defined as a lambda inline below.
// this one needs its own function since it's a template (:
template <typename SINK>
std::function<int(cv::UMat,bool,int)> fountain_decode_fun(SINK& sink, Decoder& d)
{
	return [&sink, &d] (cv::UMat m, bool pre, int cc) {
		return d.decode_fountain(m, sink, pre, cc);
	};
}

int main(int argc, char** argv)
{
	cxxopts::Options options("cimbar encoder/decoder", "Demonstration program for cimbar codes");

	unsigned colorBits = cimbar::Config::color_bits();
	unsigned compressionLevel = cimbar::Config::compression_level();
	unsigned ecc = cimbar::Config::ecc_bytes();
	options.add_options()
		("i,in", "Encoded pngs/jpgs/etc (for decode), or file to encode", cxxopts::value<vector<string>>())
		("o,out", "Output file prefix (encoding) or directory (decoding).", cxxopts::value<string>())
		("c,color-bits", "Color bits. [0-3]", cxxopts::value<int>()->default_value(turbo::str::str(colorBits)))
		("e,ecc", "ECC level", cxxopts::value<unsigned>()->default_value(turbo::str::str(ecc)))
		("m,mode", "Select a cimbar mode. B (the default) is new to 0.6.x. 4C is the 0.5.x config. [B,4C]", cxxopts::value<string>()->default_value("B"))
		("z,compression", "Compression level. 0 == no compression.", cxxopts::value<int>()->default_value(turbo::str::str(compressionLevel)))
		("color-correct", "Toggle decoding color correction. 2 == full (fountain mode only). 1 == simple. 0 == off.", cxxopts::value<int>()->default_value("2"))
		("color-correction-file", "Debug -- save color correction matrix generated during fountain decode, or use it for non-fountain decodes", cxxopts::value<string>())
		("encode", "Run the encoder!", cxxopts::value<bool>())
		("no-deskew", "Skip the deskew step -- treat input image as already extracted.", cxxopts::value<bool>())
		("no-fountain", "Disable fountain encode/decode. Will also disable compression.", cxxopts::value<bool>())
		("undistort", "Attempt undistort step -- useful if image distortion is significant.", cxxopts::value<bool>())
		("preprocess", "Run sharpen filter on the input image. 1 == on. 0 == off. -1 == guess.", cxxopts::value<int>()->default_value("-1"))
		("h,help", "Print usage")
	;
	options.show_positional_help();
	options.parse_positional({"in"});
	options.positional_help("<in...>");

	auto result = options.parse(argc, argv);
	if (result.count("help"))
	{
		std::cerr << options.help() << std::endl;
		exit(0);
	}


Review comment (suggestion):
I'm not sure about `-n`, but `-e` is already used for `ecc`. And I've seen unixtools commit worse crimes against the alphabet than this.

Code after:
		int bytes = decodefun(img, shouldPreprocess, color_correct);
		if (!bytes)
			err |= 4;
	}
	return err;
}

// see also "decodefun" for non-fountain decodes, defined as a lambda inline below.
// this one needs its own function since it's a template (:
template <typename SINK>
std::function<int(cv::UMat,bool,int)> fountain_decode_fun(SINK& sink, Decoder& d)
{
	return [&sink, &d] (cv::UMat m, bool pre, int cc) {
		return d.decode_fountain(m, sink, pre, cc);
	};
}

int main(int argc, char** argv)
{
	cxxopts::Options options("cimbar encoder/decoder", "Demonstration program for cimbar codes");

	unsigned colorBits = cimbar::Config::color_bits();
	unsigned compressionLevel = cimbar::Config::compression_level();
	unsigned ecc = cimbar::Config::ecc_bytes();
	options.add_options()
		("n,encode", "Run the encoder!", cxxopts::value<bool>())
		("i,in", "Encoded pngs/jpgs/etc (for decode), or file to encode", cxxopts::value<vector<string>>())
		("o,out", "Output file prefix (encoding) or directory (decoding).", cxxopts::value<string>())
		("c,color-bits", "Color bits. [0-3]", cxxopts::value<int>()->default_value(turbo::str::str(colorBits)))
		("e,ecc", "ECC level", cxxopts::value<unsigned>()->default_value(turbo::str::str(ecc)))
		("m,mode", "Select a cimbar mode. B (the default) is new to 0.6.x. 4C is the 0.5.x config. [B,4C]", cxxopts::value<string>()->default_value("B"))
		("z,compression", "Compression level. 0 == no compression.", cxxopts::value<int>()->default_value(turbo::str::str(compressionLevel)))
		("color-correct", "Toggle decoding color correction. 2 == full (fountain mode only). 1 == simple. 0 == off.", cxxopts::value<int>()->default_value("2"))
		("color-correction-file", "Debug -- save color correction matrix generated during fountain decode, or use it for non-fountain decodes", cxxopts::value<string>())
		("no-deskew", "Skip the deskew step -- treat input image as already extracted.", cxxopts::value<bool>())
		("no-fountain", "Disable fountain encode/decode. Will also disable compression.", cxxopts::value<bool>())
		("undistort", "Attempt undistort step -- useful if image distortion is significant.", cxxopts::value<bool>())
		("preprocess", "Run sharpen filter on the input image. 1 == on. 0 == off. -1 == guess.", cxxopts::value<int>()->default_value("-1"))
		("h,help", "Print usage")
	;
	options.show_positional_help();
	options.parse_positional({"in"});
	options.positional_help("<in...>");

	auto result = options.parse(argc, argv);
	if (result.count("help"))
	{
		std::cerr << options.help() << std::endl;
		exit(0);
	}