⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 thread_display.c

📁 Coriander is a GUI for controlling a Digital Camera (in the sense of the IIDC specs issued by the 1
💻 C
📖 第 1 页 / 共 2 页
字号:
    uyyvyy2uyvy(buffer->image,dest,buffer->width*buffer->height, overlay_byte_order);    break;  case COLOR_FORMAT7_YUV422:    yuyv2uyvy(buffer->image,dest,buffer->width*buffer->height, overlay_byte_order);    break;  case COLOR_FORMAT7_YUV444:    uyv2uyvy(buffer->image,dest,buffer->width*buffer->height, overlay_byte_order);    break;  case COLOR_FORMAT7_RGB8:    rgb2uyvy(buffer->image,dest,buffer->width*buffer->height, overlay_byte_order);    break;  case COLOR_FORMAT7_MONO16:    y162uyvy(buffer->image,dest,buffer->width*buffer->height,buffer->bpp, overlay_byte_order);    break;  case COLOR_FORMAT7_RGB16:    rgb482uyvy(buffer->image,dest,buffer->width*buffer->height, overlay_byte_order);    break;  }}voidSDLDisplayArea(chain_t *display_service){  displaythread_info_t *info=(displaythread_info_t*)display_service->data;  unsigned char *pimage;  int upper_left[2];  int lower_right[2];  int width;  int tmp;  register int i;  register int j;  pthread_mutex_lock(&watchthread_info.mutex_area);  if (watchthread_info.draw==1) {    upper_left[0]=watchthread_info.pos[0];    upper_left[1]=watchthread_info.pos[1];    lower_right[0]=watchthread_info.pos[0]+watchthread_info.size[0]-1;    lower_right[1]=watchthread_info.pos[1]+watchthread_info.size[1]-1;    width=display_service->current_buffer->width;    pthread_mutex_unlock(&watchthread_info.mutex_area);        if (lower_right[0]<upper_left[0]) {      tmp=lower_right[0];      lower_right[0]=upper_left[0];      upper_left[0]=tmp;    }    if (lower_right[1]<upper_left[1]) {      tmp=lower_right[1];      lower_right[1]=upper_left[1];      upper_left[1]=tmp;    }    for (i=upper_left[1];i<=lower_right[1];i++) {      pimage=info->sdloverlay->pixels[0]+i*info->sdloverlay->pitches[0];      for (j=upper_left[0];j<=lower_right[0];j++) {	pimage[j*2]=(unsigned char)(255-pimage[j*2]);      }    }  } else {    pthread_mutex_unlock(&watchthread_info.mutex_area);  }}voidSDLDisplayPattern(chain_t *display_service){  displaythread_info_t *info=(displaythread_info_t*)display_service->data;  unsigned char *pimage;  int sx = display_service->current_buffer->width;  int sy = display_service->current_buffer->height;  int y,u,v;  unsigned char block[4];  register int i;  register int j;  RGB2YUV(camera->prefs.overlay_color_r,camera->prefs.overlay_color_g,camera->prefs.overlay_color_b,y,u,v);  switch(display_service->camera->prefs.overlay_type) {  case OVERLAY_TYPE_REPLACE:    switch(preferences.overlay_byte_order) {    case OVERLAY_BYTE_ORDER_YUYV:      block[0]=y;      block[1]=u;      block[2]=y;      block[3]=v;      break;    case OVERLAY_BYTE_ORDER_UYVY:      block[0]=u;      block[1]=y;      block[2]=v;      block[3]=y;      break;    default:      fprintf(stderr,"Invalid overlay coding\n");      break;    }    break;  case OVERLAY_TYPE_RANDOM:    block[0]=random()/(RAND_MAX/255);    block[1]=random()/(RAND_MAX/255);    block[2]=random()/(RAND_MAX/255);    block[3]=random()/(RAND_MAX/255);    break;  case OVERLAY_TYPE_INVERT:    break;  default:    fprintf(stderr,"Invalid overlay coding\n");    break;  }  pthread_mutex_lock(&watchthread_info.mutex_area);  pimage=info->sdloverlay->pixels[0];  switch(display_service->camera->prefs.overlay_pattern) {  case OVERLAY_PATTERN_OFF:    break;  case OVERLAY_PATTERN_RECTANGLE:    if (display_service->camera->prefs.overlay_type==OVERLAY_TYPE_INVERT) {      j=(7*sy)/16;      j=j-j%4;      for (i=(7*sx)/16;i<=(9*sx)/16;i+=2) {	INVPIX(pimage, (j*sx+i)*2);	INVPIX(pimage, ((j-1)*sx+i)*2);      }      j=(9*sy)/16;      j=j-j%4;      for (i=(7*sx)/16;i<=(9*sx)/16;i+=2) {	INVPIX(pimage, (j*sx+i)*2);	INVPIX(pimage, ((j+1)*sx+i)*2);      }      j=(7*sx)/16;      j=j-j%4;      for (i=(7*sy)/16;i<=(9*sy)/16;i++) {	INVPIX(pimage, (i*sx+j)*2);      }      j=(9*sx)/16;      j=j-j%4;      for (i=(7*sy)/16;i<=(9*sy)/16;i++) {	INVPIX(pimage, (i*sx+j)*2);      }    }    else {      j=(7*sy)/16;      j=j-j%4;      for (i=(7*sx)/16;i<=(9*sx)/16;i+=2) {	REPLPIX(pimage, block, (j*sx+i)*2);	REPLPIX(pimage, block, ((j-1)*sx+i)*2);      }      j=(9*sy)/16;      j=j-j%4;      for (i=(7*sx)/16;i<=(9*sx)/16;i+=2) {	REPLPIX(pimage, block, (j*sx+i)*2);	REPLPIX(pimage, block, ((j+1)*sx+i)*2);      }      j=(7*sx)/16;      j=j-j%4;      for (i=(7*sy)/16;i<=(9*sy)/16;i++) {	REPLPIX(pimage, block, (i*sx+j)*2);      }      j=(9*sx)/16;      j=j-j%4;      for (i=(7*sy)/16;i<=(9*sy)/16;i++) {	REPLPIX(pimage, block, (i*sx+j)*2);      }    }    break;  case OVERLAY_PATTERN_SMALL_CROSS:    if (display_service->camera->prefs.overlay_type==OVERLAY_TYPE_INVERT) {      j=sy/2;      j=j-j%4;      for (i=(7*sx)/16;i<=(9*sx)/16;i+=2) {	INVPIX(pimage, (j*sx+i)*2);	INVPIX(pimage, ((j-1)*sx+i)*2);      }      j=sx/2;      j=j-j%4;      for (i=(7*sy)/16;i<=(9*sy)/16;i++) {	INVPIX(pimage, (i*sx+j)*2);      }    }    else {      j=sy/2;      j=j-j%4;      for (i=(7*sx)/16;i<=(9*sx)/16;i+=2) {	REPLPIX(pimage, block, (j*sx+i)*2);	REPLPIX(pimage, block, ((j-1)*sx+i)*2);      }      j=sx/2;      j=j-j%4;      for (i=(7*sy)/16;i<=(9*sy)/16;i++) {	REPLPIX(pimage, block, (i*sx+j)*2);      }    }    break;  case OVERLAY_PATTERN_LARGE_CROSS:    if (display_service->camera->prefs.overlay_type==OVERLAY_TYPE_INVERT) {      j=sy/2;      j=j-j%4;      for (i=0;i<sx;i+=2) {	INVPIX(pimage, (j*sx+i)*2);	INVPIX(pimage, ((j-1)*sx+i)*2);      }      j=sx/2;      j=j-j%4;      for (i=0;i<sy;i++) {	INVPIX(pimage, (i*sx+j)*2);      }    }    else {      j=sy/2;      j=j-j%4;      for (i=0;i<sx;i+=2) {	REPLPIX(pimage, block, (j*sx+i)*2);	REPLPIX(pimage, block, ((j-1)*sx+i)*2);      }      j=sx/2;      j=j-j%4;      for (i=0;i<sy;i++) {	REPLPIX(pimage, block, (i*sx+j)*2);      }    }    break;  case OVERLAY_PATTERN_GOLDEN_MEAN:    if (display_service->camera->prefs.overlay_type==OVERLAY_TYPE_INVERT) {      j=sy/3;      j=j-j%4;      for (i=0;i<sx;i+=2) {	INVPIX(pimage, (j*sx+i)*2);	INVPIX(pimage, ((j-1)*sx+i)*2);      }      j=2*sy/3;      j=j-j%4;      for (i=0;i<sx;i+=2) {	INVPIX(pimage, (j*sx+i)*2);	INVPIX(pimage, ((j-1)*sx+i)*2);      }      j=sx/3;      j=j-j%4;      for (i=0;i<sy;i++) {	INVPIX(pimage, (i*sx+j)*2);      }      j=2*sx/3;      j=j-j%4;      for (i=0;i<sy;i++) {	INVPIX(pimage, (i*sx+j)*2);      }    }    else {      j=sy/3;      j=j-j%4;      for (i=0;i<sx;i+=2) {	REPLPIX(pimage, block, (j*sx+i)*2);	REPLPIX(pimage, block, ((j-1)*sx+i)*2);      }      j=2*sy/3;      j=j-j%4;      for (i=0;i<sx;i+=2) {	REPLPIX(pimage, block, (j*sx+i)*2);	REPLPIX(pimage, block, ((j-1)*sx+i)*2);      }      j=sx/3;      j=j-j%4;      for (i=0;i<sy;i++) {	REPLPIX(pimage, block, (i*sx+j)*2);      }      j=2*sx/3;      j=j-j%4;      for (i=0;i<sy;i++) {	REPLPIX(pimage, block, (i*sx+j)*2);      }          }    break;  case OVERLAY_PATTERN_IMAGE:    break;  default:    fprintf(stderr,"Wrong overlay pattern ID\n");    break;  }  pthread_mutex_unlock(&watchthread_info.mutex_area);}voidSDLQuit(chain_t *display_service){  displaythread_info_t *info;  info=(displaythread_info_t*)display_service->data;#ifdef HAVE_SDLLIB  // if width==-1, SDL was never initialized so we do nothing  if (display_service->current_buffer->width!=-1) {    SDLEventStopThread(display_service);    SDL_FreeYUVOverlay(info->sdloverlay);    SDL_FreeSurface(info->sdlvideo);    SDL_QuitSubSystem(SDL_INIT_VIDEO);  }#endif}voidDisplayThreadCheckParams(chain_t *display_service){  displaythread_info_t *info;  int first_time=0;  int size_change;  int prev_image_size[2];  int prev_overlay_size[2];  info=(displaythread_info_t*)display_service->data;    // copy harmless parameters anyway:  display_service->local_param_copy.bpp=display_service->current_buffer->bpp;  display_service->local_param_copy.bayer_pattern=display_service->current_buffer->bayer_pattern;  if (display_service->current_buffer->width==-1)    fprintf(stderr,"Error: display size: %dx%d\n",	    display_service->current_buffer->width,	    display_service->current_buffer->height);  // if some parameters changed, we need to re-allocate the local buffers and restart the display  if ((display_service->current_buffer->width!=display_service->local_param_copy.width)||      (display_service->current_buffer->height!=display_service->local_param_copy.height)||      (display_service->current_buffer->bytes_per_frame!=display_service->local_param_copy.bytes_per_frame)||      (display_service->current_buffer->mode!=display_service->local_param_copy.mode)||      (display_service->current_buffer->format!=display_service->local_param_copy.format)||      // check F7 color mode change      ((display_service->current_buffer->format==FORMAT_SCALABLE_IMAGE_SIZE)&&       (display_service->current_buffer->format7_color_mode!=display_service->local_param_copy.format7_color_mode)       ) ||      // check bayer and stereo decoding      (display_service->current_buffer->stereo_decoding!=display_service->local_param_copy.stereo_decoding)||      (display_service->current_buffer->bayer!=display_service->local_param_copy.bayer)      ) {    first_time=((display_service->local_param_copy.width==-1)&&(display_service->current_buffer->width!=-1));    size_change=((display_service->current_buffer->width!=display_service->local_param_copy.width)||		 (display_service->current_buffer->height!=display_service->local_param_copy.height));        prev_image_size[0]=display_service->local_param_copy.width;    prev_image_size[1]=display_service->local_param_copy.height;    // copy all new parameters:    display_service->local_param_copy.width=display_service->current_buffer->width;    display_service->local_param_copy.height=display_service->current_buffer->height;    display_service->local_param_copy.bytes_per_frame=display_service->current_buffer->bytes_per_frame;    display_service->local_param_copy.mode=display_service->current_buffer->mode;    display_service->local_param_copy.format=display_service->current_buffer->format;    display_service->local_param_copy.format7_color_mode=display_service->current_buffer->format7_color_mode;    display_service->local_param_copy.stereo_decoding=display_service->current_buffer->stereo_decoding;    display_service->local_param_copy.bayer=display_service->current_buffer->bayer;    display_service->local_param_copy.buffer_image_bytes=display_service->current_buffer->buffer_image_bytes;        // DO SOMETHING    // if the width is not -1, that is if some image has already reached the thread and the size has changed    if ((display_service->local_param_copy.width!=-1)&&(size_change!=0)) {      if (first_time) {	SDLInit(display_service);      } else {	// note: in order to preserve the previous scaling and ratio, the previous parameters are used to	// determine the new size of the display area	prev_overlay_size[0]=info->sdlvideorect.w;	prev_overlay_size[1]=info->sdlvideorect.h;	watchthread_info.draw=0;	SDLResizeDisplay(display_service,			 display_service->current_buffer->width*prev_overlay_size[0]/prev_image_size[0],			 display_service->current_buffer->height*prev_overlay_size[1]/prev_image_size[1]);      }    }  }}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -