コード例 #1
0
ファイル: im.c プロジェクト: China-ls/virtuoso-opensource
caddr_t bif_im_ConvertImageBlob (caddr_t * qst, caddr_t * err, state_slot_t ** args)
{
  im_env_t env;
  caddr_t res;
        char out_name[64];
  caddr_t format = bif_string_arg (qst, args, 2, "IM ConvertImageBlob");
  im_init (&env, qst, args, "IM ConvertImageBlob");
  im_env_set_input_blob (&env, 0);
  im_env_set_blob_ext (&env, 3, -1);
  im_read (&env);

        if (env.ime_input_ext != NULL)
        {
                if (strlen(format) < 30)
                {
                        strcpy(out_name, "image.");                                                                                                                                                               
                        strcat(out_name, format);                                                                                                                                                              
                }
	}
  MagickResetIterator (env.ime_magick_wand);
  while (MagickNextImage (env.ime_magick_wand) != MagickFalse)
  {
    env.ime_status = MagickSetImageFormat (env.ime_magick_wand, format);
    MagickSetFilename (env.ime_magick_wand, out_name);
    if (env.ime_status == MagickFalse)
      im_leave_with_error (&env, "22023", "IM001", "bif_im_ConvertImageBlob cannot convert image");
    }
  res = im_write (&env);
  im_leave (&env);
  return res;
}
コード例 #2
0
ファイル: im.c プロジェクト: China-ls/virtuoso-opensource
caddr_t bif_im_CropAndResizeImageBlob(caddr_t * qst, caddr_t * err, state_slot_t ** args)
  {
  im_env_t env;
  caddr_t res;
  unsigned long width = bif_long_arg (qst, args, 2, "IM CropAndResizeImageBlob");
  unsigned long height = bif_long_arg (qst, args, 3, "IM CropAndResizeImageBlob");
  long x = bif_long_arg (qst, args, 4, "IM CropAndResizeImageBlob");
  long y = bif_long_arg (qst, args, 5, "IM CropAndResizeImageBlob");
  long h_size = bif_long_arg (qst, args, 6, "IM ResizeImageBlob");
  long v_size = bif_long_arg (qst, args, 7, "IM ResizeImageBlob");
  double blur = bif_double_arg (qst, args, 8, "IM ResizeImageBlob");
  long filter = bif_long_arg (qst, args, 9, "IM ResizeImageBlob");
  if (filter < 0 || filter > 15)
    filter = PointFilter;
  im_init (&env, qst, args, "IM CropAndResizeImageBlob");
  im_env_set_input_blob (&env, 0);
  im_env_set_blob_ext (&env, 10, -1);
  im_read (&env);
  MagickResetIterator (env.ime_magick_wand);
  while (MagickNextImage (env.ime_magick_wand) != MagickFalse)
  {
      MagickCropImage (env.ime_magick_wand, width, height, x, y);
      MagickResizeImage (env.ime_magick_wand, h_size, v_size, filter, blur);
  }
  res = im_write (&env);
  im_leave (&env);
  return res;
}
コード例 #3
0
ファイル: im.c プロジェクト: China-ls/virtuoso-opensource
caddr_t 
bif_im_CreateImageBlob (caddr_t * qst, caddr_t * err, state_slot_t ** args)
{
  im_env_t env;
  char * szMe = "IM CreateImageBlob";
  caddr_t res;
  long x_size = bif_long_arg (qst, args, 0, szMe);
  long y_size = bif_long_arg (qst, args, 1, szMe);
  caddr_t bg_color = (caddr_t)bif_string_arg (qst, args, 2, szMe);
  caddr_t fmt = (caddr_t)bif_string_arg (qst, args, 3, szMe);
  im_init (&env, qst, args, "IM CreateImageBlob");
  if (x_size <= 0 || y_size <= 0)
    im_leave_with_error (&env, "22023", "IM001", "Negative image size");
  if (x_size*y_size > 3333279) /* 10M / 3 color - 54byte */
    im_leave_with_error (&env, "22023", "IM001", "Too large image image size requested");
  im_set_background (&env, bg_color);
  env.ime_status = MagickNewImage (env.ime_magick_wand, x_size, y_size, env.ime_background);
  if (env.ime_status == MagickFalse)
    im_leave_with_error (&env, "22023", "IM001", "Cannot create image");
  env.ime_status = MagickSetImageFormat (env.ime_magick_wand, fmt);
  if (env.ime_status == MagickFalse)
    im_leave_with_error (&env, "22023", "IM001", "Cannot set image format");
  res = im_write (&env);
  im_leave (&env);
  return res;
}
コード例 #4
0
ファイル: im.c プロジェクト: China-ls/virtuoso-opensource
caddr_t bif_im_DeepZoom4to1 (caddr_t * qst, caddr_t * err, state_slot_t ** args)
  {
  im_env_t env;
  caddr_t res;
  int fmt_is_set = 0;
  int image_ctr;
  im_init (&env, qst, args, "IM DeepZoom4to1");
  im_set_background (&env, "#000000");
  env.ime_target_magick_wand = NewMagickWand ();
  if (MagickFalse == MagickNewImage (env.ime_target_magick_wand, 256, 256, env.ime_background))
    im_leave_with_error (&env, "22023", "IM001", "Can not make new image");
  if (MagickFalse == MagickSetImageType (env.ime_target_magick_wand, TrueColorType))
    im_leave_with_error (&env, "22023", "IM001", "Can not set image type");
  if (MagickFalse == MagickSetImageDepth (env.ime_target_magick_wand, 16))
    im_leave_with_error (&env, "22023", "IM001", "Can not set image depth");
  if (MagickFalse == MagickSetImageExtent (env.ime_target_magick_wand, 256, 256))
    im_leave_with_error (&env, "22023", "IM001", "Can not set image extent");
  if (MagickFalse == MagickSetImageBackgroundColor (env.ime_target_magick_wand, env.ime_background))
    im_leave_with_error (&env, "22023", "IM001", "Can not set image background");
  image_ctr = BOX_ELEMENTS (args) / 2;
  if (image_ctr > 4)
    image_ctr = 4;
  while (0 < image_ctr--)
    {
      if (DV_DB_NULL == DV_TYPE_OF (bif_arg (qst, args, image_ctr*2, "IM DeepZoom4to1")))
        continue;
      im_env_set_input_blob (&env, image_ctr * 2);
      /*im_env_set_blob_ext (&env, 2);*/
      im_read (&env);
      MagickResetIterator (env.ime_magick_wand);
      while (MagickNextImage (env.ime_magick_wand) != MagickFalse)
        {
          unsigned long v_size, h_size;
          if (!fmt_is_set)
            {
              if (MagickFalse == MagickSetImageFormat (env.ime_target_magick_wand, MagickGetImageFormat (env.ime_magick_wand)))
                im_leave_with_error (&env, "22023", "IM001", "Can not set image format");
              fmt_is_set = 1;
            }
          h_size = MagickGetImageWidth (env.ime_magick_wand);
          v_size = MagickGetImageHeight (env.ime_magick_wand);
          if ((256 < h_size) || (256 < v_size))
            continue;
          MagickResizeImage (env.ime_magick_wand, h_size/2, v_size/2, BoxFilter, 1.0);
          if (MagickFalse == MagickCompositeImage (env.ime_target_magick_wand, env.ime_magick_wand, OverCompositeOp, (image_ctr & 1) * 128, (image_ctr & 2) * 64))
            im_leave_with_error (&env, "22023", "IM001", "Can not composite image");
        }
      im_reset_read (&env);
    }
  MagickProfileImage (env.ime_target_magick_wand, "*", NULL, 0);
  DestroyMagickWand (env.ime_magick_wand);
  env.ime_magick_wand = env.ime_target_magick_wand;
  env.ime_target_magick_wand = NULL;
  res = im_write (&env);
  im_leave (&env);
  return res;
}
コード例 #5
0
ファイル: im.c プロジェクト: China-ls/virtuoso-opensource
caddr_t bif_im_ConvertImageFile (caddr_t * qst, caddr_t * err, state_slot_t ** args)
{
  im_env_t env;
  bif_string_arg (qst, args, 1, "IM ConvertImageFile");
  im_init (&env, qst, args, "IM ConvertImageFile");
  im_env_set_filenames (&env, 0, 1);
  im_read (&env);
  im_write (&env);
  im_leave (&env);
  return(0);
  }
