[Bf-blender-cvs] [69bac90] multiview: Stereo 3d Movie support

Dalai Felinto noreply at git.blender.org
Tue Sep 9 11:52:25 CEST 2014


Commit: 69bac908da35643e5c54c5b196e3ab7be3eed915
Author: Dalai Felinto
Date:   Tue Sep 9 01:28:58 2014 +0200
Branches: multiview
https://developer.blender.org/rB69bac908da35643e5c54c5b196e3ab7be3eed915

Stereo 3d Movie support

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

M	source/blender/blenkernel/BKE_image.h
M	source/blender/blenkernel/intern/image.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/space_image/image_buttons.c
M	source/blender/editors/space_image/image_ops.c
M	source/blender/makesdna/DNA_image_types.h
M	source/blender/makesrna/intern/rna_image.c

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

diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h
index 30a7c62..5dc5fde 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -251,7 +251,7 @@ float *BKE_image_get_float_pixels_for_frame(struct Image *image, int frame);
 
 /* Guess offset for the first frame in the sequence */
 int BKE_image_sequence_guess_offset(struct Image *image);
-
+bool BKE_image_has_anim(struct Image *image);
 bool BKE_image_is_animated(struct Image *image);
 bool BKE_image_is_dirty(struct Image *image);
 void BKE_image_file_format_set(struct Image *image, int ftype);
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 7d97087..b524d4c 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -278,6 +278,19 @@ void BKE_image_free_views(Image *image)
 	image_free_views(image);
 }
 
+static void image_free_anims(Image *ima)
+{
+	while (ima->anims.last) {
+		ImageAnim *ia = ima->anims.last;
+		if (ia->anim) {
+			IMB_free_anim(ia->anim);
+			ia->anim = NULL;
+		}
+		BLI_remlink(&ima->anims, ia);
+		MEM_freeN(ia);
+	}
+}
+
 /**
  * Simply free the image data from memory,
  * on display the image can load again (except for render buffers).
@@ -286,8 +299,7 @@ void BKE_image_free_buffers(Image *ima)
 {
 	image_free_cahced_frames(ima);
 
-	if (ima->anim) IMB_free_anim(ima->anim);
-	ima->anim = NULL;
+	image_free_anims(ima);
 
 	if (ima->rr) {
 		RE_FreeRenderResult(ima->rr);
@@ -347,6 +359,7 @@ static Image *image_alloc(Main *bmain, const char *name, short source, short typ
 
 		BKE_color_managed_colorspace_settings_init(&ima->colorspace_settings);
 		ima->stereo3d_format = MEM_mallocN(sizeof(Stereo3dFormat), "Image Stereo Format");
+		ima->anims.first = ima->anims.last = NULL;
 	}
 
 	return ima;
@@ -391,6 +404,19 @@ static void copy_image_views(ListBase *lbn, ListBase *lbo)
 	}
 }
 
+static void copy_image_anims(ListBase *lbn, ListBase *lbo)
+{
+	ImageAnim *ia, *ian;
+	lbn->first = lbn->last = NULL;
+	ia = lbo->first;
+	while(ia) {
+		ian = MEM_dupallocN(ia);
+		ian->anim = NULL;
+		BLI_addtail(lbn, ian);
+		ia = ia->next;
+	}
+}
+
 /* empty image block, of similar type and filename */
 Image *BKE_image_copy(Main *bmain, Image *ima)
 {
@@ -417,6 +443,7 @@ Image *BKE_image_copy(Main *bmain, Image *ima)
 
 	nima->stereo3d_format = MEM_dupallocN(ima->stereo3d_format);
 	copy_image_views(&nima->views, &ima->views);
+	copy_image_anims(&nima->anims, &ima->anims);
 
 	return nima;
 }
