From 1347642e1ba90f6971abb264576cd9df0385e561 Mon Sep 17 00:00:00 2001 From: cxgeorge <> Date: Tue, 3 Sep 2002 18:46:37 +0000 Subject: [PATCH] add resize option --- pandatool/src/imagebase/imageWriter.cxx | 38 +++++++++++++++++++++++++ pandatool/src/imagebase/imageWriter.h | 4 ++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/pandatool/src/imagebase/imageWriter.cxx b/pandatool/src/imagebase/imageWriter.cxx index 8d227c3f95..1e474a52f9 100644 --- a/pandatool/src/imagebase/imageWriter.cxx +++ b/pandatool/src/imagebase/imageWriter.cxx @@ -29,6 +29,9 @@ ImageWriter() { clear_runlines(); add_runline("[opts] 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, @@ -36,6 +39,25 @@ ImageWriter() { "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); + + 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; } @@ -47,6 +69,22 @@ ImageWriter() { //////////////////////////////////////////////////////////////////// void ImageWriter:: 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"; exit(1); diff --git a/pandatool/src/imagebase/imageWriter.h b/pandatool/src/imagebase/imageWriter.h index 7f53ede3b9..4b8ac7a46c 100644 --- a/pandatool/src/imagebase/imageWriter.h +++ b/pandatool/src/imagebase/imageWriter.h @@ -41,7 +41,9 @@ protected: virtual bool handle_args(Args &args); protected: - bool _got_output_filename; + bool _got_output_filename, _bDoResize, _bUseHighQualityFiltering; + int _newsize[2]; + double _filter_radius; Filename _output_filename; };