Example #1
0
/*
 * Open a connection from a new client to the server.
 * Returns -1 on failure.
 */
int
GrOpen(void)
{
	GdPlatformInit();			/* platform-specific initialization*/

#if NONETWORK
	SERVER_LOCK();

	/* Client calls this routine once.  We init everything here*/
	if (connectcount <= 0) {
		if(GsInitialize() < 0) {
			SERVER_UNLOCK();
			return -1;
		}
		GsAcceptClientFd(999);
		curclient = root_client;
	}
	SERVER_UNLOCK();
#endif /* NONETWORK*/

#if NANOWM
	wm_init();	/* init built-in window manager*/
#endif
    return 1;
}
void wiimote_extension_controller() {
	/* LED DEBUG */
	//PORTD &= ~(1<<4); // S3 low
	//DDRD  |= (1<<4); // S3 output

	resetDrumData();
	wm_init((uchar*)drumDeviceID, (uchar*)&data, (uchar*)drumCalibrationData, sizeof(drumCalibrationData));
	wm_newaction((void*)&data);

	while(1) {
		readJoystickSwitch();
		readInputWiiDrum();
		wm_newaction((uchar*)&data);
	}
}
Example #3
0
int main() {
	wm_new(&wm, "MyWM");
	if(!wm_init(&wm)) {
		printf("Error.");
		return 0;
	}
	wm_get_screen_resolution(&wm, &screen_width, &screen_height);
	printf("Screen: %dx%d\n", screen_width, screen_height);
	wm_set_background_color(&wm, 0, 255, 255);
	
	/*wm_set_cursor(&wm, CURSOR_DEFAULT);*/
	wm_set_cursor(&wm, CURSOR_ARROW);

	wm.key_press = my_keypress;
	wm.key_release = my_keyrelease;
	wm.draw = my_draw;

	wm_event_loop(&wm);

	wm_close(&wm);
	return 0;
}
Example #4
0
int main(int argc, char *argv[]) {

  FILE *in = stdin;
  FILE *out = stdout;
  FILE *sig = NULL;

  char output_name[MAXPATHLEN] = "(stdout)";
  char input_name[MAXPATHLEN] = "(stdin)";
  char signature_name[MAXPATHLEN];

  int i, c, w;
  int row;

  int n;

  double alpha = 0.0;
  double beta = 0.0;

  int filter = 0;
  int method = -1;
  int level = 0;
  char filter_name[MAXPATHLEN] = "";

  int verbose = 0;

  gray **image;
  Image_tree dwts;

  gray maxval;
  int rows, cols, format;

  double *watermark;

  progname = argv[0];

  pgm_init(&argc, argv); wm_init();

  while ((c = getopt(argc, argv, "a:b:e:f:F:h?o:s:v:")) != EOF) {
    switch (c) {
      case 'a':
        alpha = atof(optarg);
        if (alpha <= 0.0) {
          fprintf(stderr, "%s: alpha factor %f out of range\n", progname, alpha);
          exit(1);
        }
        break;
      case 'b':
        beta = atof(optarg);
        if (beta <= 0.0) {
          fprintf(stderr, "%s: beta factor %f out of range\n", progname, beta);
          exit(1);
        }
        break;
      case 'e':
        method = atoi(optarg);
        if (method < 0) {
          fprintf(stderr, "%s: wavelet filtering method %d out of range\n", progname, method);
          exit(1);
        }
        break;
      case 'f':
        filter = atoi(optarg);
        if (filter <= 0) {
          fprintf(stderr, "%s: filter number %d out of range\n", progname, filter);
          exit(1);
        }
        break;
      case 'F':
        strcpy(filter_name, optarg);
        break;
      case 'h':
      case '?':
        usage();
        break;
      case 'o':
        if ((out = fopen(optarg, "wb")) == NULL) {
          fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
          exit(1);
        }
        strcpy(output_name, optarg);
        break;
      case 's':
        if ((sig = fopen(optarg, "r")) == NULL) {
          fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
          exit(1);
        }
        strcpy(signature_name, optarg);
        break;
      case 'v':
        verbose = atoi(optarg);
        if (verbose < 0) {
          fprintf(stderr, "%s: verbosity level %d out of range\n", progname, verbose);
          exit(1);
        }
        break;
    }
  }

  argc -= optind;
  argv += optind;

  if (argc > 1) {
    usage();
    exit(1);
  }

  if (argc == 1 && *argv[0] != '-') {
    if ((in = fopen(argv[0], "rb")) == NULL) {
      fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
      exit(1);
    }
    else
      strcpy(input_name, argv[0]);
  }
  
  if (sig) {
    char line[32];
    fgets(line, sizeof(line), sig);
    if (strspn(line, "WGSG") >= 4) {
      fscanf(sig, "%d\n", &n);
      if (alpha == 0.0)
        fscanf(sig, "%lf\n", &alpha);
      else
        fscanf(sig, "%*f\n");
      if (beta == 0.0)
        fscanf(sig, "%lf\n", &beta);
      else
        fscanf(sig, "%*f\n");
      if (method < 0)
        fscanf(sig, "%d\n", &method);
      else
        fscanf(sig, "%*d\n");
      if (filter == 0)
        fscanf(sig, "%d\n", &filter);
      else
        fscanf(sig, "%*d\n");
      if (!strcmp(filter_name, ""))
        fscanf(sig, "%[^\n\r]\n", filter_name);
      else
        fscanf(sig, "%*[^\n\r]\n");
    }
    else {
      fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
      exit(1);
    }
  }
  else {
    fprintf(stderr, "%s: signature file not specified, use -s file option\n", progname);
    exit(1);
  }

  watermark = malloc(n * sizeof(double));
  for (i = 0; i < n; i++) 
    fscanf(sig, "%lf\n", &watermark[i]);
  fclose(sig);

  pgm_readpgminit(in, &cols, &rows, &maxval, &format);

  image = pgm_allocarray(cols, rows);

  for (row = 0; row < rows; row++)
    pgm_readpgmrow(in, image[row], cols, maxval, format);

  fclose(in);

  // complete decomposition
  level = find_deepest_level(cols, rows) - 1;

  // wavelet transform
  init_dwt(cols, rows, filter_name, filter, level, method); 
#ifdef POLLEN_STUFF
#include "pollen_stuff.c"
#endif
#ifdef PARAM_STUFF
#include "param_stuff.c"
#endif

  dwts = fdwt(image);

  // build tree for subband selection, calculate subband thresholds
  init_subbands(dwts);
  set_subbands_type_beta(HORIZONTAL, beta);
  set_subbands_type_beta(VERTICAL, beta);
  calc_subbands_threshold();

  w = 0;
  while (w < n) {
    Subband_data s;

    // select subband with max. threshold
    s = select_subband();
    if (verbose > 1)
      fprintf(stderr, "%s: selected subband %s%d, T=%lf, beta=%lf\n", progname, subband_name(s->type), s->level, s->T, s->beta);
 
    // watermark significant coefficients and set them selected
    // check is entire signature has been embedded
    c = select_subband_coeff(s);
    do {
      double p;
      if (c < 0) 
        // no more significant coefficients in subband
        break;

      p = get_subband_coeff(s, c);
      if (p < s->Cmax) {
        if (verbose > 2)
          fprintf(stderr, "%s: embedding sig. coeff. #%d (= %lf)\n  into %s%d coeff. #%d\n", 
            progname, w, watermark[w], subband_name(s->type), s->level, c);

        p = p + alpha * s->beta * s->T * watermark[w];
        set_subband_coeff(s, c, p);
        w++;
      }
      mark_subband_coeff(s, c);

      // select next significant coefficient
      c = select_subband_coeff_from(s, c);
    } while (w < n);

    // update subband threshold
    s->T /= 2.0;

  }

  free_subbands();

  free(watermark);

  idwt(dwts, image);

  pgm_writepgminit(out, cols, rows, maxval, 0);

  for (row = 0; row < rows; row++)
    pgm_writepgmrow(out, image[row], cols, maxval, 0);

  fclose(out);

  pgm_freearray(image, rows);

  exit(0);
}
Example #5
0
/*
 *	prc_wm - process the raw workload management requests.
 */
