Example #1
0
view_struct *view_struct_new_with_rgb (gint width, gint height, void (*calc_buf) (gpointer, unsigned char*, gint, gint), gpointer external_data, gboolean if_rgb)  {
//	Builds a preview structure, for a 8 bits image
	view_struct *vs;
	vs = (view_struct *) x_malloc(sizeof(view_struct), "view_struct");
//	printf("View_struct_new: %d\n",vs);
	vs->width = width;
	vs->height = height;
	vs->calc_buf = calc_buf;
	vs->external_data = external_data;
	vs->if_rgb = if_rgb;

	if (if_rgb)
		vs->buf8 = (unsigned char *) x_calloc(3*width*height,sizeof(unsigned char), "unsigned char (vs->buf8 in view_area.c)");
	else
		vs->buf8 = (unsigned char *) x_calloc(width*height,sizeof(unsigned char), "unsigned char (vs->buf8 in view_area.c)");

	vs->area = gtk_drawing_area_new();
	gtk_widget_set_size_request( GTK_WIDGET(vs->area), vs->width, vs->height);
	gtk_signal_connect(GTK_OBJECT(vs->area), "configure_event",
		(GtkSignalFunc) area_configure_event, (gpointer) vs);
	gtk_signal_connect(GTK_OBJECT(vs->area),"expose_event",
		(GtkSignalFunc) area_expose_event, (gpointer) vs);
	gtk_widget_show(vs->area);

	vs->viewport = NULL;
	return vs;
}
Example #2
0
draw_buf *draw_buf_new (gint size) {
    //	Buffer containing a "moving window" of the last pixels drawn
    //	Allows a proper merging of the pixels drawn with the original image.
    //	so that there are no holes nor superimposition when the angles
    //	of successive and connected segments are not the same
    draw_buf *db;
    db = (draw_buf *) x_malloc(sizeof(draw_buf), "draw_buf");
    db->size = size;		// Diameter
    db->data = (hf_type *) x_calloc(db->size * db->size,sizeof(hf_type), "hf_type (db->data in draw_buf_new)");
    db->tmp = (hf_type *) x_calloc(db->size * db->size,sizeof(hf_type), "hf_type (db->tmp in draw_buf_new)");
    db->active = FALSE;
    db->tail = NULL;
    db->max_tail = 0;
    db->delayed_dot = FALSE;
    return db;
}
Example #3
0
static int is_eeprom_fru(char *eeprom_file, GtkTextBuffer *buf, GtkTextIter *iter)
{
    FILE *fp;
    unsigned char *raw_input_data = NULL;
    size_t bytes;
    struct FRU_DATA *fru = NULL;
    char text[256];

    fp = fopen(eeprom_file, "rb");
    if(fp == NULL) {
        int errsv = errno;
        printf_err("Cannot open file %s\n%s\n", eeprom_file, strerror(errsv));
        return 0;
    }

    raw_input_data = x_calloc(1, 1024);
    bytes = fread(raw_input_data, 1024, 1, fp);
    fclose(fp);

    /* Since EOF should be reached, bytes should be zero */
    if (!bytes)
        fru = parse_FRU(raw_input_data);

    if (fru) {
        sprintf(text, "Found %s:\n", eeprom_file);
        gtk_text_buffer_insert(buf, iter, text, -1);

        if (fru->Board_Area->manufacturer && fru->Board_Area->manufacturer[0] & 0x3F) {
            sprintf(text, "FMC Manufacture : %s\n", &fru->Board_Area->manufacturer[1]);
            gtk_text_buffer_insert(buf, iter, text, -1);
        }
        if (fru->Board_Area->product_name && fru->Board_Area->product_name[0] & 0x3F) {
            sprintf(text, "Product Name: %s\n", &fru->Board_Area->product_name[1]);
            gtk_text_buffer_insert(buf, iter, text, -1);
        }
        if (fru->Board_Area->part_number && fru->Board_Area->part_number[0] & 0x3F) {
            sprintf(text, "Part Number : %s\n", &fru->Board_Area->part_number[1]);
            gtk_text_buffer_insert(buf, iter, text, -1);
        }
        if (fru->Board_Area->serial_number && fru->Board_Area->serial_number[0] & 0x3F) {
            sprintf(text, "Serial Number : %s\n", &fru->Board_Area->serial_number[1]);
            gtk_text_buffer_insert(buf, iter, text, -1);
        }
        if (fru->Board_Area->mfg_date) {
            time_t tmp = min2date(fru->Board_Area->mfg_date);
            sprintf(text, "Date of Man : %s", ctime(&tmp));
            gtk_text_buffer_insert(buf, iter, text, -1);
        }

        sprintf(text, "\n");
        gtk_text_buffer_insert(buf, iter, text, -1);

        free(fru);
        fru = NULL;

        return 1;
    }
    return 0;
}
Example #4
0
line_struct *line_new (gint max_seg, gint tip_size) {
//	Allocator for an irregular line struct (polyline)
	line_struct *l;
	l = (line_struct *) x_malloc(sizeof(line_struct), "line_struct");
	l->max_seg = max_seg;
	l->alloc_seg = max_seg;
	l->cur_seg = -1;
	l->segments = (segment_struct *) x_calloc(max_seg,sizeof(segment_struct), "segment_struct");
	l->size = tip_size;
	l->transl_x = 0.0;
	l->transl_y = 0.0;
	l->scale_x = 1.0;
	l->scale_y = 1.0;
// printf("MAX_SEG: %d\n",max_seg);
	return l;
}
Example #5
0
void draw_buf_reinit (map_struct *map) {
    // Reinitialize the draw buffer to 0 - public method
    gint i, j, ii;
    draw_buf *d = map->dr_buf;
//	printf("RADIUS: %d; SIZE: %d\n",map->radius, d->size);
    for (i=0; i<d->size; i++)
        for (j=0; j<d->size; j++) {
            ii = i + j*d->size;
//			*(d->data+ii) = 0.7 * *(d->data+ii);
            *(d->data+ii) = 0;
        }
    if (d->tail)
        x_free(d->tail);
    d->tail = (tail_struct *) x_calloc(d->max_tail,sizeof(tail_struct), "tail_struct (d->tail in draw_buf_reinit)" );
    d->current_tail = d->max_tail-1; // before the 1st
}
Example #6
0
void draw_buf_init (map_struct *map, gdouble spacing) {
    // Reinitialize the draw buffer to 0 - public method
    gint i;
    draw_buf *d=map->dr_buf;
    d->active = FALSE;
    for (i=0; i<(d->size*d->size); i++) {
        *(d->data+i) = (hf_type) 0;
    }
    d->max_tail = (gint)  (1.5+(1.0 / spacing));
//	printf("MAX TAIL: %d\n",d->max_tail);
    d->current_tail = d->max_tail-1; // before the 1st
    if (d->tail)
        x_free(d->tail);
    d->tail = (tail_struct*) x_calloc(d->max_tail,sizeof(tail_struct), "tail_struct (d->tail in draw_buf_init)");
    d->delayed_dot = FALSE;
}
Example #7
0
void select_for_fill (fill_struct *pen, hf_struct_type *hf, gint x, gint y) {

	// Select an area in the "magic wand" style,
	// Then fill it given the "paint bucket" parameters (fill _struct *)
	
	hf_type filling_value, height;
	
	if (!hf->tmp_buf)
		hf_backup(hf);
		
	//	We use "select_buf" for storing the selection mask
	if (!hf->select_buf)
		hf->select_buf = (hf_type *) x_calloc(sizeof(hf_type) * hf->max_x * hf->max_y, 1, "hf_type (hf->select_buf)");

	switch (pen->select_mode) {
		case SELECT_ADD:
			height = filling_value = pen->height;
			break;
		case SELECT_SUBTRACT:
			filling_value = MIN_FILLING_VALUE;
			height = pen->height + 1; // pen->height is bounded by MAX_HF_VALUE-1
			break;
		case SELECT_REPLACE:
		default:
			height = filling_value = pen->height;
			hf_reset_buffer(hf->select_buf, hf->max_x, hf->max_y);
	}
	
	// Height must be >= 1 and <= MAX_HF_VALUE-1
	height = MIN(MAX_HF_VALUE-1,MAX(1,height));
	
	fill_area_with_mode (hf->tmp_buf, hf->select_buf, hf->max_x, hf->max_y, filling_value, height, x, y, FILL_MAX, pen->select_mode);

	// Uncomment the next line for testing	
//		memcpy (hf->hf_buf, hf->select_buf, hf->max_x*hf->max_y*sizeof(hf_type));

}
Example #8
0
GtkWidget * hf_creation_dialog_new(GtkWidget *window, GtkTooltips *tooltips, 
		gpointer hf_options_ptr, gpointer widget_list_ptr) {
	// Initializes the dialog for creating height fields
	// Four parts, from top to bottom:
	//	1. Kind / type of HF
	//	2. Shape filters
	//	3. Generic options (size...)
	//	4. Options for the current HF
	// Returns a vbox container, allowing to add / substract particular controls
	// "window" only needed for heritance of characteristics in child toolbar(s)
	// "tooltips" needed for packing tooltips, could have only one for the whole app.
	// gpointer hf_options_ptr_pgtr:  is normally the address of the current hf_options pointer 
	// (hf_options_struct **)

	GtkWidget *dialog, *hbox, *vbox, *frame;
	gint default_hf_size;
	omenu_struct_type *opt_menu;
	hf_creation_wdg_struct *wdg_str;
//	printf("HFO PTR in HF_CREATION_DIALOG_NEW: %d - %x\n",hf_options_ptr, hf_options_ptr);
	wdg_str = (hf_creation_wdg_struct *) x_calloc(sizeof(hf_creation_wdg_struct),1, "hf_creation_wdg_struct");
	*((hf_creation_wdg_struct **) widget_list_ptr) = wdg_str;

	((hf_options_struct *)hf_options_ptr)->creation_widgets = wdg_str;

	frame = options_frame_new("HeightField");

	vbox = gtk_vbox_new(FALSE, 0);
	gtk_widget_show(vbox);

	//	1st generic option:  HF size - a power of 2
	//	Default:  some % of screen width
	
	hbox = gtk_hbox_new(FALSE, DEF_PAD);
	gtk_widget_show(hbox);
	define_label_in_box("Size", hbox, FALSE, FALSE, DEF_PAD);

	default_hf_size = hf_default_size();
	
	create_omenu_with_callb_data (&opt_menu, sizes_list,
		NBSIZES, 
		find_omenu_num(sizes_list, default_hf_size, NBSIZES),
		hf_options_ptr);
	gtk_box_pack_start(GTK_BOX(hbox), opt_menu->omenu_ptr, FALSE, FALSE, 0);

	wdg_str->size_menu = opt_menu;

 	gtk_box_pack_start (GTK_BOX (hbox), create_render_bar (window, tooltips, ((hf_options_struct *)hf_options_ptr)->render_str), FALSE, FALSE, 0);

	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);

	gtk_box_pack_start(GTK_BOX(vbox),
		hf_types_toolbar_new(window, tooltips, &wdg_str->hf_types_toolbar,hf_options_ptr), FALSE, FALSE, 0);

	//	Other generic options ?

	gtk_container_add(GTK_CONTAINER(frame), vbox);
	dialog = gtk_vbox_new(FALSE,0);
	gtk_box_pack_start(GTK_BOX(dialog), frame, FALSE, FALSE, 0);
	gtk_widget_show(dialog);

	return dialog;
}
Example #9
0
render_struct *render_struct_new () {
	return (render_struct *) x_calloc(sizeof(render_struct),1, "render_struct");
}
Example #10
0
static struct manifest *
read_manifest(gzFile f)
{
	struct manifest *mf = create_empty_manifest();

	uint32_t magic;
	READ_INT(4, magic);
	if (magic != MAGIC) {
		cc_log("Manifest file has bad magic number %u", magic);
		goto error;
	}

	READ_BYTE(mf->version);
	if (mf->version != MANIFEST_VERSION) {
		cc_log("Manifest file has unknown version %u", mf->version);
		goto error;
	}

	READ_BYTE(mf->hash_size);
	if (mf->hash_size != 16) {
		// Temporary measure until we support different hash algorithms.
		cc_log("Manifest file has unsupported hash size %u", mf->hash_size);
		goto error;
	}

	READ_INT(2, mf->reserved);

	READ_INT(4, mf->n_files);
	mf->files = x_calloc(mf->n_files, sizeof(*mf->files));
	for (uint32_t i = 0; i < mf->n_files; i++) {
		READ_STR(mf->files[i]);
	}

	READ_INT(4, mf->n_file_infos);
	mf->file_infos = x_calloc(mf->n_file_infos, sizeof(*mf->file_infos));
	for (uint32_t i = 0; i < mf->n_file_infos; i++) {
		READ_INT(4, mf->file_infos[i].index);
		READ_BYTES(mf->hash_size, mf->file_infos[i].hash);
		READ_INT(4, mf->file_infos[i].size);
		READ_INT(8, mf->file_infos[i].mtime);
		READ_INT(8, mf->file_infos[i].ctime);
	}

	READ_INT(4, mf->n_objects);
	mf->objects = x_calloc(mf->n_objects, sizeof(*mf->objects));
	for (uint32_t i = 0; i < mf->n_objects; i++) {
		READ_INT(4, mf->objects[i].n_file_info_indexes);
		mf->objects[i].file_info_indexes =
			x_calloc(mf->objects[i].n_file_info_indexes,
			         sizeof(*mf->objects[i].file_info_indexes));
		for (uint32_t j = 0; j < mf->objects[i].n_file_info_indexes; j++) {
			READ_INT(4, mf->objects[i].file_info_indexes[j]);
		}
		READ_BYTES(mf->hash_size, mf->objects[i].hash.hash);
		READ_INT(4, mf->objects[i].hash.size);
	}

	return mf;

error:
	cc_log("Corrupt manifest file");
	free_manifest(mf);
	return NULL;
}
Example #11
0
scale_buttons_struct *scale_buttons_new_with_callback (GtkOrientation orient, gint lower, gint upper, gpointer callback_fn, gpointer external_data) {
	GtkWidget *label, *button;
	scale_buttons_struct *sbs;
	sbs = (scale_buttons_struct *) x_calloc(sizeof(scale_buttons_struct),1, "scale_buttons_struct");
	if (orient==GTK_ORIENTATION_HORIZONTAL)
		sbs->box = gtk_hbox_new (FALSE, 0);
	else
		sbs->box = gtk_vbox_new (FALSE, 0);
	gtk_widget_show (sbs->box);
	sbs->group=NULL;
	sbs->lower = lower;
	sbs->upper = upper;
	sbs->current = 0;
	label = gtk_label_new(_("Scale % "));
	gtk_widget_show (label);
	gtk_box_pack_start(GTK_BOX(sbs->box), label, TRUE, TRUE, DEF_PAD*0.5);
	if (lower>=SCALE_ID_12_5) {
		button = define_radio_button_in_box_with_data (sbs->box, &sbs->group, 
			SCALE_12_5, set_display_scale_from_label, sbs, FALSE);
		if (callback_fn && external_data)
			gtk_signal_connect ( GTK_OBJECT (button), 
				"toggled", 
				GTK_SIGNAL_FUNC(callback_fn),
				external_data);
	}
	if ((lower>=SCALE_ID_25)&& (upper<=SCALE_ID_25)) {
		button = define_radio_button_in_box_with_data (sbs->box, &sbs->group,
			SCALE_25, set_display_scale_from_label, sbs, FALSE) ;
		if (callback_fn && external_data)
			gtk_signal_connect ( GTK_OBJECT (button), 
				"toggled", 
				GTK_SIGNAL_FUNC(callback_fn),
				external_data);
	}
	if ((lower>=SCALE_ID_50) && (upper<=SCALE_ID_50)) {
		button = define_radio_button_in_box_with_data (sbs->box, &sbs->group, 
			SCALE_50, set_display_scale_from_label, sbs, FALSE) ;
		if (callback_fn && external_data)
			gtk_signal_connect ( GTK_OBJECT (button), 
				"toggled", 
				GTK_SIGNAL_FUNC(callback_fn),
				external_data);
	}
	if ((lower>=SCALE_ID_100) && (upper<=SCALE_ID_100)) {
		button = define_radio_button_in_box_with_data (sbs->box, &sbs->group, 
			SCALE_100, set_display_scale_from_label, sbs, TRUE) ;
		if (callback_fn && external_data)
			gtk_signal_connect ( GTK_OBJECT (button), 
				"toggled", 
				GTK_SIGNAL_FUNC(callback_fn),
				external_data);
	}
	if ((lower>=SCALE_ID_200) && (upper<=SCALE_ID_200)) {
		button = define_radio_button_in_box_with_data (sbs->box, &sbs->group, 
			SCALE_200, set_display_scale_from_label, sbs, FALSE) ;
		if (callback_fn && external_data)
			gtk_signal_connect ( GTK_OBJECT (button), 
				"toggled", 
				GTK_SIGNAL_FUNC(callback_fn),
				external_data);
	}
	if ((lower>=SCALE_ID_400) && (upper<=SCALE_ID_400)) {
		button = define_radio_button_in_box_with_data (sbs->box, &sbs->group,
			SCALE_400, set_display_scale_from_label, sbs, FALSE) ;
		if (callback_fn && external_data)
			gtk_signal_connect ( GTK_OBJECT (button), 
				"toggled", 
				GTK_SIGNAL_FUNC(callback_fn),
				external_data);
	}
	if ((lower>=SCALE_ID_800) && (upper<=SCALE_ID_800)) {
		button = define_radio_button_in_box_with_data (sbs->box, &sbs->group, 
			SCALE_800, set_display_scale_from_label, sbs, FALSE) ;
		if (callback_fn && external_data)
			gtk_signal_connect ( GTK_OBJECT (button), 
				"toggled", 
				GTK_SIGNAL_FUNC(callback_fn),
				external_data);
	}
	return sbs;
}