[Bf-blender-cvs] [9220f3b64f9] temp-udim-images: Add first parts of UDIM support in the core image code

Lukas Stockner noreply at git.blender.org
Sun Jun 10 21:21:24 CEST 2018


Commit: 9220f3b64f97ae094bff061c2234df16b3427f7e
Author: Lukas Stockner
Date:   Sun Jun 10 19:01:15 2018 +0200
Branches: temp-udim-images
https://developer.blender.org/rB9220f3b64f97ae094bff061c2234df16b3427f7e

Add first parts of UDIM support in the core image code

Internally, UDIMs are handled very similar to sequences - they consist of a list
of files (containing a sequential number in their name) that all belong to one
Image datablock. This means that existing code like the IBuf cache can be reused.

The current drawing and opening code are just a minimal implementation to test
the core code, they'll be improved of course.

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

M	source/blender/blenkernel/BKE_image.h
M	source/blender/blenkernel/intern/bpath.c
M	source/blender/blenkernel/intern/image.c
M	source/blender/blenkernel/intern/packedFile.c
M	source/blender/editors/space_image/image_buttons.c
M	source/blender/editors/space_image/image_draw.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
M	source/blender/makesrna/intern/rna_image_api.c

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

diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h
index 1af123759e6..7b3aa3a3679 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -136,6 +136,7 @@ struct RenderResult;
 #define IMA_SRC_MOVIE       3
 #define IMA_SRC_GENERATED   4
 #define IMA_SRC_VIEWER      5
+#define IMA_SRC_UDIM        6
 
 /* ima->type, how to handle/generate it */
 #define IMA_TYPE_IMAGE      0
@@ -291,6 +292,7 @@ int BKE_image_sequence_guess_offset(struct Image *image);
 bool BKE_image_has_anim(struct Image *image);
 bool BKE_image_has_packedfile(struct Image *image);
 bool BKE_image_is_animated(struct Image *image);
+bool BKE_image_has_multiple(struct Image *image);
 bool BKE_image_is_dirty(struct Image *image);
 void BKE_image_file_format_set(struct Image *image, int ftype, const struct ImbFormatOptions *options);
 bool BKE_image_has_loaded_ibuf(struct Image *image);
