コード例 #1
0
ファイル: uvc_stream.c プロジェクト: akrapivniy/tinyvision
/* thread for clients that connected to this server */
void *client_thread(void *arg)
{
	int fd = *((int *) arg);
	fd_set fds;
	unsigned char *frame = (unsigned char *) calloc(1, (size_t) cd.videoIn->framesizeIn);
	int ok = 1, frame_size = 0;
	char buffer[1024] = {0};
	struct timeval to;
	answer_t answer = STREAM;

	if (arg != NULL) free(arg);
	else exit(1);

	/* set timeout to 5 seconds */
	to.tv_sec = 5;
	to.tv_usec = 0;
	FD_ZERO(&fds);
	FD_SET(fd, &fds);
	if (select(fd + 1, &fds, NULL, NULL, &to) <= 0) {
		close(fd);
		free(frame);
		return NULL;
	}
	while (ok >= 0 && !stop) {

		/* having a problem with windows (do we not always) browsers not updating the 
		   stream display, unless the browser cache is disabled - try and implement a delay
		   to allow movement to end before streem goes on - kind of works, but not well enough */

		if (cd.moved > 0) {
			SLEEP(1, 0);
			cd.moved = 0;
		}
		/* wait for fresh frames */
		pthread_cond_wait(&db_update, &db);

		/* read buffer */
		frame_size = g_size;
		memcpy(frame, g_buf, frame_size);

		pthread_mutex_unlock(&db);

		ok = print_picture(fd, frame, frame_size);
		if (ok < 0) break;
	}

	close(fd);
	free(frame);

	return NULL;
}
コード例 #2
0
ファイル: screen.c プロジェクト: dhanunjaya/termship
void title_screen()
{
  char *picture[] = {
    "                                     # #  ( )",
    "                                  ___#_#___|__",
    "                              _  |____________|  _",
    "                       _=====| | |            | | |==== _",
    "                 =====| |.---------------------------. | |====",
    "   <--------------------'   .  .  .  .  .  .  .  .   '--------------/",
    "     \\                                                             /",
    "      \\_______________________________________________WWS_________/",
    "  wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
    "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
    "   wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
    NULL
  };

  print_picture(stdscr, picture);

  /* int numsquiggles = 8; */
  /* int numreps = 2; */
  /* int framespeed = 60000; */
  /* do a little "animation" */
  /* for (int i=0; i<numreps; ++i) { */
  /*   /\* pushing out *\/ */
  /*   for (int j=0; j<numsquiggles; ++j) { */
  /*     char msg[100]; */
  /*     int s=0; */
  /*     for (int k=0; k<j+1; ++k) { */
  /*    msg[s++] = '~'; */
  /*     } */
  /*     msg[s++]=' '; */
  /*     msg[s++]='t'; */
  /*     msg[s++]='e'; */
  /*     msg[s++]='r'; */
  /*     msg[s++]='m'; */
  /*     msg[s++]='s'; */
  /*     msg[s++]='h'; */
  /*     msg[s++]='i'; */
  /*     msg[s++]='p'; */
  /*     msg[s++]=' '; */
  /*     for (int k=0; k<j+1; ++k) { */
  /*    msg[s++] = '~'; */
  /*     } */
  /*     msg[s++] = '\0'; */
  /*     show_message_box(msg); */
  /*     usleep(framespeed); */
  /*   } */
  /*   /\* pulling in *\/ */
  /*   for (int j=numsquiggles; j>0; --j) { */
  /*     char msg[100]; */
  /*     int s=0; */
  /*     for (int k=0; k<j+1; ++k) { */
  /*    msg[s++] = '~'; */
  /*     } */
  /*     msg[s++]=' '; */
  /*     msg[s++]='t'; */
  /*     msg[s++]='e'; */
  /*     msg[s++]='r'; */
  /*     msg[s++]='m'; */
  /*     msg[s++]='s'; */
  /*     msg[s++]='h'; */
  /*     msg[s++]='i'; */
  /*     msg[s++]='p'; */
  /*     msg[s++]=' '; */
  /*     for (int k=0; k<j+1; ++k) { */
  /*    msg[s++] = '~'; */
  /*     } */
  /*     msg[s++] = '\0'; */
  /*     show_message_box(msg); */
  /*     usleep(framespeed); */
  /*   } */
  /* } */



  /* Test an animation: */
  /* Animation *anim1 = create_animation("test1.txt"); */
  /* play_animation(anim1, true); */
  /* Animation *underwater_explosion = create_animation("underwater_explosion.txt"); */
  /* play_animation(underwater_explosion, true); */
  /* destroy_animation(underwater_explosion); */
  Animation *montage = create_animation("opener.txt");
  play_animation(montage, "Welcome to termship! (Press any key)", true, true);
  destroy_animation(montage);

}
コード例 #3
0
/* modify by Suttipong Kanakakorn Tue  08-29-1989  13:08:36 */
void PrintThree9pin( void ) {
	extern int linespace;
	/* FX    : 24 */
	/* LX,LQ : 20 */
	extern int nlqmode;
	extern int maxdot;
	extern char *bupper1;
	extern char *bupper2;
	extern char *bmiddle1;
	extern char *bmiddle2;
	extern char *bbelow1;
	extern char *bbelow2;
	char *print_pointer[6];
#ifdef WANT_TO_USE_GRAPH
	extern int pic_print;
	extern int grp_ready;
	extern int dot_per_line;
	extern char *print_buffer_pointer;
	char *temp_buffer;
#endif
	int i, j, spleft;
	print_pointer[0] = bupper1;
	print_pointer[1] = bupper2;
	print_pointer[2] = bmiddle1;
	print_pointer[3] = bmiddle2;
	print_pointer[4] = bbelow1;
	print_pointer[5] = bbelow2;
	if ( nlqmode == 1 ) {
		for ( i = 0; i < 6; i++ ) {
#ifdef WANT_TO_USE_GRAPH
			if ( pic_print == NO ) {
#endif
				PrintBuffer9pin( print_pointer[i] );
				if ( ( i % 2 ) == 0 ) {
					PrinterLineFeed216inch( 1 );
				} else {
					if ( i == 5 ) {							/* After finish line */
						if ( extbarprinting ) {
							spleft = linespace;
							while ( spleft > 24 ) {
								PrinterLineFeed216inch( 23 );
								PrintBuffer9pin( extbar1 );	/* More table line */
								PrinterLineFeed216inch( 1 );
								PrintBuffer9pin( extbar2 );
								spleft -= 24;
							}
							PrinterLineFeed216inch( spleft );
						} else {
							PrinterLineFeed216inch( linespace );
						}
					} else {
						PrinterLineFeed216inch( 23 );
					}
				}
#ifdef WANT_TO_USE_GRAPH
			} else { /* picprint == yes */
				switch ( dot_per_line ) {
				case 1:
					if ( i % 2 == 0 ) {
						PrintBuffer9pin( print_pointer[i] );
						PrinterLineFeed216inch( 1 );
					} else {
						/* print_picture( print_pointer[i] ); */
						PrintBuffer9pin( print_pointer[i] );
						PrinterLineFeed216inch( 23 );
					}
					break;
				case 2:
					print_picture( print_pointer[i] );
					PrintBuffer9pin( print_pointer[i] );
					if ( ( i % 2 ) == 0 ) {
						PrinterLineFeed216inch( 1 );
					} else {
						PrinterLineFeed216inch( 23 );
					}
					break;
				case 3:
					print_picture( print_pointer[i] );
					PrintBuffer9pin( print_pointer[i] );
					switch ( i % 2 ) {
					case 0:
						PrinterLineFeed216inch( 1 );
						break;
					case 1:
						PrinterLineFeed216inch( 1 );
						temp_buffer = ( char * ) calloc( 6600, sizeof( char ) );
						print_picture( temp_buffer );
						PrintBuffer9pin( temp_buffer );
						PrinterLineFeed216inch( 22 );
						free( temp_buffer );
						break;
					}
					break;
				}
			}
#endif
		}
	} else {
		for ( i = 1; i<6; i += 2 ) {
			for ( j = 0; j < maxdot; j++ ) {
				*( print_pointer[i] + j ) |= *( print_pointer[i - 1] + j );
			}
#ifdef WANT_TO_USE_GRAPH
			if ( ( pic_print == YES ) && ( dot_per_line == 1 ) ) {
				print_picture( print_pointer[i] );
			}
#endif
			PrintBuffer9pin( print_pointer[i] );
			if ( i == 5 ) {
				PrinterLineFeed216inch( linespace );
			} else {
				PrinterLineFeed216inch( 24 );
			}
		}
	}
}
コード例 #4
0
ファイル: main.c プロジェクト: Amberize/GSpot
int main(int argc, char **argv) {
	if (argc == 3) {
		int dimensions[2];

		printf("Using file: %s\n", argv[1]);
		get_picture_dimensions(argv[1], dimensions);

		printf("Dimensions: %dx%d\n", dimensions[0], dimensions[1]);

		int rows = dimensions[1];
		int columns = dimensions[0];

		int** picture;
		picture = malloc(rows * sizeof(int*));
		int i;
		for (i = 0; i < rows; i++)
			picture[i] = malloc(columns * sizeof(int));

		load_image(argv[1], picture, rows, columns);
		print_picture(picture, rows, columns);

		int j;

		int threads_count = atoi(argv[2]);
		pthread_t* thread_id = malloc(
				threads_count * threads_count * sizeof(pthread_t));

		int** pointX = malloc(threads_count * threads_count * sizeof(int*));
		int k;
		for (k = 0; k < threads_count * threads_count; k++)
			pointX[k] = malloc(sizeof(int));

		int** pointY = malloc(threads_count * threads_count * sizeof(int*));
		for (k = 0; k < threads_count * threads_count; k++)
			pointY[k] = malloc(sizeof(int));

		int* pointsSize = malloc(threads_count * threads_count * sizeof(int));
		for (k = 0; k < threads_count * threads_count; k++)
			pointsSize[k] = 1;

		int parts_x = rows / threads_count;
		int parts_y = columns / threads_count;

//		printf("partsx=%d, partsy=%d\n", rows, columns);

		struct thread_args *args = malloc(
				threads_count * threads_count * sizeof(struct thread_args));

		int id = 0;
		for (i = 0; i < threads_count; i++)
			for (j = 0; j < threads_count; j++) {
				int start_x = i * parts_x;
				int end_x = (i + 1) * parts_x;

				int start_y = j * parts_y;
				int end_y = (j + 1) * parts_y;

				args[id].picture = picture;
				args[id].start_x = start_x;
				args[id].end_x = end_x;
				args[id].start_y = start_y;
				args[id].end_y = end_y;
				args[id].rows = rows;
				args[id].columns = columns;
				args[id].pointX = pointX;
				args[id].pointY = pointY;
				args[id].pointsSize = &pointsSize[id];
				args[id].id = id;

				pthread_create(&thread_id[id], NULL, &check_picture,
						(void*) &args[id]);
				id++;
			}

		for (i = 0; i < threads_count * threads_count; i++)
			pthread_join(thread_id[i], NULL);

		int* mass_center = malloc(2 * sizeof(int));
		mass_center[0] = 0;
		mass_center[1] = 0;

		compute_mass(pointX, pointY, pointsSize, threads_count, mass_center);

		printf("Mass center: %dx%d\n", mass_center[0], mass_center[1]);

		print_picture_with_mass(picture, rows, columns, mass_center[0],
				mass_center[1]);

		free(mass_center);

		for (i = 0; i < rows - 1; i++)
			free(picture[i]);
		free(picture);

		for (i = 0; i < threads_count * threads_count; i++)
			free(pointX[i]);
		free(pointX);

		for (i = 0; i < threads_count * threads_count; i++)
			free(pointY[i]);
		free(pointY);
	} else
		printf("No input file\n");

	return 0;
}