[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50594] branches/soc-2011-tomato: Color Management: re-implement OCIO-less build configuration

Sergey Sharybin sergey.vfx at gmail.com
Fri Sep 14 16:37:00 CEST 2012


Revision: 50594
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50594
Author:   nazgul
Date:     2012-09-14 14:37:00 +0000 (Fri, 14 Sep 2012)
Log Message:
-----------
Color Management: re-implement OCIO-less build configuration

Use OCIO stub file with hardcoded displays, views and color spaces.

Intended to behave in the same way as old implementation, just it's
now more clear code with much fewer ifdef checks.

Also should make it possible to get rid of ibuf's profile flag.

Thanks Brecht van Lommel for this patch!

Modified Paths:
--------------
    branches/soc-2011-tomato/intern/CMakeLists.txt
    branches/soc-2011-tomato/intern/SConscript
    branches/soc-2011-tomato/intern/opencolorio/CMakeLists.txt
    branches/soc-2011-tomato/intern/opencolorio/SConscript
    branches/soc-2011-tomato/source/blender/imbuf/CMakeLists.txt
    branches/soc-2011-tomato/source/blender/imbuf/SConscript
    branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c

Added Paths:
-----------
    branches/soc-2011-tomato/intern/opencolorio/ocio_capi_stub.cpp

Modified: branches/soc-2011-tomato/intern/CMakeLists.txt
===================================================================
--- branches/soc-2011-tomato/intern/CMakeLists.txt	2012-09-14 14:36:53 UTC (rev 50593)
+++ branches/soc-2011-tomato/intern/CMakeLists.txt	2012-09-14 14:37:00 UTC (rev 50594)
@@ -28,6 +28,7 @@
 add_subdirectory(guardedalloc)
 add_subdirectory(moto)
 add_subdirectory(memutil)
+add_subdirectory(opencolorio)
 add_subdirectory(opennl)
 add_subdirectory(mikktspace)
 add_subdirectory(raskter)
@@ -74,6 +75,3 @@
 	add_subdirectory(utfconv)
 endif()
 
-if(WITH_OPENCOLORIO)
-	add_subdirectory(opencolorio)
-endif()

Modified: branches/soc-2011-tomato/intern/SConscript
===================================================================
--- branches/soc-2011-tomato/intern/SConscript	2012-09-14 14:36:53 UTC (rev 50593)
+++ branches/soc-2011-tomato/intern/SConscript	2012-09-14 14:37:00 UTC (rev 50594)
@@ -11,6 +11,7 @@
             'decimation/SConscript',
             'iksolver/SConscript',
             'itasc/SConscript',
+            'opencolorio/SConscript',
             'opennl/SConscript',
             'mikktspace/SConscript',
             'smoke/SConscript',
@@ -31,5 +32,3 @@
 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'win64-mingw', 'linuxcross', 'win64-vc'):
     SConscript(['utfconv/SConscript'])
 
-if env['WITH_BF_OCIO']:
-    SConscript(['opencolorio/SConscript'])

Modified: branches/soc-2011-tomato/intern/opencolorio/CMakeLists.txt
===================================================================
--- branches/soc-2011-tomato/intern/opencolorio/CMakeLists.txt	2012-09-14 14:36:53 UTC (rev 50593)
+++ branches/soc-2011-tomato/intern/opencolorio/CMakeLists.txt	2012-09-14 14:37:00 UTC (rev 50594)
@@ -23,27 +23,40 @@
 #
 # ***** END GPL LICENSE BLOCK *****
 
-set(INC
-	.
-	${OPENCOLORIO_INCLUDE_DIRS}
-)
+if(WITH_OPENCOLORIO)
+	set(INC
+		.
+		${OPENCOLORIO_INCLUDE_DIRS}
+	)
 
+	set(SRC
+		ocio_capi.cpp
+		ocio_capi.h
+	)
+
+	if(WIN32 AND NOT MINGW)
+		list(APPEND INC
+			${BOOST_INCLUDE_DIR}
+		)
+	endif()
+else()
+	set(INC
+		.
+		../../source/blender/blenlib
+	)
+
+	set(SRC
+		ocio_capi_stub.cpp
+		ocio_capi.h
+	)
+endif()
+
 set(INC_SYS
 	../guardedalloc
 )
 
-set(SRC
-	ocio_capi.cpp
-	ocio_capi.h
-)
-
 add_definitions(
 )
 
-if(WIN32 AND NOT MINGW)
-	list(APPEND INC
-		${BOOST_INCLUDE_DIR}
-	)
-endif()
+blender_add_lib(bf_intern_opencolorio "${SRC}" "${INC}" "${INC_SYS}")
 
-blender_add_lib(bf_intern_opencolorio "${SRC}" "${INC}" "${INC_SYS}")

