Writepixels() gives me BGR upside-down image
Posted: 2009-01-23T06:44:33-07:00
I'm writing a Directshow source filter in VC++. It collects bmp files from a directory and saves an AVI from them. I've selected ImageMagick to crop and unsharp the images a bit.
The DS filter needs a BYTE buffer with pixel data to save a frame, so I tried to fill it with writepixels(). When I do this, the resulting video contains the images upside down and Red and Blue channels swapped. The code is simple as:
The original bmp file is OK. When I write it back with img.write(), the result is also OK. When I open the imagefile without imagemagick, and put the bitmap data into pData, the AVI file is correct, too. (But I don't want to save the image after imagemagick operations, and open it again, the filter must be fast as possible.)
Maybe something simple, I might missed something. I'm a C# programmer, but with this DS filter I have to use c++. So I'm not too experienced with c++, I can't figure it out, why. I can only think because of writepixels().
Thanks for suggestions
The DS filter needs a BYTE buffer with pixel data to save a frame, so I tried to fill it with writepixels(). When I do this, the resulting video contains the images upside down and Red and Blue channels swapped. The code is simple as:
Code: Select all
BYTE * pData;
pSample->GetPointer(&pData); //pSample is IMediaSample
img.read((LPCTSTR)CurrentFile);
img.crop(Geometry(CropSettings.width , CropSettings.height,CropSettings.xoff , CropSettings.yoff ));
img.unsharpmask(UnsharpSettings.radius , UnsharpSettings.sigma , UnsharpSettings.amount , UnsharpSettings.threshold );
MagickCore::PixelPacket *pp = img.getPixels (0,0,img.columns (),img.rows());
img.writePixels(MagickCore::RGBQuantum,pData);
The original bmp file is OK. When I write it back with img.write(), the result is also OK. When I open the imagefile without imagemagick, and put the bitmap data into pData, the AVI file is correct, too. (But I don't want to save the image after imagemagick operations, and open it again, the filter must be fast as possible.)
Maybe something simple, I might missed something. I'm a C# programmer, but with this DS filter I have to use c++. So I'm not too experienced with c++, I can't figure it out, why. I can only think because of writepixels().
Thanks for suggestions