! read PFM file from disk */
| 19 | { |
| 20 | /*! read PFM file from disk */ |
| 21 | Ref<Image> loadEXR(const FileName& fileName) |
| 22 | { |
| 23 | float* rgba; // width * height * RGBA |
| 24 | int width; |
| 25 | int height; |
| 26 | const char* err = NULL; // or nullptr in C++11 |
| 27 | |
| 28 | int ret = LoadEXR(&rgba, &width, &height, fileName.str().c_str(), &err); |
| 29 | if (ret != TINYEXR_SUCCESS) { |
| 30 | if (err) { |
| 31 | std::cerr << "ERR: " << err; |
| 32 | FreeEXRErrorMessage(err); |
| 33 | } |
| 34 | THROW_RUNTIME_ERROR("Could not load image " + fileName.str()) |
| 35 | } |
| 36 | |
| 37 | /* create image and fill with data */ |
| 38 | Ref<Image> img = new Image4f(width,height,fileName); |
| 39 | |
| 40 | for (ssize_t y=0; y<height; y++) { |
| 41 | for (ssize_t x=0; x<width; x++) { |
| 42 | float* pix = rgba + (y * width + x) * 4; |
| 43 | img->set(x,y,Color4(pix[0],pix[1],pix[2],1.0f)); |
| 44 | } |
| 45 | } |
| 46 | free(rgba); |
| 47 | return img; |
| 48 | } |
| 49 | |
| 50 | /*! store PFM file to disk */ |
| 51 | void storeEXR(const Ref<Image>& img, const FileName& fileName) |
no test coverage detected