Пример #1
0
gint
DisplayStopThread(camera_t* cam)
{
  displaythread_info_t *info;
  chain_t *display_service;
  display_service=GetService(cam,SERVICE_DISPLAY);
  
  if (display_service!=NULL) { // if display service running... 
    info=(displaythread_info_t*)display_service->data;
    
    // send request for cancellation:
    pthread_mutex_lock(&info->mutex_cancel);
    info->cancel_req=1;
    pthread_mutex_unlock(&info->mutex_cancel);
    
    // when cancellation occured, join:
    pthread_join(display_service->thread, NULL);
    
    pthread_mutex_lock(&display_service->mutex_data);
    pthread_mutex_lock(&display_service->mutex_struct);
    RemoveChain(cam,display_service);
#ifdef HAVE_SDLLIB
    SDLQuit(display_service);
#endif
    
    pthread_mutex_unlock(&display_service->mutex_struct);
    pthread_mutex_unlock(&display_service->mutex_data);
    FreeChain(display_service);
  }
  return (1);
}
Пример #2
0
Файл: main.c Проект: ajxs/pbp
int main(int argc, char *argv[]) {
	if(!SDLinit()) {
		SDLQuit();
		exit(1);
	}

	if(argc < 2) {
		SDLerror("No filename argument supplied!\nPlease use the input filename as the first argument.\n");
		SDLQuit();
		exit(1);
	}

	if(!(srcSurface = IMG_Load(argv[1]), srcSurface)) {
		SDLerror("File could not be opened!\n");
		SDLQuit();
		exit(1);
	}

	mainSurface = SDL_CreateRGBSurface(0, srcSurface->w, srcSurface->h, 32, 0, 0, 0, 0);
	srcSurface = SDL_ConvertSurface(srcSurface, mainSurface->format, 0);

	srcSurface_rect.x = 10;
	srcSurface_rect.y = 10;

	if(srcSurface->w > 500) {	// image scaling to fit on screen.
		srcSurface_rect.w = 500;
		srcSurface_rect.h = (srcSurface->h * (500.0f / srcSurface->w));
		render = render_scaled;
	} else {
		srcSurface_rect.w = srcSurface->w;
		srcSurface_rect.h = srcSurface->h;
		render = render_normal;
	}

	mainSurface_rect.x = 20 + srcSurface_rect.w;
	mainSurface_rect.y = 10;

	mainSurface_rect.w = srcSurface_rect.w;
	mainSurface_rect.h = srcSurface_rect.h;

	SDL_BlitSurface(srcSurface,NULL,_screen,&srcSurface_rect);		// blit srcSurface once here since it never actually changes

	while(!_quit) {
		while(SDL_PollEvent(&_event)) {		// poll input
			switch(_event.type) {
				case SDL_QUIT:
					_quit = 1;
					break;
				case SDL_KEYDOWN:
					switch(_event.key.keysym.sym) {
						case SDLK_ESCAPE:
							_quit = 1;
							break;
						case SDLK_F12:
							sprintf(filenameBuffer, "%i_%i.bmp", (int)time(NULL),SDL_GetTicks());	// prints screenshot with name format <date>_<getTicks>.bmp
							SDL_SaveBMP(mainSurface,filenameBuffer);
							break;
						}
					break;
			}
		}

		for(_cycleIt = 0; _cycleIt < SQUARES_PER_CYCLE; _cycleIt++) {
			_changedState = 0;
			randomRect.w = SQUARE_MIN_SIZE+(rand()%SQUARE_MAX_SIZE);
			randomRect.h = SQUARE_MIN_SIZE+(rand()%SQUARE_MAX_SIZE);
			randomRect.x = rand()%(srcSurface->w - randomRect.w);
			randomRect.y = rand()%(srcSurface->h - randomRect.h);

			_r = rand()%255;
			_g = rand()%255;
			_b = rand()%255;

			testSum = 0;
			mainSum = 0;

			for(_rangeY = (randomRect.y + randomRect.h), ih = randomRect.y; ih < _rangeY; ih++) {
				for(_rangeX = (randomRect.x + randomRect.w), iw = randomRect.x; iw < _rangeX; iw++) {
					SDL_GetRGB(((Uint32*)srcSurface->pixels)[ih * srcSurface->w + iw],
						srcSurface->format,
						&sr,&sg,&sb);

					SDL_GetRGB(((Uint32*)mainSurface->pixels)[ih * srcSurface->w + iw],
						mainSurface->format,
						&mr,&mg,&mb);

					testSum += abs(sr - _r) + abs(sg - _g) + abs(sb - _b);
					mainSum += abs(sr - mr) + abs(sg - mg) + abs(sb - mb);
				}
			}

			if(testSum < mainSum) {
				SDL_FillRect(mainSurface, &randomRect, SDL_MapRGB(mainSurface->format, _r, _g, _b));
				_changedState = 1;
			}
		}

		if(_changedState) render();		// only render on update
	}

	SDLQuit();
	return 0;

};