diff --git a/pandatool/src/pfmprogs/pfmTrans.cxx b/pandatool/src/pfmprogs/pfmTrans.cxx index 1bf5c3b4e7..b9cc398a4d 100755 --- a/pandatool/src/pfmprogs/pfmTrans.cxx +++ b/pandatool/src/pfmprogs/pfmTrans.cxx @@ -31,6 +31,7 @@ PfmTrans:: PfmTrans() { _got_transform = false; _transform = LMatrix4::ident_mat(); + _rotate = 0; add_transform_options(); @@ -39,11 +40,6 @@ PfmTrans() { "operates on it, writing the output to another pfm file. A pfm " "file contains a 2-d table of floating-point values."); - add_option - ("r", "", 0, - "Reverses the rows of the pfm data vertically.", - &PfmTrans::dispatch_none, &_got_reverse); - add_option ("z", "", 0, "Treats (0,0,0) in the pfm file as a special don't-touch value.", @@ -57,6 +53,22 @@ PfmTrans() { "change the number of points.", &PfmTrans::dispatch_int_pair, &_got_resize, &_resize); + add_option + ("rotate", "degrees", 0, + "Rotates the pfm file the specified number of degrees counterclockwise, " + "which must be a multiple of 90.", + &PfmTrans::dispatch_int, NULL, &_rotate); + + add_option + ("mirror_x", "", 0, + "Flips the pfm file about the x axis.", + &PfmTrans::dispatch_none, &_got_mirror_x); + + add_option + ("mirror_y", "", 0, + "Flips the pfm file about the y axis.", + &PfmTrans::dispatch_none, &_got_mirror_y); + add_option ("o", "filename", 50, "Specify the filename to which the resulting pfm file will be written. " @@ -104,6 +116,11 @@ PfmTrans() { //////////////////////////////////////////////////////////////////// void PfmTrans:: run() { + if ((int)(_rotate / 90) * 90 != _rotate) { + nout << "-rotate can only accept a multiple of 90 degrees.\n"; + exit(1); + } + if (_got_vis_filename) { _mesh_root = NodePath("mesh_root"); } @@ -140,8 +157,37 @@ process_pfm(const Filename &input_filename, PfmFile &file) { file.resize(_resize[0], _resize[1]); } - if (_got_reverse) { - file.reverse_rows(); + if (_rotate != 0) { + int r = (_rotate / 90) % 4; + if (r < 0) { + r += 4; + } + switch (r) { + case 0: + break; + case 1: + // Rotate 90 degrees ccw. + file.flip(true, false, true); + break; + case 2: + // Rotate 180 degrees. + file.flip(true, true, false); + break; + case 3: + // Rotate 90 degrees cw. + file.flip(false, true, true); + break; + default: + nassertr(false, false); + } + } + + if (_got_mirror_x) { + file.flip(true, false, false); + } + + if (_got_mirror_y) { + file.flip(false, true, false); } if (_got_transform) { diff --git a/pandatool/src/pfmprogs/pfmTrans.h b/pandatool/src/pfmprogs/pfmTrans.h index a9f1e125da..67eabf66e4 100755 --- a/pandatool/src/pfmprogs/pfmTrans.h +++ b/pandatool/src/pfmprogs/pfmTrans.h @@ -51,12 +51,14 @@ private: typedef pvector Filenames; Filenames _input_filenames; - bool _got_reverse; bool _got_zero_special; bool _got_vis_inverse; bool _got_vis_2d; bool _got_resize; int _resize[2]; + int _rotate; + bool _got_mirror_x; + bool _got_mirror_y; bool _got_output_filename; Filename _output_filename;