rawls_convert.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <iostream>
  4. #include <fstream>
  5. #include <vector>
  6. #include <tuple>
  7. #include "lodepng.h"
  8. #include "rawls.h"
  9. int main(int argc, char *argv[]){
  10. std::string imageName;
  11. std::string outfileName;
  12. for (int i = 1; i < argc; ++i) {
  13. if (!strcmp(argv[i], "--image") || !strcmp(argv[i], "-image")) {
  14. imageName = argv[++i];
  15. } else if (!strcmp(argv[i], "--outfile") || !strcmp(argv[i], "-outfile")) {
  16. outfileName = argv[++i];
  17. }
  18. }
  19. if (!(rawls::HasExtension(imageName, ".rawls") || rawls::HasExtension(imageName, ".rawls_20") )){
  20. std::cout << "Unexpected `rawls` image name extension" << std::endl;
  21. return 1;
  22. }
  23. std::cout << "Read image `" << imageName << "` and save it into " << outfileName << std::endl;
  24. // create outfile
  25. if (rawls::HasExtension(outfileName, ".ppm")){
  26. rawls::convertToPPM(imageName, outfileName);
  27. }
  28. else if (rawls::HasExtension(outfileName, ".png")){
  29. rawls::convertToPNG(imageName, outfileName);
  30. }
  31. else{
  32. std::cout << "Unexpected output extension image" << std::endl;
  33. }
  34. }