@@ -716,7 +743,9 @@ Image *BKE_image_load_exists(const char *filepath)
 			BLI_path_abs(strtest, ID_BLEND_PATH(G.main, &ima->id));
 
 			if (BLI_path_cmp(strtest, str) == 0) {
-				if (ima->anim == NULL || ima->id.us == 0) {
+				if ((BKE_image_has_anim(ima) == false) ||
+					(ima->id.us == 0))
+				{
 					BLI_strncpy(ima->name, filepath, sizeof(ima->name));    /* for stringcode */
 					ima->id.us++;                                       /* officially should not, it doesn't link here! */
 					if (ima->ok == 0)
@@ -2846,50 +2875,88 @@ static ImBuf *image_load_sequence_multilayer(Image *ima, ImageUser *iuser, int f
 
 static ImBuf *image_load_movie_file(Image *ima, ImageUser *iuser, int frame)
 {
-	struct ImBuf *ibuf = NULL;
+	struct ImBuf **ibuf;
+	struct ImBuf *r_ibuf;
+	const bool is_multiview = (ima->flag & IMA_IS_MULTIVIEW) != 0;
+	const size_t totfiles = image_num_files(ima);
+	const size_t totviews = is_multiview ? BLI_countlist(&ima->views) : 1;
+	size_t i;
+	ImageAnim *ia;
 
-	ima->lastframe = frame;
+	ibuf = MEM_mallocN(sizeof(ImBuf *) * totviews, "Image Views (movie) Imbufs");
+
+	if ((BKE_image_has_anim(ima) == false) ||
+		BLI_countlist(&ima->anims) != totfiles)
+	{
+		image_free_anims(ima);
 
-	if (ima->anim == NULL) {
-		char str[FILE_MAX];
+		for (i = 0; i < totfiles; i++) {
+			char str[FILE_MAX];
+			ImageUser iuser_t;
 
-		BKE_image_user_file_path(iuser, ima, str);
+			/* allocate the ImageAnim */
+			ia = MEM_mallocN(sizeof(ImageAnim), "Image Anim");
+			BLI_addtail(&ima->anims, ia);
 
-		/* FIXME: make several stream accessible in image editor, too*/
-		ima->anim = openanim(str, IB_rect, 0, ima->colorspace_settings.name);
+			if (iuser)
+				iuser_t = *iuser;
+			else
+				iuser_t.framenr = ima->lastframe;
 
-		/* let's initialize this user */
-		if (ima->anim && iuser && iuser->frames == 0)
-			iuser->frames = IMB_anim_get_duration(ima->anim,
-			                                      IMB_TC_RECORD_RUN);
+			iuser_t.view = i;
+
+			BKE_image_user_file_path(&iuser_t, ima, str);
+
+			/* FIXME: make several stream accessible in image editor, too*/
+			ia->anim = openanim(str, IB_rect, 0, ima->colorspace_settings.name);
+
+			/* let's initialize this user */
+			if (ia->anim && iuser && iuser->frames == 0)
+				iuser->frames = IMB_anim_get_duration(ia->anim,
+			                                          IMB_TC_RECORD_RUN);
+		}
 	}
 
-	if (ima->anim) {
-		int dur = IMB_anim_get_duration(ima->anim,
-		                                IMB_TC_RECORD_RUN);
-		int fra = frame - 1;
+	if (BKE_image_has_anim(ima)) {
+		for (i = 0, ia = ima->anims.first; ia; ia = ia->next, i++) {
+			int dur = IMB_anim_get_duration(ia->anim,
+			                                IMB_TC_RECORD_RUN);
+			int fra = frame - 1;
 
-		if (fra < 0) fra = 0;
-		if (fra > (dur - 1)) fra = dur - 1;
-		ibuf = IMB_makeSingleUser(
-		    IMB_anim_absolute(ima->anim, fra,
-		                      IMB_TC_RECORD_RUN,
-		                      IMB_PROXY_NONE));
+			if (fra < 0) fra = 0;
+			if (fra > (dur - 1)) fra = dur - 1;
+			ibuf[i] = IMB_makeSingleUser(
+			                             IMB_anim_absolute(ia->anim, fra,
+			                             IMB_TC_RECORD_RUN,
+			                             IMB_PROXY_NONE));
+			if (ibuf[i])
+				image_initialize_after_load(ima, ibuf[i]);
+		}
 
-		if (ibuf) {
-			image_initialize_after_load(ima, ibuf);
-			image_assign_ibuf(ima, ibuf, 0, frame);
+		if ((ima->flag & IMA_IS_STEREO) && ima->views_format == R_IMF_VIEWS_STEREO_3D)
+			IMB_ImBufFromStereo(ima->stereo3d_format, &ibuf[0], &ibuf[1]);
+
+		for (i = 0; i < totviews; i++) {
+			if (ibuf[i]) {
+				image_assign_ibuf(ima, ibuf[i], i, frame);
+			}
+			else
+				ima->ok &= 0;
 		}
-		else
-			ima->ok = 0;
 	}
 	else
 		ima->ok = 0;
 
+	/* return the original requested ImBuf */
+	r_ibuf = ibuf[is_multiview ? (iuser ? iuser->multi_index : 0) : 0];
+
 	if (iuser)
 		iuser->ok = ima->ok;
 
-	return ibuf;
+	/* cleanup */
+	MEM_freeN(ibuf);
+
+	return r_ibuf;
 }
 
 /* warning, 'iuser' can be NULL */
@@ -2898,7 +2965,7 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra)
 	struct ImBuf **ibuf;
 	struct ImBuf *r_ibuf;
 	char **str;
-		bool assign = false;
+	bool assign = false;
 	int flag;
 	const bool is_multiview = (ima->flag & IMA_IS_MULTIVIEW) != 0;
 	const size_t totfiles = image_num_files(ima);
@@ -3861,6 +3928,13 @@ int BKE_image_sequence_guess_offset(Image *image)
 	return atoi(num);
 }
 
+
+bool BKE_image_has_anim(Image *ima)
+{
+	return (BLI_countlist(&ima->anims) > 0) && (((ImageAnim *) ima->anims.first)->anim != NULL);
+}
+
+
 /**
  * Checks the image buffer changes (not keyframed values)
  *
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 89b2f93..46c0b20 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -3315,8 +3315,7 @@ static void direct_link_image(FileData *fd, Image *ima)
 		ima->gputexture = NULL;
 		ima->rr = NULL;
 	}
-	
-	ima->anim = NULL;
+
 	ima->repbind = NULL;
 	
 	/* undo system, try to restore render buffers */
@@ -3332,6 +3331,7 @@ static void direct_link_image(FileData *fd, Image *ima)
 	}
 
 	link_list(fd, &(ima->views));
+	ima->anims.first = ima->anims.last = NULL;
 
 	ima->packedfile = direct_link_packedfile(fd, ima->packedfile);
 	ima->preview = direct_link_preview_image(fd, ima->preview);
diff --git a/source/blender/editors/space_image/image_buttons.c b/source/blender/editors/space_image/image_buttons.c
index 89b6aaa..a0fe33c 100644
--- a/source/blender/editors/space_image/image_buttons.c
+++ b/source/blender/editors/space_image/image_buttons.c
@@ -82,9 +82,9 @@ static void image_info(Scene *scene, ImageUser *iuser, Image *ima, ImBuf *ibuf,
 	else {
 		if (ima->source == IMA_SRC_MOVIE) {
 			ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Movie"), len - ofs);
-			if (ima->anim)
+			if (BKE_image_has_anim(ima))
 				ofs += BLI_snprintf(str + ofs, len - ofs, IFACE_(" %d frs"),
-				                    IMB_anim_get_duration(ima->anim, IMB_TC_RECORD_RUN));
+				                    IMB_anim_get_duration(((ImageAnim *)ima->anims.first)->anim, IMB_TC_RECORD_RUN));
 		}
 		else {
 			ofs += BLI_strncpy_rlen(str, IFACE_("Image"), len - ofs);
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 30385fe..cb5f920 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -1376,10 +1376,10 @@ static int image_match_len_exec(bContext *C, wmOperator *UNUSED(op))
 		
 	}
 
-	if (!ima || !iuser || !ima->anim)
+	if (!ima || !iuser || !BKE_image_has_anim(ima))
 		return OPERATOR_CANCELLED;
 
-	iuser->frames = IMB_anim_get_duration(ima->anim, IMB_TC_RECORD_RUN);
+	iuser->frames = IMB_anim_get_duration(((ImageAnim *) ima->anims.first)->anim, IMB_TC_RECORD_RUN);
 	BKE_image_user_frame_calc(iuser, scene->r.cfra, 0);
 
 	return OPERATOR_FINISHED;
diff --git a/source/blender/makesdna/DNA_image_types.h b/source/blender/makesdna/DNA_image_types.h
index 4b561d9..0e7982b 100644
--- a/source/blender/makesdna/DNA_image_types.h
+++ b/source/blender/makesdna/DNA_image_types.h
@@ -73,6 +73,11 @@ enum {
 	IMA_SHOW_STEREO         = (1 << 4),
 };
 
+typedef struct ImageAnim {
+	struct ImageAnim *next, *prev;
+	struct anim *anim;
+} ImageAnim;
+
 typedef struct ImageView {
 	struct ImageView *next, *prev;
 	char name[64];			/* MAX_NAME */
@@ -88,7 +93,7 @@ typedef struct Image {
 	struct GPUTexture *gputexture;	/* not written in file */
 	
 	/* sources from: */
-	struct anim *anim;
+	ListBase anims;
 	

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list