void WriteHdrImage(const std::string outName, const int width, const int height, Color* image) { // Turn image from a 2D-bottom-up array of Vector3D to an top-down-array of floats float* data = new float[width*height * 3]; float* dp = data; for (int y = height - 1; y >= 0; --y) { for (int x = 0; x<width; ++x) { Color pixel = image[y*width + x]; *dp++ = pixel[0]; *dp++ = pixel[1]; *dp++ = pixel[2]; } } // Write image to file in HDR (a.k.a RADIANCE) format rgbe_header_info info; char errbuf[100] = { 0 }; FILE* fp = fopen(outName.c_str(), "wb"); info.valid = false; int r = RGBE_WriteHeader(fp, width, height, &info, errbuf); if (r != RGBE_RETURN_SUCCESS) printf("error: %s\n", errbuf); r = RGBE_WritePixels_RLE(fp, data, width, height, errbuf); if (r != RGBE_RETURN_SUCCESS) printf("error: %s\n", errbuf); fclose(fp); delete data; }
bool HdrOutput::write_scanline (int y, int z, TypeDesc format, const void *data, stride_t xstride) { data = to_native_scanline (format, data, xstride, scratch); int r = RGBE_WritePixels_RLE (m_fd, (float *)data, m_spec.width, 1, rgbe_error); if (r != RGBE_RETURN_SUCCESS) error ("%s", rgbe_error); return (r == RGBE_RETURN_SUCCESS); }
bool writeHDR(const char* path, const cv::Mat& hdr) { FILE* fp = std::fopen(path, "wb"); if (fp == NULL) { std::fprintf(stderr, "cannot write to %s\n", path); return false; } cv::Size size = hdr.size(); cv::Mat tmp = hdr.clone(); for (int y = 0; y < size.height; ++y) { for (int x = 0; x < size.width; ++x) { cv::Vec3f& c = tmp.at<cv::Vec3f>(y, x); std::swap(c[0], c[2]); } } float* data = (float*)((void*)(tmp.ptr())); RGBE_WriteHeader(fp, size.width, size.height, NULL); RGBE_WritePixels_RLE(fp, data, size.width, size.height); std::fclose(fp); return true; }