Modified: branches/soc-2011-tomato/intern/opencolorio/SConscript
===================================================================
--- branches/soc-2011-tomato/intern/opencolorio/SConscript	2012-09-14 14:36:53 UTC (rev 50593)
+++ branches/soc-2011-tomato/intern/opencolorio/SConscript	2012-09-14 14:37:00 UTC (rev 50594)
@@ -4,10 +4,16 @@
 
 sources = env.Glob('*.cpp')
 
-incs = '. ../guardedalloc'
-incs += ' ' + env['BF_OCIO_INC']
+incs = '. ../guardedalloc ../../source/blender/blenlib'
 
-if env['OURPLATFORM'] in ('win32-vc', 'win64-vc'):
-    incs += ' ' + env['BF_BOOST_INC']
+if env['WITH_BF_OCIO']:
+    sources.remove('ocio_capi_stub.cpp')
 
+    incs += ' ' + env['BF_OCIO_INC']
+
+    if env['OURPLATFORM'] in ('win32-vc', 'win64-vc'):
+        incs += ' ' + env['BF_BOOST_INC']
+else:
+    sources.remove('ocio_capi.cpp')
+
 env.BlenderLib( 'bf_intern_opencolorio', sources, Split(incs), [], libtype=['extern','player'], priority=[10, 185])

