animesh wrote:
> Hi All,
>     I am using DirectFB 1.0.1, and trying to run the following code.
>     This code is the df_palette.c code that comes with the DirectFB 
> Examples, which i have modified a bit for seeing the use of SetColorIndex.
>    
>     Can anyone tell me what is wrong in this code, and if nothing is 
> wrong then why i am getting the error.  
>     "SetColorIndex not supported."
> 
>     What is the use of SetColorIndex?
>     How can this code be modified to use SetColorIndex.

SetColorIndex() saves finding the index by comparing each palette entry with 
the given color.

Only surfaces with DSPF_*LUT* formats support it.

 From looking at your I think this should work.

> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <unistd.h>
> #include <directfb.h>
> 
> /* the super interface */
> static IDirectFB            *dfb;
> 
> /* the primary surface (surface of primary layer) */
> static IDirectFBSurface     *primary;
> static IDirectFBPalette     *palette;
> 
> /* Input interfaces: device and its buffer */
> static IDirectFBEventBuffer *events;
> 
> static int screen_width, screen_height;
> 
> /* macro for a safe call to DirectFB functions */
> #define DFBCHECK(x...) \
>         
> {                                                                      \
>            err = 
> x;                                                            \
>            if (err != DFB_OK) 
> {                                                \
>               fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ 
> );           \
>               DirectFBErrorFatal( #x, err 
> );                                   \
>            
> }                                                                   \
>         }
>        
> static void
> generate_palette()
> {
>      int       i;
>      DFBResult err;
>      DFBColor  colors[256];
> 
>         
>      for (i=0; i<256; i++) {
>           colors[i].a = 0xff;
>           colors[i].r = i + 85;
>           colors[i].g = i;
>           colors[i].b = i + 171;
>      }
> 
>      DFBCHECK(palette->SetEntries( palette, colors, 256, 0 ));
> }
> 
> static void
> rotate_palette()
> {
>      DFBResult err;
>      DFBColor  colors[256];
> 
>      DFBCHECK(palette->GetEntries( palette, colors, 256, 0 ));
> 
>      DFBCHECK(palette->SetEntries( palette, colors + 1, 255, 0 ));
> 
>      colors[0].r += 17;
>      colors[0].g += 31;
>      colors[0].b += 29;
>      DFBCHECK(palette->SetEntries( palette, colors, 1, 255 ));
> }
> 
> static void
> fill_surface( IDirectFBSurface *surface )
> {
>      DFBResult  err;
>      int        x;
>      int        y;
>      void      *ptr;
>      int        pitch;
>      u8        *dst;
> 
>      DFBCHECK(surface->Lock( surface, DSLF_WRITE, &ptr, &pitch ));
> 
>      for (y=0; y<screen_height; y++) {
>           dst = ptr + y * pitch;
> 
>           for (x=0; x<screen_width; x++)
>                dst[x] = (x*x + y) / (y+1);
>      }
> 
>      DFBCHECK(surface->Unlock( surface ));
> }
> int
> main( int argc, char *argv[] )
> {
>      int                    quit = 0;
>      DFBResult              err;
>      DFBSurfaceDescription  sdsc;
>      DFBColor  colors[256];
>      int i;
>     
>      colors[0].a = 0xff;
>      colors[0].r = 0xff;
>      colors[0].g = 0xff;
>      colors[0].b = 0x00;
>     
>      for (i=1; i<256; i++) {
>           colors[i].a = 0xff;
>           colors[i].r = i + 85;
>           colors[i].g = i;
>           colors[i].b = i + 171;
>      }
>     
>      DFBCHECK(DirectFBInit( &argc, &argv ));
> 
>      /* create the super interface */
>      DFBCHECK(DirectFBCreate( &dfb ));
> 
>      /* create an event buffer for all devices */
>      DFBCHECK(dfb->CreateInputEventBuffer( dfb, DICAPS_ALL,
>                                            DFB_FALSE, &events ));
> 
>      /* set our cooperative level to DFSCL_FULLSCREEN
>         for exclusive access to the primary layer */
>      dfb->SetCooperativeLevel( dfb, DFSCL_FULLSCREEN );
> 
>      /* get the primary surface, i.e. the surface of the
>         primary layer we have exclusive access to */
>      sdsc.flags       = DSDESC_CAPS | DSDESC_PIXELFORMAT | DSDESC_PALETTE;
>      sdsc.caps        = DSCAPS_PRIMARY;
>      sdsc.pixelformat = DSPF_LUT8;
>      sdsc.palette.entries = colors;
>      sdsc.palette.size = 256;
> 
>      DFBCHECK(dfb->CreateSurface( dfb, &sdsc, &primary ));
>      primary->Clear( primary, 0, 0, 0, 0 );
> 
>      primary->GetSize( primary, &screen_width, &screen_height );
> 
>      /* get access to the palette */
>      DFBCHECK(primary->GetPalette( primary, &palette ));
> 
>      generate_palette();
>      fill_surface( primary );
> 
>      DFBCHECK(primary->SetColorIndex(primary, 0));
>      primary->FillRectangle (primary, 10, 10, 240, 320);
> 
>      primary->Flip (primary, NULL, 0);
> 
>      while (!quit) {
>           DFBInputEvent evt;
> 
>           while (events->GetEvent( events, DFB_EVENT(&evt) ) == DFB_OK) {
>                switch (evt.type) {
>                     case DIET_KEYPRESS:
>                          switch (evt.key_symbol) {
>                               case DIKS_ESCAPE:
>                                    quit = 1;
>                                    break;
>                               default:
>                                    ;
>                          }
>                     default:
>                          ;
>                }
>           }
>      }
> 
>      /* release our interfaces to shutdown DirectFB */
>      palette->Release( palette );
>      primary->Release( primary );
>      events->Release( events );
>      dfb->Release( dfb );
> 
>      return 0;
> }
> 
> And one more doubt, In the documentation given in the following link.
> 
> http://www.directfb.org/docs/DirectFB_Reference/types.html#DFBSurfaceDescription
> 
> 
> The DFBSurfaceDescription, structure is having the following field, but 
> in the actual code,
>     const DFBColor *entries;
>     unsigned int size ;
>     are part of the palette structure as you can seen in the above code:
>     sdsc.palette.entries = colors;
>     sdsc.palette.size = 256;
> 
> Why is this ambiguity?

The documentation generator needs to be fixed to handle nested structs.

-- 
Best regards,
   Denis Oliver Kropp

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

_______________________________________________
directfb-users mailing list
directfb-users@directfb.org
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-users

Reply via email to