List Info

Thread: Re: Work with bitmap




Re: Work with bitmap
country flaguser name
Germany
2007-03-12 13:14:49
Nikita Egorov schrieb:
>>> In most cases, it's preferable to implement
points rendering yourself
>>> (Lock()/put points/Unlock()).
>> I'm confused. Please, see little example how to put
points.
> 
> // assume that pixelformat of the surface is RGB32
> int pitch=0;
> int x = 10;//x position of the first point
> int y = 10;
> u32 *buf = 0;
> DFBResult ret;
> // get direct access to the surface memory
> ret =surface->Lock( surface, DSLF_WRITE, &buf,
&pitch );
> if ( DFB_OK == ret  ) {
>      buf[ x + y*pitch/4 ] = 0xFF0000; // red pixel
>      x++;
>      buf[ x + y*pitch/4 ] = 0xFF00;  // green pixel
>      x++;
>      buf[ x + y*pitch/4 ] = 0xFF;  // blue pixel
>      // and so on ...
> }
> surface->Unlock( surface );
> 
> 

Another example:


This was from a mail from 2003-08-26  [directfb-users] Re:
Drawing pixels


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/
                |
"------------------------------------------"

_______________________________________________
directfb-dev mailing list
directfb-devdirectfb.org
http://mail.directfb.org/cgi-bin/mailman/listinfo/
directfb-dev

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )