[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50592] branches/soc-2011-tomato/source/ blender: Color Management: image buffer loading reworked

Sergey Sharybin sergey.vfx at gmail.com
Fri Sep 14 16:36:48 CEST 2012


Revision: 50592
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50592
Author:   nazgul
Date:     2012-09-14 14:36:47 +0000 (Fri, 14 Sep 2012)
Log Message:
-----------
Color Management: image buffer loading reworked

Before this color space settings in image/movie clip data blocks
defined space in which loaded image buffer is, based on whether
this buffer contains float or byte buffer. This didn't work well
for formats like 16bit PNG, which are in fact non-linear formats
but were represented in Blender as float buffers.

Now image buffer loader is responsible to set up input default
color space for image/movie clip data blocks, which could be
based on format itself only or on particular file properties.

This means image/movie clip data blocks' input colorspace will
be initialized at time first image buffer is loaded.

This also resolves old confusing thing with image buffer's profile
flag, which in could have been non-linear for image buffer which
contained float buffer only -- this happened in mentioned case of
16 bit PNG format, i.e. Now float buffer would always be linear
which should make it easier to get rid of image buffer's profile.

Modified Paths:
--------------
    branches/soc-2011-tomato/source/blender/blenkernel/BKE_image.h
    branches/soc-2011-tomato/source/blender/blenkernel/intern/image.c
    branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c
    branches/soc-2011-tomato/source/blender/blenkernel/intern/ocean.c
    branches/soc-2011-tomato/source/blender/blenkernel/intern/sequencer.c
    branches/soc-2011-tomato/source/blender/collada/ImageExporter.cpp
    branches/soc-2011-tomato/source/blender/editors/interface/interface_icons.c
    branches/soc-2011-tomato/source/blender/editors/render/render_preview.c
    branches/soc-2011-tomato/source/blender/editors/space_file/filelist.c
    branches/soc-2011-tomato/source/blender/editors/space_image/image_ops.c
    branches/soc-2011-tomato/source/blender/imbuf/IMB_colormanagement.h
    branches/soc-2011-tomato/source/blender/imbuf/IMB_imbuf.h
    branches/soc-2011-tomato/source/blender/imbuf/intern/IMB_anim.h
    branches/soc-2011-tomato/source/blender/imbuf/intern/IMB_colormanagement_intern.h
    branches/soc-2011-tomato/source/blender/imbuf/intern/IMB_filetype.h
    branches/soc-2011-tomato/source/blender/imbuf/intern/anim_movie.c
    branches/soc-2011-tomato/source/blender/imbuf/intern/bmp.c
    branches/soc-2011-tomato/source/blender/imbuf/intern/cineon/cineon_dpx.c
    branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c
    branches/soc-2011-tomato/source/blender/imbuf/intern/dds/dds_api.cpp
    branches/soc-2011-tomato/source/blender/imbuf/intern/dds/dds_api.h
    branches/soc-2011-tomato/source/blender/imbuf/intern/filetype.c
    branches/soc-2011-tomato/source/blender/imbuf/intern/indexer.c
    branches/soc-2011-tomato/source/blender/imbuf/intern/iris.c
    branches/soc-2011-tomato/source/blender/imbuf/intern/jp2.c
    branches/soc-2011-tomato/source/blender/imbuf/intern/jpeg.c
    branches/soc-2011-tomato/source/blender/imbuf/intern/openexr/openexr_api.cpp
    branches/soc-2011-tomato/source/blender/imbuf/intern/openexr/openexr_api.h
    branches/soc-2011-tomato/source/blender/imbuf/intern/png.c
    branches/soc-2011-tomato/source/blender/imbuf/intern/radiance_hdr.c
    branches/soc-2011-tomato/source/blender/imbuf/intern/readimage.c
    branches/soc-2011-tomato/source/blender/imbuf/intern/targa.c
    branches/soc-2011-tomato/source/blender/imbuf/intern/thumbs.c
    branches/soc-2011-tomato/source/blender/imbuf/intern/tiff.c
    branches/soc-2011-tomato/source/blender/imbuf/intern/writeimage.c
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_image_api.c
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_sequencer_api.c
    branches/soc-2011-tomato/source/blender/render/intern/source/pipeline.c
    branches/soc-2011-tomato/source/blender/windowmanager/intern/wm_operators.c
    branches/soc-2011-tomato/source/blender/windowmanager/intern/wm_playanim.c

Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_image.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_image.h	2012-09-14 14:35:05 UTC (rev 50591)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_image.h	2012-09-14 14:36:47 UTC (rev 50592)
@@ -46,6 +46,8 @@
 struct ImageFormatData;
 struct Main;
 
