<varlistentry>
<term>name</term>
<listitem>
- <para>name of the color.</para>
+ <para>name of the color or matrix with names of the colors.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>rgb</term>
<listitem>
- <para>vector of RGB integer values of a color.</para>
+ <para>vector or matrix with 3 columns of RGB integer values of the colors.</para>
</listitem>
</varlistentry>
</variablelist>
<title>Description</title>
<para>
<literal>name2rgb</literal> returns the RGB values of a color given by its name. The result is
- a vector <literal>[r,g,b]</literal> where <literal>r</literal>, <literal>g</literal> and <literal>b</literal> are integers between 0 and 255
+ a vector or a matrix with 3 columns <literal>[r,g,b]</literal> where <literal>r</literal>, <literal>g</literal> and <literal>b</literal> are integers between 0 and 255
corresponding to colors components red, green and blue. As usual 0 means no intensity and
255 means all the intensity of the color.
</para>
</member>
</simplelist>
</refsection>
+ <refsection>
+ <title>History</title>
+ <revhistory>
+ <revision>
+ <revnumber>6.0</revnumber>
+ <revremark>
+ Function <function>name2rgb</function> can now handle a single string and a matrix of strings.
+ </revremark>
+ </revision>
+ </revhistory>
+ </refsection>
</refentry>
* http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
*
*/
+#include "MALLOC.h"
#include "gw_graphics.h"
#include "api_scilab.h"
#include "localization.h"
int* piAddr = NULL;
char* pstColor = NULL;
double color[3];
+ int i;
+ int nRows;
+ int nCols;
+ int nRowsCols;
+ char** pstColorMatrix = NULL;
+ double* pColor = NULL;
+
CheckInputArgument(pvApiCtx, 1, 1);
sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
return 1;
}
- if (isStringType(pvApiCtx, piAddr) == FALSE || isScalar(pvApiCtx, piAddr) == FALSE)
+ if (isStringType(pvApiCtx, piAddr) == FALSE)
{
Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1);
return 1;
}
- getAllocatedSingleString(pvApiCtx, piAddr, &pstColor);
- name2rgb(pstColor, color);
- freeAllocatedSingleString(pstColor);
-
- if (color[0] == -1 || color[1] == -1 || color[2] == -1)
+ if (isScalar(pvApiCtx, piAddr) == TRUE)
{
- createEmptyMatrix(pvApiCtx, 2);
+ getAllocatedSingleString(pvApiCtx, piAddr, &pstColor);
+ name2rgb(pstColor, color);
+ freeAllocatedSingleString(pstColor);
+
+ if (color[0] == -1 || color[1] == -1 || color[2] == -1)
+ {
+ createEmptyMatrix(pvApiCtx, 2);
+ }
+ else
+ {
+ createMatrixOfDouble(pvApiCtx, 2, 1, 3, color);
+ }
}
else
{
- createMatrixOfDouble(pvApiCtx, 2, 1, 3, color);
+ getAllocatedMatrixOfString(pvApiCtx, piAddr, &nRows, &nCols, &pstColorMatrix);
+ nRowsCols = nRows * nCols;
+ pColor = (double*)MALLOC(3 * nRowsCols * sizeof(double));
+ for (i = 0; i < nRowsCols; ++i)
+ {
+ name2rgb(pstColorMatrix[i], color);
+ if (color[0] == -1 || color[1] == -1 || color[2] == -1)
+ {
+ break;
+ }
+ pColor[i] = color[0];
+ pColor[i + nRowsCols] = color[1];
+ pColor[i + 2 * nRowsCols] = color[2];
+ }
+ freeAllocatedMatrixOfString(nRows, nCols, pstColorMatrix);
+ if (color[0] == -1 || color[1] == -1 || color[2] == -1)
+ {
+ createEmptyMatrix(pvApiCtx, 2);
+ FREE(pColor);
+ }
+ else
+ {
+ createMatrixOfDouble(pvApiCtx, 2, nRowsCols, 3, pColor);
+ FREE(pColor);
+ }
}
-
AssignOutputVariable(pvApiCtx, 1) = 2;
ReturnArguments(pvApiCtx);
return 0;
-}
\ No newline at end of file
+}
--- /dev/null
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - Scilab Enterprises - Juergen Koch
+//
+// This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- TEST WITH GRAPHIC -->
+assert_checkequal(name2rgb("red"), [255 0 0]);
+assert_checkequal(name2rgb("nocolor"), []);
+assert_checkequal(name2rgb(["red" "green"]), [255 0 0;0 255 0]);
+assert_checkequal(name2rgb(["red";"green"]), [255 0 0;0 255 0]);
+assert_checkequal(name2rgb(["red" "green";"blue" "black"]), [255 0 0;0 0 255;0 255 0;0 0 0]);
+assert_checkequal(name2rgb(["red" "green";"blue" "nocolor"]), []);
--- /dev/null
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - Scilab Enterprises - Juergen Koch
+//
+// This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- TEST WITH GRAPHIC -->
+
+assert_checkequal(name2rgb("red"), [255 0 0]);
+assert_checkequal(name2rgb("nocolor"), []);
+assert_checkequal(name2rgb(["red" "green"]), [255 0 0;0 255 0]);
+assert_checkequal(name2rgb(["red";"green"]), [255 0 0;0 255 0]);
+assert_checkequal(name2rgb(["red" "green";"blue" "black"]), [255 0 0;0 0 255;0 255 0;0 0 0]);
+assert_checkequal(name2rgb(["red" "green";"blue" "nocolor"]), []);