|
@@ -25,39 +25,29 @@
|
|
|
// output file using -o.
|
|
// output file using -o.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
ImageWriter::
|
|
ImageWriter::
|
|
|
-ImageWriter() {
|
|
|
|
|
|
|
+ImageWriter(bool allow_last_param) :
|
|
|
|
|
+ WithOutputFile(allow_last_param, false, true)
|
|
|
|
|
+{
|
|
|
clear_runlines();
|
|
clear_runlines();
|
|
|
- add_runline("[opts] outputimage");
|
|
|
|
|
|
|
+ if (_allow_last_param) {
|
|
|
|
|
+ add_runline("[opts] outputimage");
|
|
|
|
|
+ }
|
|
|
add_runline("[opts] -o outputimage");
|
|
add_runline("[opts] -o outputimage");
|
|
|
- add_runline("[opts] -s newimagesize");
|
|
|
|
|
- add_runline("[opts] -hq");
|
|
|
|
|
- add_runline("[opts] -filter_radius filter-radius");
|
|
|
|
|
|
|
|
|
|
- add_option
|
|
|
|
|
- ("o", "filename", 50,
|
|
|
|
|
- "Specify the filename to which the resulting image file will be written. "
|
|
|
|
|
- "If this is omitted, the last parameter on the command line is taken as "
|
|
|
|
|
- "the output filename.",
|
|
|
|
|
- &ImageWriter::dispatch_filename, &_got_output_filename, &_output_filename);
|
|
|
|
|
-
|
|
|
|
|
- add_option
|
|
|
|
|
- ("s", "new size", 50,
|
|
|
|
|
- "Specify the width & height of the output image using the next 2 integers. "
|
|
|
|
|
- "Ex: '-s 200,100' resizes to 200x100",
|
|
|
|
|
- &ImageWriter::dispatch_int_pair, &_bDoResize, &_newsize);
|
|
|
|
|
-
|
|
|
|
|
- add_option
|
|
|
|
|
- ("hq", "", 50,
|
|
|
|
|
- "Use High-Quality filtering to do image-resizing",
|
|
|
|
|
- &ImageWriter::dispatch_none, &_bUseHighQualityFiltering);
|
|
|
|
|
|
|
+ string o_description;
|
|
|
|
|
+ if (_allow_last_param) {
|
|
|
|
|
+ o_description =
|
|
|
|
|
+ "Specify the filename to which the resulting image file will be written. "
|
|
|
|
|
+ "If this option is omitted, the last parameter name is taken to be the "
|
|
|
|
|
+ "name of the output file.";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ o_description =
|
|
|
|
|
+ "Specify the filename to which the resulting image file will be written.";
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
add_option
|
|
add_option
|
|
|
- ("filter_radius", "filter-radius", 50,
|
|
|
|
|
- "float value specifying a filter radius to use for the High-Quality filter (ex: 1.0)",
|
|
|
|
|
- &ImageWriter::dispatch_double, NULL, &_filter_radius);
|
|
|
|
|
-
|
|
|
|
|
- _filter_radius = 1.0;
|
|
|
|
|
- _bDoResize = false;
|
|
|
|
|
|
|
+ ("o", "filename", 50, o_description,
|
|
|
|
|
+ &ImageWriter::dispatch_filename, &_got_output_filename, &_output_filename);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -69,24 +59,9 @@ ImageWriter() {
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
void ImageWriter::
|
|
void ImageWriter::
|
|
|
write_image(const PNMImage &image) {
|
|
write_image(const PNMImage &image) {
|
|
|
- if(_bDoResize) {
|
|
|
|
|
- PNMImage resized_image(_newsize[0], _newsize[1], image.get_num_channels(), image.get_maxval());
|
|
|
|
|
- if(_bUseHighQualityFiltering) {
|
|
|
|
|
- nout << "HQ filtering using filter-radius: " << _filter_radius << endl;
|
|
|
|
|
- resized_image.gaussian_filter_from(_filter_radius, image);
|
|
|
|
|
- } else {
|
|
|
|
|
- resized_image.quick_filter_from(image);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (!resized_image.write(_output_filename)) {
|
|
|
|
|
- nout << "Unable to write output image to " << _output_filename << "\n";
|
|
|
|
|
- exit(1);
|
|
|
|
|
- }
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (!image.write(_output_filename)) {
|
|
|
|
|
- nout << "Unable to write output image to " << _output_filename << "\n";
|
|
|
|
|
|
|
+ if (!image.write(get_output_filename())) {
|
|
|
|
|
+ nout << "Unable to write output image to "
|
|
|
|
|
+ << get_output_filename() << "\n";
|
|
|
exit(1);
|
|
exit(1);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -101,27 +76,19 @@ write_image(const PNMImage &image) {
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
bool ImageWriter::
|
|
bool ImageWriter::
|
|
|
handle_args(ProgramBase::Args &args) {
|
|
handle_args(ProgramBase::Args &args) {
|
|
|
- if (!_got_output_filename) {
|
|
|
|
|
- if (args.size() != 1) {
|
|
|
|
|
- nout << "You must specify the filename to write with -o, or as "
|
|
|
|
|
- << "the last parameter on the command line.\n";
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- _output_filename = Filename::from_os_specific(args[0]);
|
|
|
|
|
- _got_output_filename = true;
|
|
|
|
|
|
|
+ if (!check_last_arg(args, 0)) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- } else {
|
|
|
|
|
- if (!args.empty()) {
|
|
|
|
|
- nout << "Unexpected arguments on command line:\n";
|
|
|
|
|
- Args::const_iterator ai;
|
|
|
|
|
- for (ai = args.begin(); ai != args.end(); ++ai) {
|
|
|
|
|
- nout << (*ai) << " ";
|
|
|
|
|
- }
|
|
|
|
|
- nout << "\r";
|
|
|
|
|
- return false;
|
|
|
|
|
|
|
+ if (!args.empty()) {
|
|
|
|
|
+ nout << "Unexpected arguments on command line:\n";
|
|
|
|
|
+ Args::const_iterator ai;
|
|
|
|
|
+ for (ai = args.begin(); ai != args.end(); ++ai) {
|
|
|
|
|
+ nout << (*ai) << " ";
|
|
|
}
|
|
}
|
|
|
|
|
+ nout << "\r";
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
-
|
|
|