瀏覽代碼

add resize option

cxgeorge 23 年之前
父節點
當前提交
1347642e1b
共有 2 個文件被更改,包括 41 次插入1 次删除
  1. 38 0
      pandatool/src/imagebase/imageWriter.cxx
  2. 3 1
      pandatool/src/imagebase/imageWriter.h

+ 38 - 0
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);

+ 3 - 1
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;
 };