PDA

View Full Version : Accessing Memory Buffer



WK Ho
January 1, 2008, 05:08:18
Hi There
I am trying to access memory buffer after snapping in an image, below is the code I used:
tFrameHandlerSinkPtr pSink=FrameHandlerSink::create( eRGB32, 1 );//create a buf same as grabber
m_Grabber.setSinkType( pSink ); //set the grabbed image to copy to the sink created
pSink->setSnapMode( true );
//FrameTypeInfo info;
//pSink->getOutputFrameType( info );
m_Grabber.startLive( false );
pSink->snapImages(1);
// get pointer to the image data
smart_ptr<MemBuffer> pActiveBuf=pSink->getLastAcqMemBuffer();
// image buffer pixel format is set to eRGB32
/* Copied from sample
RGBQUAD* pbImgData = (RGBQUAD*)pActiveBuf->getPtr();

// Calculate the index of the upper left pixel
// Images are stored upside down in the image buffer
SIZE dim = pActiveBuf->getFrameType().dim;
int iOffsUpperLeft = (dim.cy-1) * dim.cx;

printf( "\nImage buffer pixel format is eRGB32\n" );
printf( "Pixel 1(RGBA): %d %d %d %d\n", pbImgData[iOffsUpperLeft].rgbRed,
pbImgData[iOffsUpperLeft].rgbGreen,
pbImgData[iOffsUpperLeft].rgbBlue,
pbImgData[iOffsUpperLeft].rgbReserved );
printf( "Pixel 2(RGBA): %d %d %d %d\n", pbImgData[iOffsUpperLeft+1].rgbRed,
pbImgData[iOffsUpperLeft+1].rgbGreen,
pbImgData[iOffsUpperLeft+1].rgbBlue,
pbImgData[iOffsUpperLeft+1].rgbReserved );

// overwrite first 3 pixels and save image to disk
// Set the first pixel to RED
pbImgData[iOffsUpperLeft].rgbRed = 0xff;
pbImgData[iOffsUpperLeft].rgbGreen = 0;
pbImgData[iOffsUpperLeft].rgbBlue = 0;
pbImgData[iOffsUpperLeft].rgbReserved = 0;

// Set the second pixel to GREEN
pbImgData[iOffsUpperLeft+1].rgbRed = 0;
pbImgData[iOffsUpperLeft+1].rgbGreen = 0xff;
pbImgData[iOffsUpperLeft+1].rgbBlue = 0;
pbImgData[iOffsUpperLeft+1].rgbReserved = 0;

// Set the third pixel to BLUE
pbImgData[iOffsUpperLeft+2].rgbRed = 0;
pbImgData[iOffsUpperLeft+2].rgbGreen = 0;
pbImgData[iOffsUpperLeft+2].rgbBlue = 0xff;
pbImgData[iOffsUpperLeft+2].rgbReserved = 0;

saveToFileBMP( *pActiveBuf, "RGB32.bmp" );
printf( "Image saved to file \"RGB32.bmp\"\n" );


I can compile it without error, however, when I run the program and it gives at the statement :
RGBQUAD* pbImgData = (RGBQUAD*)pActiveBuf->getPtr();


First-chance exception in CaptureTest.exe: 0xC0000005: Access Violation.

Before execute to the problem statemnt I get a message :

c:\csource\ic30\core\dshowlib\filtergraph.cpp(301) : Graph returned S_FALSE, so not yet started ...

What is the above message means?
Is it because the snap was fail and causes the error ?
I can view the dispalyed image before I try to snap in the image on the same program.

Thanks for your help.

WK Ho
January 1, 2008, 07:27:44
Hi There
I have found the reason because of the startLive before setting SINK. However, after I execute the application program normally and on exiting I goty memory leak?

Detected memory leaks!
Dumping objects ->
{190} normal block at 0x00DB88F8, 12 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00
c:\csource\ic30\core\dshowlibgeneral\smart_ptr.h(4 0) : {175} normal block at 0x00DB8270, 4 bytes long.
Data: < > 01 00 00 00
C:\CSource\ic30\core\TISUDSHL\iclocalization.cpp(8 8) : {174} normal block at 0x00DB8228, 4 bytes long.
Data: <`9' > 60 39 27 10
{173} normal block at 0x00DB81B0, 48 bytes long.
Data: < ' ' > 98 27 DB 00 B0 7F DB 00 98 27 DB 00 CC CD CD CD
{172} normal block at 0x00DB8128, 66 bytes long.
Data: < V C D E l e m > CD 00 56 00 43 00 44 00 45 00 6C 00 65 00 6D 00
{171} normal block at 0x00DB80B0, 48 bytes long.
Data: < ' ' > 98 27 DB 00 B0 7F DB 00 98 27 DB 00 CC CD CD CD
{170} normal block at 0x00DB8028, 66 bytes long.
Data: < V C D E l e m > CD 00 56 00 43 00 44 00 45 00 6C 00 65 00 6D 00
{169} normal block at 0x00DB7FB0, 48 bytes long.
Data: < ~ > B0 80 DB 00 B0 7E DB 00 B0 81 DB 00 CC CD CD CD


Any fix for this?

WK

Stefan Geissler
January 2, 2008, 11:17:13
Hi WK,

In order to avoid the memory leaks, the function DShowLib::ExitLibrary() should be called when your progam ends