コード例 #1
0
ファイル: utils.c プロジェクト: yshui/qingy-fork
IDirectFBSurface *load_image(const char *filename, IDirectFB *dfb, float x_ratio, float y_ratio)
{
	IDirectFBImageProvider *provider;
	IDirectFBSurface *image = NULL;
	DFBSurfaceDescription dsc;
	DFBResult err;

	if (access(filename, R_OK))
	{
		WRITELOG(ERROR, "Cannot load image: file '%s' does not exist!\n", filename);
		return NULL;
	}

	err = dfb->CreateImageProvider (dfb, filename, &provider);
	if (err != DFB_OK)
	{
		WRITELOG(ERROR, "Couldn't load image from file '%s': %s\n", filename, DirectFBErrorString (err));
		return NULL;
	}

	provider->GetSurfaceDescription (provider, &dsc);
	dsc.flags       = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT;
	dsc.pixelformat = DSPF_ARGB;
	dsc.width       = (float)dsc.width  * (float)x_ratio;
	dsc.height      = (float)dsc.height * (float)y_ratio;
	if (dfb->CreateSurface (dfb, &dsc, &image) == DFB_OK) provider->RenderTo (provider, image, NULL);

	return image;
}
コード例 #2
0
ファイル: DFBImageProvider.cpp プロジェクト: lince/ginga-srpp
	void DFBImageProvider::playOver(ISurface* surface) {
		IDirectFBImageProvider* ip;
		ip = (IDirectFBImageProvider*)decoder;

		IDirectFBSurface* s;
		s = (IDirectFBSurface*)(surface->getContent());
		DFBCHECK(ip->RenderTo(ip, s, NULL));
	}