コード例 #6
0
ファイル: top_main.cpp プロジェクト: liororama/gossimon
int main(int argc, char **argv) 
{
    void *data;
    mlog_init();
    TopSaxParser parser1;
        
    // Debugging if argc > 1
    if(argc > 1) {

        mlog_registerColorFormatter((color_formatter_func_t)sprintf_color);
        mlog_addOutputFile((char *)"/dev/tty", 1);
        mlog_setModuleLevel((char *)"top", LOG_DEBUG);
        mlog_setModuleLevel((char *)"topparser", LOG_DEBUG);
    
    }
    // init
    im_init(&data, NULL);
    
    // sleep
    sleep(1);
    
    while(1) {
        // update
        im_update(data);
        
        int i = 16000;
        im_get(data, buff, &i);
        //system("clear");
        //printf("%s", buff);
        //printf("\n");

        
        processVecT v;
        TopSaxParser parser;
        parser.parse(std::string(buff), v);
        std::cout << "================= Top Processes: " << v.size() << " ======================" << std::endl;
        for(std::vector<ProcessStatusInfo>::iterator iter = v.begin() ; iter != v.end() ; iter++) {
            ProcessStatusInfo *pi = &(*iter);
            std::cout << "XML:" << std::endl << pi->getProcessXML();
        }
        sleep(3);

    }
    
    // free
    im_free(&data);
    
    free(buff);
    return 0;
}       
コード例 #7
0
ファイル: meminfo_main.cpp プロジェクト: liororama/gossimon
int main(int argc, char **argv) 
{
    void *data;
    mlog_init();
//    MeminfoSaxParser parser1;
        
    // Debugging if argc > 1
    if(argc > 1) {

        mlog_registerColorFormatter((color_formatter_func_t)sprintf_color);
        mlog_addOutputFile((char *)"/dev/tty", 1);
        mlog_setModuleLevel((char *)"meminfo", LOG_DEBUG);
        mlog_setModuleLevel((char *)"meminfoparser", LOG_DEBUG);
    
    }
    // init
    im_init(&data, NULL);
    
    // sleep
    sleep(1);
    
    while(1) {
        // update
        im_update(data);
        
        int i = 8192;
        im_get(data, buff, &i);
        //system("clear");
        printf("%s", buff);
        printf("\n");

        
        MeminfoSaxParser parser;
        Meminfo mi;
        parser.parse(std::string(buff), mi);
       
        std::cout << mi.get_xml();
        std::cout << "====================================================" << std::endl << std::endl;
        sleep(1);

    }
    
    // free
    im_free(&data);
    
    free(buff);
    return 0;
}       
コード例 #8
0
ファイル: im.c プロジェクト: China-ls/virtuoso-opensource
caddr_t bif_im_RotateImageFile (caddr_t * qst, caddr_t * err, state_slot_t ** args)
{
  im_env_t env;
  double v_size = bif_double_arg (qst, args, 1, "IM RotateImageFile");
  im_init (&env, qst, args, "IM RotateImageFile");
  im_env_set_filenames (&env, 0, 2);
  im_read (&env);
  im_set_background (&env, "#000000");
  MagickResetIterator (env.ime_magick_wand);
  while (MagickNextImage (env.ime_magick_wand) != MagickFalse)
  {
    MagickRotateImage (env.ime_magick_wand, env.ime_background, v_size);
  }
  im_write (&env);
  im_leave (&env);
  return (0);
}
コード例 #9
0
ファイル: im.c プロジェクト: China-ls/virtuoso-opensource
caddr_t bif_im_CropImageFile (caddr_t * qst, caddr_t * err, state_slot_t ** args)
{
  im_env_t env;
  unsigned long width = (unsigned long) bif_long_arg (qst, args, 1, "IM CropImageFile");
  unsigned long height = (unsigned long) bif_long_arg (qst, args, 2, "IM CropImageFile");
  long x = bif_long_arg (qst, args, 3, "IM CropImageFile");
  long y = bif_long_arg (qst, args, 4, "IM CropImageFile");
  im_init (&env, qst, args, "IM CropImageFile");
  im_env_set_filenames (&env, 0, 5);
  im_read (&env);
  MagickResetIterator (env.ime_magick_wand);
  while (MagickNextImage (env.ime_magick_wand) != MagickFalse)
  {
      MagickCropImage (env.ime_magick_wand, width, height, x, y);
  }
  im_write (&env);
  im_leave (&env);
  return (0);
}
コード例 #10
0
ファイル: im.c プロジェクト: China-ls/virtuoso-opensource
caddr_t bif_im_RotateImageBlob (caddr_t * qst, caddr_t * err, state_slot_t ** args)
{
  im_env_t env;
  caddr_t res;
  double v_size = bif_double_arg (qst, args, 2, "IM RotateImageBlob");
  im_init (&env, qst, args, "IM RotateImageBlob");
  im_env_set_input_blob (&env, 0);
  im_env_set_blob_ext (&env, 3, -1);
  im_read (&env);
  im_set_background (&env, "#000000");
  MagickResetIterator (env.ime_magick_wand);
  while (MagickNextImage (env.ime_magick_wand) != MagickFalse)
  {
    MagickRotateImage (env.ime_magick_wand, env.ime_background, v_size);
  }
  res = im_write (&env);
  im_leave (&env);
  return res;
}
コード例 #11
0
ファイル: im.c プロジェクト: China-ls/virtuoso-opensource
caddr_t bif_im_ThumbnailImageFile (caddr_t * qst, caddr_t * err, state_slot_t ** args)
{
  im_env_t env;
  long v_size = bif_long_arg (qst, args, 1, "IM ThumbnailImageFile");
  long h_size = bif_long_arg (qst, args, 2, "IM ThumbnailImageFile");
  long filter = bif_long_arg (qst, args, 3, "IM ThumbnailImageFile");
  im_init (&env, qst, args, "IM ThumbnailImageFile");
  im_env_set_filenames (&env, 0, 4);
  im_read (&env);
  MagickResetIterator (env.ime_magick_wand);
  while (MagickNextImage (env.ime_magick_wand) != MagickFalse)
  {
    MagickResizeImage (env.ime_magick_wand,v_size, h_size,filter,1.0);
    MagickProfileImage (env.ime_magick_wand, "*", NULL, 0);
  }
  im_write (&env);
  im_leave (&env);
  return(0);
}
コード例 #12
0
ファイル: im.c プロジェクト: China-ls/virtuoso-opensource
caddr_t 
bif_im_AnnotateImageBlob (caddr_t * qst, caddr_t * err, state_slot_t ** args)
{
  char * szMe = "IM AnnotateImageBlob";
  caddr_t res;
  caddr_t blob = (caddr_t)bif_arg (qst, args, 0, szMe);
  long blob_size = box_length (blob) - 1;
  long x_pos = bif_long_arg (qst, args, 1, szMe);
  long y_pos = bif_long_arg (qst, args, 2, szMe);
  caddr_t text = bif_string_arg (qst, args, 3, szMe);
  int n_args = BOX_ELEMENTS(args);
  long angle = n_args > 4 ? bif_long_arg (qst, args, 4, szMe) : 0;
  long f_size = n_args > 5 ? bif_long_arg (qst, args, 5, szMe) : 12;
  char *text_color = n_args > 6 ? bif_string_arg (qst, args, 6, szMe) : "black" ;
  dtp_t dtp = DV_TYPE_OF (blob);
  im_env_t env;
  im_init (&env, qst, args, "IM AnnotateImageBlob");
  if (IS_STRING_DTP (dtp))
    blob_size = box_length (blob) - 1;
  else if (dtp == DV_BIN)
    blob_size = box_length (blob);
  else
    im_leave_with_error (&env, "22023", "IM001", "AnnotateImageBlob needs string or binary as 1-st argument");
  im_env_set_blob_ext (&env, 7, -1);

  env.ime_drawing_wand = NewDrawingWand ();
  im_read (&env);
  im_set_background (&env, text_color);
  DrawSetFillColor (env.ime_drawing_wand, env.ime_background);
  DrawSetFontSize (env.ime_drawing_wand, f_size);
  MagickResetIterator  (env.ime_magick_wand);
  while (MagickNextImage  (env.ime_magick_wand) != MagickFalse)
    {
      env.ime_status = MagickAnnotateImage  (env.ime_magick_wand, env.ime_drawing_wand, x_pos, y_pos, angle, text);
      if (env.ime_status == MagickFalse)
        im_leave_with_error (&env, "22023", "IM001", "Cannot annotate image");
    }
  res = im_write (&env);
  im_leave (&env);
  return res;
}
コード例 #13
0
ファイル: im.c プロジェクト: China-ls/virtuoso-opensource
caddr_t bif_im_CropImageBlob(caddr_t * qst, caddr_t * err, state_slot_t ** args)
{
  im_env_t env;
  caddr_t res;
  unsigned long width = bif_long_arg (qst, args, 2, "IM CropImageBlob");
  unsigned long height = bif_long_arg (qst, args, 3, "IM CropImageBlob");
  long x = bif_long_arg (qst, args, 4, "IM CropImageBlob");
  long y = bif_long_arg (qst, args, 5, "IM CropImageBlob");
  im_init (&env, qst, args, "IM CropImageBlob");
  im_env_set_input_blob (&env, 0);
  im_env_set_blob_ext (&env, 6, -1);
  im_read (&env);
  MagickResetIterator (env.ime_magick_wand);
  while (MagickNextImage (env.ime_magick_wand) != MagickFalse)
	{
      MagickCropImage (env.ime_magick_wand, width, height, x, y);
	}
  res = im_write (&env);
  im_leave (&env);
  return res;
  }
