Changeset View
Changeset View
Standalone View
Standalone View
source/blender/imbuf/intern/imageprocess.c
| Show First 20 Lines • Show All 332 Lines • ▼ Show 20 Lines | void nearest_interpolation(ImBuf *in, ImBuf *out, float x, float y, int xout, int yout) | ||||
| /* gcc warns these could be uninitialized, but its ok. */ | /* gcc warns these could be uninitialized, but its ok. */ | ||||
| pixel_from_buffer(out, &outI, &outF, xout, yout); | pixel_from_buffer(out, &outI, &outF, xout, yout); | ||||
| nearest_interpolation_color(in, outI, outF, x, y); | nearest_interpolation_color(in, outI, outF, x, y); | ||||
| } | } | ||||
| /*********************** Threaded image processing *************************/ | /*********************** Threaded image processing *************************/ | ||||
| static void processor_apply_func(TaskPool *__restrict pool, void *taskdata, int UNUSED(threadid)) | static void processor_apply_func(TaskPool *__restrict pool, void *taskdata) | ||||
| { | { | ||||
| void (*do_thread)(void *) = (void (*)(void *))BLI_task_pool_userdata(pool); | void (*do_thread)(void *) = (void (*)(void *))BLI_task_pool_tbb_user_data(pool); | ||||
| do_thread(taskdata); | do_thread(taskdata); | ||||
| } | } | ||||
| void IMB_processor_apply_threaded( | void IMB_processor_apply_threaded( | ||||
| int buffer_lines, | int buffer_lines, | ||||
| int handle_size, | int handle_size, | ||||
| void *init_customdata, | void *init_customdata, | ||||
| void(init_handle)(void *handle, int start_line, int tot_line, void *customdata), | void(init_handle)(void *handle, int start_line, int tot_line, void *customdata), | ||||
| void *(do_thread)(void *)) | void *(do_thread)(void *)) | ||||
| { | { | ||||
| const int lines_per_task = 64; | const int lines_per_task = 64; | ||||
| TaskScheduler *task_scheduler = BLI_task_scheduler_get(); | TaskScheduler *task_scheduler = BLI_task_scheduler_legacy_get(); | ||||
| TaskPool *task_pool; | TaskPool *task_pool; | ||||
| void *handles; | void *handles; | ||||
| int total_tasks = (buffer_lines + lines_per_task - 1) / lines_per_task; | int total_tasks = (buffer_lines + lines_per_task - 1) / lines_per_task; | ||||
| int i, start_line; | int i, start_line; | ||||
| task_pool = BLI_task_pool_create(task_scheduler, do_thread, TASK_PRIORITY_LOW); | task_pool = BLI_task_pool_tbb_create(task_scheduler, do_thread, TASK_PRIORITY_LOW); | ||||
| handles = MEM_callocN(handle_size * total_tasks, "processor apply threaded handles"); | handles = MEM_callocN(handle_size * total_tasks, "processor apply threaded handles"); | ||||
| start_line = 0; | start_line = 0; | ||||
| for (i = 0; i < total_tasks; i++) { | for (i = 0; i < total_tasks; i++) { | ||||
| int lines_per_current_task; | int lines_per_current_task; | ||||
| void *handle = ((char *)handles) + handle_size * i; | void *handle = ((char *)handles) + handle_size * i; | ||||
| if (i < total_tasks - 1) { | if (i < total_tasks - 1) { | ||||
| lines_per_current_task = lines_per_task; | lines_per_current_task = lines_per_task; | ||||
| } | } | ||||
| else { | else { | ||||
| lines_per_current_task = buffer_lines - start_line; | lines_per_current_task = buffer_lines - start_line; | ||||
| } | } | ||||
| init_handle(handle, start_line, lines_per_current_task, init_customdata); | init_handle(handle, start_line, lines_per_current_task, init_customdata); | ||||
| BLI_task_pool_push(task_pool, processor_apply_func, handle, false, NULL); | BLI_task_pool_tbb_push(task_pool, processor_apply_func, handle, false, NULL); | ||||
| start_line += lines_per_task; | start_line += lines_per_task; | ||||
| } | } | ||||
| /* work and wait until tasks are done */ | /* work and wait until tasks are done */ | ||||
| BLI_task_pool_work_and_wait(task_pool); | BLI_task_pool_tbb_work_and_wait(task_pool); | ||||
| /* Free memory. */ | /* Free memory. */ | ||||
| MEM_freeN(handles); | MEM_freeN(handles); | ||||
| BLI_task_pool_free(task_pool); | BLI_task_pool_tbb_free(task_pool); | ||||
| } | } | ||||
| typedef struct ScanlineGlobalData { | typedef struct ScanlineGlobalData { | ||||
| void *custom_data; | void *custom_data; | ||||
| ScanlineThreadFunc do_thread; | ScanlineThreadFunc do_thread; | ||||
| int scanlines_per_task; | int scanlines_per_task; | ||||
| int total_scanlines; | int total_scanlines; | ||||
| } ScanlineGlobalData; | } ScanlineGlobalData; | ||||
| static void processor_apply_scanline_func(TaskPool *__restrict pool, | static void processor_apply_scanline_func(TaskPool *__restrict pool, void *taskdata) | ||||
| void *taskdata, | |||||
| int UNUSED(threadid)) | |||||
| { | { | ||||
| ScanlineGlobalData *data = BLI_task_pool_userdata(pool); | ScanlineGlobalData *data = BLI_task_pool_tbb_user_data(pool); | ||||
| int start_scanline = POINTER_AS_INT(taskdata); | int start_scanline = POINTER_AS_INT(taskdata); | ||||
| int num_scanlines = min_ii(data->scanlines_per_task, data->total_scanlines - start_scanline); | int num_scanlines = min_ii(data->scanlines_per_task, data->total_scanlines - start_scanline); | ||||
| data->do_thread(data->custom_data, start_scanline, num_scanlines); | data->do_thread(data->custom_data, start_scanline, num_scanlines); | ||||
| } | } | ||||
| void IMB_processor_apply_threaded_scanlines(int total_scanlines, | void IMB_processor_apply_threaded_scanlines(int total_scanlines, | ||||
| ScanlineThreadFunc do_thread, | ScanlineThreadFunc do_thread, | ||||
| void *custom_data) | void *custom_data) | ||||
| { | { | ||||
| const int scanlines_per_task = 64; | const int scanlines_per_task = 64; | ||||
| ScanlineGlobalData data; | ScanlineGlobalData data; | ||||
| data.custom_data = custom_data; | data.custom_data = custom_data; | ||||
| data.do_thread = do_thread; | data.do_thread = do_thread; | ||||
| data.scanlines_per_task = scanlines_per_task; | data.scanlines_per_task = scanlines_per_task; | ||||
| data.total_scanlines = total_scanlines; | data.total_scanlines = total_scanlines; | ||||
| const int total_tasks = (total_scanlines + scanlines_per_task - 1) / scanlines_per_task; | const int total_tasks = (total_scanlines + scanlines_per_task - 1) / scanlines_per_task; | ||||
| TaskScheduler *task_scheduler = BLI_task_scheduler_get(); | TaskScheduler *task_scheduler = BLI_task_scheduler_legacy_get(); | ||||
| TaskPool *task_pool = BLI_task_pool_create(task_scheduler, &data, TASK_PRIORITY_LOW); | TaskPool *task_pool = BLI_task_pool_tbb_create(task_scheduler, &data, TASK_PRIORITY_LOW); | ||||
| for (int i = 0, start_line = 0; i < total_tasks; i++) { | for (int i = 0, start_line = 0; i < total_tasks; i++) { | ||||
| BLI_task_pool_push( | BLI_task_pool_tbb_push( | ||||
| task_pool, processor_apply_scanline_func, POINTER_FROM_INT(start_line), false, NULL); | task_pool, processor_apply_scanline_func, POINTER_FROM_INT(start_line), false, NULL); | ||||
| start_line += scanlines_per_task; | start_line += scanlines_per_task; | ||||
| } | } | ||||
| /* work and wait until tasks are done */ | /* work and wait until tasks are done */ | ||||
| BLI_task_pool_work_and_wait(task_pool); | BLI_task_pool_tbb_work_and_wait(task_pool); | ||||
| /* Free memory. */ | /* Free memory. */ | ||||
| BLI_task_pool_free(task_pool); | BLI_task_pool_tbb_free(task_pool); | ||||
| } | } | ||||
| /* Alpha-under */ | /* Alpha-under */ | ||||
| void IMB_alpha_under_color_float(float *rect_float, int x, int y, float backcol[3]) | void IMB_alpha_under_color_float(float *rect_float, int x, int y, float backcol[3]) | ||||
| { | { | ||||
| size_t a = ((size_t)x) * y; | size_t a = ((size_t)x) * y; | ||||
| float *fp = rect_float; | float *fp = rect_float; | ||||
| ▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines | |||||