コード例 #3
0
ファイル: Renderer.cpp プロジェクト: aaleswara/tanktv
Image *Renderer::loadImage(const char *path, float scaleFactor, const char *prescaled)
{
  if (!path || !path[0]) return NULL;

  unsigned key = hash(path) + (unsigned)(100*scaleFactor);

  if (m_image_cache.find(key) == m_image_cache.end()) {
    Image *image = new Image;
    image->surface = NULL;
    image->dsc.preallocated[0].data = NULL;
    
    IDirectFBImageProvider *provider = NULL;
    DFBSurfaceDescription &dsc = image->dsc;
    if (prescaled) path = prescaled;
    if (m_dfb->CreateImageProvider(m_dfb, path, &provider) == DFB_OK) {
      if (provider->GetSurfaceDescription(provider, &dsc) == DFB_OK) {
        if (!prescaled) {
          dsc.width = (int)(dsc.width * scaleFactor * m_scale);
          dsc.height = (int)(dsc.height * scaleFactor * m_scale);
        }
        dsc.flags = (DFBSurfaceDescriptionFlags)(dsc.flags | DSDESC_CAPS);
        dsc.caps = (DFBSurfaceCapabilities)(DSCAPS_VIDEOONLY);
	if ((image->surface = createSurface(&dsc))) {
	  void *data;
	  int pitch;
	  provider->RenderTo(provider, image->surface, NULL);
	  dsc.flags = (DFBSurfaceDescriptionFlags)(dsc.flags | DSDESC_PREALLOCATED);
	  image->surface->Lock(image->surface, DSLF_READ, &data, &pitch);
 	  if ((dsc.preallocated[0].data = malloc(pitch * dsc.height))) {
	    memcpy(dsc.preallocated[0].data, data, pitch * dsc.height);
	    dsc.preallocated[0].pitch = pitch;
	    dsc.preallocated[1].data = NULL;
	    dsc.preallocated[1].pitch = 0;
	  }
	  image->surface->Unlock(image->surface);
	}
	else {
	  debug("CreateSurface failed\n");
	}
      }
      else {
	debug("GetSurfaceDescription failed\n");
      }
      provider->Release(provider);
    }
    else {
      debug("CreateImageProvider failed\n");
    }
    m_image_cache[key] = image;
  }
  return m_image_cache[key];
}
コード例 #4
0
DFBResult
ICore_Real::CreateImageProvider(
                    u32                                        buffer_call,
                    u32                                       *ret_call
)
{
     DFBResult               ret;
     IDirectFBDataBuffer    *buffer;
     IDirectFBImageProvider *provider;
     ImageProviderDispatch  *dispatch;

     D_DEBUG_AT( DirectFB_CoreDFB, "ICore_Real::%s()\n", __FUNCTION__ );

     D_MAGIC_ASSERT( obj, CoreDFB );
     D_ASSERT( ret_call != NULL );

     DIRECT_ALLOCATE_INTERFACE( buffer, IDirectFBDataBuffer );
     if (!buffer)
          return (DFBResult) D_OOM();

     /* Construct data buffer client */
     ret = IDirectFBDataBuffer_Client_Construct( buffer, core, buffer_call );
     if (ret)
          return ret;

     /* Create image provider */
     ret = buffer->CreateImageProvider( buffer, &provider );
     if (ret) {
          buffer->Release( buffer );
          return ret;
     }

     /* Create dispatch object */
     ret = ImageProviderDispatch_Create( idirectfb_singleton, buffer, provider, &dispatch );
     if (ret) {
          provider->Release( provider );
          buffer->Release( buffer );
          return ret;
     }

     *ret_call = dispatch->call.call_id;

     return DFB_OK;
}
コード例 #5
0
ファイル: main.c プロジェクト: geekmaster/buildroot-kindle
void load_stars()
{
     IDirectFBImageProvider *provider;
     DFBSurfaceDescription   dsc;

     int  i;
     char name[ strlen(DATADIR"/star.png") + 4 ];

     for (i=0; i<NUM_STARS; i++) {

          sprintf( name, DATADIR"/star%d.png", i+1 );

          DFBCHECK( dfb->CreateImageProvider( dfb, name, &provider ) );
          DFBCHECK( provider->GetSurfaceDescription (provider, &dsc) );
          DFBCHECK( dfb->CreateSurface( dfb, &dsc, &stars[i] ) );
          DFBCHECK( provider->RenderTo( provider, stars[i], NULL ) );

          provider->Release( provider );

          stars[i]->SetSrcColorKey( stars[i], 0xFF, 0x00, 0xFF );
     }
}
コード例 #6
0
ファイル: df_neo.c プロジェクト: geekmaster/buildroot-kindle
static void
load_images (void)
{
  DFBSurfaceDescription   dsc;
  IDirectFBImageProvider *provider;
  int i;

  for (i = 0; i < N_IMAGES; i++)
    {
      DFBCHECK(dfb->CreateImageProvider (dfb, image_names[i], &provider));
      DFBCHECK(provider->GetSurfaceDescription (provider, &dsc));

      image_widths[i]  = dsc.width;
      image_heights[i] = dsc.height;

      DFBCHECK(dfb->CreateSurface (dfb, &dsc, &images[i]));

      provider->RenderTo (provider, images[i], NULL);

      provider->Release (provider);
    }
}
コード例 #7
0
static IDirectFBSurface *
load_image (const char *filename)
{
     IDirectFBImageProvider *provider;
     IDirectFBSurface       *tmp     = NULL;
     IDirectFBSurface       *surface = NULL;
     DFBSurfaceDescription   dsc;
     DFBResult               err;

     err = dfb->CreateImageProvider( dfb, filename, &provider );
     if (err != DFB_OK) {
          fprintf( stderr, "Couldn't load image from file '%s': %s\n",
                   filename, DirectFBErrorString( err ));
          return NULL;
     }

     provider->GetSurfaceDescription( provider, &dsc );
     dsc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT;
     dsc.pixelformat = DSPF_ARGB;
     if (dfb->CreateSurface( dfb, &dsc, &tmp ) == DFB_OK)
          provider->RenderTo( provider, tmp, NULL );

     provider->Release( provider );

     if (tmp) {
          primary->GetPixelFormat( primary, &dsc.pixelformat );
          if (dfb->CreateSurface( dfb, &dsc, &surface ) == DFB_OK) {
               surface->Clear( surface, 0, 0, 0, 0xFF );
               surface->SetBlittingFlags( surface, DSBLIT_BLEND_ALPHACHANNEL );
               surface->Blit( surface, tmp, NULL, 0, 0 );
          }
          tmp->Release( tmp );
     }

     return surface;
}
コード例 #8
0
ファイル: dfbtest_scale.c プロジェクト: Distrotech/DirectFB
int
main( int argc, char *argv[] )
{
     int                     i;
     DFBResult               ret;
     DFBSurfaceDescription   desc;
     IDirectFB              *dfb;
     IDirectFBImageProvider *provider = NULL;
     IDirectFBSurface       *source   = NULL;
     IDirectFBSurface       *dest     = NULL;
     const char             *url      = NULL;

     /* Parse arguments. */
     for (i=1; i<argc; i++) {
          if (!strcmp( argv[i], "-h" ))
               return show_usage( argv[0] );
          else if (!url)
               url = argv[i];
          else
               return show_usage( argv[0] );
     }

     /* Check if we got an URL. */
     if (!url)
          return show_usage( argv[0] );
          
     /* Initialize DirectFB. */
     ret = DirectFBInit( &argc, &argv );
     if (ret) {
          D_DERROR( ret, "DFBTest/Scale: DirectFBInit() failed!\n" );
          return ret;
     }

     /* Create super interface. */
     ret = DirectFBCreate( &dfb );
     if (ret) {
          D_DERROR( ret, "DFBTest/Scale: DirectFBCreate() failed!\n" );
          return ret;
     }

     /* Create an image provider for the image to be loaded. */
     ret = dfb->CreateImageProvider( dfb, url, &provider );
     if (ret) {
          D_DERROR( ret, "DFBTest/Scale: IDirectFB::CreateImageProvider( '%s' ) failed!\n", url );
          goto out;
     }

     /* Get the surface description. */
     ret = provider->GetSurfaceDescription( provider, &desc );
     if (ret) {
          D_DERROR( ret, "DFBTest/Scale: IDirectFBImageProvider::GetSurfaceDescription() failed!\n" );
          goto out;
     }
     
     desc.pixelformat = DSPF_LUT8;

     D_INFO( "DFBTest/Scale: Source is %dx%d using %s\n",
             desc.width, desc.height, dfb_pixelformat_name(desc.pixelformat) );

     /* Create a surface for the image. */
     ret = dfb->CreateSurface( dfb, &desc, &source );
     if (ret) {
          D_DERROR( ret, "DFBTest/Scale: IDirectFB::CreateSurface() failed!\n" );
          goto out;
     }
     
     ret = provider->RenderTo( provider, source, NULL );
     if (ret) {
          D_DERROR( ret, "DFBTest/Scale: IDirectFBImageProvider::RenderTo() failed!\n" );
          goto out;
     }
     
     desc.width  = desc.width  * 3 / 4;
     desc.height = desc.height * 3 / 4;

     if (DFB_PIXELFORMAT_IS_INDEXED( desc.pixelformat ))
          desc.pixelformat = DSPF_ARGB;

     D_INFO( "DFBTest/Scale: Destination is %dx%d using %s\n",
             desc.width, desc.height, dfb_pixelformat_name(desc.pixelformat) );

     /* Create a surface for the image. */
     ret = dfb->CreateSurface( dfb, &desc, &dest );
     if (ret) {
          D_DERROR( ret, "DFBTest/Scale: IDirectFB::CreateSurface() failed!\n" );
          goto out;
     }

     dest->SetBlittingFlags( dest, DSBLIT_SRC_PREMULTIPLY );
     dest->StretchBlit( dest, source, NULL, NULL );

     dest->Dump( dest, "dfbtest_scale", NULL );


out:
     if (dest)
          dest->Release( dest );

     if (source)
          source->Release( source );

     if (provider)
          provider->Release( provider );

     /* Shutdown DirectFB. */
     dfb->Release( dfb );

     return ret;
}
コード例 #9
0
ファイル: df_neo.c プロジェクト: geekmaster/buildroot-kindle
int
main (int    argc,
      char **argv)
{
  DFBSurfaceDescription   dsc;
  DFBSurfaceDescription   back_dsc;
  DFBRectangle            rect;
  IDirectFBImageProvider *provider;
  IDirectFBEventBuffer   *keybuffer;
  DFBInputEvent           evt;
  int                     width;
  int                     height;
  int                     quit;
  unsigned int            cycle_len;
  struct timeval          tv;
  long                    start_time;
  long                    current_time;
  long                    frame_delay;
  long                    delay;

  frame_delay = delay = FRAME_DELAY;
  cycle_len   = CYCLE_LEN;
  quit        = FALSE;

  DFBCHECK (DirectFBInit (&argc, &argv));

  if (argc > 1 && argv[1] && strcmp (argv[1], "--on-crack") == 0)
    on_crack = TRUE;

  /* create the super interface */
  DFBCHECK (DirectFBCreate (&dfb));

  dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN);
  DFBCHECK (dfb->CreateInputEventBuffer (dfb, DICAPS_KEYS,
                                         DFB_FALSE, &keybuffer));

  /*  create the primary surface  */
  dsc.flags = DSDESC_CAPS;
  dsc.caps  = DSCAPS_PRIMARY;

  if (!on_crack) {
       dsc.caps |= DSCAPS_TRIPLE;

       if (dfb->CreateSurface (dfb, &dsc, &primary) != DFB_OK) {
            dsc.caps = (dsc.caps & ~DSCAPS_TRIPLE) | DSCAPS_DOUBLE;
            DFBCHECK (dfb->CreateSurface (dfb, &dsc, &primary));
       }
  }
  else
       DFBCHECK (dfb->CreateSurface (dfb, &dsc, &primary));

  /* load size of background image */
  DFBCHECK (dfb->CreateImageProvider (dfb, BACKGROUND_NAME, &provider));
  DFBCHECK (provider->GetSurfaceDescription (provider, &back_dsc));
  back_width  = back_dsc.width;
  back_height = back_dsc.height;

  if (!back_width || !back_height)
    return -1;

  /*  create the background surface  */
  DFBCHECK (dfb->CreateSurface (dfb, &back_dsc, &background));
  provider->RenderTo (provider, background, NULL);
  provider->Release (provider);

  /*  create subsurface in the middle of the screen */
  primary->GetSize (primary, &width, &height);
  rect.x = (width  - back_width)  / 2;
  rect.y = (height - back_height) / 2;
  rect.w = back_width;
  rect.h = back_height;
  primary->GetSubSurface (primary, &rect, &sub);

  if (on_crack)
    {
      /* clear screen */
      primary->Clear (primary, 0, 0, 0, 0xff);
    }
  else
    {
      /*  fill screen and backbuffers with tiled background  */
      primary->TileBlit (primary, background, NULL, rect.x, rect.y);
      primary->Flip (primary, NULL, 0) ;
      primary->TileBlit (primary, background, NULL, rect.x, rect.y);
      primary->Flip (primary, NULL, 0) ;
      primary->TileBlit (primary, background, NULL, rect.x, rect.y);

      primary->SetClip (primary, NULL);
    }

  /*  load the remaining images  */
  load_images ();

  frame_num = 0;

  while (!quit)
    {
      gettimeofday (&tv, NULL);
      start_time = tv.tv_sec * 1000 + tv.tv_usec / 1000;

      timeout (cycle_len);

      while (keybuffer->GetEvent (keybuffer, DFB_EVENT(&evt)) == DFB_OK)
        {
          if (evt.type == DIET_KEYPRESS)
            {
              switch (evt.key_id)
                {
                case DIKI_LEFT:
                  frame_delay = MIN (500, frame_delay + 5);
                  break;
                case DIKI_RIGHT:
                  frame_delay = MAX (0, frame_delay - 5);
                  break;
                case DIKI_UP:
                  cycle_len = MIN (600, cycle_len + 6);
                  break;
                case DIKI_DOWN:
                  cycle_len = cycle_len > 6 ? cycle_len - 6 : 6;
                  break;
                case DIKI_SPACE:
                case DIKI_ENTER:
                  colorize = !colorize;
                  break;
                case DIKI_A:
                  alpha = !alpha;
                  break;
                case DIKI_HOME:
                  cycle_len   = CYCLE_LEN;
                  frame_delay = FRAME_DELAY;
                  colorize    = TRUE;
                  alpha       = TRUE;
                  break;
                case DIKI_ESCAPE:
                case DIKI_Q:
                  quit = TRUE;
                  break;
                default:
                  break;
                }

              switch (evt.key_symbol)
                {
                case DIKS_OK:
                  colorize = !colorize;
                  break;
                case DIKS_BACK:
                case DIKS_STOP:
                  quit = TRUE;
                  break;
                default:
                  break;
                }
            }
        }

      if (frame_delay)
        {
          gettimeofday (&tv, NULL);
          current_time = tv.tv_sec * 1000 + tv.tv_usec / 1000;

          delay = frame_delay - (current_time - start_time);
          if (delay > 0)
            usleep (1000 * delay);
        }
    }

  keybuffer->Release (keybuffer);
  release_images ();
  background->Release (background);
  sub->Release (sub);
  primary->Release (primary);
  dfb->Release (dfb);

  return 0;
}
コード例 #10
0
ファイル: DFBDeviceScreen.cpp プロジェクト: lince/ginga-srpp
	void DFBDeviceScreen::setBackgroundImage(string uri) {
		DFBResult               ret;
		DFBSurfaceDescription   desc;
		IDirectFBSurface       *surface;
		IDirectFBImageProvider *provider;

		ret = dfb->CreateImageProvider(dfb, uri.c_str(), &provider);
		if (ret) {
			DirectFBError("IDirectFB::CreateImageProvider() failed", ret);
			return;
		}

		ret = provider->GetSurfaceDescription(provider, &desc);
		if (ret) {
			DirectFBError(
					"DFBDeviceScreen::setBackgroundImage surdsc failed", ret);

			provider->Release(provider);
			return;
		}

		desc.width  = this->wRes;
		desc.height = this->hRes;

		ret = dfb->CreateSurface(dfb, &desc, &surface);
		if (ret) {
			DirectFBError(
					"DFBDeviceScreen::setBackgroundImage sur failed",
					ret);

			provider->Release(provider);
			return;
		}

		ret = provider->RenderTo(provider, surface, NULL);
		if (ret) {
			DirectFBError(
					"DFBDeviceScreen::setBackgroundImage renderto failed",
					ret);

			surface->Release(surface);
			provider->Release(provider);
			return;
		}

		ret = gfxLayer->SetBackgroundImage(gfxLayer, surface);
		if (ret) {
			DirectFBError(
					"DFBDeviceScreen::setBackgroundImage bg failed",
					ret);

			surface->Release(surface);
			provider->Release(provider);
			return;
		}

		ret = gfxLayer->SetBackgroundMode(gfxLayer, DLBM_IMAGE);
		if (ret) {
			DirectFBError(
					"DFBDeviceScreen::setBackgroundImage bgm failed",
					ret);
		}

		surface->Release(surface);
		provider->Release(provider);

		cout << endl << endl;
		cout << "DFBScreen::setBackgroundImage '" << uri << "'" << endl;
		cout << endl << endl;

	}