+#define IMA_MAX_SPACE       64
+
 /* call from library */
 void    BKE_image_free(struct Image *me);
 
@@ -73,7 +75,7 @@
 void    BKE_imformat_defaults(struct ImageFormatData *im_format);
 void    BKE_imbuf_to_image_format(struct ImageFormatData *im_format, const struct ImBuf *imbuf);
 
-struct anim *openanim(const char *name, int flags, int streamindex);
+struct anim *openanim(const char *name, int flags, int streamindex, char colorspace[IMA_MAX_SPACE]);
 
 void    BKE_image_de_interlace(struct Image *ima, int odd);
 

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/image.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/image.c	2012-09-14 14:35:05 UTC (rev 50591)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/image.c	2012-09-14 14:36:47 UTC (rev 50592)
@@ -304,12 +304,6 @@
 		else
 			ibuf->flags &= ~IB_cm_predivide;
 
-		if (ima->source == IMA_SRC_GENERATED) {
-			/* for other image types spaces are set by image_initialize_after_load */
-
-			IMB_colormanagement_imbuf_assign_spaces(ibuf, &ima->colorspace_settings);
-		}
-
 		/* this function accepts (link == NULL) */
 		BLI_insertlinkbefore(&ima->ibufs, link, ibuf);
 
@@ -1910,12 +1904,12 @@
 }
 
 /* used by sequencer too */
