Fix (??) bug with textures on win 32 67/12767/2
Calixte DENIZET [Tue, 1 Oct 2013 08:40:41 +0000 (10:40 +0200)]
Change-Id: Ie048c100c96ea6b663ec89ca3883ab8f18180dd3

scilab/modules/graphic_objects/includes/ColorComputer.hxx
scilab/modules/graphic_objects/src/cpp/NgonGridMatplotData.cpp
scilab/modules/graphic_objects/src/cpp/Texture.cpp
scilab/modules/scirenderer/src/org/scilab/forge/scirenderer/implementation/jogl/texture/JoGLTextureManager.java
scilab/modules/scirenderer/src/org/scilab/forge/scirenderer/texture/DrawnTextureDataProvider.java
scilab/modules/scirenderer/src/org/scilab/forge/scirenderer/texture/TextureBufferedImage.java

index 806f1dd..3de6034 100644 (file)
@@ -184,7 +184,10 @@ public :
         }
         else
         {
-            *rc = ((unsigned char)(color[0] * 255) << 24) | ((unsigned char)(color[1] * 255) << 16) | ((unsigned char)(color[2] * 255) << 8) | 0xFF;
+            returnedColor[0] = (unsigned char)(color[0] * 255);
+            returnedColor[1] = (unsigned char)(color[1] * 255);
+            returnedColor[2] = (unsigned char)(color[2] * 255);
+            returnedColor[3] = 0xFF;
         }
     }
 