コード例 #11
0
ファイル: DFBImageProvider.cpp プロジェクト: lince/ginga-srpp
	ISurface* DFBImageProvider::prepare(bool isGif) {
		ISurface* renderedSurface = NULL;

		IDirectFBImageProvider* ip;
		ip = (IDirectFBImageProvider*)decoder;

		DFBImageDescription imgDsc;
		IDirectFBSurface* destination = NULL;
		DFBSurfaceDescription surDsc;
		IColor* chromaKey = NULL;

		//IDirectFBSurface* source;
		if ((ip->GetImageDescription(ip, &imgDsc) == DFB_OK) &&
			 (ip->GetSurfaceDescription(ip, &surDsc) == DFB_OK)) {

			destination = (IDirectFBSurface*)(
					LocalDeviceManager::getInstance()->createSurface(&surDsc));

			renderedSurface = new DFBSurface(destination);

			if (imgDsc.caps & DICAPS_ALPHACHANNEL) {
				/*cout << "ImagePlayer::ImagePlayer(" << mrl << ")";
				cout << " setted alphachannel: ";*/

				//alpha channel of gif does not exists anymore, it turn into
				//black src color key (marcio 20/04/2007)
				if (isGif) {
					chromaKey = new Color(0, 0, 0);
					renderedSurface->setChromaColor(chromaKey);
					//outputDisplay->setColorKey(0, 0, 0);
					//cout << "black color cause it is a gif image" << endl;

				} else {
					renderedSurface->setCaps(DWCAPS_ALPHACHANNEL);
				}

				//cout << " trying to blit image alpha channel" << endl;

				DFBCHECK(destination->SetBlittingFlags(destination,
					 (DFBSurfaceBlittingFlags)(DSBLIT_BLEND_ALPHACHANNEL)));

				/*cout << "ImagePlayer::ImagePlayer(" << mrl << ")";
				cout << " setted alpha: '";
				cout << (((int)(imgDsc.colorkey_r & 0xFF)) & 0xFF);
				cout << ", " << (((int)(imgDsc.colorkey_g)) & 0xFF);
				cout << ", " << (((int)(imgDsc.colorkey_b)) & 0xFF);
				cout << "'" << endl;*/
			}

			if (imgDsc.caps & DICAPS_COLORKEY) {
				chromaKey = new Color(
					    imgDsc.colorkey_r,
					    imgDsc.colorkey_g,
					    imgDsc.colorkey_b);

				DFBCHECK(destination->SetBlittingFlags(destination,
					    (DFBSurfaceBlittingFlags)(
					    DSBLIT_BLEND_ALPHACHANNEL |
					    DSBLIT_SRC_COLORKEY)));

				renderedSurface->setChromaColor(chromaKey);
				/*cout << "ImagePlayer::ImagePlayer(" << mrl << ")";
				cout << " setted colorkey: '";
				cout << (((int)(imgDsc.colorkey_r & 0xFF)) & 0xFF);
				cout << ", " << (((int)(imgDsc.colorkey_g)) & 0xFF);
				cout << ", " << (((int)(imgDsc.colorkey_b)) & 0xFF);
				cout << "'" << endl;*/
			}

			if (imgDsc.caps & DICAPS_NONE) {
				DFBCHECK(destination->SetBlittingFlags(destination,
					    (DFBSurfaceBlittingFlags)DSBLIT_NOFX));

				renderedSurface->setCaps(DWCAPS_NONE);
				/*cout << "ImagePlayer::ImagePlayer(" << mrl << ")";
				cout << " NOFX" << endl;*/
			}
		}

		if (destination != NULL && renderedSurface != NULL) {
			DFBCHECK(ip->RenderTo(
					ip,
					(IDirectFBSurface*)(renderedSurface->getContent()), NULL));
		}
		return renderedSurface;
	}
