MCPcopy Create free account
hub / github.com/RenderKit/oidn / loadImageOIIO

Function loadImageOIIO

apps/utils/image_io.cpp:300–330  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

298
299 #ifdef OIDN_USE_OPENIMAGEIO
300 std::shared_ptr<ImageBuffer> loadImageOIIO(const DeviceRef& device,
301 const std::string& filename,
302 DataType dataType,
303 Storage storage)
304 {
305 auto in = OIIO::ImageInput::open(filename);
306 if (!in)
307 throw std::runtime_error("cannot open image file: '" + filename + "'");
308
309 const OIIO::ImageSpec& spec = in->spec();
310 const int numChannels = std::min(spec.nchannels, 3);
311
312 if (dataType == DataType::Undefined)
313 dataType = (spec.channelformat(0) == OIIO::TypeDesc::HALF) ? DataType::Float16 : DataType::Float32;
314
315 auto image = std::make_shared<ImageBuffer>(device, spec.width, spec.height, numChannels,
316 dataType, storage);
317 bool success = in->read_image(0, 0, 0, numChannels,
318 dataType == DataType::Float16 ? OIIO::TypeDesc::HALF : OIIO::TypeDesc::FLOAT, image->getHostData());
319
320 in->close();
321
322 #if OIIO_VERSION < 10903
323 OIIO::ImageInput::destroy(in);
324 #endif
325
326 if (!success)
327 throw std::runtime_error("failed to read image data");
328
329 return image;
330 }
331
332 void saveImageOIIO(const std::string& filename, const ImageBuffer& image)
333 {

Callers 1

loadImageFunction · 0.85

Calls 3

destroyFunction · 0.85
minFunction · 0.50
closeMethod · 0.45

Tested by

no test coverage detected