Nori  24
hdrToLdr.cpp
1 /*
2  This file is part of Nori, a simple educational ray tracer
3 
4  Copyright (c) 2015 by Romain Prévost
5 
6  Nori is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License Version 3
8  as published by the Free Software Foundation.
9 
10  Nori is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include <nori/bitmap.h>
20 #include <filesystem/path.h>
21 
22 int main(int argc, char **argv) {
23  using namespace nori;
24 
25  try {
26 
27  // if file is passed as argument, handle it
28  if (argc == 2) {
29  std::string filename = argv[1];
30  filesystem::path path(filename);
31 
32  if (path.extension() == "exr") {
33  Bitmap bitmap(filename);
34 
35  size_t lastdot = filename.find_last_of(".");
36  std::string pngFilename = filename.substr(0, lastdot) + ".png";
37  bitmap.saveToLDR(pngFilename);
38  } else {
39  cerr << "Error: unknown file \"" << filename
40  << "\", expected an extension of type .exr" << endl;
41  }
42  }
43 
44 
45  } catch (const std::exception &e) {
46  cerr << "Fatal error: " << e.what() << endl;
47  return -1;
48  }
49  return 0;
50 }
Stores a RGB high dynamic-range bitmap.
Definition: bitmap.h:32