Difference between revisions of "Colormodel kelvin"

From The Foundry MODO SDK wiki
Jump to: navigation, search
Line 14: Line 14:
  
 
===[[Server_Tags|Server tags]]===
 
===[[Server_Tags|Server tags]]===
 +
 +
This function declares some basic information about the server.
  
 
  LXtTagInfoDesc CKelvinColorModel::descInfo[] = {
 
  LXtTagInfoDesc CKelvinColorModel::descInfo[] = {
Line 22: Line 24:
 
         { 0 }
 
         { 0 }
 
  };
 
  };
 
This function declares some basic information about the server.
 
  
 
===[[Initialize_(index)|Intialization]]===
 
===[[Initialize_(index)|Intialization]]===
 +
 +
This function exports the server we've created based on the CKelvinColorModel class.
  
 
         void
 
         void
Line 33: Line 35:
 
  }
 
  }
  
This function exports the server we've created based on the CKelvinColorModel class.
+
===Helper Functions===
  
Helper Functions
+
This is a helper function that queries the user for a value.
  
 
         static int
 
         static int
Line 49: Line 51:
 
  }
 
  }
  
This is a helper function that queries the user for a value.
+
These are helper functions that return the constants that indicate that indicate the minimum and maximum values of the color model
  
 
  static const char* LXsUSER_VALUE_KELVIN_MIN_TEMP = "kelvinMinTemp";
 
  static const char* LXsUSER_VALUE_KELVIN_MIN_TEMP = "kelvinMinTemp";
Line 68: Line 70:
 
  }  
 
  }  
  
These are helper functions that return the constants that indicate that indicate the minimum and maximum values of the color model
+
This function calculates imgX and imgY in (0..imgW, 0..imgH), from hsv color components on the plane specified by xAxis, yAxis.
  
 
         LxResult
 
         LxResult
Line 92: Line 94:
 
  }
 
  }
  
This function calculates imgX and imgY in (0..imgW, 0..imgH), from hsv color components on the plane specified by xAxis, yAxis.
+
This function calculates color model components hsv using imgX and imgY in [0, 1], on the plane specified by xAxis, yAxis.
 +
NOTE: The other axis (the one that is neither x nor y) component value should already be set by the last bar selection or the initial color load.
  
 
         LxResult  
 
         LxResult  
Line 114: Line 117:
 
  }
 
  }
  
This function calculates color model components hsv using imgX and imgY in [0, 1], on the plane specified by xAxis, yAxis.
+
This function returns a clean vector so the color picker can drawn the horizontal strip properly.  For hue, this is 0,1,1, for saturation we set the value to 1 but leave the rest alone,, and for value it's always 0,0,0.
NOTE: The other axis (the one that is neither x nor y) component value should already be set by the last bar selection or the initial color load.
+
  
 
         LxResult
 
         LxResult
Line 125: Line 127:
 
         return LXe_OK;
 
         return LXe_OK;
 
  }
 
  }
 
This function returns a clean vector so the color picker can drawn the horizontal strip properly.  For hue, this is 0,1,1, for saturation we set the value to 1 but leave the rest alone,, and for value it's always 0,0,0.
 

Revision as of 21:44, 10 September 2013

Colormodel_kelvin is a basic example plugin. This wiki page is intended as a walkthrough of the code in order to help you better understand the SDK.

When installed, this plugin adds a color model that enables picking colors using a Kelvin color temperature component.

Kelvin shot1.png

The Kelvin color model

Code Walkthrough

Class Declarations

There are two class declarations here. The first function inherits from CLxLuxologyLogMessage, which is the same as inheriting from ClxLogMessage but with an added Luxology copyright. We inherit from this class in order to write out to the log. The second function inherits from CLxImpl_ColorModel because it has the functions we need in order to create our color model, which we want the CKelvinColorModel to create. It first declares a log object for the color model and then declares a Tag interface description so that the server can get a name and information. Following that, it redeclares some of the virtual functions declared in CLxImpl_ColorModel so that it can create a color model with the values it wants.

