title: Efficiently convert a BufferedImage to an IplImage
body: <p>I'm trying to do efficiently convert a BufferedImage to an IplImage... could you give me any hint about the jni part? </p>
  
  <p>Right now I do these steps:</p>
  
  <p>I get the rgbs from the BufferedImage and I send them to the jni code where I do the following:</p>
  
  <pre><code>IplImage* getIplImageFromIntArray(JNIEnv* env, jintArray array_data,
      jint width, jint height) {
  int *pixels = env-&gt;GetIntArrayElements(array_data, 0);
  if (pixels == 0) {      
      return 0;
  }
  IplImage *image = loadPixels(pixels, width, height);
  env-&gt;ReleaseIntArrayElements(array_data, pixels, 0);
  if (image == 0) {   
      return 0;
  }
  return image;}};
  </code></pre>
  
  <p>and</p>
  
  <pre><code>IplImage* loadPixels(int* pixels, int width, int height) {
  int x, y;
  IplImage *img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
  unsigned char* base = (unsigned char*) (img-&gt;imageData);
  unsigned char* ptr;
  for (y = 0; y &lt; height; y++) {
      ptr = base + y * img-&gt;widthStep;
      for (x = 0; x &lt; width; x++) {
          // blue
          ptr[3 * x] = pixels[x + y * width] &amp; 0xFF;
          // green
          ptr[3 * x + 1] = pixels[x + y * width] &gt;&gt; 8 &amp; 0xFF;
          // blue
          ptr[3 * x + 2] = pixels[x + y * width] &gt;&gt; 16 &amp; 0xFF;
      }
  }
  return img;}
  </code></pre>
  
  <p>But that is really slow... thank you for your help!</p>