index 36eab04..c4773c1 100644 (file)
@@ -647,7 +647,7 @@ void NgonGridMatplotData::setImageData(void const* data, const int numElements)
     void * dest = this->data;
     if (this->imagetype == MATPLOT_INDEX)
     {
-        this->gltype = MATPLOT_GL_RGBA;
+        this->gltype = MATPLOT_GL_RGBA_BYTE;
     }
     else if (Texture::getImage(data, numElements, this->datatype, this->imagetype, &(this->data), &(this->dataSize), &(this->gltype)))
     {
index a658be1..5260a5e 100644 (file)
@@ -171,13 +171,17 @@ bool Texture::getImage(void const * data, const int numElements, const DataType
                     const unsigned char * R = (const unsigned char *)data;
                     const unsigned char * G = R + numElements;
                     const unsigned char * B = G + numElements;
-                    unsigned int * uidata = (unsigned int *) * dest;
+                    unsigned char * ucdata = (unsigned char *) * dest;
+                    unsigned int k = 0;
 
                     for (int i = 0; i < numElements; i++)
                     {
-                        uidata[i] = (R[i] << 24) | (G[i] << 16) | (B[i] << 8) | 0xFF;
+                        ucdata[k] = R[i];
+                        ucdata[k + 1] = G[i];
+                        ucdata[k + 2] = B[i];
+                        k += 3;
                     }
-                    *gltype = MATPLOT_GL_RGBA;
+                    *gltype = MATPLOT_GL_RGB;
                     break;
                 }
                 case MATPLOT_HM3_Double :
@@ -210,27 +214,35 @@ bool Texture::getImage(void const * data, const int numElements, const DataType
                 case MATPLOT_Int :
                 {
                     const unsigned int * ui = (const unsigned int *)data;
-                    unsigned int * uidata = (unsigned int *) * dest;
+                    unsigned char * ucdata = (unsigned char *) * dest;
+                    unsigned int k = 0;
 
                     for (int i = 0; i < numElements; i++)
                     {
-                        uidata[i] = (ui[i] << 8) | 0xFF;
+                        ucdata[k] = (ui[i] >> 16) & 0xFF;
+                        ucdata[k + 1] = (ui[i] >> 8) & 0xFF;
+                        ucdata[k + 2] = ui[i] & 0xFF;
+                        k += 3;
                     }
 
-                    *gltype = MATPLOT_GL_RGBA;
+                    *gltype = MATPLOT_GL_RGB;
                     break;
                 }
                 case MATPLOT_UInt :
                 {
                     const unsigned int * ui = (const unsigned int *)data;
-                    unsigned int * uidata = (unsigned int *) * dest;
+                    unsigned char * ucdata = (unsigned char *) * dest;
+                    unsigned int k = 0;
 
                     for (int i = 0; i < numElements; i++)
                     {
-                        uidata[i] = ui[i] | 0xFF;
+                        ucdata[k] = (ui[i] >> 24) & 0xFF;
+                        ucdata[k + 1] = (ui[i] >> 16) & 0xFF;
+                        ucdata[k + 2] = (ui[i] >> 8) & 0xFF;
+                        k += 3;
                     }
 
-                    *gltype = MATPLOT_GL_RGBA;
+                    *gltype = MATPLOT_GL_RGB;
                     break;
                 }
                 case MATPLOT_Short :
@@ -249,13 +261,17 @@ bool Texture::getImage(void const * data, const int numElements, const DataType
                 case MATPLOT_Double :
                 {
                     const double * d = (const double *)data;
-                    unsigned int * uidata = (unsigned int *) * dest;
+                    unsigned char * ucdata = (unsigned char *) * dest;
+                    unsigned int k = 0;
 
                     for (int i = 0; i < numElements; i++)
                     {
-                        uidata[i] = (((unsigned int)d[i]) << 8) | 0xFF;
+                        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;
+                        k += 3;
                     }
-                    *gltype = MATPLOT_GL_RGBA;
+                    *gltype = MATPLOT_GL_RGB;
                     break;
                 }
             }
@@ -271,13 +287,18 @@ bool Texture::getImage(void const * data, const int numElements, const DataType
                     const unsigned char * R = (const unsigned char *)data;
                     const unsigned char * G = R + numElements;
                     const unsigned char * B = G + numElements;
-                    unsigned int * uidata = (unsigned int *) * dest;
+                    unsigned char * ucdata = (unsigned char *) * dest;
+                    unsigned int k = 0;
 
                     for (int i = 0; i < numElements; i++)
                     {
-                        uidata[i] = (R[i] << 24) | (G[i] << 16) | (B[i] << 8) | 0xFF;
+                        ucdata[k] = R[i];
+                        ucdata[k + 1] = G[i];
+                        ucdata[k + 2] = B[i];
+                        ucdata[k + 3] = 0xFF;
+                        k += 4;
                     }
-                    *gltype = MATPLOT_GL_RGBA;
+                    *gltype = MATPLOT_GL_RGBA_BYTE;
                     break;
                 }
                 case MATPLOT_HM4_Char :
@@ -287,13 +308,18 @@ bool Texture::getImage(void const * data, const int numElements, const DataType
                     const unsigned char * G = R + numElements;
                     const unsigned char * B = G + numElements;
                     const unsigned char * A = B + numElements;
-                    unsigned int * uidata = (unsigned int *) * dest;
+                    unsigned char * ucdata = (unsigned char *) * dest;
+                    unsigned int k = 0;
 
                     for (int i = 0; i < numElements; i++)
                     {
-                        uidata[i] = (R[i] << 24) | (G[i] << 16) | (B[i] << 8) | A[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;
+                    *gltype = MATPLOT_GL_RGBA_BYTE;
                     break;
                 }
                 case MATPLOT_HM3_Double :
@@ -345,19 +371,35 @@ bool Texture::getImage(void const * data, const int numElements, const DataType
                 case MATPLOT_Int :
                 {
                     const unsigned int * ui = (const unsigned int *)data;
-                    unsigned int * uidata = (unsigned int *) * dest;
+                    unsigned char * ucdata = (unsigned char *) * dest;
+                    unsigned int k = 0;
 
                     for (int i = 0; i < numElements; i++)
                     {
-                        uidata[i] = (ui[i] << 8) | 0xFF;
+                        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;
+                    *gltype = MATPLOT_GL_RGBA_BYTE;
                     break;
                 }
                 case MATPLOT_UInt :
                 {
-                    memcpy(*dest, data, size);
-                    *gltype = MATPLOT_GL_RGBA;
+                    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] >> 24) & 0xFF;
+                        ucdata[k + 1] = (ui[i] >> 16) & 0xFF;
+                        ucdata[k + 2] = (ui[i] >> 8) & 0xFF;
+                        ucdata[k + 3] = ui[i] & 0xFF;
+                        k += 4;
+                    }
+                    *gltype = MATPLOT_GL_RGBA_BYTE;
                     break;
                 }
                 case MATPLOT_Short :
@@ -376,14 +418,18 @@ bool Texture::getImage(void const * data, const int numElements, const DataType
                 case MATPLOT_Double :
                 {
                     const double * d = (const double *)data;
-                    unsigned int * uidata = (unsigned int *) * dest;
+                    unsigned char * ucdata = (unsigned char *) * dest;
+                    unsigned int k = 0;
 
                     for (int i = 0; i < numElements; i++)
                     {
-                        uidata[i] = (unsigned int)d[i];
+                        ucdata[k] = (((unsigned int)d[i]) >> 24) & 0xFF;
+                        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;
                     }
-                    *gltype = MATPLOT_GL_RGBA;
-                    break;
+                    *gltype = MATPLOT_GL_RGBA_BYTE;
                 }
             }
             break;
@@ -483,7 +529,7 @@ bool Texture::getImage(void const * data, const int numElements, const DataType
         case MATPLOT_INDEX :
         {
             memcpy(*dest, data, size);
-            *gltype = MATPLOT_GL_RGBA;
+            *gltype = MATPLOT_GL_RGBA_BYTE;
             break;
         }
         case MATPLOT_RED :
index 3d14698..16d9246 100644 (file)
@@ -666,7 +666,7 @@ public class JoGLTextureManager implements TextureManager {
                     break;
                 case RGBA:
                     this.internalFormat = GL2.GL_RGBA;
-                    setPixelFormat(GL2.GL_RGBA);
+                    setPixelFormat(GL.GL_RGBA);
                     setPixelType(GL2.GL_UNSIGNED_INT_8_8_8_8);
                     this.alignment = 4;
                     break;
index cfea28a..db228e8 100644 (file)
@@ -31,7 +31,7 @@ public class DrawnTextureDataProvider extends AbstractDataProvider<Texture> impl
 
     public DrawnTextureDataProvider(TextureDrawer textureDrawer) {
         this.textureDrawer = textureDrawer;
-        imageType = ImageType.RGBA;
+        imageType = ImageType.RGBA_BYTE;
         //reDraw();
     }
 
index 6c1701b..0d886aa 100644 (file)
@@ -49,7 +49,7 @@ public class TextureBufferedImage extends BufferedImage {
         int[] pixels = ((DataBufferInt) getRaster().getDataBuffer()).getData();
 
         for (int i = 0; i < pixels.length; i++) {
-            pixels[i] = (pixels[i] >> 24) | (pixels[i] << 8);
+            pixels[i] = (pixels[i] & 0xFF00FF00) | ((pixels[i] << 16) & 0x00FF0000) | ((pixels[i] >> 16) & 0xFF);
         }
 
         //updateFrame(this);
@@ -79,7 +79,7 @@ public class TextureBufferedImage extends BufferedImage {
         ByteBuffer buffer = ByteBuffer.allocate(pixels.length * 4);
         buffer.order(ByteOrder.nativeOrder());
         for (int i = 0; i < pixels.length; i++) {
-            buffer.putInt(((pixels[i] >> 24) & 0xFF) | ((pixels[i] << 8) & 0xFFFFFF00));
+            buffer.putInt((pixels[i] & 0xFF00FF00) | ((pixels[i] << 16) & 0x00FF0000) | ((pixels[i] >> 16) & 0xFF));
         }
         buffer.rewind();