Server tags

This function declares some basic information about the server.

LXtTagInfoDesc	 CKelvinColorModel::descInfo[] = {
       { LXsLOD_CLASSLIST,          LXa_COLORMODEL       },
       { LXsSRV_USERNAME,	     "Kelvin"             },
       { LXsSRV_LOGSUBSYSTEM,	     "kelvin-color-model" },
       { LXsCOLORMODEL_VALUEPRESET, "0:kelvin"	          },
       { 0 }
};

Intialization

This function exports the server we've created based on the CKelvinColorModel class.

       void
initialize ()
{
       LXx_ADD_SERVER (ColorModel, CKelvinColorModel, "kelvin_color_model");
}

Helper Functions

This is a helper function that queries the user for a value.

       static int
GetUserInt (const char *prefKey, int defaultValue = 0)
{
       int	value = defaultValue;
       CLxReadUserValue ruvUser;
       if (ruvUser.Query (prefKey)) {
               value = ruvUser.GetInt ();
       }

       return value;
}

These are helper functions that return the constants that indicate that indicate the minimum and maximum values of the color model

static const char* LXsUSER_VALUE_KELVIN_MIN_TEMP	= "kelvinMinTemp";
static const char* LXsUSER_VALUE_KELVIN_MAX_TEMP	= "kelvinMaxTemp";

       unsigned
CKelvinColorModel::MinTemp () const
{
       return GetUserInt (LXsUSER_VALUE_KELVIN_MIN_TEMP,
               static_cast<unsigned>(MIN_KELVIN));
}

       unsigned
CKelvinColorModel::MaxTemp () const
{
       return GetUserInt (LXsUSER_VALUE_KELVIN_MAX_TEMP,
               static_cast<unsigned>(MAX_KELVIN));
} 

This function calculates imgX and imgY in (0..imgW, 0..imgH), from hsv color components on the plane specified by xAxis, yAxis.

       LxResult
CKelvinColorModel::colm_ToSlicePos (
       unsigned	 xAxis,
       unsigned	 yAxis,
       unsigned	 imgW,
       unsigned	 imgH,
       const float	*kelvin,
       unsigned	*imgX,
       unsigned	*imgY)
{
       float minTemp = static_cast<float>(MinTemp ());
       float maxTemp = static_cast<float>(MaxTemp ());
       float kelvinRange = maxTemp - minTemp;
       float x = (*kelvin - minTemp) / kelvinRange;
       float y = 0.5f;

       *imgX = static_cast<unsigned>(LXxCLAMP (x, 0, 1) * imgW);
       *imgY = static_cast<unsigned>(LXxCLAMP (y, 0, 1) * imgH);

       return LXe_OK;
}

This function calculates color model components hsv using imgX and imgY in [0, 1], on the plane specified by xAxis, yAxis. NOTE: The other axis (the one that is neither x nor y) component value should already be set by the last bar selection or the initial color load.

       LxResult 
CKelvinColorModel::colm_FromSlicePos (
       unsigned	 xAxis,
       unsigned	 yAxis,
       unsigned	 imgW,
       unsigned	 imgH,
       unsigned	 imgX,
       unsigned	 imgY,
       float		*downVec,
       float		*kelvin)
{
       float minTemp = static_cast<float>(MinTemp ());
       float maxTemp = static_cast<float>(MaxTemp ());
       float kelvinRange = maxTemp - minTemp;

       *kelvin = minTemp + (static_cast<float>(imgX) / imgW) * kelvinRange;

       return LXe_OK;
}

This function returns a clean vector so the color picker can drawn the horizontal strip properly. For hue, this is 0,1,1, for saturation we set the value to 1 but leave the rest alone,, and for value it's always 0,0,0.

       LxResult
CKelvinColorModel::colm_StripBaseVector (
       unsigned	 axis,
       int		 dynamic,
       float		*kelvin)
{
       return LXe_OK;
}