//defined in the header file corresponding to this file // ComparisonReturnedTable CompareCVPolygons(std::vector<OPENCV_POINT>& poly_reference, std::vector<OPENCV_POINT>& poly_target) { TURN_REP trf, trg; TURN_REP* f; TURN_REP* g; EVENT_REC e; double ht0, slope, alpha, theta_star, metric2, metric, ht0_err, slope_err; poly_to_turn_rep(poly_reference, &trg); g = &trg; poly_to_turn_rep(poly_target, &trf); f = &trf; init_vals(f, g, &ht0, &slope, &alpha); init_events(f, g); metric2 = h_t0min(f, g, ht0, slope, alpha, reinit_interval(f, g), &theta_star, &e, &ht0_err, &slope_err); /* * Fixups: The value of metric2 can be a tiny * negative number for an exact match. Call it 0. * Theta_star can be over 360 or under -360 because we * handle t=0 events at t=1. Normalize to [-PI,PI). */ metric = metric2 > 0 ? sqrt(metric2) : 0; return ComparisonReturnedTable(metric, turn(theta_star, 0)*180/M_PI, tr_i(f, e.fi), tr_i(g, e.gi), ht0_err, slope_err); }
int main() { //Assign pins and whatnot init_hw(); //Set up the screen values, but not sure this makes sense //because the epic ought to send it the latest values init_vals(); //LCD initialisation incantations lcd_init(); //Performed here, but also redone every time the sensor chip returns a zero //on the i2c reset_rht(); //Unpack the QR code into a bit array unpack(); //do the screen 'touch points to calibrate' prompt tp_calibrate(); while(1) { poll_tp(); poll_screen(); rxipoll(); poll_temps(); poll_val_uploads(); rxipoll(); } }
/* * Recompute ht0 and slope for the current event. * Renormalize the turning reps so that the event * discontinuities are first in each. This keeps * all s values within [0,1) while recomputing so * that all are represented with the same precision. * If we check that no other events are pending within * machine epsilon of t for (fi,gi) before calling this, * numerical stability is guaranteed (unlike the first * two ways I tried). */ void reinit_vals(TURN_REP* f, TURN_REP* g, int fi, int gi, double* ht0_rtn, double* slope_rtn) { double a; TURN_REP fr, gr; rotate_turn_rep(f, fi, &fr); rotate_turn_rep(g, gi, &gr); init_vals(&fr, &gr, ht0_rtn, slope_rtn, &a); }
static inline ref_t continuation(cont_t fn, ref_t saved_cont) { ref_t obj = gc_alloc(sizeof(struct continuation), CONTINUATION_POINTER_TAG); C(obj)->fn = fn; C(obj)->expand = NO; C(obj)->saved_cont = saved_cont; C(obj)->closure = isnil(saved_cont) ? NIL : C(saved_cont)->closure; init_vals(obj); return obj; }
static action_t cont_apply() { ref_t func = C(cont)->val[0]; size_t len = length(expr), arity = getarity(func); if (hasrest(func)) { if (len < arity) argument_error(len); } else { if (len != arity) argument_error(len); } init_vals(cont); C(cont)->fn = cont_apply_arg, C(cont)->val[0] = func, C(cont)->val[1] = cdr(expr); return eval_expr(car(expr)); }
static action_t cont_apply_apply() { ref_t func = C(cont)->val[0], args = expr; ref_t formals = getformals(func); size_t arity = getarity(func); C(cont)->closure = getclosure(func); for(; arity > 0; arity--, formals = cdr(formals), args = cdr(args)) bind(car(formals), car(args)); if (!isnil(formals)) bind(car(formals), args); init_vals(cont); if (isbuiltin(func)) { getfn(func)(); pop_cont(); } else eval_do(getbody(func)); return ACTION_APPLY_CONT; }
/* * Parse options, read polygons, convert to turning reps, initialize * everything, compute the answers, and print the answers. Do all * this in a loop until all the polygons are gone. */ int main(int argc, char** argv) { int update_p, precise_p, n_repeats, i; TURN_REP trf, trg; TURN_REP* f; TURN_REP* g; std::vector<OPENCV_POINT> pf, pg; EVENT_REC e; double ht0, slope, alpha, theta_star, metric2, metric, ht0_err, slope_err; #ifdef CPU_TIME struct tms cpu_time; clock_t cpu_start_time; int elapsed_ms; int total_elapsed_ms = 0; #define start_cpu_time() \ (times(&cpu_time), cpu_start_time = cpu_time.tms_utime) #define get_cpu_time() \ (times(&cpu_time), (cpu_time.tms_utime - cpu_start_time)*1000/HZ) #endif precise_p = 0; update_p = 1; n_repeats = 1; while(--argc) { ++argv; if (argv[0][0] == '-' && argv[0][1] != '\0') switch(argv[0][1]) { case 'p': precise_p = 1; break; case 'n': update_p = 0; break; case 'r': if (sscanf(&argv[0][2], "%d", &i) == 1) n_repeats = i; break; default: fprintf(stderr, "sim: unknown option\n"); return 1; } } if (read_poly(pg)) //reference polygon is pg { poly_to_turn_rep(pg, &trg); g = &trg; while (read_poly(pf)) { poly_to_turn_rep(pf, &trf); f = &trf; #ifdef CPU_TIME start_cpu_time(); #endif /* Performance measure repeat loop. */ for (i = 0; i < n_repeats; ++i) { init_vals(f, g, &ht0, &slope, &alpha); init_events(f, g); metric2 = h_t0min(f, g, ht0, slope, alpha, update_p ? reinit_interval(f, g) : 0, &theta_star, &e, &ht0_err, &slope_err); } #ifdef CPU_TIME elapsed_ms = get_cpu_time(); total_elapsed_ms += elapsed_ms; #endif /* * Fixups: The value of metric2 can be a tiny * negative number for an exact match. Call it 0. * Theta_star can be over 360 or under -360 because we * handle t=0 events at t=1. Normalize to [-PI,PI). */ metric = metric2 > 0 ? sqrt(metric2) : 0; printf(precise_p ? "%.18lg %.18lg %d %d %lg %lg" : "%lg %lg %d %d %lg %lg", metric, turn(theta_star, 0)*180/M_PI, tr_i(f, e.fi), tr_i(g, e.gi), ht0_err, slope_err); #ifdef CPU_TIME printf(" %d\n", (elapsed_ms + (n_repeats/2))/n_repeats); #else printf("\n"); #endif } } #ifdef CPU_TIME printf("total user time: %d ms\n", (total_elapsed_ms + (n_repeats/2))/n_repeats); #endif return 0; }
static void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[1]; GimpPDBStatusType status = GIMP_PDB_SUCCESS; GimpRunMode run_mode; /* Plug-in variables */ gboolean single_image; gboolean defaults_proc; /* Plug-In variables */ cairo_surface_t *pdf_file; cairo_t *cr; GimpExportCapabilities capabilities; guint32 i = 0; gint32 j = 0; gdouble x_res, y_res; gdouble x_scale, y_scale; gint32 image_id; gboolean exported; GimpImageBaseType type; gint32 temp; gint *layers; gint32 num_of_layers; GimpDrawable *layer; cairo_surface_t *layer_image; gdouble opacity; gint x, y; GimpRGB layer_color; gboolean single_color; gint32 mask_id = -1; GimpDrawable *mask = NULL; cairo_surface_t *mask_image = NULL; FILE *fp; INIT_I18N (); /* Setting mandatory output values */ *nreturn_vals = 1; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; /* Initializing all the settings */ multi_page.image_count = 0; if (! init_vals (name, nparams, param, &single_image, &defaults_proc, &run_mode)) { values[0].data.d_status = GIMP_PDB_CALLING_ERROR; return; } /* Starting the executions */ if (run_mode == GIMP_RUN_INTERACTIVE) { if (single_image) { if (! gui_single ()) { values[0].data.d_status = GIMP_PDB_CANCEL; return; } } else if (! gui_multi ()) { values[0].data.d_status = GIMP_PDB_CANCEL; return; } if (file_name == NULL) { values[0].data.d_status = GIMP_PDB_CALLING_ERROR; gimp_message (_("You must select a file to save!")); return; } } fp = g_fopen (file_name, "wb"); pdf_file = cairo_pdf_surface_create_for_stream (write_func, fp, 1, 1); if (cairo_surface_status (pdf_file) != CAIRO_STATUS_SUCCESS) { char *str = g_strdup_printf (_("An error occured while creating the PDF file:\n" "%s\n" "Make sure you entered a valid filename and that the selected location isn't read only!"), cairo_status_to_string (cairo_surface_status (pdf_file))); gimp_message (str); g_free (str); values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR; return; } cr = cairo_create (pdf_file); capabilities = GIMP_EXPORT_CAN_HANDLE_RGB | GIMP_EXPORT_CAN_HANDLE_ALPHA | GIMP_EXPORT_CAN_HANDLE_GRAY | GIMP_EXPORT_CAN_HANDLE_LAYERS | GIMP_EXPORT_CAN_HANDLE_INDEXED; if (optimize.apply_masks) capabilities |= GIMP_EXPORT_CAN_HANDLE_LAYER_MASKS; for (i = 0; i < multi_page.image_count; i++) { /* Save the state of the surface before any changes, so that settings * from one page won't affect all the others */ cairo_save (cr); image_id = multi_page.images[i]; /* We need the active layer in order to use gimp_image_export */ temp = gimp_image_get_active_drawable (image_id); if (temp == -1) exported = gimp_export_image (&image_id, &temp, NULL, capabilities) == GIMP_EXPORT_EXPORT; else exported = FALSE; type = gimp_image_base_type (image_id); gimp_image_get_resolution (image_id, &x_res, &y_res); x_scale = 72.0 / x_res; y_scale = 72.0 / y_res; cairo_pdf_surface_set_size (pdf_file, gimp_image_width (image_id) * x_scale, gimp_image_height (image_id) * y_scale); /* This way we set how many pixels are there in every inch. * It's very important for PangoCairo */ cairo_surface_set_fallback_resolution (pdf_file, x_res, y_res); /* PDF is usually 72 points per inch. If we have a different resolution, * we will need this to fit our drawings */ cairo_scale (cr, x_scale, y_scale); /* Now, we should loop over the layers of each image */ layers = gimp_image_get_layers (image_id, &num_of_layers); for (j = 0; j < num_of_layers; j++) { layer = gimp_drawable_get (layers [num_of_layers-j-1]); opacity = gimp_layer_get_opacity (layer->drawable_id)/100.0; /* Gimp doesn't display indexed layers with opacity below 50% * And if it's above 50%, it will be rounded to 100% */ if (type == GIMP_INDEXED) { if (opacity <= 0.5) opacity = 0.0; else opacity = 1.0; } if (gimp_item_get_visible (layer->drawable_id) && (! optimize.ignore_hidden || (optimize.ignore_hidden && opacity > 0.0))) { mask_id = gimp_layer_get_mask (layer->drawable_id); if (mask_id != -1) { mask = gimp_drawable_get (mask_id); mask_image = get_drawable_image (mask); } gimp_drawable_offsets (layer->drawable_id, &x, &y); /* For raster layers */ if (!gimp_item_is_text_layer (layer->drawable_id)) { layer_color = get_layer_color (layer, &single_color); cairo_rectangle (cr, x, y, layer->width, layer->height); if (optimize.vectorize && single_color) { cairo_set_source_rgba (cr, layer_color.r, layer_color.g, layer_color.b, layer_color.a * opacity); if (mask_id != -1) cairo_mask_surface (cr, mask_image, x, y); else cairo_fill (cr); } else { cairo_clip (cr); layer_image = get_drawable_image (layer); cairo_set_source_surface (cr, layer_image, x, y); cairo_push_group (cr); cairo_paint_with_alpha (cr, opacity); cairo_pop_group_to_source (cr); if (mask_id != -1) cairo_mask_surface (cr, mask_image, x, y); else cairo_paint (cr); cairo_reset_clip (cr); cairo_surface_destroy (layer_image); } } /* For text layers */ else { drawText (layer, opacity, cr, x_res, y_res); } } /* We are done with the layer - time to free some resources */ gimp_drawable_detach (layer); if (mask_id != -1) { gimp_drawable_detach (mask); cairo_surface_destroy (mask_image); } } /* We are done with this image - Show it! */ cairo_show_page (cr); cairo_restore (cr); if (exported) gimp_image_delete (image_id); } /* We are done with all the images - time to free the resources */ cairo_surface_destroy (pdf_file); cairo_destroy (cr); fclose (fp); /* Finally done, let's save the parameters */ gimp_set_data (DATA_OPTIMIZE, &optimize, sizeof (optimize)); if (!single_image) { g_strlcpy (multi_page.file_name, file_name, MAX_FILE_NAME_LENGTH); gimp_set_data (DATA_IMAGE_LIST, &multi_page, sizeof (multi_page)); } }
static int __init vfb_probe(struct platform_device *dev) { struct fb_info *info; int retval = -ENOMEM; /* Reserve the framebuffer memory */ if (!request_mem_region(vfb_addr, vfb_size, "STM32F4 Framebuffer")) { printk(KERN_ERR "vfb: unable to reserve " "framebuffer at 0x%0x\n", (unsigned int)vfb_addr); retval = -EBUSY; goto fail_reqmem; } /* Allocate framebuffer info structure */ info = framebuffer_alloc(sizeof(struct fb_info), &dev->dev); if (!info) { printk(KERN_ERR "vfb: unable to reserve framebuffer info\n"); retval = -ENOMEM; goto fail_fballoc; } /* For real video cards we use ioremap */ info->screen_base = ioremap(vfb_addr, vfb_size); if (!info->screen_base) { printk(KERN_ERR "vfb: unable to map framebuffer\n"); retval = -ENOMEM; goto fail_remap; } /* Assign the frame buffer data */ info->screen_size = vfb_size; info->fbops = &vfb_ops; /* * VFB must clear memory to prevent kernel info * leakage into userspace * VGA-based drivers MUST NOT clear memory if * they want to be able to take over vgacon */ memset(info->screen_base, 0, info->screen_size); retval = fb_find_mode(&info->var, info, NULL, NULL, 0, NULL, 8); if ((!retval) || (retval == 4)) memcpy(&(info->var), &vfb_default, sizeof(struct fb_var_screeninfo)); vfb_fix.smem_start = vfb_addr; vfb_fix.smem_len = vfb_size; memcpy(&(info->fix), &vfb_fix, sizeof(struct fb_fix_screeninfo)); /* Allocate pseudo palette data */ info->pseudo_palette = kmalloc(sizeof(u32) * 16, GFP_KERNEL); if (!info->pseudo_palette) { printk(KERN_ERR "vfb: unable to reserve palette memory\n"); retval = -ENOMEM; goto fail_palette; } //info->pseudo_palette = info->par; info->par = NULL; info->flags = FBINFO_FLAG_DEFAULT; /* * We expect the boot loader to have initialized the chip * with appropriate parameters from which we can determinte * the flavor of lcd panel attached */ retval = init_vals(info); if (retval < 0) { printk(KERN_ERR "vfb: unable to reserve cmap memory\n"); goto fail_cmap; } /* Regiser the framebuffer */ retval = register_framebuffer(info); if (retval < 0) { printk(KERN_ERR "vfb: unable to register framebuffer\n"); goto fail_register; } /* Assign the driver data */ platform_set_drvdata(dev, info); /* Everything is OK */ printk(KERN_INFO "fb%d: Virtual frame buffer device, " "using %ldK of video memory\n", info->node, info->screen_size >> 10); return 0; /* There is an error! */ fail_register: fb_dealloc_cmap(&info->cmap); fail_cmap: kfree(info->pseudo_palette); fail_palette: iounmap(info->screen_base); fail_remap: framebuffer_release(info); fail_fballoc: release_mem_region(vfb_addr, vfb_size); fail_reqmem: return retval; }
int main(int argc, char **argv) { if(argc < 5) { fprintf(stderr, "stream_producer needs at least 4 arguments\n"); exit(1); } if(strcmp(argv[1], "--write-fifo") != 0) { fprintf(stderr, "stream_producer first arg must be --write-fifo\n"); exit(1); } if(strcmp(argv[3], "--read-fifo") != 0) { fprintf(stderr, "stream producer third arg must be --read-fifo\n"); exit(1); } printf("C binopt: start\n"); ciel_init(argv[2], argv[4]); json_t* task_private = ciel_get_task(); json_error_t error_bucket; json_t* kwargs; char* s_str; char* k_str; char* t_str; char* v_str; char* rf_str; char* cp_str; char* n_str; char* chunk_str; char* start_str; fprintf(stderr, "doing decode\n"); if(json_unpack_ex(task_private, &error_bucket, 0, "{s[sssssssss]so}", "proc_pargs", &s_str, &k_str, &t_str, &v_str, &rf_str, &cp_str, &n_str, &chunk_str, &start_str, "proc_kwargs", &kwargs)) { ciel_json_error("Failed to decode proc_pargs", &error_bucket); exit(1); } fprintf(stderr, "doing conversion\n"); s = strtod(s_str, NULL); k = strtod(k_str, NULL); t = strtod(t_str, NULL); v = strtod(v_str, NULL); rf = strtod(rf_str, NULL); cp = strtod(cp_str, NULL); n = (int)strtod(n_str, NULL); chunk = (int)strtod(chunk_str, NULL); start = strcmp(start_str, "false"); fprintf(stderr, "Got arguments: %g %g %g %g %g %g %d %d %s\n", s, k, t, v, rf, cp, n, chunk, start_str); if(!start) { json_t* in_ref = json_object_get(kwargs, "input_ref"); binopt_ciel_in = ciel_open_ref_async(in_ref, 1, 1, 0); ciel_set_input_unbuffered(binopt_ciel_in); } else { binopt_ciel_in = 0; } json_decref(task_private); binopt_ciel_out = ciel_open_output(0, 1, 0, 0); ciel_set_output_unbuffered(binopt_ciel_out); init_vals(); if (start == 1) { OUTPUT(n); gen_initial_optvals(); } else { int rowstart=0; INPUT(rowstart); if (rowstart==0) { double v; INPUT(v); char buf[20]; int chars_written = min(snprintf(buf, 20, "%.9f\n", v), 20); ciel_write_output(binopt_ciel_out, buf, chars_written); } else { int rowto = (rowstart - chunk) > 0 ? (rowstart - chunk) : 0; process_rows(rowstart, rowto); } } if(!start) { ciel_close_ref(binopt_ciel_in); } ciel_close_output(binopt_ciel_out); ciel_exit(); return 0; }
static void fn_macroexpand1() { init_vals(cont); C(cont)->fn = cont_macroexpand1; cont = continuation(NULL, cont); expr = lookup(sym_args); }