title: Java SWT: Displaying image Pixel by Pixel but Blues look Yellow
body: <p>I am displaying an image Pixel by Pixel.  All the blues look yellow.  I suspect the issue is with the PalletteData or with the following line(The Pixel object just holds the int representation of the colour):</p>
  
  <pre><code>p = (pixel.Alpha&lt;&lt;24) | (pixel.Red&lt;&lt;16) | (pixel.Green&lt;&lt;8) | pixel.Blue;
  </code></pre>
  
  <p>Note: as the call is from Java to C++ accross JNI, there are some conversions:</p>
  
  <p>Each colour is read in to an unsigned char. Then it is converted to char to pass accross JNI. Then is read as a byte on the Java side. Then converted to Int  </p>
  
  <p>Here is the full listing. Can you see what my problem is? </p>
  
  <pre><code>            PaletteData palette=new PaletteData(0xff0000,0x00ff00,0xff);
              ImageData imageData = new ImageData(width, height,32,palette);
  
              int pixelVecLoc=0;
              for (int h = 0; h&lt;1300; h++)
              {
                  for (int w = 0; w&lt;1300; w++)
                  {
                      int p = 0;
                      Pixel pixel = pixelVec.get(pixelVecLoc);
                      p = (pixel.Alpha&lt;&lt;24) | (pixel.Red&lt;&lt;16) | (pixel.Green&lt;&lt;8) | pixel.Blue;                        
  
                      imageData.setPixel(w, h, p);
  
                      pixelVecLoc++;
                  }
              }
  
              imageData = imageData.scaledTo(600, 500);
              Image image = ImageDescriptor.createFromImageData(imageData).createImage();
              //Image image = new GVImageProcessingJNIWrapper().GetBMPFromGTX();
              e.gc.drawImage(image, 0, 0);
  </code></pre>