-struct anim *openanim(const char *name, int flags, int streamindex)
+struct anim *openanim(const char *name, int flags, int streamindex, char colorspace[IMA_MAX_SPACE])
 {
 	struct anim *anim;
 	struct ImBuf *ibuf;
 
-	anim = IMB_open_anim(name, flags, streamindex);
+	anim = IMB_open_anim(name, flags, streamindex, colorspace);
 	if (anim == NULL) return NULL;
 
 	ibuf = IMB_anim_absolute(anim, 0, IMB_TC_NONE, IMB_PROXY_NONE);
@@ -2224,9 +2218,6 @@
 /* common stuff to do with images after loading */
 static void image_initialize_after_load(Image *ima, ImBuf *ibuf)
 {
-	/* make float buffer stored in ImBuf scene linear space */
-	IMB_colormanagement_imbuf_make_scene_linear(ibuf, &ima->colorspace_settings);
-
 	/* preview is NULL when it has never been used as an icon before */
 	if (G.background == 0 && ima->preview == NULL)
 		BKE_icon_changed(BKE_icon_getid(&ima->id));
@@ -2261,7 +2252,7 @@
 		flag |= IB_premul;
 
 	/* read ibuf */
-	ibuf = IMB_loadiffname(name, flag);
+	ibuf = IMB_loadiffname(name, flag, ima->colorspace_settings.name);
 
 #if 0
 	if (ibuf) {
@@ -2369,7 +2360,7 @@
 		BKE_image_user_file_path(iuser, ima, str);
 
 		/* FIXME: make several stream accessible in image editor, too*/
-		ima->anim = openanim(str, IB_rect, 0);
+		ima->anim = openanim(str, IB_rect, 0, ima->colorspace_settings.name);
 
 		/* let's initialize this user */
 		if (ima->anim && iuser && iuser->frames == 0)
@@ -2420,8 +2411,8 @@
 		flag = IB_rect | IB_multilayer;
 		if (ima->flag & IMA_DO_PREMUL) flag |= IB_premul;
 
-		ibuf = IMB_ibImageFromMemory((unsigned char *)ima->packedfile->data,
-		                             ima->packedfile->size, flag, "<packed data>");
+		ibuf = IMB_ibImageFromMemory((unsigned char *)ima->packedfile->data, ima->packedfile->size, flag,
+		                             ima->colorspace_settings.name, "<packed data>");
 	}
 	else {
 		flag = IB_rect | IB_multilayer | IB_metadata;
@@ -2433,7 +2424,7 @@
 		BKE_image_user_file_path(iuser, ima, str);
 
 		/* read ibuf */
-		ibuf = IMB_loadiffname(str, flag);
+		ibuf = IMB_loadiffname(str, flag, ima->colorspace_settings.name);
 	}
 
 	if (ibuf) {

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c	2012-09-14 14:35:05 UTC (rev 50591)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c	2012-09-14 14:36:47 UTC (rev 50592)
@@ -199,19 +199,25 @@
 	struct ImBuf *ibuf;
 	char name[FILE_MAX];
 	int loadflag, use_proxy = FALSE;
+	char *colorspace;
 
 	use_proxy = (flag & MCLIP_USE_PROXY) && user->render_size != MCLIP_PROXY_RENDER_SIZE_FULL;
 	if (use_proxy) {
 		int undistort = user->render_flag & MCLIP_PROXY_RENDER_UNDISTORT;
 		get_proxy_fname(clip, user->render_size, undistort, framenr, name);
+
+		/* proxies were built using default color space settings */
+		colorspace = NULL;
 	}
-	else
+	else {
 		get_sequence_fname(clip, framenr, name);
+		colorspace = clip->colorspace_settings.name;
+	}
 
 	loadflag = IB_rect | IB_multilayer;
 
 	/* read ibuf */
-	ibuf = IMB_loadiffname(name, loadflag);
+	ibuf = IMB_loadiffname(name, loadflag, colorspace);
 
 	return ibuf;
 }
@@ -225,7 +231,7 @@
 		BLI_path_abs(str, ID_BLEND_PATH(G.main, &clip->id));
 
 		/* FIXME: make several stream accessible in image editor, too */
-		clip->anim = openanim(str, IB_rect, 0);
+		clip->anim = openanim(str, IB_rect, 0, clip->colorspace_settings.name);
 
 		if (clip->anim) {
 			if (clip->flag & MCLIP_USE_PROXY_CUSTOM_DIR) {
@@ -781,11 +787,6 @@
 			ibuf = movieclip_load_movie_file(clip, user, framenr, flag);
 		}
 
-		if (ibuf) {
-			/* make float buffer stored in ImBuf scene linear space */
-			IMB_colormanagement_imbuf_make_scene_linear(ibuf, &clip->colorspace_settings);
-		}
-
 		if (ibuf && (cache_flag & MOVIECLIP_CACHE_SKIP) == 0)
 			put_imbuf_cache(clip, user, ibuf, flag);
 	}

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/ocean.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/ocean.c	2012-09-14 14:35:05 UTC (rev 50591)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/ocean.c	2012-09-14 14:36:47 UTC (rev 50592)
@@ -1117,19 +1117,20 @@
 	/* if image is already loaded in mem, return */
 	if (och->ibufs_disp[f] != NULL) return;
 
+	/* use default color spaces since we know for sure cache files were saved with default settings too */
 
 	cache_filename(string, och->bakepath, och->relbase, frame, CACHE_TYPE_DISPLACE);
-	och->ibufs_disp[f] = IMB_loadiffname(string, 0);
+	och->ibufs_disp[f] = IMB_loadiffname(string, 0, NULL);
 	//if (och->ibufs_disp[f] == NULL) printf("error loading %s\n", string);
 	//else printf("loaded cache %s\n", string);
 
 	cache_filename(string, och->bakepath, och->relbase, frame, CACHE_TYPE_FOAM);
-	och->ibufs_foam[f] = IMB_loadiffname(string, 0);
+	och->ibufs_foam[f] = IMB_loadiffname(string, 0, NULL);
 	//if (och->ibufs_foam[f] == NULL) printf("error loading %s\n", string);
 	//else printf("loaded cache %s\n", string);
 
 	cache_filename(string, och->bakepath, och->relbase, frame, CACHE_TYPE_NORMAL);
-	och->ibufs_norm[f] = IMB_loadiffname(string, 0);
+	och->ibufs_norm[f] = IMB_loadiffname(string, 0, NULL);
 	//if (och->ibufs_norm[f] == NULL) printf("error loading %s\n", string);
 	//else printf("loaded cache %s\n", string);
 }

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/sequencer.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/sequencer.c	2012-09-14 14:35:05 UTC (rev 50591)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/sequencer.c	2012-09-14 14:36:47 UTC (rev 50592)
@@ -686,8 +686,10 @@
 			BLI_path_abs(str, G.main->name);
 
 			if (seq->anim) IMB_free_anim(seq->anim);
-			seq->anim = openanim(str, IB_rect | ((seq->flag & SEQ_FILTERY) ? IB_animdeinterlace : 0), seq->streamindex);
 
+			/* OCIO_TODO: support configurable input space for strips */
+			seq->anim = openanim(str, IB_rect | ((seq->flag & SEQ_FILTERY) ? IB_animdeinterlace : 0), seq->streamindex, NULL);
+
 			if (!seq->anim) {
 				return;
 			}
@@ -1183,7 +1185,8 @@
 	                 seq->strip->dir, seq->strip->stripdata->name);
 	BLI_path_abs(name, G.main->name);
 	
