[Bf-blender-cvs] [83f2309] soc-2016-multiview: remove duplicate code of drawing secondary clip

Tianwei Shen noreply at git.blender.org
Sat Aug 6 13:43:06 CEST 2016


Commit: 83f23099c2239f3653d4596428f4eb03529c4213
Author: Tianwei Shen
Date:   Sat Aug 6 19:40:23 2016 +0800
Branches: soc-2016-multiview
https://developer.blender.org/rB83f23099c2239f3653d4596428f4eb03529c4213

remove duplicate code of drawing secondary clip

- main clip and witness clip seem to only differ in one pointer, use a
  function utility to handle different context change, so that other
  duplicate code for witness clip can be remove.

===================================================================

M	source/blender/editors/include/ED_clip.h
M	source/blender/editors/space_clip/clip_draw.c
M	source/blender/editors/space_clip/clip_editor.c
M	source/blender/editors/space_clip/clip_intern.h
M	source/blender/editors/space_clip/space_clip.c

===================================================================

diff --git a/source/blender/editors/include/ED_clip.h b/source/blender/editors/include/ED_clip.h
index deb436a..74e0440c 100644
--- a/source/blender/editors/include/ED_clip.h
+++ b/source/blender/editors/include/ED_clip.h
@@ -61,10 +61,8 @@ void ED_space_clip_get_aspect_dimension_aware(struct SpaceClip *sc, float *aspx,
 
 int ED_space_clip_get_clip_frame_number(struct SpaceClip *sc);
 
-struct ImBuf *ED_space_clip_get_buffer(struct SpaceClip *sc);
-struct ImBuf *ED_space_clip_secondary_get_buffer(struct SpaceClip *sc);
-struct ImBuf *ED_space_clip_get_stable_buffer(struct SpaceClip *sc, float loc[2], float *scale, float *angle);
-struct ImBuf *ED_space_clip_get_secondary_stable_buffer(struct SpaceClip *sc, float loc[2], float *scale, float *angle);
+struct ImBuf *ED_space_clip_get_buffer(struct SpaceClip *sc, struct ARegion *ar);
+struct ImBuf *ED_space_clip_get_stable_buffer(struct SpaceClip *sc, struct ARegion *ar, float loc[2], float *scale, float *angle);
 
 bool ED_space_clip_color_sample(struct Scene *scene, struct SpaceClip *sc, struct ARegion *ar, int mval[2], float r_col[3]);
 
diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c
index 4294a17..53efb13 100644
--- a/source/blender/editors/space_clip/clip_draw.c
+++ b/source/blender/editors/space_clip/clip_draw.c
@@ -325,53 +325,10 @@ static void draw_movieclip_buffer(const bContext *C, SpaceClip *sc, ARegion *ar,
 		glDisable(GL_BLEND);
 }
 
-static void draw_movieclip_secondary_buffer(const bContext *C, SpaceClip *sc, ARegion *ar, ImBuf *ibuf,
-                                            int width, int height, float zoomx, float zoomy)
-{
-	MovieClip *clip = ED_space_clip_get_secondary_clip(sc);
-	int filter = GL_LINEAR;
-	int x, y;
-
-	/* find window pixel coordinates of origin */
-	UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y);
-
-	/* checkerboard for case alpha */
-	if (ibuf->planes == 32) {
-		glEnable(GL_BLEND);
-		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
-		fdrawcheckerboard(x, y, x + zoomx * ibuf->x, y + zoomy * ibuf->y);
-	}
-
-	/* non-scaled proxy shouldn't use filtering */
-	if ((clip->flag & MCLIP_USE_PROXY) == 0 ||
-	    ELEM(sc->user.render_size, MCLIP_PROXY_RENDER_SIZE_FULL, MCLIP_PROXY_RENDER_SIZE_100))
-	{
-		filter = GL_NEAREST;
-	}
-
-	/* set zoom */
-	glPixelZoom(zoomx * width / ibuf->x, zoomy * height / ibuf->y);
-
-	glaDrawImBuf_glsl_ctx(C, ibuf, x, y, filter);
-	/* reset zoom */
-	glPixelZoom(1.0f, 1.0f);
-
-
-	if (sc->flag & SC_SHOW_METADATA) {
-		rctf frame;
-		BLI_rctf_init(&frame, 0.0f, ibuf->x, 0.0f, ibuf->y);
-		ED_region_image_metadata_draw(x, y, ibuf, &frame, zoomx * width / ibuf->x, zoomy * height / ibuf->y);
-	}
-
-	if (ibuf->planes == 32)
-		glDisable(GL_BLEND);
-}
-
 static void draw_stabilization_border(SpaceClip *sc, ARegion *ar, int width, int height, float zoomx, float zoomy)
 {
 	int x, y;
-	MovieClip *clip = ED_space_clip_get_clip(sc);
+	MovieClip *clip = ED_space_clip_get_clip_in_region(sc, ar);
 
 	/* find window pixel coordinates of origin */
 	UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y);
