summaryrefslogtreecommitdiff
path: root/src/nuke/OCIOLookTransform/OCIOLookTransform.h
blob: 9526bfa455d4958537bdab4c0134da57de175c3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#ifndef INCLUDED_OCIO_NUKE_COLORSPACECONVERSION_H_
#define INCLUDED_OCIO_NUKE_COLORSPACECONVERSION_H_

// Include these early, for Nuke's headers under gcc 4.4.2.
#include <memory>
#include <cstdarg>

#include <DDImage/PixelIop.h>
#include <DDImage/Row.h>
#include <DDImage/Knob.h>

#include <OpenColorIO/OpenColorIO.h>
namespace OCIO = OCIO_NAMESPACE;


/*!
 * Iop that uses OpenColorIO to perform colorspace conversions
 */
class OCIOLookTransform : public DD::Image::PixelIop {

    protected:

        bool m_hasColorSpaces; //!< Were colorspaces found for both input and output? If not, always error.
        
        std::string m_look;
        std::string m_lookhelp;
        
        int m_dirIndex;
        int m_inputColorSpaceIndex;
        int m_outputColorSpaceIndex;
        
        std::vector<std::string> m_colorSpaceNames; //!< list of input and output colorspace names (memory for const char* s below)
        std::vector<const char*> m_inputColorSpaceCstrNames; //!< list for the pulldown list knob (used raw)
        std::vector<const char*> m_outputColorSpaceCstrNames;
        
        bool m_ignoreErrors;
        
        OCIO::ConstContextRcPtr getLocalContext();
        
        OCIO::ConstProcessorRcPtr m_processor;
        
        /*! Controlled by hidden "version" knob, incremented to redraw image */
        int m_reload_version;
    public:

        OCIOLookTransform(Node *node);

        virtual ~OCIOLookTransform();

        // These are public so the nuke wrapper can introspect into it
        // TODO: use 'friend' instead
        std::string m_contextKey1;
        std::string m_contextValue1;
        std::string m_contextKey2;
        std::string m_contextValue2;
        std::string m_contextKey3;
        std::string m_contextValue3;
        std::string m_contextKey4;
        std::string m_contextValue4;
        
        static const DD::Image::Op::Description description;

        /*! Return the command name that will be stored in Nuke scripts. */
        virtual const char *Class() const;

        /*!
         * Return a name for this class that will be shown to the user. The
         * default implementation returns Class(). You can return a different
         * (ie more user-friendly) name instead here, and there is no need for
         * this to be unique.
         * 
         * Nuke currently will remove any trailing digits and underscores from
         * this and add a new number to make a unique name for the new node.
         * 
         * \return "OCIOLookTransform"
         */
        virtual const char *displayName() const;

        /*!
         * Return help information for this node. This information is in the
         * pop-up window that the user gets when they hit the [?] button in
         * the lower-left corner of the control panel.
         */
        virtual const char *node_help() const;

        /*!
         * Define the knobs that will be presented in the control panel.
         */
        virtual void knobs(DD::Image::Knob_Callback f);

        /*!
         * Specify the channels required from input n to produce the channels
         * in mask by modifying mask in-place. (At least one channel in the
         * input is assumed.)
         *
         * Since colorspace conversions can have channel cross-talk, any rgb
         * output channel requires all its rgb bretheren. (Non-rgb
         * are passed through.)
         */
        virtual void in_channels(int n, DD::Image::ChannelSet& mask) const;

        /*!
         * Calculate the output pixel data.
         * \param rowY vertical line number
         * \param rowX inclusive left bound
         * \param rowXBound exclusive right bound
         * \param outputChannels a subset of out_channels(), the required channels to be produced
         */
        virtual void pixel_engine(
            const DD::Image::Row& in,
            int rowY, int rowX, int rowXBound,
            DD::Image::ChannelMask outputChannels,
            DD::Image::Row& out);

    protected:

        /*!
         * Check that colorspaces are available, and that the transform
         * is not a noop. (As OCIO whether a given transform is a noop, since it
         * can do more analysis than just name matching.)
         */
        virtual void _validate(bool for_real);
        
        /*!
         * Ensure Node hash is reflects all parameters
         */
        virtual void append(DD::Image::Hash& nodehash);

        /*!
         * Hide and show UI elements based on other parameters.
         Also handles reload button
         */
        virtual int knob_changed(DD::Image::Knob* k);

};


static DD::Image::Op* build(Node *node);

#endif // INCLUDED_OCIO_NUKE_COLORSPACECONVERSION_H_