1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2013 - Scilab Enterprises - Calixte DENIZET
4  *
5  * Copyright (C) 2012 - 2016 - Scilab Enterprises
6  *
7  * This file is hereby licensed under the terms of the GNU GPL v2.0,
8  * pursuant to article 5.3.4 of the CeCILL v.2.1.
9  * This file was originally licensed under the terms of the CeCILL v2.1,
10  * and continues to be available under such terms.
11  * For more information, see the COPYING file which you should have received
12  * along with this program.
13  *
14  */
15 
16 /*------------------------------------------------------------------------*/
17 /* file: set_image_type_property.c                                         */
18 /* desc : function to modify in Scilab the image_type field of             */
19 /*        a matplot handle                                                        */
20 /*------------------------------------------------------------------------*/
21 
22 #include "setHandleProperty.h"
23 #include "SetProperty.h"
24 #include "getPropertyAssignedValue.h"
25 #include "Scierror.h"
26 #include "localization.h"
27 #include "SetPropertyStatus.h"
28 
29 #include "getGraphicObjectProperty.h"
30 #include "setGraphicObjectProperty.h"
31 #include "graphicObjectProperties.h"
32 #include "os_string.h"
33 
34 #include "Matplot.h"
35 
36 /*------------------------------------------------------------------------*/
set_image_type_property(void * _pvCtx,int iObjUID,void * _pvData,int valueType,int nbRow,int nbCol)37 int set_image_type_property(void* _pvCtx, int iObjUID, void* _pvData, int valueType, int nbRow, int nbCol)
38 {
39     BOOL status = FALSE;
40     int imagetype = (int)MATPLOT_INDEX;
41     int type = -1;
42     int *piType = &type;
43 
44     if (valueType != sci_strings)
45     {
46         Scierror(999, _("Wrong type for '%s' property: String expected.\n"), "image_type");
47         return SET_PROPERTY_ERROR;
48     }
49 
50     getGraphicObjectProperty(iObjUID, __GO_TYPE__, jni_int, (void **)&piType);
51     if (type != __GO_MATPLOT__)
52     {
53         Scierror(999, _("Incompatible type for property %s.\n"), "image_type");
54         return SET_PROPERTY_ERROR;
55     }
56 
57     if (stricmp((char*)_pvData, "rgb") == 0)
58     {
59         imagetype = (int)MATPLOT_RGB;
60     }
61     else if (stricmp((char*)_pvData, "rgba") == 0)
62     {
63         imagetype = (int)MATPLOT_RGBA;
64     }
65     else if (stricmp((char*)_pvData, "argb") == 0)
66     {
67         imagetype = (int)MATPLOT_ARGB;
68     }
69     else if (stricmp((char*)_pvData, "gray") == 0)
70     {
71         imagetype = (int)MATPLOT_GRAY;
72     }
73     else if (stricmp((char*)_pvData, "index") == 0)
74     {
75         imagetype = (int)MATPLOT_INDEX;
76     }
77     else if (stricmp((char*)_pvData, "red") == 0)
78     {
79         imagetype = (int)MATPLOT_RED;
80     }
81     else if (stricmp((char*)_pvData, "green") == 0)
82     {
83         imagetype = (int)MATPLOT_GREEN;
84     }
85     else if (stricmp((char*)_pvData, "blue") == 0)
86     {
87         imagetype = (int)MATPLOT_BLUE;
88     }
89     else if (stricmp((char*)_pvData, "rgb332") == 0)
90     {
91         imagetype = (int)MATPLOT_RGB_332;
92     }
93     else if (stricmp((char*)_pvData, "rgb444") == 0)
94     {
95         imagetype = (int)MATPLOT_RGB_444;
96     }
97     else if (stricmp((char*)_pvData, "rgba4444") == 0)
98     {
99         imagetype = (int)MATPLOT_RGBA_4444;
100     }
101     else if (stricmp((char*)_pvData, "rgb555") == 0)
102     {
103         imagetype = (int)MATPLOT_RGB_555;
104     }
105     else if (stricmp((char*)_pvData, "rgba5551") == 0)
106     {
107         imagetype = (int)MATPLOT_RGBA_5551;
108     }
109     else
110     {
111         Scierror(999, _("Wrong value for '%s' property: Must be in the set {%s}.\n"), "image_type", "rgb, rgba, gray, index");
112         return SET_PROPERTY_ERROR;
113     }
114 
115     status = setGraphicObjectProperty(iObjUID, __GO_DATA_MODEL_MATPLOT_IMAGE_TYPE__, &imagetype, jni_int, 1);
116     if (status == TRUE)
117     {
118         return SET_PROPERTY_SUCCEED;
119     }
120     else
121     {
122         Scierror(999, _("Invalid image type for this handle.\n"));
123         return SET_PROPERTY_ERROR;
124     }
125 }
126 /*------------------------------------------------------------------------*/
127