[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49661] trunk/blender/source/blender/ blenkernel/intern/sequencer.c: Made color balance in sequencer multi-threaded
Sergey Sharybin
sergey.vfx at gmail.com
Tue Aug 7 18:09:43 CEST 2012
Revision: 49661
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49661
Author: nazgul
Date: 2012-08-07 16:09:42 +0000 (Tue, 07 Aug 2012)
Log Message:
-----------
Made color balance in sequencer multi-threaded
Should give some more realtime update, but it's currently not the
biggest issue - changing color balance settings would imply reloading
of file which is slow. Would be investigated further.
This change shouldn't affect on pre-fetching job which is already
multi-threaded and doing threaded color balance would make things
only worse.
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/intern/sequencer.c
Modified: trunk/blender/source/blender/blenkernel/intern/sequencer.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/sequencer.c 2012-08-07 16:04:14 UTC (rev 49660)
+++ trunk/blender/source/blender/blenkernel/intern/sequencer.c 2012-08-07 16:09:42 UTC (rev 49661)
@@ -1577,12 +1577,12 @@
}
}
-static void color_balance_byte_byte(Sequence *seq, ImBuf *ibuf, float mul)
+static void color_balance_byte_byte(Sequence *seq, unsigned char *rect, int width, int height, float mul)
{
unsigned char cb_tab[3][256];
int c;
- unsigned char *p = (unsigned char *) ibuf->rect;
- unsigned char *e = p + ibuf->x * 4 * ibuf->y;
+ unsigned char *p = rect;
+ unsigned char *e = p + width * 4 * height;
StripColorBalance cb = calc_cb(seq->strip->color_balance);
@@ -1600,19 +1600,17 @@
}
}
-static void color_balance_byte_float(Sequence *seq, ImBuf *ibuf, float mul)
+static void color_balance_byte_float(Sequence *seq, unsigned char *rect, float *rect_float, int width, int height, float mul)
{
float cb_tab[4][256];
int c, i;
- unsigned char *p = (unsigned char *) ibuf->rect;
- unsigned char *e = p + ibuf->x * 4 * ibuf->y;
+ unsigned char *p = rect;
+ unsigned char *e = p + width * 4 * height;
float *o;
StripColorBalance cb;
- imb_addrectfloatImBuf(ibuf);
+ o = rect_float;
- o = ibuf->rect_float;
-
cb = calc_cb(seq->strip->color_balance);
for (c = 0; c < 3; c++) {
@@ -1633,10 +1631,10 @@
}
}
-static void color_balance_float_float(Sequence *seq, ImBuf *ibuf, float mul)
+static void color_balance_float_float(Sequence *seq, float *rect_float, int width, int height, float mul)
{
- float *p = ibuf->rect_float;
- float *e = ibuf->rect_float + ibuf->x * 4 * ibuf->y;
+ float *p = rect_float;
+ float *e = rect_float + width * 4 * height;
StripColorBalance cb = calc_cb(seq->strip->color_balance);
while (p < e) {
@@ -1648,19 +1646,97 @@
}
}
-static void color_balance(Sequence *seq, ImBuf *ibuf, float mul)
+typedef struct ColorBalanceThread {
+ Sequence *seq;
+ float mul;
+
+ int width, height;
+
+ unsigned char *rect;
+ float *rect_float;
+} ColorBalanceThread;
+
+static void *color_balance_do_thread(void *thread_data_v)
{
- if (ibuf->rect_float) {
- color_balance_float_float(seq, ibuf, mul);
+ ColorBalanceThread *thread_data = (ColorBalanceThread *) thread_data_v;
+ Sequence *seq = thread_data->seq;
+ int width = thread_data->width, height = thread_data->height;
+ unsigned char *rect = thread_data->rect;
+ float *rect_float = thread_data->rect_float;
+ float mul = thread_data->mul;
+
+ if (rect_float) {
+ color_balance_float_float(seq, rect_float, width, height, mul);
}
else if (seq->flag & SEQ_MAKE_FLOAT) {
- color_balance_byte_float(seq, ibuf, mul);
+ color_balance_byte_float(seq, rect, rect_float, width, height, mul);
}
else {
- color_balance_byte_byte(seq, ibuf, mul);
+ color_balance_byte_byte(seq, rect, width, height, mul);
}
+
+ return NULL;
}
+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 (!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;
+ }
+
+ 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;
+
+ handles[i].seq = seq;
+ handles[i].mul = mul;
+ handles[i].width = ibuf->x;
+
+ 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;
+
+ if (ibuf->rect_float)
+ handles[i].rect_float = ibuf->rect_float + offset;
+ else
+ handles[i].rect_float = NULL;
+
+ if (tot_thread > 1)
+ BLI_insert_thread(&threads, &handles[i]);
+
+ 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
*
More information about the Bf-blender-cvs
mailing list