Beispiel #1
0
/* DDS3.2.12: Draw Group Entry */
void draw_group_entry(struct cursor cursor, enum HlFlag highlight,
		      bool interrupt)
{
	struct image_set set;
	struct image *image, *highlighted;
	struct coordinates coordinates;
	unsigned int pref_size;
	struct audio_set audio = { NULL, { NULL, NULL, NULL } };

	/* We play audio only if highlighted */
	if (highlight)
		audio = get_audio_at_cursor(&cursor);

	set = get_img_at_cursor(&cursor);
	
	coordinates = get_cursor_coordinates(cursor);

	/* set contains either a group heading image or a candidate 
	   and pref_box image */
	if (set.group) {
		image = set.group;
		if (highlight) {
			highlighted = highlight_image(image);
			paste_image(coordinates.x, coordinates.y, highlighted);
			play_audio_loop(interrupt, audio.group_audio);
		}
		else {
			paste_image(coordinates.x, coordinates.y, image);
		}
	}
	else {
		/* set contains candidate and pref_box images */
		image = set.candidate;
		pref_size = image_width(set.prefnumber);
		paste_image(coordinates.x, coordinates.y, set.prefnumber);
		if (highlight) {
			highlighted = highlight_image(image);
			paste_image(coordinates.x + pref_size, coordinates.y, 
				    highlighted);

			/* Audio for this candidate */
			play_multiaudio_loop(interrupt, 3,
					     audio.candidate_audio);
		} else {
			paste_image(coordinates.x + pref_size, coordinates.y, 
				    image);
		}
				   
	}
}
/* DDS3.14: Handle END PAPER Screen */
static bool handle_end_paper_screen(void)
{
	struct image *message;
	enum deo_keystroke key;
	struct cursor cursor, default_cursor;
	
	cursor = get_cursor_position();
	default_cursor.group_index = DEFAULT_DEO_CURSOR_X;
	default_cursor.screen_candidate_index = DEFAULT_DEO_CURSOR_Y;
	
	/*clear_screen();*/
	message = get_finish_prompt();
	paste_image(0,0,message);

	while (1) {
		key = interpret_deo_keystroke();
		/* DEO is sure */
		if (key == DEO_KEYSTROKE_DELETE) {
			clear_screen();
			reset_deo_cursor();
			return true;
		}
		/* DEO changes its mind */
		else if (key == DEO_KEYSTROKE_DOWN) {
			/*clear_screen();*/
			dsp_mn_vt_scn();
			draw_group_entry(default_cursor, NO, NO);
			draw_group_entry(cursor, YES, NO);
			return false;
		}
	}
}
Beispiel #3
0
/* Draw a blank groun entry */
void draw_blank_entry(unsigned int group_index,
		      int screen_index)
{
	struct image *blank;
	struct cursor cursor;
	struct coordinates coords;

	/* Create a dummy cursor for this position */
	cursor.group_index = group_index;
	cursor.screen_candidate_index = screen_index;
	/* Convert to screen coordinates */
	coords = get_cursor_coordinates(cursor);

	/* Get the blank image for this electorate, and paste it */
	blank = get_blank_image(get_voter_electorate()->code);
	paste_image(coords.x, coords.y, blank);
}
Beispiel #4
0
/* DDS????: Display Error */
void display_error(enum error err)
{
	unsigned int language;
	struct image *bgimage;

	language = get_language();

fprintf(stderr, "Fatal Error number %d\n", err);
exit(-1);
	/* Draw background if we can, otherwise clear screen */
	bgimage = get_message_mayfail(language, MSG_BACKGROUND);
	if (bgimage) paste_image(0, 0, bgimage);
	else clear_screen();

	/* Use electorate "1" here for the numbers. */
	draw_error(get_message_mayfail(language, MSG_ERROR),
		   get_preference_image_mayfail(1, (unsigned int)err),
		   err);

}
Beispiel #5
0
/* DDS????: Display Error */
void display_error(enum error err)
{
	unsigned int language;
	struct image *bgimage;

	language = get_language();

	/* Draw background if we can, otherwise clear screen */
	bgimage = get_message_mayfail(language, MSG_BACKGROUND);
	if (bgimage) paste_image(0, 0, bgimage);
	else clear_screen();

	/* Message to tell them */
	play_audio(true, get_audio("error.raw"));

	/* Use electorate "1" here for the numbers. */
	draw_error(get_message_mayfail(language, MSG_ERROR),
		   get_preference_image_mayfail(1, (unsigned int)err),
		   err);

	/* Loop until reset. */
	wait_for_reset();
}
Beispiel #6
0
int main( int argc, char** argv ) {
  int ikey=0;
  char key;
  IplImage *imCapt,*imDisp,*imDisp2;
  static int tb1_val,tb2_val;  /* Trackbar parameters */
  timewin *tw;
  buffer *bf_img;
  bbuffer *bf_blobs;
  int width,height;

  if(kb_lowresfl) {
    width=320;
    height=240;
  } else {
    width=640;
    height=480;
  }

  /* Set window title to a list of control keys */
  const char *window1 = "Controls: (n)eighbours, (d)istance, (b)lur type, (h)igh-res, (c)olourspace, (r)eset, (ESC) exit";
  const char *trackbar1 = "margin";
  const char *trackbar2 = "timesteps";
  
  int fno;
 
  cvInitSystem( argc,argv );
  
  /* Get an OpenCV camera handle */
  cam = cvCreateCameraCapture(0);

  /* Set size of image (appears to be ignored in Linux) */
  cvSetCaptureProperty(cam, CV_CAP_PROP_FRAME_WIDTH, width);
  cvSetCaptureProperty(cam, CV_CAP_PROP_FRAME_HEIGHT, height);

  /* Create a window with slider */
  cvNamedWindow(window1, CV_WINDOW_AUTOSIZE);
  cvSetMouseCallback(window1,callback_mouse, NULL );
  tb_margin = DEF_MARGIN; /* Default */
  tb1_val=tb_margin/TB1_SCALE*TB1_MAX;
  cvCreateTrackbar(trackbar1,window1,&tb1_val,TB1_MAX,callback_trackbar1);
  tb2_val = tb_timesteps = DEF_TIMESTEPS; /* Default */
  cvCreateTrackbar(trackbar2,window1,&tb2_val,TB2_MAX,callback_trackbar2);
  cvMoveWindow(window1, 100, 45);

  /* Allocate image buffers */
  if(kb_lowresfl)
    imDisp2 =  cvCreateImage( cvSize(width*4,height*2), IPL_DEPTH_8U, 3);
  else
    imDisp2 =  cvCreateImage( cvSize(width*2,height), IPL_DEPTH_8U, 3);
  imDisp =  cvCreateImage( cvSize(width*2,height), IPL_DEPTH_8U, 3);
  bf_img = buffer_new(height,width,3);
  bf_blobs = bbuffer_new(height,width,3);

  tw=timewin_new(DEF_TIMESIZE);
  fno=0;

  key=(char)cvWaitKey(500);
  
  while ( key !=27 ) {
    imCapt = cvQueryFrame(cam);
    buffer_iplcopy(bf_img,imCapt,1);
    /* Detect blobs */
    detect_and_render_blobs(bf_img,bf_blobs);

    /* Display result */
    flip_image(imCapt,imDisp);
    paste_image(imDisp,bf_blobs,width);
    
    if(kb_lowresfl) {
      upsample_image(imDisp,imDisp2);
      cvShowImage(window1, imDisp2);
    } else {
      cvShowImage(window1, imDisp);
    }

    ikey=cvWaitKey(5); /* Needed for highgui event processing */
    if(ikey>0) {
      key=(char)ikey;

      if(key == 'n') {
	kb_n8flag=1-kb_n8flag;
	printf("n8flag=%d\n",kb_n8flag);
      }
      
      if(key == 'd') {
	kb_normfl=1-kb_normfl;
	printf("normfl=%d\n",kb_normfl);
      }
      
      if(key == 'b') {
	kb_blurfl=1-kb_blurfl;
	printf("blurfl=%d\n",kb_blurfl);
      }
      if(key =='c') {
	kb_cspace=1-kb_cspace; /* Toggle colourspace */
	printf("cspace=%d\n",kb_cspace);
      }
      
      if(key == 'r') {
	tb_margin=DEF_MARGIN; /* Reset to default */
	tb1_val=tb_margin/TB1_SCALE*TB1_MAX;
	cvSetTrackbarPos(trackbar1,window1,tb1_val);
	tb2_val=tb_timesteps=DEF_TIMESTEPS;  /* Reset to default */
	cvSetTrackbarPos(trackbar2,window1,tb2_val);
	kb_n8flag=DEF_N8FLAG;
	kb_normfl=DEF_NORMFL;
	kb_blurfl=DEF_BLURFL;
	printf("timesteps =%d\n",tb_timesteps);
	printf("min_margin=%g\n",tb_margin);
	printf("n8flag=%d\n",kb_n8flag);
	printf("normfl=%d\n",kb_normfl);
	printf("blurfl=%d\n",kb_blurfl);
	cvWaitKey(1); 
	/* printf("tb1:%d\n",cvGetTrackbarPos(trackbar1,window1)); */
	/* printf("tb2:%d\n",cvGetTrackbarPos(trackbar2,window1)); */
      }
      if(key == 'h') {
	kb_lowresfl=1-kb_lowresfl; /* Toggle resolution */
	if(kb_lowresfl) {
	  width=320;
	  height=240;
	} else {
	  width=640;
	  height=480;
	}
	cvReleaseCapture(&cam);
	cam = cvCreateCameraCapture(0);
	/* Set size of image */
	cvSetCaptureProperty(cam, CV_CAP_PROP_FRAME_WIDTH, width);
	cvSetCaptureProperty(cam, CV_CAP_PROP_FRAME_HEIGHT, height);
	/* Free image buffers */
	cvReleaseImage( &imDisp );
	buffer_free(bf_img);
	bbuffer_free(bf_blobs);
	/* Allocate image buffers */
	imDisp =  cvCreateImage( cvSize(width*2,height), IPL_DEPTH_8U, 3);
	bf_img = buffer_new(height,width,3);
	bf_blobs = bbuffer_new(height,width,3);
      }
    }

    timewin_addtime(tw);
    fno++;
    if((fno%DEF_TIMESIZE)==0) printf("Frame rate %g Hz\n",timewin_rate(tw));
  }
  /* Clean up */
  timewin_free(tw);
  buffer_free(bf_img);
  bbuffer_free(bf_blobs);
  cvDestroyAllWindows();
  cvReleaseCapture(&cam);
  return 0;
}
Beispiel #7
0
/* DDS3.12: Display DEO Ballot Screen */
void dsp_mn_vt_scn(void)
{
	const struct electorate *electorate;
	struct ballot_contents *bc;
	unsigned int group_index;
	unsigned int physical_column;
	unsigned int grid_block;
	int cand;
	struct cursor cursor_position;
	struct image *ballot_h_image;

	/* Number of grid blocks in each row. */
	unsigned int groups_across;

	/* grid_block_mod_groups_across = (grid_block % groups_across) */
	unsigned int grid_block_mod_groups_across;
	/* The first grid block of the next group (or the end
	   of the ballot, if there is no next group). */
	unsigned int next_grid_block;

	electorate = get_voter_electorate();
	bc = get_ballot_contents();
	ballot_h_image = get_bh_image(get_language(), electorate);
	paste_image(0,0,ballot_h_image);

	/* SIPL 2011-07-11 Need this to fill in
	   map_physical_column_to_grid_block. */
	groups_across = get_grid_blocks_across(electorate);

	/* SIPL 2011-06-29 Now loop over physical columns and grid blocks
	   as well as groups. Fill in map_physical_column_to_grid_block
	   during this process. */
	group_index = 0;
	physical_column = 0;
	grid_block = 0;
	while (group_index < bc->num_groups) {
		/* Need to fill in all the map entries for the group
		   before calling draw_group_entry. */
		bc->map_physical_column_to_grid_block[physical_column] =
			grid_block;
		/* For the rest in the group, draw blank entry */
		/* All physical columns but the last for this group. */
		while (physical_column <
		       bc->map_group_to_physical_column[group_index+1] - 1) {
			for (cand = bc->num_candidates_in_physical_column[
				physical_column];
			     cand < electorate->num_seats; cand++)
				draw_blank_entry_no_divider_grid_block(
					grid_block, cand);
			physical_column++;
			grid_block++;
			bc->map_physical_column_to_grid_block[
					physical_column] = grid_block;
		}
		/* The last physical column for this group. */
		for (cand = bc->num_candidates_in_physical_column[
				physical_column];
		     cand < electorate->num_seats; cand++)
			draw_blank_entry_grid_block(grid_block, cand);

		/* Now all of the entries in
		   map_physical_column_to_grid_block required for
		   this group have been filled in, so the candidates
		   can be drawn. */
		/* candidate -1 corresponds to group heading */
		for (cand = -1;
		     cand < (int)bc->num_candidates[group_index];
		     cand++) {
			cursor_position.group_index = group_index;
			cursor_position.screen_candidate_index = cand;
			draw_group_entry(cursor_position,NO,false);
		}

		group_index++;
		physical_column++;
		grid_block++;

		/* Is there a next group, and, if so, it there room for
		   the next group?
		   If this is the last group, set the map value to
		   the grid block after the end of the entire screen.
		   Otherwise, set the map value to the grid block
		   at the beginning of the next row.
		   Group group_index occupies
		   (bc->map_group_to_physical_column[group_index+1] -
		   bc->map_group_to_physical_column[group_index])
		   physical columns. */
		grid_block_mod_groups_across = grid_block % groups_across;
		if (group_index < bc->num_groups) {
			if (grid_block_mod_groups_across +
			    (bc->map_group_to_physical_column[group_index+1] -
			     bc->map_group_to_physical_column[group_index])
			    > groups_across)
				/* No room.  Move to the next row. */
				next_grid_block = grid_block + (groups_across -
					grid_block_mod_groups_across);
			else
				/* There is room. */
				next_grid_block = grid_block;
		} else {
			/* This is the last group. */
			next_grid_block = grid_blocks_possible();
		}
		/* Now fill in the map entry. */
		bc->map_physical_column_to_grid_block[physical_column] =
			next_grid_block;

		/* Fill in any blank grid blocks at the end of the row,
		   or the ballot. */
		while (grid_block < next_grid_block) {
			draw_blank_group_entry_grid_block(grid_block);
			for (cand = 0; cand < (int)electorate->num_seats;
			     cand++)
				draw_blank_entry_grid_block(grid_block,
							    cand);
			grid_block++;
		}
	}
}