diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2016-05-24 00:23:51 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2016-05-24 10:34:55 +0300 |
commit | 93b3f1c85606f3d21c60dbf9aab761a0ad71d26e (patch) | |
tree | 908bc0cf80fa81664cbd66f04b9c6bd66c3d0fc9 /source/blender/editors | |
parent | 886349fd982847466b3215f8b5eebf71ea86f3ac (diff) |
Sequencer's histogram view: OMP -> BLI_task.
New code using loop/finalize model is about 45% faster (from 4.4ms tp 2.4ms per frame,
overall playback of single shot in sequencer in this preview mode goes from 40 to 45fps).
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/space_sequencer/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/editors/space_sequencer/sequencer_scopes.c | 117 |
2 files changed, 68 insertions, 50 deletions
diff --git a/source/blender/editors/space_sequencer/CMakeLists.txt b/source/blender/editors/space_sequencer/CMakeLists.txt index 778ccf902d1..6dce962ee02 100644 --- a/source/blender/editors/space_sequencer/CMakeLists.txt +++ b/source/blender/editors/space_sequencer/CMakeLists.txt @@ -28,6 +28,7 @@ set(INC ../../makesdna ../../makesrna ../../windowmanager + ../../../../intern/atomic ../../../../intern/guardedalloc ../../../../intern/glew-mx ) diff --git a/source/blender/editors/space_sequencer/sequencer_scopes.c b/source/blender/editors/space_sequencer/sequencer_scopes.c index c197aabedfd..80cb42c0b3d 100644 --- a/source/blender/editors/space_sequencer/sequencer_scopes.c +++ b/source/blender/editors/space_sequencer/sequencer_scopes.c @@ -30,11 +30,14 @@ #include <string.h> #include "BLI_utildefines.h" +#include "BLI_task.h" #include "IMB_colormanagement.h" #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" +#include "atomic_ops.h" + #include "sequencer_intern.h" /* XXX, why is this function better then BLI_math version? @@ -450,41 +453,57 @@ static void draw_histogram_bar(ImBuf *ibuf, int x, float val, int col) #define HIS_STEPS 512 -static ImBuf *make_histogram_view_from_ibuf_byte(ImBuf *ibuf) +typedef struct MakeHistogramViewData { + const ImBuf *ibuf; + uint32_t (*bins)[HIS_STEPS]; +} MakeHistogramViewData; + +static void make_histogram_view_from_ibuf_byte_cb_ex( + void *userdata, void *userdata_chunk, const int y, const int UNUSED(threadid)) { - ImBuf *rval = IMB_allocImBuf(515, 128, 32, IB_rect); - int x, y; - unsigned int nr, ng, nb; + MakeHistogramViewData *data = userdata; + const ImBuf *ibuf = data->ibuf; const unsigned char *src = (unsigned char *)ibuf->rect; - unsigned int bins[3][HIS_STEPS]; - - memset(bins, 0, sizeof(bins)); + uint32_t (*cur_bins)[HIS_STEPS] = userdata_chunk; -#pragma omp parallel for shared(bins, src, ibuf) private(x, y) if (ibuf->y >= 256) - for (y = 0; y < ibuf->y; y++) { - unsigned int cur_bins[3][HIS_STEPS]; + for (int x = 0; x < ibuf->x; x++) { + const unsigned char *pixel = src + (y * ibuf->x + x) * 4; - memset(cur_bins, 0, sizeof(cur_bins)); + for (int j = 3; j--;) { + cur_bins[j][pixel[j]]++; + } + } +} - for (x = 0; x < ibuf->x; x++) { - const unsigned char *pixel = src + (y * ibuf->x + x) * 4; +static void make_histogram_view_from_ibuf_finalize(void *userdata, void *userdata_chunk) +{ + MakeHistogramViewData *data = userdata; + uint32_t (*bins)[HIS_STEPS] = data->bins; - cur_bins[0][pixel[0]]++; - cur_bins[1][pixel[1]]++; - cur_bins[2][pixel[2]]++; - } + uint32_t (*cur_bins)[HIS_STEPS] = userdata_chunk; -#pragma omp critical - { - int i; - for (i = 0; i < HIS_STEPS; i++) { - bins[0][i] += cur_bins[0][i]; - bins[1][i] += cur_bins[1][i]; - bins[2][i] += cur_bins[2][i]; - } + for (int j = 3; j--;) { + for (int i = 0; i < HIS_STEPS; i++) { + bins[j][i] += cur_bins[j][i]; } } +} + +static ImBuf *make_histogram_view_from_ibuf_byte(ImBuf *ibuf) +{ + ImBuf *rval = IMB_allocImBuf(515, 128, 32, IB_rect); + int x; + unsigned int nr, ng, nb; + + unsigned int bins[3][HIS_STEPS]; + + memset(bins, 0, sizeof(bins)); + + MakeHistogramViewData data = {.ibuf = ibuf, .bins = bins}; + BLI_task_parallel_range_finalize( + 0, ibuf->y, &data, bins, sizeof(bins), make_histogram_view_from_ibuf_byte_cb_ex, + make_histogram_view_from_ibuf_finalize, ibuf->y >= 256, false); nr = nb = ng = 0; for (x = 0; x < HIS_STEPS; x++) { @@ -528,40 +547,38 @@ BLI_INLINE int get_bin_float(float f) return (int) (((f + 0.25f) / 1.5f) * 512); } -static ImBuf *make_histogram_view_from_ibuf_float(ImBuf *ibuf) +static void make_histogram_view_from_ibuf_float_cb_ex( + void *userdata, void *userdata_chunk, const int y, const int UNUSED(threadid)) { - ImBuf *rval = IMB_allocImBuf(515, 128, 32, IB_rect); - int nr, ng, nb, x, y; + const MakeHistogramViewData *data = userdata; + const ImBuf *ibuf = data->ibuf; const float *src = ibuf->rect_float; - unsigned int bins[3][HIS_STEPS]; + uint32_t (*cur_bins)[HIS_STEPS] = userdata_chunk; - memset(bins, 0, sizeof(bins)); + for (int x = 0; x < ibuf->x; x++) { + const float *pixel = src + (y * ibuf->x + x) * 4; -#pragma omp parallel for shared(bins, src, ibuf) private(x, y) if (ibuf->y >= 256) - for (y = 0; y < ibuf->y; y++) { - unsigned int cur_bins[3][HIS_STEPS]; + for (int j = 3; j--;) { + cur_bins[j][get_bin_float(pixel[j])]++; + } + } +} - memset(cur_bins, 0, sizeof(cur_bins)); +static ImBuf *make_histogram_view_from_ibuf_float(ImBuf *ibuf) +{ + ImBuf *rval = IMB_allocImBuf(515, 128, 32, IB_rect); + int nr, ng, nb; + int x; - for (x = 0; x < ibuf->x; x++) { - const float *pixel = src + (y * ibuf->x + x) * 4; + unsigned int bins[3][HIS_STEPS]; - cur_bins[0][get_bin_float(pixel[0])]++; - cur_bins[1][get_bin_float(pixel[1])]++; - cur_bins[2][get_bin_float(pixel[2])]++; - } + memset(bins, 0, sizeof(bins)); -#pragma omp critical - { - int i; - for (i = 0; i < HIS_STEPS; i++) { - bins[0][i] += cur_bins[0][i]; - bins[1][i] += cur_bins[1][i]; - bins[2][i] += cur_bins[2][i]; - } - } - } + MakeHistogramViewData data = {.ibuf = ibuf, .bins = bins}; + BLI_task_parallel_range_finalize( + 0, ibuf->y, &data, bins, sizeof(bins), make_histogram_view_from_ibuf_float_cb_ex, + make_histogram_view_from_ibuf_finalize, ibuf->y >= 256, false); nr = nb = ng = 0; for (x = 0; x < HIS_STEPS; x++) { |