Cleanup: Turn filter node methods into an Enum

This patch turns the filter node methods into an enum and renames the
members from FILT into FILTER for easier writing.
This commit is contained in:
Omar Emara 2022-08-23 09:24:25 +02:00
parent 78061e6c3e
commit 655e9eabc3
4 changed files with 38 additions and 36 deletions

View File

@ -1326,16 +1326,6 @@ void BKE_nodetree_remove_layer_n(struct bNodeTree *ntree, struct Scene *scene, i
#define CMP_CHAN_RGB 1
#define CMP_CHAN_A 2
/* filter types */
#define CMP_FILT_SOFT 0
#define CMP_FILT_SHARP_BOX 1
#define CMP_FILT_LAPLACE 2
#define CMP_FILT_SOBEL 3
#define CMP_FILT_PREWITT 4
#define CMP_FILT_KIRSCH 5
#define CMP_FILT_SHADOW 6
#define CMP_FILT_SHARP_DIAMOND 7
/* scale node type, in custom1 */
#define CMP_SCALE_RELATIVE 0
#define CMP_SCALE_ABSOLUTE 1

View File

@ -21,7 +21,7 @@ void FilterNode::convert_to_operations(NodeConverter &converter,
ConvolutionFilterOperation *operation = nullptr;
switch (this->get_bnode()->custom1) {
case CMP_FILT_SOFT:
case CMP_NODE_FILTER_SOFT:
operation = new ConvolutionFilterOperation();
operation->set3x3Filter(1 / 16.0f,
2 / 16.0f,
@ -33,11 +33,11 @@ void FilterNode::convert_to_operations(NodeConverter &converter,
2 / 16.0f,
1 / 16.0f);
break;
case CMP_FILT_SHARP_BOX:
case CMP_NODE_FILTER_SHARP_BOX:
operation = new ConvolutionFilterOperation();
operation->set3x3Filter(-1, -1, -1, -1, 9, -1, -1, -1, -1);
break;
case CMP_FILT_LAPLACE:
case CMP_NODE_FILTER_LAPLACE:
operation = new ConvolutionEdgeFilterOperation();
operation->set3x3Filter(-1 / 8.0f,
-1 / 8.0f,
@ -49,23 +49,23 @@ void FilterNode::convert_to_operations(NodeConverter &converter,
-1 / 8.0f,
-1 / 8.0f);
break;
case CMP_FILT_SOBEL:
case CMP_NODE_FILTER_SOBEL:
operation = new ConvolutionEdgeFilterOperation();
operation->set3x3Filter(1, 2, 1, 0, 0, 0, -1, -2, -1);
break;
case CMP_FILT_PREWITT:
case CMP_NODE_FILTER_PREWITT:
operation = new ConvolutionEdgeFilterOperation();
operation->set3x3Filter(1, 1, 1, 0, 0, 0, -1, -1, -1);
break;
case CMP_FILT_KIRSCH:
case CMP_NODE_FILTER_KIRSCH:
operation = new ConvolutionEdgeFilterOperation();
operation->set3x3Filter(5, 5, 5, -3, -3, -3, -2, -2, -2);
break;
case CMP_FILT_SHADOW:
case CMP_NODE_FILTER_SHADOW:
operation = new ConvolutionFilterOperation();
operation->set3x3Filter(1, 2, 1, 0, 1, 0, -1, -2, -1);
break;
case CMP_FILT_SHARP_DIAMOND:
case CMP_NODE_FILTER_SHARP_DIAMOND:
operation = new ConvolutionFilterOperation();
operation->set3x3Filter(0, -1, 0, -1, 5, -1, 0, -1, 0);
break;

View File

@ -1881,6 +1881,18 @@ typedef enum CMPNodeFlipMode {
CMP_NODE_FLIP_X_Y = 2,
} CMPNodeFlipMode;
/* Filter Node. Stored in custom1. */
typedef enum CMPNodeFilterMethod {
CMP_NODE_FILTER_SOFT = 0,
CMP_NODE_FILTER_SHARP_BOX = 1,
CMP_NODE_FILTER_LAPLACE = 2,
CMP_NODE_FILTER_SOBEL = 3,
CMP_NODE_FILTER_PREWITT = 4,
CMP_NODE_FILTER_KIRSCH = 5,
CMP_NODE_FILTER_SHADOW = 6,
CMP_NODE_FILTER_SHARP_DIAMOND = 7,
} CMPNodeFilterMethod;
/* Plane track deform node. */
enum {

View File

@ -64,9 +64,9 @@ class FilterOperation : public NodeOperation {
GPU_shader_unbind();
}
int get_filter_method()
CMPNodeFilterMethod get_filter_method()
{
return bnode().custom1;
return (CMPNodeFilterMethod)bnode().custom1;
}
float3x3 get_filter_kernel()
@ -75,41 +75,41 @@ class FilterOperation : public NodeOperation {
* return the kernel in the X direction, while the kernel in the Y direction will be computed
* inside the shader by transposing the kernel in the X direction. */
switch (get_filter_method()) {
case CMP_FILT_SOFT: {
case CMP_NODE_FILTER_SOFT: {
const float kernel[3][3] = {{1.0f / 16.0f, 2.0f / 16.0f, 1.0f / 16.0f},
{2.0f / 16.0f, 4.0f / 16.0f, 2.0f / 16.0f},
{1.0f / 16.0f, 2.0f / 16.0f, 1.0f / 16.0f}};
return float3x3(kernel);
}
case CMP_FILT_SHARP_BOX: {
case CMP_NODE_FILTER_SHARP_BOX: {
const float kernel[3][3] = {
{-1.0f, -1.0f, -1.0f}, {-1.0f, 9.0f, -1.0f}, {-1.0f, -1.0f, -1.0f}};
return float3x3(kernel);
}
case CMP_FILT_LAPLACE: {
case CMP_NODE_FILTER_LAPLACE: {
const float kernel[3][3] = {{-1.0f / 8.0f, -1.0f / 8.0f, -1.0f / 8.0f},
{-1.0f / 8.0f, 1.0f, -1.0f / 8.0f},
{-1.0f / 8.0f, -1.0f / 8.0f, -1.0f / 8.0f}};
return float3x3(kernel);
}
case CMP_FILT_SOBEL: {
case CMP_NODE_FILTER_SOBEL: {
const float kernel[3][3] = {{1.0f, 0.0f, -1.0f}, {2.0f, 0.0f, -2.0f}, {1.0f, 0.0f, -1.0f}};
return float3x3(kernel);
}
case CMP_FILT_PREWITT: {
case CMP_NODE_FILTER_PREWITT: {
const float kernel[3][3] = {{1.0f, 0.0f, -1.0f}, {1.0f, 0.0f, -1.0f}, {1.0f, 0.0f, -1.0f}};
return float3x3(kernel);
}
case CMP_FILT_KIRSCH: {
case CMP_NODE_FILTER_KIRSCH: {
const float kernel[3][3] = {
{5.0f, -3.0f, -2.0f}, {5.0f, -3.0f, -2.0f}, {5.0f, -3.0f, -2.0f}};
return float3x3(kernel);
}
case CMP_FILT_SHADOW: {
case CMP_NODE_FILTER_SHADOW: {
const float kernel[3][3] = {{1.0f, 2.0f, 1.0f}, {0.0f, 1.0f, 0.0f}, {-1.0f, -2.0f, -1.0f}};
return float3x3(kernel);
}
case CMP_FILT_SHARP_DIAMOND: {
case CMP_NODE_FILTER_SHARP_DIAMOND: {
const float kernel[3][3] = {
{0.0f, -1.0f, 0.0f}, {-1.0f, 5.0f, -1.0f}, {0.0f, -1.0f, 0.0f}};
return float3x3(kernel);
@ -124,15 +124,15 @@ class FilterOperation : public NodeOperation {
const char *get_shader_name()
{
switch (get_filter_method()) {
case CMP_FILT_LAPLACE:
case CMP_FILT_SOBEL:
case CMP_FILT_PREWITT:
case CMP_FILT_KIRSCH:
case CMP_NODE_FILTER_LAPLACE:
case CMP_NODE_FILTER_SOBEL:
case CMP_NODE_FILTER_PREWITT:
case CMP_NODE_FILTER_KIRSCH:
return "compositor_edge_filter";
case CMP_FILT_SOFT:
case CMP_FILT_SHARP_BOX:
case CMP_FILT_SHADOW:
case CMP_FILT_SHARP_DIAMOND:
case CMP_NODE_FILTER_SOFT:
case CMP_NODE_FILTER_SHARP_BOX:
case CMP_NODE_FILTER_SHADOW:
case CMP_NODE_FILTER_SHARP_DIAMOND:
default:
return "compositor_filter";
}