Difference between revisions of "Colormodel kelvin"

From The Foundry MODO SDK wiki
Jump to: navigation, search
Line 42: Line 42:
 
  GetUserInt (const char *prefKey, int defaultValue = 0)
 
  GetUserInt (const char *prefKey, int defaultValue = 0)
 
  {
 
  {
         int value = defaultValue;
+
         ...
        CLxReadUserValue ruvUser;
+
        if (ruvUser.Query (prefKey)) {
+
                value = ruvUser.GetInt ();
+
        }
+
+
        return value;
+
 
  }
 
  }
  
Line 59: Line 53:
 
  CKelvinColorModel::MinTemp () const
 
  CKelvinColorModel::MinTemp () const
 
  {
 
  {
        return GetUserInt (LXsUSER_VALUE_KELVIN_MIN_TEMP,
+
      ...
                static_cast<unsigned>(MIN_KELVIN));
+
 
  }
 
  }
 
   
 
   
Line 66: Line 59:
 
  CKelvinColorModel::MaxTemp () const
 
  CKelvinColorModel::MaxTemp () const
 
  {
 
  {
         return GetUserInt (LXsUSER_VALUE_KELVIN_MAX_TEMP,
+
         ...
                static_cast<unsigned>(MAX_KELVIN));
+
 
  }  
 
  }  
  
Line 82: Line 74:
 
         unsigned *imgY)
 
         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;
+
 
  }
 
  }
  
Line 108: Line 91:
 
         float *kelvin)
 
         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;
+
 
  }
 
  }
  
Line 125: Line 102:
 
         float *kelvin)
 
         float *kelvin)
 
  {
 
  {
         return LXe_OK;
+
         ...
 
  }
 
  }

Revision as of 22:58, 11 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)
{
       ...
}

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
{
      ...
}

       unsigned
CKelvinColorModel::MaxTemp () const
{
       ...
} 

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)
{
      ...
}

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)
{
       ...
}

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)
{
       ...
}