diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2012-06-11 00:50:43 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2012-06-11 00:50:43 +0400 |
commit | 8135cc9f954e0d63ab3e97d4a7c52ff5e573eef0 (patch) | |
tree | a12ec0daccfc45b7e3c68e4a2d7099655daf619d /source/blender/compositor | |
parent | 0f33d5719fd0adc666e7e92e0f062281f4285f13 (diff) | |
parent | 298feff39006c14aa28b5e0232aa7ed70a83a496 (diff) |
Merged changes in the trunk up to revision 47700.
Conflicts resolved:
source/blender/blenkernel/BKE_main.h
source/blender/blenkernel/CMakeLists.txt
source/blender/blenkernel/intern/library.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/editors/interface/resources.c
source/blender/makesdna/DNA_ID.h
source/blender/makesdna/DNA_action_types.h
source/blender/makesdna/intern/makesdna.c
source/blender/makesrna/SConscript
source/blender/makesrna/intern/rna_internal.h
source/blender/makesrna/intern/rna_main.c
source/blender/makesrna/intern/rna_main_api.c
source/blender/windowmanager/WM_types.h
Diffstat (limited to 'source/blender/compositor')
81 files changed, 1276 insertions, 686 deletions
diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt index dc28328e867..22f72270734 100644 --- a/source/blender/compositor/CMakeLists.txt +++ b/source/blender/compositor/CMakeLists.txt @@ -26,24 +26,24 @@ set(INC . + intern + nodes + operations ../blenkernel ../blenlib + ../blenlib + ../blenloader + ../imbuf ../makesdna - ../render/extern/include - ../render/intern/include ../makesrna - ../blenloader - ../blenlib + ../opencl ../windowmanager - ../imbuf - ../../../intern/guardedalloc - nodes - ../nodes/ + ../nodes ../nodes/composite ../nodes/intern - intern - operations - ../opencl + ../render/extern/include + ../render/intern/include + ../../../intern/guardedalloc ) set(SRC @@ -100,7 +100,7 @@ set(SRC operations/COM_QualityStepHelper.h operations/COM_QualityStepHelper.cpp -# Internal nodes + # Internal nodes nodes/COM_MuteNode.cpp nodes/COM_MuteNode.h nodes/COM_GroupNode.cpp @@ -108,7 +108,7 @@ set(SRC nodes/COM_SocketProxyNode.cpp nodes/COM_SocketProxyNode.h -# input nodes + # input nodes nodes/COM_RenderLayersNode.cpp nodes/COM_RenderLayersNode.h nodes/COM_ImageNode.cpp @@ -129,8 +129,10 @@ set(SRC nodes/COM_MovieClipNode.h nodes/COM_OutputFileNode.cpp nodes/COM_OutputFileNode.h + nodes/COM_MaskNode.cpp + nodes/COM_MaskNode.h -# output nodes + # output nodes nodes/COM_CompositorNode.cpp nodes/COM_CompositorNode.h nodes/COM_ViewerNode.cpp @@ -144,7 +146,7 @@ set(SRC operations/COM_CalculateMeanOperation.cpp operations/COM_CalculateMeanOperation.h -# distort nodes + # distort nodes nodes/COM_TranslateNode.cpp nodes/COM_TranslateNode.h nodes/COM_ScaleNode.cpp @@ -191,27 +193,27 @@ set(SRC nodes/COM_DefocusNode.cpp nodes/COM_DefocusNode.h -# color nodes - nodes/COM_VectorCurveNode.cpp - nodes/COM_VectorCurveNode.h - nodes/COM_ColorCurveNode.cpp - nodes/COM_ColorCurveNode.h - nodes/COM_ColorToBWNode.cpp - nodes/COM_ColorToBWNode.h - nodes/COM_ColorRampNode.cpp - nodes/COM_ColorRampNode.h - nodes/COM_MixNode.cpp - nodes/COM_MixNode.h - nodes/COM_AlphaOverNode.cpp - nodes/COM_AlphaOverNode.h - nodes/COM_ZCombineNode.cpp - nodes/COM_ZCombineNode.h - nodes/COM_BrightnessNode.cpp - nodes/COM_BrightnessNode.h - nodes/COM_ColorBalanceNode.cpp - nodes/COM_ColorBalanceNode.h - nodes/COM_InvertNode.cpp - nodes/COM_InvertNode.h + # color nodes + nodes/COM_VectorCurveNode.cpp + nodes/COM_VectorCurveNode.h + nodes/COM_ColorCurveNode.cpp + nodes/COM_ColorCurveNode.h + nodes/COM_ColorToBWNode.cpp + nodes/COM_ColorToBWNode.h + nodes/COM_ColorRampNode.cpp + nodes/COM_ColorRampNode.h + nodes/COM_MixNode.cpp + nodes/COM_MixNode.h + nodes/COM_AlphaOverNode.cpp + nodes/COM_AlphaOverNode.h + nodes/COM_ZCombineNode.cpp + nodes/COM_ZCombineNode.h + nodes/COM_BrightnessNode.cpp + nodes/COM_BrightnessNode.h + nodes/COM_ColorBalanceNode.cpp + nodes/COM_ColorBalanceNode.h + nodes/COM_InvertNode.cpp + nodes/COM_InvertNode.h nodes/COM_GammaNode.cpp nodes/COM_GammaNode.h nodes/COM_SetAlphaNode.cpp @@ -231,25 +233,25 @@ set(SRC operations/COM_TonemapOperation.cpp operations/COM_TonemapOperation.h -# converter nodes - nodes/COM_IDMaskNode.cpp - nodes/COM_IDMaskNode.h - nodes/COM_SeparateRGBANode.cpp - nodes/COM_SeparateRGBANode.h - nodes/COM_CombineRGBANode.cpp - nodes/COM_CombineRGBANode.h - nodes/COM_SeparateHSVANode.cpp - nodes/COM_SeparateHSVANode.h - nodes/COM_CombineHSVANode.cpp - nodes/COM_CombineHSVANode.h - nodes/COM_SeparateYUVANode.cpp - nodes/COM_SeparateYUVANode.h - nodes/COM_CombineYUVANode.cpp - nodes/COM_CombineYUVANode.h - nodes/COM_SeparateYCCANode.cpp - nodes/COM_SeparateYCCANode.h - nodes/COM_CombineYCCANode.cpp - nodes/COM_CombineYCCANode.h + # converter nodes + nodes/COM_IDMaskNode.cpp + nodes/COM_IDMaskNode.h + nodes/COM_SeparateRGBANode.cpp + nodes/COM_SeparateRGBANode.h + nodes/COM_CombineRGBANode.cpp + nodes/COM_CombineRGBANode.h + nodes/COM_SeparateHSVANode.cpp + nodes/COM_SeparateHSVANode.h + nodes/COM_CombineHSVANode.cpp + nodes/COM_CombineHSVANode.h + nodes/COM_SeparateYUVANode.cpp + nodes/COM_SeparateYUVANode.h + nodes/COM_CombineYUVANode.cpp + nodes/COM_CombineYUVANode.h + nodes/COM_SeparateYCCANode.cpp + nodes/COM_SeparateYCCANode.h + nodes/COM_CombineYCCANode.cpp + nodes/COM_CombineYCCANode.h nodes/COM_NormalNode.cpp nodes/COM_NormalNode.h @@ -263,7 +265,7 @@ set(SRC operations/COM_NormalizeOperation.cpp operations/COM_NormalizeOperation.h -# Filter nodes + # Filter nodes nodes/COM_BilateralBlurNode.cpp nodes/COM_BilateralBlurNode.h operations/COM_BilateralBlurOperation.cpp @@ -273,12 +275,10 @@ set(SRC operations/COM_VectorBlurOperation.cpp operations/COM_VectorBlurOperation.h - - - nodes/COM_FilterNode.cpp - nodes/COM_FilterNode.h - nodes/COM_DilateErodeNode.cpp - nodes/COM_DilateErodeNode.h + nodes/COM_FilterNode.cpp + nodes/COM_FilterNode.h + nodes/COM_DilateErodeNode.cpp + nodes/COM_DilateErodeNode.h nodes/COM_BlurNode.cpp nodes/COM_BlurNode.h nodes/COM_BokehBlurNode.cpp @@ -308,7 +308,7 @@ set(SRC operations/COM_GammaCorrectOperation.h operations/COM_GammaCorrectOperation.cpp -# Matte nodes + # Matte nodes nodes/COM_BoxMaskNode.cpp nodes/COM_BoxMaskNode.h nodes/COM_EllipseMaskNode.cpp @@ -320,50 +320,50 @@ set(SRC operations/COM_DoubleEdgeMaskOperation.cpp operations/COM_DoubleEdgeMaskOperation.h -operations/COM_ColorSpillOperation.cpp -operations/COM_ColorSpillOperation.h - operations/COM_RenderLayersBaseProg.cpp - operations/COM_RenderLayersBaseProg.h - operations/COM_RenderLayersImageProg.cpp - operations/COM_RenderLayersImageProg.h - operations/COM_RenderLayersAlphaProg.cpp - operations/COM_RenderLayersAlphaProg.h - operations/COM_RenderLayersDepthProg.cpp - operations/COM_RenderLayersDepthProg.h - operations/COM_RenderLayersNormalOperation.cpp - operations/COM_RenderLayersNormalOperation.h - operations/COM_RenderLayersSpeedOperation.cpp - operations/COM_RenderLayersSpeedOperation.h - operations/COM_RenderLayersColorOperation.cpp - operations/COM_RenderLayersColorOperation.h - operations/COM_RenderLayersUVOperation.cpp - operations/COM_RenderLayersUVOperation.h - operations/COM_RenderLayersMistOperation.cpp - operations/COM_RenderLayersMistOperation.h - operations/COM_RenderLayersObjectIndexOperation.cpp - operations/COM_RenderLayersObjectIndexOperation.h - operations/COM_RenderLayersMaterialIndexOperation.cpp - operations/COM_RenderLayersMaterialIndexOperation.h - operations/COM_RenderLayersDiffuseOperation.cpp - operations/COM_RenderLayersDiffuseOperation.h - operations/COM_RenderLayersSpecularOperation.cpp - operations/COM_RenderLayersSpecularOperation.h - operations/COM_RenderLayersShadowOperation.cpp - operations/COM_RenderLayersShadowOperation.h - operations/COM_RenderLayersAOOperation.cpp - operations/COM_RenderLayersAOOperation.h - operations/COM_RenderLayersEmitOperation.cpp - operations/COM_RenderLayersEmitOperation.h - operations/COM_RenderLayersReflectionOperation.cpp - operations/COM_RenderLayersReflectionOperation.h - operations/COM_RenderLayersRefractionOperation.cpp - operations/COM_RenderLayersRefractionOperation.h - operations/COM_RenderLayersEnvironmentOperation.cpp - operations/COM_RenderLayersEnvironmentOperation.h - operations/COM_RenderLayersIndirectOperation.cpp - operations/COM_RenderLayersIndirectOperation.h - operations/COM_RenderLayersCyclesOperation.cpp - operations/COM_RenderLayersCyclesOperation.h + operations/COM_ColorSpillOperation.cpp + operations/COM_ColorSpillOperation.h + operations/COM_RenderLayersBaseProg.cpp + operations/COM_RenderLayersBaseProg.h + operations/COM_RenderLayersImageProg.cpp + operations/COM_RenderLayersImageProg.h + operations/COM_RenderLayersAlphaProg.cpp + operations/COM_RenderLayersAlphaProg.h + operations/COM_RenderLayersDepthProg.cpp + operations/COM_RenderLayersDepthProg.h + operations/COM_RenderLayersNormalOperation.cpp + operations/COM_RenderLayersNormalOperation.h + operations/COM_RenderLayersSpeedOperation.cpp + operations/COM_RenderLayersSpeedOperation.h + operations/COM_RenderLayersColorOperation.cpp + operations/COM_RenderLayersColorOperation.h + operations/COM_RenderLayersUVOperation.cpp + operations/COM_RenderLayersUVOperation.h + operations/COM_RenderLayersMistOperation.cpp + operations/COM_RenderLayersMistOperation.h + operations/COM_RenderLayersObjectIndexOperation.cpp + operations/COM_RenderLayersObjectIndexOperation.h + operations/COM_RenderLayersMaterialIndexOperation.cpp + operations/COM_RenderLayersMaterialIndexOperation.h + operations/COM_RenderLayersDiffuseOperation.cpp + operations/COM_RenderLayersDiffuseOperation.h + operations/COM_RenderLayersSpecularOperation.cpp + operations/COM_RenderLayersSpecularOperation.h + operations/COM_RenderLayersShadowOperation.cpp + operations/COM_RenderLayersShadowOperation.h + operations/COM_RenderLayersAOOperation.cpp + operations/COM_RenderLayersAOOperation.h + operations/COM_RenderLayersEmitOperation.cpp + operations/COM_RenderLayersEmitOperation.h + operations/COM_RenderLayersReflectionOperation.cpp + operations/COM_RenderLayersReflectionOperation.h + operations/COM_RenderLayersRefractionOperation.cpp + operations/COM_RenderLayersRefractionOperation.h + operations/COM_RenderLayersEnvironmentOperation.cpp + operations/COM_RenderLayersEnvironmentOperation.h + operations/COM_RenderLayersIndirectOperation.cpp + operations/COM_RenderLayersIndirectOperation.h + operations/COM_RenderLayersCyclesOperation.cpp + operations/COM_RenderLayersCyclesOperation.h operations/COM_ImageOperation.cpp operations/COM_ImageOperation.h @@ -375,39 +375,39 @@ operations/COM_ColorSpillOperation.h operations/COM_BokehImageOperation.h - operations/COM_SocketProxyOperation.h - operations/COM_SocketProxyOperation.cpp + operations/COM_SocketProxyOperation.h + operations/COM_SocketProxyOperation.cpp - operations/COM_CompositorOperation.h - operations/COM_CompositorOperation.cpp + operations/COM_CompositorOperation.h + operations/COM_CompositorOperation.cpp operations/COM_OutputFileOperation.h operations/COM_OutputFileOperation.cpp - operations/COM_ViewerBaseOperation.h - operations/COM_ViewerBaseOperation.cpp - operations/COM_ViewerOperation.h - operations/COM_ViewerOperation.cpp - operations/COM_PreviewOperation.h - operations/COM_PreviewOperation.cpp - operations/COM_SplitViewerOperation.h - operations/COM_SplitViewerOperation.cpp - operations/COM_ConvertValueToColourProg.h - operations/COM_ConvertValueToColourProg.cpp - operations/COM_ConvertColourToValueProg.h - operations/COM_ConvertColourToValueProg.cpp - operations/COM_ConvertColorToBWOperation.h - operations/COM_ConvertColorToBWOperation.cpp - operations/COM_ConvertColorToVectorOperation.h - operations/COM_ConvertColorToVectorOperation.cpp - operations/COM_ConvertValueToVectorOperation.h - operations/COM_ConvertValueToVectorOperation.cpp - operations/COM_ConvertVectorToColorOperation.h - operations/COM_ConvertVectorToColorOperation.cpp - operations/COM_ConvertVectorToValueOperation.h - operations/COM_ConvertVectorToValueOperation.cpp -operations/COM_ConvertDepthToRadiusOperation.h -operations/COM_ConvertDepthToRadiusOperation.cpp - operations/COM_ZCombineOperation.cpp - operations/COM_ZCombineOperation.h + operations/COM_ViewerBaseOperation.h + operations/COM_ViewerBaseOperation.cpp + operations/COM_ViewerOperation.h + operations/COM_ViewerOperation.cpp + operations/COM_PreviewOperation.h + operations/COM_PreviewOperation.cpp + operations/COM_SplitViewerOperation.h + operations/COM_SplitViewerOperation.cpp + operations/COM_ConvertValueToColourProg.h + operations/COM_ConvertValueToColourProg.cpp + operations/COM_ConvertColourToValueProg.h + operations/COM_ConvertColourToValueProg.cpp + operations/COM_ConvertColorToBWOperation.h + operations/COM_ConvertColorToBWOperation.cpp + operations/COM_ConvertColorToVectorOperation.h + operations/COM_ConvertColorToVectorOperation.cpp + operations/COM_ConvertValueToVectorOperation.h + operations/COM_ConvertValueToVectorOperation.cpp + operations/COM_ConvertVectorToColorOperation.h + operations/COM_ConvertVectorToColorOperation.cpp + operations/COM_ConvertVectorToValueOperation.h + operations/COM_ConvertVectorToValueOperation.cpp + operations/COM_ConvertDepthToRadiusOperation.h + operations/COM_ConvertDepthToRadiusOperation.cpp + operations/COM_ZCombineOperation.cpp + operations/COM_ZCombineOperation.h operations/COM_ConvertRGBToYCCOperation.h operations/COM_ConvertRGBToYCCOperation.cpp @@ -468,86 +468,86 @@ operations/COM_ConvertDepthToRadiusOperation.cpp operations/COM_GammaOperation.h operations/COM_ColorCorrectionOperation.cpp operations/COM_ColorCorrectionOperation.h - operations/COM_SetValueOperation.h - operations/COM_SetValueOperation.cpp - operations/COM_SetColorOperation.h - operations/COM_SetColorOperation.cpp - operations/COM_SetVectorOperation.h - operations/COM_SetVectorOperation.cpp - - operations/COM_MixBurnOperation.h - operations/COM_MixBurnOperation.cpp - operations/COM_MixColorOperation.h - operations/COM_MixColorOperation.cpp - operations/COM_MixDarkenOperation.h - operations/COM_MixDarkenOperation.cpp - operations/COM_MixDodgeOperation.h - operations/COM_MixDodgeOperation.cpp - operations/COM_MixDifferenceOperation.h - operations/COM_MixDifferenceOperation.cpp - operations/COM_MixDivideOperation.h - operations/COM_MixDivideOperation.cpp - operations/COM_MixHueOperation.h - operations/COM_MixHueOperation.cpp - operations/COM_MixLightenOperation.h - operations/COM_MixLightenOperation.cpp - operations/COM_MixLinearLightOperation.h - operations/COM_MixLinearLightOperation.cpp - operations/COM_MixOverlayOperation.h - operations/COM_MixOverlayOperation.cpp - operations/COM_MixSaturationOperation.h - operations/COM_MixSaturationOperation.cpp - operations/COM_MixScreenOperation.h - operations/COM_MixScreenOperation.cpp - operations/COM_MixSoftLightOperation.h - operations/COM_MixSoftLightOperation.cpp - operations/COM_MixValueOperation.h - operations/COM_MixValueOperation.cpp - operations/COM_MixSubtractOperation.h - operations/COM_MixSubtractOperation.cpp + operations/COM_SetValueOperation.h + operations/COM_SetValueOperation.cpp + operations/COM_SetColorOperation.h + operations/COM_SetColorOperation.cpp + operations/COM_SetVectorOperation.h + operations/COM_SetVectorOperation.cpp + + operations/COM_MixBurnOperation.h + operations/COM_MixBurnOperation.cpp + operations/COM_MixColorOperation.h + operations/COM_MixColorOperation.cpp + operations/COM_MixDarkenOperation.h + operations/COM_MixDarkenOperation.cpp + operations/COM_MixDodgeOperation.h + operations/COM_MixDodgeOperation.cpp + operations/COM_MixDifferenceOperation.h + operations/COM_MixDifferenceOperation.cpp + operations/COM_MixDivideOperation.h + operations/COM_MixDivideOperation.cpp + operations/COM_MixHueOperation.h + operations/COM_MixHueOperation.cpp + operations/COM_MixLightenOperation.h + operations/COM_MixLightenOperation.cpp + operations/COM_MixLinearLightOperation.h + operations/COM_MixLinearLightOperation.cpp + operations/COM_MixOverlayOperation.h + operations/COM_MixOverlayOperation.cpp + operations/COM_MixSaturationOperation.h + operations/COM_MixSaturationOperation.cpp + operations/COM_MixScreenOperation.h + operations/COM_MixScreenOperation.cpp + operations/COM_MixSoftLightOperation.h + operations/COM_MixSoftLightOperation.cpp + operations/COM_MixValueOperation.h + operations/COM_MixValueOperation.cpp + operations/COM_MixSubtractOperation.h + operations/COM_MixSubtractOperation.cpp operations/COM_MathBaseOperation.h operations/COM_MathBaseOperation.cpp - operations/COM_AlphaOverMixedOperation.h - operations/COM_AlphaOverMixedOperation.cpp - operations/COM_AlphaOverPremultiplyOperation.h - operations/COM_AlphaOverPremultiplyOperation.cpp - operations/COM_AlphaOverKeyOperation.h - operations/COM_AlphaOverKeyOperation.cpp - - operations/COM_ColorBalanceLGGOperation.h - operations/COM_ColorBalanceLGGOperation.cpp - operations/COM_ColorBalanceASCCDLOperation.h - operations/COM_ColorBalanceASCCDLOperation.cpp - operations/COM_InvertOperation.cpp - operations/COM_InvertOperation.h + operations/COM_AlphaOverMixedOperation.h + operations/COM_AlphaOverMixedOperation.cpp + operations/COM_AlphaOverPremultiplyOperation.h + operations/COM_AlphaOverPremultiplyOperation.cpp + operations/COM_AlphaOverKeyOperation.h + operations/COM_AlphaOverKeyOperation.cpp + + operations/COM_ColorBalanceLGGOperation.h + operations/COM_ColorBalanceLGGOperation.cpp + operations/COM_ColorBalanceASCCDLOperation.h + operations/COM_ColorBalanceASCCDLOperation.cpp + operations/COM_InvertOperation.cpp + operations/COM_InvertOperation.h operations/COM_SetAlphaOperation.cpp operations/COM_SetAlphaOperation.h operations/COM_MapValueOperation.cpp operations/COM_MapValueOperation.h -# Distort operation - operations/COM_TranslateOperation.h - operations/COM_TranslateOperation.cpp - operations/COM_RotateOperation.h - operations/COM_RotateOperation.cpp - operations/COM_ScaleOperation.h - operations/COM_ScaleOperation.cpp - operations/COM_MapUVOperation.h - operations/COM_MapUVOperation.cpp - operations/COM_DisplaceOperation.h - operations/COM_DisplaceOperation.cpp - operations/COM_DisplaceSimpleOperation.h - operations/COM_DisplaceSimpleOperation.cpp - operations/COM_FlipOperation.h - operations/COM_FlipOperation.cpp - operations/COM_ProjectorLensDistortionOperation.cpp - operations/COM_ProjectorLensDistortionOperation.h - operations/COM_ScreenLensDistortionOperation.cpp - operations/COM_ScreenLensDistortionOperation.h - -#Filter operations + # Distort operation + operations/COM_TranslateOperation.h + operations/COM_TranslateOperation.cpp + operations/COM_RotateOperation.h + operations/COM_RotateOperation.cpp + operations/COM_ScaleOperation.h + operations/COM_ScaleOperation.cpp + operations/COM_MapUVOperation.h + operations/COM_MapUVOperation.cpp + operations/COM_DisplaceOperation.h + operations/COM_DisplaceOperation.cpp + operations/COM_DisplaceSimpleOperation.h + operations/COM_DisplaceSimpleOperation.cpp + operations/COM_FlipOperation.h + operations/COM_FlipOperation.cpp + operations/COM_ProjectorLensDistortionOperation.cpp + operations/COM_ProjectorLensDistortionOperation.h + operations/COM_ScreenLensDistortionOperation.cpp + operations/COM_ScreenLensDistortionOperation.h + + #Filter operations operations/COM_ConvolutionFilterOperation.h operations/COM_ConvolutionFilterOperation.cpp operations/COM_ConvolutionEdgeFilterOperation.h @@ -570,7 +570,7 @@ operations/COM_ConvertDepthToRadiusOperation.cpp operations/COM_SetSamplerOperation.h -#Convert operations + #Convert operations operations/COM_IDMaskOperation.cpp operations/COM_IDMaskOperation.h @@ -581,7 +581,8 @@ operations/COM_ConvertDepthToRadiusOperation.cpp operations/COM_DotproductOperation.cpp operations/COM_DotproductOperation.h -# Matte operation + + # Matte operation operations/COM_BoxMaskOperation.h operations/COM_BoxMaskOperation.cpp operations/COM_EllipseMaskOperation.h @@ -594,6 +595,9 @@ operations/COM_ConvertDepthToRadiusOperation.cpp operations/COM_AntiAliasOperation.cpp operations/COM_AntiAliasOperation.h + + operations/COM_MaskOperation.cpp + operations/COM_MaskOperation.h ) blender_add_lib(bf_compositor "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/compositor/COM_defines.h b/source/blender/compositor/COM_defines.h index df807091cb8..f87265c50f5 100644 --- a/source/blender/compositor/COM_defines.h +++ b/source/blender/compositor/COM_defines.h @@ -52,12 +52,25 @@ typedef enum CompositorQuality { COM_QUALITY_LOW = 2 } CompositorQuality; +/** + * @brief Possible priority settings + * @ingroup Execution + */ +typedef enum CompositorPriority { + /** @brief High quality setting */ + COM_PRIORITY_HIGH = 2 , + /** @brief Medium quality setting */ + COM_PRIORITY_MEDIUM = 1, + /** @brief Low quality setting */ + COM_PRIORITY_LOW = 0 +} CompositorPriority; + // configurable items // chunk size determination #define COM_PREVIEW_SIZE 140.0f -#define COM_OPENCL_ENABLED -#define COM_PREVIEW_ENABLED +//#define COM_OPENCL_ENABLED + // workscheduler threading models /** * COM_TM_QUEUE is a multithreaded model, which uses the BLI_thread_queue pattern. This is the default option. diff --git a/source/blender/compositor/intern/COM_ChunkOrderHotspot.cpp b/source/blender/compositor/intern/COM_ChunkOrderHotspot.cpp index 94110f0bcfe..0ab08ec5810 100644 --- a/source/blender/compositor/intern/COM_ChunkOrderHotspot.cpp +++ b/source/blender/compositor/intern/COM_ChunkOrderHotspot.cpp @@ -35,6 +35,6 @@ double ChunkOrderHotspot::determineDistance(int x, int y) int dx = x-this->x; int dy = y-this->y; double result = sqrt((double)(dx*dx+dy*dy)); - result += this->addition; + result += (double)this->addition; return result; } diff --git a/source/blender/compositor/intern/COM_Converter.cpp b/source/blender/compositor/intern/COM_Converter.cpp index 3cb297801ca..dc6409e7b86 100644 --- a/source/blender/compositor/intern/COM_Converter.cpp +++ b/source/blender/compositor/intern/COM_Converter.cpp @@ -111,6 +111,7 @@ #include "COM_DefocusNode.h" #include "COM_DoubleEdgeMaskNode.h" #include "COM_CropNode.h" +#include "COM_MaskNode.h" Node *Converter::convert(bNode *bNode) { @@ -347,6 +348,9 @@ case CMP_NODE_OUTPUT_FILE: case CMP_NODE_CROP: node = new CropNode(bNode); break; + case CMP_NODE_MASK: + node = new MaskNode(bNode); + break; /* not inplemented yet */ default: node = new MuteNode(bNode); diff --git a/source/blender/compositor/intern/COM_ExecutionGroup.cpp b/source/blender/compositor/intern/COM_ExecutionGroup.cpp index 0ebf9af207b..481b83c81a3 100644 --- a/source/blender/compositor/intern/COM_ExecutionGroup.cpp +++ b/source/blender/compositor/intern/COM_ExecutionGroup.cpp @@ -57,7 +57,7 @@ ExecutionGroup::ExecutionGroup() this->chunksFinished = 0; } -int ExecutionGroup::getRenderPriotrity() +CompositorPriority ExecutionGroup::getRenderPriotrity() { return this->getOutputNodeOperation()->getRenderPriority(); } @@ -351,7 +351,8 @@ void ExecutionGroup::execute(ExecutionSystem *graph) startIndex = index+1; } } - PIL_sleep_ms(10); + + WorkScheduler::finish(); if (bTree->test_break && bTree->test_break(bTree->tbh)) { breaked = true; @@ -401,47 +402,11 @@ MemoryBuffer** ExecutionGroup::getInputBuffersOpenCL(int chunkNumber) return memoryBuffers; } -// @todo: for opencl the memory buffers size needs to be same as the needed size -// currently this method is not called, but will be when opencl nodes are created MemoryBuffer *ExecutionGroup::constructConsolidatedMemoryBuffer(MemoryProxy *memoryProxy, rcti *rect) { - // find all chunks inside the rect - // determine minxchunk, minychunk, maxxchunk, maxychunk where x and y are chunknumbers - float chunkSizef = this->chunkSize; - - int indexx, indexy; - - const int minxchunk = floor(rect->xmin/chunkSizef); - const int maxxchunk = ceil((rect->xmax-1)/chunkSizef); - const int minychunk = floor(rect->ymin/chunkSizef); - const int maxychunk = ceil((rect->ymax-1)/chunkSizef); - - if (maxxchunk== minxchunk+1 && maxychunk == minychunk+1) { - MemoryBuffer *result =memoryProxy->getBuffer(); - return result; - } - - rcti chunkRect; - chunkRect.xmin = minxchunk*this->chunkSize; - chunkRect.xmax = maxxchunk*this->chunkSize; - chunkRect.ymin = minychunk*this->chunkSize; - chunkRect.ymax = maxychunk*this->chunkSize; - - CLAMP(chunkRect.xmin, 0, (int)this->width); - CLAMP(chunkRect.xmax, 0, (int)this->width); - CLAMP(chunkRect.ymin, 0, (int)this->height); - CLAMP(chunkRect.ymax, 0, (int)this->height); - - MemoryBuffer *result = new MemoryBuffer(memoryProxy, &chunkRect); - - for (indexx = max(minxchunk, 0); indexx<min((int)this->numberOfXChunks, maxxchunk) ; indexx++) { - for (indexy = max(minychunk, 0); indexy<min((int)this->numberOfYChunks, maxychunk) ; indexy++) { - /* int chunkNumber = indexx+indexy*this->numberOfXChunks; */ /* UNUSED */ - MemoryBuffer *chunkBuffer = memoryProxy->getBuffer(); - result->copyContentFrom(chunkBuffer); - } - } - + MemoryBuffer* imageBuffer = memoryProxy->getBuffer(); + MemoryBuffer* result = new MemoryBuffer(memoryProxy, rect); + result->copyContentFrom(imageBuffer); return result; } @@ -487,14 +452,14 @@ void ExecutionGroup::determineChunkRect(rcti *rect, const unsigned int chunkNumb MemoryBuffer *ExecutionGroup::allocateOutputBuffer(int chunkNumber, rcti *rect) { - MemoryBuffer *outputBuffer = NULL; - // output allocation is only valid when our outputoperation is a memorywriter + // we asume that this method is only called from complex execution groups. NodeOperation * operation = this->getOutputNodeOperation(); if (operation->isWriteBufferOperation()) { -/* WriteBufferOperation *writeOperation = (WriteBufferOperation*)operation; */ /* UNUSED */ -// @todo outputBuffer = MemoryManager::allocateMemoryBuffer(writeOperation->getMemoryProxy(), chunkNumber, rect); + WriteBufferOperation *writeOperation = (WriteBufferOperation*)operation; + MemoryBuffer *buffer = new MemoryBuffer(writeOperation->getMemoryProxy(), rect); + return buffer; } - return outputBuffer; + return NULL; } @@ -600,11 +565,6 @@ void ExecutionGroup::determineDependingMemoryProxies(vector<MemoryProxy*> *memor } } -bool ExecutionGroup::operator ==(const ExecutionGroup & executionGroup) const -{ - return this->getOutputNodeOperation() == executionGroup.getOutputNodeOperation(); -} - bool ExecutionGroup::isOpenCL() { return this->openCL; diff --git a/source/blender/compositor/intern/COM_ExecutionGroup.h b/source/blender/compositor/intern/COM_ExecutionGroup.h index cbdc9bb1787..416a78eb8b8 100644 --- a/source/blender/compositor/intern/COM_ExecutionGroup.h +++ b/source/blender/compositor/intern/COM_ExecutionGroup.h @@ -167,13 +167,7 @@ private: * @param operation the operation to be added */ bool canContainOperation(NodeOperation *operation); - - /** - * @brief get the Render priority of this ExecutionGroup - * @see ExecutionSystem.execute - */ - int getRenderPriotrity(); - + /** * @brief calculate the actual chunk size of this execution group. * @note A chunk size is an unsigned int that is both the height and width of a chunk. @@ -396,17 +390,21 @@ public: * @see determineChunkSize() */ void determineChunkRect(rcti *rect, const unsigned int chunkNumber) const; - - - bool operator ==(const ExecutionGroup &executionGroup) const; - - /** + + /** * @brief can this ExecutionGroup be scheduled on an OpenCLDevice * @see WorkScheduler.schedule */ bool isOpenCL(); - + void setChunksize(int chunksize) {this->chunkSize = chunksize;} + + /** + * @brief get the Render priority of this ExecutionGroup + * @see ExecutionSystem.execute + */ + CompositorPriority getRenderPriotrity(); + }; #endif diff --git a/source/blender/compositor/intern/COM_ExecutionSystem.cpp b/source/blender/compositor/intern/COM_ExecutionSystem.cpp index 96d2a6f4434..8c0b37a0685 100644 --- a/source/blender/compositor/intern/COM_ExecutionSystem.cpp +++ b/source/blender/compositor/intern/COM_ExecutionSystem.cpp @@ -127,20 +127,9 @@ void ExecutionSystem::execute() WorkScheduler::start(this->context); - - vector<ExecutionGroup*> executionGroups; - this->findOutputExecutionGroup(&executionGroups); - - /* start execution of the ExecutionGroups based on priority of their output node */ - for (int priority = 9 ; priority>=0 ; priority--) { - for (index = 0 ; index < executionGroups.size(); index ++) { - ExecutionGroup *group = executionGroups[index]; - NodeOperation *output = group->getOutputNodeOperation(); - if (output->getRenderPriority() == priority) { - group->execute(this); - } - } - } + executeGroups(COM_PRIORITY_HIGH); + executeGroups(COM_PRIORITY_MEDIUM); + executeGroups(COM_PRIORITY_LOW); WorkScheduler::finish(); WorkScheduler::stop(); @@ -155,6 +144,18 @@ void ExecutionSystem::execute() } } +void ExecutionSystem::executeGroups(CompositorPriority priority) +{ + int index; + vector<ExecutionGroup*> executionGroups; + this->findOutputExecutionGroup(&executionGroups, priority); + + for (index = 0 ; index < executionGroups.size(); index ++) { + ExecutionGroup *group = executionGroups[index]; + group->execute(this); + } +} + void ExecutionSystem::addOperation(NodeOperation *operation) { ExecutionSystemHelper::addOperation(this->operations, operation); @@ -304,6 +305,17 @@ void ExecutionSystem::determineActualSocketDataTypes(vector<NodeBase*> &nodes) } } +void ExecutionSystem::findOutputExecutionGroup(vector<ExecutionGroup*> *result, CompositorPriority priority) const +{ + unsigned int index; + for (index = 0 ; index < this->groups.size() ; index ++) { + ExecutionGroup *group = this->groups[index]; + if (group->isOutputExecutionGroup() && group->getRenderPriotrity() == priority) { + result->push_back(group); + } + } +} + void ExecutionSystem::findOutputExecutionGroup(vector<ExecutionGroup*> *result) const { unsigned int index; diff --git a/source/blender/compositor/intern/COM_ExecutionSystem.h b/source/blender/compositor/intern/COM_ExecutionSystem.h index 85fec8b6145..510e58ba1bb 100644 --- a/source/blender/compositor/intern/COM_ExecutionSystem.h +++ b/source/blender/compositor/intern/COM_ExecutionSystem.h @@ -141,6 +141,11 @@ private: //methods /** * find all execution group with output nodes */ + void findOutputExecutionGroup(vector<ExecutionGroup*> *result, CompositorPriority priority) const; + + /** + * find all execution group with output nodes + */ void findOutputExecutionGroup(vector<ExecutionGroup*> *result) const; public: @@ -224,6 +229,8 @@ private: * @param nodes list of nodes or operations to do the data type determination */ void determineActualSocketDataTypes(vector<NodeBase*> &nodes); + + void executeGroups(CompositorPriority priority); }; #endif diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.cpp b/source/blender/compositor/intern/COM_MemoryBuffer.cpp index 37d79607d12..3ebf8398c02 100644 --- a/source/blender/compositor/intern/COM_MemoryBuffer.cpp +++ b/source/blender/compositor/intern/COM_MemoryBuffer.cpp @@ -150,8 +150,8 @@ void MemoryBuffer::readCubic(float result[4], float x, float y) float valuex = x - x1; float valuey = y - y1; - float mvaluex = 1.0 - valuex; - float mvaluey = 1.0 - valuey; + float mvaluex = 1.0f - valuex; + float mvaluey = 1.0f - valuey; float color1[4]; float color2[4]; diff --git a/source/blender/compositor/intern/COM_Node.cpp b/source/blender/compositor/intern/COM_Node.cpp index ba5e21d53ae..264725b4b2c 100644 --- a/source/blender/compositor/intern/COM_Node.cpp +++ b/source/blender/compositor/intern/COM_Node.cpp @@ -83,23 +83,20 @@ void Node::addSetValueOperation(ExecutionSystem *graph, InputSocket *inputsocket graph->addOperation(operation); } -void Node::addPreviewOperation(ExecutionSystem *system, OutputSocket *outputSocket, int priority) +void Node::addPreviewOperation(ExecutionSystem *system, OutputSocket *outputSocket) { -#ifdef COM_PREVIEW_ENABLED PreviewOperation *operation = new PreviewOperation(); system->addOperation(operation); operation->setbNode(this->getbNode()); operation->setbNodeTree(system->getContext().getbNodeTree()); - operation->setPriority(priority); this->addLink(system, outputSocket, operation->getInputSocket(0)); -#endif } -void Node::addPreviewOperation(ExecutionSystem *system, InputSocket *inputSocket, int priority) +void Node::addPreviewOperation(ExecutionSystem *system, InputSocket *inputSocket) { if (inputSocket->isConnected()) { OutputSocket *outputsocket = inputSocket->getConnection()->getFromSocket(); - this->addPreviewOperation(system, outputsocket, priority); + this->addPreviewOperation(system, outputsocket); } } diff --git a/source/blender/compositor/intern/COM_Node.h b/source/blender/compositor/intern/COM_Node.h index 2666d0a6980..23744adf642 100644 --- a/source/blender/compositor/intern/COM_Node.h +++ b/source/blender/compositor/intern/COM_Node.h @@ -120,8 +120,8 @@ protected: Node(); - void addPreviewOperation(ExecutionSystem *system, InputSocket *inputSocket, int priority); - void addPreviewOperation(ExecutionSystem *system, OutputSocket *inputSocket, int priority); + void addPreviewOperation(ExecutionSystem *system, InputSocket *inputSocket); + void addPreviewOperation(ExecutionSystem *system, OutputSocket *outputSocket); bNodeSocket *getEditorInputSocket(int editorNodeInputSocketIndex); bNodeSocket *getEditorOutputSocket(int editorNodeOutputSocketIndex); diff --git a/source/blender/compositor/intern/COM_NodeOperation.cpp b/source/blender/compositor/intern/COM_NodeOperation.cpp index fae652e39d7..650e4af5ae0 100644 --- a/source/blender/compositor/intern/COM_NodeOperation.cpp +++ b/source/blender/compositor/intern/COM_NodeOperation.cpp @@ -124,3 +124,111 @@ bool NodeOperation::determineDependingAreaOfInterest(rcti * input, ReadBufferOpe return false; } } + +cl_mem NodeOperation::COM_clAttachMemoryBufferToKernelParameter(cl_context context, cl_kernel kernel, int parameterIndex, int offsetIndex, list<cl_mem> *cleanup, MemoryBuffer **inputMemoryBuffers, SocketReader* reader) +{ + cl_int error; + MemoryBuffer* result = (MemoryBuffer*)reader->initializeTileData(NULL, inputMemoryBuffers); + + const cl_image_format imageFormat = { + CL_RGBA, + CL_FLOAT + }; + + cl_mem clBuffer = clCreateImage2D(context, CL_MEM_READ_ONLY|CL_MEM_USE_HOST_PTR, &imageFormat, result->getWidth(), + result->getHeight(), 0, result->getBuffer(), &error); + + if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } + if (error == CL_SUCCESS) cleanup->push_back(clBuffer); + + error = clSetKernelArg(kernel, parameterIndex, sizeof(cl_mem), &clBuffer); + if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } + + COM_clAttachMemoryBufferOffsetToKernelParameter(kernel, offsetIndex, result); + return clBuffer; +} + +void NodeOperation::COM_clAttachMemoryBufferOffsetToKernelParameter(cl_kernel kernel, int offsetIndex, MemoryBuffer *memoryBuffer) +{ + if (offsetIndex != -1) { + cl_int error; + rcti* rect = memoryBuffer->getRect(); + cl_int2 offset = {rect->xmin, rect->ymin}; + + error = clSetKernelArg(kernel, offsetIndex, sizeof(cl_int2), &offset); + if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } + } +} + +void NodeOperation::COM_clAttachSizeToKernelParameter(cl_kernel kernel, int offsetIndex) +{ + if (offsetIndex != -1) { + cl_int error; + cl_int2 offset = {this->getWidth(), this->getHeight()}; + + error = clSetKernelArg(kernel, offsetIndex, sizeof(cl_int2), &offset); + if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } + } +} + +void NodeOperation::COM_clAttachOutputMemoryBufferToKernelParameter(cl_kernel kernel, int parameterIndex, cl_mem clOutputMemoryBuffer) +{ + cl_int error; + error = clSetKernelArg(kernel, parameterIndex, sizeof(cl_mem), &clOutputMemoryBuffer); + if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } +} + +void NodeOperation::COM_clEnqueueRange(cl_command_queue queue, cl_kernel kernel, MemoryBuffer *outputMemoryBuffer) { + cl_int error; + const size_t size[] = {outputMemoryBuffer->getWidth(),outputMemoryBuffer->getHeight()}; + + error = clEnqueueNDRangeKernel(queue, kernel, 2, NULL, size, 0, 0, 0, NULL); + if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } +} + +void NodeOperation::COM_clEnqueueRange(cl_command_queue queue, cl_kernel kernel, MemoryBuffer *outputMemoryBuffer, int offsetIndex) { + cl_int error; + const int width = outputMemoryBuffer->getWidth(); + const int height = outputMemoryBuffer->getHeight(); + int offsetx; + int offsety; + const int localSize = 32; + size_t size[2]; + cl_int2 offset; + + for (offsety = 0 ; offsety < height; offsety+=localSize) { + offset[1] = offsety; + if (offsety+localSize < height) { + size[1] = localSize; + } else { + size[1] = height - offsety; + } + for (offsetx = 0 ; offsetx < width ; offsetx+=localSize) { + if (offsetx+localSize < width) { + size[0] = localSize; + } else { + size[0] = width - offsetx; + } + offset[0] = offsetx; + + error = clSetKernelArg(kernel, offsetIndex, sizeof(cl_int2), &offset); + if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } + error = clEnqueueNDRangeKernel(queue, kernel, 2, NULL, size, 0, 0, 0, NULL); + if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } + clFlush(queue); + } + } +} + +cl_kernel NodeOperation::COM_clCreateKernel(cl_program program, const char *kernelname, list<cl_kernel> *clKernelsToCleanUp) +{ + cl_int error; + cl_kernel kernel = clCreateKernel(program, kernelname, &error) ; + if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); + } + else { + if (clKernelsToCleanUp) clKernelsToCleanUp->push_back(kernel); + } + return kernel; + +} diff --git a/source/blender/compositor/intern/COM_NodeOperation.h b/source/blender/compositor/intern/COM_NodeOperation.h index 73ba5b472d7..2219907b0c8 100644 --- a/source/blender/compositor/intern/COM_NodeOperation.h +++ b/source/blender/compositor/intern/COM_NodeOperation.h @@ -139,8 +139,10 @@ public: * @param rect the rectangle of the chunk (location and size) * @param chunkNumber the chunkNumber to be calculated * @param memoryBuffers all input MemoryBuffer's needed + * @param outputBuffer the outputbuffer to write to */ - virtual void executeOpenCLRegion(cl_context context, cl_program program, cl_command_queue queue, rcti *rect, unsigned int chunkNumber, MemoryBuffer** memoryBuffers) {} + virtual void executeOpenCLRegion(cl_context context, cl_program program, cl_command_queue queue, rcti *rect, + unsigned int chunkNumber, MemoryBuffer** memoryBuffers, MemoryBuffer* outputBuffer) {} /** * @brief custom handle to add new tasks to the OpenCL command queue in order to execute a chunk on an GPUDevice @@ -207,9 +209,9 @@ public: /** * @brief get the render priority of this node. * @note only applicable for output operations like ViewerOperation - * @return [0:9] 9 is highest priority + * @return CompositorPriority */ - virtual const int getRenderPriority() const {return 0;} + virtual const CompositorPriority getRenderPriority() const {return COM_PRIORITY_LOW;} /** * @brief can this NodeOperation be scheduled on an OpenCLDevice @@ -242,6 +244,13 @@ protected: */ void setOpenCL(bool openCL) {this->openCL = openCL;} + static cl_mem COM_clAttachMemoryBufferToKernelParameter(cl_context context, cl_kernel kernel, int parameterIndex, int offsetIndex, list<cl_mem> *cleanup, MemoryBuffer **inputMemoryBuffers, SocketReader* reader); + static void COM_clAttachMemoryBufferOffsetToKernelParameter(cl_kernel kernel, int offsetIndex, MemoryBuffer *memoryBuffers); + static void COM_clAttachOutputMemoryBufferToKernelParameter(cl_kernel kernel, int parameterIndex, cl_mem clOutputMemoryBuffer); + void COM_clAttachSizeToKernelParameter(cl_kernel kernel, int offsetIndex); + static void COM_clEnqueueRange(cl_command_queue queue, cl_kernel kernel, MemoryBuffer* outputMemoryBuffer); + static void COM_clEnqueueRange(cl_command_queue queue, cl_kernel kernel, MemoryBuffer *outputMemoryBuffer, int offsetIndex); + cl_kernel COM_clCreateKernel(cl_program program, const char* kernelname, list<cl_kernel> *clKernelsToCleanUp); }; diff --git a/source/blender/compositor/intern/COM_OpenCLDevice.cpp b/source/blender/compositor/intern/COM_OpenCLDevice.cpp index 692b96f40b3..e6d3789b06d 100644 --- a/source/blender/compositor/intern/COM_OpenCLDevice.cpp +++ b/source/blender/compositor/intern/COM_OpenCLDevice.cpp @@ -56,10 +56,10 @@ void OpenCLDevice::execute(WorkPackage *work) MemoryBuffer ** inputBuffers = executionGroup->getInputBuffersOpenCL(chunkNumber); MemoryBuffer * outputBuffer = executionGroup->allocateOutputBuffer(chunkNumber, &rect); - executionGroup->getOutputNodeOperation()->executeOpenCLRegion(this->context, this->program, this->queue, &rect, chunkNumber, inputBuffers); + executionGroup->getOutputNodeOperation()->executeOpenCLRegion(this->context, this->program, this->queue, &rect, + chunkNumber, inputBuffers, outputBuffer); + + delete outputBuffer; executionGroup->finalizeChunkExecution(chunkNumber, inputBuffers); - if (outputBuffer != NULL) { - outputBuffer->setCreatedState(); - } } diff --git a/source/blender/compositor/intern/COM_WorkScheduler.cpp b/source/blender/compositor/intern/COM_WorkScheduler.cpp index 80b91b2364c..ba8bfe55310 100644 --- a/source/blender/compositor/intern/COM_WorkScheduler.cpp +++ b/source/blender/compositor/intern/COM_WorkScheduler.cpp @@ -28,7 +28,7 @@ #include "COM_OpenCLDevice.h" #include "OCL_opencl.h" #include "stdio.h" -#include "COM_OpenCLKernels.cl.cpp" +#include "COM_OpenCLKernels.cl.h" #include "BKE_global.h" #if COM_CURRENT_THREADING_MODEL == COM_TM_NOTHREAD @@ -39,8 +39,6 @@ #endif -/// @brief global state of the WorkScheduler. -static WorkSchedulerState state; /// @brief list of all CPUDevices. for every hardware thread an instance of CPUDevice is created static vector<CPUDevice*> cpudevices; @@ -68,43 +66,29 @@ static bool openclActive = false; #if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE void *WorkScheduler::thread_execute_cpu(void *data) { - bool continueLoop = true; Device *device = (Device*)data; - while (continueLoop) { - WorkPackage *work = (WorkPackage*)BLI_thread_queue_pop(cpuqueue); - if (work) { - device->execute(work); - delete work; - } - PIL_sleep_ms(10); - - if (WorkScheduler::isStopping()) { - continueLoop = false; - } + WorkPackage *work; + + while ((work = (WorkPackage*)BLI_thread_queue_pop(cpuqueue))) { + device->execute(work); + delete work; } + return NULL; } void *WorkScheduler::thread_execute_gpu(void *data) { - bool continueLoop = true; Device *device = (Device*)data; - while (continueLoop) { - WorkPackage *work = (WorkPackage*)BLI_thread_queue_pop(gpuqueue); - if (work) { - device->execute(work); - delete work; - } - PIL_sleep_ms(10); - - if (WorkScheduler::isStopping()) { - continueLoop = false; - } + WorkPackage *work; + + while ((work = (WorkPackage*)BLI_thread_queue_pop(gpuqueue))) { + device->execute(work); + delete work; } + return NULL; } - -bool WorkScheduler::isStopping() {return state == COM_WSS_STOPPING;} #endif @@ -135,7 +119,6 @@ void WorkScheduler::start(CompositorContext &context) #if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE unsigned int index; cpuqueue = BLI_thread_queue_init(); - BLI_thread_queue_nowait(cpuqueue); BLI_init_threads(&cputhreads, thread_execute_cpu, cpudevices.size()); for (index = 0 ; index < cpudevices.size() ; index ++) { Device *device = cpudevices[index]; @@ -144,7 +127,6 @@ void WorkScheduler::start(CompositorContext &context) #ifdef COM_OPENCL_ENABLED if (context.getHasActiveOpenCLDevices()) { gpuqueue = BLI_thread_queue_init(); - BLI_thread_queue_nowait(gpuqueue); BLI_init_threads(&gputhreads, thread_execute_gpu, gpudevices.size()); for (index = 0 ; index < gpudevices.size() ; index ++) { Device *device = gpudevices[index]; @@ -157,45 +139,39 @@ void WorkScheduler::start(CompositorContext &context) } #endif #endif - state = COM_WSS_STARTED; } void WorkScheduler::finish() { #if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE #ifdef COM_OPENCL_ENABLED if (openclActive) { - while (BLI_thread_queue_size(gpuqueue) + BLI_thread_queue_size(cpuqueue) > 0) { - PIL_sleep_ms(10); - } + BLI_thread_queue_wait_finish(gpuqueue); + BLI_thread_queue_wait_finish(cpuqueue); } else { - while (BLI_thread_queue_size(cpuqueue) > 0) { - PIL_sleep_ms(10); - } + BLI_thread_queue_wait_finish(cpuqueue); } #else - while (BLI_thread_queue_size(cpuqueue) > 0) { - PIL_sleep_ms(10); - } + BLI_thread_queue_wait_finish(cpuqueue); #endif #endif } void WorkScheduler::stop() { - state = COM_WSS_STOPPING; #if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE + BLI_thread_queue_nowait(cpuqueue); BLI_end_threads(&cputhreads); BLI_thread_queue_free(cpuqueue); cpuqueue = NULL; #ifdef COM_OPENCL_ENABLED if (openclActive) { + BLI_thread_queue_nowait(gpuqueue); BLI_end_threads(&gputhreads); BLI_thread_queue_free(gpuqueue); gpuqueue = NULL; } #endif #endif - state = COM_WSS_STOPPED; } bool WorkScheduler::hasGPUDevices() @@ -218,8 +194,6 @@ extern void clContextError(const char *errinfo, const void *private_info, size_t void WorkScheduler::initialize() { - state = COM_WSS_UNKNOWN; - #if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE int numberOfCPUThreads = BLI_system_thread_count(); @@ -260,7 +234,7 @@ void WorkScheduler::initialize() if (totalNumberOfDevices > 0) { context = clCreateContext(NULL, totalNumberOfDevices, cldevices, clContextError, NULL, &error); if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } - program = clCreateProgramWithSource(context, 1, &sourcecode, 0, &error); + program = clCreateProgramWithSource(context, 1, &clkernelstoh_COM_OpenCLKernels_cl, 0, &error); error = clBuildProgram(program, totalNumberOfDevices, cldevices, 0, 0, 0); if (error != CL_SUCCESS) { cl_int error2; @@ -298,8 +272,6 @@ void WorkScheduler::initialize() } #endif #endif - - state = COM_WSS_INITIALIZED; } void WorkScheduler::deinitialize() @@ -329,5 +301,4 @@ void WorkScheduler::deinitialize() } #endif #endif - state = COM_WSS_DEINITIALIZED; } diff --git a/source/blender/compositor/intern/COM_WorkScheduler.h b/source/blender/compositor/intern/COM_WorkScheduler.h index 0de1763749e..b03b514d139 100644 --- a/source/blender/compositor/intern/COM_WorkScheduler.h +++ b/source/blender/compositor/intern/COM_WorkScheduler.h @@ -31,19 +31,6 @@ extern "C" { #include "COM_defines.h" #include "COM_Device.h" -// STATES -/** @brief states of the WorkScheduler - * @ingroup execution - */ -typedef enum WorkSchedulerState { - COM_WSS_UNKNOWN = -1, - COM_WSS_INITIALIZED = 0, - COM_WSS_STARTED = 1, - COM_WSS_STOPPING = 2, - COM_WSS_STOPPED = 3, - COM_WSS_DEINITIALIZED = 4 -} WorkSchedulerState; - /** @brief the workscheduler * @ingroup execution */ diff --git a/source/blender/compositor/nodes/COM_BlurNode.cpp b/source/blender/compositor/nodes/COM_BlurNode.cpp index b209e36dd48..d9cf2c2fef0 100644 --- a/source/blender/compositor/nodes/COM_BlurNode.cpp +++ b/source/blender/compositor/nodes/COM_BlurNode.cpp @@ -55,7 +55,7 @@ void BlurNode::convertToOperations(ExecutionSystem *graph, CompositorContext * c this->getInputSocket(1)->relinkConnections(operationfgb->getInputSocket(1), 1, graph); this->getOutputSocket(0)->relinkConnections(operationfgb->getOutputSocket(0)); graph->addOperation(operationfgb); - addPreviewOperation(graph, operationfgb->getOutputSocket(), 5); + addPreviewOperation(graph, operationfgb->getOutputSocket()); } else if (!data->bokeh) { GaussianXBlurOperation *operationx = new GaussianXBlurOperation(); @@ -71,7 +71,7 @@ void BlurNode::convertToOperations(ExecutionSystem *graph, CompositorContext * c graph->addOperation(operationy); addLink(graph, operationx->getOutputSocket(), operationy->getInputSocket(0)); addLink(graph, operationx->getInputSocket(1)->getConnection()->getFromSocket(), operationy->getInputSocket(1)); - addPreviewOperation(graph, operationy->getOutputSocket(), 5); + addPreviewOperation(graph, operationy->getOutputSocket()); if (!connectedSizeSocket) { operationx->setSize(size); @@ -86,7 +86,7 @@ void BlurNode::convertToOperations(ExecutionSystem *graph, CompositorContext * c operation->setQuality(quality); graph->addOperation(operation); this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket()); - addPreviewOperation(graph, operation->getOutputSocket(), 5); + addPreviewOperation(graph, operation->getOutputSocket()); if (!connectedSizeSocket) { operation->setSize(size); diff --git a/source/blender/compositor/nodes/COM_BokehBlurNode.cpp b/source/blender/compositor/nodes/COM_BokehBlurNode.cpp index d6f4f58fe70..abae1b88890 100644 --- a/source/blender/compositor/nodes/COM_BokehBlurNode.cpp +++ b/source/blender/compositor/nodes/COM_BokehBlurNode.cpp @@ -41,9 +41,9 @@ void BokehBlurNode::convertToOperations(ExecutionSystem *graph, CompositorContex if (this->getInputSocket(2)->isConnected()) { VariableSizeBokehBlurOperation *operation = new VariableSizeBokehBlurOperation(); ConvertDepthToRadiusOperation *converter = new ConvertDepthToRadiusOperation(); - converter->setfStop(4.0f); + converter->setfStop(this->getbNode()->custom3); converter->setCameraObject(camob); - operation->setMaxBlur(16); + operation->setMaxBlur((int)this->getbNode()->custom4); operation->setQuality(context->getQuality()); this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph); this->getInputSocket(1)->relinkConnections(operation->getInputSocket(1), 1, graph); diff --git a/source/blender/compositor/nodes/COM_BokehImageNode.cpp b/source/blender/compositor/nodes/COM_BokehImageNode.cpp index 35511d213f5..f498fa11e30 100644 --- a/source/blender/compositor/nodes/COM_BokehImageNode.cpp +++ b/source/blender/compositor/nodes/COM_BokehImageNode.cpp @@ -35,5 +35,5 @@ void BokehImageNode::convertToOperations(ExecutionSystem *graph, CompositorConte this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket(0)); graph->addOperation(operation); operation->setData((NodeBokehImage*)this->getbNode()->storage); - addPreviewOperation(graph, operation->getOutputSocket(0), 9); + addPreviewOperation(graph, operation->getOutputSocket(0)); } diff --git a/source/blender/compositor/nodes/COM_ChannelMatteNode.cpp b/source/blender/compositor/nodes/COM_ChannelMatteNode.cpp index dbe5b9936dc..f1d5b8d39cc 100644 --- a/source/blender/compositor/nodes/COM_ChannelMatteNode.cpp +++ b/source/blender/compositor/nodes/COM_ChannelMatteNode.cpp @@ -82,7 +82,7 @@ void ChannelMatteNode::convertToOperations(ExecutionSystem *graph, CompositorCon graph->addOperation(operationAlpha); addLink(graph, operation->getOutputSocket(), operationAlpha->getInputSocket(1)); - addPreviewOperation(graph, operationAlpha->getOutputSocket(), 9); + addPreviewOperation(graph, operationAlpha->getOutputSocket()); if (outputSocketImage->isConnected()) { outputSocketImage->relinkConnections(operationAlpha->getOutputSocket()); diff --git a/source/blender/compositor/nodes/COM_ChromaMatteNode.cpp b/source/blender/compositor/nodes/COM_ChromaMatteNode.cpp index dd3b3855e3f..82059ed8493 100644 --- a/source/blender/compositor/nodes/COM_ChromaMatteNode.cpp +++ b/source/blender/compositor/nodes/COM_ChromaMatteNode.cpp @@ -63,7 +63,7 @@ void ChromaMatteNode::convertToOperations(ExecutionSystem *graph, CompositorCont addLink(graph, operation->getOutputSocket(), operationAlpha->getInputSocket(1)); graph->addOperation(operationAlpha); - addPreviewOperation(graph, operationAlpha->getOutputSocket(), 9); + addPreviewOperation(graph, operationAlpha->getOutputSocket()); if (outputSocketImage->isConnected()) { outputSocketImage->relinkConnections(operationAlpha->getOutputSocket()); diff --git a/source/blender/compositor/nodes/COM_ColorCurveNode.cpp b/source/blender/compositor/nodes/COM_ColorCurveNode.cpp index d7cde21a984..0d331ed9b05 100644 --- a/source/blender/compositor/nodes/COM_ColorCurveNode.cpp +++ b/source/blender/compositor/nodes/COM_ColorCurveNode.cpp @@ -31,16 +31,32 @@ ColorCurveNode::ColorCurveNode(bNode *editorNode): Node(editorNode) void ColorCurveNode::convertToOperations(ExecutionSystem *graph, CompositorContext * context) { - ColorCurveOperation *operation = new ColorCurveOperation(); - - this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph); - this->getInputSocket(1)->relinkConnections(operation->getInputSocket(1), 1, graph); - this->getInputSocket(2)->relinkConnections(operation->getInputSocket(2), 2, graph); - this->getInputSocket(3)->relinkConnections(operation->getInputSocket(3), 3, graph); - - this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket()); - - operation->setCurveMapping((CurveMapping*)this->getbNode()->storage); - - graph->addOperation(operation); + if (this->getInputSocket(2)->isConnected() || this->getInputSocket(3)->isConnected()) { + ColorCurveOperation *operation = new ColorCurveOperation(); + + this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph); + this->getInputSocket(1)->relinkConnections(operation->getInputSocket(1), 1, graph); + this->getInputSocket(2)->relinkConnections(operation->getInputSocket(2), 2, graph); + this->getInputSocket(3)->relinkConnections(operation->getInputSocket(3), 3, graph); + + this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket()); + + operation->setCurveMapping((CurveMapping*)this->getbNode()->storage); + + graph->addOperation(operation); + } else { + ConstantLevelColorCurveOperation *operation = new ConstantLevelColorCurveOperation(); + + this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph); + this->getInputSocket(1)->relinkConnections(operation->getInputSocket(1), 1, graph); + bNodeSocketValueRGBA *val = (bNodeSocketValueRGBA*)this->getInputSocket(2)->getbNodeSocket()->default_value; + operation->setBlackLevel(val->value); + val = (bNodeSocketValueRGBA*)this->getInputSocket(3)->getbNodeSocket()->default_value; + operation->setWhiteLevel(val->value); + this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket()); + + operation->setCurveMapping((CurveMapping*)this->getbNode()->storage); + + graph->addOperation(operation); + } } diff --git a/source/blender/compositor/nodes/COM_ColorMatteNode.cpp b/source/blender/compositor/nodes/COM_ColorMatteNode.cpp index 860d1a01194..ad117e1ca2c 100644 --- a/source/blender/compositor/nodes/COM_ColorMatteNode.cpp +++ b/source/blender/compositor/nodes/COM_ColorMatteNode.cpp @@ -60,7 +60,7 @@ void ColorMatteNode::convertToOperations(ExecutionSystem *graph, CompositorConte addLink(graph, operationRGBToHSV_Image->getInputSocket(0)->getConnection()->getFromSocket(), operationAlpha->getInputSocket(0)); addLink(graph, operation->getOutputSocket(), operationAlpha->getInputSocket(1)); graph->addOperation(operationAlpha); - addPreviewOperation(graph, operationAlpha->getOutputSocket(), 9); + addPreviewOperation(graph, operationAlpha->getOutputSocket()); if (outputSocketImage->isConnected()) { outputSocketImage->relinkConnections(operationAlpha->getOutputSocket()); diff --git a/source/blender/compositor/nodes/COM_CompositorNode.cpp b/source/blender/compositor/nodes/COM_CompositorNode.cpp index 57821e7fe27..e2cc34bb6ce 100644 --- a/source/blender/compositor/nodes/COM_CompositorNode.cpp +++ b/source/blender/compositor/nodes/COM_CompositorNode.cpp @@ -39,6 +39,6 @@ void CompositorNode::convertToOperations(ExecutionSystem *graph, CompositorConte imageSocket->relinkConnections(colourAlphaProg->getInputSocket(0)); alphaSocket->relinkConnections(colourAlphaProg->getInputSocket(1)); graph->addOperation(colourAlphaProg); - addPreviewOperation(graph, colourAlphaProg->getInputSocket(0), 5); + addPreviewOperation(graph, colourAlphaProg->getInputSocket(0)); } } diff --git a/source/blender/compositor/nodes/COM_DifferenceMatteNode.cpp b/source/blender/compositor/nodes/COM_DifferenceMatteNode.cpp index c26fb4e5c5d..596fefff77c 100644 --- a/source/blender/compositor/nodes/COM_DifferenceMatteNode.cpp +++ b/source/blender/compositor/nodes/COM_DifferenceMatteNode.cpp @@ -49,5 +49,5 @@ void DifferenceMatteNode::convertToOperations(ExecutionSystem *graph, Compositor addLink(graph, operationSet->getOutputSocket(), operation->getInputSocket(1)); outputSocketImage->relinkConnections(operation->getOutputSocket()); graph->addOperation(operation); - addPreviewOperation(graph, operation->getOutputSocket(), 5); + addPreviewOperation(graph, operation->getOutputSocket()); } diff --git a/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp b/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp index d7b4e481ec2..20a55ae195c 100644 --- a/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp +++ b/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp @@ -52,7 +52,7 @@ void DistanceMatteNode::convertToOperations(ExecutionSystem *graph, CompositorCo addLink(graph, operation->getOutputSocket(), operationAlpha->getInputSocket(1)); graph->addOperation(operationAlpha); - addPreviewOperation(graph, operationAlpha->getOutputSocket(), 9); + addPreviewOperation(graph, operationAlpha->getOutputSocket()); if (outputSocketImage->isConnected()) { outputSocketImage->relinkConnections(operationAlpha->getOutputSocket()); diff --git a/source/blender/compositor/nodes/COM_FilterNode.cpp b/source/blender/compositor/nodes/COM_FilterNode.cpp index bdba69dc47d..7700bceb4ab 100644 --- a/source/blender/compositor/nodes/COM_FilterNode.cpp +++ b/source/blender/compositor/nodes/COM_FilterNode.cpp @@ -76,7 +76,7 @@ void FilterNode::convertToOperations(ExecutionSystem *graph, CompositorContext * inputImageSocket->relinkConnections(operation->getInputSocket(0), 1, graph); inputSocket->relinkConnections(operation->getInputSocket(1), 0, graph); outputSocket->relinkConnections(operation->getOutputSocket()); - addPreviewOperation(graph, operation->getOutputSocket(0), 5); + addPreviewOperation(graph, operation->getOutputSocket(0)); graph->addOperation(operation); } diff --git a/source/blender/compositor/nodes/COM_GroupNode.cpp b/source/blender/compositor/nodes/COM_GroupNode.cpp index 076d4f1501a..ec06a3acd7e 100644 --- a/source/blender/compositor/nodes/COM_GroupNode.cpp +++ b/source/blender/compositor/nodes/COM_GroupNode.cpp @@ -45,23 +45,16 @@ void GroupNode::ungroup(ExecutionSystem &system) InputSocket * inputSocket = inputsockets[index]; bNodeSocket *editorInput = inputSocket->getbNodeSocket(); if (editorInput->groupsock) { - if (inputSocket->isConnected()) { - SocketProxyNode * proxy = new SocketProxyNode(this->getbNode(), editorInput, editorInput->groupsock); - inputSocket->relinkConnections(proxy->getInputSocket(0), index, &system); - ExecutionSystemHelper::addNode(system.getNodes(), proxy); - } - else { - OutputSocketProxyNode * proxy = new OutputSocketProxyNode(this->getbNode(), editorInput, editorInput->groupsock); - inputSocket->relinkConnections(proxy->getInputSocket(0), index, &system); - ExecutionSystemHelper::addNode(system.getNodes(), proxy); - } + SocketProxyNode * proxy = new SocketProxyNode(this->getbNode(), editorInput, editorInput->groupsock); + inputSocket->relinkConnections(proxy->getInputSocket(0), index, &system); + ExecutionSystemHelper::addNode(system.getNodes(), proxy); } } for (index = 0 ; index < outputsockets.size();index ++) { OutputSocket * outputSocket = outputsockets[index]; bNodeSocket *editorOutput = outputSocket->getbNodeSocket(); - if (outputSocket->isConnected() && editorOutput->groupsock) { + if (editorOutput->groupsock) { SocketProxyNode * proxy = new SocketProxyNode(this->getbNode(), editorOutput->groupsock, editorOutput); outputSocket->relinkConnections(proxy->getOutputSocket(0)); ExecutionSystemHelper::addNode(system.getNodes(), proxy); diff --git a/source/blender/compositor/nodes/COM_ImageNode.cpp b/source/blender/compositor/nodes/COM_ImageNode.cpp index 7f14b068136..cfd530173a9 100644 --- a/source/blender/compositor/nodes/COM_ImageNode.cpp +++ b/source/blender/compositor/nodes/COM_ImageNode.cpp @@ -105,7 +105,7 @@ void ImageNode::convertToOperations(ExecutionSystem *graph, CompositorContext * break; } if (index == 0 && operation) { - addPreviewOperation(graph, operation->getOutputSocket(), 9); + addPreviewOperation(graph, operation->getOutputSocket()); } } } @@ -123,7 +123,7 @@ void ImageNode::convertToOperations(ExecutionSystem *graph, CompositorContext * operation->setImageUser(imageuser); operation->setFramenumber(framenumber); graph->addOperation(operation); - addPreviewOperation(graph, operation->getOutputSocket(), 9); + addPreviewOperation(graph, operation->getOutputSocket()); } if (numberOfOutputs > 1) { diff --git a/source/blender/compositor/nodes/COM_LuminanceMatteNode.cpp b/source/blender/compositor/nodes/COM_LuminanceMatteNode.cpp index eb78657f3c4..37976216106 100644 --- a/source/blender/compositor/nodes/COM_LuminanceMatteNode.cpp +++ b/source/blender/compositor/nodes/COM_LuminanceMatteNode.cpp @@ -53,7 +53,7 @@ void LuminanceMatteNode::convertToOperations(ExecutionSystem *graph, CompositorC addLink(graph, rgbToYUV->getInputSocket(0)->getConnection()->getFromSocket(), operation->getInputSocket(0)); addLink(graph, operationSet->getOutputSocket(), operation->getInputSocket(1)); graph->addOperation(operation); - addPreviewOperation(graph, operation->getOutputSocket(), 9); + addPreviewOperation(graph, operation->getOutputSocket()); if (outputSocketImage->isConnected()) { outputSocketImage->relinkConnections(operation->getOutputSocket()); diff --git a/source/blender/compositor/nodes/COM_MaskNode.cpp b/source/blender/compositor/nodes/COM_MaskNode.cpp new file mode 100644 index 00000000000..991c3f75e05 --- /dev/null +++ b/source/blender/compositor/nodes/COM_MaskNode.cpp @@ -0,0 +1,65 @@ +/* + * Copyright 2012, Blender Foundation. + * + * 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. + * + * Contributor: + * Jeroen Bakker + * Monique Dewanchand + * Sergey Sharybin + */ + +#include "COM_MaskNode.h" +#include "COM_ExecutionSystem.h" +#include "COM_MaskOperation.h" + +extern "C" { + #include "DNA_mask_types.h" +} + +MaskNode::MaskNode(bNode *editorNode): Node(editorNode) +{ +} + +void MaskNode::convertToOperations(ExecutionSystem *graph, CompositorContext * context) +{ + const RenderData *data = &context->getScene()->r; + + InputSocket *inputImage = this->getInputSocket(0); + OutputSocket *outputMask = this->getOutputSocket(0); + + bNode *editorNode = this->getbNode(); + Mask *mask = (Mask *)editorNode->id; + + // always connect the output image + MaskOperation *operation = new MaskOperation(); + + if (inputImage->isConnected()) { + inputImage->relinkConnections(operation->getInputSocket(0), 0, graph); + } + else { + operation->setMaskWidth(data->xsch * data->size / 100.0f); + operation->setMaskHeight(data->ysch * data->size / 100.0f); + } + + if (outputMask->isConnected()) { + outputMask->relinkConnections(operation->getOutputSocket()); + } + + operation->setMask(mask); + operation->setFramenumber(context->getFramenumber()); + + graph->addOperation(operation); +} diff --git a/source/blender/compositor/nodes/COM_MaskNode.h b/source/blender/compositor/nodes/COM_MaskNode.h new file mode 100644 index 00000000000..9d2ea1889d9 --- /dev/null +++ b/source/blender/compositor/nodes/COM_MaskNode.h @@ -0,0 +1,38 @@ +/* + * Copyright 2012, Blender Foundation. + * + * 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. + * + * Contributor: + * Jeroen Bakker + * Monique Dewanchand + * Sergey Sharybin + */ + +#include "COM_Node.h" +#include "DNA_node_types.h" + +/** + * @brief MaskNode + * @ingroup Node + */ +class MaskNode : public Node { + + +public: + MaskNode(bNode *editorNode); + void convertToOperations(ExecutionSystem *graph, CompositorContext *context); + +}; diff --git a/source/blender/compositor/nodes/COM_MixNode.cpp b/source/blender/compositor/nodes/COM_MixNode.cpp index 86ca5ebc237..42e32a4e55e 100644 --- a/source/blender/compositor/nodes/COM_MixNode.cpp +++ b/source/blender/compositor/nodes/COM_MixNode.cpp @@ -125,7 +125,7 @@ void MixNode::convertToOperations(ExecutionSystem *graph, CompositorContext * co color1Socket->relinkConnections(convertProg->getInputSocket(1), 1, graph); color2Socket->relinkConnections(convertProg->getInputSocket(2), 2, graph); outputSocket->relinkConnections(convertProg->getOutputSocket(0)); - addPreviewOperation(graph, convertProg->getOutputSocket(0), 5); + addPreviewOperation(graph, convertProg->getOutputSocket(0)); convertProg->getInputSocket(2)->setResizeMode(color2Socket->getResizeMode()); diff --git a/source/blender/compositor/nodes/COM_MovieClipNode.cpp b/source/blender/compositor/nodes/COM_MovieClipNode.cpp index 75831130936..eac581dc903 100644 --- a/source/blender/compositor/nodes/COM_MovieClipNode.cpp +++ b/source/blender/compositor/nodes/COM_MovieClipNode.cpp @@ -62,7 +62,7 @@ void MovieClipNode::convertToOperations(ExecutionSystem *graph, CompositorContex converter->setFromColorProfile(IB_PROFILE_LINEAR_RGB); converter->setToColorProfile(IB_PROFILE_SRGB); addLink(graph, operation->getOutputSocket(), converter->getInputSocket(0)); - addPreviewOperation(graph, converter->getOutputSocket(), 9); + addPreviewOperation(graph, converter->getOutputSocket()); if (outputMovieClip->isConnected()) { outputMovieClip->relinkConnections(converter->getOutputSocket()); } @@ -72,7 +72,7 @@ void MovieClipNode::convertToOperations(ExecutionSystem *graph, CompositorContex } } else { - addPreviewOperation(graph, operation->getOutputSocket(), 9); + addPreviewOperation(graph, operation->getOutputSocket()); if (outputMovieClip->isConnected()) { outputMovieClip->relinkConnections(operation->getOutputSocket()); } diff --git a/source/blender/compositor/nodes/COM_OutputFileNode.cpp b/source/blender/compositor/nodes/COM_OutputFileNode.cpp index cc060e9f7cd..ca18ea5fbf7 100644 --- a/source/blender/compositor/nodes/COM_OutputFileNode.cpp +++ b/source/blender/compositor/nodes/COM_OutputFileNode.cpp @@ -59,7 +59,7 @@ void OutputFileNode::convertToOperations(ExecutionSystem *graph, CompositorConte input->relinkConnections(outputOperation->getInputSocket(i)); } } - if (hasConnections) addPreviewOperation(graph, outputOperation->getInputSocket(0), 5); + if (hasConnections) addPreviewOperation(graph, outputOperation->getInputSocket(0)); graph->addOperation(outputOperation); } @@ -81,7 +81,7 @@ void OutputFileNode::convertToOperations(ExecutionSystem *graph, CompositorConte input->relinkConnections(outputOperation->getInputSocket(0)); graph->addOperation(outputOperation); if (!previewAdded) { - addPreviewOperation(graph, outputOperation->getInputSocket(0), 5); + addPreviewOperation(graph, outputOperation->getInputSocket(0)); previewAdded = true; } } diff --git a/source/blender/compositor/nodes/COM_RenderLayersNode.cpp b/source/blender/compositor/nodes/COM_RenderLayersNode.cpp index 4e99db090e1..8216205b925 100644 --- a/source/blender/compositor/nodes/COM_RenderLayersNode.cpp +++ b/source/blender/compositor/nodes/COM_RenderLayersNode.cpp @@ -63,7 +63,7 @@ void RenderLayersNode::testSocketConnection(ExecutionSystem *system, int outputS outputSocket->relinkConnections(operation->getOutputSocket()); system->addOperation(operation); if (outputSocketNumber == 0) { // only do for image socket if connected - addPreviewOperation(system, operation->getOutputSocket(), 9); + addPreviewOperation(system, operation->getOutputSocket()); } } else { @@ -71,7 +71,7 @@ void RenderLayersNode::testSocketConnection(ExecutionSystem *system, int outputS system->addOperation(operation); operation->setScene(scene); operation->setLayerId(layerId); - addPreviewOperation(system, operation->getOutputSocket(), 9); + addPreviewOperation(system, operation->getOutputSocket()); } else { delete operation; diff --git a/source/blender/compositor/nodes/COM_SocketProxyNode.cpp b/source/blender/compositor/nodes/COM_SocketProxyNode.cpp index 42dd49bd1da..fbb25afe266 100644 --- a/source/blender/compositor/nodes/COM_SocketProxyNode.cpp +++ b/source/blender/compositor/nodes/COM_SocketProxyNode.cpp @@ -46,50 +46,48 @@ SocketProxyNode::SocketProxyNode(bNode *editorNode, bNodeSocket *editorInput, bN void SocketProxyNode::convertToOperations(ExecutionSystem *graph, CompositorContext * context) { OutputSocket * outputsocket = this->getOutputSocket(0); - if (outputsocket->isConnected()) { - SocketProxyOperation *operation = new SocketProxyOperation(); - this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0)); - this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket(0)); - graph->addOperation(operation); - } -} - -void OutputSocketProxyNode::convertToOperations(ExecutionSystem *graph, CompositorContext * context) -{ - OutputSocket * outputsocket = this->getOutputSocket(0); InputSocket * inputsocket = this->getInputSocket(0); if (outputsocket->isConnected()) { - switch (outputsocket->getActualDataType()) { - case COM_DT_VALUE: - { - SetValueOperation *operation = new SetValueOperation(); - bNodeSocketValueFloat *dval = (bNodeSocketValueFloat*)inputsocket->getbNodeSocket()->default_value; - operation->setValue(dval->value); - this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket(0)); - graph->addOperation(operation); - break; - } - case COM_DT_COLOR: - { - SetColorOperation *operation = new SetColorOperation(); - bNodeSocketValueRGBA *dval = (bNodeSocketValueRGBA*)inputsocket->getbNodeSocket()->default_value; - operation->setChannels(dval->value); - this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket(0)); - graph->addOperation(operation); - break; - } - case COM_DT_VECTOR: - { - SetVectorOperation *operation = new SetVectorOperation(); - bNodeSocketValueVector *dval = (bNodeSocketValueVector*)inputsocket->getbNodeSocket()->default_value; - operation->setVector(dval->value); - this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket(0)); + if (inputsocket->isConnected()) { + SocketProxyOperation *operation = new SocketProxyOperation(); + inputsocket->relinkConnections(operation->getInputSocket(0)); + outputsocket->relinkConnections(operation->getOutputSocket(0)); graph->addOperation(operation); - break; } - /* quiet warnings */ - case COM_DT_UNKNOWN: - break; + else { + /* If input is not connected, add a constant value operation instead */ + switch (outputsocket->getActualDataType()) { + case COM_DT_VALUE: + { + SetValueOperation *operation = new SetValueOperation(); + bNodeSocketValueFloat *dval = (bNodeSocketValueFloat*)inputsocket->getbNodeSocket()->default_value; + operation->setValue(dval->value); + outputsocket->relinkConnections(operation->getOutputSocket(0)); + graph->addOperation(operation); + break; + } + case COM_DT_COLOR: + { + SetColorOperation *operation = new SetColorOperation(); + bNodeSocketValueRGBA *dval = (bNodeSocketValueRGBA*)inputsocket->getbNodeSocket()->default_value; + operation->setChannels(dval->value); + outputsocket->relinkConnections(operation->getOutputSocket(0)); + graph->addOperation(operation); + break; + } + case COM_DT_VECTOR: + { + SetVectorOperation *operation = new SetVectorOperation(); + bNodeSocketValueVector *dval = (bNodeSocketValueVector*)inputsocket->getbNodeSocket()->default_value; + operation->setVector(dval->value); + outputsocket->relinkConnections(operation->getOutputSocket(0)); + graph->addOperation(operation); + break; + } + /* quiet warnings */ + case COM_DT_UNKNOWN: + break; + } } } } diff --git a/source/blender/compositor/nodes/COM_SocketProxyNode.h b/source/blender/compositor/nodes/COM_SocketProxyNode.h index 1b5ee699211..b73ca24a45e 100644 --- a/source/blender/compositor/nodes/COM_SocketProxyNode.h +++ b/source/blender/compositor/nodes/COM_SocketProxyNode.h @@ -37,10 +37,4 @@ public: virtual bool isProxyNode() const { return true; } }; -class OutputSocketProxyNode: public SocketProxyNode { -public: - OutputSocketProxyNode(bNode *editorNode, bNodeSocket *editorInput, bNodeSocket *editorOutput): SocketProxyNode(editorNode, editorInput, editorOutput) {} - void convertToOperations(ExecutionSystem *graph, CompositorContext * context); -}; - #endif diff --git a/source/blender/compositor/nodes/COM_SplitViewerNode.cpp b/source/blender/compositor/nodes/COM_SplitViewerNode.cpp index 9f9efbd8fe5..bf434c164c0 100644 --- a/source/blender/compositor/nodes/COM_SplitViewerNode.cpp +++ b/source/blender/compositor/nodes/COM_SplitViewerNode.cpp @@ -45,7 +45,7 @@ void SplitViewerNode::convertToOperations(ExecutionSystem *graph, CompositorCont splitViewerOperation->setXSplit(!this->getbNode()->custom2); image1Socket->relinkConnections(splitViewerOperation->getInputSocket(0), 0, graph); image2Socket->relinkConnections(splitViewerOperation->getInputSocket(1), 1, graph); - addPreviewOperation(graph, splitViewerOperation->getInputSocket(0), 0); + addPreviewOperation(graph, splitViewerOperation->getInputSocket(0)); graph->addOperation(splitViewerOperation); } } diff --git a/source/blender/compositor/nodes/COM_TextureNode.cpp b/source/blender/compositor/nodes/COM_TextureNode.cpp index be8bb623f4c..fe8a8e2250e 100644 --- a/source/blender/compositor/nodes/COM_TextureNode.cpp +++ b/source/blender/compositor/nodes/COM_TextureNode.cpp @@ -39,7 +39,7 @@ void TextureNode::convertToOperations(ExecutionSystem *system, CompositorContext operation->setTexture(texture); operation->setScene(context->getScene()); system->addOperation(operation); - addPreviewOperation(system, operation->getOutputSocket(), 9); + addPreviewOperation(system, operation->getOutputSocket()); if (this->getOutputSocket(0)->isConnected()) { TextureAlphaOperation *alphaOperation = new TextureAlphaOperation(); diff --git a/source/blender/compositor/nodes/COM_ViewerNode.cpp b/source/blender/compositor/nodes/COM_ViewerNode.cpp index 3282929af52..f5dab52d021 100644 --- a/source/blender/compositor/nodes/COM_ViewerNode.cpp +++ b/source/blender/compositor/nodes/COM_ViewerNode.cpp @@ -36,8 +36,8 @@ void ViewerNode::convertToOperations(ExecutionSystem *graph, CompositorContext * InputSocket *alphaSocket = this->getInputSocket(1); Image *image = (Image*)this->getbNode()->id; ImageUser * imageUser = (ImageUser*) this->getbNode()->storage; + bNode *editorNode = this->getbNode(); if (imageSocket->isConnected()) { - bNode *editorNode = this->getbNode(); ViewerOperation *viewerOperation = new ViewerOperation(); viewerOperation->setColorManagement(context->getScene()->r.color_mgt_flag & R_COLOR_MANAGEMENT); viewerOperation->setColorPredivide(context->getScene()->r.color_mgt_flag & R_COLOR_MANAGEMENT_PREDIVIDE); @@ -51,6 +51,6 @@ void ViewerNode::convertToOperations(ExecutionSystem *graph, CompositorContext * imageSocket->relinkConnections(viewerOperation->getInputSocket(0), 0, graph); alphaSocket->relinkConnections(viewerOperation->getInputSocket(1)); graph->addOperation(viewerOperation); - addPreviewOperation(graph, viewerOperation->getInputSocket(0), 0); + addPreviewOperation(graph, viewerOperation->getInputSocket(0)); } } diff --git a/source/blender/compositor/operations/COM_BlurBaseOperation.cpp b/source/blender/compositor/operations/COM_BlurBaseOperation.cpp index babea459d6a..2280ee3a435 100644 --- a/source/blender/compositor/operations/COM_BlurBaseOperation.cpp +++ b/source/blender/compositor/operations/COM_BlurBaseOperation.cpp @@ -101,7 +101,10 @@ void BlurBaseOperation::deinitExecution() void BlurBaseOperation::updateSize(MemoryBuffer **memoryBuffers) { - float result[4]; - this->getInputSocketReader(1)->read(result, 0, 0, COM_PS_NEAREST, memoryBuffers); - this->size = result[0]; + if (!this->sizeavailable) { + float result[4]; + this->getInputSocketReader(1)->read(result, 0, 0, COM_PS_NEAREST, memoryBuffers); + this->size = result[0]; + this->sizeavailable = true; + } } diff --git a/source/blender/compositor/operations/COM_BokehBlurOperation.cpp b/source/blender/compositor/operations/COM_BokehBlurOperation.cpp index 1050fc57194..71a87dce2a7 100644 --- a/source/blender/compositor/operations/COM_BokehBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_BokehBlurOperation.cpp @@ -34,8 +34,9 @@ BokehBlurOperation::BokehBlurOperation() : NodeOperation() this->addInputSocket(COM_DT_VALUE); this->addOutputSocket(COM_DT_COLOR); this->setComplex(true); + this->setOpenCL(true); - this->size = .01; + this->size = 1.0f; this->inputProgram = NULL; this->inputBokehProgram = NULL; @@ -90,7 +91,7 @@ void BokehBlurOperation::executePixel(float *color, int x, int y, MemoryBuffer * int bufferwidth = inputBuffer->getWidth(); int bufferstartx = inputBuffer->getRect()->xmin; int bufferstarty = inputBuffer->getRect()->ymin; - int pixelSize = this->size*this->getWidth(); + int pixelSize = this->size*this->getWidth()/100.0f; int miny = y - pixelSize; int maxy = y + pixelSize; @@ -120,9 +121,9 @@ void BokehBlurOperation::executePixel(float *color, int x, int y, MemoryBuffer * bufferindex +=offsetadd; } } - color[0] = tempColor[0]*(1.0/overallmultiplyerr); - color[1] = tempColor[1]*(1.0/overallmultiplyerg); - color[2] = tempColor[2]*(1.0/overallmultiplyerb); + color[0] = tempColor[0] * (1.0f / overallmultiplyerr); + color[1] = tempColor[1] * (1.0f / overallmultiplyerg); + color[2] = tempColor[2] * (1.0f / overallmultiplyerb); color[3] = 1.0f; } else { @@ -142,10 +143,10 @@ bool BokehBlurOperation::determineDependingAreaOfInterest(rcti *input, ReadBuffe rcti newInput; rcti bokehInput; - newInput.xmax = input->xmax + (size*this->getWidth()); - newInput.xmin = input->xmin - (size*this->getWidth()); - newInput.ymax = input->ymax + (size*this->getWidth()); - newInput.ymin = input->ymin - (size*this->getWidth()); + newInput.xmax = input->xmax + (size*this->getWidth()/100.0f); + newInput.xmin = input->xmin - (size*this->getWidth()/100.0f); + newInput.ymax = input->ymax + (size*this->getWidth()/100.0f); + newInput.ymin = input->ymin - (size*this->getWidth()/100.0f); NodeOperation *operation = getInputOperation(1); bokehInput.xmax = operation->getWidth(); @@ -165,3 +166,27 @@ bool BokehBlurOperation::determineDependingAreaOfInterest(rcti *input, ReadBuffe } return false; } + +static cl_kernel kernel = 0; +void BokehBlurOperation::executeOpenCL(cl_context context, cl_program program, cl_command_queue queue, + MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, + MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, + list<cl_kernel> *clKernelsToCleanUp) +{ + if (!kernel) { + kernel = COM_clCreateKernel(program, "bokehBlurKernel", NULL); + } + cl_int radius = this->getWidth()*this->size/100.0f; + cl_int step = this->getStep(); + + COM_clAttachMemoryBufferToKernelParameter(context, kernel, 0, -1, clMemToCleanUp, inputMemoryBuffers, this->inputBoundingBoxReader); + COM_clAttachMemoryBufferToKernelParameter(context, kernel, 1, 4, clMemToCleanUp, inputMemoryBuffers, this->inputProgram); + COM_clAttachMemoryBufferToKernelParameter(context, kernel, 2, -1, clMemToCleanUp, inputMemoryBuffers, this->inputBokehProgram); + COM_clAttachOutputMemoryBufferToKernelParameter(kernel, 3, clOutputBuffer); + COM_clAttachMemoryBufferOffsetToKernelParameter(kernel, 5, outputMemoryBuffer); + clSetKernelArg(kernel, 6, sizeof(cl_int), &radius); + clSetKernelArg(kernel, 7, sizeof(cl_int), &step); + COM_clAttachSizeToKernelParameter(kernel, 8); + + COM_clEnqueueRange(queue, kernel, outputMemoryBuffer, 9); +} diff --git a/source/blender/compositor/operations/COM_BokehBlurOperation.h b/source/blender/compositor/operations/COM_BokehBlurOperation.h index ce14faa8596..3cdd995b1df 100644 --- a/source/blender/compositor/operations/COM_BokehBlurOperation.h +++ b/source/blender/compositor/operations/COM_BokehBlurOperation.h @@ -56,5 +56,7 @@ public: bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); void setSize(float size) {this->size = size;} + + void executeOpenCL(cl_context context, cl_program program, cl_command_queue queue, MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, list<cl_kernel> *clKernelsToCleanUp); }; #endif diff --git a/source/blender/compositor/operations/COM_BokehImageOperation.cpp b/source/blender/compositor/operations/COM_BokehImageOperation.cpp index 0279b9a5bdf..a0297b12961 100644 --- a/source/blender/compositor/operations/COM_BokehImageOperation.cpp +++ b/source/blender/compositor/operations/COM_BokehImageOperation.cpp @@ -34,25 +34,25 @@ void BokehImageOperation::initExecution() this->centerY = getHeight() / 2; this->center[0] = this->centerX; this->center[1] = this->centerY; - this->inverseRounding = 1.0-this->data->rounding; + this->inverseRounding = 1.0f - this->data->rounding; this->circularDistance = getWidth()/2; - this->flapRad = (M_PI*2)/this->data->flaps; - this->flapRadAdd = (this->data->angle/360.0)*M_PI*2; - while (this->flapRadAdd<0.0f) { - this->flapRadAdd+=M_PI*2; + this->flapRad = (float)(M_PI * 2) / this->data->flaps; + this->flapRadAdd = (this->data->angle / 360.0f) * (float)(M_PI * 2.0); + while (this->flapRadAdd < 0.0f) { + this->flapRadAdd += (float)(M_PI * 2.0); } - while (this->flapRadAdd>M_PI) { - this->flapRadAdd-=M_PI*2; + while (this->flapRadAdd > (float)M_PI) { + this->flapRadAdd -= (float)(M_PI * 2.0); } } void BokehImageOperation::detemineStartPointOfFlap(float r[2], int flapNumber, float distance) { - r[0] = sin(flapRad*flapNumber + flapRadAdd)*distance+centerX; - r[1] = cos(flapRad*flapNumber + flapRadAdd)*distance+centerY; + r[0] = sinf(flapRad * flapNumber + flapRadAdd) * distance + centerX; + r[1] = cosf(flapRad * flapNumber + flapRadAdd) * distance + centerY; } float BokehImageOperation::isInsideBokeh(float distance, float x, float y) { - float insideBokeh = 0.0; + float insideBokeh = 0.0f; const float deltaX = x - centerX; const float deltaY = y - centerY; float closestPoint[2]; @@ -63,7 +63,7 @@ float BokehImageOperation::isInsideBokeh(float distance, float x, float y) point[1] = y; const float distanceToCenter = len_v2v2(point, center); - const float bearing = (atan2f(deltaX, deltaY) + (M_PI*2)); + const float bearing = (atan2f(deltaX, deltaY) + (float)(M_PI * 2.0)); int flapNumber = (int)((bearing-flapRadAdd)/flapRad); detemineStartPointOfFlap(lineP1, flapNumber, distance); @@ -73,16 +73,16 @@ float BokehImageOperation::isInsideBokeh(float distance, float x, float y) const float distanceLineToCenter = len_v2v2(center, closestPoint); const float distanceRoundingToCenter = inverseRounding*distanceLineToCenter+this->data->rounding*distance; - const float catadioptricDistanceToCenter = distanceRoundingToCenter*this->data->catadioptric; - if (distanceRoundingToCenter>=distanceToCenter && catadioptricDistanceToCenter<=distanceToCenter) { - if (distanceRoundingToCenter-distanceToCenter<1.0) { + const float catadioptricDistanceToCenter = distanceRoundingToCenter * this->data->catadioptric; + if (distanceRoundingToCenter>=distanceToCenter && catadioptricDistanceToCenter <= distanceToCenter) { + if (distanceRoundingToCenter - distanceToCenter < 1.0f) { insideBokeh = (distanceRoundingToCenter-distanceToCenter); } - else if (this->data->catadioptric != 0.0 && distanceToCenter-catadioptricDistanceToCenter<1.0) { - insideBokeh = (distanceToCenter-catadioptricDistanceToCenter); + else if (this->data->catadioptric != 0.0f && distanceToCenter - catadioptricDistanceToCenter < 1.0f) { + insideBokeh = (distanceToCenter - catadioptricDistanceToCenter); } else { - insideBokeh = 1.0; + insideBokeh = 1.0f; } } return insideBokeh; @@ -90,11 +90,11 @@ float BokehImageOperation::isInsideBokeh(float distance, float x, float y) void BokehImageOperation::executePixel(float *color, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) { float shift = this->data->lensshift; - float shift2 = shift/2.0f; + float shift2 = shift / 2.0f; float distance = this->circularDistance; float insideBokehMax = isInsideBokeh(distance, x, y); - float insideBokehMed = isInsideBokeh(distance-fabs(shift2*distance), x, y); - float insideBokehMin = isInsideBokeh(distance-fabs(shift*distance), x, y); + float insideBokehMed = isInsideBokeh(distance - fabsf(shift2 * distance), x, y); + float insideBokehMin = isInsideBokeh(distance - fabsf(shift * distance), x, y); if (shift<0) { color[0] = insideBokehMax; color[1] = insideBokehMed; diff --git a/source/blender/compositor/operations/COM_BoxMaskOperation.cpp b/source/blender/compositor/operations/COM_BoxMaskOperation.cpp index 0244be4cad3..ae83115ff69 100644 --- a/source/blender/compositor/operations/COM_BoxMaskOperation.cpp +++ b/source/blender/compositor/operations/COM_BoxMaskOperation.cpp @@ -38,7 +38,7 @@ void BoxMaskOperation::initExecution() { this->inputMask = this->getInputSocketReader(0); this->inputValue = this->getInputSocketReader(1); - const double rad = DEG2RAD(this->data->rotation); + const double rad = DEG2RAD((double)this->data->rotation); this->cosine = cos(rad); this->sine = sin(rad); this->aspectRatio = ((float)this->getWidth())/this->getHeight(); @@ -60,12 +60,12 @@ void BoxMaskOperation::executePixel(float *color, float x, float y, PixelSampler this->inputMask->read(inputMask, x, y, sampler, inputBuffers); this->inputValue->read(inputValue, x, y, sampler, inputBuffers); - float halfHeight = (this->data->height)/2.0f; - float halfWidth = this->data->width/2.0f; - bool inside = rx > this->data->x-halfWidth - && rx < this->data->x+halfWidth - && ry > this->data->y-halfHeight - && ry < this->data->y+halfHeight; + float halfHeight = this->data->height / 2.0f; + float halfWidth = this->data->width / 2.0f; + bool inside = (rx > this->data->x - halfWidth && + rx < this->data->x + halfWidth && + ry > this->data->y - halfHeight && + ry < this->data->y + halfHeight); switch (this->maskType) { case CMP_NODE_MASKTYPE_ADD: diff --git a/source/blender/compositor/operations/COM_ChangeHSVOperation.cpp b/source/blender/compositor/operations/COM_ChangeHSVOperation.cpp index 9b7f87e38bc..f949b0a55fa 100644 --- a/source/blender/compositor/operations/COM_ChangeHSVOperation.cpp +++ b/source/blender/compositor/operations/COM_ChangeHSVOperation.cpp @@ -46,7 +46,8 @@ void ChangeHSVOperation::executePixel(float *outputValue, float x, float y, Pixe inputOperation->read(inputColor1, x, y, sampler, inputBuffers); outputValue[0] = inputColor1[0] + (this->hue - 0.5f); - if (outputValue[0]>1.0f) outputValue[0]-=1.0; else if (outputValue[0]<0.0) outputValue[0]+= 1.0; + if (outputValue[0] > 1.0f) outputValue[0] -= 1.0f; + else if (outputValue[0] < 0.0f) outputValue[0] += 1.0f; outputValue[1] = inputColor1[1] * this->saturation; outputValue[2] = inputColor1[2] * this->value; outputValue[3] = inputColor1[3]; diff --git a/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.cpp b/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.cpp index cc535cd95df..6fe6bde7c09 100644 --- a/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.cpp +++ b/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.cpp @@ -28,7 +28,7 @@ inline float colorbalance_cdl(float in, float offset, float power, float slope) float x = in * slope + offset; /* prevent NaN */ - CLAMP(x, 0.0, 1.0); + CLAMP(x, 0.0f, 1.0f); return powf(x, power); } diff --git a/source/blender/compositor/operations/COM_ColorCorrectionOperation.cpp b/source/blender/compositor/operations/COM_ColorCorrectionOperation.cpp index af28b776892..82a71f6a7a8 100644 --- a/source/blender/compositor/operations/COM_ColorCorrectionOperation.cpp +++ b/source/blender/compositor/operations/COM_ColorCorrectionOperation.cpp @@ -62,21 +62,21 @@ void ColorCorrectionOperation::executePixel(float *output, float x, float y, Pix float levelShadows = 0.0; float levelMidtones = 0.0; float levelHighlights = 0.0; -#define MARGIN 0.10 -#define MARGIN_DIV (0.5/MARGIN) - if (level < this->data->startmidtones-MARGIN) { +#define MARGIN 0.10f +#define MARGIN_DIV (0.5f / MARGIN) + if (level < this->data->startmidtones - MARGIN) { levelShadows = 1.0f; } - else if (level < this->data->startmidtones+MARGIN) { - levelMidtones = ((level-this->data->startmidtones)*MARGIN_DIV)+0.5; - levelShadows = 1.0 - levelMidtones; + else if (level < this->data->startmidtones + MARGIN) { + levelMidtones = ((level - this->data->startmidtones) * MARGIN_DIV) + 0.5f; + levelShadows = 1.0f - levelMidtones; } - else if (level < this->data->endmidtones-MARGIN) { + else if (level < this->data->endmidtones - MARGIN) { levelMidtones = 1.0f; } - else if (level < this->data->endmidtones+MARGIN) { - levelHighlights = ((level-this->data->endmidtones)*MARGIN_DIV)+0.5; - levelMidtones = 1.0 - levelHighlights; + else if (level < this->data->endmidtones + MARGIN) { + levelHighlights = ((level - this->data->endmidtones) * MARGIN_DIV) + 0.5f; + levelMidtones = 1.0f - levelHighlights; } else { levelHighlights = 1.0f; @@ -93,15 +93,15 @@ void ColorCorrectionOperation::executePixel(float *output, float x, float y, Pix g = inputImageColor[1]; b = inputImageColor[2]; - float invgamma = 1.0f/gamma; - float luma = 0.2126 * r + 0.7152 * g + 0.0722 * b; + float invgamma = 1.0f / gamma; + float luma = 0.2126f * r + 0.7152f * g + 0.0722f * b; r = (luma + saturation * (r - luma)); g = (luma + saturation * (g - luma)); b = (luma + saturation * (b - luma)); - r = 0.5+((r-0.5)*contrast); - g = 0.5+((g-0.5)*contrast); - b = 0.5+((b-0.5)*contrast); + r = 0.5f + ((r - 0.5f) * contrast); + g = 0.5f + ((g - 0.5f) * contrast); + b = 0.5f + ((b - 0.5f) * contrast); r = powf(r*gain+lift, invgamma); g = powf(g*gain+lift, invgamma); diff --git a/source/blender/compositor/operations/COM_ColorCurveOperation.cpp b/source/blender/compositor/operations/COM_ColorCurveOperation.cpp index 8aee54013b1..a38012271f1 100644 --- a/source/blender/compositor/operations/COM_ColorCurveOperation.cpp +++ b/source/blender/compositor/operations/COM_ColorCurveOperation.cpp @@ -28,6 +28,7 @@ extern "C" { #include "BKE_colortools.h" #ifdef __cplusplus } +#include "MEM_guardedalloc.h" #endif ColorCurveOperation::ColorCurveOperation(): CurveBaseOperation() @@ -59,6 +60,9 @@ void ColorCurveOperation::initExecution() void ColorCurveOperation::executePixel(float *color, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) { + CurveMapping* cumap = this->curveMapping; + CurveMapping* workingCopy = (CurveMapping*)MEM_dupallocN(cumap); + float black[4]; float white[4]; float fac[4]; @@ -67,26 +71,27 @@ void ColorCurveOperation::executePixel(float *color, float x, float y, PixelSamp this->inputBlackProgram->read(black, x, y, sampler, inputBuffers); this->inputWhiteProgram->read(white, x, y, sampler, inputBuffers); - curvemapping_set_black_white(this->curveMapping, black, white); + curvemapping_set_black_white(workingCopy, black, white); this->inputFacProgram->read(fac, x, y, sampler, inputBuffers); this->inputImageProgram->read(image, x, y, sampler, inputBuffers); - if (fac[0] >= 1.0) - curvemapping_evaluate_premulRGBF(this->curveMapping, color, image); - else if (*fac<=0.0) { + if (*fac >= 1.0f) + curvemapping_evaluate_premulRGBF(workingCopy, color, image); + else if (*fac <= 0.0f) { color[0] = image[0]; color[1] = image[1]; color[2] = image[2]; } else { - float col[4], mfac = 1.0f-*fac; - curvemapping_evaluate_premulRGBF(this->curveMapping, col, image); - color[0] = mfac*image[0] + *fac*col[0]; - color[1] = mfac*image[1] + *fac*col[1]; - color[2] = mfac*image[2] + *fac*col[2]; + float col[4], mfac = 1.0f - *fac; + curvemapping_evaluate_premulRGBF(workingCopy, col, image); + color[0] = mfac * image[0] + *fac * col[0]; + color[1] = mfac * image[1] + *fac * col[1]; + color[2] = mfac * image[2] + *fac * col[2]; } color[3] = image[3]; + MEM_freeN(workingCopy); } void ColorCurveOperation::deinitExecution() @@ -97,3 +102,61 @@ void ColorCurveOperation::deinitExecution() this->inputWhiteProgram = NULL; curvemapping_premultiply(this->curveMapping, 1); } + + +// Constant level curve mapping + +ConstantLevelColorCurveOperation::ConstantLevelColorCurveOperation(): CurveBaseOperation() +{ + this->addInputSocket(COM_DT_VALUE); + this->addInputSocket(COM_DT_COLOR); + this->addOutputSocket(COM_DT_COLOR); + + this->inputFacProgram = NULL; + this->inputImageProgram = NULL; + + this->setResolutionInputSocketIndex(1); +} +void ConstantLevelColorCurveOperation::initExecution() +{ + CurveBaseOperation::initExecution(); + this->inputFacProgram = this->getInputSocketReader(0); + this->inputImageProgram = this->getInputSocketReader(1); + + curvemapping_premultiply(this->curveMapping, 0); + + curvemapping_set_black_white(this->curveMapping, this->black, this->white); +} + +void ConstantLevelColorCurveOperation::executePixel(float *color, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) +{ + float fac[4]; + float image[4]; + + + this->inputFacProgram->read(fac, x, y, sampler, inputBuffers); + this->inputImageProgram->read(image, x, y, sampler, inputBuffers); + + if (*fac >= 1.0f) + curvemapping_evaluate_premulRGBF(this->curveMapping, color, image); + else if (*fac <= 0.0f) { + color[0] = image[0]; + color[1] = image[1]; + color[2] = image[2]; + } + else { + float col[4], mfac = 1.0f - *fac; + curvemapping_evaluate_premulRGBF(this->curveMapping, col, image); + color[0] = mfac * image[0] + *fac * col[0]; + color[1] = mfac * image[1] + *fac * col[1]; + color[2] = mfac * image[2] + *fac * col[2]; + } + color[3] = image[3]; +} + +void ConstantLevelColorCurveOperation::deinitExecution() +{ + this->inputFacProgram = NULL; + this->inputImageProgram = NULL; + curvemapping_premultiply(this->curveMapping, 1); +} diff --git a/source/blender/compositor/operations/COM_ColorCurveOperation.h b/source/blender/compositor/operations/COM_ColorCurveOperation.h index 15f9fd25e81..6ce5befb14a 100644 --- a/source/blender/compositor/operations/COM_ColorCurveOperation.h +++ b/source/blender/compositor/operations/COM_ColorCurveOperation.h @@ -53,4 +53,37 @@ public: */ void deinitExecution(); }; + +class ConstantLevelColorCurveOperation : public CurveBaseOperation { +private: + /** + * Cached reference to the inputProgram + */ + SocketReader * inputFacProgram; + SocketReader * inputImageProgram; + float black[3]; + float white[3]; + +public: + ConstantLevelColorCurveOperation(); + + /** + * the inner loop of this program + */ + void executePixel(float *color, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]); + + /** + * Initialize the execution + */ + void initExecution(); + + /** + * Deinitialize the execution + */ + void deinitExecution(); + + void setBlackLevel(float black[3]) {this->black[0] =black[0];this->black[1] =black[1];this->black[2] =black[2]; } + void setWhiteLevel(float white[3]) {this->white[0] =white[0];this->white[1] =white[1];this->white[2] =white[2]; } +}; + #endif diff --git a/source/blender/compositor/operations/COM_CompositorOperation.h b/source/blender/compositor/operations/COM_CompositorOperation.h index 41d43f896bb..13cb4f28324 100644 --- a/source/blender/compositor/operations/COM_CompositorOperation.h +++ b/source/blender/compositor/operations/COM_CompositorOperation.h @@ -63,7 +63,7 @@ public: bool isOutputOperation(bool rendering) const {return true;} void initExecution(); void deinitExecution(); - const int getRenderPriority() const {return 7;} + const CompositorPriority getRenderPriority() const {return COM_PRIORITY_MEDIUM;} void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); }; #endif diff --git a/source/blender/compositor/operations/COM_DifferenceMatteOperation.cpp b/source/blender/compositor/operations/COM_DifferenceMatteOperation.cpp index 628daa7c775..0b1ac1b2127 100644 --- a/source/blender/compositor/operations/COM_DifferenceMatteOperation.cpp +++ b/source/blender/compositor/operations/COM_DifferenceMatteOperation.cpp @@ -57,16 +57,16 @@ void DifferenceMatteOperation::executePixel(float *outputValue, float x, float y this->inputImage1Program->read(inColor1, x, y, sampler, inputBuffers); this->inputImage2Program->read(inColor2, x, y, sampler, inputBuffers); - difference = (fabs(inColor2[0] - inColor1[0]) + - fabs(inColor2[1] - inColor1[1]) + - fabs(inColor2[2] - inColor1[2])); + difference = (fabsf(inColor2[0] - inColor1[0]) + + fabsf(inColor2[1] - inColor1[1]) + + fabsf(inColor2[2] - inColor1[2])); - /*average together the distances*/ - difference=difference/3.0; + /* average together the distances */ + difference = difference / 3.0f; /*make 100% transparent*/ if (difference < tolerence) { - outputValue[0]=0.0; + outputValue[0] = 0.0f; } /*in the falloff region, make partially transparent */ else if (difference < falloff+tolerence) { diff --git a/source/blender/compositor/operations/COM_DirectionalBlurOperation.cpp b/source/blender/compositor/operations/COM_DirectionalBlurOperation.cpp index 30a09a45ade..43cba09d16f 100644 --- a/source/blender/compositor/operations/COM_DirectionalBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_DirectionalBlurOperation.cpp @@ -51,17 +51,17 @@ void DirectionalBlurOperation::initExecution() const float height = getHeight(); const float a = angle; - const float itsc = 1.f / pow(2.f, (float)iterations); + const float itsc = 1.0f / powf(2.0f, (float)iterations); float D; D = distance * sqrtf(width*width + height*height); center_x_pix = center_x * width; center_y_pix = center_y * height; - tx= itsc * D * cos(a); - ty= -itsc * D * sin(a); - sc= itsc * zoom; - rot = itsc * spin; + tx = itsc * D * cosf(a); + ty = -itsc * D * sinf(a); + sc = itsc * zoom; + rot = itsc * spin; } diff --git a/source/blender/compositor/operations/COM_EllipseMaskOperation.cpp b/source/blender/compositor/operations/COM_EllipseMaskOperation.cpp index 85a629f7365..650c57dd8dc 100644 --- a/source/blender/compositor/operations/COM_EllipseMaskOperation.cpp +++ b/source/blender/compositor/operations/COM_EllipseMaskOperation.cpp @@ -38,7 +38,7 @@ void EllipseMaskOperation::initExecution() { this->inputMask = this->getInputSocketReader(0); this->inputValue = this->getInputSocketReader(1); - const double rad = DEG2RAD(this->data->rotation); + const double rad = DEG2RAD((double)this->data->rotation); this->cosine = cos(rad); this->sine = sin(rad); this->aspectRatio = ((float)this->getWidth())/this->getHeight(); diff --git a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp index ad8f3b12387..ad58631f2c1 100644 --- a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp @@ -26,13 +26,12 @@ FastGaussianBlurOperation::FastGaussianBlurOperation(): BlurBaseOperation() { - this->iirgaus = false; + this->iirgaus = NULL; } void FastGaussianBlurOperation::executePixel(float *color,int x, int y, MemoryBuffer *inputBuffers[], void *data) { MemoryBuffer *newData = (MemoryBuffer*)data; - newData->read(color, x, y); } @@ -51,10 +50,7 @@ bool FastGaussianBlurOperation::determineDependingAreaOfInterest(rcti *input, Re } else { if (this->iirgaus) { - newInput.xmax = input->xmax + (sx); - newInput.xmin = input->xmin - (sx); - newInput.ymax = input->ymax + (sy); - newInput.ymin = input->ymin - (sy); + return false; } else { newInput.xmin = 0; @@ -66,38 +62,51 @@ bool FastGaussianBlurOperation::determineDependingAreaOfInterest(rcti *input, Re } } -void *FastGaussianBlurOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers) +void FastGaussianBlurOperation::initExecution() { - MemoryBuffer *newBuf = (MemoryBuffer*)this->inputProgram->initializeTileData(rect, memoryBuffers); - MemoryBuffer *copy = newBuf->duplicate(); - updateSize(memoryBuffers); - - int c; - sx = data->sizex * this->size/2.0f; - sy = data->sizey * this->size/2.0f; - this->iirgaus = true; - - if ((sx == sy) && (sx > 0.f)) { - for (c=0; c<COM_NUMBER_OF_CHANNELS; ++c) - IIR_gauss(copy, sx, c, 3); + BlurBaseOperation::initExecution(); + BlurBaseOperation::initMutex(); +} + +void FastGaussianBlurOperation::deinitExecution() +{ + if (this->iirgaus) { + delete this->iirgaus; + this->iirgaus = NULL; } - else { - if (sx > 0.f) { + BlurBaseOperation::deinitMutex(); +} + +void *FastGaussianBlurOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers) +{ + BLI_mutex_lock(this->getMutex()); + if (!iirgaus) { + MemoryBuffer *newBuf = (MemoryBuffer*)this->inputProgram->initializeTileData(rect, memoryBuffers); + MemoryBuffer *copy = newBuf->duplicate(); + updateSize(memoryBuffers); + + int c; + sx = data->sizex * this->size/2.0f; + sy = data->sizey * this->size/2.0f; + + if ((sx == sy) && (sx > 0.f)) { for (c=0; c<COM_NUMBER_OF_CHANNELS; ++c) - IIR_gauss(copy, sx, c, 1); + IIR_gauss(copy, sx, c, 3); } - if (sy > 0.f) { - for (c=0; c<COM_NUMBER_OF_CHANNELS; ++c) - IIR_gauss(copy, sy, c, 2); + else { + if (sx > 0.f) { + for (c=0; c<COM_NUMBER_OF_CHANNELS; ++c) + IIR_gauss(copy, sx, c, 1); + } + if (sy > 0.f) { + for (c=0; c<COM_NUMBER_OF_CHANNELS; ++c) + IIR_gauss(copy, sy, c, 2); + } } + this->iirgaus = copy; } - return copy; -} - -void FastGaussianBlurOperation::deinitializeTileData(rcti *rect, MemoryBuffer **memoryBuffers, void *data) -{ - MemoryBuffer *newData = (MemoryBuffer*)data; - delete newData; + BLI_mutex_unlock(this->getMutex()); + return iirgaus; } void FastGaussianBlurOperation::IIR_gauss(MemoryBuffer *src, float sigma, int chan, int xy) diff --git a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h index 6c3e373472b..1f71fe7f9ed 100644 --- a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h +++ b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h @@ -30,7 +30,7 @@ class FastGaussianBlurOperation: public BlurBaseOperation { private: float sx; float sy; - bool iirgaus; + MemoryBuffer* iirgaus; public: FastGaussianBlurOperation(); bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); @@ -38,7 +38,8 @@ public: static void IIR_gauss(MemoryBuffer *src, float sigma, int channel, int xy); void *initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers); - void deinitializeTileData(rcti *rect, MemoryBuffer **memoryBuffers, void *data); + void deinitExecution(); + void initExecution(); }; #endif diff --git a/source/blender/compositor/operations/COM_FogGlowImageOperation.cpp b/source/blender/compositor/operations/COM_FogGlowImageOperation.cpp index 600bfde64d9..05a758aca7f 100644 --- a/source/blender/compositor/operations/COM_FogGlowImageOperation.cpp +++ b/source/blender/compositor/operations/COM_FogGlowImageOperation.cpp @@ -37,7 +37,7 @@ void FogGlowImageOperation::executePixel(float *color, float x, float y, PixelSa u = 2.f*(x / (float)512) - 1.f; r = (u*u + v*v)*256; d = -sqrtf(sqrtf(sqrtf(r))); - w = (0.5f + 0.5f*cos((double)u*M_PI))*(0.5f + 0.5f*cos((double)v*M_PI)); + w = (0.5f + 0.5f * cosf(u * (float)M_PI)) * (0.5f + 0.5f * cosf(v * (float)M_PI)); color[0] = expf(d*cs_r) * w; color[1] = expf(d*cs_g) * w; color[2] = expf(d*cs_b) * w; diff --git a/source/blender/compositor/operations/COM_GammaOperation.cpp b/source/blender/compositor/operations/COM_GammaOperation.cpp index f0887d4adee..989ffd5dfba 100644 --- a/source/blender/compositor/operations/COM_GammaOperation.cpp +++ b/source/blender/compositor/operations/COM_GammaOperation.cpp @@ -46,9 +46,9 @@ void GammaOperation::executePixel(float *color, float x, float y, PixelSampler s this->inputGammaProgram->read(inputGamma, x, y, sampler, inputBuffers); const float gamma = inputGamma[0]; /* check for negative to avoid nan's */ - color[0] = inputValue[0]>0.0f?pow(inputValue[0], gamma):inputValue[0]; - color[1] = inputValue[1]>0.0f?pow(inputValue[1], gamma):inputValue[1]; - color[2] = inputValue[2]>0.0f?pow(inputValue[2], gamma):inputValue[2]; + color[0] = inputValue[0] > 0.0f ? powf(inputValue[0], gamma) : inputValue[0]; + color[1] = inputValue[1] > 0.0f ? powf(inputValue[1], gamma) : inputValue[1]; + color[2] = inputValue[2] > 0.0f ? powf(inputValue[2], gamma) : inputValue[2]; color[3] = inputValue[3]; } diff --git a/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp b/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp index b5d175729f3..e522d334d8b 100644 --- a/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp @@ -43,6 +43,8 @@ void *GaussianBokehBlurOperation::initializeTileData(rcti *rect, MemoryBuffer ** void GaussianBokehBlurOperation::initExecution() { + BlurBaseOperation::initExecution(); + if (this->sizeavailable) { updateGauss(NULL); } @@ -145,11 +147,11 @@ void GaussianBokehBlurOperation::executePixel(float *color, int x, int y, Memory bufferindex +=offsetadd; } } - float divider = 1.0/overallmultiplyer; - color[0] = tempColor[0]*divider; - color[1] = tempColor[1]*divider; - color[2] = tempColor[2]*divider; - color[3] = tempColor[3]*divider; + float divider = 1.0f / overallmultiplyer; + color[0] = tempColor[0] * divider; + color[1] = tempColor[1] * divider; + color[2] = tempColor[2] * divider; + color[3] = tempColor[3] * divider; } void GaussianBokehBlurOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_GaussianXBlurOperation.cpp b/source/blender/compositor/operations/COM_GaussianXBlurOperation.cpp index 121bbbd45a0..2eb51b4577f 100644 --- a/source/blender/compositor/operations/COM_GaussianXBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_GaussianXBlurOperation.cpp @@ -45,6 +45,8 @@ void *GaussianXBlurOperation::initializeTileData(rcti *rect, MemoryBuffer **memo void GaussianXBlurOperation::initExecution() { + BlurBaseOperation::initExecution(); + if (this->sizeavailable) { float rad = size*this->data->sizex; if (rad<1) @@ -75,7 +77,7 @@ void GaussianXBlurOperation::executePixel(float *color, int x, int y, MemoryBuff tempColor[1] = 0; tempColor[2] = 0; tempColor[3] = 0; - float overallmultiplyer = 0; + float overallmultiplyer = 0.0f; MemoryBuffer *inputBuffer = (MemoryBuffer*)data; float *buffer = inputBuffer->getBuffer(); int bufferwidth = inputBuffer->getWidth(); @@ -104,11 +106,11 @@ void GaussianXBlurOperation::executePixel(float *color, int x, int y, MemoryBuff overallmultiplyer += multiplyer; bufferindex +=offsetadd; } - float divider = 1.0/overallmultiplyer; - color[0] = tempColor[0]*divider; - color[1] = tempColor[1]*divider; - color[2] = tempColor[2]*divider; - color[3] = tempColor[3]*divider; + float divider = 1.0f / overallmultiplyer; + color[0] = tempColor[0] * divider; + color[1] = tempColor[1] * divider; + color[2] = tempColor[2] * divider; + color[3] = tempColor[3] * divider; } void GaussianXBlurOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_GaussianYBlurOperation.cpp b/source/blender/compositor/operations/COM_GaussianYBlurOperation.cpp index cab3e3d6094..28e8e548530 100644 --- a/source/blender/compositor/operations/COM_GaussianYBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_GaussianYBlurOperation.cpp @@ -101,11 +101,11 @@ void GaussianYBlurOperation::executePixel(float *color, int x, int y, MemoryBuff tempColor[3] += multiplyer * buffer[bufferindex+3]; overallmultiplyer += multiplyer; } - float divider = 1.0/overallmultiplyer; - color[0] = tempColor[0]*divider; - color[1] = tempColor[1]*divider; - color[2] = tempColor[2]*divider; - color[3] = tempColor[3]*divider; + float divider = 1.0f / overallmultiplyer; + color[0] = tempColor[0] * divider; + color[1] = tempColor[1] * divider; + color[2] = tempColor[2] * divider; + color[3] = tempColor[3] * divider; } void GaussianYBlurOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.cpp b/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.cpp index 2970c396493..2afcc2e5cc7 100644 --- a/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.cpp +++ b/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.cpp @@ -63,8 +63,8 @@ void HueSaturationValueCorrectOperation::executePixel(float *output, float x, fl f = curvemapping_evaluateF(this->curveMapping, 2, hsv[0]); hsv[2] *= (f * 2.f); - hsv[0] = hsv[0] - floor(hsv[0]); /* mod 1.0 */ - CLAMP(hsv[1], 0.f, 1.f); + hsv[0] = hsv[0] - floorf(hsv[0]); /* mod 1.0 */ + CLAMP(hsv[1], 0.0f, 1.0f); output[0] = hsv[0]; output[1] = hsv[1]; diff --git a/source/blender/compositor/operations/COM_ImageOperation.cpp b/source/blender/compositor/operations/COM_ImageOperation.cpp index 020dfdbdc14..04cd91d3c3a 100644 --- a/source/blender/compositor/operations/COM_ImageOperation.cpp +++ b/source/blender/compositor/operations/COM_ImageOperation.cpp @@ -99,8 +99,8 @@ void BaseImageOperation::determineResolution(unsigned int resolution[], unsigned { ImBuf *stackbuf = getImBuf(); - resolution[0] = 0; - resolution[1] = 0; + resolution[0] = 0; + resolution[1] = 0; if (stackbuf) { resolution[0] = stackbuf->x; diff --git a/source/blender/compositor/operations/COM_MapUVOperation.cpp b/source/blender/compositor/operations/COM_MapUVOperation.cpp index 7b393cc04a8..035f5584065 100644 --- a/source/blender/compositor/operations/COM_MapUVOperation.cpp +++ b/source/blender/compositor/operations/COM_MapUVOperation.cpp @@ -61,16 +61,16 @@ void MapUVOperation::executePixel(float *color, float x, float y, PixelSampler s /* adaptive sampling, red (U) channel */ this->inputUVProgram->read(uv_a, x-1, y, COM_PS_NEAREST, inputBuffers); this->inputUVProgram->read(uv_b, x+1, y, COM_PS_NEAREST, inputBuffers); - uv_l = uv_a[2]!=0.f? fabs(inputUV[0] - uv_a[0]) : 0.f; - uv_r = uv_b[2]!=0.f? fabs(inputUV[0] - uv_b[0]) : 0.f; + uv_l = uv_a[2]!=0.f? fabsf(inputUV[0] - uv_a[0]) : 0.f; + uv_r = uv_b[2]!=0.f? fabsf(inputUV[0] - uv_b[0]) : 0.f; dx = 0.5f * (uv_l + uv_r); /* adaptive sampling, green (V) channel */ this->inputUVProgram->read(uv_a, x, y-1, COM_PS_NEAREST, inputBuffers); this->inputUVProgram->read(uv_b, x, y+1, COM_PS_NEAREST, inputBuffers); - uv_u = uv_a[2]!=0.f? fabs(inputUV[1] - uv_a[1]) : 0.f; - uv_d = uv_b[2]!=0.f? fabs(inputUV[1] - uv_b[1]) : 0.f; + uv_u = uv_a[2]!=0.f? fabsf(inputUV[1] - uv_a[1]) : 0.f; + uv_d = uv_b[2]!=0.f? fabsf(inputUV[1] - uv_b[1]) : 0.f; dy = 0.5f * (uv_u + uv_d); diff --git a/source/blender/compositor/operations/COM_MaskOperation.cpp b/source/blender/compositor/operations/COM_MaskOperation.cpp new file mode 100644 index 00000000000..a7c1de323f1 --- /dev/null +++ b/source/blender/compositor/operations/COM_MaskOperation.cpp @@ -0,0 +1,124 @@ +/* + * Copyright 2012, Blender Foundation. + * + * 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. + * + * Contributor: + * Jeroen Bakker + * Monique Dewanchand + * Sergey Sharybin + */ + +#include "COM_MaskOperation.h" + +#include "MEM_guardedalloc.h" + +#include "BLI_listbase.h" +#include "BLI_math.h" + +#include "DNA_scene_types.h" + +extern "C" { + #include "BKE_mask.h" +} + +MaskOperation::MaskOperation(): NodeOperation() +{ + this->addInputSocket(COM_DT_COLOR); + this->addOutputSocket(COM_DT_COLOR); + this->mask = NULL; + this->maskWidth = 0; + this->maskHeight = 0; + this->framenumber = 0; + this->rasterizedMask = NULL; + setComplex(true); +} + +void MaskOperation::initExecution() +{ + initMutex(); + this->rasterizedMask = NULL; +} + +void MaskOperation::deinitExecution() +{ + if (this->rasterizedMask) { + MEM_freeN(rasterizedMask); + this->rasterizedMask = NULL; + } +} + +void *MaskOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers) +{ + if (this->rasterizedMask) + return this->rasterizedMask; + + if (!this->mask) + return NULL; + + BLI_mutex_lock(getMutex()); + if (this->rasterizedMask == NULL) { + int width = this->getWidth(); + int height = this->getHeight(); + float *buffer; + + buffer = (float *)MEM_callocN(sizeof(float) * width * height, "rasterized mask"); + BKE_mask_rasterize(mask, width, height, buffer, TRUE, TRUE); + + this->rasterizedMask = buffer; + } + BLI_mutex_unlock(getMutex()); + + return this->rasterizedMask; +} + +void MaskOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +{ + if (maskWidth == 0 || maskHeight == 0) { + NodeOperation::determineResolution(resolution, preferredResolution); + } + else { + unsigned int nr[2]; + + nr[0] = maskWidth; + nr[1] = maskHeight; + + NodeOperation::determineResolution(resolution, nr); + + resolution[0] = maskWidth; + resolution[1] = maskHeight; + } +} + +void MaskOperation::executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data) +{ + if (!data) { + color[0] = 0; + color[1] = 0; + color[2] = 0; + color[3] = 1.0f; + } + else { + float *buffer = (float*) data; + int index = (y * this->getWidth() + x); + + color[0] = buffer[index]; + color[1] = buffer[index]; + color[2] = buffer[index]; + color[3] = 1.0f; + } +} + + diff --git a/source/blender/compositor/operations/COM_MaskOperation.h b/source/blender/compositor/operations/COM_MaskOperation.h new file mode 100644 index 00000000000..9f2c7f53f56 --- /dev/null +++ b/source/blender/compositor/operations/COM_MaskOperation.h @@ -0,0 +1,66 @@ +/* + * Copyright 2012, Blender Foundation. + * + * 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. + * + * Contributor: + * Jeroen Bakker + * Monique Dewanchand + * Sergey Sharybin + */ + + +#ifndef _COM_MaskOperation_h +#define _COM_MaskOperation_h + +#include "COM_NodeOperation.h" +#include "DNA_scene_types.h" +#include "DNA_mask_types.h" +#include "BLI_listbase.h" +#include "IMB_imbuf_types.h" + +/** + * Class with implementation of mask rasterization + */ +class MaskOperation : public NodeOperation { +protected: + Mask *mask; + int maskWidth; + int maskHeight; + int framenumber; + float *rasterizedMask; + + /** + * Determine the output resolution. The resolution is retrieved from the Renderer + */ + void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + +public: + MaskOperation(); + + void initExecution(); + void deinitExecution(); + + void *initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers); + + void setMask(Mask *mask) {this->mask = mask;} + void setMaskWidth(int width) {this->maskWidth = width;} + void setMaskHeight(int height) {this->maskHeight = height;} + void setFramenumber(int framenumber) {this->framenumber = framenumber;} + + void executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data); +}; + +#endif diff --git a/source/blender/compositor/operations/COM_MathBaseOperation.cpp b/source/blender/compositor/operations/COM_MathBaseOperation.cpp index 2ea5f85253b..b943ec88fde 100644 --- a/source/blender/compositor/operations/COM_MathBaseOperation.cpp +++ b/source/blender/compositor/operations/COM_MathBaseOperation.cpp @@ -196,8 +196,8 @@ void MathPowerOperation::executePixel(float *outputValue, float x, float y, Pixe else { float y_mod_1 = fmod(inputValue2[0], 1); /* if input value is not nearly an integer, fall back to zero, nicer than straight rounding */ - if (y_mod_1 > 0.999 || y_mod_1 < 0.001) { - outputValue[0] = pow(inputValue1[0], (float)floor(inputValue2[0] + 0.5)); + if (y_mod_1 > 0.999f || y_mod_1 < 0.001f) { + outputValue[0] = pow(inputValue1[0], floorf(inputValue2[0] + 0.5f)); } else { outputValue[0] = 0.0; diff --git a/source/blender/compositor/operations/COM_OpenCLKernels.cl b/source/blender/compositor/operations/COM_OpenCLKernels.cl index 40932e54bc7..aeccfcab8b5 100644 --- a/source/blender/compositor/operations/COM_OpenCLKernels.cl +++ b/source/blender/compositor/operations/COM_OpenCLKernels.cl @@ -1,10 +1,52 @@ /// This file contains all opencl kernels for node-operation implementations -__kernel void testKernel(__global __write_only image2d_t output) +// Global SAMPLERS +const sampler_t SAMPLER_NEAREST = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; + +__constant const int2 zero = {0,0}; + +// KERNEL --- BOKEH BLUR --- +__kernel void bokehBlurKernel(__global __read_only image2d_t boundingBox, __global __read_only image2d_t inputImage, + __global __read_only image2d_t bokehImage, __global __write_only image2d_t output, + int2 offsetInput, int2 offsetOutput, int radius, int step, int2 dimension, int2 offset) { - int x = get_global_id(0); - int y = get_global_id(1); - int2 coords = {x, y}; - float4 color = {0.0f, 1.0f, 0.0f, 1.0f}; + int2 coords = {get_global_id(0), get_global_id(1)}; + coords += offset; + float tempBoundingBox; + float4 color = {0.0f,0.0f,0.0f,0.0f}; + float4 multiplyer = {0.0f,0.0f,0.0f,0.0f}; + float4 bokeh; + const float radius2 = radius*2.0f; + const int2 realCoordinate = coords + offsetOutput; + + tempBoundingBox = read_imagef(boundingBox, SAMPLER_NEAREST, coords).s0; + + if (tempBoundingBox > 0.0f) { + const int2 bokehImageDim = get_image_dim(bokehImage); + const int2 bokehImageCenter = bokehImageDim/2; + const int2 minXY = max(realCoordinate - radius, zero); + const int2 maxXY = min(realCoordinate + radius, dimension); + int nx, ny; + + float2 uv; + int2 inputXy; + + for (ny = minXY.y, inputXy.y = ny - offsetInput.y ; ny < maxXY.y ; ny +=step, inputXy.y+=step) { + uv.y = ((realCoordinate.y-ny)/radius2)*bokehImageDim.y+bokehImageCenter.y; + + for (nx = minXY.x, inputXy.x = nx - offsetInput.x; nx < maxXY.x ; nx +=step, inputXy.x+=step) { + uv.x = ((realCoordinate.x-nx)/radius2)*bokehImageDim.x+bokehImageCenter.x; + bokeh = read_imagef(bokehImage, SAMPLER_NEAREST, uv); + color += bokeh * read_imagef(inputImage, SAMPLER_NEAREST, inputXy); + multiplyer += bokeh; + } + } + color /= multiplyer; + + } else { + int2 imageCoordinates = realCoordinate - offsetInput; + color = read_imagef(inputImage, SAMPLER_NEAREST, imageCoordinates); + } + write_imagef(output, coords, color); } diff --git a/source/blender/compositor/operations/COM_OpenCLKernels.cl.cpp b/source/blender/compositor/operations/COM_OpenCLKernels.cl.cpp deleted file mode 100644 index 1024d460044..00000000000 --- a/source/blender/compositor/operations/COM_OpenCLKernels.cl.cpp +++ /dev/null @@ -1,15 +0,0 @@ -/// @todo: this source needs to be generated from COM_OpenCLKernels.cl. -/// not implemented yet. new data to h - -const char *sourcecode = "/// This file contains all opencl kernels for node-operation implementations \n" \ -"\n" \ -"__kernel void testKernel(__global __write_only image2d_t output)\n" \ -"{\n" \ -" int x = get_global_id(0);\n" \ -" int y = get_global_id(1);\n" \ -" int2 coords = {x, y}; \n" \ -" float4 color = {0.0f, 1.0f, 0.0f, 1.0f};\n" \ -" write_imagef(output, coords, color);\n" \ -"}\n" \ -"\0\n"; - diff --git a/source/blender/compositor/operations/COM_OpenCLKernels.cl.h b/source/blender/compositor/operations/COM_OpenCLKernels.cl.h new file mode 100644 index 00000000000..3cf33c75272 --- /dev/null +++ b/source/blender/compositor/operations/COM_OpenCLKernels.cl.h @@ -0,0 +1,55 @@ +/* clkernelstoh output of file <COM_OpenCLKernels_cl> */ + +const char * clkernelstoh_COM_OpenCLKernels_cl = "/// This file contains all opencl kernels for node-operation implementations\n" \ +"\n" \ +"// Global SAMPLERS\n" \ +"const sampler_t SAMPLER_NEAREST = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST;\n" \ +"\n" \ +"__constant const int2 zero = {0,0};\n" \ +"\n" \ +"// KERNEL --- BOKEH BLUR ---\n" \ +"__kernel void bokehBlurKernel(__global __read_only image2d_t boundingBox, __global __read_only image2d_t inputImage,\n" \ +" __global __read_only image2d_t bokehImage, __global __write_only image2d_t output,\n" \ +" int2 offsetInput, int2 offsetOutput, int radius, int step, int2 dimension, int2 offset)\n" \ +"{\n" \ +" int2 coords = {get_global_id(0), get_global_id(1)};\n" \ +" coords += offset;\n" \ +" float tempBoundingBox;\n" \ +" float4 color = {0.0f,0.0f,0.0f,0.0f};\n" \ +" float4 multiplyer = {0.0f,0.0f,0.0f,0.0f};\n" \ +" float4 bokeh;\n" \ +" const float radius2 = radius*2.0f;\n" \ +" const int2 realCoordinate = coords + offsetOutput;\n" \ +"\n" \ +" tempBoundingBox = read_imagef(boundingBox, SAMPLER_NEAREST, coords).s0;\n" \ +"\n" \ +" if (tempBoundingBox > 0.0f) {\n" \ +" const int2 bokehImageDim = get_image_dim(bokehImage);\n" \ +" const int2 bokehImageCenter = bokehImageDim/2;\n" \ +" const int2 minXY = max(realCoordinate - radius, zero);;\n" \ +" const int2 maxXY = min(realCoordinate + radius, dimension);;\n" \ +" int nx, ny;\n" \ +"\n" \ +" float2 uv;\n" \ +" int2 inputXy;\n" \ +"\n" \ +" for (ny = minXY.y, inputXy.y = ny - offsetInput.y ; ny < maxXY.y ; ny +=step, inputXy.y+=step) {\n" \ +" uv.y = ((realCoordinate.y-ny)/radius2)*bokehImageDim.y+bokehImageCenter.y;\n" \ +"\n" \ +" for (nx = minXY.x, inputXy.x = nx - offsetInput.x; nx < maxXY.x ; nx +=step, inputXy.x+=step) {\n" \ +" uv.x = ((realCoordinate.x-nx)/radius2)*bokehImageDim.x+bokehImageCenter.x;\n" \ +" bokeh = read_imagef(bokehImage, SAMPLER_NEAREST, uv);\n" \ +" color += bokeh * read_imagef(inputImage, SAMPLER_NEAREST, inputXy);\n" \ +" multiplyer += bokeh;\n" \ +" }\n" \ +" }\n" \ +" color /= multiplyer;\n" \ +"\n" \ +" } else {\n" \ +" int2 imageCoordinates = realCoordinate - offsetInput;\n" \ +" color = read_imagef(inputImage, SAMPLER_NEAREST, imageCoordinates);\n" \ +" }\n" \ +"\n" \ +" write_imagef(output, coords, color);\n" \ +"}\n" \ +"\0"; diff --git a/source/blender/compositor/operations/COM_OutputFileOperation.h b/source/blender/compositor/operations/COM_OutputFileOperation.h index 0e37432ca5b..9b9fb023467 100644 --- a/source/blender/compositor/operations/COM_OutputFileOperation.h +++ b/source/blender/compositor/operations/COM_OutputFileOperation.h @@ -49,7 +49,7 @@ public: bool isOutputOperation(bool rendering) const {return true;} void initExecution(); void deinitExecution(); - const int getRenderPriority() const {return 7;} + const CompositorPriority getRenderPriority() const {return COM_PRIORITY_LOW;} }; /* extra info for OpenEXR layers */ @@ -83,7 +83,7 @@ public: bool isOutputOperation(bool rendering) const {return true;} void initExecution(); void deinitExecution(); - const int getRenderPriority() const {return 7;} + const CompositorPriority getRenderPriority() const {return COM_PRIORITY_LOW;} }; #endif diff --git a/source/blender/compositor/operations/COM_PreviewOperation.cpp b/source/blender/compositor/operations/COM_PreviewOperation.cpp index a7b6fc93b25..4975f13a285 100644 --- a/source/blender/compositor/operations/COM_PreviewOperation.cpp +++ b/source/blender/compositor/operations/COM_PreviewOperation.cpp @@ -46,7 +46,6 @@ PreviewOperation::PreviewOperation() : NodeOperation() this->input = NULL; this->divider = 1.0f; this->node = NULL; - this->priority = 0; } void PreviewOperation::initExecution() @@ -129,7 +128,7 @@ void PreviewOperation::determineResolution(unsigned int resolution[], unsigned i resolution[1] = height; } -const int PreviewOperation::getRenderPriority() const +const CompositorPriority PreviewOperation::getRenderPriority() const { - return this->priority; + return COM_PRIORITY_LOW; } diff --git a/source/blender/compositor/operations/COM_PreviewOperation.h b/source/blender/compositor/operations/COM_PreviewOperation.h index 8450b7fc556..3d1cd38a5ea 100644 --- a/source/blender/compositor/operations/COM_PreviewOperation.h +++ b/source/blender/compositor/operations/COM_PreviewOperation.h @@ -37,20 +37,18 @@ protected: const bNodeTree *tree; SocketReader *input; float divider; - int priority; public: PreviewOperation(); bool isOutputOperation(bool rendering) const {return true;} void initExecution(); void deinitExecution(); - const int getRenderPriority() const; + const CompositorPriority getRenderPriority() const; void executeRegion(rcti *rect, unsigned int tileNumber, MemoryBuffer **memoryBuffers); void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); void setbNode(bNode *node) { this->node = node;} void setbNodeTree(const bNodeTree *tree) { this->tree = tree;} bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); - void setPriority(int priority) { this->priority = priority; } }; #endif diff --git a/source/blender/compositor/operations/COM_RotateOperation.cpp b/source/blender/compositor/operations/COM_RotateOperation.cpp index 313e49d8609..af2633f0e53 100644 --- a/source/blender/compositor/operations/COM_RotateOperation.cpp +++ b/source/blender/compositor/operations/COM_RotateOperation.cpp @@ -43,7 +43,7 @@ void RotateOperation::initExecution() this->degreeSocket->read(degree, 0, 0, COM_PS_NEAREST, NULL); double rad; if (this->doDegree2RadConversion) { - rad = DEG2RAD(degree[0]); + rad = DEG2RAD((double)degree[0]); } else { rad = degree[0]; diff --git a/source/blender/compositor/operations/COM_TonemapOperation.cpp b/source/blender/compositor/operations/COM_TonemapOperation.cpp index 56830f4970d..d8089bdf3ea 100644 --- a/source/blender/compositor/operations/COM_TonemapOperation.cpp +++ b/source/blender/compositor/operations/COM_TonemapOperation.cpp @@ -53,14 +53,14 @@ void TonemapOperation::executePixel(float *color, int x, int y, MemoryBuffer *in float dr = output[0] + this->data->offset; float dg = output[1] + this->data->offset; float db = output[2] + this->data->offset; - output[0] /= ((dr == 0.f) ? 1.f : dr); - output[1] /= ((dg == 0.f) ? 1.f : dg); - output[2] /= ((db == 0.f) ? 1.f : db); + output[0] /= ((dr == 0.f) ? 1.0f : dr); + output[1] /= ((dg == 0.f) ? 1.0f : dg); + output[2] /= ((db == 0.f) ? 1.0f : db); const float igm = avg->igm; - if (igm != 0.f) { - output[0] = pow((double)MAX2(output[0], 0.), (double)igm); - output[1] = pow((double)MAX2(output[1], 0.), (double)igm); - output[2] = pow((double)MAX2(output[2], 0.), (double)igm); + if (igm != 0.0f) { + output[0] = powf(MAX2(output[0], 0.0f), igm); + output[1] = powf(MAX2(output[1], 0.0f), igm); + output[2] = powf(MAX2(output[2], 0.0f), igm); } color[0] = output[0]; @@ -68,31 +68,31 @@ void TonemapOperation::executePixel(float *color, int x, int y, MemoryBuffer *in color[2] = output[2]; color[3] = output[3]; } -void PhotoreceptorTonemapOperation::executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void * data) +void PhotoreceptorTonemapOperation::executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data) { - AvgLogLum * avg = (AvgLogLum*)data; + AvgLogLum *avg = (AvgLogLum *)data; NodeTonemap *ntm = this->data; - const float f = exp((double)-this->data->f); - const float m = (ntm->m > 0.f) ? ntm->m : (0.3f + 0.7f*pow((double)avg->auto_key, 1.4)); - const float ic = 1.f - ntm->c, ia = 1.f - ntm->a; + const float f = expf(-this->data->f); + const float m = (ntm->m > 0.0f) ? ntm->m : (0.3f + 0.7f * powf(avg->auto_key, 1.4f)); + const float ic = 1.0f - ntm->c, ia = 1.0f - ntm->a; float output[4]; this->imageReader->read(output, x, y, inputBuffers, NULL); - const float L = 0.212671f*output[0] + 0.71516f*output[1] + 0.072169f*output[2]; - float I_l = output[0] + ic*(L - output[0]); - float I_g = avg->cav[0] + ic*(avg->lav - avg->cav[0]); - float I_a = I_l + ia*(I_g - I_l); - output[0] /= (output[0] + pow((double)f*I_a, (double)m)); - I_l = output[1] + ic*(L - output[1]); - I_g = avg->cav[1] + ic*(avg->lav - avg->cav[1]); - I_a = I_l + ia*(I_g - I_l); - output[1] /= (output[1] + pow((double)f*I_a,(double)m)); - I_l = output[2] + ic*(L - output[2]); - I_g = avg->cav[2] + ic*(avg->lav - avg->cav[2]); - I_a = I_l + ia*(I_g - I_l); - output[2] /= (output[2] + pow((double)f*I_a, (double)m)); + const float L = 0.212671f * output[0] + 0.71516f * output[1] + 0.072169f * output[2]; + float I_l = output[0] + ic * (L - output[0]); + float I_g = avg->cav[0] + ic * (avg->lav - avg->cav[0]); + float I_a = I_l + ia * (I_g - I_l); + output[0] /= (output[0] + powf(f * I_a, m)); + I_l = output[1] + ic * (L - output[1]); + I_g = avg->cav[1] + ic * (avg->lav - avg->cav[1]); + I_a = I_l + ia * (I_g - I_l); + output[1] /= (output[1] + powf(f * I_a, m)); + I_l = output[2] + ic * (L - output[2]); + I_g = avg->cav[2] + ic * (avg->lav - avg->cav[2]); + I_a = I_l + ia * (I_g - I_l); + output[2] /= (output[2] + powf(f * I_a, m)); color[0] = output[0]; color[1] = output[1]; @@ -133,20 +133,20 @@ void *TonemapOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuff float * buffer = tile->getBuffer(); - float lsum = 0; + float lsum = 0.0f; int p = tile->getWidth() * tile->getHeight(); float *bc = buffer; float avl, maxl = -1e10f, minl = 1e10f; - const float sc = 1.f/(p); + const float sc = 1.0f / p; float Lav = 0.f; float cav[4] = {0.0f,0.0f,0.0f,0.0f}; while (p--) { - float L = 0.212671f*bc[0] + 0.71516f*bc[1] + 0.072169f*bc[2]; + float L = 0.212671f * bc[0] + 0.71516f * bc[1] + 0.072169f * bc[2]; Lav += L; cav[0] += bc[0]; cav[1] += bc[1]; cav[2] += bc[2]; - lsum += (float)log((double)MAX2(L, 0.0) + 1e-5); + lsum += logf(MAX2(L, 0.0f) + 1e-5f); maxl = (L > maxl) ? L : maxl; minl = (L < minl) ? L : minl; bc+=4; @@ -155,7 +155,7 @@ void *TonemapOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuff data->cav[0] = cav[0]*sc; data->cav[1] = cav[1]*sc; data->cav[2] = cav[2]*sc; - maxl = log((double)maxl + 1e-5); minl = log((double)minl + 1e-5f); avl = lsum*sc; + maxl = log((double)maxl + 1e-5); minl = log((double)minl + 1e-5); avl = lsum * sc; data->auto_key = (maxl > minl) ? ((maxl - avl) / (maxl - minl)) : 1.f; float al = exp((double)avl); data->al = (al == 0.f) ? 0.f : (this->data->key / al); diff --git a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp index f14de097dfd..270fedc174b 100644 --- a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp @@ -89,7 +89,7 @@ void VariableSizeBokehBlurOperation::executePixel(float *color, int x, int y, Me if (nx == x && ny == y) { /* pass */ } - else if (size>= fabs(dx) && size >= fabs(dy)) { + else if (size >= fabsf(dx) && size >= fabsf(dy)) { float u = 256 + dx*256/size; float v = 256 + dy*256/size; inputBokehProgram->read(bokeh, u, v, COM_PS_NEAREST, inputBuffers); @@ -104,9 +104,9 @@ void VariableSizeBokehBlurOperation::executePixel(float *color, int x, int y, Me } } } - color[0] = tempColor[0]*(1.0/overallmultiplyerr); - color[1] = tempColor[1]*(1.0/overallmultiplyerg); - color[2] = tempColor[2]*(1.0/overallmultiplyerb); + color[0] = tempColor[0] * (1.0f / overallmultiplyerr); + color[1] = tempColor[1] * (1.0f / overallmultiplyerg); + color[2] = tempColor[2] * (1.0f / overallmultiplyerb); color[3] = 1.0f; } diff --git a/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp b/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp index 44b4c26fb64..809c688195f 100644 --- a/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp +++ b/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp @@ -50,8 +50,9 @@ ViewerBaseOperation::ViewerBaseOperation() : NodeOperation() void ViewerBaseOperation::initExecution() { - // When initializing the tree during initial load the width and height can be zero. - initImage(); + if (isActiveViewerOutput()) { + initImage(); + } } void ViewerBaseOperation::initImage() @@ -79,7 +80,6 @@ void ViewerBaseOperation::initImage() } void ViewerBaseOperation:: updateImage(rcti *rect) { - /// @todo: introduce new event to update smaller area WM_main_add_notifier(NC_WINDOW|ND_DRAW, NULL); } @@ -88,12 +88,12 @@ void ViewerBaseOperation::deinitExecution() this->outputBuffer = NULL; } -const int ViewerBaseOperation::getRenderPriority() const +const CompositorPriority ViewerBaseOperation::getRenderPriority() const { if (this->isActiveViewerOutput()) { - return 8; + return COM_PRIORITY_HIGH; } else { - return 0; + return COM_PRIORITY_LOW; } } diff --git a/source/blender/compositor/operations/COM_ViewerBaseOperation.h b/source/blender/compositor/operations/COM_ViewerBaseOperation.h index 58101911550..51fa8cecc0d 100644 --- a/source/blender/compositor/operations/COM_ViewerBaseOperation.h +++ b/source/blender/compositor/operations/COM_ViewerBaseOperation.h @@ -42,7 +42,7 @@ protected: bool doColorPredivide; public: - bool isOutputOperation(bool rendering) const {return true;} + bool isOutputOperation(bool rendering) const {return isActiveViewerOutput();} void initExecution(); void deinitExecution(); void setImage(Image *image) {this->image = image;} @@ -56,7 +56,7 @@ public: float getCenterX() { return this->centerX; } float getCenterY() { return this->centerY; } OrderOfChunks getChunkOrder() { return this->chunkOrder; } - const int getRenderPriority() const; + const CompositorPriority getRenderPriority() const; void setColorManagement(bool doColorManagement) {this->doColorManagement = doColorManagement;} void setColorPredivide(bool doColorPredivide) {this->doColorPredivide = doColorPredivide;} bool isViewerOperation() {return true;} diff --git a/source/blender/compositor/operations/COM_WriteBufferOperation.cpp b/source/blender/compositor/operations/COM_WriteBufferOperation.cpp index 498add2fc87..222b879645c 100644 --- a/source/blender/compositor/operations/COM_WriteBufferOperation.cpp +++ b/source/blender/compositor/operations/COM_WriteBufferOperation.cpp @@ -111,10 +111,9 @@ void WriteBufferOperation::executeRegion(rcti *rect, unsigned int tileNumber, Me memoryBuffer->setCreatedState(); } -void WriteBufferOperation::executeOpenCLRegion(cl_context context, cl_program program, cl_command_queue queue, rcti *rect, unsigned int chunkNumber, MemoryBuffer** inputMemoryBuffers) +void WriteBufferOperation::executeOpenCLRegion(cl_context context, cl_program program, cl_command_queue queue, rcti *rect, unsigned int chunkNumber, MemoryBuffer** inputMemoryBuffers, MemoryBuffer* outputBuffer) { - MemoryBuffer *outputMemoryBuffer = this->getMemoryProxy()->getBuffer();// @todo wrong implementation needs revision - float *outputFloatBuffer = outputMemoryBuffer->getBuffer(); + float *outputFloatBuffer = outputBuffer->getBuffer(); cl_int error; /* * 1. create cl_mem from outputbuffer @@ -125,8 +124,8 @@ void WriteBufferOperation::executeOpenCLRegion(cl_context context, cl_program pr * note: list of cl_mem will be filled by 2, and needs to be cleaned up by 4 */ // STEP 1 - const unsigned int outputBufferWidth = outputMemoryBuffer->getWidth(); - const unsigned int outputBufferHeight = outputMemoryBuffer->getHeight(); + const unsigned int outputBufferWidth = outputBuffer->getWidth(); + const unsigned int outputBufferHeight = outputBuffer->getHeight(); const cl_image_format imageFormat = { CL_RGBA, @@ -141,19 +140,26 @@ void WriteBufferOperation::executeOpenCLRegion(cl_context context, cl_program pr clMemToCleanUp->push_back(clOutputBuffer); list<cl_kernel> *clKernelsToCleanUp = new list<cl_kernel>(); - this->input->executeOpenCL(context, program, queue, outputMemoryBuffer, clOutputBuffer, inputMemoryBuffers, clMemToCleanUp, clKernelsToCleanUp); + this->input->executeOpenCL(context, program, queue, outputBuffer, clOutputBuffer, inputMemoryBuffers, clMemToCleanUp, clKernelsToCleanUp); // STEP 3 size_t origin[3] = {0,0,0}; size_t region[3] = {outputBufferWidth,outputBufferHeight,1}; +// clFlush(queue); +// clFinish(queue); + error = clEnqueueBarrier(queue); if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } error = clEnqueueReadImage(queue, clOutputBuffer, CL_TRUE, origin, region, 0, 0, outputFloatBuffer, 0, NULL, NULL); if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } + + this->getMemoryProxy()->getBuffer()->copyContentFrom(outputBuffer); + // STEP 4 + while (clMemToCleanUp->size()>0) { cl_mem mem = clMemToCleanUp->front(); error = clReleaseMemObject(mem); diff --git a/source/blender/compositor/operations/COM_WriteBufferOperation.h b/source/blender/compositor/operations/COM_WriteBufferOperation.h index b17122d68f0..6f2c49c49bd 100644 --- a/source/blender/compositor/operations/COM_WriteBufferOperation.h +++ b/source/blender/compositor/operations/COM_WriteBufferOperation.h @@ -46,7 +46,7 @@ public: void initExecution(); void deinitExecution(); void setbNodeTree(const bNodeTree *tree) {this->tree = tree;} - void executeOpenCLRegion(cl_context context, cl_program program, cl_command_queue queue, rcti *rect, unsigned int chunkNumber, MemoryBuffer** memoryBuffers); + void executeOpenCLRegion(cl_context context, cl_program program, cl_command_queue queue, rcti *rect, unsigned int chunkNumber, MemoryBuffer** memoryBuffers, MemoryBuffer* outputBuffer); }; #endif |