@@ -1728,7 +1685,7 @@ static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip,
 
 void clip_draw_main(const bContext *C, SpaceClip *sc, ARegion *ar)
 {
-	MovieClip *clip = ED_space_clip_get_clip(sc);
+	MovieClip *clip = ED_space_clip_get_clip_in_region(sc, ar);
 	Scene *scene = CTX_data_scene(C);
 	ImBuf *ibuf = NULL;
 	int width, height;
@@ -1749,7 +1706,7 @@ void clip_draw_main(const bContext *C, SpaceClip *sc, ARegion *ar)
 		float smat[4][4], ismat[4][4];
 
 		if ((sc->flag & SC_MUTE_FOOTAGE) == 0) {
-			ibuf = ED_space_clip_get_stable_buffer(sc, sc->loc,
+			ibuf = ED_space_clip_get_stable_buffer(sc, ar, sc->loc,
 			                                       &sc->scale, &sc->angle);
 		}
 
@@ -1769,7 +1726,7 @@ void clip_draw_main(const bContext *C, SpaceClip *sc, ARegion *ar)
 		mul_m4_series(sc->unistabmat, smat, sc->stabmat, ismat);
 	}
 	else if ((sc->flag & SC_MUTE_FOOTAGE) == 0) {
-		ibuf = ED_space_clip_get_buffer(sc);
+		ibuf = ED_space_clip_get_buffer(sc, ar);
 
 		zero_v2(sc->loc);
 		sc->scale = 1.0f;
@@ -1795,75 +1752,6 @@ void clip_draw_main(const bContext *C, SpaceClip *sc, ARegion *ar)
 	}
 }
 
-void clip_draw_secondary_clip(const bContext *C, SpaceClip *sc, ARegion *ar)
-{
-	MovieClip *sclip = ED_space_clip_get_secondary_clip(sc);
-	Scene *scene = CTX_data_scene(C);
-	ImBuf *ibuf = NULL;
-	int width, height;
-	float zoomx, zoomy;
-
-	ED_space_clip_get_size(sc, &width, &height);
-	ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy);
-
-	/* if no clip, nothing to do */
-	if (!sclip) {
-		ED_region_grid_draw(ar, zoomx, zoomy);
-		return;
-	}
-
-	if (sc->flag & SC_SHOW_STABLE) {
-		float translation[2];
-		float aspect = sclip->tracking.camera.pixel_aspect;
-		float smat[4][4], ismat[4][4];
-
-		if ((sc->flag & SC_MUTE_FOOTAGE) == 0) {
-			ibuf = ED_space_clip_get_secondary_stable_buffer(sc, sc->loc,
-			                                                 &sc->scale, &sc->angle);
-		}
-
-		if (ibuf != NULL && width != ibuf->x)
-			mul_v2_v2fl(translation, sc->loc, (float)width / ibuf->x);
-		else
-			copy_v2_v2(translation, sc->loc);
-
-		BKE_tracking_stabilization_data_to_mat4(width, height, aspect, translation,
-		                                        sc->scale, sc->angle, sc->stabmat);
-
-		unit_m4(smat);
-		smat[0][0] = 1.0f / width;
-		smat[1][1] = 1.0f / height;
-		invert_m4_m4(ismat, smat);
-
-		mul_m4_series(sc->unistabmat, smat, sc->stabmat, ismat);
-	}
-	else if ((sc->flag & SC_MUTE_FOOTAGE) == 0) {
-		ibuf = ED_space_clip_secondary_get_buffer(sc);
-
-		zero_v2(sc->loc);
-		sc->scale = 1.0f;
-		unit_m4(sc->stabmat);
-		unit_m4(sc->unistabmat);
-	}
-
-	if (ibuf) {
-		draw_movieclip_secondary_buffer(C, sc, ar, ibuf, width, height, zoomx, zoomy);
-		IMB_freeImBuf(ibuf);
-	}
-	else if (sc->flag & SC_MUTE_FOOTAGE) {
-		draw_movieclip_muted(ar, width, height, zoomx, zoomy);
-	}
-	else {
-		ED_region_grid_draw(ar, zoomx, zoomy);
-	}
-
-	if (width && height) {
-		draw_stabilization_border(sc, ar, width, height, zoomx, zoomy);
-		draw_tracking_tracks(sc, scene, ar, sclip, width, height, zoomx, zoomy);
-		draw_distortion(sc, ar, sclip, width, height, zoomx, zoomy);
-	}
-}
-
 void clip_draw_cache_and_notes(const bContext *C, SpaceClip *sc, ARegion *ar)
 {
 	Scene *scene = CTX_data_scene(C);
diff --git a/source/blender/editors/space_clip/clip_editor.c b/source/blender/editors/space_clip/clip_editor.c
index 07cd0eb..59f20e2 100644
--- a/source/blender/editors/space_clip/clip_editor.c
+++ b/source/blender/editors/space_clip/clip_editor.c
@@ -237,46 +237,13 @@ int ED_space_clip_get_clip_frame_number(SpaceClip *sc)
 	return BKE_movieclip_remap_scene_to_clip_frame(clip, sc->user.framenr);
 }
 
