[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49806] trunk/blender: Sequencer: support for masked color balance

Sergey Sharybin sergey.vfx at gmail.com
Sat Aug 11 16:37:58 CEST 2012


Revision: 49806
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49806
Author:   nazgul
Date:     2012-08-11 14:37:58 +0000 (Sat, 11 Aug 2012)
Log Message:
-----------
Sequencer: support for masked color balance

This implements option which could be used to color balance only
specified area. Currently done by adding Mask input to Adjustment
effect. Affects on color balance and multiply settings.

Supporting masked saturation control is in the list, not supported
in this commit.

Also show value slider in the right of color wheel.

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/space_sequencer.py
    trunk/blender/source/blender/blenkernel/BKE_sequencer.h
    trunk/blender/source/blender/blenkernel/intern/seqeffects.c
    trunk/blender/source/blender/blenkernel/intern/sequencer.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/makesdna/DNA_sequence_types.h
    trunk/blender/source/blender/makesrna/intern/rna_sequencer.c

Modified: trunk/blender/release/scripts/startup/bl_ui/space_sequencer.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_sequencer.py	2012-08-11 13:42:44 UTC (rev 49805)
+++ trunk/blender/release/scripts/startup/bl_ui/space_sequencer.py	2012-08-11 14:37:58 UTC (rev 49806)
@@ -423,18 +423,24 @@
         return strip.type in {'ADD', 'SUBTRACT', 'ALPHA_OVER', 'ALPHA_UNDER',
                               'CROSS', 'GAMMA_CROSS', 'MULTIPLY', 'OVER_DROP',
                               'WIPE', 'GLOW', 'TRANSFORM', 'COLOR', 'SPEED',
-                              'MULTICAM'}
+                              'MULTICAM', 'ADJUSTMENT'}
 
     def draw(self, context):
         layout = self.layout
 
+        sequencer = context.scene.sequence_editor
         strip = act_strip(context)
+
         if strip.input_count > 0:
             col = layout.column()
             col.prop(strip, "input_1")
             if strip.input_count > 1:
                 col.prop(strip, "input_2")
 
+        if strip.is_supports_mask:
+            col = layout.column()
+            col.prop_search(strip, "input_mask", sequencer, "sequences")
+
         if strip.type == 'COLOR':
             layout.prop(strip, "color")
 
@@ -765,21 +771,21 @@
         if strip.use_color_balance and strip.color_balance:  # TODO - need to add this somehow
             col = layout.column()
             col.label(text="Lift:")
-            col.template_color_wheel(strip.color_balance, "lift", value_slider=False, cubic=True)
+            col.template_color_wheel(strip.color_balance, "lift", value_slider=True, cubic=True)
             row = col.row()
             row.prop(strip.color_balance, "lift", text="")
             row.prop(strip.color_balance, "invert_lift", text="Inverse")
 
             col = layout.column()
             col.label(text="Gamma:")
-            col.template_color_wheel(strip.color_balance, "gamma", value_slider=False, lock_luminosity=True, cubic=True)
+            col.template_color_wheel(strip.color_balance, "gamma", value_slider=True, lock_luminosity=True, cubic=True)
             row = col.row()
             row.prop(strip.color_balance, "gamma", text="")
             row.prop(strip.color_balance, "invert_gamma", text="Inverse")
 
             col = layout.column()
             col.label(text="Gain:")
-            col.template_color_wheel(strip.color_balance, "gain", value_slider=False, lock_luminosity=True, cubic=True)
+            col.template_color_wheel(strip.color_balance, "gain", value_slider=True, lock_luminosity=True, cubic=True)
             row = col.row()
             row.prop(strip.color_balance, "gain", text="")
             row.prop(strip.color_balance, "invert_gain", text="Inverse")

Modified: trunk/blender/source/blender/blenkernel/BKE_sequencer.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_sequencer.h	2012-08-11 13:42:44 UTC (rev 49805)
+++ trunk/blender/source/blender/blenkernel/BKE_sequencer.h	2012-08-11 14:37:58 UTC (rev 49806)
@@ -110,7 +110,8 @@
 };
 
 struct SeqEffectHandle {
-	int multithreaded;
+	short multithreaded;
+	short supports_mask;
 
 	/* constructors & destructor */
 	/* init is _only_ called on first creation */
@@ -150,11 +151,12 @@
 	struct ImBuf * (*execute)(SeqRenderData context, struct Sequence *seq, float cfra, float facf0, float facf1,
 	                          struct ImBuf *ibuf1, struct ImBuf *ibuf2, struct ImBuf *ibuf3);
 
-	struct ImBuf * (*init_execution)(SeqRenderData context, struct ImBuf *ibuf1, struct ImBuf *ibuf2, struct ImBuf *ibuf3);
+	struct ImBuf * (*init_execution)(SeqRenderData context, struct ImBuf *ibuf1, struct ImBuf *ibuf2,
+	                                 struct ImBuf *ibuf3);
 
 	void (*execute_slice)(SeqRenderData context, struct Sequence *seq, float cfra, float facf0, float facf1,
 	                      struct ImBuf *ibuf1, struct ImBuf *ibuf2, struct ImBuf *ibuf3,
-	                       int start_line, int total_lines, struct ImBuf *out);
+	                      int start_line, int total_lines, struct ImBuf *out);
 };
 
 /* ********************* prototypes *************** */
