From 64114e5c95ab2dda48fb6b933c5b65f3adf50a86 Mon Sep 17 00:00:00 2001 From: Steve Meyfroidt Date: Wed, 20 Aug 2025 20:11:37 +0100 Subject: [PATCH] Refactor to expose savePixels This minor refactor allows pixels to be fetched from a GPU FBO, then to save those pixels as an EXR file on the CPU without roundtripping through an ofFloatImage, which depends on OpenGL. Which means that the slow "save to disk" process can happen on a worker thread once the pixels have been fetched. --- src/ofxTinyEXR.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/ofxTinyEXR.cpp b/src/ofxTinyEXR.cpp index e5ec789..2920de2 100644 --- a/src/ofxTinyEXR.cpp +++ b/src/ofxTinyEXR.cpp @@ -335,15 +335,15 @@ bool ofxTinyEXR::loadImage(ofFloatImage & image, const string filepath){ } */ -bool ofxTinyEXR::saveImage( const ofFloatImage & img, string filepath){ +bool ofxTinyEXR::savePixels( const ofFloatPixels & pixels, string filepath){ string filepath_full =ofToDataPath(filepath); const char * filename = filepath_full.c_str(); - const float * data = img.getPixels().getData(); - int width = img.getPixels().getWidth(); - int height = img.getPixels().getHeight(); - int components = img.getPixels().getNumChannels(); + const float * data = pixels.getData(); + int width = pixels.getWidth(); + int height = pixels.getHeight(); + int components = pixels.getNumChannels(); int save_as_fp16 = 0; // save as float, not half const char* err = NULL; // or nullptr in C++11 @@ -361,6 +361,10 @@ bool ofxTinyEXR::saveImage( const ofFloatImage & img, string filepath){ return true; } +bool ofxTinyEXR::saveImage( const ofFloatImage & img, string filepath){ + return savePixels(img.getPixels(), filepath); +} + bool ofxTinyEXR::saveHDRImage( const ofFloatImage & img, string filepath){ string filepath_full =ofToDataPath(filepath); @@ -386,4 +390,4 @@ bool ofxTinyEXR::saveHDRImage( const ofFloatImage & img, string filepath){ } return true; -} \ No newline at end of file +}