Changeset View
Changeset View
Standalone View
Standalone View
source/blender/compositor/operations/COM_ViewerOperation.cc
| /* SPDX-License-Identifier: GPL-2.0-or-later | /* SPDX-License-Identifier: GPL-2.0-or-later | ||||
| * Copyright 2011 Blender Foundation. */ | * Copyright 2011 Blender Foundation. */ | ||||
| #include "COM_ViewerOperation.h" | #include "COM_ViewerOperation.h" | ||||
| #include "BKE_image.h" | #include "BKE_image.h" | ||||
| #include "BKE_scene.h" | #include "BKE_scene.h" | ||||
| #include "COM_ExecutionSystem.h" | #include "COM_ExecutionSystem.h" | ||||
| #include "IMB_colormanagement.h" | #include "IMB_colormanagement.h" | ||||
| #include "IMB_imbuf.h" | #include "IMB_imbuf.h" | ||||
| #include "IMB_imbuf_types.h" | #include "IMB_imbuf_types.h" | ||||
| namespace blender::compositor { | #include "DNA_node_types.h" | ||||
| static int MAX_VIEWER_TRANSLATION_PADDING = 12000; | namespace blender::compositor { | ||||
| ViewerOperation::ViewerOperation() | ViewerOperation::ViewerOperation() | ||||
| { | { | ||||
| this->set_image(nullptr); | this->set_image(nullptr); | ||||
| this->set_image_user(nullptr); | this->set_image_user(nullptr); | ||||
| output_buffer_ = nullptr; | output_buffer_ = nullptr; | ||||
| depth_buffer_ = nullptr; | depth_buffer_ = nullptr; | ||||
| active_ = false; | active_ = false; | ||||
| ▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | void ViewerOperation::init_image() | ||||
| iuser.multi_index = BKE_scene_multiview_view_id_get(rd_, view_name_); | iuser.multi_index = BKE_scene_multiview_view_id_get(rd_, view_name_); | ||||
| ibuf = BKE_image_acquire_ibuf(ima, &iuser, &lock); | ibuf = BKE_image_acquire_ibuf(ima, &iuser, &lock); | ||||
| if (!ibuf) { | if (!ibuf) { | ||||
| BLI_thread_unlock(LOCK_DRAW_IMAGE); | BLI_thread_unlock(LOCK_DRAW_IMAGE); | ||||
| return; | return; | ||||
| } | } | ||||
| int padding_x = abs(canvas_.xmin) * 2; | if (ibuf->x != get_width() || ibuf->y != get_height()) { | ||||
| int padding_y = abs(canvas_.ymin) * 2; | |||||
| if (padding_x > MAX_VIEWER_TRANSLATION_PADDING) { | |||||
| padding_x = MAX_VIEWER_TRANSLATION_PADDING; | |||||
| } | |||||
| if (padding_y > MAX_VIEWER_TRANSLATION_PADDING) { | |||||
| padding_y = MAX_VIEWER_TRANSLATION_PADDING; | |||||
| } | |||||
| display_width_ = get_width() + padding_x; | |||||
| display_height_ = get_height() + padding_y; | |||||
| if (ibuf->x != display_width_ || ibuf->y != display_height_) { | |||||
| imb_freerectImBuf(ibuf); | imb_freerectImBuf(ibuf); | ||||
| imb_freerectfloatImBuf(ibuf); | imb_freerectfloatImBuf(ibuf); | ||||
| IMB_freezbuffloatImBuf(ibuf); | IMB_freezbuffloatImBuf(ibuf); | ||||
| ibuf->x = display_width_; | ibuf->x = get_width(); | ||||
| ibuf->y = display_height_; | ibuf->y = get_height(); | ||||
| /* zero size can happen if no image buffers exist to define a sensible resolution */ | /* zero size can happen if no image buffers exist to define a sensible resolution */ | ||||
| if (ibuf->x > 0 && ibuf->y > 0) { | if (ibuf->x > 0 && ibuf->y > 0) { | ||||
| imb_addrectfloatImBuf(ibuf); | imb_addrectfloatImBuf(ibuf); | ||||
| } | } | ||||
| ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID; | ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID; | ||||
| } | } | ||||
| Show All 17 Lines | |||||
| } | } | ||||
| void ViewerOperation::update_image(const rcti *rect) | void ViewerOperation::update_image(const rcti *rect) | ||||
| { | { | ||||
| if (exec_system_->is_breaked()) { | if (exec_system_->is_breaked()) { | ||||
| return; | return; | ||||
| } | } | ||||
| image_->display_offset_x = canvas_.xmin; | |||||
| image_->display_offset_y = canvas_.ymin; | |||||
| float *buffer = output_buffer_; | float *buffer = output_buffer_; | ||||
| IMB_partial_display_buffer_update(ibuf_, | IMB_partial_display_buffer_update(ibuf_, | ||||
| buffer, | buffer, | ||||
| nullptr, | nullptr, | ||||
| display_width_, | get_width(), | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| view_settings_, | view_settings_, | ||||
| display_settings_, | display_settings_, | ||||
| rect->xmin, | rect->xmin, | ||||
| rect->ymin, | rect->ymin, | ||||
| rect->xmax, | rect->xmax, | ||||
| rect->ymax); | rect->ymax); | ||||
| Show All 16 Lines | |||||
| void ViewerOperation::update_memory_buffer_partial(MemoryBuffer *UNUSED(output), | void ViewerOperation::update_memory_buffer_partial(MemoryBuffer *UNUSED(output), | ||||
| const rcti &area, | const rcti &area, | ||||
| Span<MemoryBuffer *> inputs) | Span<MemoryBuffer *> inputs) | ||||
| { | { | ||||
| if (!output_buffer_) { | if (!output_buffer_) { | ||||
| return; | return; | ||||
| } | } | ||||
| const int offset_x = area.xmin + (canvas_.xmin > 0 ? canvas_.xmin * 2 : 0); | |||||
| const int offset_y = area.ymin + (canvas_.ymin > 0 ? canvas_.ymin * 2 : 0); | |||||
| MemoryBuffer output_buffer( | MemoryBuffer output_buffer( | ||||
| output_buffer_, COM_DATA_TYPE_COLOR_CHANNELS, display_width_, display_height_); | output_buffer_, COM_DATA_TYPE_COLOR_CHANNELS, get_width(), get_height()); | ||||
| const MemoryBuffer *input_image = inputs[0]; | const MemoryBuffer *input_image = inputs[0]; | ||||
| output_buffer.copy_from(input_image, area, offset_x, offset_y); | output_buffer.copy_from(input_image, area); | ||||
| if (use_alpha_input_) { | if (use_alpha_input_) { | ||||
| const MemoryBuffer *input_alpha = inputs[1]; | const MemoryBuffer *input_alpha = inputs[1]; | ||||
| output_buffer.copy_from( | output_buffer.copy_from(input_alpha, area, 0, COM_DATA_TYPE_VALUE_CHANNELS, 3); | ||||
| input_alpha, area, 0, COM_DATA_TYPE_VALUE_CHANNELS, offset_x, offset_y, 3); | |||||
| } | } | ||||
| if (depth_buffer_) { | if (depth_buffer_) { | ||||
| MemoryBuffer depth_buffer( | MemoryBuffer depth_buffer( | ||||
| depth_buffer_, COM_DATA_TYPE_VALUE_CHANNELS, display_width_, display_height_); | depth_buffer_, COM_DATA_TYPE_VALUE_CHANNELS, get_width(), get_height()); | ||||
| const MemoryBuffer *input_depth = inputs[2]; | const MemoryBuffer *input_depth = inputs[2]; | ||||
| depth_buffer.copy_from(input_depth, area, offset_x, offset_y); | depth_buffer.copy_from(input_depth, area); | ||||
| } | } | ||||
| rcti display_area; | update_image(&area); | ||||
| BLI_rcti_init(&display_area, | |||||
| offset_x, | |||||
| offset_x + BLI_rcti_size_x(&area), | |||||
| offset_y, | |||||
| offset_y + BLI_rcti_size_y(&area)); | |||||
| update_image(&display_area); | |||||
| } | } | ||||
| void ViewerOperation::clear_display_buffer() | void ViewerOperation::clear_display_buffer() | ||||
| { | { | ||||
| BLI_assert(is_active_viewer_output()); | BLI_assert(is_active_viewer_output()); | ||||
| if (exec_system_->is_breaked()) { | if (exec_system_->is_breaked()) { | ||||
| return; | return; | ||||
| } | } | ||||
| Show All 16 Lines | |||||