@@ -253,6 +255,7 @@
 /* extern */
 struct SeqEffectHandle BKE_sequence_get_effect(struct Sequence *seq);
 int BKE_sequence_effect_get_num_inputs(int seq_type);
+int BKE_sequence_effect_get_supports_mask(int seq_type);
 
 /* **********************************************************************
  * Sequencer editing functions
@@ -284,6 +287,7 @@
 struct Sequence *BKE_sequence_dupli_recursive(struct Scene *scene, struct Scene *scene_to, struct Sequence *seq, int dupe_flag);
 int BKE_sequence_swap(struct Sequence *seq_a, struct Sequence *seq_b, const char **error_str);
 
+int BKE_sequence_check_depend(struct Sequence *seq, struct Sequence *cur);
 void BKE_sequence_invalidate_cache(struct Scene *scene, struct Sequence *seq);
 
 void BKE_sequencer_update_sound_bounds_all(struct Scene *scene);

Modified: trunk/blender/source/blender/blenkernel/intern/seqeffects.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/seqeffects.c	2012-08-11 13:42:44 UTC (rev 49805)
+++ trunk/blender/source/blender/blenkernel/intern/seqeffects.c	2012-08-11 14:37:58 UTC (rev 49806)
@@ -2840,6 +2840,7 @@
 	int sequence_type = seq_type;
 
 	rval.multithreaded = FALSE;
+	rval.supports_mask = FALSE;
 	rval.init = init_noop;
 	rval.num_inputs = num_inputs_default;
 	rval.load = load_noop;
@@ -2945,6 +2946,7 @@
 			rval.execute = do_multicam;
 			break;
 		case SEQ_TYPE_ADJUSTMENT:
+			rval.supports_mask = TRUE;
 			rval.num_inputs = num_inputs_adjustment;
 			rval.early_out = early_out_adjustment;
 			rval.execute = do_adjustment;
@@ -2956,7 +2958,7 @@
 
 struct SeqEffectHandle BKE_sequence_get_effect(Sequence *seq)
 {
-	struct SeqEffectHandle rval = {FALSE, NULL};
+	struct SeqEffectHandle rval = {FALSE, FALSE, NULL};
 
 	if (seq->type & SEQ_TYPE_EFFECT) {
 		rval = get_sequence_effect_impl(seq->type);
@@ -2971,7 +2973,7 @@
 
 struct SeqEffectHandle BKE_sequence_get_blend(Sequence *seq)
 {
-	struct SeqEffectHandle rval = {FALSE, NULL};
+	struct SeqEffectHandle rval = {FALSE, FALSE, NULL};
 
 	if (seq->blend_mode != 0) {
 		rval = get_sequence_effect_impl(seq->blend_mode);
@@ -2994,3 +2996,10 @@
 	}
 	return 0;
 }
+
+int BKE_sequence_effect_get_supports_mask(int seq_type)
+{
+	struct SeqEffectHandle rval = get_sequence_effect_impl(seq_type);
+
+	return rval.supports_mask;
+}

Modified: trunk/blender/source/blender/blenkernel/intern/sequencer.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/sequencer.c	2012-08-11 13:42:44 UTC (rev 49805)
+++ trunk/blender/source/blender/blenkernel/intern/sequencer.c	2012-08-11 14:37:58 UTC (rev 49806)
@@ -1426,12 +1426,13 @@
 	}
 }
 
-static void color_balance_byte_byte(Sequence *seq, unsigned char *rect, int width, int height, float mul)
+static void color_balance_byte_byte(Sequence *seq, unsigned char *rect, unsigned char *mask_rect, int width, int height, float mul)
 {
 	unsigned char cb_tab[3][256];
 	int c;
 	unsigned char *p = rect;
 	unsigned char *e = p + width * 4 * height;
+	unsigned char *m = mask_rect;
 
 	StripColorBalance cb = calc_cb(seq->strip->color_balance);
 
@@ -1440,20 +1441,32 @@
 	}
 
 	while (p < e) {
-		p[0] = cb_tab[0][p[0]];
-		p[1] = cb_tab[1][p[1]];
-		p[2] = cb_tab[2][p[2]];
+		if (m) {
+			float t[3] = {m[0] / 255.0f, m[1] / 255.0f, m[2] / 255.0f};
+
+			p[0] = p[0] * (1.0f - t[0]) + t[0] * cb_tab[0][p[0]];
+			p[1] = p[1] * (1.0f - t[1]) + t[1] * cb_tab[1][p[1]];
+			p[2] = p[2] * (1.0f - t[2]) + t[2] * cb_tab[2][p[2]];
+
+			m += 4;
+		}
+		else {
+			p[0] = cb_tab[0][p[0]];
+			p[1] = cb_tab[1][p[1]];
+			p[2] = cb_tab[2][p[2]];
+		}
 		
 		p += 4;
 	}
 }
 
-static void color_balance_byte_float(Sequence *seq, unsigned char *rect, float *rect_float, int width, int height, float mul)
+static void color_balance_byte_float(Sequence *seq, unsigned char *rect, float *rect_float, unsigned char *mask_rect, int width, int height, float mul)
 {
 	float cb_tab[4][256];
 	int c, i;
 	unsigned char *p = rect;
 	unsigned char *e = p + width * 4 * height;
+	unsigned char *m = mask_rect;
 	float *o;
 	StripColorBalance cb;
 
@@ -1470,27 +1483,48 @@
 	}
 
 	while (p < e) {
-		o[0] = cb_tab[0][p[0]];
-		o[1] = cb_tab[1][p[1]];
-		o[2] = cb_tab[2][p[2]];
+		if (m) {
+			float t[3] = {m[0] / 255.0f, m[1] / 255.0f, m[2] / 255.0f};
+
+			p[0] = p[0] * (1.0f - t[0]) + t[0] * cb_tab[0][p[0]];
+			p[1] = p[1] * (1.0f - t[1]) + t[1] * cb_tab[1][p[1]];
+			p[2] = p[2] * (1.0f - t[2]) + t[2] * cb_tab[2][p[2]];
+
+			m += 4;
+		}
+		else {
+			o[0] = cb_tab[0][p[0]];
+			o[1] = cb_tab[1][p[1]];
+			o[2] = cb_tab[2][p[2]];
+		}
+
 		o[3] = cb_tab[3][p[3]];
 
 		p += 4; o += 4;
 	}
 }
 
-static void color_balance_float_float(Sequence *seq, float *rect_float, int width, int height, float mul)
+static void color_balance_float_float(Sequence *seq, float *rect_float, float *mask_rect_float, int width, int height, float mul)
 {
 	float *p = rect_float;
 	float *e = rect_float + width * 4 * height;
+	float *m = mask_rect_float;
 	StripColorBalance cb = calc_cb(seq->strip->color_balance);
 
 	while (p < e) {
 		int c;
 		for (c = 0; c < 3; c++) {
-			p[c] = color_balance_fl(p[c], cb.lift[c], cb.gain[c], cb.gamma[c], mul);
+			float t = color_balance_fl(p[c], cb.lift[c], cb.gain[c], cb.gamma[c], mul);
+
+			if (m)
+				p[c] = p[c] * (1.0f - m[c]) + t * m[c];
+			else
+				p[c] = t;
 		}
+
 		p += 4;
+		if (m)
+			m += 4;
 	}
 }
 
@@ -1498,6 +1532,7 @@
 	Sequence *seq;
 	ImBuf *ibuf;
 	float mul;
+	ImBuf *mask;
 } ColorBalanceInitData;
 
 typedef struct ColorBalanceThread {
@@ -1506,8 +1541,8 @@
 
 	int width, height;
 
-	unsigned char *rect;
-	float *rect_float;
+	unsigned char *rect, *mask_rect;
+	float *rect_float, *mask_rect_float;
 } ColorBalanceThread;
 
 static void color_balance_init_handle(void *handle_v, int start_line, int tot_line, void *init_data_v)
@@ -1515,6 +1550,7 @@
 	ColorBalanceThread *handle = (ColorBalanceThread *) handle_v;
 	ColorBalanceInitData *init_data = (ColorBalanceInitData *) init_data_v;
 	ImBuf *ibuf = init_data->ibuf;
+	ImBuf *mask = init_data->mask;
 
 	int offset = 4 * start_line * ibuf->x;
 
@@ -1530,6 +1566,18 @@
 
 	if (ibuf->rect_float)
 		handle->rect_float = ibuf->rect_float + offset;
+
+	if (mask) {

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list