-	seq->anim = openanim(name, IB_rect | ((seq->flag & SEQ_FILTERY) ? IB_animdeinterlace : 0), seq->streamindex);
+	/* OCIO_TODO: support configurable input space for strips */
+	seq->anim = openanim(name, IB_rect | ((seq->flag & SEQ_FILTERY) ? IB_animdeinterlace : 0), seq->streamindex, NULL);
 
 	if (seq->anim == NULL) {
 		return;
@@ -1289,8 +1292,9 @@
 			if (seq_proxy_get_fname(seq, cfra, render_size, name) == 0) {
 				return NULL;
 			}
- 
-			seq->strip->proxy->anim = openanim(name, IB_rect, 0);
+
+			/* proxies are generated in default color space */
+			seq->strip->proxy->anim = openanim(name, IB_rect, 0, NULL);
 		}
 		if (seq->strip->proxy->anim == NULL) {
 			return NULL;
@@ -1308,7 +1312,8 @@
 	}
 
 	if (BLI_exists(name)) {
-		ImBuf *ibuf = IMB_loadiffname(name, IB_rect);
+		/* OCIO_TODO: support configurable spaces for strips */
+		ImBuf *ibuf = IMB_loadiffname(name, IB_rect, NULL);
 
 		if (ibuf)
 			BKE_sequencer_imbuf_assign_spaces(context.scene, ibuf);
@@ -1351,7 +1356,8 @@
 		ibuf->planes = 24;
 
 	BLI_make_existing_file(name);
-	
+
+	/* OCIO_TODO: support per-strip color space settings */
 	ok = IMB_saveiff(ibuf, name, IB_rect | IB_zbuf | IB_zbuffloat);
 	if (ok == 0) {
 		perror(name);
@@ -2536,7 +2542,8 @@
 				BLI_path_abs(name, G.main->name);
 			}
 
-			if (s_elem && (ibuf = IMB_loadiffname(name, IB_rect))) {
+			/* OCIO_TODO: support configurable space for image strips */
+			if (s_elem && (ibuf = IMB_loadiffname(name, IB_rect, NULL))) {
 				/* we don't need both (speed reasons)! */
 				if (ibuf->rect_float && ibuf->rect)
 					imb_freerectImBuf(ibuf);
@@ -4046,7 +4053,8 @@
 	BLI_strncpy(path, seq_load->path, sizeof(path));
 	BLI_path_abs(path, G.main->name);
 
-	an = openanim(path, IB_rect, 0);
+	/* OCIO_TODO: support configurable input space for strips */
+	an = openanim(path, IB_rect, 0, NULL);
 
 	if (an == NULL)
 		return NULL;

Modified: branches/soc-2011-tomato/source/blender/collada/ImageExporter.cpp
===================================================================
--- branches/soc-2011-tomato/source/blender/collada/ImageExporter.cpp	2012-09-14 14:35:05 UTC (rev 50591)
+++ branches/soc-2011-tomato/source/blender/collada/ImageExporter.cpp	2012-09-14 14:36:47 UTC (rev 50592)
@@ -102,7 +102,7 @@
 			// So we have to export it. The export will keep the image state intact,

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list