コード例 #14
0
ファイル: im.c プロジェクト: China-ls/virtuoso-opensource
caddr_t bif_im_ResizeImageFile (caddr_t * qst, caddr_t * err, state_slot_t ** args)
{
  im_env_t env;
  long v_size = bif_long_arg (qst, args, 1, "IM ResizeImageFile");
  long h_size = bif_long_arg (qst, args, 2, "IM ResizeImageFile");
  double blur = bif_double_arg (qst, args, 3, "IM ResizeImageFile");
  long filter = bif_long_arg (qst, args, 4, "IM ResizeImageFile");
  if (filter < 0 || filter > 15)
    filter = PointFilter;
  im_init (&env, qst, args, "IM ResiseImageFile");
  im_env_set_filenames (&env, 0, 5);
  im_read (&env);
  MagickResetIterator (env.ime_magick_wand);
  while (MagickNextImage (env.ime_magick_wand) != MagickFalse)
  {
    MagickResizeImage (env.ime_magick_wand,v_size, h_size,filter,blur);
  }
  im_write (&env);
  im_leave (&env);
  return(0);
}
コード例 #15
0
ファイル: im.c プロジェクト: China-ls/virtuoso-opensource
caddr_t bif_im_ResampleImageBlob (caddr_t * qst, caddr_t * err, state_slot_t ** args)
{
  im_env_t env;
  caddr_t res;
  double v_size = bif_double_arg (qst, args, 2, "IM ResampleImageBlob");
  double h_size = bif_double_arg (qst, args, 3, "IM ResampleImageBlob");
  double blur = bif_double_arg (qst, args, 4, "IM ResampleImageBlob");
  long filter = bif_long_arg (qst, args, 5, "IM ResampleImageBlob");
  if (filter < 0 || filter > 15)
    filter = PointFilter;
  im_init (&env, qst, args, "IM ResampleImageBlob");
  im_env_set_input_blob (&env, 0);
  im_env_set_blob_ext (&env, 6, -1);
  im_read (&env);
  MagickResetIterator (env.ime_magick_wand);
  while (MagickNextImage (env.ime_magick_wand) != MagickFalse)
  {
    MagickResampleImage (env.ime_magick_wand,v_size, h_size,filter,blur);
  }
  res = im_write (&env);
  im_leave (&env);
  return res;
}
コード例 #16
0
ファイル: im.c プロジェクト: China-ls/virtuoso-opensource
caddr_t bif_im_ThumbnailImageBlob (caddr_t * qst, caddr_t * err, state_slot_t ** args)
{
  im_env_t env;
  caddr_t res;
  long v_size = bif_long_arg (qst, args, 2, "IM ThumbnailImageBlob");
  long h_size = bif_long_arg (qst, args, 3, "IM ThumbnailImageBlob");
  long filter = bif_long_arg (qst, args, 4, "IM ThumbnailImageBlob");
  if (filter < 0 || filter > 15)
    filter = PointFilter;
  im_init (&env, qst, args, "IM ThumbnailImageBlob");
  im_env_set_input_blob (&env, 0);
  im_env_set_blob_ext (&env, 5, -1);
  im_read (&env);
  MagickResetIterator (env.ime_magick_wand);
  while (MagickNextImage (env.ime_magick_wand) != MagickFalse)
		{
    MagickResizeImage (env.ime_magick_wand,v_size, h_size,filter,1.0);
    MagickProfileImage (env.ime_magick_wand, "*", NULL, 0);
		}
  res = im_write (&env);
  im_leave (&env);
  return res;
	}
