void writeRgba3 (const char fileName[], const Rgba *pixels, int width, int height, const char comments[], const M44f &cameraTransform) { // // Write an RGBA image using class RgbaOutputFile. // Store two extra attributes in the image header: // a string and a 4x4 transformation matrix. // // - open the file // - describe the memory layout of the pixels // - store the pixels in the file // Header header (width, height); header.insert ("comments", StringAttribute (comments)); header.insert ("cameraTransform", M44fAttribute (cameraTransform)); RgbaOutputFile file (fileName, header, WRITE_RGBA); file.setFrameBuffer (pixels, 1, width); file.writePixels (height); }
void writeRgba (const char fileName[], const Rgba *pixels, int width, int height) { // // Write an RGBA image using class RgbaOutputFile. // // - open the file // - describe the memory layout of the pixels // - store the pixels in the file // RgbaOutputFile file (fileName, width, height, WRITE_RGBA); file.setFrameBuffer (pixels, 1, width); file.writePixels (height); }
void ZFnEXR::save(float* data, const char* filename, int width, int height) { Array2D<Rgba> px (height, width); for (int y = 0; y < height; ++y) { int invy = height-1-y; for (int x = 0; x < width; ++x) { Rgba &p = px[y][x]; p.r = data[(invy*width+x)*4]; p.g = data[(invy*width+x)*4+1]; p.b = data[(invy*width+x)*4+2]; p.a = data[(invy*width+x)*4+3]; } } RgbaOutputFile file (filename, width, height, WRITE_RGBA); file.setFrameBuffer (&px[0][0], 1, width); file.writePixels (height); }
void writeRgba2 (const char fileName[], const Rgba *pixels, int width, int height, const Box2i &dataWindow) { // // Write an RGBA image using class RgbaOutputFile. // Don't store the whole image in the file, but // crop it according to the given data window. // // - open the file // - describe the memory layout of the pixels // - store the pixels in the file // Box2i displayWindow (V2i (0, 0), V2i (width - 1, height - 1)); RgbaOutputFile file (fileName, displayWindow, dataWindow, WRITE_RGBA); file.setFrameBuffer (pixels, 1, width); file.writePixels (dataWindow.max.y - dataWindow.min.y + 1); }
void exrCtlExr (const char inFileName[], const char outFileName[], const std::vector<std::string> &transformNames, const AttrMap &extraAttrs, int numThreads, bool verbose) { setGlobalThreadCount (numThreads); // // Read the input file // if (verbose) cout << "reading file " << inFileName << endl; RgbaInputFile in (inFileName); const Box2i &dw = in.dataWindow(); int w = dw.max.x - dw.min.x + 1; int h = dw.max.y - dw.min.y + 1; Array2D<Rgba> inPixels (h, w); in.setFrameBuffer (&inPixels[0][0] - dw.min.x - dw.min.y * w, 1, w); in.readPixels (dw.min.y, dw.max.y); // // Apply the CTL transforms to the R, G and B channels of the input file // if (verbose) { cout << "applying CTL transforms:"; for (int i = 0; i < transformNames.size(); ++i) cout << " " << transformNames[i]; cout << endl; } Header outHeader = in.header(); Array2D<Rgba> outPixels (h, w); applyCtlExrToExr (in.header(), outHeader, inPixels, outPixels, w, h, transformNames, extraAttrs); // // Just in case one of the CTL transforms decided to mess // with the data window in the output header, avoid a crash // by resetting the data window to its original value. // outHeader.dataWindow() = in.header().dataWindow(); // // If the input pixels have an A channel, copy it into // the output pixels. // if (in.channels() & WRITE_A) { const Rgba *inPtr = &inPixels[0][0]; Rgba *outPtr = &outPixels[0][0]; size_t numPixels = w * h; for (size_t i = 0; i < numPixels; ++i) (outPtr++)->a = (inPtr++)->a; } // // Write the output file // if (verbose) cout << "writing file " << outFileName << endl; RgbaOutputFile out (outFileName, outHeader, in.channels()); out.setFrameBuffer (&outPixels[0][0] - dw.min.x - dw.min.y * w, 1, w); out.writePixels (h); }
bool writeEXRStream(const osg::Image &img, std::ostream& fout, const std::string &fileName) const { bool writeOK = true; //Obtain data from texture int width = img.s(); int height = img.t(); unsigned int pixelFormat = img.getPixelFormat(); int numComponents = img.computeNumComponents(pixelFormat); unsigned int dataType = img.getDataType(); //Validates image data //if numbers of components matches if (!( numComponents == 3 || numComponents == 4)) { writeOK = false; return false; } if (!( dataType == GL_HALF_FLOAT_ARB || dataType == GL_FLOAT)) { writeOK = false; return false; } //Create a stream to save to C_OStream outStream(&fout); //Copy data from texture to rgba pixel format Array2D<Rgba> outPixels(height,width); //If texture is half format if (dataType == GL_HALF_FLOAT_ARB) { half* pOut = (half*) img.data(); for (long i = height-1; i >= 0; i--) { for (long j = 0 ; j < width; j++) { outPixels[i][j].r = (*pOut); pOut++; outPixels[i][j].g = (*pOut); pOut++; outPixels[i][j].b = (*pOut); pOut++; if (numComponents >= 4) { outPixels[i][j].a = (*pOut); pOut++; } else { outPixels[i][j].a = 1.0f; } } } } else if (dataType == GL_FLOAT) { float* pOut = (float*) img.data(); for (long i = height-1; i >= 0; i--) { for (long j = 0 ; j < width; j++) { outPixels[i][j].r = half(*pOut); pOut++; outPixels[i][j].g = half(*pOut); pOut++; outPixels[i][j].b = half(*pOut); pOut++; if (numComponents >= 4) { outPixels[i][j].a = half(*pOut); pOut++; } else { outPixels[i][j].a = 1.0f; } } } } else { //If texture format not supported return false; } try { //Write to stream Header outHeader(width, height); RgbaOutputFile rgbaFile (outStream, outHeader, WRITE_RGBA); rgbaFile.setFrameBuffer ((&outPixels)[0][0], 1, width); rgbaFile.writePixels (height); } catch( char * str ) { writeOK = false; } return writeOK; }
void Exr::writeRgba(const string outf, const Array2D<Rgba> &pix, int w, int h) { RgbaOutputFile file (outf.c_str(), w, h, WRITE_RGBA); file.setFrameBuffer (&pix[0][0], 1, w); file.writePixels (h); }