Page MenuHome
Paste P1051

(An Untitled Masterwork)
ActivePublic

Authored by Brecht Van Lommel (brecht) on Jul 26 2019, 12:42 PM.
static void studiolight_load_equirect_image(StudioLight *sl)
{
if (sl->flag & STUDIOLIGHT_EXTERNAL_FILE) {
ImBuf *ibuf = IMB_loadiffname(sl->path, IB_multilayer, NULL);
ImBuf *specular_ibuf = NULL;
ImBuf *diffuse_ibuf = NULL;
const bool failed = (ibuf == NULL);
if (ibuf) {
if (ibuf->ftype == IMB_FTYPE_OPENEXR && ibuf->userdata) {
/* the read file is a multilayered openexr file (userdata != NULL)
* This file is currently only supported for MATCAPS where
* the first found 'diffuse' pass will be used for diffuse lighting
* and the first found 'specular' pass will be used for specular lighting */
MultilayerConvertContext ctx = {};
IMB_exr_multilayer_convert(ibuf->userdata,
&ctx,
&studiolight_multilayer_addview,
&studiolight_multilayer_addlayer,
&studiolight_multilayer_addpass);
if (ctx.diffuse_pass != NULL) {
diffuse_ibuf = IMB_allocFromBuffer(
NULL, ctx.diffuse_pass, ibuf->x, ibuf->y, ctx.num_diffuse_channels);
MEM_freeN(ctx.diffuse_pass);
}
if (ctx.specular_pass != NULL) {
specular_ibuf = IMB_allocFromBuffer(
NULL, ctx.specular_pass, ibuf->x, ibuf->y, ctx.num_specular_channels);
MEM_freeN(ctx.specular_pass);
}
IMB_exr_close(ibuf->userdata);
ibuf->userdata = NULL;
IMB_freeImBuf(ibuf);
ibuf = NULL;
}
else {
/* read file is an single layer openexr file or the read file isn't
* an openexr file */
IMB_float_from_rect(ibuf);
diffuse_ibuf = ibuf;
ibuf = NULL;
}
}
if (diffuse_ibuf == NULL) {
/* Create 1x1 diffuse buffer, in case image failed to load or if there was
* only a specular pass in the multilayer file. */
const float black[4] = {0.0f, 0.0f, 0.0f, 1.0f};
const float magenta[4] = {1.0f, 0.0f, 1.0f, 1.0f};
diffuse_ibuf = IMB_allocFromBuffer(NULL, (failed) ? magenta : black, 1, 1, 4);
}
if ((sl->flag & STUDIOLIGHT_TYPE_MATCAP)) {
sl->matcap_diffuse.ibuf = diffuse_ibuf;
sl->matcap_specular.ibuf = specular_ibuf;
if (specular_ibuf != NULL) {
sl->flag |= STUDIOLIGHT_SPECULAR_HIGHLIGHT_PASS;
}
}
else {
sl->equirect_radiance_buffer = diffuse_ibuf;
if (specular_ibuf != NULL) {
IMB_freeImBuf(specular_ibuf);
}
}
}
sl->flag |= STUDIOLIGHT_EXTERNAL_IMAGE_LOADED;
}