コード例 #17
0
int main(int argc, char *argv[])
{
        /* current configuration */
        LedPrefs *p = NULL;
    	/** current setup */
    	LedSetup *s = NULL;
        /** list of LED hardware adapters */
        LedHardware *hw = NULL;
        /* input pixel-frame buffer */
        LedFrame *frame = NULL;
        /** width of map */
        LedFrameCord width;
        /** height of map */
        LedFrameCord height;



        /* check libniftyled binary version compatibility */
        NFT_LED_CHECK_VERSION

        /* set default loglevel to INFO */
        nft_log_level_set(L_INFO);

        /* initialize exit handlers */
#if WIN32
        int signals[] = { SIGINT, SIGABRT };
#else
        int signals[] = { SIGHUP, SIGINT, SIGQUIT, SIGABRT };
#endif
        unsigned int i;
        for(i=0; i<sizeof(signals)/sizeof(int); i++)
        {
            if(signal(signals[i], _exit_signal_handler) == SIG_ERR)
            {
                NFT_LOG_PERROR("signal()");
                return -1;
            }
        }



        /* default result of main() function */
        int res = -1;

        /* default fps */
        _c.fps = 25;

        /* default endianess */
        _c.is_big_endian = FALSE;

#if HAVE_IMAGEMAGICK == 1
        /* default handle-input-as-raw */
        _c.raw = FALSE;
#endif

        /* default looping */
        _c.do_loop = FALSE;

        /* set "running" flag */
        _c.running = TRUE;

        /* default pixel-format */
        strncpy(_c.pixelformat, "RGB u8", sizeof(_c.pixelformat));

        /* default prefs-filename */
        if(!led_prefs_default_filename(_c.prefsfile, sizeof(_c.prefsfile), ".ledcat.xml"))
                return -1;


	/* parse commandline arguments */
	if(!_parse_args(argc, argv))
		return -1;



	/* print welcome msg */
	NFT_LOG(L_INFO, "%s %s (c) D.Hiepler 2006-2012", PACKAGE_NAME, ledcat_version_long());
	NFT_LOG(L_VERBOSE, "Loglevel: %s", nft_log_level_to_string(nft_log_level_get()));


#if HAVE_IMAGEMAGICK == 1
        /* initialize imagemagick */
        if(!_c.raw)
        {
                if(!im_init(&_c))
                {
                        NFT_LOG(L_ERROR, "Failed to initialize ImageMagick");
                        return -1;
                }
        }
#endif

    	/* initialize preferences context */
    	if(!(p = led_prefs_init()))
    		return -1;

	/* parse prefs-file */
    	LedPrefsNode *pnode;
    	if(!(pnode = led_prefs_node_from_file(_c.prefsfile)))
    	{
		NFT_LOG(L_ERROR, "Failed to open configfile \"%s\"",
		        		_c.prefsfile);
		goto m_deinit;
	}

        /* create setup from prefs-node */
    	if(!(s = led_prefs_setup_from_node(p, pnode)))
    	{
		NFT_LOG(L_ERROR, "No valid setup found in preferences file.");
		led_prefs_node_free(pnode);
		goto m_deinit;
	}

    	/* free preferences node */
    	led_prefs_node_free(pnode);

        /* determine width of input-frames */
        if(!_c.width)
                /* width of mapped chain */
                width = led_setup_get_width(s);
        else
                /* use value from cmdline arguments */
                width = _c.width;


        /* determine height of input-frames */
        if(!_c.height)
                /* height of mapped chain */
                height = led_setup_get_height(s);
        else
                height = _c.height;


        /* validate dimensions */
        if(width <= 0 || height <= 0)
        {
                NFT_LOG(L_ERROR, "Dimensions %dx%d not possible in this universe. Exiting.", width, height);
                goto m_deinit;
        }


	/* allocate frame (where our pixelbuffer resides) */
	NFT_LOG(L_INFO, "Allocating frame: %dx%d (%s)",
	        width, height, _c.pixelformat);
        LedPixelFormat *format = led_pixel_format_from_string(_c.pixelformat);
	if(!(frame = led_frame_new(width, height, format)))
		goto m_deinit;


        /* get first toplevel hardware */
        if(!(hw = led_setup_get_hardware(s)))
                goto m_deinit;

        /* initialize hardware */
	/*if(!(led_hardware_init(hw, ledcount, (LedGreyscaleFormat) format)))
	{
		NFT_LOG(L_ERROR, "failed to initialize hardware.");
                goto m_deinit;
	}*/

        /* initialize pixel->led mapping */
        if(!led_hardware_list_refresh_mapping(hw))
                goto m_deinit;

        /* precalc memory offsets for actual mapping */
        LedHardware *ch;
        for(ch = hw; ch; ch = led_hardware_list_get_next(ch))
        {
                if(!led_chain_map_from_frame(led_hardware_get_chain(ch), frame))
                        goto m_deinit;
        }

        /* set correct gain to hardware */
        if(!led_hardware_list_refresh_gain(hw))
                goto m_deinit;

#if HAVE_IMAGEMAGICK == 1
        /* determine format that ImageMagick should provide */
        if(!_c.raw)
        {
                if(!(im_format(&_c, format)))
                {
                        NFT_LOG(L_ERROR, "Failed to determine valid ImageMagick format");
                        goto m_deinit;
                }
        }
#endif

	/* do we have at least one filename? */
	if(!_c.files[0])
	{
		NFT_LOG(L_ERROR, "No input file(s) given");
		goto m_deinit;
	}


        /* initially sample time for frame-timing */
        if(!led_fps_sample())
                goto m_deinit;


#if ! WIN32
        /* initialize alarm-signal handler for periodical fps output */
        {
                struct sigaction sa;
                struct itimerval timer;

                memset(&sa, 0, sizeof(sa));
                sa.sa_handler = &_alarm_signal_handler;
                sigaction(SIGALRM, &sa, NULL);
                timer.it_value.tv_sec = 1;
                timer.it_value.tv_usec = 0;
                timer.it_interval.tv_sec = 1;
                timer.it_interval.tv_usec = 0;
                setitimer(ITIMER_REAL, &timer, NULL);
        }
#endif

        /* get data-buffer of frame to write our pixels to */
        char *buf;
        if(!(buf = led_frame_get_buffer(frame)))
        {
                NFT_LOG(L_ERROR, "Frame has NULL buffer");
                goto m_deinit;
        }


	/* walk all files (supplied as commandline arguments) and output them */
	int filecount;
	for(filecount = 0; _c.files[filecount]; filecount++)
	{

		NFT_LOG(L_VERBOSE, "Getting pixels from \"%s\"", _c.files[filecount]);

		/* open file */
		if(_c.files[filecount][0] == '-' && strlen(_c.files[filecount]) == 1)
		{
			_c.fd = STDIN_FILENO;
		}
		else
		{
			if((_c.fd = open(_c.files[filecount], O_RDONLY)) < 0)
			{
				NFT_LOG(L_ERROR, "Failed to open \"%s\": %s",
				        _c.files[filecount], strerror(errno));
				continue;
			}
		}

#if HAVE_IMAGEMAGICK == 1
                /** initialize stream for ImageMagick */
                if(!_c.raw)
                {
                        if(!(im_open_stream(&_c)))
                                continue;
                }
#endif



		/* output file frame-by-frame */
		while(_c.running)
		{

#if HAVE_IMAGEMAGICK == 1
                        /* use imagemagick to load file if we're not in "raw-mode" */
                        if(!_c.raw)
                        {
                                /* load frame to buffer using ImageMagick */
                                if(!im_read_frame(&_c, width, height, buf))
                                        break;

                        }
                        else
                        {
#endif
                                /* read raw frame */
                                if(raw_read_frame(&_c.running, buf, _c.fd,
                                               led_pixel_format_get_buffer_size(
                                                        led_frame_get_format(frame),
                                                        led_frame_get_width(frame)*led_frame_get_height(frame))) == 0)
                                        continue;

#if HAVE_IMAGEMAGICK == 1
                        }
#endif

                        /* set endianess (flag will be changed when conversion occurs) */
                        led_frame_set_big_endian(frame, _c.is_big_endian);

			/* print frame for debugging */
			//nft_frame_buffer_print(frame);

			/* fill chain of every hardware from frame */
                        LedHardware *h;
                        for(h = hw; h; h = led_hardware_list_get_next(h))
                        {
                                if(!led_chain_fill_from_frame(led_hardware_get_chain(h), frame))
                                {
                                        NFT_LOG(L_ERROR, "Error while mapping frame");
                                        break;
                                }
                        }

			/* send frame to hardware(s) */
			NFT_LOG(L_DEBUG, "Sending frame");
                        led_hardware_list_send(hw);

			/* delay in respect to fps */
			if(!led_fps_delay(_c.fps))
				break;

			/* latch hardware */
			NFT_LOG(L_DEBUG, "Showing frame");
                        led_hardware_list_show(hw);


			/* save time when frame is displayed */
			if(!led_fps_sample())
				break;


			/* clear frame */
			//nft_frame_clear_buffer(frame);

		}


#if HAVE_IMAGEMAGICK == 1
		if(!_c.raw)
                	im_close_stream(&_c);
#else
                close(_c.fd);
#endif

                /* loop endlessly? */
                if((_c.running) && (!_c.files[filecount+1]) && _c.do_loop)
                {
                        /* start over by resetting the for-loop */
                        filecount = -1;
                }
	}

        /* all ok */
        res = 0;

m_deinit:
    	/* free setup */
    	led_setup_destroy(s);

	/* free frame */
	led_frame_destroy(frame);

        /* destroy config */
        led_prefs_deinit(p);

#if HAVE_IMAGEMAGICK == 1
        /* deinitialize ImageMagick */
        im_deinit(&_c);
#endif

        return res;
}
コード例 #18
0
ファイル: im.c プロジェクト: China-ls/virtuoso-opensource
caddr_t
bif_im_get_impl (caddr_t * qst, caddr_t * err, state_slot_t ** args, int is_file_in, int op, const char *bifname)
  {
  im_env_t env;
  char *strg_value = NULL;
  unsigned long ul_value = 0;
  caddr_t res = NULL;
  int is_string_res = (('A' == op) || ('F' == op) || ('I' == op));
  int is_list_res = ('2' == op);
  int is_key_needed = ('A' == op);
  caddr_t key = is_key_needed ? bif_string_arg (qst, args, (is_file_in ? 1 : 2), bifname) : NULL;
  im_init (&env, qst, args, bifname);
  if (is_file_in)
    im_env_set_filenames (&env, 0, -1);
  else
{
      im_env_set_input_blob (&env, 0);
      im_env_set_blob_ext (&env, (is_key_needed ? 3 : 2), -1);
    }
  im_read (&env);
  MagickResetIterator(env.ime_magick_wand);
  while (MagickNextImage (env.ime_magick_wand) != MagickFalse)
	{
      switch (op)
		{
        case 'A': strg_value = MagickGetImageAttribute (env.ime_magick_wand, key); break;
        case 'F': strg_value = MagickGetImageFormat (env.ime_magick_wand); break;
        case 'I': strg_value = MagickIdentifyImage (env.ime_magick_wand); break;
        case 'W': ul_value = MagickGetImageWidth (env.ime_magick_wand); break;
        case 'H': ul_value = MagickGetImageHeight (env.ime_magick_wand); break;
        case 'D': ul_value = MagickGetImageDepth (env.ime_magick_wand); break;
        case '2':
          ul_value = MagickGetImageWidth (env.ime_magick_wand);
          if (ul_value)
  {
              dk_free_tree (res);
              res = dk_alloc_box (2 * sizeof (caddr_t), DV_ARRAY_OF_POINTER);
              ((caddr_t *)res)[0] = box_num (ul_value);
              ((caddr_t *)res)[1] = box_num (MagickGetImageHeight (env.ime_magick_wand));
  }
          break;
  }
}
  if (is_string_res)
	{
      if (strg_value)
		{
          res = box_dv_short_string (strg_value);
          MagickRelinquishMemory (strg_value);
		}
	}
  else if (!is_list_res)
  {
      if (ul_value)
        res = box_num (ul_value);
  }
  if (NULL == res)
    res = NEW_DB_NULL;
  im_leave (&env);
  return res;
}
コード例 #19
0
ファイル: edvips.c プロジェクト: nrobidoux/libvips
int
main( int argc, char **argv )
{
	GOptionContext *context;
	GError *error = NULL;
	IMAGE *im;
	unsigned char header[IM_SIZEOF_HEADER];

	if( im_init_world( argv[0] ) )
	        error_exit( "%s", _( "unable to start VIPS" ) );
	textdomain( GETTEXT_PACKAGE );
	setlocale( LC_ALL, "" );

	context = g_option_context_new( 
		_( "vipsfile - edit vipsfile header" ) );
	g_option_context_add_main_entries( context, entries, GETTEXT_PACKAGE );
	g_option_context_add_group( context, im_get_option_group() );
	if( !g_option_context_parse( context, &argc, &argv, &error ) ) {
		if( error ) {
			fprintf( stderr, "%s\n", error->message );
		        g_error_free( error );
		}

		exit( -1 );
	}
	if( argc != 2 ) {
		fprintf( stderr, _( "usage: %s [OPTION...] vipsfile\n" ), 
			g_get_prgname() );
		exit( -1 );
	}

	if( !(im = im_init( argv[1] )) ||
		(im->fd = im__open_image_file( im->filename )) == -1 ) 
		error_exit( _( "could not open image %s" ), argv[1] );
	if( read( im->fd, header, IM_SIZEOF_HEADER ) != IM_SIZEOF_HEADER ||
		im__read_header_bytes( im, header ) ) 
		error_exit( _( "could not read VIPS header for %s" ), 
			im->filename );

	if( xsize ) 
		parse_pint( xsize, &im->Xsize );
	if( ysize ) 
		parse_pint( ysize, &im->Ysize );
	if( bands ) 
		parse_pint( bands, &im->Bands );
	if( format ) {
		if( (im->BandFmt = im_char2BandFmt( format )) < 0 )
			error_exit( _( "bad format %s" ), format );
		im->Bbits = im_bits_of_fmt( im->BandFmt );
	}
	if( type ) {
		if( (im->Type = im_char2Type( type )) < 0 )
			error_exit( _( "bad type %s" ), type );
	}
	if( coding ) {
		if( (im->Coding = im_char2Coding( coding )) < 0 )
			error_exit( _( "bad coding %s" ), coding );
	}
	if( xres ) 
		im->Xres = atof( xres );
	if( yres ) 
		im->Yres = atof( yres );
	if( xoffset ) 
		im->Xoffset = atoi( xoffset );
	if( yoffset ) 
		im->Yoffset = atoi( yoffset );

	if( lseek( im->fd, 0, SEEK_SET ) == (off_t) -1 ) 
		error_exit( _( "could not seek on %s" ), im->filename );
	if( im__write_header_bytes( im, header ) ||
		im__write( im->fd, header, IM_SIZEOF_HEADER ) )
		error_exit( _( "could not write to %s" ), im->filename );

	if( setext ) {
		char *xml;
		unsigned int size;

		if( !(xml = im__file_read( stdin, "stdin", &size )) )
			error_exit( "%s", _( "could not get ext data" ) );

		/* Strip trailing whitespace ... we can get stray \n at the 
		 * end, eg. "echo | edvips --setext fred.v".
		 */
		while( size > 0 && isspace( xml[size - 1] ) )
			size -= 1;

		if( im__write_extension_block( im, xml, size ) )
			error_exit( "%s", _( "could not set extension" ) );
		im_free( xml );
	}

	im_close( im );

	vips_shutdown();

	return( 0 );
}
コード例 #20
0
ファイル: peer_manager.c プロジェクト: TanekLiang/rt-thread
ret_code_t pm_init(void)
{
    ret_code_t err_code;

    err_code = pds_init();
    if (err_code != NRF_SUCCESS)
    {
        return NRF_ERROR_INTERNAL;
    }

    err_code = pdb_init();
    if (err_code != NRF_SUCCESS)
    {
        return NRF_ERROR_INTERNAL;
    }

    err_code = sm_init();
    if (err_code != NRF_SUCCESS)
    {
        return NRF_ERROR_INTERNAL;
    }

    err_code = smd_init();
    if (err_code != NRF_SUCCESS)
    {
        return NRF_ERROR_INTERNAL;
    }

    err_code = gcm_init();
    if (err_code != NRF_SUCCESS)
    {
        return NRF_ERROR_INTERNAL;
    }

    err_code = gscm_init();
    if (err_code != NRF_SUCCESS)
    {
        return NRF_ERROR_INTERNAL;
    }

    err_code = im_init();
    if (err_code != NRF_SUCCESS)
    {
        return NRF_ERROR_INTERNAL;
    }

    internal_state_reset();

    m_pairing_flag_id = ble_conn_state_user_flag_acquire();
    if (m_pairing_flag_id == BLE_CONN_STATE_USER_FLAG_INVALID)
    {
        return NRF_ERROR_INTERNAL;
    }

    m_bonding_flag_id = ble_conn_state_user_flag_acquire();
    if (m_bonding_flag_id == BLE_CONN_STATE_USER_FLAG_INVALID)
    {
        return NRF_ERROR_INTERNAL;
    }

    m_peer_rank_initialized = false;
    m_module_initialized    = true;

    return NRF_SUCCESS;
}
コード例 #21
0
ファイル: im_binfile.c プロジェクト: Ikulagin/transmem
/**
 * im_binfile:
 * @name: filename to open
 * @xsize: image width
 * @ysize: image height
 * @bands: image bands (or bytes per pixel)
 * @offset: bytes to skip at start of file
 *
 * This function maps the named file and returns an #IMAGE you can use to
 * read it.
 *
 * It returns an 8-bit image with @bands bands. If the image is not 8-bit, use 
 * im_copy_set() to transform the descriptor after loading it.
 *
 * See also: im_copy_set(), im_raw2vips(), im_open().
 *
 * Returns: the new #IMAGE, or NULL on error.
 */
