exchanging 2 memory positions

Posted by Jordi on Stack Overflow See other posts from Stack Overflow or by Jordi
Published on 2010-04-01T07:34:48Z Indexed on 2010/04/01 7:43 UTC
Read the original article Hit count: 311

Filed under:
|
|
|

I am working with OpenCV and Qt, Opencv use BGR while Qt uses RGB , so I have to swap those 2 bytes for very big images.

There is a better way of doing the following? I can not think of anything faster but looks so simple and lame...

    int width = iplImage->width;
 int height = iplImage->height;

 uchar *iplImagePtr = (uchar *) iplImage->imageData;
 uchar buf;
 int limit = height * width;

 for (int y = 0; y < limit; ++y) {
  buf = iplImagePtr[2];
  iplImagePtr[2] = iplImagePtr[0];
  iplImagePtr[0] = buf;
  iplImagePtr += 3;
 }

 QImage img((uchar *) iplImage->imageData, width, height,
     QImage::Format_RGB888);

© Stack Overflow or respective owner

Related posts about c++

Related posts about opencv