Hi,

Stefan Nobis <[EMAIL PROTECTED]> writes:

> > Lock the surface, write the data to it, then unlock it.
> 
> How do i write data to a surface (with the public API)? Maybe i'm
> quite blind, but i don't see it. The only way i found to write
> data to an existing surface is either with private API or via
> ImageProvider. What am i missing?

I'll repeat it once more then...

Lock the surface, then write your data to the memory address the
IDirectFBSurface::Lock() call gives you. Do this line-by-line, taking
into account the pitch that you obtained with the Lock call. Then
unlock the surface again.

Here's a short code example. It assumes you have a data buffer of
width x height pixels of the same pixelformat as the DirectFB surface.
For simplicity we also assume that your data buffer's pitch is equal
to width * bpp.

{
  char *src = buffer;   /*  buffer points to your data buffer  */
  char *dst;
  int   pitch;

  surface->Lock (surface, (void **) &dst, &pitch);

  for (y = 0; y < height; y++)
    {
      memcpy (dst, src, width * bpp);

      src += width * bpp;
      dst += pitch;
    }

  surface->UnLock (surface);
}


I've written this from the top of my head and didn't compile it. So if
there's a typo or something, please bear with me.

> If i have RGB24 or RGB32 surface then is the pitch cols*bpp? Or am
> i missing something here, too?

Yes, you are missing something. As I said, you cannot be sure that
this is the case. Not only might there be padding to assure that every
row starts on a word boundary, the surface might be laid out in memory
interleaved with rows of other surfaces. Simple rule: use pitch to
advance from one row to the next.

> BTW: DirectFB is a nice project and i really like it (for my
> project i looked to quite some libraries) -- but mixing one
> library with sparse documentation with another library with even
> less documentation sometimes become really frustrating (even more
> because it's not to easy to debug my application).

Help with the docs is always appreciated. Perhaps you want to
contribute to the tutorials? Perhaps a short example of how to write
data to a surface?


Sven


-- 
Info: To unsubscribe send a mail to [EMAIL PROTECTED] with 
"unsubscribe directfb-users" as subject.

Reply via email to