Re: about Color Format transformation



On Tue, 12 Apr 2005 20:11:57 +0500, Yeghia Dolbakyan wrote:

As I read the code, it will accept RGB or YUV in and allow RGB out only.

Having said that your code will not reject YUV output if a downstream
filter proposes that (you don't check mtOut in CheckTransform), so a
renderer may still propose a YUV type if it doesn't want to connect up RGB
and this code will accept it.

Iain

> Hi Iain
>
> The code I have follows. Is there anything wrong?
>
> HRESULT CVideoProcessorFilter::GetMediaType(int iPosition, CMediaType
> *pMediaType)
> {
> // Is the input pin connected
> if (!m_pInput->IsConnected())
> return E_UNEXPECTED;
>
> // This should never happen
> if (iPosition < 0)
> return E_INVALIDARG;
>
> // Do we have more items to offer
> if (iPosition > 0)
> return VFW_S_NO_MORE_ITEMS;
>
> CheckPointer(pMediaType,E_POINTER);
>
> VIDEOINFOHEADER2 *pVih = (VIDEOINFOHEADER2
> *)pMediaType->AllocFormatBuffer(4096);
> memset(pVih, 0, sizeof(VIDEOINFOHEADER2));
> pVih->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
> pVih->bmiHeader.biWidth = 720;
> pVih->bmiHeader.biHeight = 576;
> pVih->bmiHeader.biBitCount = 24;
> pVih->bmiHeader.biPlanes = 1;
> pVih->bmiHeader.biCompression = BI_RGB;
> pVih->bmiHeader.biSizeImage = GetBitmapSize(&pVih->bmiHeader);
> pVih->bmiHeader.biClrImportant = 0;
>
> SetRect(&pVih->rcSource, 0, 0, 720, 576);
> SetRect(&pVih->rcTarget, 0, 0, 720, 576);
>
> pMediaType->SetType(&MEDIATYPE_Video);
> pMediaType->SetFormatType(&FORMAT_VideoInfo2);
> pMediaType->SetTemporalCompression(FALSE);
> pMediaType->SetFormat((BYTE *)pVih, sizeof(VIDEOINFOHEADER2));
>
> // Work out the GUID for the subtype from the header info.
> const GUID SubTypeGUID = GetBitmapSubtype(&pVih->bmiHeader);
> pMediaType->SetSubtype(&SubTypeGUID);
> pMediaType->SetSampleSize(pVih->bmiHeader.biSizeImage);
>
> return S_OK;
> }
>
>
> HRESULT CVideoProcessorFilter::CheckTransform(const CMediaType *mtIn, const
> CMediaType *mtOut)
> {
> CheckPointer(mtIn, E_POINTER);
> CheckPointer(mtOut, E_POINTER);
>
> BOOL bResult = FALSE;
> if (IsEqualGUID(*mtIn->Type(), MEDIATYPE_Video))
> {
> bResult = IsEqualGUID(*mtIn->Subtype(), MEDIASUBTYPE_RGB24) ||
> IsEqualGUID(*mtIn->Subtype(), MEDIASUBTYPE_RGB32) ||
> IsEqualGUID(*mtIn->Subtype(), MEDIASUBTYPE_YUY2);
> }
>
> return bResult ? NOERROR : E_FAIL;
> }
>
> BOOL CVideoProcessorFilter::CanPerformVideoProcessor(const CMediaType
> *pMediaType) const
> {
> CheckPointer(pMediaType,FALSE);
>
>
> return FALSE;
> }
>
> Regards
> Yeghia
>
> "Iain" <Iain@xxxxxxxxxxxxxxxxxx> wrote in message
> news:13pjrcnhacju6$.1brx4p7f94pwa$.dlg@xxxxxxxxxxxxx
>> On Mon, 11 Apr 2005 23:41:57 +0500, Yeghia Dolbakyan wrote:
>>
>>> Hi guys
>>>
>>> I have to develop transform filter which make conversion from YUY2 (or
>>> basicly any YUV format) to RGB24. My problem is that I don't understand
>>> what should I do to make my output pin report its type as RGB24. It
>>> always
>>> shows YUY2 (the same as input format). I need to work on the frame n RGB
>>> format.
>>>
>>> What you can offer me? Is there any similar sample (except of Microsoft's
>>> EZRGBxxx samples)
>>>
>>> Thanks for your help
>>>
>>> Regards
>>> Yeghia
>>
>> Simply put you need to do 2 things.
>>
>> IMpleement a GetMediaType Method and implement a CHeckTransform method.
>>
>> This is covered in 'Step 3. Support Media Type Negotiation' in the Writing
>> Transform Filters section of the docs.
>>
>> Iain
>> --
>> Iain Downs (DirectShow MVP)
>> Software Product Consultant
>> www.idcl.co.uk


--
Iain Downs (DirectShow MVP)
Software Product Consultant
www.idcl.co.uk
.



Relevant Pages

  • Re: Need help in converting YUV to RGB using OV7620
    ... Hope you guys can give me some advise on converting the YUV ... THEN consider doing colour conversion. ... the format is best described spatially as ... You cannot work out true RGB until 2nd Y and V has been acquired, ...
    (comp.arch.embedded)
  • Re: Color balance in YUV/YCbCr domain
    ... Colour balancing is selecting an area in the image that you know is ... If you know what scaling factors are needed to colour-balance the RGB ... So the operation that colour-balances a YUV ... Multiplying three 3x3 matrices together is *not* complicated. ...
    (sci.image.processing)
  • Re: Need help in converting YUV to RGB using OV7620
    ... >THEN consider doing colour conversion. ... >You cannot work out true RGB until 2nd Y and V has been acquired, ... >>The formula given in the data sheet to get YUV was as followed ... I did not do any gamma correction but basically I just convert the ...
    (comp.arch.embedded)
  • Re: C : how to export raw YUV to a file ?
    ... Hasn't someone written a PGP client that can ... | put the ugly stuff in headers where I don't have to look at it unless I ... I thought that some lib could directly export from YUV to png. ... I d just need to understand which format WritePNGexpect RGB data to ...
    (comp.programming)
  • Re: Using different background colors with rows
    ... Thanks again Iain. ... a custom color. ... I use a RGB color a lot, can I use this colour aswell? ... Switch them to Basic Syntax ...
    (microsoft.public.vb.crystal)

Quantcast