[Bf-blender-cvs] [11ee2d8] master: implement cache line for image editor

Sergey Sharybin noreply at git.blender.org
Wed Apr 2 12:54:40 CEST 2014


Commit: 11ee2d8b97ddbdde9ef5a7b77df2b9f9eb2d0e91
Author: Sergey Sharybin
Date:   Wed Apr 2 16:50:06 2014 +0600
https://developer.blender.org/rB11ee2d8b97ddbdde9ef5a7b77df2b9f9eb2d0e91

implement cache line for image editor

It works exactly the same as a cache line in movie clip editor.

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

M	source/blender/blenkernel/intern/image.c
M	source/blender/editors/include/ED_screen.h
M	source/blender/editors/screen/area.c
M	source/blender/editors/space_clip/clip_draw.c
M	source/blender/editors/space_clip/clip_intern.h
M	source/blender/editors/space_clip/clip_utils.c
M	source/blender/editors/space_image/image_draw.c
M	source/blender/editors/space_image/image_intern.h
M	source/blender/editors/space_image/space_image.c

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

diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 7664367..c0c0286 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -133,6 +133,15 @@ static int imagecache_hashcmp(const void *a_v, const void *b_v)
 	return a->index - b->index;
 }
 
+static void imagecache_keydata(void *userkey, int *framenr, int *proxy, int *render_flags)
+{
+	ImageCacheKey *key = (ImageCacheKey *)userkey;
+
+	*framenr = IMA_INDEX_FRAME(key->index);
+	*proxy = IMB_PROXY_NONE;
+	*render_flags = 0;
+}
+
 static void imagecache_put(Image *image, int index, ImBuf *ibuf)
 {
 	ImageCacheKey key;
@@ -143,6 +152,7 @@ static void imagecache_put(Image *image, int index, ImBuf *ibuf)
 
 		image->cache = IMB_moviecache_create("Image Datablock Cache", sizeof(ImageCacheKey),
 		                                     imagecache_hashhash, imagecache_hashcmp);
+		IMB_moviecache_set_getdata_callback(image->cache, imagecache_keydata);
 	}
 
 	key.index = index;
diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h
index 1d1777a..060702f 100644
--- a/source/blender/editors/include/ED_screen.h
+++ b/source/blender/editors/include/ED_screen.h
@@ -178,6 +178,12 @@ int     ED_operator_posemode(struct bContext *C);
 int     ED_operator_mask(struct bContext *C);
 
 
+/* Cache display helpers */
+
+void ED_region_cache_draw_background(const struct ARegion *ar);
+void ED_region_cache_draw_curfra_label(const int framenr, const float x, const float y);
+void ED_region_cache_draw_cached_segments(const struct ARegion *ar, const int num_segments, const int *points, const int sfra, const int efra);
+
 /* default keymaps, bitflags */
 #define ED_KEYMAP_UI        1
 #define ED_KEYMAP_VIEW2D    2
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 1efd3cc..907f5fe 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -2007,3 +2007,49 @@ void ED_region_visible_rect(ARegion *ar, rcti *rect)
 	BLI_rcti_translate(rect, -ar->winrct.xmin, -ar->winrct.ymin);
 }
 
+/* Cache display helpers */
+
+void ED_region_cache_draw_background(const ARegion *ar)
+{
+	glColor4ub(128, 128, 255, 64);
+	glRecti(0, 0, ar->winx, 8 * UI_DPI_FAC);
+}
+
+void ED_region_cache_draw_curfra_label(const int framenr, const float x, const float y)
+{
+	uiStyle *style = UI_GetStyle();
+	int fontid = style->widget.uifont_id;
+	char numstr[32];
+	float font_dims[2] = {0.0f, 0.0f};
+
+	/* frame number */
+	BLF_size(fontid, 11.0f * U.pixelsize, U.dpi);
+	BLI_snprintf(numstr, sizeof(numstr), "%d", framenr);
+
+	BLF_width_and_height(fontid, numstr, sizeof(numstr), &font_dims[0], &font_dims[1]);
+
+	glRecti(x, y, x + font_dims[0] + 6.0f, y + font_dims[1] + 4.0f);
+
+	UI_ThemeColor(TH_TEXT);
+	BLF_position(fontid, x + 2.0f, y + 2.0f, 0.0f);
+	BLF_draw(fontid, numstr, sizeof(numstr));
+}
+
+void ED_region_cache_draw_cached_segments(const ARegion *ar, const int num_segments, const int *points, const int sfra, const int efra)
+{
+	if (num_segments) {
+		int a;
+
+		glColor4ub(128, 128, 255, 128);
+
+		for (a = 0; a < num_segments; a++) {
+			float x1, x2;
+
+			x1 = (float)(points[a * 2] - sfra) / (efra - sfra + 1) * ar->winx;
+			x2 = (float)(points[a * 2 + 1] - sfra + 1) / (efra - sfra + 1) * ar->winx;
+
+			glRecti(x1, 0, x2, 8 * UI_DPI_FAC);
+		}
+	}
+}
+
diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c
index a17cf0e..eaf12a8 100644
--- a/source/blender/editors/space_clip/clip_draw.c
+++ b/source/blender/editors/space_clip/clip_draw.c
@@ -76,26 +76,6 @@
 
 /*********************** main area drawing *************************/
 
-void clip_draw_curfra_label(const int framenr, const float x, const float y)
-{
-	uiStyle *style = UI_GetStyle();
-	int fontid = style->widget.uifont_id;
-	char numstr[32];
-	float font_dims[2] = {0.0f, 0.0f};
-
-	/* frame number */
-	BLF_size(fontid, 11.0f * U.pixelsize, U.dpi);
-	BLI_snprintf(numstr, sizeof(numstr), "%d", framenr);
-
-	BLF_width_and_height(fontid, numstr, sizeof(numstr), &font_dims[0], &font_dims[1]);
-
-	glRecti(x, y, x + font_dims[0] + 6.0f, y + font_dims[1] + 4.0f);
-
-	UI_ThemeColor(TH_TEXT);
-	BLF_position(fontid, x + 2.0f, y + 2.0f, 0.0f);
-	BLF_draw(fontid, numstr, sizeof(numstr));
-}
-
 static void draw_keyframe(int frame, int cfra, int sfra, float framelen, int width)
 {
 	int height = (frame == cfra) ? 22 : 10;
@@ -183,23 +163,11 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc
 	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
 	/* cache background */
-	glColor4ub(128, 128, 255, 64);
-	glRecti(0, 0, ar->winx, 8 * UI_DPI_FAC);
+	ED_region_cache_draw_background(ar);
 
 	/* cached segments -- could be usefu lto debug caching strategies */
 	BKE_movieclip_get_cache_segments(clip, &sc->user, &totseg, &points);
-	if (totseg) {
-		glColor4ub(128, 128, 255, 128);
-
-		for (a = 0; a < totseg; a++) {
-			float x1, x2;
-
-			x1 = (points[a * 2] - sfra) / (efra - sfra + 1) * ar->winx;
-			x2 = (points[a * 2 + 1] - sfra + 1) / (efra - sfra + 1) * ar->winx;
-
-			glRecti(x1, 0, x2, 8 * UI_DPI_FAC);
-		}
-	}
+	ED_region_cache_draw_cached_segments(ar, totseg, points, sfra, efra);
 
 	/* track */
 	if (act_track || act_plane_track) {
@@ -271,7 +239,7 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc
 	UI_ThemeColor(TH_CFRAME);
 	glRecti(x, 0, x + ceilf(framelen), 8 * UI_DPI_FAC);
 
-	clip_draw_curfra_label(sc->user.framenr, x, 8.0f * UI_DPI_FAC);
+	ED_region_cache_draw_curfra_label(sc->user.framenr, x, 8.0f * UI_DPI_FAC);
 
 	/* solver keyframes */
 	glColor4ub(175, 255, 0, 255);
diff --git a/source/blender/editors/space_clip/clip_intern.h b/source/blender/editors/space_clip/clip_intern.h
index 811f8e2..2a5d959 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_grease_pencil(struct bContext *C, int onlyv2d);
-void clip_draw_curfra_label(const int framenr, const float x, const float y);
 void clip_draw_cache_and_notes(const bContext *C, SpaceClip *sc, ARegion *ar);
 
 /* clip_editor.c */
diff --git a/source/blender/editors/space_clip/clip_utils.c b/source/blender/editors/space_clip/clip_utils.c
index fd994d5..e4392cb 100644
--- a/source/blender/editors/space_clip/clip_utils.c
+++ b/source/blender/editors/space_clip/clip_utils.c
@@ -319,7 +319,7 @@ void clip_draw_cfra(SpaceClip *sc, ARegion *ar, Scene *scene)
 	UI_view2d_getscale(v2d, &xscale, &yscale);
 	glScalef(1.0f / xscale, 1.0f, 1.0f);
 
-	clip_draw_curfra_label(sc->user.framenr, (float)sc->user.framenr * xscale, 18);
+	ED_region_cache_draw_curfra_label(sc->user.framenr, (float)sc->user.framenr * xscale, 18);
 
 	/* restore view transform */
 	glScalef(xscale, 1.0, 1.0);
diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c
index 2cdd105..27d2a19 100644
--- a/source/blender/editors/space_image/image_draw.c
+++ b/source/blender/editors/space_image/image_draw.c
@@ -40,6 +40,7 @@
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_brush_types.h"
+#include "DNA_mask_types.h"
 
 #include "PIL_time.h"
 
@@ -52,6 +53,7 @@
 #include "IMB_imbuf.h"
 #include "IMB_imbuf_types.h"
 #include "IMB_colormanagement.h"
+#include "IMB_moviecache.h"
 
 #include "BKE_context.h"
 #include "BKE_global.h"
@@ -65,6 +67,7 @@
 
 #include "ED_gpencil.h"
 #include "ED_image.h"
+#include "ED_mask.h"
 #include "ED_screen.h"
 
 #include "UI_interface.h"
@@ -884,3 +887,48 @@ void draw_image_main(const bContext *C, ARegion *ar)
 	if (ima && show_render)
 		draw_render_info(scene, ima, ar, zoomx, zoomy);
 }
+
+void draw_image_cache(const bContext *C, ARegion *ar)
+{
+	SpaceImage *sima = CTX_wm_space_image(C);
+	Scene *scene = CTX_data_scene(C);
+	Image *image = ED_space_image(sima);
+	float x, cfra = CFRA, sfra = SFRA, efra = EFRA, framelen = ar->winx / (efra - sfra + 1);
+	Mask *mask = NULL;
+
+	if (sima->mode == SI_MODE_MASK) {
+		mask = ED_space_image_get_mask(sima);
+	}
+
+	if (image == NULL && mask == NULL) {
+		return;
+	}
+
+	glEnable(GL_BLEND);
+	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+	/* Draw cache background. */
+	ED_region_cache_draw_background(ar);
+
+	/* Draw cached segments. */
+	if (image != NULL && image->cache != NULL && ELEM(image->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) {
+		int num_segments = 0;
+		int *points = NULL;
+
+		IMB_moviecache_get_cache_segments(image->cache, IMB_PROXY_NONE, 0, &num_segments, &points);
+		ED_region_cache_draw_cached_segments(ar, num_segments, points, sfra + sima->iuser.offset, efra + sima->iuser.offset);
+	}
+
+	glDisable(GL_BLEND);
+
+	/* Draw current frame. */
+	x = (cfra - sfra) / (efra - sfra + 1) * ar->winx;
+
+	UI_ThemeColor(TH_CFRAME);
+	glRecti(x, 0, x + ceilf(framelen), 8 * UI_DPI_FAC);
+	ED_region_cache_draw_curfra_label(cfra, x, 8.0f * UI_DPI_FAC);
+
+	if (mask != NULL) {
+		ED_mask_draw_frames(mask, ar, cfra, sfra, efra);
+	}
+}
diff --git a/source/blender/editors/space_image/image_intern.h b/source/blender/editors/space_image/image_intern.h
index 30fa5f4..a6c7e15 100644
--- a/source/blender/editors/space_image/image_intern.h
+++ b/source/blender/editors/space_image/image_intern.h
@@ -53,6 +53,7 @@ extern const char *image_context_dir[]; /* doc access */
 
 /* image_draw.c */
 void draw_image_main(const struct bContext *C, struct ARegion *ar);
+void draw_image_cache(const struct bContext *C, struct ARegion *ar);
 void draw_image_grease_pencil(struct bContext *C, bool onlyv2d);
 void draw_image_sample_line(struct SpaceImage *sima);
 
diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c
index 1224ade..50f3bc2 100644
--- a/source/blender/editors/space_image/space_image.c
+++ b/source/blender/editors/space_image/space_image.c
@@ -739,13 +739,13 @@ static void image_m

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list