static void prc_wm(struct wkmgmtbs *wbuf)
{
	static	int	nrec = 0;

	nrec++;
	if (db_flag > 8) {
		print_wm_rec(wbuf);
	}

	switch(wbuf->type) {

		/*
		 *	Informational record 
		 */
	case WM_INFO:
		if (db_flag > 8) {
			Ndebug("prc_wm(9): INFO.\n");
		}
		break;		/* ignore this record?? */

		/*
		 * 	A request has been received.
		 *	Add a request node to the end of the linked 
		 *	list and then initialize the node.
		 */
	case WM_RECV:
		wm_recv(wbuf);
		break;

		/*
		 *	A request has been initiated.
		 *	Add a new segment node to the end of this 
		 *	request's segment list.
		 */
	case WM_INIT:
		wm_init(wbuf);
		break;

		/*
		 *	A request has been terminated.
		 *	Add the termination code to the wkmgmtbs node.
		 */
	case WM_TERM:
		wm_term(wbuf);
		break;

		/*
		 *	A request's output has been spooled (netclient).
		 *	If necessary, add a request node to the end of
		 *	the linked list and then initialize the node.
		 */
	case WM_SPOOL:
		wm_spool(wbuf);
		break;

		/*
		 *	A recycled consolidated request has been found.
		 *	Save all data in consolidated structure.
		 */
	case WM_CON:
		wm_con(wbuf);
		break;

	default:
		acct_err(ACCT_CAUT,
		  _("An unknown record type (%4o) was found in the '%s' routine."),
		    wbuf->type, "prc_wm()");

	}		/* end of switch(type) */

	if (db_flag > 8) {
		dump_wm_tbl();
	}

	return;
}
Example #6
0
int main()
{
	#ifdef USE_SERPORT
	// start serial port
	sbi(uart_port, uart_rx_pin); // pull up
	serInit(38400);
	#endif

	// initialize ports

	// make power detect pin input
	cbi(power_detect_port, power_detect_pin);
	cbi(power_detect_ddr, power_detect_pin);

	sbi(LED_port, LED_pin);
	sbi(LED_ddr, LED_pin);

	#ifdef pull_up_res
	#ifdef trig_on_fall
	// setting port = pull ups on
	sbi(drum_port, green_pin);
	sbi(drum_port, red_pin);
	sbi(drum_port, yellow_pin);
	sbi(drum_port, blue_pin);
	sbi(drum_port, orange_pin);
	#endif
	#else
	cbi(drum_port, green_pin);
	cbi(drum_port, red_pin);
	cbi(drum_port, yellow_pin);
	cbi(drum_port, blue_pin);
	cbi(drum_port, orange_pin);
	#endif

	#ifdef trig_on_rise
	// clearing port = pull ups off
	cbi(drum_port, green_pin);
	cbi(drum_port, red_pin);
	cbi(drum_port, yellow_pin);
	cbi(drum_port, blue_pin);
	cbi(drum_port, orange_pin);
	#endif

	sbi(bass_port, bass1_pin);
	sbi(bass_port, bass2_pin);

	#ifdef GHWT
	sbi(plusminus_port, plus_pin);
	sbi(plusminus_port, minus_pin);
	sbi(stick_port, up_stick_pin);
	sbi(stick_port, down_stick_pin);
	sbi(stick_port, left_stick_pin);
	sbi(stick_port, right_stick_pin);
	#endif

	// all input
	cbi(drum_ddr, green_pin);
	cbi(drum_ddr, red_pin);
	cbi(drum_ddr, yellow_pin);
	cbi(drum_ddr, blue_pin);
	cbi(drum_ddr, orange_pin);
	cbi(bass_ddr, bass1_pin);
	cbi(bass_ddr, bass2_pin);

	#ifdef GHWT
	cbi(plusminus_ddr, plus_pin);
	cbi(plusminus_ddr, minus_pin);
	cbi(stick_ddr, up_stick_pin);
	cbi(stick_ddr, down_stick_pin);
	cbi(stick_ddr, left_stick_pin);
	cbi(stick_ddr, right_stick_pin);
	#endif

	// preinitialize comparison
	drum_in_preg = drum_in_reg;
	bass_in_preg = bass_in_reg;

	// initialize variables	
	wm_timer = 0;

	// initialize flags
	hit_f_l = 0xFF;
	hit_f_h = 0xFF;
	for(unsigned char i = 0; i < 8; i++)
	{
		hit_t[i] = 0;
		hit_s[i] = default_hit_softness;
	}

	unsigned char but_dat[6]; // struct containing button data
	but_dat[0] = 0b00011111;
	but_dat[1] = 0b00011111;
	but_dat[2] = 0b11111111;
	but_dat[3] = 0b11111111;
	but_dat[4] = 0b11111111;
	but_dat[5] = 0b11111111;

	// make wiimote think this is a drum
	wm_init(drum_id, but_dat, cal_data, wm_timer_inc);

	while(1)
	{
		// check if connected to wiimote
		if(bit_is_clear(power_detect_input, power_detect_pin))
		{
			// disconnected

			#ifdef USE_SERPORT
			// clear serial port buffer
			serFlush();
			#endif

			// handles reconnections
			wm_init(drum_id, but_dat, cal_data, wm_timer_inc);

			continue;
		}
		
		// check hardware
		check_for_hits();
		check_hit_f_llags();

		// apply hits
		but_dat[5] = hit_f_l;

		#ifdef USE_SERPORT
		unsigned char d; // serial port latest data
		unsigned char c; // number of char in serial port buffer
		d = serRx(&c); // check for serial command

		if(c > 0) // new command over serial port
		{
			but_dat[4] = 0xFF;
			but_dat[5] = 0xFF;

			if(bit_is_set(d, 0)) cbi(but_dat[5], green_bit);
			if(bit_is_set(d, 1)) cbi(but_dat[5], red_bit);
			if(bit_is_set(d, 2)) cbi(but_dat[5], yellow_bit);
			if(bit_is_set(d, 3)) cbi(but_dat[5], blue_bit);
			if(bit_is_set(d, 4)) cbi(but_dat[5], orange_bit);
			if(bit_is_set(d, 5)) cbi(but_dat[5], bass_bit);

			if(bit_is_set(d, 6)) cbi(but_dat[4], minus_bit);
			if(bit_is_set(d, 7)) cbi(but_dat[4], plus_bit);
		}
		#endif

		#ifdef GHWT

		but_dat[2] = 0xFF;
		but_dat[3] = 0xFF;

		if(but_dat[5] != 0xFF)
		{
			unsigned long t = wm_timer;
			
			// if any pads active, then send "softness"
			for(unsigned long i = hit_last + t; i < 16; i++)
			{
				unsigned char j = (unsigned char)(i % 8);
				if(bit_is_clear(but_dat[5], j))
				{
					// set pad
					but_dat[2] = pad_tbl[j];
					
					// set softness
					but_dat[3] = 0b00001100 | (hit_s[i] << 5);
					but_dat[4] &= 0b01111110;
					break;
				}
			}
		}

		// plus and minus buttons
		if(bit_is_clear(plusminus_in_reg, plus_pin)) cbi(but_dat[4], plus_bit);
		if(bit_is_clear(plusminus_in_reg, minus_pin)) cbi(but_dat[4], minus_bit);

		// simulate thumbstick with switches
		but_dat[0] = 0b00011111;
		but_dat[1] = 0b00011111;
		if(bit_is_clear(stick_in_reg, up_stick_pin)) but_dat[1] += thumbstick_speed;
		if(bit_is_clear(stick_in_reg, down_stick_pin)) but_dat[1] -= thumbstick_speed;
		if(bit_is_clear(stick_in_reg, left_stick_pin)) but_dat[0] -= thumbstick_speed;
		if(bit_is_clear(stick_in_reg, right_stick_pin)) but_dat[0] += thumbstick_speed;

		#endif

		wm_newaction(but_dat);
	}

	return 0;
}
Example #7
0
//--------------------------------------------------------
int main(int argc, char* argv[])
{
  FILE *in, *out;
  int **image_i;
  double *image_f = NULL;
  int N;
  int c;
  int coeff_start = 5000, wm_length = 10000, wm_key = 123;
  double wm_alpha = 0.2;

  pgm_init(&argc, argv); wm_init();

  while ((c = getopt(argc, argv, "a:s:l:k:")) != EOF) {
    switch (c) {
        case 'a':
        wm_alpha = atof(optarg);
        break;
        case 's':
        coeff_start = atoi(optarg);
        break;
        case 'l':
        wm_length = atoi(optarg);
        break;
        case 'k':
        wm_key = atoi(optarg);
        break;
    }
  }
  argc -= optind;
  argv += optind;

  in = stdin;
  out = stdout;

  open_image(in, &width, &height);
  image_i = imatrix(height, width);
  load_image(image_i, in, width, height);

  if (height == width)
    N = height;
  else {
    fprintf(stderr, "Cannot Proccess non-square images!\n");
    exit( -11);
  }

  initialize_constants();
  image_f = (double *)calloc(N * N, sizeof(double));
  if (image_f == NULL) {
    printf("Unable to allocate the float array\n");
    exit(1);
  }

  put_image_from_int_2_double(image_i, image_f, N);
  fct2d(image_f, N, N);
  add_watermark(image_f, N, coeff_start, wm_length, wm_key, wm_alpha);
  ifct2d(image_f, N, N);
  put_image_from_double_2_int(image_f, image_i, N);
  save_image(image_i, out, width, height);
  freematrix(image_i, height);
  free(image_f);
  fclose(in);
  fclose(out);

  exit(EXIT_SUCCESS);
}
Example #8
0
int main(int argc, char *argv[]) {
  FILE *in = stdin;
  FILE *out = stdout;
  FILE *sig = NULL;

  char output_name[MAXPATHLEN] = "(stdout)";
  char input_name[MAXPATHLEN] = "(stdin)";
  char signature_name[MAXPATHLEN];
  char *binstr;

  int verbose = 0;
  int c;
  int i;
  int l = 3;
  int n = 0;
  int s = 0;
  int q = 4;
  int e = 2;
  int f = 1;
  int blocksize = 64;
  char F[MAXPATHLEN] = "filter.dat";

  progname = argv[0];

  wm_init();

  while ((c = getopt(argc, argv, "b:e:f:F:h?l:n:o:q:s:S:v:")) != EOF) {
    switch (c) {
      case 'b':
        blocksize = atoi(optarg);
        if (blocksize < 0)
          fprintf(stderr, "%s: block size %d out of range\n", progname, blocksize);
        break;
      case 'e':
        e = atoi(optarg);
        if (e < 0) {
          fprintf(stderr, "%s: wavelet filtering method %d out of range\n", progname, e);
        }
        break;
      case 'f':
        f = atoi(optarg);
        if (f <= 0) {
          fprintf(stderr, "%s: filter number %d out of range\n", progname, f);
          exit(1);
        }
        break;
      case 'F':
        strcpy(F, optarg);
        break;
      case 'h':
      case '?':
        usage();
        break;
      case 'l':
        l = atoi(optarg);
        if (l < 1) {
          fprintf(stderr, "%s: embedding level out of range\n", progname);
          exit(1);
        }
        break;
      case 'n':
        n = atoi(optarg);
        if (n < 1 || n > 1000) {
          fprintf(stderr, "%s: watermark length %d out of range\n", progname, n);
          exit(1);
        }
        break;
      case 'o':
        if ((out = fopen(optarg, "wb")) == NULL) {
          fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
          exit(1);
        }
        strcpy(output_name, optarg);
        break;
      case 'q':
        q = atoi(optarg);
        if (q < 1) {
          fprintf(stderr, "%s: signature strength %d out of range\n", progname, q);
          exit(1);
        }
        break;
     case 's':
        if ((sig = fopen(optarg, "r")) == NULL) {
          fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
          exit(1);
        }
        strcpy(signature_name, optarg);
        break;
      case 'S':
        s = atoi(optarg);
        break;
      case 'v':
        verbose = atoi(optarg);
        if (verbose < 0) {
          fprintf(stderr, "%s: verbosity level %d out of range", progname, verbose);
          exit(1);
        }
        break;
    }
  }

  argc -= optind;
  argv += optind;

  if (argc > 1) {
    usage();
    exit(1);
  }

  if (argc == 1 && *argv[0] != '-') {
    if ((in = fopen(argv[0], "rb")) == NULL) {
      fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
      exit(1);
    }
    else
      strcpy(input_name, argv[0]);
  }
  
  if (sig) {
    char line[32];
    fgets(line, sizeof(line), sig);
    if (strspn(line, "KD2SG") >= 5) {
      if (n == 0)
        fscanf(sig, "%d\n", &n);
      else
        fscanf(sig, "%*d\n");
      if (q == 0)
        fscanf(sig, "%d\n", &q);
      else
        fscanf(sig, "%*d\n");
      if (blocksize == 0)
        fscanf(sig, "%d\n", &blocksize);
      else
        fscanf(sig, "%*d\n");
      if (e < 0)
        fscanf(sig, "%d\n", &e);
      else
        fscanf(sig, "%*d\n");
      if (f == 0)
        fscanf(sig, "%d\n", &f);
      else
        fscanf(sig, "%*d\n");
      if (!strcmp(F, ""))
        fscanf(sig, "%[^\n\r]\n", F);
      else
        fscanf(sig, "%*[^\n\r]\n");
      if (l == 0)
        fscanf(sig, "%d\n", &l);
      else
        fscanf(sig, "%*d\n");
    }
   else {
      fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
      exit(1);
    }
    fclose(sig);
  }

  if (s)
    srandom(s);
  else
    srandom(time(NULL) * getpid());

  if (n > 0) {
    n_signature = fread(signature, sizeof(char), i = NBITSTOBYTES(n), in);
    nbit_signature = NBYTESTOBITS(n_signature);
    if (n_signature < i) {
      fprintf(stderr, "%s: failed to read all %d signature bits from %s\n", progname, n, input_name);
      exit(1);
    }
  }
  else {
    if (fscanf(in, "%128[^\n\r]", signature) == EOF) {
      fprintf(stderr, "%s: failed to read signature bits from %s\n", progname, input_name);
      exit(1);
    }
    n_signature = strlen(signature);
    nbit_signature = NBYTESTOBITS(n_signature);
    fprintf(stderr, "%s: got %d signature bits\n", progname, nbit_signature);
  }

  fprintf(out, "KD2SG\n");
  fprintf(out, "%d\n", nbit_signature);
  fprintf(out, "%d\n", q);
  fprintf(out, "%d\n", blocksize);
  fprintf(out, "%d\n", e);
  fprintf(out, "%d\n", f);
  fprintf(out, "%s\n", F);
  fprintf(out, "%d\n", l);
  fprintf(out, "%ld\n", random());
  binstr = malloc((nbit_signature + 1) * sizeof(char));
  sig_to_binstr(binstr);
  fprintf(out, "%s\n", binstr);
  free(binstr);

  fclose(out);

  exit(0);
}