[Bf-blender-cvs] [8904eaf] master: Fix T40107: painting on a psd image crashes blender + style cleanup in file

Dalai Felinto noreply at git.blender.org
Sat May 10 15:59:28 CEST 2014


Commit: 8904eaf5047780eaf97eb7dc3acebb1b65f258bd
Author: Dalai Felinto
Date:   Sat May 10 10:58:35 2014 -0300
https://developer.blender.org/rB8904eaf5047780eaf97eb7dc3acebb1b65f258bd

Fix T40107: painting on a psd image crashes blender + style cleanup in file

The issue was that we can't assume we support the colorspace from the file. The reported file had an invalid colorspace in fact, which was leading to the segfault in Blender.

Thanks for Sergey Sharybin for the help here.

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

M	source/blender/imbuf/intern/oiio/openimageio_api.cpp

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

diff --git a/source/blender/imbuf/intern/oiio/openimageio_api.cpp b/source/blender/imbuf/intern/oiio/openimageio_api.cpp
index ec9c8fd..6e3f97a 100644
--- a/source/blender/imbuf/intern/oiio/openimageio_api.cpp
+++ b/source/blender/imbuf/intern/oiio/openimageio_api.cpp
@@ -100,9 +100,9 @@ static ImBuf *imb_oiio_load_image(ImageInput *in, int width, int height, int com
 	{
 		if (!in->read_image(TypeDesc::UINT8,
 		                    (uchar *)ibuf->rect + (height - 1) * scanlinesize,
-		           	   	    AutoStride,
-		           	   	    -scanlinesize,
-		           	   	    AutoStride))
+		                    AutoStride,
+		                    -scanlinesize,
+		                    AutoStride))
 		{
 			std::cerr << __func__ << ": ImageInput::read_image() failed:" << std::endl
 			          << in->geterror() << std::endl;
@@ -139,9 +139,9 @@ static ImBuf *imb_oiio_load_image_float(ImageInput *in, int width, int height, i
 	{
 		if (!in->read_image(TypeDesc::FLOAT,
 		                    (uchar *)ibuf->rect_float + (height - 1) * scanlinesize,
-		           	   	    AutoStride,
-		           	   	    -scanlinesize,
-		           	   	    AutoStride))
+		                    AutoStride,
+		                    -scanlinesize,
+		                    AutoStride))
 		{
 			std::cerr << __func__ << ": ImageInput::read_image() failed:" << std::endl
 			          << in->geterror() << std::endl;
@@ -185,7 +185,8 @@ int imb_is_a_photoshop(const char *filename)
 int imb_save_photoshop(struct ImBuf *ibuf, const char *name, int flags)
 {
 	if (flags & IB_mem) {
-		printf("Photoshop PSD-save: Create PSD in memory CURRENTLY NOT SUPPORTED !\n");
+		std::cerr << __func__ << ": Photoshop PSD-save: Create PSD in memory"
+		          << " currently not supported" << std::endl;
 		imb_addencodedbufferImBuf(ibuf);
 		ibuf->encodedsize = 0;
 		return(0);
@@ -202,6 +203,7 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac
 	bool is_float, is_alpha;
 	TypeDesc typedesc;
 	int basesize;
+	char file_colorspace[IM_MAX_SPACE];
 
 	/* load image from file through OIIO */
 	if (imb_is_a_photoshop(filename) == 0) return (NULL);
@@ -226,7 +228,15 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac
 	}
 
 	string ics = spec.get_string_attribute("oiio:ColorSpace");
-	BLI_strncpy(colorspace, ics.c_str(), IM_MAX_SPACE);
+	BLI_strncpy(file_colorspace, ics.c_str(), IM_MAX_SPACE);
+
+	/* only use colorspaces exis */
+	if (colormanage_colorspace_get_named(file_colorspace))
+		strcpy(colorspace, file_colorspace);
+	else
+		std::cerr << __func__ << ": The embed colorspace (\"" << file_colorspace
+		          << "\") not supported in existent OCIO configuration file. Fallback "
+		          << "to system default colorspace (\"" << colorspace << "\")." << std::endl;
 
 	width = spec.width;
 	height = spec.height;




More information about the Bf-blender-cvs mailing list