rawls_h_flip.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <stdio.h>
  2. #include "rawls.h"
  3. int main(int argc, char *argv[]){
  4. std::string imageName;
  5. std::string outfileName;
  6. for (int i = 1; i < argc; ++i) {
  7. if (!strcmp(argv[i], "--image") || !strcmp(argv[i], "-image")) {
  8. imageName = argv[++i];
  9. } else if (!strcmp(argv[i], "--outfile") || !strcmp(argv[i], "-outfile")) {
  10. outfileName = argv[++i];
  11. }
  12. }
  13. // extract data from image
  14. unsigned width, height, nbChanels;
  15. float* buffer;
  16. float* outputBuffer;
  17. std::tuple<unsigned, unsigned, unsigned, float*> data = rawls::getDataRAWLS(imageName);
  18. width = std::get<0>(data);
  19. height = std::get<1>(data);
  20. nbChanels = std::get<2>(data);
  21. buffer = std::get<3>(data);
  22. outputBuffer = new float[width * height * nbChanels];
  23. for(unsigned y = 0; y < height; y++){
  24. for(unsigned x = 0; x < width; x++) {
  25. unsigned reversedWidth = width - x;
  26. for(unsigned j = 0; j < nbChanels; j++){
  27. float value = buffer[nbChanels * width * y + nbChanels * reversedWidth + j];
  28. outputBuffer[nbChanels * width * y + nbChanels * x + j] = value;
  29. }
  30. }
  31. }
  32. // create outfile
  33. if (rawls::HasExtension(outfileName, ".ppm")){
  34. rawls::saveAsPPM(width, height, nbChanels, outputBuffer, outfileName);
  35. }
  36. else if (rawls::HasExtension(outfileName, ".png")){
  37. rawls::saveAsPNG(width, height, nbChanels, outputBuffer, outfileName);
  38. }
  39. else if (rawls::HasExtension(outfileName, ".rawls") || rawls::HasExtension(outfileName, ".rawls_20")){
  40. // need to get comments from an image
  41. std::string comments = rawls::getCommentsRAWLS(imageName);
  42. // Here no gamma conversion is done, only mean of samples
  43. rawls::saveAsRAWLS(width, height, nbChanels, comments, outputBuffer, outfileName);
  44. }
  45. else{
  46. std::cout << "Unexpected output extension image" << std::endl;
  47. }
  48. }