// ======================================================================== // // Copyright 2009-2014 Intel Corporation // // // // Licensed under the Apache License, Version 2.0 (the "License"); // // you may not use this file except in compliance with the License. // // You may obtain a copy of the License at // // // // http://www.apache.org/licenses/LICENSE-2.0 // // // // Unless required by applicable law or agreed to in writing, software // // distributed under the License is distributed on an "AS IS" BASIS, // // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // // See the License for the specific language governing permissions and // // limitations under the License. // // ======================================================================== // #ifdef USE_OPENEXR #include "image/image.h" /* include OpenEXR headers */ #ifdef __WIN32__ #include #include #pragma comment (lib, "Half.lib") #pragma comment (lib, "Iex.lib") #pragma comment (lib, "IlmImf.lib") #pragma comment (lib, "IlmThread.lib") #pragma comment (lib, "Imath.lib") #pragma comment (lib, "zlib.lib") #else #include #include #endif namespace embree { /*! load an EXR file from disk */ Ref loadExr(const FileName& filename) { Imf::RgbaInputFile file (filename.c_str()); Imath::Box2i dw = file.dataWindow(); ssize_t width = dw.max.x - dw.min.x + 1; ssize_t height = dw.max.y - dw.min.y + 1; Imf::Array2D pixels(height, width); file.setFrameBuffer (&pixels[0][0] - dw.min.x - dw.min.y * width, 1, width); file.readPixels (dw.min.y, dw.max.y); Ref img = new Image3f(width,height,filename); if (file.lineOrder() == Imf::INCREASING_Y) { for (ssize_t y=0; yset(x,y,Color4(c.r,c.g,c.b,c.a)); } } } else { for (ssize_t y=0; yset(x,height-y-1,Color4(c.r,c.g,c.b,c.a)); } } } return img; } /*! store an EXR file to disk */ void storeExr(const Ref& img, const FileName& filename) { Imf::Array2D pixels(img->height,img->width); for (size_t y=0; yheight; y++) { for (size_t x=0; xwidth; x++) { const Color4 c = img->get(x,y); pixels[y][x] = Imf::Rgba(c.r,c.g,c.b,c.a); } } Imf::RgbaOutputFile file(filename.c_str(), img->width, img->height, Imf::WRITE_RGBA); file.setFrameBuffer(&pixels[0][0], 1, img->width); file.writePixels(img->height); } } #endif // USE_OPENEXR