[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49666] trunk/blender/source/blender: Made image buffer threaded processor generic function,
Sergey Sharybin
sergey.vfx at gmail.com
Tue Aug 7 18:47:46 CEST 2012
Revision: 49666
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49666
Author: nazgul
Date: 2012-08-07 16:47:46 +0000 (Tue, 07 Aug 2012)
Log Message:
-----------
Made image buffer threaded processor generic function,
so color management could use the same routines.
Should be no functional changes.
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/intern/sequencer.c
trunk/blender/source/blender/imbuf/IMB_imbuf.h
trunk/blender/source/blender/imbuf/intern/imageprocess.c
Modified: trunk/blender/source/blender/blenkernel/intern/sequencer.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/sequencer.c 2012-08-07 16:47:27 UTC (rev 49665)
+++ trunk/blender/source/blender/blenkernel/intern/sequencer.c 2012-08-07 16:47:46 UTC (rev 49666)
@@ -1646,6 +1646,12 @@
}
}
+typedef struct ColorBalanceInitData {
+ Sequence *seq;
+ ImBuf *ibuf;
+ float mul;
+} ColorBalanceInitData;
+
typedef struct ColorBalanceThread {
Sequence *seq;
float mul;
@@ -1656,6 +1662,28 @@
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,63 +1708,37 @@
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);
+ init_data.seq = seq;
+ init_data.ibuf = ibuf;
+ init_data.mul = mul;
- if (tot_thread > 1)
- BLI_init_threads(&threads, color_balance_do_thread, tot_thread);
+ IMB_processor_apply_threaded(ibuf->y, sizeof(ColorBalanceThread), &init_data,
+ color_balance_init_handle, color_balance_do_thread);
- start_line = 0;
- tot_line = ((float)(ibuf->y / tot_thread)) + 0.5f;
+ }
+ else {
+ ColorBalanceThread handle;
- for (i = 0; i < tot_thread; i++) {
- int offset;
+ 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;
- handles[i].seq = seq;
- handles[i].mul = mul;
- handles[i].width = ibuf->x;
+ color_balance_do_thread(&handle);
+} }
- 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
*
Modified: trunk/blender/source/blender/imbuf/IMB_imbuf.h
===================================================================
--- trunk/blender/source/blender/imbuf/IMB_imbuf.h 2012-08-07 16:47:27 UTC (rev 49665)
+++ trunk/blender/source/blender/imbuf/IMB_imbuf.h 2012-08-07 16:47:46 UTC (rev 49666)
@@ -498,5 +498,11 @@
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
Modified: trunk/blender/source/blender/imbuf/intern/imageprocess.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/imageprocess.c 2012-08-07 16:47:27 UTC (rev 49665)
+++ trunk/blender/source/blender/imbuf/intern/imageprocess.c 2012-08-07 16:47:46 UTC (rev 49666)
@@ -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 @@
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);
+}
More information about the Bf-blender-cvs
mailing list