IMAGE *
im_binfile( const char *name, int xsize, int ysize, int bands, int offset )
{
	IMAGE *im;
	gint64 psize;
	gint64 rsize;

	/* Check parameters.
	 */
	if( xsize <= 0 || ysize <= 0 || bands <= 0 ) {
		im_error( "im_binfile", 
			"%s", _( "bad parameters" ) );
		return( NULL );
	}

	/* Make new output image for us.
	 */
	if( !(im = im_init( name )) )
		return( NULL );
	if( (im->fd = im__open_image_file( name )) == -1 ) {
		im_close( im );
		return( NULL );
	}
	im->dtype = IM_OPENIN;
	im->sizeof_header = offset;

	/* Predict file size.
	 */
	psize = (gint64) xsize * ysize * bands + offset;

	/* Read the real file length and check against what we think 
	 * the size should be.
	 */
	if( (rsize = im_file_length( im->fd )) == -1 ) {
		im_close( im );
		return( NULL );
	}
	im->file_length = rsize;

	/* Very common, so special message.
	 */
	if( psize > rsize ) {
		im_error( "im_binfile", _( "unable to open %s: "
			"file has been truncated" ), im->filename );
		im_close( im );
		return( NULL );
	}

	/* Just wierd. Only print a warning for this, since we should
	 * still be able to process it without coredumps.
	 */
	if( psize < rsize )
		im_warn( "im_binfile", _( "%s is longer than expected" ),
			im->filename );

	/* Set header fields.
	 */
	im->Xsize = xsize;
	im->Ysize = ysize;
	im->Bands = bands;

	/* Set others to standard values.
	 */
	im->BandFmt = IM_BANDFMT_UCHAR;
	im->Bbits = im_bits_of_fmt( im->BandFmt );
	im->Coding = IM_CODING_NONE;

	if( bands == 1 )
		im->Type = IM_TYPE_B_W;
	else if( bands == 3 )
		im->Type = IM_TYPE_RGB;
	else 
		im->Type = IM_TYPE_MULTIBAND;

	im->Xres = 1.0;
	im->Yres = 1.0;

	im->Length = 0;
	im->Compression = 0;
	im->Level = 0;

	im->Xoffset = 0;
	im->Yoffset = 0;

	/* Init others too.
	 */
	im->dhint = IM_THINSTRIP;

	return( im );
}
コード例 #22
0
ファイル: vipsedit.c プロジェクト: DINKIN/libvips
int
main( int argc, char **argv )
{
	GOptionContext *context;
	GOptionGroup *main_group;
	GError *error = NULL;
	IMAGE *im;
	unsigned char header[IM_SIZEOF_HEADER];

	if( VIPS_INIT( argv[0] ) )
	        vips_error_exit( "%s", _( "unable to start VIPS" ) );
	textdomain( GETTEXT_PACKAGE );
	setlocale( LC_ALL, "" );

	context = g_option_context_new( 
		_( "vipsedit - edit vips file header" ) );
	main_group = g_option_group_new( NULL, NULL, NULL, NULL, NULL );
	g_option_group_add_entries( main_group, entries );
	vips_add_option_entries( main_group ); 
	g_option_group_set_translation_domain( main_group, GETTEXT_PACKAGE );
	g_option_context_set_main_group( context, main_group );

	if( !g_option_context_parse( context, &argc, &argv, &error ) ) {
		if( error ) {
			fprintf( stderr, "%s\n", error->message );
		        g_error_free( error );
		}

		exit( -1 );
	}
	if( argc != 2 ) {
		fprintf( stderr, _( "usage: %s [OPTION...] vips-file\n" ), 
			g_get_prgname() );
		exit( -1 );
	}

	if( !(im = im_init( argv[1] )) ||
		(im->fd = im__open_image_file( im->filename )) == -1 ) 
		error_exit( _( "could not open image %s" ), argv[1] );
	if( read( im->fd, header, IM_SIZEOF_HEADER ) != IM_SIZEOF_HEADER ||
		im__read_header_bytes( im, header ) ) 
		error_exit( _( "could not read VIPS header for %s" ), 
			im->filename );

	if( endian ) {
		if( strcmp( endian, "little" ) == 0 )
			im->magic = VIPS_MAGIC_INTEL;
		else if( strcmp( endian, "big" ) == 0 )
			im->magic = VIPS_MAGIC_SPARC;
		else 
			error_exit( _( "bad endian-ness %s, "
				"should be 'big' or 'little'" ), endian );
	}
	if( xsize ) 
		parse_pint( xsize, &im->Xsize );
	if( ysize ) 
		parse_pint( ysize, &im->Ysize );
	if( bands ) 
		parse_pint( bands, &im->Bands );
	if( format ) {
		VipsBandFormat f;

		if( (f = im_char2BandFmt( format )) < 0 )
			error_exit( _( "bad format %s" ), format );
		im->BandFmt = f;
		im->Bbits = im_bits_of_fmt( f );
	}
	if( interpretation ) {
		VipsInterpretation i;

		if( (i = im_char2Type( interpretation )) < 0 )
			error_exit( _( "bad interpretation %s" ), 
				interpretation );
		im->Type = i;
	}
	if( coding ) {
		VipsCoding c;

		if( (c = im_char2Coding( coding )) < 0 )
			error_exit( _( "bad coding %s" ), coding );
		im->Coding = c;
	}
	if( xres ) 
		im->Xres = atof( xres );
	if( yres ) 
		im->Yres = atof( yres );
	if( xoffset ) 
		im->Xoffset = atoi( xoffset );
	if( yoffset ) 
		im->Yoffset = atoi( yoffset );

	if( lseek( im->fd, 0, SEEK_SET ) == (off_t) -1 ) 
		error_exit( _( "could not seek on %s" ), im->filename );
	if( im__write_header_bytes( im, header ) ||
		im__write( im->fd, header, IM_SIZEOF_HEADER ) )
		error_exit( _( "could not write to %s" ), im->filename );

	if( setext ) {
		char *xml;
		size_t size;

		if( !(xml = im__file_read( stdin, "stdin", &size )) )
			error_exit( "%s", _( "could not get ext data" ) );

		/* Strip trailing whitespace ... we can get stray \n at the 
		 * end, eg. "echo | editvips --setext fred.v".
		 */
		while( size > 0 && isspace( xml[size - 1] ) )
			size -= 1;

		if( im__write_extension_block( im, xml, size ) )
			error_exit( "%s", _( "could not set extension" ) );
		im_free( xml );
	}

	im_close( im );

	vips_shutdown();

	return( 0 );
}