Directshow source filter problem :
while developing the filter, I got confusion in the following....
pvi->bmiHeader.biCompression = BI_RGB; //This is the compression format
while using JPEG we have to use BI_JPEG and for PNG we have to change it as BI_PNG...
But I didnt do anything... if I made it like this for JPEG i got an error...
So what I have done is whatever may be the file format, I simply used the BI_RGB to represent all the types of file formats
regardless of the JPEG or pNg image.. BI_RGB may be acceptable due to OpenCV...
OpenCV may give the decompressed data as bytes from the file.. For Example if the JPEG is a compressed file..
if we are loading the JPEG image with cvLoadImage() fn ,openCV will loads the decompressed buffer of the JPEg file...
So we need not specify the things in pvi->bmiHeader.biCompression.
HRESULT CMySourceStream::GetMediaType(CMediaType* pMediaType)
{
try
{
HRESULT hr = S_OK;
CheckPointer(pMediaType,E_POINTER);
OutputDebugString("\n CMySourceStream::GetMediaType() fn");
ZeroMemory(pMediaType,sizeof(CMediaType));
VIDEOINFO *pvi = (VIDEOINFO*)pMediaType->AllocFormatBuffer(sizeof(VIDEOINFO));
if(m_pSrcImage == NULL)
{
m_pSrcImage = cvLoadImage("D:\\cartoon.png");
cvFlip(m_pSrcImage);
}
//check the file extension...
//if JPEG or jpg extension - BI_JPEG
//if BMP extension - BI_RGB
//if PNG extension - BI_PNG...
pvi->bmiHeader.biCompression = BI_RGB;
pvi->bmiHeader.biBitCount = (m_pSrcImage->nChannels * 8 );
pvi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pvi->bmiHeader.biWidth = m_pSrcImage->width;
pvi->bmiHeader.biHeight = m_pSrcImage->height;
pvi->bmiHeader.biPlanes = 1;
pvi->bmiHeader.biSizeImage = m_pSrcImage->imageSize;
pvi->bmiHeader.biClrImportant = 0;
SetRectEmpty(&(pvi->rcSource));
SetRectEmpty(&(pvi->rcTarget));
pMediaType->SetType(&MEDIATYPE_Video);
pMediaType->SetFormatType(&FORMAT_VideoInfo);
pMediaType->SetTemporalCompression(FALSE);
//pMediaType->SetSubtype(&MEDIASUBTYPE_Vi)
const GUID SubTypeGUID = GetBitmapSubtype(&pvi->bmiHeader);
pMediaType->SetSubtype(&SubTypeGUID);
pMediaType->SetSampleSize(pvi->bmiHeader.biSizeImage);
m_bmpInfo.bmiHeader = pvi->bmiHeader;
return hr;
}
catch(...)
{
OutputDebugString("\n Errror in CMySourceStream::GetMediaType() fn");
return E_FAIL;
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment