main.cpp 1.15 KB
#include <iostream>
#include <vector>
#include <stim/parser/arguments.h>
#include <stim/parser/filename.h>
#include <stim/image/image.h>

int main(int argc, char* argv[]) {
	stim::arglist args;

	args.parse(argc, argv);

	if (args.nargs() == 0) {
		std::cout << "Specify a file or file list to convert images to Netpbm." << std::endl;

	stim::filename fmask(args.arg(0));
	stim::filepath fpath(".");					//default to the current file path
	if (args.nargs() == 2) fpath = args.arg(1);	//if a destination path is specified, save there

	if (fmask.wildcards()) {					//if the given file name contains wild cards
		std::vector<stim::filename> flist;		//declare an STL vector
		flist = fmask.get_list();				//get the corresponding file list

		for (size_t i = 0; i < flist.size(); i++) {	//for each file in the list
			stim::image<unsigned char> I(flist[i].str());	//load the corresponding image
			std::string outname = fpath.str() + flist[i].prefix() + ".ppm";
			std::cout << "Saving " << outname << std::endl;
			I.save_netpbm(outname);			//save the file as a PPM
	else {
		stim::image<unsigned char> I(fmask.str()); + ".ppm");