diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-08-07 20:47:46 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-08-07 20:47:46 +0400 |
commit | 6cf1a9834b82ce18d5b5358fe431b48037f1bca4 (patch) | |
tree | 5f26a61e25eb477261994a5fb38d909813cff157 /source/blender | |
parent | 258b4a8dad5b357b465a14a3e3a32fe6fafcd767 (diff) |
Made image buffer threaded processor generic function,
so color management could use the same routines.
Should be no functional changes.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/sequencer.c | 94 | ||||
-rw-r--r-- | source/blender/imbuf/IMB_imbuf.h | 6 | ||||
-rw-r--r-- | source/blender/imbuf/intern/imageprocess.c | 50 |
3 files changed, 104 insertions, 46 deletions
diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index 869b8a0df6a..02ae9566eed 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -1646,6 +1646,12 @@ static void color_balance_float_float(Sequence *seq, float *rect_float, int widt } } +typedef struct ColorBalanceInitData { + Sequence *seq; + ImBuf *ibuf; + float mul; +} ColorBalanceInitData; + typedef struct ColorBalanceThread { Sequence *seq; float mul; @@ -1656,6 +1662,28 @@ typedef struct ColorBalanceThread { float *rect_float; } ColorBalanceThread; +static void color_balance_init_handle(void *handle_v, int start_line, int tot_line, void *init_data_v) +{ + ColorBalanceThread *handle = (ColorBalanceThread *) handle_v; + ColorBalanceInitData *init_data = (ColorBalanceInitData *) init_data_v; + ImBuf *ibuf = init_data->ibuf; + + int offset = 4 * start_line * ibuf->x; + + memset(handle, 0, sizeof(ColorBalanceThread)); + + handle->seq = init_data->seq; + handle->mul = init_data->mul; + handle->width = ibuf->x; + handle->height = tot_line; + + if (ibuf->rect) + handle->rect = (unsigned char *) ibuf->rect + offset; + + if (ibuf->rect_float) + handle->rect_float = ibuf->rect_float + offset; +} + static void *color_balance_do_thread(void *thread_data_v) { ColorBalanceThread *thread_data = (ColorBalanceThread *) thread_data_v; @@ -1680,62 +1708,36 @@ static void *color_balance_do_thread(void *thread_data_v) static void color_balance(Sequence *seq, ImBuf *ibuf, float mul) { - int i, tot_thread = BLI_system_thread_count(); - int start_line, tot_line; - ListBase threads; - ColorBalanceThread handles[BLENDER_MAX_THREADS]; + if (!ibuf->rect_float && seq->flag & SEQ_MAKE_FLOAT) + imb_addrectfloatImBuf(ibuf); - if (!BLI_thread_is_main()) { + if (BLI_thread_is_main()) { /* color balance could have been called from prefetching job which * is already multithreaded, so doing threading here makes no sense */ - tot_thread = 1; - } + ColorBalanceInitData init_data; - if (!ibuf->rect_float && seq->flag & SEQ_MAKE_FLOAT) - imb_addrectfloatImBuf(ibuf); - - if (tot_thread > 1) - BLI_init_threads(&threads, color_balance_do_thread, tot_thread); - - start_line = 0; - tot_line = ((float)(ibuf->y / tot_thread)) + 0.5f; - - for (i = 0; i < tot_thread; i++) { - int offset; + init_data.seq = seq; + init_data.ibuf = ibuf; + init_data.mul = mul; - handles[i].seq = seq; - handles[i].mul = mul; - handles[i].width = ibuf->x; + IMB_processor_apply_threaded(ibuf->y, sizeof(ColorBalanceThread), &init_data, + color_balance_init_handle, color_balance_do_thread); - if (i < tot_thread - 1) - handles[i].height = tot_line; - else - handles[i].height = ibuf->y - start_line; - - offset = 4 * start_line * ibuf->x; - - if (ibuf->rect) - handles[i].rect = (unsigned char *)ibuf->rect + offset; - else - handles[i].rect = NULL; + } + else { + ColorBalanceThread handle; - if (ibuf->rect_float) - handles[i].rect_float = ibuf->rect_float + offset; - else - handles[i].rect_float = NULL; + handle.seq = seq; + handle.mul = mul; + handle.width = ibuf->x; + handle.height = ibuf->y; + handle.rect = (unsigned char *)ibuf->rect; + handle.rect_float = ibuf->rect_float; - if (tot_thread > 1) - BLI_insert_thread(&threads, &handles[i]); + color_balance_do_thread(&handle); +} } - start_line += tot_line; - } - - if (tot_thread > 1) - BLI_end_threads(&threads); - else - color_balance_do_thread(handles); -} /* * input preprocessing for SEQ_TYPE_IMAGE, SEQ_TYPE_MOVIE, SEQ_TYPE_MOVIECLIP and SEQ_TYPE_SCENE diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index 1a68d3c1f09..8d7c4bd55bf 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -498,5 +498,11 @@ void imb_freemipmapImBuf(struct ImBuf *ibuf); short imb_addtilesImBuf(struct ImBuf *ibuf); void imb_freetilesImBuf(struct ImBuf *ibuf); +/* threaded processors */ +void IMB_processor_apply_threaded(int buffer_lines, int handle_size, void *init_customdata, + void (init_handle) (void *handle, int start_line, int tot_line, + void *customdata), + void *(do_thread) (void *)); + #endif diff --git a/source/blender/imbuf/intern/imageprocess.c b/source/blender/imbuf/intern/imageprocess.c index e0483f70e72..3fd06a7c34d 100644 --- a/source/blender/imbuf/intern/imageprocess.c +++ b/source/blender/imbuf/intern/imageprocess.c @@ -38,7 +38,11 @@ #include <stdlib.h> +#include "MEM_guardedalloc.h" + #include "BLI_utildefines.h" +#include "BLI_threads.h" +#include "BLI_listbase.h" #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" @@ -446,3 +450,49 @@ void neareast_interpolation(ImBuf *in, ImBuf *out, float x, float y, int xout, i neareast_interpolation_color(in, outI, outF, x, y); } + +/*********************** Threaded image processing *************************/ + +void IMB_processor_apply_threaded(int buffer_lines, int handle_size, void *init_customdata, + void (init_handle) (void *handle, int start_line, int tot_line, + void *customdata), + void *(do_thread) (void *)) +{ + void *handles; + ListBase threads; + + int i, tot_thread = BLI_system_thread_count(); + int start_line, tot_line; + + handles = MEM_callocN(handle_size * tot_thread, "processor apply threaded handles"); + + if (tot_thread > 1) + BLI_init_threads(&threads, do_thread, tot_thread); + + start_line = 0; + tot_line = ((float)(buffer_lines / tot_thread)) + 0.5f; + + for (i = 0; i < tot_thread; i++) { + int cur_tot_line; + void *handle = ((char *) handles) + handle_size * i; + + if (i < tot_thread - 1) + cur_tot_line = tot_line; + else + cur_tot_line = buffer_lines - start_line; + + init_handle(handle, start_line, cur_tot_line, init_customdata); + + if (tot_thread > 1) + BLI_insert_thread(&threads, handle); + + start_line += tot_line; + } + + if (tot_thread > 1) + BLI_end_threads(&threads); + else + do_thread(handles); + + MEM_freeN(handles); +} |