Matplot: handle ARGB data 28/14028/2
Calixte DENIZET [Fri, 14 Mar 2014 14:46:25 +0000 (15:46 +0100)]
Change-Id: I7f4b697fb3af65bc68e0ea8192fb3040bde49ee3

scilab/modules/graphic_objects/includes/Matplot.h
scilab/modules/graphic_objects/src/cpp/NgonGridMatplotData.cpp
scilab/modules/graphic_objects/src/cpp/Texture.cpp
scilab/modules/graphics/help/en_US/2d_plot/Matplot.xml
scilab/modules/graphics/help/en_US/2d_plot/Matplot_properties.xml
scilab/modules/graphics/src/c/getHandleProperty/get_image_type_property.c
scilab/modules/graphics/src/c/getHandleProperty/set_image_type_property.c

index 02affb1..e9511b5 100644 (file)
@@ -55,7 +55,8 @@ typedef enum
     MATPLOT_RGB_444 = 8,
     MATPLOT_RGB_555 = 9,
     MATPLOT_RGBA_4444 = 10,
-    MATPLOT_RGBA_5551 = 11
+    MATPLOT_RGBA_5551 = 11,
+    MATPLOT_ARGB = 12,
 } ImageType;
 
 typedef enum
index c4773c1..a650d55 100644 (file)
@@ -467,7 +467,7 @@ int NgonGridMatplotData::setImageType(int imagetype)
             {
                 grid[2] = (ySize - 1) * 3 + 1;
             }
-            else if (this->imagetype == MATPLOT_RGBA)
+            else if (this->imagetype == MATPLOT_RGBA || this->imagetype == MATPLOT_ARGB)
             {
                 grid[2] = (ySize - 1) * 4 + 1;
             }
@@ -480,7 +480,7 @@ int NgonGridMatplotData::setImageType(int imagetype)
                 }
                 grid[2] = (grid[2] - 1) / 3 + 1;
             }