Added: branches/soc-2011-tomato/intern/opencolorio/ocio_capi_stub.cpp
===================================================================
--- branches/soc-2011-tomato/intern/opencolorio/ocio_capi_stub.cpp	                        (rev 0)
+++ branches/soc-2011-tomato/intern/opencolorio/ocio_capi_stub.cpp	2012-09-14 14:37:00 UTC (rev 50594)
@@ -0,0 +1,380 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2012 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Brecht van Lommel
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <string.h>
+
+#include "MEM_guardedalloc.h"
+#include "BLI_math_color.h"
+
+namespace OCIO_NAMESPACE {};
+
+#include "ocio_capi.h"
+
+#define CONFIG_DEFAULT           ((ConstConfigRcPtr*)1)
+
+#define PROCESSOR_LINEAR_TO_SRGB ((ConstProcessorRcPtr*)1)
+#define PROCESSOR_SRGB_TO_LINEAR ((ConstProcessorRcPtr*)2)
+#define PROCESSOR_UNKNOWN        ((ConstProcessorRcPtr*)3)
+
+#define COLORSPACE_LINEAR        ((ConstColorSpaceRcPtr*)1)
+#define COLORSPACE_SRGB          ((ConstColorSpaceRcPtr*)2)
+
+typedef struct PackedImageDescription {
+	float *data;
+	long width;
+	long height;
+	long numChannels;
+	long chanStrideBytes;
+	long xStrideBytes;
+	long yStrideBytes;
+} PackedImageDescription;
+
+ConstConfigRcPtr *OCIO_getCurrentConfig(void)
+{
+	return CONFIG_DEFAULT;
+}
+
+void OCIO_setCurrentConfig(const ConstConfigRcPtr *)
+{
+}
+
+ConstConfigRcPtr *OCIO_configCreateFromEnv(void)
+{
+	return CONFIG_DEFAULT;
+}
+
+ConstConfigRcPtr *OCIO_configCreateFromFile(const char *)
+{
+	return CONFIG_DEFAULT;
+}
+
+void OCIO_configRelease(ConstConfigRcPtr *)
+{
+}
+
+int OCIO_configGetNumColorSpaces(ConstConfigRcPtr *)
+{
+	return 2;
+}
+
+const char *OCIO_configGetColorSpaceNameByIndex(ConstConfigRcPtr *, int index)
+{
+	if (index == 0)
+		return "Linear";
+	else if (index == 1)
+		return "sRGB";
+	
+	return NULL;
+}
+
+ConstColorSpaceRcPtr *OCIO_configGetColorSpace(ConstConfigRcPtr *, const char *name)
+{
+	if (strcmp(name, "scene_linear") == 0)
+		return COLORSPACE_LINEAR;
+	else if (strcmp(name, "color_picking") == 0)
+		return COLORSPACE_SRGB;
+	else if (strcmp(name, "texture_paint") == 0)
+		return COLORSPACE_LINEAR;
+	else if (strcmp(name, "default_byte") == 0)
+		return COLORSPACE_SRGB;
+	else if (strcmp(name, "default_float") == 0)
+		return COLORSPACE_LINEAR;
+	else if (strcmp(name, "default_sequencer") == 0)
+		return COLORSPACE_SRGB;
+	else if (strcmp(name, "Linear") == 0)
+		return COLORSPACE_LINEAR;
+	else if (strcmp(name, "sRGB") == 0)
+		return COLORSPACE_SRGB;
+
+	return NULL;
+}
+
+int OCIO_configGetIndexForColorSpace(ConstConfigRcPtr *config, const char *name)
+{
+	ConstColorSpaceRcPtr *cs = OCIO_configGetColorSpace(config, name);
+
+	if (cs == COLORSPACE_LINEAR)
+		return 0;
+	else if (cs == COLORSPACE_SRGB)
+		return 1;
+
+	return -1;
+}
+
+const char *OCIO_configGetDefaultDisplay(ConstConfigRcPtr *)
+{
+	return "sRGB";
+}
+
+int OCIO_configGetNumDisplays(ConstConfigRcPtr* config)
+{
+	return 1;
+}
+
+const char *OCIO_configGetDisplay(ConstConfigRcPtr *, int index)
+{
+	if (index == 0)
+		return "sRGB";
+	
+	return NULL;
+}
+
+const char *OCIO_configGetDefaultView(ConstConfigRcPtr *, const char *)
+{
+	return "Default";
+}
+
+int OCIO_configGetNumViews(ConstConfigRcPtr *, const char *)
+{
+	return 1;
+}
+
+const char *OCIO_configGetView(ConstConfigRcPtr *, const char *, int index)
+{
+	if (index == 0)
+		return "Default";
+
+	return NULL;
+}
+
+const char *OCIO_configGetDisplayColorSpaceName(ConstConfigRcPtr *, const char *, const char *)
+{
+	return "sRGB";
+}
+
+int OCIO_colorSpaceIsInvertible(ConstColorSpaceRcPtr *cs)
+{
+	return 1;
+}
+
+void OCIO_colorSpaceRelease(ConstColorSpaceRcPtr *cs)
+{
+}
+
+ConstProcessorRcPtr *OCIO_configGetProcessorWithNames(ConstConfigRcPtr *config, const char *srcName, const char *dstName)
+{
+	ConstColorSpaceRcPtr *cs_src = OCIO_configGetColorSpace(config, srcName);
+	ConstColorSpaceRcPtr *cs_dst = OCIO_configGetColorSpace(config, dstName);
+
+	if (cs_src == COLORSPACE_LINEAR && cs_dst == COLORSPACE_SRGB)
+		return PROCESSOR_LINEAR_TO_SRGB;
+	else if (cs_src == COLORSPACE_SRGB && cs_dst == COLORSPACE_LINEAR)
+		return PROCESSOR_SRGB_TO_LINEAR;
+
+	return 0;
+}
+
+ConstProcessorRcPtr *OCIO_configGetProcessor(ConstConfigRcPtr *, ConstTransformRcPtr *tfm)
+{
+	return (ConstProcessorRcPtr*)tfm;
+}
+
+void OCIO_processorApply(ConstProcessorRcPtr *processor, PackedImageDesc *img)
+{
+	/* OCIO_TODO stride not respected, channels must be 3 or 4 */
+	PackedImageDescription *desc = (PackedImageDescription*)img;
+	int channels = desc->numChannels;
+	float *pixels = desc->data;
+	int width = desc->width;
+	int height = desc->height;
+	int x, y;
+
+	for (y = 0; y < height; y++) {
+		for (x = 0; x < width; x++) {
+			float *pixel = pixels + channels * (y * width + x);
+
+			if (channels == 4)
+				OCIO_processorApplyRGBA(processor, pixel);
+			else if (channels == 3)
+				OCIO_processorApplyRGB(processor, pixel);
+		}
+	}
+}
+
+void OCIO_processorApply_predivide(ConstProcessorRcPtr *processor, PackedImageDesc *img)
+{
+	/* OCIO_TODO stride not respected, channels must be 3 or 4 */
+	PackedImageDescription *desc = (PackedImageDescription*)img;
+	int channels = desc->numChannels;
+	float *pixels = desc->data;
+	int width = desc->width;
+	int height = desc->height;
+	int x, y;
+
+	for (y = 0; y < height; y++) {
+		for (x = 0; x < width; x++) {
+			float *pixel = pixels + channels * (y * width + x);
+
+			if (channels == 4)
+				OCIO_processorApplyRGBA_predivide(processor, pixel);
+			else if (channels == 3)
+				OCIO_processorApplyRGB(processor, pixel);
+		}
+	}
+}
+
+void OCIO_processorApplyRGB(ConstProcessorRcPtr *processor, float *pixel)
+{
+	if (processor == PROCESSOR_LINEAR_TO_SRGB)
+		linearrgb_to_srgb_v3_v3(pixel, pixel);
+	else if (processor == PROCESSOR_SRGB_TO_LINEAR)
+		srgb_to_linearrgb_v3_v3(pixel, pixel);
+}
+
+void OCIO_processorApplyRGBA(ConstProcessorRcPtr *processor, float *pixel)
+{
+	if (processor == PROCESSOR_LINEAR_TO_SRGB)
+		linearrgb_to_srgb_v4(pixel, pixel);
+	else if (processor == PROCESSOR_SRGB_TO_LINEAR)
+		srgb_to_linearrgb_v4(pixel, pixel);
+}
+
+void OCIO_processorApplyRGBA_predivide(ConstProcessorRcPtr *processor, float *pixel)
+{
+	if (pixel[3] == 1.0f || pixel[3] == 0.0f) {
+		OCIO_processorApplyRGBA(processor, pixel);
+	}
+	else {

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list