diff --git a/source/blender/blenkernel/intern/bpath.c b/source/blender/blenkernel/intern/bpath.c
index 82d9f9f8f69..605ba1644f3 100644
--- a/source/blender/blenkernel/intern/bpath.c
+++ b/source/blender/blenkernel/intern/bpath.c
@@ -435,7 +435,7 @@ void BKE_bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int
 			Image *ima;
 			ima = (Image *)id;
 			if (BKE_image_has_packedfile(ima) == false || (flag & BKE_BPATH_TRAVERSE_SKIP_PACKED) == 0) {
-				if (ELEM(ima->source, IMA_SRC_FILE, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) {
+				if (ELEM(ima->source, IMA_SRC_FILE, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE, IMA_SRC_UDIM)) {
 					if (rewrite_path_fixed(ima->name, visit_cb, absbase, bpath_user_data)) {
 						if (flag & BKE_BPATH_TRAVERSE_RELOAD_EDITED) {
 							if (!BKE_image_has_packedfile(ima) &&
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 9a29a8a898b..a0de165441e 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -111,9 +111,9 @@ static void image_add_view(Image *ima, const char *viewname, const char *filepat
 /* max int, to indicate we don't store sequences in ibuf */
 #define IMA_NO_INDEX    0x7FEFEFEF
 
-/* quick lookup: supports 1 million frames, thousand passes */
-#define IMA_MAKE_INDEX(frame, index)    (((frame) << 10) + (index))
-#define IMA_INDEX_FRAME(index)           ((index) >> 10)
+/* quick lookup: supports 1 million entries, thousand passes */
+#define IMA_MAKE_INDEX(entry, index)    (((entry) << 10) + (index))
+#define IMA_INDEX_ENTRY(index)           ((index) >> 10)
 #if 0
 #define IMA_INDEX_PASS(index)           (index & ~1023)
 #endif
@@ -142,7 +142,7 @@ static void imagecache_keydata(void *userkey, int *framenr, int *proxy, int *ren
 {
 	ImageCacheKey *key = userkey;
 
-	*framenr = IMA_INDEX_FRAME(key->index);
+	*framenr = IMA_INDEX_ENTRY(key->index);
 	*proxy = IMB_PROXY_NONE;
 	*render_flags = 0;
 }
@@ -403,28 +403,28 @@ static Image *image_alloc(Main *bmain, const char *name, short source, short typ
 	return ima;
 }
 
-/* Get the ibuf from an image cache by it's index and frame.
+/* Get the ibuf from an image cache by it's index and entry.
  * Local use here only.
  *
  * Returns referenced image buffer if it exists, callee is to
  * call IMB_freeImBuf to de-reference the image buffer after
  * it's done handling it.
  */
-static ImBuf *image_get_cached_ibuf_for_index_frame(Image *ima, int index, int frame)
+static ImBuf *image_get_cached_ibuf_for_index_entry(Image *ima, int index, int entry)
 {
 	if (index != IMA_NO_INDEX) {
-		index = IMA_MAKE_INDEX(frame, index);
+		index = IMA_MAKE_INDEX(entry, index);
 	}
 
 	return imagecache_get(ima, index);
 }
 
 /* no ima->ibuf anymore, but listbase */
-static void image_assign_ibuf(Image *ima, ImBuf *ibuf, int index, int frame)
+static void image_assign_ibuf(Image *ima, ImBuf *ibuf, int index, int entry)
 {
 	if (ibuf) {
 		if (index != IMA_NO_INDEX)
-			index = IMA_MAKE_INDEX(frame, index);
+			index = IMA_MAKE_INDEX(entry, index);
 
 		imagecache_put(ima, index, ibuf);
 	}
@@ -784,7 +784,7 @@ static void image_memorypack_multiview(Image *ima)
 	image_free_packedfiles(ima);
 
 	for (i = 0, iv = ima->views.first; iv; iv = iv->next, i++) {
-		ImBuf *ibuf = image_get_cached_ibuf_for_index_frame(ima, i, 0);
+		ImBuf *ibuf = image_get_cached_ibuf_for_index_entry(ima, i, 0);
 
 		ibuf->ftype = IMB_FTYPE_PNG;
 		ibuf->planes = R_IMF_PLANES_RGBA;
@@ -839,7 +839,7 @@ void BKE_image_memorypack(Image *ima)
 		return;
 	}
 
-	ibuf = image_get_cached_ibuf_for_index_frame(ima, IMA_NO_INDEX, 0);
+	ibuf = image_get_cached_ibuf_for_index_entry(ima, IMA_NO_INDEX, 0);
 
 	if (ibuf == NULL)
 		return;
@@ -1048,12 +1048,13 @@ void BKE_image_free_all_textures(void)
 #endif
 }
 
+/* TODO(lukas): What does this do? */
 static bool imagecache_check_free_anim(ImBuf *ibuf, void *UNUSED(userkey), void *userdata)
 {
 	int except_frame = *(int *)userdata;
 	return (ibuf->userflags & IB_BITMAPDIRTY) == 0 &&
 	       (ibuf->index != IMA_NO_INDEX) &&
-	       (except_frame != IMA_INDEX_FRAME(ibuf->index));
+	       (except_frame != IMA_INDEX_ENTRY(ibuf->index));
 }
 
 /* except_frame is weak, only works for seqs without offset... */
@@ -2734,7 +2735,7 @@ void BKE_image_signal(Image *ima, ImageUser *iuser, int signal)
 
 			if (ima->source == IMA_SRC_GENERATED) {
 				if (ima->gen_x == 0 || ima->gen_y == 0) {
-					ImBuf *ibuf = image_get_cached_ibuf_for_index_frame(ima, IMA_NO_INDEX, 0);
+					ImBuf *ibuf = image_get_cached_ibuf_for_index_entry(ima, IMA_NO_INDEX, 0);
 					if (ibuf) {
 						ima->gen_x = ibuf->x;
 						ima->gen_y = ibuf->y;
@@ -2817,7 +2818,7 @@ void BKE_image_signal(Image *ima, ImageUser *iuser, int signal)
 		case IMA_SIGNAL_USER_NEW_IMAGE:
 			if (iuser) {
 				iuser->ok = 1;
-				if (ima->source == IMA_SRC_FILE || ima->source == IMA_SRC_SEQUENCE) {
+				if (ELEM(ima->source, IMA_SRC_FILE, IMA_SRC_SEQUENCE, IMA_SRC_UDIM)) {
 					if (ima->type == IMA_TYPE_MULTILAYER) {
 						image_init_imageuser(ima, iuser);
 					}
@@ -2950,7 +2951,7 @@ void BKE_image_multiview_index(Image *ima, ImageUser *iuser)
 /* and because rendered results use fake layer/passes, don't correct for wrong indices here */
 bool BKE_image_is_multilayer(Image *ima)
 {
-	if (ELEM(ima->source, IMA_SRC_FILE, IMA_SRC_SEQUENCE)) {
+	if (ELEM(ima->source, IMA_SRC_FILE, IMA_SRC_SEQUENCE, IMA_SRC_UDIM)) {
 		if (ima->type == IMA_TYPE_MULTILAYER) {
 			return true;
 		}
@@ -3038,7 +3039,7 @@ void BKE_image_release_renderresult(Scene *scene, Image *ima)
 bool BKE_image_is_openexr(struct Image *ima)
 {
 #ifdef WITH_OPENEXR
-	if (ELEM(ima->source, IMA_SRC_FILE, IMA_SRC_SEQUENCE)) {
+	if (ELEM(ima->source, IMA_SRC_FILE, IMA_SRC_SEQUENCE, IMA_SRC_UDIM)) {
 		return BLI_testextensie(ima->name, ".exr");
 	}
 #else
@@ -3240,7 +3241,7 @@ static ImBuf *load_sequence_single(Image *ima, ImageUser *iuser, int frame, cons
 	return ibuf;
 }
 
-static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int frame)
+static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int entry, int frame)
 {
 	struct ImBuf *ibuf = NULL;
 	const bool is_multiview = BKE_image_is_multiview(ima);
@@ -3250,7 +3251,7 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int frame)
 	if (!is_multiview) {
 		ibuf = load_sequence_single(ima, iuser, frame, 0, &assign);
 		if (assign) {
-			image_assign_ibuf(ima, ibuf, 0, frame);
+			image_assign_ibuf(ima, ibuf, 0, entry);
 		}
 	}
 	else {
@@ -3271,7 +3272,7 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int frame)
 
 		if (assign) {
 			for (i = 0; i < totviews; i++) {
-				image_assign_ibuf(ima, ibuf_arr[i], i, frame);
+				image_assign_ibuf(ima, ibuf_arr[i], i, entry);
 			}
 		}
 
@@ -3289,7 +3290,7 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int frame)
 	return ibuf;
 }
 
-static ImBuf *image_load_sequence_multilayer(Image *ima, ImageUser *iuser, int frame)
+static ImBuf *image_load_sequence_multilayer(Image *ima, ImageUser *iuser, int entry, int frame)
 {
 	struct ImBuf *ibuf = NULL;
 
@@ -3307,7 +3308,7 @@ static ImBuf *image_load_sequence_multilayer(Image *ima, ImageUser *iuser, int f
 			ima->rr = NULL;
 		}
 
-		ibuf = image_load_sequence_file(ima, iuser, frame);
+		ibuf = image_load_sequence_file(ima, iuser, entry, frame);
 
 		if (ibuf) { /* actually an error */
 			ima->type = IMA_TYPE_IMAGE;
@@ -3327,7 +3328,7 @@ static ImBuf *image_load_sequence_multilayer(Image *ima, ImageUser *iuser, int f
 			ibuf->channels = rpass->channels;
 
 			image_initialize_after_load(ima, ibuf);
-			image_assign_ibuf(ima, ibuf, iuser ? iuser->multi_index : 0, frame);
+			image_assign_ibuf(ima, ibuf, iuser ? iuser->multi_index : 0, entry);
 
 		}
 		// else printf("pass not found\n");
@@ -3768,7 +3769,7 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser, void **r_loc
 		}
 	}
 
-	ibuf = image_get_cached_ibuf_for_index_frame(ima, IMA_NO_INDEX, 0);
+	ibuf = image_get_cached_ibuf_for_index_entry(ima, IMA_NO_INDEX, 0);
 
 	/* make ibuf if needed, and initialize it */
 	if (ibuf == NULL) {
@@ -3852,7 +3853,7 @@ static int image_get_multiview_index(Image *ima, ImageUser *iuser)
 {
 	const bool is_multilayer = BKE_image_is_multilayer(ima);
 	const bool is_backdrop = (ima->source == IMA_SRC_VIEWER) && (ima->type ==  IMA_TYPE_COMPOSITE) && (iuser == NULL);
-	int index = BKE_image_is_animated(ima) ? 0 : IMA_NO_INDEX;
+	int index = BKE_image_has_multiple(ima) ? 0 : IMA_NO_INDEX;
 
 	if (is_multilayer) {
 		return iuser ? iuser->multi_index : index;
@@ -3870,24 +3871,27 @@ static int image_get_multiview_index(Image *ima, ImageUser *iuser)
 	return index;
 }
 
-static void image_get_frame_and_index(Image *ima, ImageUser *iuser, int *r_frame, int *r_index)
+static void image_get_entry_and_index(Image *ima, ImageUser *iuser, int *r_entry, int *r_index)
 {
-	int frame = 0, index = image_get_multiview_index(ima, iuser);
+	int entry = 0, index = image_get_multiview_index(ima, iuser);
 
 	/* see if we already have an appropriate ibuf, with image source and type */
 	if (ima->source == IMA_SRC_MOVIE) {
-		frame = iuser ? iuser->framenr : ima->lastframe;
+		entry = iuser ? iuser->framenr : ima->l

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list