-            else if (type == MATPLOT_RGBA)
+            else if (type == MATPLOT_RGBA || type == MATPLOT_ARGB)
             {
                 if ((grid[2] - 1) % 4 != 0)
                 {
index 5260a5e..c88ecff 100644 (file)
@@ -67,6 +67,7 @@ bool Texture::getImage(void const * data, const int numElements, const DataType
             }
             break;
         case MATPLOT_RGBA :
+        case MATPLOT_ARGB :
             switch (datatype)
             {
                 case MATPLOT_HM3_Char :
@@ -427,7 +428,187 @@ bool Texture::getImage(void const * data, const int numElements, const DataType
                         ucdata[k + 1] = (((unsigned int)d[i]) >> 16) & 0xFF;
                         ucdata[k + 2] = (((unsigned int)d[i]) >> 8) & 0xFF;
                         ucdata[k + 3] = ((unsigned int)d[i]) & 0xFF;
-                        unsigned int k = 0;
+                        k += 4;
+                    }
+                    *gltype = MATPLOT_GL_RGBA_BYTE;
+                }
+            }
+            break;
+        }
+        case MATPLOT_ARGB :
+        {
+            switch (datatype)
+            {
+                case MATPLOT_HM3_Char :
+                case MATPLOT_HM3_UChar :
+                {
+                    const unsigned char * R = (const unsigned char *)data;
+                    const unsigned char * G = R + numElements;
+                    const unsigned char * B = G + numElements;
+                    unsigned char * ucdata = (unsigned char *) * dest;
+                    unsigned int k = 0;
+
+                    for (int i = 0; i < numElements; i++)
+                    {
+                        ucdata[k] = R[i];
+                        ucdata[k + 1] = G[i];
+                        ucdata[k + 2] = B[i];
+                        ucdata[k + 3] = 0xFF;
+                        k += 4;
+                    }
+                    *gltype = MATPLOT_GL_RGBA_BYTE;
+                    break;
+                }
+                case MATPLOT_HM4_Char :
+                case MATPLOT_HM4_UChar :
+                {
+                    const unsigned char * A = (const unsigned char *)data;
+                    const unsigned char * R = A + numElements;
+                    const unsigned char * G = R + numElements;
+                    const unsigned char * B = G + numElements;
+                    unsigned char * ucdata = (unsigned char *) * dest;
+                    unsigned int k = 0;
+
+                    for (int i = 0; i < numElements; i++)
+                    {
+                        ucdata[k] = R[i];
+                        ucdata[k + 1] = G[i];
+                        ucdata[k + 2] = B[i];
+                        ucdata[k + 3] = A[i];
+                        k += 4;
+                    }
+                    *gltype = MATPLOT_GL_RGBA_BYTE;
+                    break;
+                }
+                case MATPLOT_HM3_Double :
+                {
+                    const double * R = (const double *)data;
+                    const double * G = R + numElements;
+                    const double * B = G + numElements;
+                    float * fdata = (float *) * dest;
+                    unsigned int k = 0;
+
+                    for (int i = 0; i < numElements; i++)
+                    {
+                        fdata[k] = (float)R[i];
+                        fdata[k + 1] = (float)G[i];
+                        fdata[k + 2] = (float)B[i];
+                        fdata[k + 3] = 1.0f;
+                        k += 4;
+                    }
+                    *gltype = MATPLOT_GL_RGBA_FLOAT;
+                    break;
+                }
+                case MATPLOT_HM4_Double :
+                {
+                    const double * A = (const double *)data;
+                    const double * R = A + numElements;
+                    const double * G = R + numElements;
+                    const double * B = G + numElements;
+                    float * fdata = (float *) * dest;
+                    unsigned int k = 0;
+
+                    for (int i = 0; i < numElements; i++)
+                    {
+                        fdata[k] = (float)R[i];
+                        fdata[k + 1] = (float)G[i];
+                        fdata[k + 2] = (float)B[i];
+                        fdata[k + 3] = (float)A[i];
+                        k += 4;
+                    }
+                    *gltype = MATPLOT_GL_RGBA_FLOAT;
+                    break;
+                }
+                case MATPLOT_HM1_Char :
+                case MATPLOT_HM1_UChar :
+                case MATPLOT_UChar :
+                case MATPLOT_Char :
+                {
+                    const unsigned char * uc = (const unsigned char *)data;
+                    unsigned char * ucdata = (unsigned char *) * dest;
+
+                    for (int i = 0; i < size; i += 4)
+                    {
+                        ucdata[i] = uc[i + 1];
+                        ucdata[i + 1] = uc[i + 2];
+                        ucdata[i + 2] = uc[i + 3];
+                        ucdata[i + 3] = uc[i];
+                    }
+                    *gltype = MATPLOT_GL_RGBA_BYTE;
+                    break;
+                }
+                case MATPLOT_Int :
+                {
+                    const unsigned int * ui = (const unsigned int *)data;
+                    unsigned char * ucdata = (unsigned char *) * dest;
+                    unsigned int k = 0;
+
+                    for (int i = 0; i < numElements; i++)
+                    {
+                        ucdata[k] = (ui[i] >> 16) & 0xFF;
+                        ucdata[k + 1] = (ui[i] >> 8) & 0xFF;
+                        ucdata[k + 2] = ui[i] & 0xFF;
+                        ucdata[k + 3] = 0xFF;
+                        k += 4;
+                    }
+                    *gltype = MATPLOT_GL_RGBA_BYTE;
+                    break;
+                }
+                case MATPLOT_UInt :
+                {
+                    const unsigned int * ui = (const unsigned int *)data;
+                    unsigned char * ucdata = (unsigned char *) * dest;
+                    unsigned int k = 0;
+
+                    for (int i = 0; i < numElements; i++)
+                    {
+                        ucdata[k] = (ui[i] >> 16) & 0xFF;
+                        ucdata[k + 1] = (ui[i] >> 8) & 0xFF;
+                        ucdata[k + 2] = ui[i] & 0xFF;
+                        ucdata[k + 3] = (ui[i] >> 24) & 0xFF;
+                        k += 4;
+                    }
+                    *gltype = MATPLOT_GL_RGBA_BYTE;
+                    break;
+                }
+                case MATPLOT_Short :
+                {
+                    const unsigned short * us = (const unsigned short *)data;
+                    unsigned short * usdata = (unsigned short *) * dest;
+
+                    for (int i = 0; i < numElements; i++)
+                    {
+                        usdata[i] = (us[i] >> 12) | (us[i] << 4);
+                    }
+                    *gltype = MATPLOT_GL_RGBA_4444;
+                    break;
+                }
+                case MATPLOT_UShort :
+                {
+                    const unsigned short * us = (const unsigned short *)data;
+                    unsigned short * usdata = (unsigned short *) * dest;
+
+                    for (int i = 0; i < numElements; i++)
+                    {
+                        usdata[i] = (us[i] >> 15) | (us[i] << 1);
+                    }
+                    *gltype = MATPLOT_GL_RGBA_5551;
+                    break;
+                }
+                case MATPLOT_HM1_Double :
+                case MATPLOT_Double :
+                {
+                    const double * d = (const double *)data;
+                    unsigned char * ucdata = (unsigned char *) * dest;
+                    unsigned int k = 0;
+
+                    for (int i = 0; i < numElements; i++)
+                    {
+                        ucdata[k] = (((unsigned int)d[i]) >> 16) & 0xFF;
+                        ucdata[k + 1] = (((unsigned int)d[i]) >> 8) & 0xFF;
+                        ucdata[k + 2] = ((unsigned int)d[i]) & 0xFF;
+                        ucdata[k + 3] = (((unsigned int)d[i]) >> 24) & 0xFF;
+                        k += 4;
                     }
                     *gltype = MATPLOT_GL_RGBA_BYTE;
                 }
index 4015b61..53f2e51 100644 (file)
             <warning>
                 To update the Matplot data, the <literal>data</literal> field of the corresponding handle must be used.
             </warning>
+            <literal>data</literal> can be a matrix (or an hypermatrix) containing RGB, RGBA, ... data (see <link linkend="Matplot_properties">Matplot_properties</link>).
         </para>
         <para>
             Enter the command <code>Matplot()</code> to see a demo.
@@ -362,4 +363,15 @@ Matplot((1:xget("lastpattern")))
             </member>
         </simplelist>
     </refsection>
+    <refsection>
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>5.5.0</revnumber>
+                <revremark>
+                    <literal>data</literal> can now be a matrix (or an hypermatrix) containing RGB, RGBA, ... data (see <link linkend="Matplot_properties">Matplot_properties</link>).
+                </revremark>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index 4af7862..3ed336b 100644 (file)
@@ -82,7 +82,7 @@
                 <listitem>
                     <para>
                         this field defines the image type. It could be one of the values: "rgb", "rgba", "gray", "index",
-                        "red", "green", "blue", "rgb332", "rgb444", "rgb555", "rgba5551".
+                        "red", "green", "blue", "rgb332", "rgb444", "rgb555", "rgba5551", "argb".
                     </para>
                     <para>
                         Colors are determinated by the data type and by image_type:
                                 When image_type is equal to rgb5551, matrices of int16 or uint16 will give RGBA colors where each non-alpha components is wrote on 5 bits and the alpha component on 1 bit. For other data types, RGBA (8-8-8-8) data are converted into RGBA (5-5-5-1).
                             </para>
                         </listitem>
+                        <listitem>
+                            <para>
+                                When image_type is equal to argb, hypermat of int8 or uint8 will give the ARGB components, hypermat of doubles will give normalized ARGB components (values between 0 and 1), matrices of int8 or uint8 where number of rows is a multiple of 4 will give the RGB components, matrices of int32 will give ARGB colors, matrices of uint32 will give ARGB colors.
+                            </para>
+                        </listitem>
                     </itemizedlist>
                 </listitem>
             </varlistentry>
index 55cca4c..ca92ffb 100644 (file)
@@ -70,6 +70,8 @@ int get_image_type_property(void* _pvCtx, int iObjUID)
             return sciReturnString(_pvCtx, "rgb555");
         case MATPLOT_RGBA_5551 :
             return sciReturnString(_pvCtx, "rgba5551");
+        case MATPLOT_ARGB :
+            return sciReturnString(_pvCtx, "argb");
         default :
             Scierror(999, _("Wrong value for '%s' property.\n"), "image_type");
             return -1;
index ed4ef00..9c300f1 100644 (file)
@@ -59,6 +59,10 @@ int set_image_type_property(void* _pvCtx, int iObjUID, void* _pvData, int valueT
     {
         imagetype = (int)MATPLOT_RGBA;
     }
+    else if (stricmp((char*)_pvData, "argb") == 0)
+    {
+        imagetype = (int)MATPLOT_ARGB;
+    }
     else if (stricmp((char*)_pvData, "gray") == 0)
     {
         imagetype = (int)MATPLOT_GRAY;