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_user_data(pool); | void (*do_thread)(void *) = (void (*)(void *))BLI_task_pool_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(); | |||||
| 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_create(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; | ||||
| Show All 22 Lines | |||||
| 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_user_data(pool); | ScanlineGlobalData *data = BLI_task_pool_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(); | TaskPool *task_pool = BLI_task_pool_create(&data, TASK_PRIORITY_LOW); | ||||
| TaskPool *task_pool = BLI_task_pool_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_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_work_and_wait(task_pool); | ||||
| ▲ Show 20 Lines • Show All 74 Lines • Show Last 20 Lines | |||||