Quoting Sarfraz Nawaz ([EMAIL PROTECTED]):
> >
> There's no method for drawing a single pixel, because developers shouldn't
> use such a method. Drawing several pixels with one call for each pixel is
> very much overhead. Instead you should lock the surface data via Lock() and
> write all pixels yourself.
> 
> If you like you can use FillRectangle() with size 1x1. It has the same overhead
> as a DrawPixel() method would have.
> >
> 
> Can you explain the locking and writing pixels approach a bit further. I
> would be writing around 400 pixels in one go and then blitting the surfaces.

You have to call Lock() and get a data pointer and the pitch (number of bytes
to add to the data pointer to get to the next row).

Furthermore it depends on the pixel format how your pixels have to be written.

Example (not checked if it compiles):

DFBResult fill_surface( IDirectFBSurface *surface, __u8 r, __u8 g, __u8 b )
{
     DFBResult              ret;
     void                  *data;
     int                    pitch;
     int                    x, y, width, height;
     DFBSurfacePixelFormat  format;

     ret = surface->Lock( surface, DSLF_WRITE, &data, &pitch );
     if (ret) {
          DirectFBError( "IDirectFBSurface::Lock() failed", ret );
          return ret;
     }

     surface->GetSize( surface, &width, &height );
     surface->GetPixelFormat( surface, &format );

     switch (format) {
          case DSPF_RGB16:
               for (y=0; y<height; y++) {
                    __u16 *dst = data + y * pitch;

                    for (x=0; x<width; x++)
                         dst[x] = PIXEL_RGB16( r, g, b );
               }
               break;
          case DSPF_ARGB1555:
               for (y=0; y<height; y++) {
                    __u16 *dst = data + y * pitch;

                    for (x=0; x<width; x++)
                         dst[x] = PIXEL_ARGB1555( 0xff, r, g, b );
               }
               break;
          case DSPF_ARGB:
               for (y=0; y<height; y++) {
                    __u32 *dst = data + y * pitch;

                    for (x=0; x<width; x++)
                         dst[x] = PIXEL_ARGB( 0xff, r, g, b );
               }
               break;
          case DSPF_RGB332:
               for (y=0; y<height; y++) {
                    __u8 *dst = data + y * pitch;

                    for (x=0; x<width; x++)
                         dst[x] = PIXEL_RGB332( r, g, b );
               }
               break;
          default:
               fprintf( stderr, "Unhandled pixel format 0x%08x!\n", format );
               break;
     }

     surface->Unlock( surface );

     return DFB_OK;
}

-- 
Best regards,
  Denis Oliver Kropp

.------------------------------------------.
| DirectFB - Hardware accelerated graphics |
| http://www.directfb.org/                 |
"------------------------------------------"

                            Convergence GmbH


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

Reply via email to