Merging r58266 through r58279 from trunk into soc-2013-depsgraph_mt
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 15 Jul 2013 18:48:34 +0000 (18:48 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 15 Jul 2013 18:48:34 +0000 (18:48 +0000)
24 files changed:
source/blender/blenkernel/BKE_dynamicpaint.h
source/blender/blenkernel/intern/brush.c
source/blender/blenkernel/intern/dynamicpaint.c
source/blender/blenkernel/intern/effect.c
source/blender/blenkernel/intern/image.c
source/blender/blenkernel/intern/pointcache.c
source/blender/blenkernel/intern/scene.c
source/blender/blenkernel/intern/sequencer.c
source/blender/blenkernel/intern/smoke.c
source/blender/compositor/nodes/COM_TextureNode.cpp
source/blender/compositor/operations/COM_TextureOperation.cpp
source/blender/compositor/operations/COM_TextureOperation.h
source/blender/editors/physics/dynamicpaint_ops.c
source/blender/imbuf/intern/cineon/logImageCore.c
source/blender/makesrna/intern/rna_dynamicpaint.c
source/blender/makesrna/intern/rna_texture_api.c
source/blender/modifiers/intern/MOD_displace.c
source/blender/modifiers/intern/MOD_util.c
source/blender/modifiers/intern/MOD_util.h
source/blender/modifiers/intern/MOD_warp.c
source/blender/modifiers/intern/MOD_wave.c
source/blender/modifiers/intern/MOD_weightvg_util.c
source/blender/render/extern/include/RE_shader_ext.h
source/blender/render/intern/source/render_texture.c

index ffce16f39fff3b83b489f3e448c8a948a12550dd..62715c205002caf137cc9285ee5bf0f5b271df4a 100644 (file)
@@ -29,6 +29,7 @@
 
 struct bContext;
 struct wmOperator;
+struct Scene;
 
 /* Actual surface point        */
 typedef struct PaintSurfaceData {
@@ -69,8 +70,8 @@ void dynamicPaint_Modifier_copy(struct DynamicPaintModifierData *pmd, struct Dyn
 
 int dynamicPaint_createType(struct DynamicPaintModifierData *pmd, int type, struct Scene *scene);
 struct DynamicPaintSurface *dynamicPaint_createNewSurface(struct DynamicPaintCanvasSettings *canvas, struct Scene *scene);
-void dynamicPaint_clearSurface(struct DynamicPaintSurface *surface);
-int  dynamicPaint_resetSurface(struct DynamicPaintSurface *surface);
+void dynamicPaint_clearSurface(struct Scene *scene, struct DynamicPaintSurface *surface);
+int  dynamicPaint_resetSurface(struct Scene *scene, struct DynamicPaintSurface *surface);
 void dynamicPaint_freeSurface(struct DynamicPaintSurface *surface);
 void dynamicPaint_freeCanvas(struct DynamicPaintModifierData *pmd);
 void dynamicPaint_freeBrush(struct DynamicPaintModifierData *pmd);
@@ -85,7 +86,7 @@ void dynamicPaint_resetPreview(struct DynamicPaintCanvasSettings *canvas);
 struct DynamicPaintSurface *get_activeSurface(struct DynamicPaintCanvasSettings *canvas);
 
 /* image sequence baking */
-int dynamicPaint_createUVSurface(struct DynamicPaintSurface *surface);
+int dynamicPaint_createUVSurface(struct Scene *scene, struct DynamicPaintSurface *surface);
 int dynamicPaint_calculateFrame(struct DynamicPaintSurface *surface, struct Scene *scene, struct Object *cObject, int frame);
 void dynamicPaint_outputSurfaceImage(struct DynamicPaintSurface *surface, char *filename, short output_layer);
 
index 8130f6e646cc693481e38174105c27fa79c811f0..70b5d90120de9ea86905f2283f92fec1b2ade36a 100644 (file)
@@ -993,7 +993,8 @@ unsigned int *BKE_brush_gen_texture_cache(Brush *br, int half_side)
                                co[2] = 0.0f;
 
                                /* This is copied from displace modifier code */
-                               hasrgb = multitex_ext(mtex->tex, co, NULL, NULL, 0, &texres, NULL);
+                               /* TODO(sergey): brush are always cacheing with CM enabled for now. */
+                               hasrgb = multitex_ext(mtex->tex, co, NULL, NULL, 0, &texres, NULL, true);
 
                                /* if the texture gave an RGB value, we assume it didn't give a valid
                                 * intensity, so calculate one (formula from do_material_tex).
index a6811af1a9459f1a224c9b92eb3ab954125cfa65..1d5eaf3a1fccbe8bed28ba5bf20e6d8a407b055e 100644 (file)
@@ -1449,12 +1449,13 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, int for
        MEM_freeN(temp_data);
 }
 
-static void dynamicPaint_setInitialColor(DynamicPaintSurface *surface)
+static void dynamicPaint_setInitialColor(Scene *scene, DynamicPaintSurface *surface)
 {
        PaintSurfaceData *sData = surface->data;
        PaintPoint *pPoint = (PaintPoint *)sData->type_data;
        DerivedMesh *dm = surface->canvas->dm;
        int i;
+       bool scene_color_manage = BKE_scene_check_color_management_enabled(scene);
 
        if (surface->type != MOD_DPAINT_SURFACE_T_PAINT)
                return;
@@ -1503,7 +1504,7 @@ static void dynamicPaint_setInitialColor(DynamicPaintSurface *surface)
                                        uv[0] = tface[i].uv[j][0] * 2.0f - 1.0f;
                                        uv[1] = tface[i].uv[j][1] * 2.0f - 1.0f;
 
-                                       multitex_ext_safe(tex, uv, &texres, pool);
+                                       multitex_ext_safe(tex, uv, &texres, pool, scene_color_manage);
 
                                        if (texres.tin > pPoint[*vert].alpha) {
                                                copy_v3_v3(pPoint[*vert].color, &texres.tr);
@@ -1536,8 +1537,8 @@ static void dynamicPaint_setInitialColor(DynamicPaintSurface *surface)
                                /* remap to -1.0 to 1.0 */
                                uv_final[0] = uv_final[0] * 2.0f - 1.0f;
                                uv_final[1] = uv_final[1] * 2.0f - 1.0f;
-                                       
-                               multitex_ext_safe(tex, uv_final, &texres, NULL);
+
+                               multitex_ext_safe(tex, uv_final, &texres, NULL, scene_color_manage);
 
                                /* apply color */
                                copy_v3_v3(pPoint[i].color, &texres.tr);
@@ -1596,7 +1597,7 @@ static void dynamicPaint_setInitialColor(DynamicPaintSurface *surface)
 }
 
 /* clears surface data back to zero */
-void dynamicPaint_clearSurface(DynamicPaintSurface *surface)
+void dynamicPaint_clearSurface(Scene *scene, DynamicPaintSurface *surface)
 {
        PaintSurfaceData *sData = surface->data;
        if (sData && sData->type_data) {
@@ -1613,7 +1614,7 @@ void dynamicPaint_clearSurface(DynamicPaintSurface *surface)
 
                /* set initial color */
                if (surface->type == MOD_DPAINT_SURFACE_T_PAINT)
-                       dynamicPaint_setInitialColor(surface);
+                       dynamicPaint_setInitialColor(scene, surface);
 
                if (sData->bData)
                        sData->bData->clear = 1;
@@ -1621,7 +1622,7 @@ void dynamicPaint_clearSurface(DynamicPaintSurface *surface)
 }
 
 /* completely (re)initializes surface (only for point cache types)*/
-int dynamicPaint_resetSurface(DynamicPaintSurface *surface)
+int dynamicPaint_resetSurface(Scene *scene, DynamicPaintSurface *surface)
 {
        int numOfPoints = dynamicPaint_surfaceNumOfPoints(surface);
        /* free existing data */
@@ -1642,16 +1643,16 @@ int dynamicPaint_resetSurface(DynamicPaintSurface *surface)
 
        /* set initial color */
        if (surface->type == MOD_DPAINT_SURFACE_T_PAINT)
-               dynamicPaint_setInitialColor(surface);
+               dynamicPaint_setInitialColor(scene, surface);
 
        return 1;
 }
 
 /* make sure allocated surface size matches current requirements */
-static int dynamicPaint_checkSurfaceData(DynamicPaintSurface *surface)
+static int dynamicPaint_checkSurfaceData(Scene *scene, DynamicPaintSurface *surface)
 {
        if (!surface->data || ((dynamicPaint_surfaceNumOfPoints(surface) != surface->data->total_points))) {
-               return dynamicPaint_resetSurface(surface);
+               return dynamicPaint_resetSurface(scene, surface);
        }
        return 1;
 }
@@ -1953,7 +1954,7 @@ static void dynamicPaint_frameUpdate(DynamicPaintModifierData *pmd, Scene *scene
 
                        /* make sure surface is valid */
                        no_surface_data = surface->data == NULL;
-                       if (!dynamicPaint_checkSurfaceData(surface)) continue;
+                       if (!dynamicPaint_checkSurfaceData(scene, surface)) continue;
 
                        /* limit frame range */
                        CLAMP(current_frame, surface->start_frame, surface->end_frame);
@@ -2225,7 +2226,7 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh
 /*
  *     Create a surface for uv image sequence format
  */
-int dynamicPaint_createUVSurface(DynamicPaintSurface *surface)
+int dynamicPaint_createUVSurface(Scene *scene, DynamicPaintSurface *surface)
 {
        /* Antialias jitter point relative coords       */
        float jitter5sample[10] =  {0.0f, 0.0f,
@@ -2676,7 +2677,7 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface)
                }
 
 #endif
-               dynamicPaint_setInitialColor(surface);
+               dynamicPaint_setInitialColor(scene, surface);
        }
 
        return (error == 0);
index 8d58caf8769134005970a343853e59767d47c1c0..81b0de9fd32c59bd0ed63b6ef058161388c91a93 100644 (file)
@@ -745,6 +745,7 @@ static void do_texture_effector(EffectorCache *eff, EffectorData *efd, EffectedP
        float nabla = eff->pd->tex_nabla;
        int hasrgb;
        short mode = eff->pd->tex_mode;
+       bool scene_color_manage;
 
        if (!eff->pd->tex)
                return;
@@ -764,7 +765,9 @@ static void do_texture_effector(EffectorCache *eff, EffectorData *efd, EffectedP
                mul_m4_v3(eff->ob->imat, tex_co);
        }
 
-       hasrgb = multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result, NULL);
+       scene_color_manage = BKE_scene_check_color_management_enabled(eff->scene);
+
+       hasrgb = multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result, NULL, scene_color_manage);
 
        if (hasrgb && mode==PFIELD_TEX_RGB) {
                force[0] = (0.5f - result->tr) * strength;
@@ -775,15 +778,15 @@ static void do_texture_effector(EffectorCache *eff, EffectorData *efd, EffectedP
                strength/=nabla;
 
                tex_co[0] += nabla;
-               multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result+1, NULL);
+               multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result+1, NULL, scene_color_manage);
 
                tex_co[0] -= nabla;
                tex_co[1] += nabla;
-               multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result+2, NULL);
+               multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result+2, NULL, scene_color_manage);
 
                tex_co[1] -= nabla;
                tex_co[2] += nabla;
