[cairo] copy cairo surface content to a bitmap cont'd..

John McCullough john at cobainltd.com
Thu Feb 18 08:33:55 PST 2010


Hi list,
I'd posted earlier today to ask about how to copy a cairo surface into a pre-existing buffer.

I've made some progress, as below, but my bitmap is rendered upside down and back to front.  This is to be expected, due to the bottom up format of the Bitmap format<http://en.wikipedia.org/wiki/BMP_file_format>.

Flipping every bitmap is expensive, and I'd like to avoid doing that.  My use of cairo is probably incorrect, I think I may need to use an alternative to creating a DIB etc..

I'm writing a DirectShow Source Filter<http://msdn.microsoft.com/en-us/library/dd758088(VS.85).aspx>, so I can't use device contexts, I can only render to a pre-allocated memory block, as acquired from IMediaSample<http://msdn.microsoft.com/en-us/library/dd407001(VS.85).aspx>.

I allocate a cairo surface like this:

                m_pSurface  = cairo_win32_surface_create_with_dib(CAIRO_FORMAT_ARGB32, m_nImageWidth, m_nImageHeight );

And I reuse this each frame.

At render time, when I'm writing to the supplied buffer, I do so like this:

void SrcOutPin::DrawFrame( BYTE* pData, LONG lDataLen )
{
      cairo_surface_t *       pSurface    = NULL;
      unsigned char *         pBuffer     = NULL;


      if( m_pSurface && m_pCR )
      {
            //
            // { cairo specific drawing stuff here }
//

            // Get a byte ptr to the surface data
            cairo_surface_t * pSurface    = cairo_win32_surface_get_image( m_pSurface );
            unsigned char * pBuffer       = cairo_image_surface_get_data( pSurface );

            memcpy( (void*)pData, (const void*) pBuffer, lDataLen );

            m_lFrameCount++;
      }
}

While this memcpy succeeds, the bitmap is upside down and back to front.

To my question:
Windows has many functions (e.g. StretchBlt<http://msdn.microsoft.com/en-us/library/ms940373.aspx>) to solve this problem when working with device contexts, but not when working with memory buffers (to my knowledge).

Since I can't use a device context in this instance, is there another, more suitable method to use in order to achieve what I need ???

thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cairographics.org/archives/cairo/attachments/20100218/3fa27e1b/attachment.html 


More information about the cairo mailing list