diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2017-11-08 02:20:59 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2017-11-08 02:20:59 +0300 |
commit | 7b1d7074817dac9d0f088e8e7e5b336bae662c36 (patch) | |
tree | 4ebd67459d2fc160d3a6c76a2509cefc68f4e89c /source/blender/imbuf | |
parent | 1b18e158025a488e1ba2446ad93c2eb563c11611 (diff) | |
parent | a0478ebe379c8384376586e2880ebc813a6afef7 (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r-- | source/blender/imbuf/intern/openexr/openexr_api.cpp | 477 | ||||
-rw-r--r-- | source/blender/imbuf/intern/openexr/openexr_multi.h | 13 | ||||
-rw-r--r-- | source/blender/imbuf/intern/openexr/openexr_stub.cpp | 18 |
3 files changed, 130 insertions, 378 deletions
diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp index 1fa3b943524..451869415e7 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.cpp +++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp @@ -374,21 +374,13 @@ static void openexr_header_metadata_callback(void *data, const char *propname, c static bool imb_save_openexr_half( - ImBuf *ibuf, const char *name, const int flags, const int totviews, - const char * (*getview)(void *base, int view_id), - ImBuf *(*getbuffer)(void *base, const int view_id)) + ImBuf *ibuf, const char *name, const int flags) { const int channels = ibuf->channels; const bool is_alpha = (channels >= 4) && (ibuf->planes == 32); const bool is_zbuf = (flags & IB_zbuffloat) && ibuf->zbuf_float != NULL; /* summarize */ const int width = ibuf->x; const int height = ibuf->y; - const bool is_multiview = (flags & IB_multiview) && ibuf->userdata; - - BLI_assert((!is_multiview) || (getview && getbuffer)); - - std::vector <string> views; - int view_id; try { @@ -397,22 +389,14 @@ static bool imb_save_openexr_half( openexr_header_compression(&header, ibuf->foptions.flag & OPENEXR_COMPRESS); openexr_header_metadata(&header, ibuf); - /* create views when possible */ - for (view_id = 0; view_id < totviews; view_id ++) - views.push_back(is_multiview ? getview(ibuf->userdata, view_id) : ""); - - if (is_multiview) - addMultiView(header, views); - - for (view_id = 0; view_id < totviews; view_id ++) { - header.channels().insert(insertViewName("R", views, view_id), Channel(HALF)); - header.channels().insert(insertViewName("G", views, view_id), Channel(HALF)); - header.channels().insert(insertViewName("B", views, view_id), Channel(HALF)); - if (is_alpha) - header.channels().insert(insertViewName("A", views, view_id), Channel(HALF)); - if (is_zbuf) // z we do as float always - header.channels().insert(insertViewName("Z", views, view_id), Channel(Imf::FLOAT)); - } + /* create channels */ + header.channels().insert("R", Channel(HALF)); + header.channels().insert("G", Channel(HALF)); + header.channels().insert("B", Channel(HALF)); + if (is_alpha) + header.channels().insert("A", Channel(HALF)); + if (is_zbuf) // z we do as float always + header.channels().insert("Z", Channel(Imf::FLOAT)); FrameBuffer frameBuffer; @@ -421,65 +405,49 @@ static bool imb_save_openexr_half( OutputFile file(file_stream, header); /* we store first everything in half array */ - std::vector<RGBAZ> pixels(height * width * totviews); + std::vector<RGBAZ> pixels(height * width); + RGBAZ *to = &pixels[0]; int xstride = sizeof(RGBAZ); int ystride = xstride * width; - for (view_id = 0; view_id < totviews; view_id ++) { - ImBuf *view_ibuf = is_multiview ? getbuffer(ibuf->userdata, view_id) : ibuf; - const size_t offset = view_id * width * height; - RGBAZ *to = &pixels[offset]; - - /* TODO (dfelinto) - * In some cases we get NULL ibufs, it needs investigation, meanwhile prevent crash - * Multiview Render + Image Editor + OpenEXR + Multi-View - */ - if (view_ibuf == NULL) { - throw std::runtime_error(std::string("Missing data to write to ") + name); - } - - /* indicate used buffers */ - frameBuffer.insert(insertViewName("R", views, view_id), Slice(HALF, (char *) &pixels[offset].r, xstride, ystride)); - frameBuffer.insert(insertViewName("G", views, view_id), Slice(HALF, (char *) &pixels[offset].g, xstride, ystride)); - frameBuffer.insert(insertViewName("B", views, view_id), Slice(HALF, (char *) &pixels[offset].b, xstride, ystride)); - if (is_alpha) - frameBuffer.insert(insertViewName("A", views, view_id), Slice(HALF, (char *) &pixels[offset].a, xstride, ystride)); - if (is_zbuf) - frameBuffer.insert(insertViewName("Z", views, view_id), Slice(Imf::FLOAT, (char *)(view_ibuf->zbuf_float + (height - 1) * width), - sizeof(float), sizeof(float) * -width)); - if (view_ibuf->rect_float) { - float *from; - - for (int i = view_ibuf->y - 1; i >= 0; i--) { - from = view_ibuf->rect_float + channels * i * width; - - for (int j = view_ibuf->x; j > 0; j--) { - to->r = from[0]; - to->g = (channels >= 2) ? from[1] : from[0]; - to->b = (channels >= 3) ? from[2] : from[0]; - to->a = (channels >= 4) ? from[3] : 1.0f; - to++; from += channels; - } + /* indicate used buffers */ + frameBuffer.insert("R", Slice(HALF, (char *) &to->r, xstride, ystride)); + frameBuffer.insert("G", Slice(HALF, (char *) &to->g, xstride, ystride)); + frameBuffer.insert("B", Slice(HALF, (char *) &to->b, xstride, ystride)); + if (is_alpha) + frameBuffer.insert("A", Slice(HALF, (char *) &to->a, xstride, ystride)); + if (is_zbuf) + frameBuffer.insert("Z", Slice(Imf::FLOAT, (char *)(ibuf->zbuf_float + (height - 1) * width), + sizeof(float), sizeof(float) * -width)); + if (ibuf->rect_float) { + float *from; + + for (int i = ibuf->y - 1; i >= 0; i--) { + from = ibuf->rect_float + channels * i * width; + + for (int j = ibuf->x; j > 0; j--) { + to->r = from[0]; + to->g = (channels >= 2) ? from[1] : from[0]; + to->b = (channels >= 3) ? from[2] : from[0]; + to->a = (channels >= 4) ? from[3] : 1.0f; + to++; from += channels; } } - else { - unsigned char *from; + } + else { + unsigned char *from; - for (int i = view_ibuf->y - 1; i >= 0; i--) { - from = (unsigned char *)view_ibuf->rect + 4 * i * width; + for (int i = ibuf->y - 1; i >= 0; i--) { + from = (unsigned char *)ibuf->rect + 4 * i * width; - for (int j = view_ibuf->x; j > 0; j--) { - to->r = srgb_to_linearrgb((float)from[0] / 255.0f); - to->g = srgb_to_linearrgb((float)from[1] / 255.0f); - to->b = srgb_to_linearrgb((float)from[2] / 255.0f); - to->a = channels >= 4 ? (float)from[3] / 255.0f : 1.0f; - to++; from += 4; - } + for (int j = ibuf->x; j > 0; j--) { + to->r = srgb_to_linearrgb((float)from[0] / 255.0f); + to->g = srgb_to_linearrgb((float)from[1] / 255.0f); + to->b = srgb_to_linearrgb((float)from[2] / 255.0f); + to->a = channels >= 4 ? (float)from[3] / 255.0f : 1.0f; + to++; from += 4; } } - - if (is_multiview) - IMB_freeImBuf(view_ibuf); } exr_printf("OpenEXR-save: Writing OpenEXR file of height %d.\n", height); @@ -498,21 +466,13 @@ static bool imb_save_openexr_half( } static bool imb_save_openexr_float( - ImBuf *ibuf, const char *name, const int flags, const int totviews, - const char * (*getview)(void *base, const int view_id), - ImBuf *(*getbuffer)(void *base, const int view_id)) + ImBuf *ibuf, const char *name, const int flags) { const int channels = ibuf->channels; const bool is_alpha = (channels >= 4) && (ibuf->planes == 32); const bool is_zbuf = (flags & IB_zbuffloat) && ibuf->zbuf_float != NULL; /* summarize */ const int width = ibuf->x; const int height = ibuf->y; - const bool is_multiview = (flags & IB_multiview) && ibuf->userdata; - - BLI_assert((!is_multiview) || (getview && getbuffer)); - - std::vector <string> views; - int view_id; try { @@ -521,22 +481,14 @@ static bool imb_save_openexr_float( openexr_header_compression(&header, ibuf->foptions.flag & OPENEXR_COMPRESS); openexr_header_metadata(&header, ibuf); - /* create views when possible */ - for (view_id = 0; view_id < totviews; view_id ++) - views.push_back(is_multiview ? getview(ibuf->userdata, view_id) : ""); - - if (is_multiview) - addMultiView(header, views); - - for (view_id = 0; view_id < totviews; view_id ++) { - header.channels().insert(insertViewName("R", views, view_id), Channel(Imf::FLOAT)); - header.channels().insert(insertViewName("G", views, view_id), Channel(Imf::FLOAT)); - header.channels().insert(insertViewName("B", views, view_id), Channel(Imf::FLOAT)); - if (is_alpha) - header.channels().insert(insertViewName("A", views, view_id), Channel(Imf::FLOAT)); - if (is_zbuf) - header.channels().insert(insertViewName("Z", views, view_id), Channel(Imf::FLOAT)); - } + /* create channels */ + header.channels().insert("R", Channel(Imf::FLOAT)); + header.channels().insert("G", Channel(Imf::FLOAT)); + header.channels().insert("B", Channel(Imf::FLOAT)); + if (is_alpha) + header.channels().insert("A", Channel(Imf::FLOAT)); + if (is_zbuf) + header.channels().insert("Z", Channel(Imf::FLOAT)); FrameBuffer frameBuffer; @@ -547,36 +499,22 @@ static bool imb_save_openexr_float( int xstride = sizeof(float) * channels; int ystride = -xstride * width; - for (view_id = 0; view_id < totviews; view_id ++) { - float *rect[4] = {NULL, NULL, NULL, NULL}; - ImBuf *view_ibuf = is_multiview ? getbuffer(ibuf->userdata, view_id) : ibuf; - - /* TODO (dfelinto) - * In some cases we get NULL ibufs, it needs investigation, meanwhile prevent crash - * Multiview Render + Image Editor + OpenEXR + Multi-View - */ - if (view_ibuf == NULL) { - throw std::runtime_error(std::string("Missing data to write to ") + name); - } + /* last scanline, stride negative */ + float *rect[4] = {NULL, NULL, NULL, NULL}; + rect[0] = ibuf->rect_float + channels * (height - 1) * width; + rect[1] = (channels >= 2) ? rect[0] + 1 : rect[0]; + rect[2] = (channels >= 3) ? rect[0] + 2 : rect[0]; + rect[3] = (channels >= 4) ? rect[0] + 3 : rect[0]; /* red as alpha, is this needed since alpha isn't written? */ + + frameBuffer.insert("R", Slice(Imf::FLOAT, (char *)rect[0], xstride, ystride)); + frameBuffer.insert("G", Slice(Imf::FLOAT, (char *)rect[1], xstride, ystride)); + frameBuffer.insert("B", Slice(Imf::FLOAT, (char *)rect[2], xstride, ystride)); + if (is_alpha) + frameBuffer.insert("A", Slice(Imf::FLOAT, (char *)rect[3], xstride, ystride)); + if (is_zbuf) + frameBuffer.insert("Z", Slice(Imf::FLOAT, (char *) (ibuf->zbuf_float + (height - 1) * width), + sizeof(float), sizeof(float) * -width)); - /* last scanline, stride negative */ - rect[0] = view_ibuf->rect_float + channels * (height - 1) * width; - rect[1] = (channels >= 2) ? rect[0] + 1 : rect[0]; - rect[2] = (channels >= 3) ? rect[0] + 2 : rect[0]; - rect[3] = (channels >= 4) ? rect[0] + 3 : rect[0]; /* red as alpha, is this needed since alpha isn't written? */ - - frameBuffer.insert(insertViewName("R", views, view_id), Slice(Imf::FLOAT, (char *)rect[0], xstride, ystride)); - frameBuffer.insert(insertViewName("G", views, view_id), Slice(Imf::FLOAT, (char *)rect[1], xstride, ystride)); - frameBuffer.insert(insertViewName("B", views, view_id), Slice(Imf::FLOAT, (char *)rect[2], xstride, ystride)); - if (is_alpha) - frameBuffer.insert(insertViewName("A", views, view_id), Slice(Imf::FLOAT, (char *)rect[3], xstride, ystride)); - if (is_zbuf) - frameBuffer.insert(insertViewName("Z", views, view_id), Slice(Imf::FLOAT, (char *) (view_ibuf->zbuf_float + (height - 1) * width), - sizeof(float), sizeof(float) * -width)); - - if (is_multiview) - IMB_freeImBuf(view_ibuf); - } file.setFrameBuffer(frameBuffer); file.writePixels(height); } @@ -599,50 +537,16 @@ int imb_save_openexr(struct ImBuf *ibuf, const char *name, int flags) } if (ibuf->foptions.flag & OPENEXR_HALF) - return (int) imb_save_openexr_half(ibuf, name, flags, 1, NULL, NULL); + return (int) imb_save_openexr_half(ibuf, name, flags); else { /* when no float rect, we save as half (16 bits is sufficient) */ if (ibuf->rect_float == NULL) - return (int) imb_save_openexr_half(ibuf, name, flags, 1, NULL, NULL); + return (int) imb_save_openexr_half(ibuf, name, flags); else - return (int) imb_save_openexr_float(ibuf, name, flags, 1, NULL, NULL); + return (int) imb_save_openexr_float(ibuf, name, flags); } } -static bool imb_save_openexr_multiview( - ImBuf *ibuf, const char *name, const int flags, const int totviews, - const char *(*getview)(void *base, const int view_id), - ImBuf *(*getbuffer)(void *base, const int view_id)) -{ - if (flags & IB_mem) { - printf("OpenEXR-save: Create multiview EXR in memory CURRENTLY NOT SUPPORTED !\n"); - imb_addencodedbufferImBuf(ibuf); - ibuf->encodedsize = 0; - return false; - } - - if (ibuf->foptions.flag & OPENEXR_HALF) - return imb_save_openexr_half(ibuf, name, flags, totviews, getview, getbuffer); - else { - /* when no float rect, we save as half (16 bits is sufficient) */ - if (ibuf->rect_float == NULL) - return imb_save_openexr_half(ibuf, name, flags, totviews, getview, getbuffer); - else - return imb_save_openexr_float(ibuf, name, flags, totviews, getview, getbuffer); - } -} - -/* Save single-layer multiview OpenEXR - * If we have more multiview formats in the future, the function below could be incorporated - * in our ImBuf write functions, meanwhile this is an OpenEXR special case only */ -bool IMB_exr_multiview_save( - ImBuf *ibuf, const char *name, const int flags, const int totviews, - const char *(*getview)(void *base, const int view_id), - ImBuf *(*getbuffer)(void *base, const int view_id)) -{ - return imb_save_openexr_multiview(ibuf, name, flags, totviews, getview, getbuffer); -} - /* ********************* Nicer API, MultiLayer and with Tile file support ************************************ */ /* naming rules: @@ -841,7 +745,7 @@ void IMB_exr_add_channel(void *handle, if (layname && layname[0] != '\0') { imb_exr_insert_view_name(echan->name, echan->m->name.c_str(), echan->m->view.c_str()); } - else if (data->multiView->size() > 1) { + else if (data->multiView->size() >= 1) { std::string raw_name = insertViewName(echan->m->name, *data->multiView, echan->view_id); BLI_strncpy(echan->name, raw_name.c_str(), sizeof(echan->name)); } @@ -1071,7 +975,7 @@ float *IMB_exr_channel_rect(void *handle, const char *layname, const char *pass imb_exr_insert_view_name(temp_buf, name, viewname); BLI_strncpy(name, temp_buf, sizeof(name)); } - else if (data->multiView->size() > 1) { + else if (data->multiView->size() >= 1) { const int view_id = std::max(0, imb_exr_get_multiView_id(*data->multiView, viewname)); std::string raw_name = insertViewName(name, *data->multiView, view_id); BLI_strncpy(name, raw_name.c_str(), sizeof(name)); @@ -1199,64 +1103,10 @@ void IMB_exrtile_write_channels(void *handle, int partx, int party, int level, c } } -/* called only when handle has all views */ -void IMB_exrmultiview_write_channels(void *handle, const char *viewname) -{ - ExrHandle *data = (ExrHandle *)handle; - const int view_id = viewname ? imb_exr_get_multiView_id(*data->multiView, viewname) : -1; - int numparts = (view_id == -1 ? data->parts : view_id + 1); - std::vector <FrameBuffer> frameBuffers(numparts); - std::vector <OutputPart> outputParts; - ExrChannel *echan; - int i, part; - - if (data->channels.first == NULL) - return; - - exr_printf("\nIMB_exrmultiview_write_channels()\n"); - - for (echan = (ExrChannel *)data->channels.first; echan; echan = echan->next) { - if (view_id != -1 && echan->view_id != view_id) - continue; - - part = (view_id == -1 ? echan->m->part_number : echan->view_id); - - /* last scanline, stride negative */ - float *rect = echan->rect + echan->xstride * (data->height - 1) * data->width; - frameBuffers[part].insert(echan->m->internal_name, - Slice(Imf::FLOAT, - (char *)rect, - echan->xstride * sizeof(float), - -echan->ystride * sizeof(float)) - ); - } - - for (i = 0; i < numparts; i++) { - OutputPart out(*data->mpofile, i); - out.setFrameBuffer(frameBuffers[i]); - outputParts.push_back(out); - } - - try { - for (i = 0; i < numparts; i++) { - if (view_id != -1 && i != view_id) - continue; - - outputParts[i].writePixels(data->height); - } - } - catch (const std::exception& exc) { - std::cerr << "OpenEXR-write Multi Part: ERROR: " << exc.what() << std::endl; - } -} - void IMB_exr_read_channels(void *handle) { ExrHandle *data = (ExrHandle *)handle; - ExrChannel *echan; int numparts = data->ifile->parts(); - std::vector<FrameBuffer> frameBuffers(numparts); - std::vector<InputPart> inputParts; /* check if exr was saved with previous versions of blender which flipped images */ const StringAttribute *ta = data->ifile->header(0).findTypedAttribute <StringAttribute> ("BlenderMultiChannel"); @@ -1264,37 +1114,56 @@ void IMB_exr_read_channels(void *handle) exr_printf("\nIMB_exr_read_channels\n%s %-6s %-22s \"%s\"\n---------------------------------------------------------------------\n", "p", "view", "name", "internal_name"); - for (echan = (ExrChannel *)data->channels.first; echan; echan = echan->next) { - exr_printf("%d %-6s %-22s \"%s\"\n", echan->m->part_number, echan->m->view.c_str(), echan->m->name.c_str(), echan->m->internal_name.c_str()); + for (int i = 0; i < numparts; i++) { + /* Read part header. */ + InputPart in(*data->ifile, i); + Header header = in.header(); + Box2i dw = header.dataWindow(); + + /* Insert all matching channel into framebuffer. */ + FrameBuffer frameBuffer; + ExrChannel *echan; + + for (echan = (ExrChannel *)data->channels.first; echan; echan = echan->next) { + if(echan->m->part_number != i) { + continue; + } + + exr_printf("%d %-6s %-22s \"%s\"\n", echan->m->part_number, echan->m->view.c_str(), echan->m->name.c_str(), echan->m->internal_name.c_str()); + + if (echan->rect) { + float *rect = echan->rect; + size_t xstride = echan->xstride * sizeof(float); + size_t ystride = echan->ystride * sizeof(float); + + if (!flip) { + /* inverse correct first pixel for datawindow coordinates */ + rect -= echan->xstride * (dw.min.x - dw.min.y * data->width); + /* move to last scanline to flip to Blender convention */ + rect += echan->xstride * (data->height - 1) * data->width; + ystride = -ystride; + } + else { + /* inverse correct first pixel for datawindow coordinates */ + rect -= echan->xstride * (dw.min.x + dw.min.y * data->width); + } - if (echan->rect) { - if (flip) - frameBuffers[echan->m->part_number].insert(echan->m->internal_name, Slice(Imf::FLOAT, (char *)echan->rect, - echan->xstride * sizeof(float), echan->ystride * sizeof(float))); + frameBuffer.insert(echan->m->internal_name, Slice(Imf::FLOAT, (char *)rect, xstride, ystride)); + } else - frameBuffers[echan->m->part_number].insert(echan->m->internal_name, Slice(Imf::FLOAT, (char *)(echan->rect + echan->xstride * (data->height - 1) * data->width), - echan->xstride * sizeof(float), -echan->ystride * sizeof(float))); + printf("warning, channel with no rect set %s\n", echan->m->internal_name.c_str()); } - else - printf("warning, channel with no rect set %s\n", echan->m->internal_name.c_str()); - } - - for (int i = 0; i < numparts; i++) { - InputPart in (*data->ifile, i); - in.setFrameBuffer(frameBuffers[i]); - inputParts.push_back(in); - } - try { - for (int i = 0; i < numparts; i++) { - Header header = inputParts[i].header(); - exr_printf("readPixels:readPixels[%d]: min.y: %d, max.y: %d\n", i, header.dataWindow().min.y, header.dataWindow().max.y); - inputParts[i].readPixels(header.dataWindow().min.y, header.dataWindow().max.y); - inputParts[i].readPixels(0, data->height - 1); + /* Read pixels. */ + try { + in.setFrameBuffer(frameBuffer); + exr_printf("readPixels:readPixels[%d]: min.y: %d, max.y: %d\n", i, dw.min.y, dw.max.y); + in.readPixels(dw.min.y, dw.max.y); + } + catch (const std::exception& exc) { + std::cerr << "OpenEXR-readPixels: ERROR: " << exc.what() << std::endl; + break; } - } - catch (const std::exception& exc) { - std::cerr << "OpenEXR-readPixels: ERROR: " << exc.what() << std::endl; } } @@ -1336,69 +1205,6 @@ void IMB_exr_multilayer_convert(void *handle, void *base, } } -void IMB_exr_multiview_convert(void *handle, void *base, - void (*addview)(void *base, const char *str), - void (*addbuffer)(void *base, const char *str, ImBuf *ibuf, const int frame), - const int frame) -{ - ExrHandle *data = (ExrHandle *)handle; - MultiPartInputFile *file = data->ifile; - ExrLayer *lay; - ExrPass *pass; - ImBuf *ibuf = NULL; - const bool is_alpha = exr_has_alpha(*file); - Box2i dw = file->header(0).dataWindow(); - const size_t width = dw.max.x - dw.min.x + 1; - const size_t height = dw.max.y - dw.min.y + 1; - const bool is_depth = exr_has_zbuffer(*file); - - /* add views to RenderResult */ - for (StringVector::const_iterator i = data->multiView->begin(); i != data->multiView->end(); ++i) { - addview(base, (*i).c_str()); - } - - if (BLI_listbase_is_empty(&data->layers)) { - printf("cannot convert multiviews, no views in handle\n"); - return; - } - - /* there is one float/pass per layer (layer here is a view) */ - BLI_assert(BLI_listbase_count_ex(&data->layers, 2) == 1); - lay = (ExrLayer *)data->layers.first; - for (pass = (ExrPass *)lay->passes.first; pass; pass = pass->next) { - if (STREQ(pass->chan_id, "RGB") || STREQ(pass->chan_id, "RGBA")) { - ibuf = IMB_allocImBuf(width, height, is_alpha ? 32 : 24, IB_rectfloat); - - if (!ibuf) { - printf("error creating multiview buffer\n"); - return; - } - - IMB_buffer_float_from_float( - ibuf->rect_float, pass->rect, pass->totchan, - IB_PROFILE_LINEAR_RGB, IB_PROFILE_LINEAR_RGB, false, - ibuf->x, ibuf->y, ibuf->x, ibuf->x); - - if (hasXDensity(file->header(0))) { - ibuf->ppm[0] = xDensity(file->header(0)) * 39.3700787f; - ibuf->ppm[1] = ibuf->ppm[0] * (double)file->header(0).pixelAspectRatio(); - } - - if (is_depth) { - ExrPass *zpass; - for (zpass = (ExrPass *)lay->passes.first; zpass; zpass = zpass->next) { - if (STREQ(zpass->chan_id, "Z") && STREQ(zpass->view, pass->view)) { - addzbuffloatImBuf(ibuf); - memcpy(ibuf->zbuf_float, zpass->rect, sizeof(float) * ibuf->x * ibuf->y); - } - } - } - - addbuffer(base, pass->view, ibuf, frame); - } - } -} - void IMB_exr_close(void *handle) { ExrHandle *data = (ExrHandle *)handle; @@ -1863,49 +1669,20 @@ static void imb_exr_type_by_channels(ChannelList& channels, StringVector& views, else { *r_singlelayer = true; *r_multilayer = false; - *r_multiview = false; } BLI_assert(r_singlelayer != r_multilayer); } -bool IMB_exr_has_singlelayer_multiview(void *handle) -{ - ExrHandle *data = (ExrHandle *)handle; - MultiPartInputFile *file = data->ifile; - std::set <std::string> layerNames; - const ChannelList& channels = file->header(0).channels(); - const StringAttribute *comments; - - if (exr_has_multiview(*file) == false) - return false; - - comments = file->header(0).findTypedAttribute<StringAttribute>("BlenderMultiChannel"); - - if (comments) - return false; - - /* will not include empty layer names */ - channels.layers(layerNames); - - /* returns false if any layer differs from views list */ - if (layerNames.size()) - for (std::set<string>::iterator i = layerNames.begin(); i != layerNames.end(); i++) - if (imb_exr_get_multiView_id(*data->multiView, *i) == -1) - return false; - - return true; -} - -bool IMB_exr_has_multilayer(void *handle) -{ - ExrHandle *data = (ExrHandle *)handle; - return imb_exr_is_multilayer_file(*data->ifile); -} - static bool exr_has_multiview(MultiPartInputFile& file) { - return hasMultiView(file.header(0)); + for (int p = 0; p < file.parts(); p++) { + if (hasMultiView(file.header(p))) { + return true; + } + } + + return false; } static bool exr_has_multipart_file(MultiPartInputFile& file) @@ -1929,6 +1706,12 @@ static bool imb_exr_is_multi(MultiPartInputFile& file) return false; } +bool IMB_exr_has_multilayer(void *handle) +{ + ExrHandle *data = (ExrHandle *)handle; + return imb_exr_is_multi(*data->ifile); +} + struct ImBuf *imb_load_openexr(const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE]) { struct ImBuf *ibuf = NULL; diff --git a/source/blender/imbuf/intern/openexr/openexr_multi.h b/source/blender/imbuf/intern/openexr/openexr_multi.h index 0fa0f64bdce..d9517d13cc4 100644 --- a/source/blender/imbuf/intern/openexr/openexr_multi.h +++ b/source/blender/imbuf/intern/openexr/openexr_multi.h @@ -68,7 +68,6 @@ float *IMB_exr_channel_rect(void *handle, const char *layname, const char *pass void IMB_exr_read_channels(void *handle); void IMB_exr_write_channels(void *handle); void IMB_exrtile_write_channels(void *handle, int partx, int party, int level, const char *viewname); -void IMB_exrmultiview_write_channels(void *handle, const char *viewname); void IMB_exr_clear_channels(void *handle); void IMB_exr_multilayer_convert( @@ -78,23 +77,11 @@ void IMB_exr_multilayer_convert( void (*addpass)(void *base, void *lay, const char *str, float *rect, int totchan, const char *chan_id, const char *view)); -void IMB_exr_multiview_convert( - void *handle, void *base, - void (*addview)(void *base, const char *str), - void (*addbuffer)(void *base, const char *str, struct ImBuf *ibuf, const int frame), - const int frame); - -bool IMB_exr_multiview_save( - struct ImBuf *ibuf, const char *name, const int flags, const int totviews, - const char *(*getview)(void *base, int view_id), - struct ImBuf *(*getbuffer)(void *base, const int view_id)); - void IMB_exr_close(void *handle); void IMB_exr_add_view(void *handle, const char *name); bool IMB_exr_has_multilayer(void *handle); -bool IMB_exr_has_singlelayer_multiview(void *handle); #ifdef __cplusplus } // extern "C" diff --git a/source/blender/imbuf/intern/openexr/openexr_stub.cpp b/source/blender/imbuf/intern/openexr/openexr_stub.cpp index 498e246a915..05fddcb5fa5 100644 --- a/source/blender/imbuf/intern/openexr/openexr_stub.cpp +++ b/source/blender/imbuf/intern/openexr/openexr_stub.cpp @@ -48,7 +48,6 @@ float *IMB_exr_channel_rect (void * /*handle*/, const char * /*layname*/ void IMB_exr_read_channels (void * /*handle*/) { } void IMB_exr_write_channels (void * /*handle*/) { } void IMB_exrtile_write_channels (void * /*handle*/, int /*partx*/, int /*party*/, int /*level*/, const char * /*viewname*/) { } -void IMB_exrmultiview_write_channels(void * /*handle*/, const char * /*viewname*/) { } void IMB_exr_clear_channels (void * /*handle*/) { } void IMB_exr_multilayer_convert( @@ -60,24 +59,7 @@ void IMB_exr_multilayer_convert( { } -void IMB_exr_multiview_convert( - void * /*handle*/, void * /*base*/, - void (* /*addview*/)(void *base, const char *str), - void (* /*addbuffer*/)(void *base, const char *str, struct ImBuf *ibuf, const int frame), - const int /*frame*/) -{ -} - -bool IMB_exr_multiview_save( - struct ImBuf * /*ibuf*/, const char * /*name*/, const int /*flags*/, const int /*totviews*/, - const char *(* /*getview*/)(void *base, const int view_id), - struct ImBuf *(* /*getbuffer*/)(void *base, const int view_id)) -{ - return false; -} - void IMB_exr_close (void * /*handle*/) { } void IMB_exr_add_view(void * /*handle*/, const char * /*name*/) { } bool IMB_exr_has_multilayer(void * /*handle*/) { return false; } -bool IMB_exr_has_singlelayer_multiview(void * /*handle*/) { return false; } |