-               multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result+3, NULL);
+               multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result+3, NULL, scene_color_manage);
 
                if (mode == PFIELD_TEX_GRAD || !hasrgb) { /* if we don't have rgb fall back to grad */
                        /* generate intensity if texture only has rgb value */
index f34053816c5b7ed854703dc29dac858de9ed2ed5..135d847cce7c8a48f9e8840da11b349a5ff776cc 100644 (file)
@@ -633,7 +633,7 @@ Image *BKE_image_load_exists(const char *filepath)
        for (ima = G.main->image.first; ima; ima = ima->id.next) {
                if (ima->source != IMA_SRC_VIEWER && ima->source != IMA_SRC_GENERATED) {
                        BLI_strncpy(strtest, ima->name, sizeof(ima->name));
-                       BLI_path_abs(strtest, G.main->name);
+                       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) {
index 6f77d63d90f3887f370f3469b137d85c57603a2a..06748dfc44d63e08e87c5e8f6fd827d0dfadfbb2 100644 (file)
@@ -2800,7 +2800,7 @@ int  BKE_ptcache_id_reset(Scene *scene, PTCacheID *pid, int mode)
                        smokeModifier_reset_turbulence(pid->calldata);
 #endif
                else if (pid->type == PTCACHE_TYPE_DYNAMICPAINT)
-                       dynamicPaint_clearSurface((DynamicPaintSurface*)pid->calldata);
+                       dynamicPaint_clearSurface(scene, (DynamicPaintSurface*)pid->calldata);
        }
        if (clear)
                BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_ALL, 0);
index c08d3d5bf2023532510fed5285c4f7fbc4b50cf1..8df2160f021dccf2bdc563e32adcebdfdf39719b 100644 (file)
@@ -1683,6 +1683,16 @@ void BKE_scene_disable_color_management(Scene *scene)
 
 int BKE_scene_check_color_management_enabled(const Scene *scene)
 {
+       /* TODO(sergey): shouldn't be needed. but we're currently far to close to the release,
+        *               so better be extra-safe than sorry.
+        *
+        *               Will remove the check after the release.
+        */
+       if (!scene) {
+               BLI_assert(!"Shouldn't happen!");
+               return TRUE;
+       }
+
        return strcmp(scene->display_settings.display_device, "None") != 0;
 }
 
index 027b1d7fa03ad1417f969f19244f2fe0c599be0b..e81afc7efb61d979f650d673a571eef455813310 100644 (file)
@@ -50,6 +50,7 @@
 #include "BLI_listbase.h"
 #include "BLI_path_util.h"
 #include "BLI_string.h"
+#include "BLI_string_utf8.h"
 #include "BLI_threads.h"
 #include "BLI_utildefines.h"
 
@@ -3948,7 +3949,8 @@ Mask *BKE_sequencer_mask_get(Scene *scene)
 static void seq_load_apply(Scene *scene, Sequence *seq, SeqLoadInfo *seq_load)
 {
        if (seq) {
-               BLI_strncpy(seq->name + 2, seq_load->name, sizeof(seq->name) - 2);
+               BLI_strncpy_utf8(seq->name + 2, seq_load->name, sizeof(seq->name) - 2);
+               BLI_utf8_invalid_strip(seq->name + 2, sizeof(seq->name) - 2);
                BKE_sequence_base_unique_name_recursive(&scene->ed->seqbase, seq);
 
                if (seq_load->flag & SEQ_LOAD_FRAME_ADVANCE) {
index 05c3550d81016b34aab21103449ab582766e4e40..9fa4cc2ae40d4f1aab7bcc3681425eb68a8a3b8d 100644 (file)
@@ -1413,12 +1413,14 @@ static void emit_from_particles(Object *flow_ob, SmokeDomainSettings *sds, Smoke
        }
 }
 
+/* TODO(sergey): de-duplicate with get_texture_value from modifier utils */
+/* NOTE: Skips color management, because result is only used for value now, not for color. */
 static void get_texture_value(Tex *texture, float tex_co[3], TexResult *texres)
 {
        int result_type;
 
        /* no node textures for now */
-       result_type = multitex_ext_safe(texture, tex_co, texres, NULL);
+       result_type = multitex_ext_safe(texture, tex_co, texres, NULL, false);
 
        /* if the texture gave an RGB value, we assume it didn't give a valid
         * intensity, since this is in the context of modifiers don't use perceptual color conversion.
index 5b386a504e473d62845116011ff74a680296f5a5..6f2baa63b0e5ec2087d1f0b288dafa351ae293f4 100644 (file)
@@ -34,11 +34,14 @@ void TextureNode::convertToOperations(ExecutionSystem *system, CompositorContext
        bNode *editorNode = this->getbNode();
        Tex *texture = (Tex *)editorNode->id;
        TextureOperation *operation = new TextureOperation();
+       const ColorManagedDisplaySettings *displaySettings = context->getDisplaySettings();
+       bool sceneColorManage = strcmp(displaySettings->display_device, "None") != 0;
        this->getOutputSocket(1)->relinkConnections(operation->getOutputSocket());
        this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, system);
        this->getInputSocket(1)->relinkConnections(operation->getInputSocket(1), 1, system);
        operation->setTexture(texture);
        operation->setRenderData(context->getRenderData());
+       operation->setSceneColorManage(sceneColorManage);
        system->addOperation(operation);
        addPreviewOperation(system, context, operation->getOutputSocket());
 
@@ -49,6 +52,7 @@ void TextureNode::convertToOperations(ExecutionSystem *system, CompositorContext
                addLink(system, operation->getInputSocket(1)->getConnection()->getFromSocket(), alphaOperation->getInputSocket(1));
                alphaOperation->setTexture(texture);
                alphaOperation->setRenderData(context->getRenderData());
+               alphaOperation->setSceneColorManage(sceneColorManage);
                system->addOperation(alphaOperation);
        }
 }
index 08f6f8ada4af2661f33d09750ccaab486747f4c2..bbb7c8b52891489a3225d8ec0e65f42e97ceb876 100644 (file)
@@ -33,6 +33,8 @@ TextureBaseOperation::TextureBaseOperation() : SingleThreadedNodeOperation()
        this->m_inputSize = NULL;
        this->m_inputOffset = NULL;
        this->m_rd = NULL;
+       this->m_pool = NULL;
+       this->m_sceneColorManage = false;
 }
 TextureOperation::TextureOperation() : TextureBaseOperation()
 {
@@ -101,7 +103,7 @@ void TextureBaseOperation::executePixel(float output[4], float x, float y, Pixel
        vec[1] = textureSize[1] * (v + textureOffset[1]);
        vec[2] = textureSize[2] * textureOffset[2];
 
-       retval = multitex_ext(this->m_texture, vec, NULL, NULL, 0, &texres, m_pool);
+       retval = multitex_ext(this->m_texture, vec, NULL, NULL, 0, &texres, m_pool, m_sceneColorManage);
 
        if (texres.talpha)
                output[3] = texres.ta;
index fc9369099a6426280a2ec1771a6359b4cf8c5de3..b776f6f2493ee1d8d6824c98c227bcd9252d09ae 100644 (file)
@@ -46,6 +46,7 @@ private:
        SocketReader *m_inputSize;
        SocketReader *m_inputOffset;
        struct ImagePool *m_pool;
+       bool m_sceneColorManage;
 
 protected:
 
@@ -67,6 +68,7 @@ public:
        void initExecution();
        void deinitExecution();
        void setRenderData(const RenderData *rd) { this->m_rd = rd; }
+       void setSceneColorManage(bool sceneColorManage) { this->m_sceneColorManage = sceneColorManage; }
 };
 
 class TextureOperation : public TextureBaseOperation {
index 9634acd701a32e7573c3d74fba084bf1f12dffd8..5cb74e1ca09b73a1c204ed71f94d1da950da7ad4 100644 (file)
@@ -294,7 +294,7 @@ static int dynamicPaint_bakeImageSequence(bContext *C, DynamicPaintSurface *surf
        ED_update_for_newframe(CTX_data_main(C), scene, 1);
 
        /* Init surface */
-       if (!dynamicPaint_createUVSurface(surface)) return 0;
+       if (!dynamicPaint_createUVSurface(scene, surface)) return 0;
 
        /* Loop through selected frames */
        for (frame = surface->start_frame; frame <= surface->end_frame; frame++) {
index c10f201fb553cfee2711530d71f4669cf96f2df3..d8d01d0cc5a55f731cad8c0ca9d516acf3541560 100644 (file)
@@ -918,25 +918,35 @@ static int getYUVtoRGBMatrix(float *matrix, LogImageElement logElement)
        }
 }
 
-static void getLinToLogLut(float *lut, LogImageFile *logImage, LogImageElement logElement)
+static float *getLinToLogLut(LogImageFile *logImage, LogImageElement logElement)
 {
+       float *lut;
        float gain, negativeFilmGamma, offset, step;
+       unsigned int lutsize = (unsigned int)(logElement.maxValue + 1);
        unsigned int i;
+       
+       lut = MEM_mallocN(sizeof(float)*lutsize, "getLinToLogLut");
 
        negativeFilmGamma = 0.6;
        step = logElement.refHighQuantity / logElement.maxValue;
        gain = logElement.maxValue / (1.0f - powf(10, (logImage->referenceBlack - logImage->referenceWhite) * step / negativeFilmGamma * logImage->gamma / 1.7f));
        offset = gain - logElement.maxValue;
 
-       for (i = 0; i < (int)(logElement.maxValue + 1); i++)
+       for (i = 0; i < lutsize; i++)
                lut[i] = (logImage->referenceWhite + log10f(powf((i + offset) / gain, 1.7f / logImage->gamma)) / (step / negativeFilmGamma)) / logElement.maxValue;
+       
+       return lut;
 }
 
-static void getLogToLinLut(float *lut, LogImageFile *logImage, LogImageElement logElement)
+static float *getLogToLinLut(LogImageFile *logImage, LogImageElement logElement)
 {
+       float *lut;
        float breakPoint, gain, kneeGain, kneeOffset, negativeFilmGamma, offset, step, softClip;
        /* float filmGamma; unused */
+       unsigned int lutsize = (unsigned int)(logElement.maxValue + 1);
        unsigned int i;
+       
+       lut = MEM_mallocN(sizeof(float)*lutsize, "getLogToLinLut");
 
        /* Building the Log -> Lin LUT */
        step = logElement.refHighQuantity / logElement.maxValue;
@@ -952,7 +962,7 @@ static void getLogToLinLut(float *lut, LogImageFile *logImage, LogImageElement l
        kneeOffset = powf(10, (breakPoint - logImage->referenceWhite) * step / negativeFilmGamma * logImage->gamma / 1.7f) * gain - offset;
        kneeGain = (logElement.maxValue - kneeOffset) / powf(5 * softClip, softClip / 100);
 
-       for (i = 0; i < (int)(logElement.maxValue + 1); i++) {
+       for (i = 0; i < lutsize; i++) {
                if (i < logImage->referenceBlack)
                        lut[i] = 0.0f;
                else if (i > breakPoint)
@@ -960,61 +970,76 @@ static void getLogToLinLut(float *lut, LogImageFile *logImage, LogImageElement l
                else
                        lut[i] = (powf(10, ((float)i - logImage->referenceWhite) * step / negativeFilmGamma * logImage->gamma / 1.7f) * gain - offset) / logElement.maxValue;
        }
+
+       return lut;
 }
 
-static void getLinToSrgbLut(float *lut, LogImageElement logElement)
+static float *getLinToSrgbLut(LogImageElement logElement)
 {
+       float col, *lut;
+       unsigned int lutsize = (unsigned int)(logElement.maxValue + 1);
        unsigned int i;
-       float col;
 
-       for (i = 0; i < (int)(logElement.maxValue + 1); i++) {
+       lut = MEM_mallocN(sizeof(float)*lutsize, "getLogToLinLut");
+
+       for (i = 0; i < lutsize; i++) {
                col = (float)i / logElement.maxValue;
                if (col < 0.0031308f)
                        lut[i] = (col < 0.0f) ? 0.0f : col * 12.92f;
                else
                        lut[i] = 1.055f * powf(col, 1.0f / 2.4f) - 0.055f;
        }
+
+       return lut;
 }
 
-static void getSrgbToLinLut(float *lut, LogImageElement logElement)
+static float *getSrgbToLinLut(LogImageElement logElement)
 {
+       float col, *lut;
+       unsigned int lutsize = (unsigned int)(logElement.maxValue + 1);
        unsigned int i;
-       float col;
 
-       for (i = 0; i < (int)(logElement.maxValue + 1); i++) {
+       lut = MEM_mallocN(sizeof(float)*lutsize, "getLogToLinLut");
+
+       for (i = 0; i < lutsize; i++) {
                col = (float)i / logElement.maxValue;
                if (col < 0.04045f)
                        lut[i] = (col < 0.0f) ? 0.0f : col * (1.0f / 12.92f);
                else
                        lut[i] = powf((col + 0.055f) * (1.0f / 1.055f), 2.4f);
        }
+
+       return lut;
 }
 
 static int convertRGBA_RGB(float *src, float *dst, LogImageFile *logImage,
                            LogImageElement logElement, int elementIsSource)
 {
        unsigned int i;
-       float lut[65536];
        float *src_ptr = src;
        float *dst_ptr = dst;
 
        switch (logElement.transfer) {
                case transfer_UserDefined:
                case transfer_Linear:
-               case transfer_Logarithmic:
+               case transfer_Logarithmic: {
                        for (i = 0; i < logImage->width * logImage->height; i++) {
                                *(dst_ptr++) = *(src_ptr++);
                                *(dst_ptr++) = *(src_ptr++);
                                *(dst_ptr++) = *(src_ptr++);
                                src_ptr++;
                        }
+
                        return 0;
+               }
+
+               case transfer_PrintingDensity: {
+                       float *lut;
 
-               case transfer_PrintingDensity:
                        if (elementIsSource == 1)
-                               getLogToLinLut((float *)&lut, logImage, logElement);
+                               lut = getLogToLinLut(logImage, logElement);
                        else
-                               getLinToLogLut((float *)&lut, logImage, logElement);
+                               lut = getLinToLogLut(logImage, logElement);
 
                        for (i = 0; i < logImage->width * logImage->height; i++) {
                                *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
@@ -1022,7 +1047,11 @@ static int convertRGBA_RGB(float *src, float *dst, LogImageFile *logImage,
                                *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
                                src_ptr++;
                        }
+
+                       MEM_freeN(lut);
+
                        return 0;
+               }
 
                default:
                        return 1;
@@ -1033,27 +1062,30 @@ static int convertRGB_RGBA(float *src, float *dst, LogImageFile *logImage,
                            LogImageElement logElement, int elementIsSource)
 {
        unsigned int i;
-       float lut[65536];
        float *src_ptr = src;
        float *dst_ptr = dst;
 
        switch (logElement.transfer) {
                case transfer_UserDefined:
                case transfer_Linear:
-               case transfer_Logarithmic:
+               case transfer_Logarithmic: {
                        for (i = 0; i < logImage->width * logImage->height; i++) {
                                *(dst_ptr++) = *(src_ptr++);
                                *(dst_ptr++) = *(src_ptr++);
                                *(dst_ptr++) = *(src_ptr++);
                                *(dst_ptr++) = 1.0f;
                        }
+
                        return 0;
+               }
+
+               case transfer_PrintingDensity: {
+                       float *lut;
 
-               case transfer_PrintingDensity:
                        if (elementIsSource == 1)
-                               getLogToLinLut((float *)&lut, logImage, logElement);
+                               lut = getLogToLinLut(logImage, logElement);
                        else
-                               getLinToLogLut((float *)&lut, logImage, logElement);
+                               lut = getLinToLogLut(logImage, logElement);
 
                        for (i = 0; i < logImage->width * logImage->height; i++) {
                                *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
@@ -1061,7 +1093,11 @@ static int convertRGB_RGBA(float *src, float *dst, LogImageFile *logImage,
                                *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
                                *(dst_ptr++) = 1.0f;
                        }
+
+                       MEM_freeN(lut);
+
                        return 0;
+               }
 
                default:
                        return 1;
@@ -1072,22 +1108,24 @@ static int convertRGBA_RGBA(float *src, float *dst, LogImageFile *logImage,
                             LogImageElement logElement, int elementIsSource)
 {
        unsigned int i;
-       float lut[65536];
        float *src_ptr = src;
        float *dst_ptr = dst;
 
        switch (logElement.transfer) {
                case transfer_UserDefined:
                case transfer_Linear:
-               case transfer_Logarithmic:
+               case transfer_Logarithmic: {
                        memcpy(dst, src, 4 * logImage->width * logImage->height * sizeof(float));
                        return 0;
+               }
+
+               case transfer_PrintingDensity: {
+                       float *lut;
 
-               case transfer_PrintingDensity:
                        if (elementIsSource == 1)
-                               getLogToLinLut((float *)&lut, logImage, logElement);
+                               lut = getLogToLinLut(logImage, logElement);
                        else
-                               getLinToLogLut((float *)&lut, logImage, logElement);
+                               lut = getLinToLogLut(logImage, logElement);
 
                        for (i = 0; i < logImage->width * logImage->height; i++) {
                                *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
@@ -1095,7 +1133,11 @@ static int convertRGBA_RGBA(float *src, float *dst, LogImageFile *logImage,
                                *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
                                *(dst_ptr++) = *(src_ptr++);
                        }
+
+                       MEM_freeN(lut);
+
                        return 0;
+               }
 
                default:
                        return 1;
@@ -1106,14 +1148,13 @@ static int convertABGR_RGBA(float *src, float *dst, LogImageFile *logImage,
                             LogImageElement logElement, int elementIsSource)
 {
        unsigned int i;
-       float lut[65536];
        float *src_ptr = src;
        float *dst_ptr = dst;
 
        switch (logElement.transfer) {
                case transfer_UserDefined:
                case transfer_Linear:
-               case transfer_Logarithmic:
+               case transfer_Logarithmic: {
                        for (i = 0; i < logImage->width * logImage->height; i++) {
                                src_ptr += 4;
                                *(dst_ptr++) = *(src_ptr--);
@@ -1123,12 +1164,15 @@ static int convertABGR_RGBA(float *src, float *dst, LogImageFile *logImage,
                                src_ptr += 4;
                        }
                        return 0;
+               }
+
+               case transfer_PrintingDensity: {
+                       float *lut;
 
-               case transfer_PrintingDensity:
                        if (elementIsSource == 1)
-                               getLogToLinLut((float *)&lut, logImage, logElement);
+                               lut = getLogToLinLut(logImage, logElement);
                        else
-                               getLinToLogLut((float *)&lut, logImage, logElement);
+                               lut = getLinToLogLut(logImage, logElement);
 
                        for (i = 0; i < logImage->width * logImage->height; i++) {
                                src_ptr += 4;
@@ -1138,7 +1182,11 @@ static int convertABGR_RGBA(float *src, float *dst, LogImageFile *logImage,
                                *(dst_ptr++) = *(src_ptr--);
                                src_ptr += 4;
                        }
+
+                       MEM_freeN(lut);
+
                        return 0;
+               }
 
                default:
                        return 1;
@@ -1309,7 +1357,6 @@ static int convertLogElementToRGBA(float *src, float *dst, LogImageFile *logImag
        unsigned int i;
        float *src_ptr;
        float *dst_ptr;
-       float lut[65536];
 
        /* Convert data in src to linear RGBA in dst */
        switch (logElement.descriptor) {
@@ -1357,7 +1404,7 @@ static int convertLogElementToRGBA(float *src, float *dst, LogImageFile *logImag
                return 1;
        else if (dstIsLinearRGB) {
                /* convert data from sRGB to Linear RGB via lut */
-               getSrgbToLinLut((float *)&lut, logElement);
+               float *lut = getSrgbToLinLut(logElement);
                src_ptr = dst; // no error here
                dst_ptr = dst;
                for (i = 0; i < logImage->width * logImage->height; i++) {
@@ -1366,6 +1413,7 @@ static int convertLogElementToRGBA(float *src, float *dst, LogImageFile *logImag
                        *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
                        dst_ptr++; src_ptr++;
                }
+               MEM_freeN(lut);
        }
        return 0;
 }
@@ -1378,7 +1426,7 @@ static int convertRGBAToLogElement(float *src, float *dst, LogImageFile *logImag
        float *srgbSrc;
        float *srgbSrc_ptr;
        float *src_ptr = src;
-       float lut[65536];
+       float *lut;
 
        if (srcIsLinearRGB != 0) {
                /* we need to convert src to sRGB */
@@ -1390,13 +1438,14 @@ static int convertRGBAToLogElement(float *src, float *dst, LogImageFile *logImag
                srgbSrc_ptr = srgbSrc;
 
                /* convert data from Linear RGB to sRGB via lut */
-               getLinToSrgbLut((float *)&lut, logElement);
+               lut = getLinToSrgbLut(logElement);
                for (i = 0; i < logImage->width * logImage->height; i++) {
                        *(srgbSrc_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
                        *(srgbSrc_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
                        *(srgbSrc_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
                        srgbSrc_ptr++; src_ptr++;
                }
+               MEM_freeN(lut);
        }
        else
                srgbSrc = src;
index 900ae5122ef461367efbb538f59c9d0099c8c89f..fb16dd0c5a1c5633ffb4cd512b3ea54be7251b1a 100644 (file)
@@ -107,7 +107,7 @@ static void rna_DynamicPaintSurfaces_updateFrames(Main *bmain, Scene *scene, Poi
 
 static void rna_DynamicPaintSurface_reset(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
-       dynamicPaint_resetSurface((DynamicPaintSurface *)ptr->data);
+       dynamicPaint_resetSurface(scene, (DynamicPaintSurface *)ptr->data);
        rna_DynamicPaint_redoModifier(bmain, scene, ptr);
 }
 
@@ -116,7 +116,7 @@ static void rna_DynamicPaintSurface_initialcolortype(Main *bmain, Scene *scene,
        DynamicPaintSurface *surface = (DynamicPaintSurface *)ptr->data;
 
        surface->init_layername[0] = '\0';
-       dynamicPaint_clearSurface(surface);
+       dynamicPaint_clearSurface(scene, surface);
        rna_DynamicPaint_redoModifier(bmain, scene, ptr);
 }
 
@@ -143,7 +143,7 @@ static void rna_DynamicPaintSurface_uniqueName(Main *bmain, Scene *scene, Pointe
 static void rna_DynamicPaintSurface_changeType(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
        dynamicPaintSurface_updateType((DynamicPaintSurface *)ptr->data);
-       dynamicPaint_resetSurface((DynamicPaintSurface *)ptr->data);
+       dynamicPaint_resetSurface(scene, (DynamicPaintSurface *)ptr->data);
        rna_DynamicPaintSurface_reset(bmain, scene, ptr);
 }
 
index 10ac5a9548a7907209205a1967721f962be4865d..132faacbaac7d0544c2282e5ebe6178c997f6d98 100644 (file)
@@ -72,7 +72,9 @@ static void clear_envmap(struct EnvMap *env, bContext *C)
 static void texture_evaluate(struct Tex *tex, float value[3], float color_r[4])
 {
        TexResult texres = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, NULL};
-       multitex_ext(tex, value, NULL, NULL, 1, &texres, NULL);
+
+       /* TODO(sergey): always use color management now.  */
+       multitex_ext(tex, value, NULL, NULL, 1, &texres, NULL, true);
 
        color_r[0] = texres.tr;
        color_r[1] = texres.tg;
index ffd202736a936924b9f7c655470ec7a40dc94c9e..b59730d624438101ba8eb26802dff63af7ec2776 100644 (file)
@@ -219,7 +219,7 @@ static void displaceModifier_do(
 
                if (dmd->texture) {
                        texres.nor = NULL;
-                       get_texture_value(dmd->texture, tex_co[i], &texres);
+                       get_texture_value(dmd->modifier.scene, dmd->texture, tex_co[i], &texres, false);
                        delta = texres.tin - dmd->midlevel;
                }
                else {
index c3748ce026531735d723fbb90ad61c1eee42464b..adbdd9ac2ab6fc18c20e13874573dd56b985d7cf 100644 (file)
@@ -50,6 +50,7 @@
 #include "BKE_lattice.h"
 #include "BKE_mesh.h"
 #include "BKE_displist.h"
+#include "BKE_scene.h"
 
 #include "BKE_modifier.h"
 
@@ -69,12 +70,17 @@ void modifier_init_texture(Scene *scene, Tex *tex)
                BKE_image_user_frame_calc(&tex->iuser, scene->r.cfra, 0);
 }
 
-void get_texture_value(Tex *texture, float *tex_co, TexResult *texres)
+void get_texture_value(Scene *scene, Tex *texture, float *tex_co, TexResult *texres, bool use_color_management)
 {
        int result_type;
+       bool do_color_manage = false;
+
+       if (use_color_management) {
+               do_color_manage = BKE_scene_check_color_management_enabled(scene);
+       }
 
        /* no node textures for now */
-       result_type = multitex_ext_safe(texture, tex_co, texres, NULL);
+       result_type = multitex_ext_safe(texture, tex_co, texres, NULL, do_color_manage);
 
        /* if the texture gave an RGB value, we assume it didn't give a valid
         * intensity, since this is in the context of modifiers don't use perceptual color conversion.
index 6f05c9a957a488fba7c803a21565c08f6210797b..468e1621d073685cbe7595b304904b158a9dfbfd 100644 (file)
@@ -41,7 +41,7 @@ struct Tex;
 struct TexResult;
 
 void modifier_init_texture(struct Scene *scene, struct Tex *texture);
-void get_texture_value(struct Tex *texture, float *tex_co, struct TexResult *texres);
+void get_texture_value(struct Scene *scene, struct Tex *texture, float *tex_co, struct TexResult *texres, bool do_color_manage);
 void get_texture_coords(struct MappingInfoModifierData *dmd, struct Object *ob, struct DerivedMesh *dm,
                         float (*co)[3], float (*texco)[3], int numVerts);
 void modifier_vgroup_cache(struct ModifierData *md, float (*vertexCos)[3]);
index cba1880491c1acfcf4ade5bf25cbd681f66caefd..9acb2f3dc5d8f9b35df33d5132356a0218ed6f9b 100644 (file)
@@ -282,7 +282,7 @@ static void warpModifier_do(WarpModifierData *wmd, Object *ob,
                        if (tex_co) {
                                TexResult texres;
                                texres.nor = NULL;
-                               get_texture_value(wmd->texture, tex_co[i], &texres);
+                               get_texture_value(wmd->modifier.scene, wmd->texture, tex_co[i], &texres, false);
                                fac *= texres.tin;
                        }
 
index 8c6c483472edf2f0f1c6f8e089a12d41fd0714bd..71e668a1670a0e79cd9838dcd9d2e328a64e1407 100644 (file)
@@ -306,7 +306,7 @@ static void waveModifier_do(WaveModifierData *md,
                                if (wmd->texture) {
                                        TexResult texres;
                                        texres.nor = NULL;
-                                       get_texture_value(wmd->texture, tex_co[i], &texres);
+                                       get_texture_value(wmd->modifier.scene, wmd->texture, tex_co[i], &texres, false);
                                        amplit *= texres.tin;
                                }
 
index a5e63a7832fb8f62f9f1ab1b92ba50489f387c86..8ad9e26f78831e655f99f067d01b84d79d23cf49 100644 (file)
@@ -158,9 +158,12 @@ void weightvg_do_mask(int num, const int *indices, float *org_w, const float *ne
                        int idx = indices ? indices[i] : i;
                        TexResult texres;
                        float hsv[3]; /* For HSV color space. */
+                       bool do_color_manage;
+
+                       do_color_manage = tex_use_channel != MOD_WVG_MASK_TEX_USE_INT;
 
                        texres.nor = NULL;
-                       get_texture_value(texture, tex_co[idx], &texres);
+                       get_texture_value(scene, texture, tex_co[idx], &texres, do_color_manage);
                        /* Get the good channel value... */
                        switch (tex_use_channel) {
                                case MOD_WVG_MASK_TEX_USE_INT:
index d686de215177196b38bcbdff7ee9153d7eae263e..19ddfb7a13d5c080984799ffbd0185b3eb2f8a5a 100644 (file)
@@ -196,12 +196,13 @@ struct ImBuf;
 struct ImagePool;
 
 /* this one uses nodes */
-int    multitex_ext(struct Tex *tex, float texvec[3], float dxt[3], float dyt[3], int osatex, struct TexResult *texres, struct ImagePool *pool);
+int    multitex_ext(struct Tex *tex, float texvec[3], float dxt[3], float dyt[3], int osatex, struct TexResult *texres, struct ImagePool *pool, bool scene_color_manage);
 /* nodes disabled */
-int multitex_ext_safe(struct Tex *tex, float texvec[3], struct TexResult *texres, struct ImagePool *pool);
+int multitex_ext_safe(struct Tex *tex, float texvec[3], struct TexResult *texres, struct ImagePool *pool, bool scene_color_manage);
 /* only for internal node usage */
 int multitex_nodes(struct Tex *tex, float texvec[3], float dxt[3], float dyt[3], int osatex, struct TexResult *texres,
-                   const short thread, short which_output, struct ShadeInput *shi, struct MTex *mtex, struct ImagePool *pool);
+                   const short thread, short which_output, struct ShadeInput *shi, struct MTex *mtex,
+                   struct ImagePool *pool);
 
 /* shaded view and bake */
 struct Render;
index ee722ee426c22a7fd9b4a7bd12fa749068740de4..ad923a4172cb1b2cfec974278112b40922b7d54b 100644 (file)
@@ -1212,9 +1212,9 @@ static int multitex(Tex *tex, float texvec[3], float dxt[3], float dyt[3], int o
        return retval;
 }
 
-/* this is called from the shader and texture nodes */
-int multitex_nodes(Tex *tex, float texvec[3], float dxt[3], float dyt[3], int osatex, TexResult *texres,
-                   const short thread, short which_output, ShadeInput *shi, MTex *mtex, struct ImagePool *pool)
+static int multitex_nodes_intern(Tex *tex, float texvec[3], float dxt[3], float dyt[3], int osatex, TexResult *texres,
+                                 const short thread, short which_output, ShadeInput *shi, MTex *mtex, struct ImagePool *pool,
+                                 bool scene_color_manage)
 {
        if (tex==NULL) {
                memset(texres, 0, sizeof(TexResult));
@@ -1236,7 +1236,7 @@ int multitex_nodes(Tex *tex, float texvec[3], float dxt[3], float dyt[3], int os
                                ImBuf *ibuf = BKE_image_pool_acquire_ibuf(tex->ima, &tex->iuser, pool);
                                
                                /* don't linearize float buffers, assumed to be linear */
-                               if (ibuf && !(ibuf->rect_float) && R.scene_color_manage)
+                               if (ibuf && !(ibuf->rect_float) && scene_color_manage)
                                        IMB_colormanagement_colorspace_to_scene_linear_v3(&texres->tr, ibuf->rect_colorspace);
 
                                BKE_image_pool_release_ibuf(tex->ima, ibuf, pool);
@@ -1269,7 +1269,7 @@ int multitex_nodes(Tex *tex, float texvec[3], float dxt[3], float dyt[3], int os
                                ImBuf *ibuf = BKE_image_pool_acquire_ibuf(tex->ima, &tex->iuser, pool);
 
                                /* don't linearize float buffers, assumed to be linear */
-                               if (ibuf && !(ibuf->rect_float) && R.scene_color_manage)
+                               if (ibuf && !(ibuf->rect_float) && scene_color_manage)
                                        IMB_colormanagement_colorspace_to_scene_linear_v3(&texres->tr, ibuf->rect_colorspace);
 
                                BKE_image_pool_release_ibuf(tex->ima, ibuf, pool);
@@ -1283,6 +1283,16 @@ int multitex_nodes(Tex *tex, float texvec[3], float dxt[3], float dyt[3], int os
        }
 }
 
+/* this is called from the shader and texture nodes
+ * Use it from render pipeline only!
+ */
+int multitex_nodes(Tex *tex, float texvec[3], float dxt[3], float dyt[3], int osatex, TexResult *texres,
+                   const short thread, short which_output, ShadeInput *shi, MTex *mtex, struct ImagePool *pool)
+{
+       return multitex_nodes_intern(tex, texvec, dxt, dyt, osatex, texres,
+                                    thread, which_output, shi, mtex, pool, R.scene_color_manage);
+}
+
 /* this is called for surface shading */
 static int multitex_mtex(ShadeInput *shi, MTex *mtex, float texvec[3], float dxt[3], float dyt[3], TexResult *texres, struct ImagePool *pool)
 {
@@ -1300,19 +1310,25 @@ static int multitex_mtex(ShadeInput *shi, MTex *mtex, float texvec[3], float dxt
 }
 
 /* Warning, if the texres's values are not declared zero, check the return value to be sure
- * the color values are set before using the r/g/b values, otherwise you may use uninitialized values - Campbell */
-int multitex_ext(Tex *tex, float texvec[3], float dxt[3], float dyt[3], int osatex, TexResult *texres, struct ImagePool *pool)
+ * the color values are set before using the r/g/b values, otherwise you may use uninitialized values - Campbell
+ *
+ * Use it for stuff which is out of render pipeline.
+ */
+int multitex_ext(Tex *tex, float texvec[3], float dxt[3], float dyt[3], int osatex, TexResult *texres, struct ImagePool *pool, bool scene_color_manage)
 {
-       return multitex_nodes(tex, texvec, dxt, dyt, osatex, texres, 0, 0, NULL, NULL, pool);
+       return multitex_nodes_intern(tex, texvec, dxt, dyt, osatex, texres, 0, 0, NULL, NULL, pool, scene_color_manage);
 }
 
-/* extern-tex doesn't support nodes (ntreeBeginExec() can't be called when rendering is going on) */
-int multitex_ext_safe(Tex *tex, float texvec[3], TexResult *texres, struct ImagePool *pool)
+/* extern-tex doesn't support nodes (ntreeBeginExec() can't be called when rendering is going on)\
+ *
+ * Use it for stuff which is out of render pipeline.
+ */
+int multitex_ext_safe(Tex *tex, float texvec[3], TexResult *texres, struct ImagePool *pool, bool scene_color_manage)
 {
        int use_nodes= tex->use_nodes, retval;
        
        tex->use_nodes = FALSE;
-       retval= multitex_nodes(tex, texvec, NULL, NULL, 0, texres, 0, 0, NULL, NULL, pool);
+       retval= multitex_nodes_intern(tex, texvec, NULL, NULL, 0, texres, 0, 0, NULL, NULL, pool, scene_color_manage);
        tex->use_nodes= use_nodes;
        
        return retval;