static gboolean paint_cb (void *user_data) { Data *data = user_data; CoglError *error = NULL; const CoglGLES2Vtable *gles2 = data->gles2_vtable; /* Draw scene with GLES2 */ if (!cogl_push_gles2_context (data->ctx, data->gles2_ctx, data->fb, data->fb, &error)) { g_error ("Failed to push gles2 context: %s\n", error->message); } /* Clear offscreen framebuffer with a random color */ gles2->glClearColor (g_random_double (), g_random_double (), g_random_double (), 1.0f); gles2->glClear (GL_COLOR_BUFFER_BIT); cogl_pop_gles2_context (data->ctx); /* Draw scene with Cogl */ cogl_primitive_draw (data->triangle, data->fb, data->pipeline); cogl_onscreen_swap_buffers (COGL_ONSCREEN (data->fb)); return FALSE; /* remove the callback */ }
static gboolean screen_saver_floater_should_bubble_up (ScreenSaver *screen_saver, ScreenSaverFloater *floater, gdouble performance_ratio, gdouble *duration) { if ((performance_ratio < .5) && (g_random_double () > .5)) { if (duration) *duration = performance_ratio * 30.0; return TRUE; } if ((floater->scale < .3) && (g_random_double () > .6)) { if (duration) *duration = 30.0; return TRUE; } return FALSE; }
gchar* set_password(const gchar *raw_password) { gchar *salt; gchar *hsh; gchar *str1, *str2; gchar *password; gdouble rand; rand = g_random_double(); str1 = g_strdup_printf("%g", rand); rand = g_random_double(); str2 = g_strdup_printf("%g", rand); salt = get_hexdigest(str1, str2); salt[5] = '\0'; g_free(str1); g_free(str2); hsh = get_hexdigest(salt, raw_password); password = g_strdup_printf("sha1$%s$%s", salt, hsh); g_free(salt); g_free(hsh); return password; }
void cd_icon_effect_rewind_star_particle (CairoParticle *p, double dt) { double a = .2; p->x = 2 * g_random_double () - 1; p->y = g_random_double (); p->fSizeFactor = 1.; p->iInitialLife = myConfig.iStarDuration / dt; p->iLife = p->iInitialLife * (g_random_double () + a) / (1 + a); }
static gboolean init (Icon *pIcon, CairoDock *pDock, double dt, CDIconEffectData *pData) { if (pData->pRainSystem != NULL) return TRUE; if (myData.iRainTexture == 0) myData.iRainTexture = cd_icon_effect_load_rain_texture (); double fMaxScale = 1. + myIconsParam.fAmplitude * pDock->fMagnitudeMax; CairoParticleSystem *pParticleSystem = cairo_dock_create_particle_system (myConfig.iNbRainParticles, myData.iRainTexture, pIcon->fWidth * pIcon->fScale, pIcon->fHeight * fMaxScale); g_return_val_if_fail (pParticleSystem != NULL, FALSE); pParticleSystem->dt = dt; if (myConfig.bRotateEffects && ! pDock->container.bDirectionUp && pDock->container.bIsHorizontal) pParticleSystem->bDirectionUp = FALSE; double a = myConfig.fRainParticleSpeed; static double epsilon = 0.1; double r = myConfig.iRainParticleSize; double fBlend; double vmax = 1. / myConfig.iRainDuration; CairoParticle *p; int i; for (i = 0; i < myConfig.iNbRainParticles; i ++) { p = &(pParticleSystem->pParticles[i]); p->x = 2 * g_random_double () - 1; p->y = 1.; p->z = 2 * g_random_double () - 1; p->fWidth = r*(p->z + 2)/3 * g_random_double (); p->fHeight = p->fWidth; p->vx = 0.; p->vy = -a * vmax * ((p->z + 1)/2 * g_random_double () + epsilon) * dt; p->iInitialLife = MIN (-1./ p->vy, ceil (myConfig.iRainDuration / dt)); p->iLife = p->iInitialLife; { fBlend = g_random_double (); p->color[0] = fBlend * myConfig.pRainColor1[0] + (1 - fBlend) * myConfig.pRainColor2[0]; p->color[1] = fBlend * myConfig.pRainColor1[1] + (1 - fBlend) * myConfig.pRainColor2[1]; p->color[2] = fBlend * myConfig.pRainColor1[2] + (1 - fBlend) * myConfig.pRainColor2[2]; } p->color[3] = 0.; p->fOscillation = 0.; p->fOmega = 0.; // tr/s p->fSizeFactor = 1.; p->fResizeSpeed = 0.; // zoom 1 a la fin. } pData->pRainSystem = pParticleSystem; return TRUE; }
int get_timeout() { static int saved_timeout = 0; if (saved_timeout < 300) { return 150 + 400 * g_random_double(); } else { return 100 + 400 * g_random_double(); } printf("GetTimeout: %d\n", saved_timeout); return saved_timeout; }
static gboolean init (Icon *pIcon, CairoDock *pDock, double dt, CDIconEffectData *pData) { if (pData->pStormSystem != NULL) return TRUE; if (myData.iFireTexture == 0) myData.iFireTexture = cd_icon_effect_load_storm_texture (); double fMaxScale = 1. + myIconsParam.fAmplitude * pDock->fMagnitudeMax; CairoParticleSystem *pParticleSystem = cairo_dock_create_particle_system (myConfig.iNbStormParticles, myData.iFireTexture, pIcon->fWidth * pIcon->fScale, pIcon->fHeight * fMaxScale); g_return_val_if_fail (pParticleSystem != NULL, FALSE); pParticleSystem->dt = dt; if (myConfig.bRotateEffects && ! pDock->container.bDirectionUp && pDock->container.bIsHorizontal) pParticleSystem->bDirectionUp = FALSE; double r = myConfig.iStormParticleSize; double vmax = 1. / myConfig.iStormDuration * 2; double fBlend; CairoParticle *p; int i; for (i = 0; i < myConfig.iNbStormParticles; i ++) { p = &pParticleSystem->pParticles[i]; p->x = 0.; // on le calculera a la main. p->y = -1. * i /myConfig.iNbStormParticles + .01 * (2 * g_random_double () - 1); p->z = 1.; // idem. p->fWidth = r * (1 + ar * (2 * g_random_double () - 1)); p->fHeight = p->fWidth; p->vx = ad * (2 * g_random_double () - 1); // utilisation detournee : dispersion. p->vy = vmax * (1 - ad * g_random_double ()) * dt * 2; p->iInitialLife = MIN ((1 - p->y) / p->vy, ceil (myConfig.iStormDuration/2 / dt)); p->iLife = p->iInitialLife; fBlend = g_random_double (); p->color[0] = fBlend * myConfig.pStormColor1[0] + (1 - fBlend) * myConfig.pStormColor2[0]; p->color[1] = fBlend * myConfig.pStormColor1[1] + (1 - fBlend) * myConfig.pStormColor2[1]; p->color[2] = fBlend * myConfig.pStormColor1[2] + (1 - fBlend) * myConfig.pStormColor2[2]; p->color[3] = (p->y < 0 ? 0. : at); p->fOscillation = 0.; p->fOmega = 0.; p->fSizeFactor = 1.; p->fResizeSpeed = 0.; // zoom constant. } pData->pStormSystem = pParticleSystem; return TRUE; }
CairoParticleSystem *cd_icon_effect_init_stars (Icon *pIcon, CairoDock *pDock, double dt) { if (myData.iStarTexture == 0) myData.iStarTexture = cd_icon_effect_load_star_texture (); double fMaxScale = (pDock->bAtBottom ? 1. : cairo_dock_get_max_scale (CAIRO_CONTAINER (pDock))); CairoParticleSystem *pStarParticleSystem = cairo_dock_create_particle_system (myConfig.iNbStarParticles, myData.iStarTexture, pIcon->fWidth * pIcon->fScale, pIcon->fHeight * fMaxScale); g_return_val_if_fail (pStarParticleSystem != NULL, NULL); pStarParticleSystem->dt = dt; pStarParticleSystem->bAddLuminance = TRUE; static double a = .4; static double epsilon = 0.1; double r = myConfig.iStarParticleSize; double fBlend; CairoParticle *p; int i; for (i = 0; i < myConfig.iNbStarParticles; i ++) { p = &pStarParticleSystem->pParticles[i]; p->x = 2 * g_random_double () - 1; p->y = g_random_double (); p->z = 2 * g_random_double () - 1; p->fWidth = r*(p->z + 1)/2 * g_random_double (); p->fHeight = p->fWidth; p->vx = 0.; p->vy = 0.; p->iInitialLife = myConfig.iStarDuration / dt; p->iLife = p->iInitialLife * (g_random_double () + a) / (1 + a); if (myConfig.bMysticalStars) { p->color[0] = g_random_double (); p->color[1] = g_random_double (); p->color[2] = g_random_double (); } else { fBlend = g_random_double (); p->color[0] = fBlend * myConfig.pStarColor1[0] + (1 - fBlend) * myConfig.pStarColor2[0]; p->color[1] = fBlend * myConfig.pStarColor1[1] + (1 - fBlend) * myConfig.pStarColor2[1]; p->color[2] = fBlend * myConfig.pStarColor1[2] + (1 - fBlend) * myConfig.pStarColor2[2]; } p->color[3] = 0.; // on va gerer nous-mêmes la transparence. p->fOscillation = 0.; p->fOmega = 0.; p->fSizeFactor = 1.; p->fResizeSpeed = - 1. / myConfig.iStarDuration * dt; // zoom 0 a la fin. } return pStarParticleSystem; }
static gpointer test_g_static_rw_lock_thread (gpointer data) { while (test_g_static_rw_lock_run) { if (g_random_double() > .2) /* I'm a reader */ { if (g_random_double() > .2) /* I'll block */ g_static_rw_lock_reader_lock (&test_g_static_rw_lock_lock); else /* I'll only try */ if (!g_static_rw_lock_reader_trylock (&test_g_static_rw_lock_lock)) continue; G_LOCK (test_g_static_rw_lock_state); g_assert (test_g_static_rw_lock_state >= 0); test_g_static_rw_lock_state++; G_UNLOCK (test_g_static_rw_lock_state); g_usleep (g_random_int_range (20,1000)); G_LOCK (test_g_static_rw_lock_state); test_g_static_rw_lock_state--; G_UNLOCK (test_g_static_rw_lock_state); g_static_rw_lock_reader_unlock (&test_g_static_rw_lock_lock); } else /* I'm a writer */ { if (g_random_double() > .2) /* I'll block */ g_static_rw_lock_writer_lock (&test_g_static_rw_lock_lock); else /* I'll only try */ if (!g_static_rw_lock_writer_trylock (&test_g_static_rw_lock_lock)) continue; G_LOCK (test_g_static_rw_lock_state); g_assert (test_g_static_rw_lock_state == 0); test_g_static_rw_lock_state = -1; G_UNLOCK (test_g_static_rw_lock_state); g_usleep (g_random_int_range (20,1000)); G_LOCK (test_g_static_rw_lock_state); test_g_static_rw_lock_state = 0; G_UNLOCK (test_g_static_rw_lock_state); g_static_rw_lock_writer_unlock (&test_g_static_rw_lock_lock); } } return NULL; }
static int vips_gaussnoise_gen( VipsRegion *or, void *seq, void *a, void *b, gboolean *stop ) { VipsGaussnoise *gaussnoise = (VipsGaussnoise *) a; int sz = VIPS_REGION_N_ELEMENTS( or ); int y; for( y = 0; y < or->valid.height; y++ ) { float *q = (float *) VIPS_REGION_ADDR( or, or->valid.left, y + or->valid.top ); int x; for( x = 0; x < sz; x++ ) { double sum; int i; sum = 0.0; for( i = 0; i < 12; i++ ) sum += g_random_double(); q[x] = (sum - 6.0) * gaussnoise->sigma + gaussnoise->mean; } } return( 0 ); }
static gboolean handle_btn1(Annotation *annotation, Property *prop) { Color col; text_get_attributes(annotation->text,&annotation->attrs); col = annotation->attrs.color; /* g_message("in handle_btn1 for object %p col=%.2f:%.2f:%.2f", annotation,col.red,col.green,col.blue); */ col.red = g_random_double(); col.green = g_random_double(); col.blue = g_random_double(); annotation->attrs.color = col; text_set_attributes(annotation->text,&annotation->attrs); /* g_message("end of handle_btn1 for object %p col=%.2f:%.2f:%.2f", annotation,col.red,col.green,col.blue); */ return TRUE; }
static int vips_worley_build( VipsObject *object ) { VipsCreate *create = VIPS_CREATE( object ); VipsWorley *worley = (VipsWorley *) object; if( VIPS_OBJECT_CLASS( vips_worley_parent_class )->build( object ) ) return( -1 ); /* Be careful if width is a multiple of cell_size. */ worley->cells_across = ROUND_UP( worley->width, worley->cell_size ) / worley->cell_size; worley->cells_down = ROUND_UP( worley->height, worley->cell_size ) / worley->cell_size; worley->seed = g_random_double() * 0xffffffffu; vips_image_init_fields( create->out, worley->width, worley->height, 1, VIPS_FORMAT_INT, VIPS_CODING_NONE, VIPS_INTERPRETATION_B_W, 1.0, 1.0 ); vips_image_pipelinev( create->out, VIPS_DEMAND_STYLE_ANY, NULL ); if( vips_image_generate( create->out, vips_worley_start, vips_worley_gen, vips_worley_stop, worley, NULL ) ) return( -1 ); return( 0 ); }
static Benchmark * setup_benchmark(opencl_desc *ocl, Settings *settings) { Benchmark *b; cl_program program; cl_int errcode = CL_SUCCESS; program = ocl_get_program(ocl, "nlm.cl", ""); if (program == NULL) { g_warning ("Could not open nlm.cl"); ocl_free (ocl); return NULL; } b = (Benchmark *) g_malloc0(sizeof(Benchmark)); b->ocl = ocl; b->settings = settings; /* Create kernel for each device */ b->kernels = g_malloc0(ocl->num_devices * sizeof(cl_kernel)); for (int i = 0; i < ocl->num_devices; i++) { b->kernels[i] = clCreateKernel(program, "nlm", &errcode); CHECK_ERROR(errcode); } b->num_images = b->settings->num_images < 0 ? ocl->num_devices * 16 : b->settings->num_images; b->image_size = b->settings->width * b->settings->height * sizeof(gfloat); b->single_result = (gfloat **) g_malloc0(b->num_images * sizeof(gfloat *)); b->multi_result = (gfloat **) g_malloc0(b->num_images * sizeof(gfloat *)); b->host_data = (gfloat **) g_malloc0(b->num_images * sizeof(gfloat *)); b->events = (cl_event *) g_malloc0(b->num_images * sizeof(cl_event)); b->read_events = (cl_event *) g_malloc0(b->num_images * sizeof(cl_event)); b->write_events = (cl_event *) g_malloc0(b->num_images * sizeof(cl_event)); g_print("# Computing <nlm> for %i images of size %ix%i\n", b->num_images, b->settings->width, b->settings->height); for (guint i = 0; i < b->num_images; i++) { b->host_data[i] = (gfloat *) g_malloc0(b->image_size); b->single_result[i] = (gfloat *) g_malloc0(b->image_size); b->multi_result[i] = (gfloat *) g_malloc0(b->image_size); for (guint j = 0; j < b->settings->width * b->settings->height; j++) b->host_data[i][j] = (gfloat) g_random_double(); } b->dev_data_in = (cl_mem *) g_malloc0(ocl->num_devices * sizeof(cl_mem)); b->dev_data_out = (cl_mem *) g_malloc0(ocl->num_devices * sizeof(cl_mem)); for (guint i = 0; i < ocl->num_devices; i++) { b->dev_data_in[i] = clCreateBuffer(ocl->context, CL_MEM_READ_WRITE, b->image_size, NULL, &errcode); CHECK_ERROR(errcode); b->dev_data_out[i] = clCreateBuffer(ocl->context, CL_MEM_READ_WRITE, b->image_size, NULL, &errcode); CHECK_ERROR(errcode); } return b; }
static void calc_pi (void) { unsigned long n = 0, h = 0; double x, y; printf ("\n"); for (;;) { x = g_random_double (); y = g_random_double (); if (x*x + y*y <= 1) h++; n++; if ( ! (n & 0xfff)) printf ("pi ~~ %1.10f\t(%lu/%lu * 4) iteration: %lu \r", ((double)h)/(double)n * 4.0, h, n, n); } }
// Sample from a normal distribution with zero mean and unit variance. // See http://en.wikipedia.org/wiki/Normal_distribution // #Generating_values_for_normal_random_variables static float _random_sample_normal_intl(float* loglik) { double u, v = 0.0; static const double k = 0.918938533204673; // = 0.5 * (log(2) + log(pi)), see below. u = g_random_double(); v = g_random_double(); v = sqrt(-2.0 * log(u)) * cos(2.0 * G_PI * v); // actual likelihood is 1/sqrt(2*pi) exp(-(x^2)) since mu = 0 and sigma^2 = 1. // log-likelihood is therefore: // \ell(x) = - (x^2) - 0.5 * (log(2) + log(pi)) = - (x^2) - k if(loglik) *loglik = (float) ( - (v*v) - k ); return v; }
static void _rewind_storm_particle (CairoParticle *p, double dt) { p->x = 0; p->y = .03 * (2 * g_random_double () - 1); p->z = 1.; p->fSizeFactor = 1.; p->color[3] = at; p->iInitialLife = MIN (1. / p->vy, ceil (myConfig.iStormDuration/2 / dt)); p->iLife = p->iInitialLife; }
void _rewind_rain_particle (CairoParticle *p, double dt) { static double epsilon = 0.1; double a = myConfig.fRainParticleSpeed/2; double r = myConfig.iRainParticleSize; double vmax = 1. / myConfig.iRainDuration; p->x = 2 * g_random_double () - 1; p->y = 1.; p->z = 2 * g_random_double () - 1; p->fWidth = r*(p->z + 2)/3 * g_random_double (); p->fHeight = p->fWidth; p->vy = -a * vmax * ((p->z + 1)/2 * g_random_double () + epsilon) * dt; p->iInitialLife = MIN (-1./ p->vy, ceil (myConfig.iRainDuration / dt)); p->iLife = p->iInitialLife; p->fSizeFactor = 1.; }
static gboolean probe_cb (GstPad * pad, GstBuffer * buf, gdouble * drop_probability) { if (g_random_double () < *drop_probability) { GST_LOG ("dropping buffer [t=%" GST_TIME_FORMAT "-%" GST_TIME_FORMAT "], " "offset=%" G_GINT64_FORMAT ", offset_end=%" G_GINT64_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf)), GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf)); return FALSE; /* drop buffer */ } return TRUE; /* don't drop buffer */ }
static void add_line(CrItem *group) { int i, total; double angle, dist, cx, cy, x, y; GArray *array; CrItem *line; guint color; cairo_pattern_t *pattern; array = g_array_new(FALSE, FALSE, sizeof(double)); total = g_random_int_range(3, 30); cx = g_random_double_range(40, 360); cy = g_random_double_range(40, 360); for (i = 0, angle = 0; i < total; angle += 2. * M_PI/total, i++) { dist = g_random_double_range(10, 40); x = cx + dist * sin(angle); y = cy + dist * cos(angle); g_array_append_val(array, x); g_array_append_val(array, y); } line = cr_line_new(group, "array", array, "outline_color_rgba", 0x000000ff, "line_scaleable", TRUE, "line_width", 3.0, NULL); if (g_random_boolean()) { color = g_random_int_range(0,255) << 24 | g_random_int_range(0,255) << 16 | g_random_int_range(0,255) << 8 | 0xff; g_object_set(line, "fill_color_rgba", color, NULL); } else { pattern = cairo_pattern_create_linear(0, 0, g_random_double_range(5, 20), g_random_double_range(5, 20)); cairo_pattern_add_color_stop_rgb(pattern, 0, g_random_double(), g_random_double(), g_random_double()); cairo_pattern_add_color_stop_rgb(pattern, 10, g_random_double(), g_random_double(), g_random_double()); cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); g_object_set(line, "pattern", pattern, NULL); cairo_pattern_destroy(pattern); } g_signal_connect(line, "event", (GCallback) item_event, NULL); }
gint main (int argc, gchar **argv) { gint i,j = 0; gfloat val; gfloat foo; gdouble sum = 0; gint count=0; GeglLookup *lookup; gint ticks; gfloat *rand = g_malloc (SAMPLES * sizeof (gfloat)); for (i=0;i<SAMPLES;i++) { rand[i]=g_random_double (); } lookup = gegl_lookup_new (wrapped_sqrt, NULL); ticks = gegl_ticks (); for (i=0;i<ITERATIONS;i++) for (j=0;j<SAMPLES;j++) foo = gegl_lookup (lookup, rand[j]); ticks = gegl_ticks ()-ticks; g_print ("First run: %i\n", ticks); ticks = gegl_ticks (); for (i=0;i<ITERATIONS;i++) for (j=0;j<SAMPLES;j++) foo = gegl_lookup (lookup, rand[j]); ticks = gegl_ticks ()-ticks; g_print ("Second run: %i\n", ticks); ticks = gegl_ticks (); for (i=0;i<ITERATIONS;i++) for (j=0;j<SAMPLES;j++) foo = sqrt (rand[j]); ticks = gegl_ticks ()-ticks; g_print ("Just sqrt: %i\n", ticks); gegl_lookup_free (lookup); lookup = gegl_lookup_new (passthrough, NULL); for (val = 0.0, sum=0.0, count=0; val < 1.0; val+=0.000001, count++) sum += fabs (val-gegl_lookup (lookup, val)); g_printf ("Average error in range 0.0-1.0: %f\n", sum/count); foo = sqrt (val); gegl_lookup_free (lookup); g_free (rand); return 0; }
static GstPadProbeReturn probe_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data) { GstBuffer *buf = GST_PAD_PROBE_INFO_BUFFER (info); gdouble *drop_probability = user_data; if (g_random_double () < *drop_probability) { GST_LOG ("dropping buffer [t=%" GST_TIME_FORMAT "-%" GST_TIME_FORMAT "], " "offset=%" G_GINT64_FORMAT ", offset_end=%" G_GINT64_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf)), GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf)); return GST_PAD_PROBE_DROP; /* drop buffer */ } return GST_PAD_PROBE_OK; /* don't drop buffer */ }
static gboolean diffuse_map (GstGeometricTransform * gt, gint x, gint y, gdouble * in_x, gdouble * in_y) { GstDiffuse *diffuse = GST_DIFFUSE_CAST (gt); gint angle; gdouble distance; angle = g_random_int_range (0, 256); distance = g_random_double (); *in_x = x + distance * diffuse->sin_table[angle]; *in_y = y + distance * diffuse->cos_table[angle]; GST_DEBUG_OBJECT (diffuse, "Inversely mapped %d %d into %lf %lf", x, y, *in_x, *in_y); return TRUE; }
static gboolean screen_saver_floater_should_come_on_screen (ScreenSaver *screen_saver, ScreenSaverFloater *floater, gdouble performance_ratio, gdouble *duration) { if (!screen_saver_floater_is_off_canvas (screen_saver, floater)) return FALSE; if ((abs (performance_ratio - .5) >= G_MINDOUBLE) && (g_random_double () > .5)) { if (duration) *duration = g_random_double_range (3.0, 7.0); return TRUE; } return FALSE; }
int GWQSessionLogin(GWQSession* wqs, const gchar* chatStatus) { SoupMessage *msg; GString *str; if (wqs->st != GWQS_ST_OFFLINE) { GWQ_ERR_OUT(ERR_OUT, "\n"); } wqs->chatSt = chatStatus; str = g_string_new(""); g_string_printf(str, "http://"CHECKHOST""VCCHECKPATH"?uin=%s&appid="APPID"&r=%.16f", wqs->num->str, g_random_double()); msg = soup_message_new("GET", str->str); GWQ_DBG("do check\n"); soup_session_queue_message (wqs->sps, msg, _process_check_resp, wqs); g_string_free(str, TRUE); wqs->st = GWQS_ST_LOGIN; return 0; ERR_OUT: return -1; }
static void screen_saver_create_floaters (ScreenSaver *screen_saver) { gint i; for (i = 0; i < screen_saver->max_floater_count; i++) { ScreenSaverFloater *floater; Point position; gdouble scale; position.x = g_random_double_range (screen_saver->canvas_rectangle.top_left_point.x, screen_saver->canvas_rectangle.bottom_right_point.x); position.y = g_random_double_range (screen_saver->canvas_rectangle.top_left_point.y, screen_saver->canvas_rectangle.bottom_right_point.y); scale = g_random_double (); floater = screen_saver_floater_new (screen_saver, &position, scale); screen_saver->floaters = g_list_prepend (screen_saver->floaters, floater); } }
static GstFlowReturn test_injector_chain (GstPad * pad, GstBuffer * buf) { GstFlowReturn ret; GstPad *srcpad; srcpad = gst_element_get_pad (GST_ELEMENT (GST_PAD_PARENT (pad)), "src"); /* since we're increasing timestamp/offsets, push this one first */ GST_LOG (" passing buffer [t=%" GST_TIME_FORMAT "-%" GST_TIME_FORMAT "], offset=%" G_GINT64_FORMAT ", offset_end=%" G_GINT64_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf)), GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf)); gst_buffer_ref (buf); ret = gst_pad_push (srcpad, buf); if (g_random_double () < injector_inject_probability) { GstBuffer *ibuf; ibuf = gst_buffer_copy (buf); if (GST_BUFFER_OFFSET_IS_VALID (buf) && GST_BUFFER_OFFSET_END_IS_VALID (buf)) { guint64 delta; delta = GST_BUFFER_OFFSET_END (buf) - GST_BUFFER_OFFSET (buf); GST_BUFFER_OFFSET (ibuf) += delta / 4; GST_BUFFER_OFFSET_END (ibuf) += delta / 4; } else { GST_BUFFER_OFFSET (ibuf) = GST_BUFFER_OFFSET_NONE; GST_BUFFER_OFFSET_END (ibuf) = GST_BUFFER_OFFSET_NONE; } if (GST_BUFFER_TIMESTAMP_IS_VALID (buf) && GST_BUFFER_DURATION_IS_VALID (buf)) { GstClockTime delta; delta = GST_BUFFER_DURATION (buf); GST_BUFFER_TIMESTAMP (ibuf) += delta / 4; } else { GST_BUFFER_TIMESTAMP (ibuf) = GST_CLOCK_TIME_NONE; GST_BUFFER_DURATION (ibuf) = GST_CLOCK_TIME_NONE; } if (GST_BUFFER_TIMESTAMP_IS_VALID (ibuf) || GST_BUFFER_OFFSET_IS_VALID (ibuf)) { GST_LOG ("injecting buffer [t=%" GST_TIME_FORMAT "-%" GST_TIME_FORMAT "], offset=%" G_GINT64_FORMAT ", offset_end=%" G_GINT64_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (ibuf)), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (ibuf) + GST_BUFFER_DURATION (ibuf)), GST_BUFFER_OFFSET (ibuf), GST_BUFFER_OFFSET_END (ibuf)); if (gst_pad_push (srcpad, ibuf) != GST_FLOW_OK) { /* ignore return value */ } } else { GST_WARNING ("couldn't inject buffer, no incoming timestamps or offsets"); gst_buffer_unref (ibuf); } } gst_buffer_unref (buf); return ret; }
void run_test () { guint a_len = g_random_int_range (3, 128); guint b_len = g_random_int_range (3, 128); gdouble *a_data = g_new (gdouble, a_len); gdouble *b_data = g_new (gdouble, b_len); gdouble *out_data = g_new (gdouble, a_len + b_len); gdouble *out2_data = g_new (gdouble, a_len + b_len); guint i,j; g_message ("run_test: a_len=%u, b_len=%u",a_len,b_len); for (i = 0; i < a_len; i++) a_data[i] = g_random_double (); for (i = 0; i < b_len; i++) b_data[i] = g_random_double (); bb_convolve (a_len, a_data, b_len, b_data, out_data); for (i = 0; i < a_len + b_len - 1; i++) { gint a_start = 0; gint count = a_len; gint b_start = i; gdouble outval = 0; if (b_start >= (gint) b_len) { guint remove = b_start - b_len + 1; b_start -= remove; a_start += remove; count -= remove; } if (b_start + 1 < count) { count = b_start + 1; } g_assert (count > 0); for (j = 0; j < (guint) count; j++) outval += a_data[a_start + j] * b_data[b_start - j]; out2_data[i] = outval; } out2_data[i] = 0; for (i = 0; i < a_len + b_len; i++) { gdouble ratio; #define IS_VERY_CLOSE_TO_ZERO(a) (ABS(a) < 1e-7) #define SAFE_RATIO(a,b) ((IS_VERY_CLOSE_TO_ZERO(a)&&IS_VERY_CLOSE_TO_ZERO(b)) ? 1.0 : ((a)/(b))) ratio = SAFE_RATIO (out_data[i], out2_data[i]); if (!(0.99999 <= ratio && ratio <= 1.00001)) { g_warning ("mismatch on sample %u", i); for (i = 0; i < a_len + b_len; i++) { ratio = SAFE_RATIO (out_data[i], out2_data[i]); g_message ("sample %4u: fft=%.6f; brute-force=%.6f (ratio=%.6f)", i, out_data[i], out2_data[i], ratio); } g_error ("TEST FAILED"); } } g_free (a_data); g_free (b_data); g_free (out_data); g_free (out2_data); }
gboolean rs_external_editor_gimp(RS_PHOTO *photo, RSFilter *prior_to_resample, guint snapshot) { #ifdef WIN32 return FALSE; #else RSOutput *output = NULL; g_assert(RS_IS_PHOTO(photo)); // We need at least GIMP 2.4.0 to export photo if (!rs_has_gimp(2,4,0)) { return FALSE; } DBusConnection *bus; DBusMessage *message, *reply; GString *filename; bus = dbus_bus_get (DBUS_BUS_SESSION, NULL); gchar* org_name = g_path_get_basename(photo->filename); gchar* org_name_noext = g_utf8_strchr(org_name, -1, '.'); /* Terminate string there */ if (NULL != org_name_noext) org_name_noext[0] = 0; filename = g_string_new(""); g_string_printf(filename, "%s/%s-rawstudio_%.0f.png",g_get_tmp_dir(), org_name, g_random_double()*10000); g_free(org_name); /* Setup our filter chain for saving */ RSFilter *ftransform_input = rs_filter_new("RSColorspaceTransform", prior_to_resample); RSFilter *fdcp = rs_filter_new("RSDcp", ftransform_input); RSFilter *fdenoise= rs_filter_new("RSDenoise", fdcp); RSFilter *ftransform_display = rs_filter_new("RSColorspaceTransform", fdenoise); RSFilter *fend = ftransform_display; GList *filters = g_list_append(NULL, fend); rs_photo_apply_to_filters(photo, filters, snapshot); g_list_free(filters); output = rs_output_new("RSPngfile"); g_object_set(output, "filename", filename->str, NULL); g_object_set(output, "save16bit", FALSE, NULL); g_object_set(output, "copy-metadata", TRUE, NULL); rs_output_execute(output, fend); g_object_unref(output); g_object_unref(ftransform_input); g_object_unref(ftransform_display); g_object_unref(fdenoise); g_object_unref(fdcp); message = dbus_message_new_method_call("org.gimp.GIMP.UI", "/org/gimp/GIMP/UI", "org.gimp.GIMP.UI", "OpenAsNew"); dbus_message_append_args (message, DBUS_TYPE_STRING, &filename->str, DBUS_TYPE_INVALID); /* Send DBus message to GIMP */ reply = dbus_connection_send_with_reply_and_block (bus, message, -1, NULL); /* If we didn't get a reply from GIMP - we try to start it and resend the message */ if (!reply) { gint retval = system("gimp &"); if (retval != 0) { g_warning("system(\"gimp &\") returned: %d\n", retval); g_unlink(filename->str); g_string_free(filename, TRUE); dbus_message_unref (message); return FALSE; } } /* Allow GIMP to start - we send the message every one second */ while (!reply) { gint i = 0; if (i > EXPORT_TO_GIMP_TIMEOUT_SECONDS) { g_warning("Never got a reply from GIMP - deleting temporary file"); g_unlink(filename->str); g_string_free(filename, TRUE); dbus_message_unref (message); return FALSE; } sleep(1); i++; reply = dbus_connection_send_with_reply_and_block (bus, message, -1, NULL); } dbus_message_unref (message); /* Depends on GIMP DBus signal: 'Opened' */ if (rs_has_gimp(2,6,2)) { /* Connect to GIMP and listen for "Opened" signal */ dbus_bus_add_match (bus, "type='signal',interface='org.gimp.GIMP.UI'", NULL); dbus_connection_add_filter(bus, dbus_gimp_opened, filename->str , NULL); g_string_free(filename, FALSE); } else { /* Old sad way - GIMP doesn't let us know that it has opened the photo */ g_warning("You have an old version of GIMP and we suggest that you upgrade to at least 2.6.2"); g_warning("Rawstudio will stop responding for 10 seconds while it waits for GIMP to open the file"); sleep(10); g_unlink(filename->str); g_string_free(filename, TRUE); } return TRUE; #endif }
/* * Get the verify code image form the server */ static gint get_vc_image(QQInfo *info) { if(info -> vc_type == NULL || info -> vc_type -> len <=0){ g_warning("Need vc_type!!(%s, %d)", __FILE__, __LINE__); return PARAMETER_ERR; } gint ret = 0; gchar params[500]; gint res = 0; Request *req = request_new(); Response *rps = NULL; request_set_method(req, "GET"); request_set_version(req, "HTTP/1.1"); g_sprintf(params, IMAGEPATH"?aid="APPID"&r=%.16f&uin=%s&vc_type=%s" , g_random_double(), info -> me -> uin -> str , info -> vc_type -> str); request_set_uri(req, params); request_set_default_headers(req); request_add_header(req, "Host", IMAGEHOST); Connection *con = connect_to_host(IMAGEHOST, 80); if(con == NULL){ g_warning("Can NOT connect to server!(%s, %d)" , __FILE__, __LINE__); request_del(req); return NETWORK_ERR; } send_request(con, req); res = rcv_response(con, &rps); close_con(con); connection_free(con); const gchar *retstatus = rps -> status -> str; if(g_strstr_len(retstatus, -1, "200") == NULL){ g_warning("Server status %s (%s, %d)", retstatus , __FILE__, __LINE__); ret = NETWORK_ERR; goto error; } info -> vc_image_data = g_string_new(NULL); g_string_append_len(info -> vc_image_data, rps -> msg -> str , rps -> msg -> len); info -> vc_image_size = rps -> msg -> len; gchar *ct = response_get_header_chars(rps, "Content-Type"); gchar *vc_ftype = g_strstr_len(ct, -1, "image/"); g_debug("vc content type: %s(%s, %d)", vc_ftype, __FILE__, __LINE__); if(vc_ftype == NULL){ g_warning("Unknown verify code image file type!(%s, %d)" , __FILE__, __LINE__); g_string_free(info -> vc_image_data, TRUE); info -> vc_image_data = NULL; ret = NETWORK_ERR; goto error; } vc_ftype += (sizeof("image/") - 1); g_debug("Verify code image file type: %s len %d (%s, %d)", vc_ftype , info -> vc_image_size, __FILE__, __LINE__); g_strstrip(vc_ftype); info -> vc_image_type = g_string_new(vc_ftype); error: request_del(req); response_del(rps); return ret; }
/* * Check if we need input the verify code. * The result is stored in info. * * return -1 if error ocurs or return 0 */ static gint check_verify_code(QQInfo *info) { g_debug("Check veriry code...(%s, %d)", __FILE__, __LINE__); gint ret = 0; gchar params[300]; Request *req = request_new(); Response *rps = NULL; int res = 0; request_set_method(req, "GET"); request_set_version(req, "HTTP/1.1"); g_sprintf(params, VCCHECKPATH"?uin=%s&appid="APPID"&r=%.16f" , info -> me -> uin -> str, g_random_double()); request_set_uri(req, params); request_set_default_headers(req); request_add_header(req, "Host", LOGINHOST); Connection *con = connect_to_host(LOGINHOST, 80); send_request(con, req); res = rcv_response(con, &rps); close_con(con); connection_free(con); if (-1 == res || !rps) { g_warning("Null point access (%s, %d)\n", __FILE__, __LINE__); ret = -1; goto error; } const gchar *retstatus = rps -> status -> str; if(g_strstr_len(retstatus, -1, "200") == NULL){ g_warning("Server status %s (%s, %d)", retstatus , __FILE__, __LINE__); ret = NETWORK_ERR; goto error; } /* * The http message body has two format: * * ptui_checkVC('1','9ed32e3f644d968809e8cbeaaf2cce42de62df * ee12c14b74'); * ptui_checkVC('0','!LOB'); * The former means we need verify code image and the second * parameter is vc_type. * The later means we don't need the verify code image. The second * parameter is the verify code. The vc_type is in the header * "Set-Cookie". */ gchar *c, *s; s = rps -> msg -> str; if(g_strstr_len(s, -1, "ptui_checkVC") == NULL){ g_warning("Get vc_type error!(%s, %d)", __FILE__, __LINE__); ret = NETWORK_ERR; goto error; } g_debug("check vc return: %s(%s, %d)", s, __FILE__, __LINE__); c = g_strstr_len(s, -1, "'"); ++c; if(*c == '0'){ /* * We got the verify code. */ info -> need_vcimage = FALSE; s = c; c = g_strstr_len(s, -1, "'"); s = c + 1; c = g_strstr_len(s, -1, "'"); s = c + 1; c = g_strstr_len(s, -1, "'"); *c = '\0'; info -> verify_code = g_string_new(s); g_debug("Verify code : %s (%s, %d)", info -> verify_code -> str , __FILE__, __LINE__); /* * We need get the ptvfsession from the header "Set-Cookie" */ info -> ptvfsession = get_cookie(rps, "ptvfsession"); }else if(*c == '1'){ /* * We need get the verify image. */ info -> need_vcimage = TRUE; s = c; c = g_strstr_len(s, -1, "'"); s = c + 1; c = g_strstr_len(s, -1, "'"); s = c + 1; c = g_strstr_len(s, -1, "'"); *c = '\0'; info -> vc_type = g_string_new(s); g_debug("We need verify code image! vc_type: %s (%s, %d)" , info -> vc_type -> str, __FILE__, __LINE__); }else{ g_warning("Unknown return value!(%s, %d)", __FILE__, __LINE__); ret = NETWORK_ERR; goto error; } error: request_del(req); response_del(rps); return ret; }