コード例 #12
0
ファイル: graphics.c プロジェクト: ALojdl/Zapper
void render()
{
    IDirectFBImageProvider *provider;
	IDirectFBSurface *logoSurface;
	IDirectFBFont *fontInterface;
	DFBFontDescription fontDesc;
	char imageName[15];
	int32_t logoHeight;
	int32_t logoWidth;
	char prog[32];
	char date[32];
	char telxt[32];
	char audio[32];
	char video[32];
	
    // Fetch the screen size and clear screen.    
    DFBCHECK(primary->SetColor(primary, 0x00, 0x00, 0x00, 0x00));                               
	DFBCHECK(primary->FillRectangle(primary, 0, 0, screenWidth, screenHeight));
	
	if (volumeBar.visible)	
	{
	    // Make a new name.
	    sprintf(imageName, "volume_%hu.png", volumeBar.volume);
	
        // Read image, prepare surface descriptor and render image to given surface.
	    DFBCHECK(dfbInterface->CreateImageProvider(dfbInterface, imageName, &provider));
	    DFBCHECK(provider->GetSurfaceDescription(provider, &surfaceDesc));
	    DFBCHECK(dfbInterface->CreateSurface(dfbInterface, &surfaceDesc, &logoSurface));
	    DFBCHECK(provider->RenderTo(provider, logoSurface, NULL));
	    provider->Release(provider);
	
        // Fetch the logo size and add it to the screen buffer. 
	    DFBCHECK(logoSurface->GetSize(logoSurface, &logoWidth, &logoHeight));
	    DFBCHECK(primary->Blit(primary, logoSurface,
	        NULL, VOLUME_X_COOR, VOLUME_Y_COOR));   
    } 
    
    if (infoBar.visible)
    {
        // Prepare strings for info bar.
	    sprintf(prog, "Program %hu", infoBar.channelNumber);
	    sprintf(date, "Naziv dana u nedelji %s", infoBar.date);
	    sprintf(audio, "Audio PID %hu", infoBar.audioPID);
	    sprintf(video, "Video PID %hu", infoBar.videoPID);
	    if (infoBar.teletextExist)
        {
            sprintf(telxt, "Teletekst postoji");    
        }
        else
        {
            sprintf(telxt, "Teletekst ne postoji");    
        }
        
        // Prepare text font, color and size. Then create font and draw it.
	    fontDesc.flags = DFDESC_HEIGHT;
	    fontDesc.height = 40;
	    DFBCHECK(dfbInterface->CreateFont(dfbInterface, 
	        "/home/galois/fonts/DejaVuSans.ttf", &fontDesc, &fontInterface));
	    DFBCHECK(primary->SetFont(primary, fontInterface));    
	
	    // Draw a rectangle representing info bar.    
        DFBCHECK(primary->SetColor(primary, INFO_BAR_RED, 
            INFO_BAR_GREEN, INFO_BAR_BLUE, 0xff));
        DFBCHECK(primary->FillRectangle(primary, screenWidth/6, 4*screenHeight/5,
            4*screenWidth/6, screenHeight/6));

        // Write program number, date and teletext to info bar.
        DFBCHECK(primary->SetColor(primary, TEXT_RED, TEXT_GREEN, TEXT_BLUE, 0xff));
        DFBCHECK(primary->DrawString(primary, prog, -1, screenWidth/5, 
	        17*screenHeight/20, DSTF_LEFT));
	    DFBCHECK(primary->DrawString(primary, audio, -1, screenWidth/5, 
	        18*screenHeight/20, DSTF_LEFT));
	    DFBCHECK(primary->DrawString(primary, video, -1, screenWidth/5, 
	        19*screenHeight/20, DSTF_LEFT));
	    DFBCHECK(primary->DrawString(primary, date, -1, 4*screenWidth/9, 
	        19*screenHeight/20, DSTF_LEFT));  
	    DFBCHECK(primary->DrawString(primary, telxt, -1, 4*screenWidth/9, 
	    	17*screenHeight/20, DSTF_LEFT));    
    }
    
    // Switch buffers.
	DFBCHECK(primary->Flip(primary, NULL, 0));
}
コード例 #13
0
ファイル: unit_test_rle.c プロジェクト: canalplus/r7oss
//------------------------------------------------------------------------------
//  Unit Test main
//------------------------------------------------------------------------------
int main (int argc, char **argv)
{
    int i, j;
    DFBResult rle_build_databuffer_err;

    //    File name to load logo image from
    char *filename                           = NULL;

    //    Basic directfb elements
    IDirectFB               *dfb             = NULL;
    IDirectFBSurface        *primary         = NULL;
    int                      screen_width    = 0;
    int                      screen_height   = 0;

    //    The image is to be loaded into a surface that we can blit from.
    IDirectFBSurface         *logo           = NULL;

    //    Loading an image is done with an Image Provider.
    IDirectFBImageProvider   *provider       = NULL;

    //    An Image provider instance can also be created from a directfb buffer
    IDirectFBDataBuffer      *databuffer     = NULL;

    //    Surface description
    DFBSurfaceDescription     surface_dsc;



    //    Initialize directfb first
    DFBCHECK (DirectFBInit (&argc, &argv));
    DFBCHECK (DirectFBCreate (&dfb));
    DFBCHECK (dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN));


    //  Create primary surface
    surface_dsc.flags = DSDESC_CAPS;
    surface_dsc.caps  = DSCAPS_PRIMARY | DSCAPS_FLIPPING;
    DFBCHECK (dfb->CreateSurface( dfb, &surface_dsc, &primary ));
    DFBCHECK (primary->GetSize (primary, &screen_width, &screen_height));

    if (argc==1)
    {
        argv[1] = "./data/directfb.rle";
        argc++;
    }

    DISPLAY_INFO ("Rendering %d files\n",argc-1);
    for (j=1; j<argc; j++)
    {

        //
        //  --- WE CREATE OUR IMAGE PROVIDER INSTANCE HERE
        //
        filename     =     argv[j];
        DISPLAY_INFO ("Rendering : %s\n",filename);

        //  We create a directfb data buffer holding RLE image contents that we
        //  pick up from a file (could get the RLE contents from memory as well).
        //  "rle_build_databuffer" details the process of dealing with a memory
        //  RLE packet as a matter of fact.
        rle_build_databuffer_err = rle_build_databuffer (dfb, filename, &databuffer);
        if (rle_build_databuffer_err == DFB_OK) {
            //  We want to create an Image Provider tied to a directfb data buffer.
            //  DirectFB will find (or not) an Image Provider for the data type
            //  depending on Image Providers probe method (sniffing data headers)
            DFBCHECK (databuffer->CreateImageProvider (databuffer, &provider));
        }
        else {
#       ifdef   USE_PACKET_BUILDER_ONLY
            DFBFAIL(rle_build_databuffer_err);
#       else
            //  We could also create an Image Provider by passing a filename.
            //  DirectFB will find (or not) an Image Provider matching the file type.
            DFBCHECK (dfb->CreateImageProvider (dfb, filename, &provider));
#       endif
        }



        //    Get a surface description from the provider. It will contain the width,
        //    height, bits per pixel and the flag for an alphachannel if the image
        //    has one. If the image has no alphachannel the bits per pixel is set to
        //    the bits per pixel of the primary layer to use simple blitting without
        //    pixel format conversion.
        DFBCHECK (provider->GetSurfaceDescription (provider, &surface_dsc));

        //    Create a surface based on the description of the provider.
        DFBCHECK (dfb->CreateSurface( dfb, &surface_dsc, &logo ));

        //    Let the provider render to our surface. Image providers are supposed
        //    to support every destination pixel format and size. If the size
        //    differs the image will be scaled (bilinear). The last parameter allows
        //    to specify an optional destination rectangle. We use NULL here so that
        //    our image covers the whole logo surface.
        DFBCHECK (provider->RenderTo (provider, logo, NULL));
        //    Note: RLE Image Provider allows for direct non-scaled LUT-8 surface
        //          rendering without any attached colormap.

        #ifdef CLEVER_APPROACH
        //    Let's setup our logo surface palette outside of the RLE Image
        //    Provider if we got a colormap from rle_build_databuffer ...
        if (color_palette)
        {
            IDirectFBPalette *palette;
            DFBCHECK (logo->GetPalette (logo, &palette));
            palette->SetEntries (palette, color_palette, number_of_colors, 0);
            palette->Release (palette);
        }
        #endif

        //
        //  --- WE GET RID OF OUR IMAGE PROVIDER INSTANCE HERE
        //
        //    Release the provider, we don't need it anymore.
        provider->Release (provider);           provider    = NULL;
        //    Destroy the databuffer as well, we don't need it anymore.
        rle_destroy_databuffer (databuffer);    databuffer  = NULL;


#   ifndef SUBTITLES_MODE
        //    We want to let the logo slide in on the left and slide out on the
        //    right.
        for (i = -surface_dsc.width; i < screen_width; i++)
#   else
        //    We want to let the logo slide in on the right and slide out on the
        //    left.
        for (i = screen_width-1; i >= -surface_dsc.width; i--)
#   endif
        {
            //    Clear the screen.
            DFBCHECK (primary->FillRectangle (primary, 0, 0,
                                              screen_width, screen_height));

            //    Blit the logo vertically centered with "i" as the X coordinate.
            //    NULL means that we want to blit the whole surface.
            DFBCHECK (primary->Blit (primary, logo, NULL, i,
                                     (screen_height - surface_dsc.height) / 2));

            //    Flip the front and back buffer, but wait for the vertical
            //    retrace to avoid tearing.
            DFBCHECK (primary->Flip (primary, NULL, DSFLIP_WAITFORSYNC));

            if (argc < 3)
            {
                usleep(1000*5);
            }
        }

        //    Release the image.
        if (logo)
        {
            logo->Release (logo);
        }

   }

   //    Release everything else
   primary->Release (primary);
   dfb->Release (dfb);

   return 0;
}
コード例 #14
0
ファイル: dfbtest_sync.c プロジェクト: Distrotech/DirectFB
int
main( int argc, char *argv[] )
{
     int                     i;
     DFBResult               ret;
     DFBSurfaceDescription   desc;
     IDirectFB              *dfb;
     IDirectFBImageProvider *provider      = NULL;
     IDirectFBSurface       *source        = NULL;
     IDirectFBSurface       *dest          = NULL;
     const char             *url           = NULL;
     DFBSurfacePixelFormat   source_format = DSPF_UNKNOWN;
     DFBSurfacePixelFormat   dest_format   = DSPF_UNKNOWN;
     bool                    dest_resize   = false;

     /* Initialize DirectFB. */
     ret = DirectFBInit( &argc, &argv );
     if (ret) {
          D_DERROR( ret, "DFBTest/Blit: DirectFBInit() failed!\n" );
          return ret;
     }

     /* Parse arguments. */
     for (i=1; i<argc; i++) {
          const char *arg = argv[i];

          if (strcmp( arg, "-h" ) == 0 || strcmp (arg, "--help") == 0)
               return print_usage( argv[0] );
          else if (strcmp (arg, "-v") == 0 || strcmp (arg, "--version") == 0) {
               fprintf (stderr, "dfbtest_blit version %s\n", DIRECTFB_VERSION);
               return false;
          }
          else if (strcmp (arg, "-s") == 0 || strcmp (arg, "--source") == 0) {
               if (++i == argc) {
                    print_usage (argv[0]);
                    return false;
               }

               if (!parse_format( argv[i], &source_format ))
                    return false;
          }
          else if (strcmp (arg, "-d") == 0 || strcmp (arg, "--dest") == 0) {
               if (++i == argc) {
                    print_usage (argv[0]);
                    return false;
               }

               if (!parse_format( argv[i], &dest_format ))
                    return false;
          }
          else if (strcmp (arg, "-r") == 0 || strcmp (arg, "--resize") == 0)
               dest_resize = true;
          else if (!url)
               url = arg;
          else
               return print_usage( argv[0] );
     }

     /* Check if we got an URL. */
     if (!url)
          return print_usage( argv[0] );
          
     /* Create super interface. */
     ret = DirectFBCreate( &dfb );
     if (ret) {
          D_DERROR( ret, "DFBTest/Blit: DirectFBCreate() failed!\n" );
          return ret;
     }

     /* Create an image provider for the image to be loaded. */
     ret = dfb->CreateImageProvider( dfb, url, &provider );
     if (ret) {
          D_DERROR( ret, "DFBTest/Blit: IDirectFB::CreateImageProvider( '%s' ) failed!\n", url );
          goto out;
     }

     /* Get the surface description. */
     ret = provider->GetSurfaceDescription( provider, &desc );
     if (ret) {
          D_DERROR( ret, "DFBTest/Blit: IDirectFBImageProvider::GetSurfaceDescription() failed!\n" );
          goto out;
     }

     if (source_format != DSPF_UNKNOWN)
          desc.pixelformat = source_format;
     
     D_INFO( "DFBTest/Blit: Source is %dx%d using %s\n",
             desc.width, desc.height, dfb_pixelformat_name(desc.pixelformat) );

     /* Create a surface for the image. */
     ret = dfb->CreateSurface( dfb, &desc, &source );
     if (ret) {
          D_DERROR( ret, "DFBTest/Blit: IDirectFB::CreateSurface() failed!\n" );
          goto out;
     }
     
     ret = provider->RenderTo( provider, source, NULL );
     if (ret) {
          D_DERROR( ret, "DFBTest/Blit: IDirectFBImageProvider::RenderTo() failed!\n" );
          goto out;
     }

     /* Fill description for a primary surface. */
     desc.flags = DSDESC_CAPS;
     desc.caps  = DSCAPS_PRIMARY | DSCAPS_FLIPPING;

     if (dest_format != DSPF_UNKNOWN) {
          desc.flags       |= DSDESC_PIXELFORMAT;
          desc.pixelformat  = dest_format;
     }

     if (dest_resize)
          desc.flags |= DSDESC_WIDTH | DSDESC_HEIGHT;

     dfb->SetCooperativeLevel( dfb, DFSCL_FULLSCREEN );

     /* Create a primary surface. */
     ret = dfb->CreateSurface( dfb, &desc, &dest );
     if (ret) {
          D_DERROR( ret, "DFBTest/Blit: IDirectFB::CreateSurface() failed!\n" );
          goto out;
     }

     dest->GetSize( dest, &desc.width, &desc.height );
     dest->GetPixelFormat( dest, &desc.pixelformat );

     D_INFO( "DFBTest/Blit: Destination is %dx%d using %s\n",
             desc.width, desc.height, dfb_pixelformat_name(desc.pixelformat) );

     for (i=0; i<100000; i++) {
          int j,n = rand()%100;

          for (j=0; j<n; j++) {
               switch (rand()%3) {
                    case 0:
                         dest->SetDrawingFlags( dest, rand() & (DSDRAW_BLEND) );
                         dest->FillRectangle( dest, rand()%100, rand()%100, rand()%100, rand()%100 );
                         break;

                    case 1:
                         dest->SetBlittingFlags( dest, rand() & (DSBLIT_BLEND_ALPHACHANNEL |
                                                                 DSBLIT_BLEND_COLORALPHA   |
                                                                 DSBLIT_COLORIZE           |
                                                                 DSBLIT_ROTATE90) );
                         dest->Blit( dest, source, NULL, rand()%100, rand()%100 );
                         break;

                    case 2:
                         dest->SetBlittingFlags( dest, rand() & (DSBLIT_BLEND_ALPHACHANNEL |
                                                                 DSBLIT_BLEND_COLORALPHA   |
                                                                 DSBLIT_COLORIZE           |
                                                                 DSBLIT_ROTATE90) );
                         dest->StretchBlit( dest, source, NULL, NULL );
                         break;
               }
          }

          dfb->WaitIdle( dfb );

          dest->Flip( dest, NULL, DSFLIP_NONE );
     }

out:
     if (dest)
          dest->Release( dest );

     if (source)
          source->Release( source );

     if (provider)
          provider->Release( provider );

     /* Shutdown DirectFB. */
     dfb->Release( dfb );

     return ret;
}
コード例 #15
0
ファイル: evas_directfb_window.c プロジェクト: Limsik/e17
int main( int argc, char *argv[] )
{
     IDirectFB              *dfb;
     IDirectFBDisplayLayer  *layer;

     IDirectFBSurface       *bgsurface;
     IDirectFBImageProvider *provider;

     IDirectFBWindow        *window1;
     IDirectFBWindow        *window2;
     IDirectFBSurface       *window_surface1;
     IDirectFBSurface       *window_surface2;

     IDirectFBEventBuffer   *buffer;

     DFBDisplayLayerConfig  layer_config;

#if ((DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23))
     DFBCardCapabilities    caps;
#else
     DFBGraphicsDeviceDescription caps;
#endif
     IDirectFBWindow*       upper;
     DFBWindowID            id1;

     IDirectFBFont          *font;
     int fontheight;
     int err;
     int quit = 0;


     DFBCHECK(DirectFBInit( &argc, &argv ));
     DFBCHECK(DirectFBCreate( &dfb ));

#if ((DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23))
     dfb->GetCardCapabilities( dfb, &caps );
#else
     dfb->GetDeviceDescription( dfb, &caps );
#endif

     dfb->GetDisplayLayer( dfb, DLID_PRIMARY, &layer );

     if (!((caps.blitting_flags & DSBLIT_BLEND_ALPHACHANNEL) &&
           (caps.blitting_flags & DSBLIT_BLEND_COLORALPHA  )))
     {
          layer_config.flags = DLCONF_BUFFERMODE;
          layer_config.buffermode = DLBM_BACKSYSTEM;

          layer->SetConfiguration( layer, &layer_config );
     }

     layer->GetConfiguration( layer, &layer_config );
     layer->EnableCursor ( layer, 1 );

     {
          DFBFontDescription desc;

          desc.flags = DFDESC_HEIGHT;
          desc.height = layer_config.width/50;

          DFBCHECK(dfb->CreateFont( dfb, PACKAGE_DATA_DIR"/grunge.ttf", &desc, &font ));
          font->GetHeight( font, &fontheight );
     }

     {
          DFBSurfaceDescription desc;

          DFBCHECK(dfb->CreateImageProvider( dfb,
                                             PACKAGE_DATA_DIR"/bg.png",
                                             &provider ));

          desc.flags = DSDESC_WIDTH | DSDESC_HEIGHT;
          desc.width = layer_config.width;
          desc.height = layer_config.height;

          DFBCHECK(dfb->CreateSurface( dfb, &desc, &bgsurface ) );


          provider->RenderTo( provider, bgsurface, NULL );
          provider->Release( provider );

	  DFBCHECK(bgsurface->SetFont( bgsurface, font ));

          bgsurface->SetColor( bgsurface, 0xCF, 0xCF, 0xFF, 0xFF );
          bgsurface->DrawString( bgsurface,
                                 "Move the mouse over a window to activate it.",
                                 -1, 10, 0, DSTF_LEFT | DSTF_TOP );

          bgsurface->SetColor( bgsurface, 0xFF, 0xCF, 0xFF, 0xFF );
          bgsurface->DrawString( bgsurface,
                    "You can drag them around, too, if you want.",
                                 -1, 10 , 40, DSTF_LEFT | DSTF_TOP );

          bgsurface->SetColor( bgsurface, 0xCF, 0xCF, 0xFF, 0xFF );
	  bgsurface->DrawString( bgsurface,
                    "The one with funky stuff happening and things flying around is an evas.",
                                 -1, 10, 80, DSTF_LEFT | DSTF_TOP );




          layer->SetBackgroundImage( layer, bgsurface );
          layer->SetBackgroundMode( layer, DLBM_IMAGE );
     }
     {
	  DFBWindowDescription desc;
	  desc.flags = ( DWDESC_POSX | DWDESC_POSY |
                         DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_CAPS );

	  desc.posx = 20;
          desc.posy = 120;
          desc.width = 200;
          desc.height = 200;
	  desc.caps = DWCAPS_ALPHACHANNEL;

          DFBCHECK( layer->CreateWindow( layer, &desc, &window2 ) );
          window2->GetSurface( window2, &window_surface2 );

          window2->SetOpacity( window2, 0xFF );

          window2->CreateEventBuffer( window2, &buffer );

	  {
	     window_surface2->SetColor( window_surface2,
		   0x00, 0x30, 0x10, 0xc0 );
	     window_surface2->DrawRectangle( window_surface2, 0, 0,
		   desc.width, desc.height );
	     window_surface2->SetColor( window_surface2,
		   0x80, 0xa0, 0x00, 0x90 );
	     window_surface2->FillRectangle( window_surface2, 1, 1,
		   desc.width-2, desc.height-2 );


	     DFBCHECK(window_surface2->SetFont(window_surface2, font ));
	     window_surface2->SetColor( window_surface2, 0xCF, 0xFF, 0xCF, 0xFF );

	     window_surface2->DrawString( window_surface2,
		   "Pants!",
		   -1,10, fontheight + 5, DSTF_LEFT | DSTF_TOP );

	  }

          window_surface2->Flip( window_surface2, NULL, 0 );
     }

     {
          DFBWindowDescription desc;

          desc.flags = ( DWDESC_POSX | DWDESC_POSY |
                         DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_CAPS );
          desc.posx = 200;
          desc.posy = 200;
          desc.width = 240;
          desc.height = 320;
          desc.caps = DWCAPS_ALPHACHANNEL;

          DFBCHECK(layer->CreateWindow( layer, &desc, &window1 ) );
          window1->GetSurface( window1, &window_surface1 );

          window_surface1->SetColor( window_surface1, 0xFF, 0x20, 0x20, 0x90 );
          window_surface1->DrawRectangle( window_surface1, 0, 0,
                                          desc.width, desc.height );

          window_surface1->Flip( window_surface1, NULL, 0 );

          window1->SetOpacity( window1, 0xFF );

          window1->GetID( window1, &id1 );

          window1->AttachEventBuffer( window1, buffer );
     }

     window1->RequestFocus( window1 );
     window1->RaiseToTop( window1 );
     upper = window1;
     {
	evas_init();
	evas = evas_new();
	evas_output_method_set(evas, evas_render_method_lookup("directfb"));
	evas_output_size_set(evas, 240, 320);
	evas_output_viewport_set(evas, 0, 0, 240, 320);
	{
	   Evas_Engine_Info_DirectFB *einfo;

	   einfo = (Evas_Engine_Info_DirectFB *) evas_engine_info_get(evas);

	   einfo->info.dfb = dfb;
	   einfo->info.surface = window_surface1;
	   einfo->info.flags = DSDRAW_BLEND;
	   evas_engine_info_set(evas, (Evas_Engine_Info *) einfo);
	}
	setup();
	evas_render(evas);
	start_time = get_time();
     }

     while (!quit) {
          static IDirectFBWindow* active = NULL;
          static int grabbed = 0;
          static int startx = 0;
          static int starty = 0;
          static int endx = 0;
          static int endy = 0;
          DFBWindowEvent evt;

          buffer->WaitForEventWithTimeout( buffer, 0, 10 );

          while (buffer->GetEvent( buffer, DFB_EVENT(&evt) ) == DFB_OK) {
               IDirectFBWindow* window;

               if (evt.window_id == id1)
                    window = window1;
               else
                    window = window2;

               if (active) {
                    switch (evt.type) {

                    case DWET_BUTTONDOWN:
                         if (!grabbed && evt.button == DIBI_LEFT) {
                              grabbed = 1;
                              layer->GetCursorPosition( layer,
                                                        &startx, &starty );
                              window->GrabPointer( window );
                         }
                         break;

                    case DWET_BUTTONUP:
                         switch (evt.button) {
                              case DIBI_LEFT:
                                   if (grabbed) {
                                        window->UngrabPointer( window );
                                        grabbed = 0;
                                   }
                                   break;
                              case DIBI_MIDDLE:
                                   upper->LowerToBottom( upper );
                                   upper = (upper == window1) ? window2 : window1;
                                   break;
                              case DIBI_RIGHT:
                                   quit = DIKS_DOWN;
                                   break;
                              default:
                                   break;
                         }
                         break;

                    case DWET_KEYDOWN:
                         if (grabbed)
                              break;
                         switch (evt.key_id) {
                              case DIKI_RIGHT:
                                   active->Move (active, 1, 0);
                                   break;
                              case DIKI_LEFT:
                                   active->Move (active, -1, 0);
                                   break;
                              case DIKI_UP:
                                   active->Move (active, 0, -1);
                                   break;
                              case DIKI_DOWN:
                                   active->Move (active, 0, 1);
                                   break;
                              default:
                                   break;
                         }
                         break;

                    case DWET_LOSTFOCUS:
                         if (!grabbed)
                              active = NULL;
                         break;

                    default:
                         break;

                    }
               }
               else if (evt.type == DWET_GOTFOCUS)
                    active = window;

               switch (evt.type) {

               case DWET_MOTION:
                    endx = evt.cx;
                    endy = evt.cy;
                    break;

               case DWET_KEYDOWN:
                    switch (evt.key_symbol) {
                    case DIKS_ESCAPE:
                    case DIKS_SMALL_Q:
                    case DIKS_CAPITAL_Q:
                    case DIKS_BACK:
                    case DIKS_STOP:
                         quit = 1;
                         break;
                    default:
                         break;
                    }
                    break;

               default:
                    break;
               }
          }

          if (active) {
               if (grabbed) {
                    active->Move( active, endx - startx, endy - starty);
                    startx = endx;
                    starty = endy;
               }
               active->SetOpacity( active,
                                   (sin( myclock()/300.0 ) * 85) + 170 );
          }
	  loop();
	  {
	     Eina_List *updates;

	     updates = evas_render_updates(evas);
	     /* efficient update.. only flip the rectangle regions that changed! */
	     if (updates)
	       {
		  DFBRegion region;
		  Eina_List *l;

		  for (l = updates; l; l = l->next)
		    {
		       Evas_Rectangle *rect;

		       rect = l->data;
		       region.x1 = rect->x;
		       region.y1 = rect->y;
		       region.x2 = rect->x + rect->w - 1;
		       region.y2 = rect->y + rect->h - 1;
		       window_surface1->Flip(window_surface1, &region,
					     DSFLIP_BLIT);
		    }
		  evas_render_updates_free(updates);
	       }
	  }
     }

     buffer->Release( buffer );
     window_surface2->Release( window_surface2 );
     window_surface1->Release( window_surface1 );
     window2->Release( window2 );
     window1->Release( window1 );
     layer->Release( layer );
     bgsurface->Release( bgsurface );
     dfb->Release( dfb );

   evas_shutdown();
   return 0;
}
コード例 #16
0
ファイル: df_porter.c プロジェクト: openDFB/openDFB-examples
int main( int argc, char *argv[] )
{
     int                     i;
     int                     step;
     DFBResult               err;
     DFBSurfaceDescription   sdsc;
     DFBFontDescription      fdsc;
     IDirectFBImageProvider *provider;

     DFBCHECK(DirectFBInit( &argc, &argv ));

     /* create the super interface */
     DFBCHECK(DirectFBCreate( &dfb ));

     /* create an event buffer with all devices attached that have keys */
     DFBCHECK(dfb->CreateInputEventBuffer( dfb, DIDCAPS_KEYS, 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;
     sdsc.caps  = DSCAPS_PRIMARY | DSCAPS_FLIPPING | DSCAPS_PREMULTIPLIED;

     DFBCHECK(dfb->CreateSurface( dfb, &sdsc, &primary ));

     primary->Clear( primary, 0, 0, 0, 0 );
     primary->Flip( primary, NULL, DSFLIP_NONE );

     primary->GetSize( primary, &screen_width, &screen_height );

     step = screen_width / 5;


     /* create the temporary surface */
     sdsc.flags       = DSDESC_CAPS | DSDESC_PIXELFORMAT | DSDESC_WIDTH | DSDESC_HEIGHT;
     sdsc.caps        = DSCAPS_PREMULTIPLIED;
     sdsc.pixelformat = DSPF_ARGB;
     sdsc.width       = screen_width;
     sdsc.height      = screen_height;

     DFBCHECK(dfb->CreateSurface( dfb, &sdsc, &tempsurf ));



     /* Load background image. */
     DFBCHECK(dfb->CreateImageProvider( dfb, DATADIR"/wood_andi.jpg", &provider ));

     /* Render to temporary surface. */
     provider->RenderTo( provider, tempsurf, NULL );
     provider->Release( provider );

     /* Blit background onto primary surface (dimmed). */
     primary->SetBlittingFlags( primary, DSBLIT_COLORIZE );
     primary->SetColor( primary, 190, 200, 180, 0 );
     primary->Blit( primary, tempsurf, NULL, 0, 0 );


     tempsurf->Clear( tempsurf, 0, 0, 0, 0 );


     tempsurf->SetDrawingFlags( tempsurf, DSDRAW_SRC_PREMULTIPLY | DSDRAW_BLEND );
     tempsurf->SetPorterDuff( tempsurf, DSPD_SRC );

     fdsc.flags = DFDESC_HEIGHT;
     fdsc.height = screen_width/24;

     DFBCHECK(dfb->CreateFont( dfb, FONT, &fdsc, &font ));
     DFBCHECK(tempsurf->SetFont( tempsurf, font ));

     tempsurf->SetColor( tempsurf, 0xFF, 0xFF, 0xFF, 0xFF );
     tempsurf->DrawString( tempsurf, "Porter/Duff Demo", -1, screen_width/2, 20, DSTF_TOPCENTER );

     font->Release( font );


     fdsc.height = screen_width/32;

     DFBCHECK(dfb->CreateFont( dfb, FONT, &fdsc, &font ));
     DFBCHECK(tempsurf->SetFont( tempsurf, font ));


     for (i=0; i<num_rules; i++) {
          int x = (1 + i % 4) * step;
          int y = (0 + i / 4) * 180;
          DFBAccelerationMask mask;
          char *str;

          str = strdup( rules[i] );

          tempsurf->SetPorterDuff( tempsurf, DSPD_SRC );
          tempsurf->SetColor( tempsurf, 255, 0, 0, 140 );
          tempsurf->FillRectangle( tempsurf, x - 50, y + 100, 80, 70 );

          tempsurf->SetPorterDuff( tempsurf, i+1 );
          tempsurf->SetColor( tempsurf, 0, 0, 255, 200 );
          tempsurf->FillRectangle( tempsurf, x - 30, y + 130, 80, 70 );

          tempsurf->GetAccelerationMask( tempsurf, NULL, &mask );
          if (mask & DFXL_FILLRECTANGLE)
               str[0] = '*';

          tempsurf->SetPorterDuff( tempsurf, DSPD_SRC_OVER );
          tempsurf->SetColor( tempsurf, 6*0x1F, 6*0x10+0x7f, 0xFF, 0xFF );
          tempsurf->DrawString( tempsurf, str, -1, x, y + 210, DSTF_CENTER | DSTF_TOP );

          free( str );
     }

     font->Release( font );


     primary->SetBlittingFlags( primary, DSBLIT_BLEND_ALPHACHANNEL );
     primary->SetPorterDuff( primary, DSPD_SRC_OVER );
     primary->Blit( primary, tempsurf, NULL, 0, 0 );

     primary->Flip( primary, NULL, DSFLIP_NONE );


     while (1) {
          DFBInputEvent ev;

          events->WaitForEvent( events );

          events->GetEvent( events, DFB_EVENT(&ev) );

          if (ev.type == DIET_KEYRELEASE && ev.key_symbol == DIKS_ESCAPE)
               break;
     }

     /* release our interfaces to shutdown DirectFB */
     tempsurf->Release( tempsurf );
     primary->Release( primary );
     events->Release( events );
     dfb->Release( dfb );

     return 0;
}
コード例 #17
0
ファイル: video_td.cpp プロジェクト: FFTEAM/evolux-spark-sh4
void cVideo::ShowPicture(const char * fname)
{
	lt_debug("%s(%s)\n", __FUNCTION__, fname);
	char destname[512];
	char cmd[512];
	char *p;
	void *data;
	int mfd;
	struct stat st;
	strcpy(destname, "/var/cache");
	mkdir(destname, 0755);
	/* the cache filename is (example for /share/tuxbox/neutrino/icons/radiomode.jpg):
	   /var/cache/share.tuxbox.neutrino.icons.radiomode.jpg.m2v
	   build that filename first...
	   TODO: this could cause name clashes, use a hashing function instead... */
	strcat(destname, fname);
	p = &destname[strlen("/var/cache/")];
	while ((p = strchr(p, '/')) != NULL)
		*p = '.';
	strcat(destname, ".m2v");
	/* ...then check if it exists already...
	   TODO: check if the cache file is older than the jpeg file... */
	if (access(destname, R_OK))
	{
		/* it does not exist, so call ffmpeg to create it... */
		sprintf(cmd, "ffmpeg -y -f mjpeg -i '%s' -s 704x576 '%s' </dev/null",
							fname, destname);
		system(cmd); /* TODO: use libavcodec to directly convert it */
	}
	/* the mutex is a workaround: setBlank is apparently called from
	   a differnt thread and takes slightly longer, so that the decoder
	   was blanked immediately after displaying the image, which is not
	   what we want. the mutex ensures proper ordering. */
	pthread_mutex_lock(&stillp_mutex);
	mfd = open(destname, O_RDONLY);
	if (mfd < 0)
	{
		lt_info("%s cannot open %s: %m", __FUNCTION__, destname);
		goto out;
	}
	if (fstat(mfd, &st) != -1 && st.st_size > 0)
	{
		data = malloc(st.st_size);
		if (! data)
			lt_info("%s malloc failed (%m)\n", __FUNCTION__);
		else if (read(mfd, data, st.st_size) != st.st_size)
			lt_info("%s short read (%m)\n", __FUNCTION__);
		else
		{
			BUFINFO buf;
			buf.ulLen = st.st_size;
			buf.ulStartAdrOff = (int)data;
			Stop(false);
			fop(ioctl, MPEG_VID_STILLP_WRITE, &buf);
		}
		free(data);
	}
	close(mfd);
 out:
	pthread_mutex_unlock(&stillp_mutex);
	return;
#if 0
	/* DirectFB based picviewer: works, but is slow and the infobar
	   draws in the same plane */
	int width;
	int height;
	if (!fname)
		return;

	IDirectFBImageProvider *provider;
	DFBResult err = dfb->CreateImageProvider(dfb, fname, &provider);
	if (err)
	{
		fprintf(stderr, "cVideo::ShowPicture: CreateImageProvider error!\n");
		return;
	}

	DFBSurfaceDescription desc;
	provider->GetSurfaceDescription (provider, &desc);
	width = desc.width;
	height = desc.height;
	provider->RenderTo(provider, dfbdest, NULL);
	provider->Release(provider);
#endif
}
コード例 #18
0
int
main( int argc, char *argv[] )
{
    int                     i;
    DFBResult               ret;
    DFBSurfaceDescription   desc;
    IDirectFB              *dfb;
    IDirectFBImageProvider *provider = NULL;
    IDirectFBSurface       *source   = NULL;
    IDirectFBSurface       *dest     = NULL;
    IDirectFBSurface       *dest2    = NULL;
    const char             *url      = NULL;

    /* Initialize DirectFB. */
    ret = DirectFBInit( &argc, &argv );
    if (ret) {
        D_DERROR( ret, "DFBTest/Scale: DirectFBInit() failed!\n" );
        return ret;
    }

    /* Parse arguments. */
    for (i=1; i<argc; i++) {
        if (!strcmp( argv[i], "-h" ))
            return show_usage( argv[0] );
        else if (!url)
            url = argv[i];
        else
            return show_usage( argv[0] );
    }

    /* Check if we got an URL. */
    if (!url)
        return show_usage( argv[0] );

    /* Create super interface. */
    ret = DirectFBCreate( &dfb );
    if (ret) {
        D_DERROR( ret, "DFBTest/Scale: DirectFBCreate() failed!\n" );
        return ret;
    }

    /* Create an image provider for the image to be loaded. */
    ret = dfb->CreateImageProvider( dfb, url, &provider );
    if (ret) {
        D_DERROR( ret, "DFBTest/Scale: IDirectFB::CreateImageProvider( '%s' ) failed!\n", url );
        goto out;
    }

    /* Get the surface description. */
    ret = provider->GetSurfaceDescription( provider, &desc );
    if (ret) {
        D_DERROR( ret, "DFBTest/Scale: IDirectFBImageProvider::GetSurfaceDescription() failed!\n" );
        goto out;
    }

    desc.pixelformat = DSPF_NV21;

    D_INFO( "DFBTest/Scale: Source is %dx%d using %s\n",
            desc.width, desc.height, dfb_pixelformat_name(desc.pixelformat) );

    /* Create a surface for the image. */
    ret = dfb->CreateSurface( dfb, &desc, &source );
    if (ret) {
        D_DERROR( ret, "DFBTest/Scale: IDirectFB::CreateSurface() failed!\n" );
        goto out;
    }

    ret = provider->RenderTo( provider, source, NULL );
    if (ret) {
        D_DERROR( ret, "DFBTest/Scale: IDirectFBImageProvider::RenderTo() failed!\n" );
        goto out;
    }

    desc.width  = desc.width  * 3 / 4;
    desc.height = desc.height * 3 / 4;

    D_INFO( "DFBTest/Scale: Destination is %dx%d using %s\n",
            desc.width, desc.height, dfb_pixelformat_name(desc.pixelformat) );

    /* Create a surface for the image. */
    ret = dfb->CreateSurface( dfb, &desc, &dest );
    if (ret) {
        D_DERROR( ret, "DFBTest/Scale: IDirectFB::CreateSurface() failed!\n" );
        goto out;
    }

    DFBRectangle srect = {
        10, 10, 200, 200
    };

    DFBRectangle drect = {
        10, 10, 300, 300
    };

    DFBRegion clip = {
        40, 40, 199, 199
    };

    dest->Clear( dest, 0xff, 0xff, 0xff, 0xff );

    dest->SetClip( dest, &clip );
    dest->StretchBlit( dest, source, &srect, &drect );


    desc.pixelformat = DSPF_ARGB;

    D_INFO( "DFBTest/Scale: Destination2 is %dx%d using %s\n",
            desc.width, desc.height, dfb_pixelformat_name(desc.pixelformat) );

    /* Create a surface for the image. */
    ret = dfb->CreateSurface( dfb, &desc, &dest2 );
    if (ret) {
        D_DERROR( ret, "DFBTest/Scale: IDirectFB::CreateSurface() failed!\n" );
        goto out;
    }

    dest2->Blit( dest2, dest, NULL, 0, 0 );

    dest2->Dump( dest2, "dfbtest_scale_nv21", NULL );


out:
    if (dest2)
        dest2->Release( dest2 );

    if (dest)
        dest->Release( dest );

    if (source)
        source->Release( source );

    if (provider)
        provider->Release( provider );

    /* Shutdown DirectFB. */
    dfb->Release( dfb );

    return ret;
}