-ImBuf *ED_space_clip_get_buffer(SpaceClip *sc)
+ImBuf *ED_space_clip_get_buffer(SpaceClip *sc, ARegion *ar)
 {
-	if (sc->clip) {
-		ImBuf *ibuf;
-
-		ibuf = BKE_movieclip_get_postprocessed_ibuf(sc->clip, &sc->user, sc->postproc_flag);
-
-		if (ibuf && (ibuf->rect || ibuf->rect_float))
-			return ibuf;
-
-		if (ibuf)
-			IMB_freeImBuf(ibuf);
-	}
-
-	return NULL;
-}
-
-ImBuf *ED_space_clip_secondary_get_buffer(SpaceClip *sc)
-{
-	if (sc->secondary_clip) {
-		ImBuf *ibuf;
-
-		ibuf = BKE_movieclip_get_postprocessed_ibuf(sc->secondary_clip, &sc->user, sc->postproc_flag);
-
-		if (ibuf && (ibuf->rect || ibuf->rect_float))
-			return ibuf;
-
-		if (ibuf)
-			IMB_freeImBuf(ibuf);
-	}
-
-	return NULL;
-}
-
-ImBuf *ED_space_clip_get_stable_buffer(SpaceClip *sc, float loc[2], float *scale, float *angle)
-{
-	if (sc->clip) {
+	MovieClip *clip = ED_space_clip_get_clip_in_region(sc, ar);
+	if (clip) {
 		ImBuf *ibuf;
 
-		ibuf = BKE_movieclip_get_stable_ibuf(sc->clip, &sc->user, loc, scale, angle, sc->postproc_flag);
+		ibuf = BKE_movieclip_get_postprocessed_ibuf(clip, &sc->user, sc->postproc_flag);
 
 		if (ibuf && (ibuf->rect || ibuf->rect_float))
 			return ibuf;
@@ -288,12 +255,13 @@ ImBuf *ED_space_clip_get_stable_buffer(SpaceClip *sc, float loc[2], float *scale
 	return NULL;
 }
 
-ImBuf *ED_space_clip_get_secondary_stable_buffer(SpaceClip *sc, float loc[2], float *scale, float *angle)
+ImBuf *ED_space_clip_get_stable_buffer(SpaceClip *sc, ARegion *ar, float loc[2], float *scale, float *angle)
 {
-	if (sc->secondary_clip) {
+	MovieClip *clip = ED_space_clip_get_clip_in_region(sc, ar);
+	if (clip) {
 		ImBuf *ibuf;
 
-		ibuf = BKE_movieclip_get_stable_ibuf(sc->secondary_clip, &sc->user, loc, scale, angle, sc->postproc_flag);
+		ibuf = BKE_movieclip_get_stable_ibuf(clip, &sc->user, loc, scale, angle, sc->postproc_flag);
 
 		if (ibuf && (ibuf->rect || ibuf->rect_float))
 			return ibuf;
@@ -314,7 +282,7 @@ bool ED_space_clip_color_sample(Scene *scene, SpaceClip *sc, ARegion *ar, int mv
 	float fx, fy, co[2];
 	bool ret = false;
 
-	ibuf = ED_space_clip_get_buffer(sc);
+	ibuf = ED_space_clip_get_buffer(sc, ar);
 	if (!ibuf) {
 		return false;
 	}
diff --git a/source/blender/editors/space_clip/clip_intern.h b/source/blender/editors/space_clip/clip_intern.h
index 994dc30..190c446 100644
--- a/source/blender/editors/space_clip/clip_intern.h
+++ b/source/blender/editors/space_clip/clip_intern.h
@@ -72,7 +72,6 @@ void CLIP_OT_dopesheet_view_all(struct wmOperatorType *ot);
 
 /* clip_draw.c */
 void clip_draw_main(const struct bContext *C, struct SpaceClip *sc, struct ARegion *ar);
-void clip_draw_secondary_clip(const struct bContext *C, struct SpaceClip *sc, struct ARegion *ar);
 void clip_draw_grease_pencil(struct bContext *C, int onlyv2d);
 void clip_draw_cache_and_notes(const bContext *C, SpaceClip *sc, ARegion *ar);
 
diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c
index 87999c5..e998cc7 100644
--- a/source/blender/editors/space_clip/space_clip.c
+++ b/source/blender/editors/space_clip/space_clip.c
@@ -1188,7 +1188,7 @@ static void clip_main_region_draw(const bContext *C, ARegion *ar)
 		ImBuf *tmpibuf = NULL;
 
 		if (clip && clip->tracking.stabilization.flag & TRACKING_2D_STABILIZATION) {
-			tmpibuf = ED_space_clip_get_stable_buffer(sc, NULL, NULL, NULL);
+			tmpibuf = ED_space_clip_get_stable_buffer(sc, ar, NULL, 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list