Beispiel #1
0
static void
run (const gchar      *name,
     gint              nparams,
     const GimpParam  *param,
     gint             *nreturn_vals,
     GimpParam       **return_vals)
{
  GimpDrawable      *drawable;
  GimpRunMode        run_mode;
  GimpPDBStatusType  status = GIMP_PDB_SUCCESS;        /* assume the best! */
  static GimpParam   values[1];

  INIT_I18N ();

  /*
   *  Get the specified drawable, do standard initialization.
   */
  if (strcmp (name, PLUG_IN_PROC[0]) == 0)
    rndm_type = RNDM_HURL;
  else if (strcmp (name, PLUG_IN_PROC[1]) == 0)
    rndm_type = RNDM_PICK;
  else if (strcmp (name, PLUG_IN_PROC[2]) == 0)
    rndm_type = RNDM_SLUR;

  run_mode = param[0].data.d_int32;
  drawable = gimp_drawable_get(param[2].data.d_drawable);

  *nreturn_vals = 1;
  *return_vals  = values;

  values[0].type          = GIMP_PDB_STATUS;
  values[0].data.d_status = status;

  gr = g_rand_new ();
  /*
   *  Make sure the drawable type is appropriate.
   */
  if (gimp_drawable_is_rgb (drawable->drawable_id)  ||
      gimp_drawable_is_gray (drawable->drawable_id) ||
      gimp_drawable_is_indexed (drawable->drawable_id))
    {
      gimp_tile_cache_ntiles (2 * drawable->ntile_cols);

      switch (run_mode)
        {
          /*
           *  If we're running interactively, pop up the dialog box.
           */
        case GIMP_RUN_INTERACTIVE:
          gimp_get_data (PLUG_IN_PROC[rndm_type - 1], &pivals);

          if (! randomize_dialog (drawable)) /* return on Cancel */
            return;
          break;
          /*
           *  If we're not interactive (probably scripting), we
           *  get the parameters from the param[] array, since
           *  we don't use the dialog box.  Make sure they all
           *  parameters have legitimate values.
           */
        case GIMP_RUN_NONINTERACTIVE:
          if (nparams != 7)
            {
              status = GIMP_PDB_CALLING_ERROR;
            }
          else
            {
              pivals.rndm_pct    = (gdouble) param[3].data.d_float;
              pivals.rndm_rcount = (gdouble) param[4].data.d_float;
              pivals.randomize   = (gboolean) param[5].data.d_int32;
              pivals.seed        = (gint) param[6].data.d_int32;

              if (pivals.randomize)
                pivals.seed = g_random_int ();

              if ((rndm_type != RNDM_PICK &&
                   rndm_type != RNDM_SLUR &&
                   rndm_type != RNDM_HURL) ||
                  (pivals.rndm_pct < 1.0 || pivals.rndm_pct > 100.0) ||
                  (pivals.rndm_rcount < 1.0 || pivals.rndm_rcount > 100.0))
                {
                  status = GIMP_PDB_CALLING_ERROR;
                }
            }
          break;
          /*
           *  If we're running with the last set of values, get those values.
           */
        case GIMP_RUN_WITH_LAST_VALS:
          gimp_get_data (PLUG_IN_PROC[rndm_type - 1], &pivals);

          if (pivals.randomize)
            pivals.seed = g_random_int ();
          break;
          /*
           *  Hopefully we never get here!
           */
        default:
          break;
        }

      if (status == GIMP_PDB_SUCCESS)
        {
          gimp_progress_init_printf ("%s", gettext (RNDM_NAME[rndm_type - 1]));

          /*
           *  Initialize the g_rand() function seed
           */
          g_rand_set_seed (gr, pivals.seed);

          randomize (drawable, NULL);
          /*
           *  If we ran interactively (even repeating) update the display.
           */
          if (run_mode != GIMP_RUN_NONINTERACTIVE)
            {
              gimp_displays_flush ();
            }
          /*
           *  If we use the dialog popup, set the data for future use.
           */
          if (run_mode == GIMP_RUN_INTERACTIVE)
            {
              gimp_set_data (PLUG_IN_PROC[rndm_type - 1], &pivals,
                             sizeof (RandomizeVals));
            }
        }
    }
  else
    {
      /*
       *  If we got the wrong drawable type, we need to complain.
       */
      status = GIMP_PDB_EXECUTION_ERROR;
    }
  /*
   *  DONE!
   *  Set the status where GIMP can see it, and let go
   *  of the drawable.
   */
  g_rand_free (gr);
  values[0].data.d_status = status;
  gimp_drawable_detach(drawable);
}
Beispiel #2
0
/* ibus stress test
   Send random key press and release event message to ibus-daemon.
   Key kind are a-z and space.
   Check ibus-daemon and ibus engine crash.
*/
gint
main (gint argc, gchar **argv)
{
    GTimer *timer;
    GRand *rnd;
    BusTestClient *client;
    /* num of send space key */
    guint32 seed = (guint32) time (NULL);
    int count = 0;
    int send_key_num = 0;

    setlocale (LC_ALL, "");
    gtk_set_locale ();
    gtk_init (&argc, &argv);

    /* need to set active engine */
    client = bus_test_client_new ();
    if (client == NULL) {
        g_printerr ("don't create test-client instance.");
        exit(1);
    }

    timer = g_timer_new ();
    rnd = g_rand_new ();
    g_rand_set_seed (rnd, seed);
    g_print("random seed:%u\n",seed);
    g_timer_start (timer);

    while (1) {
        guint keysym;
        if (send_key_num > MAX_SEND_KEY_NUM) {
            break;
        }
        if (!bus_test_client_is_connected (client)) {
            g_printerr ("ibus-daemon is disconnected\n");
            break;
        }
        if (!bus_test_client_is_enabled (client)) {
            g_printerr ("ibus engine is enabled\n");
            break;
        }

        if(count>0 || g_rand_int_range (rnd, 0, 5) == 0) {
            /* send space key 20% */
            if (count == 0) {
                count = g_rand_int_range (rnd, 0, MAX_RANDOM_SPACE) + 1;
            }
            if (count-- == 1) {
                keysym = IBUS_KEY_Return;
            } else {
                keysym = IBUS_KEY_space;
            }
        } else {
            /* send random a-z key */
            keysym = g_rand_int_range (rnd, 0, 'z'-'a'+1) + 'a';
        }
        bus_test_client_send_key (client, keysym);
        send_key_num += 1;
        /* limit the typing rate to 800 hits/minutes */
        _sleep (1000 * 60 / 800);
    }

    g_print ("%f sec\n", g_timer_elapsed (timer, NULL));

    return 0;
}
Beispiel #3
0
gint 
main (gint argc, gchar **argv) 
{
    GOptionContext *context;
    xmlParserCtxtPtr parser;
    xmlDocPtr doc;
    YelpTransform *transform;
    gchar **params;
    const gchar *stylesheet;
    gchar *file;

    context = g_option_context_new ("[STYLESHEET] FILE");
    g_option_context_add_main_entries (context, options, NULL);
    g_option_context_parse (context, &argc, &argv, NULL);

    if (files == NULL || files[0] == NULL) {
	g_printerr ("Usage: test-transform [OPTION...] [STYLESHEET] FILE\n");
	return 1;
    }

    if (files[1] == NULL) {
	stylesheet = DATADIR"/yelp/xslt/db2html.xsl";
	file = files[0];
    } else {
	stylesheet = files[0];
	file = files[1];
    }

    params = g_new0 (gchar *, 7);
    params[0] = g_strdup ("db.chunk.extension");
    params[1] = g_strdup ("\"\"");
    params[2] = g_strdup ("db.chunk.info_basename");
    params[3] = g_strdup ("\"x-yelp-titlepage\"");
    params[4] = g_strdup ("db.chunk.max_depth");
    params[5] = g_strdup ("2");
    params[6] = NULL;

    transform = yelp_transform_new (stylesheet);
    g_object_weak_ref ((GObject *) transform, transform_destroyed, NULL);

    g_signal_connect (transform, "chunk-ready", (GCallback) transform_chunk, NULL);
    g_signal_connect (transform, "finished", (GCallback) transform_finished, NULL);
    g_signal_connect (transform, "error", (GCallback) transform_error, NULL);

    parser = xmlNewParserCtxt ();
    doc = xmlCtxtReadFile (parser,
			   file,
			   NULL,
			   XML_PARSE_DTDLOAD | XML_PARSE_NOCDATA |
			   XML_PARSE_NOENT   | XML_PARSE_NONET   );
    xmlFreeParserCtxt (parser);
    xmlXIncludeProcessFlags (doc,
			     XML_PARSE_DTDLOAD | XML_PARSE_NOCDATA |
			     XML_PARSE_NOENT   | XML_PARSE_NONET   );
    if (!yelp_transform_start (transform, doc, NULL, (const gchar **) params))
	return 1;

    if (random_timeout) {
	GRand *rand = g_rand_new ();
	timeout = g_rand_int_range (rand, 80, 280);
	g_rand_free (rand);
    }

    if (timeout >= 0)
	g_timeout_add (timeout, (GSourceFunc) transform_release, transform);

    loop = g_main_loop_new (NULL, FALSE);
    g_main_loop_run (loop);

    return 0;
}
Beispiel #4
0
static void
run (const gchar      *name,
     gint              nparams,
     const GimpParam  *param,
     gint             *nreturn_vals,
     GimpParam       **return_vals)
{
  static GimpParam values[1];
  gint sel_x1, sel_y1, sel_x2, sel_y2;
  gint img_height, img_width, img_bpp, img_has_alpha;

  GimpDrawable      *drawable;
  GimpRunMode        run_mode;
  GimpPDBStatusType  status;

  *nreturn_vals = 1;
  *return_vals  = values;

  status = GIMP_PDB_SUCCESS;

  if (param[0].type != GIMP_PDB_INT32)
    status = GIMP_PDB_CALLING_ERROR;
  run_mode = param[0].data.d_int32;

  INIT_I18N ();

  if (param[2].type != GIMP_PDB_DRAWABLE)
    status = GIMP_PDB_CALLING_ERROR;

  drawable = gimp_drawable_get (param[2].data.d_drawable);

  img_width = gimp_drawable_width (drawable->drawable_id);
  img_height = gimp_drawable_height (drawable->drawable_id);
  img_bpp = gimp_drawable_bpp (drawable->drawable_id);
  img_has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
  gimp_drawable_mask_bounds (drawable->drawable_id,
                             &sel_x1, &sel_y1, &sel_x2, &sel_y2);

  if (!gimp_drawable_is_rgb (drawable->drawable_id))
    status = GIMP_PDB_CALLING_ERROR;

  if (status == GIMP_PDB_SUCCESS)
    {
      gr = g_rand_new ();

      memset (&qbist_info, 0, sizeof (qbist_info));
      create_info (&qbist_info.info);
      qbist_info.oversampling = 4;

      switch (run_mode)
        {
        case GIMP_RUN_INTERACTIVE:
          /* Possibly retrieve data */
          gimp_get_data (PLUG_IN_PROC, &qbist_info);

          /* Get information from the dialog */
          if (dialog_run ())
            {
              status = GIMP_PDB_SUCCESS;
              gimp_set_data (PLUG_IN_PROC, &qbist_info, sizeof (QbistInfo));
            }
          else
            status = GIMP_PDB_EXECUTION_ERROR;
          break;

        case GIMP_RUN_NONINTERACTIVE:
          status = GIMP_PDB_CALLING_ERROR;
          break;

        case GIMP_RUN_WITH_LAST_VALS:
          /* Possibly retrieve data */
          gimp_get_data (PLUG_IN_PROC, &qbist_info);
          status = GIMP_PDB_SUCCESS;
          break;

        default:
          status = GIMP_PDB_CALLING_ERROR;
          break;
        }

      if (status == GIMP_PDB_SUCCESS)
        {
          GimpPixelRgn imagePR;
          gpointer     pr;

          gimp_tile_cache_ntiles ((drawable->width + gimp_tile_width () - 1) /
                                  gimp_tile_width ());
          gimp_pixel_rgn_init (&imagePR, drawable,
                               0, 0, img_width, img_height, TRUE, TRUE);

          optimize (&qbist_info.info);

          gimp_progress_init (_("Qbist"));

          for (pr = gimp_pixel_rgns_register (1, &imagePR);
               pr != NULL;
               pr = gimp_pixel_rgns_process (pr))
            {
              gint row;

              for (row = 0; row < imagePR.h; row++)
                {
                  qbist (&qbist_info.info,
                         imagePR.data + row * imagePR.rowstride,
                         imagePR.x,
                         imagePR.y + row,
                         imagePR.w,
                         sel_x2 - sel_x1,
                         sel_y2 - sel_y1,
                         imagePR.bpp,
                         qbist_info.oversampling);
                }

              gimp_progress_update ((gfloat) (imagePR.y - sel_y1) /
                                    (gfloat) (sel_y2 - sel_y1));
            }

          gimp_drawable_flush (drawable);
          gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
          gimp_drawable_update (drawable->drawable_id,
                                sel_x1, sel_y1,
                                (sel_x2 - sel_x1), (sel_y2 - sel_y1));

          gimp_displays_flush ();
        }

      g_rand_free (gr);
    }

  values[0].type          = GIMP_PDB_STATUS;
  values[0].data.d_status = status;

  gimp_drawable_detach (drawable);
}