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

📄 yuvscaler.c

📁 Motion JPEG编解码器源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
  if (reste >= frontiere)    ratio++;  if ((ratio < 0) || (ratio > 255))    mjpeg_error_exit1 ("Division error: %lu/%lu not in [0;255] range !!\n", p,		       q);  return ((uint8_t) ratio);}// *************************************************************************************// *************************************************************************************static y4m_ratio_tyuvscaler_calculate_output_sar (int out_w, int out_h,				int in_w, int in_h, y4m_ratio_t in_sar){// This function calculates the sample aspect ratio (SAR) for the output stream,//    given the input->output scale factors, and the input SAR.  if (Y4M_RATIO_EQL (in_sar, y4m_sar_UNKNOWN))    {      return y4m_sar_UNKNOWN;    }  else    {      y4m_ratio_t out_sar;      /*         out_SAR_w     in_SAR_w    input_W   output_H         ---------  =  -------- *  ------- * --------         out_SAR_h     in_SAR_h    input_H   output_W       */      out_sar.n = in_sar.n * in_w * out_h;      out_sar.d = in_sar.d * in_h * out_w;      y4m_ratio_reduce (&out_sar);      return out_sar;    }}// *************************************************************************************// *************************************************************************************intyuvscaler_y4m_read_frame (int fd, y4m_stream_info_t *si, 			y4m_frame_info_t * frameinfo,			unsigned long int buflen, uint8_t * buf){  // This function reads a frame from input stream. It does the same thing as the y4m_read_frame function (from yuv4mpeg.c)  // May be replaced directly by it in the near future  static int err = Y4M_OK;   if ((err = y4m_read_frame_header (fd, si, frameinfo)) == Y4M_OK)     {	if ((err = y4m_read (fd, buf, buflen)) != Y4M_OK)	  {	     mjpeg_info ("Couldn't read FRAME content: %s!",			 y4m_strerr (err));	     return (err);	  }     }   else     {	if (err != Y4M_ERR_EOF)	  mjpeg_info ("Couldn't read FRAME header: %s!", y4m_strerr (err));	else	  mjpeg_info ("End of stream!");	return (err);     }   return Y4M_OK;}// *************************************************************************************// *************************************************************************************// PREPROCESSING// *************************************************************************************intblackout (uint8_t * input_y, uint8_t * input_u, uint8_t * input_v){  // The blackout function makes input borders pixels become black  unsigned int line;  uint8_t *right;  // Y COMPONENT  for (line = 0; line < input_black_line_above; line++)    {      memset (input_y, blacky, input_useful_width);      input_y += input_width;    }  right = input_y + input_black_col_left + input_active_width;  for (line = 0; line < input_active_height; line++)    {      memset (input_y, blacky, input_black_col_left);      memset (right, blacky, input_black_col_right);      input_y += input_width;      right += input_width;    }  for (line = 0; line < input_black_line_under; line++)    {      memset (input_y, blacky, input_useful_width);      input_y += input_width;    }  // U COMPONENT  for (line = 0; line < (input_black_line_above >> 1); line++)    {      memset (input_u, blackuv, input_useful_width >> 1);      input_u += input_width >> 1;    }  right = input_u + ((input_black_col_left + input_active_width) >> 1);  for (line = 0; line < (input_active_height >> 1); line++)    {      memset (input_u, blackuv, input_black_col_left >> 1);      memset (right, blackuv, input_black_col_right >> 1);      input_u += input_width >> 1;      right += input_width >> 1;    }  for (line = 0; line < (input_black_line_under >> 1); line++)    {      memset (input_u, blackuv, input_useful_width >> 1);      input_u += input_width >> 1;    }  // V COMPONENT  for (line = 0; line < (input_black_line_above >> 1); line++)    {      memset (input_v, blackuv, input_useful_width >> 1);      input_v += input_width >> 1;    }  right = input_v + ((input_black_col_left + input_active_width) >> 1);  for (line = 0; line < (input_active_height >> 1); line++)    {      memset (input_v, blackuv, input_black_col_left >> 1);      memset (right, blackuv, input_black_col_right >> 1);      input_v += input_width >> 1;      right += input_width >> 1;    }  for (line = 0; line < (input_black_line_under >> 1); line++)    {      memset (input_v, blackuv, input_useful_width >> 1);      input_v += input_width >> 1;    }  return (0);}// *************************************************************************************// *************************************************************************************voidhandle_args_global (int argc, char *argv[]){  // This function takes care of the global variables   // initialisation that are independent of the input stream  // The main goal is to know whether input frames originate from file or stdin  int c;  while ((c = getopt (argc, argv, legal_opt_flags)) != -1)    {      switch (c)	{	case 'v':	  verbose = atoi (optarg);	  if (verbose < 0 || verbose > 2)	    {	      mjpeg_error_exit1 ("Verbose level must be [0..2]");	    }	  break;	case 'n':		// TV norm for SVCD/VCD output	  switch (*optarg)	    {	    case 'p':	    case 's':	      norm = 0;	      break;	    case 'n':	      norm = 1;	      break;	    default:	      mjpeg_error_exit1 ("Illegal norm letter specified: %c",				 *optarg);	    }	  break;	case 'h'://      case '?':	  yuvscaler_print_usage (argv);	  break;	default:	  break;	}    }  if (optind != argc)    yuvscaler_print_usage (argv);}// *************************************************************************************// *************************************************************************************voidhandle_args_dependent (int argc, char *argv[]){  // This function takes care of the global variables   // initialisation that may depend on the input stream  // It does also coherence check on input, useful_input, display, output_active sizes and ratio sizes  int c;  unsigned int ui1, ui2, ui3, ui4;  int output, input, mode;  // By default, display sizes is the same as input size  display_width = input_width;  display_height = input_height;  optind = 1;  while ((c = getopt (argc, argv, legal_opt_flags)) != -1)    {      switch (c)	{	  // **************               	  // OUTPUT KEYWORD	  // **************               	case 'O':	  output = 0;	  if (strcmp (optarg, VCD_KEYWORD) == 0)	    {	      output = 1;	      vcd = 1;	      svcd = 0;		// if user gives VCD, SVCD and DVD keywords, take last one only into account	      dvd = 0;	      display_width = 352;	      if (norm == 0)		{		  mjpeg_info		    ("VCD output format requested in PAL/SECAM norm");		  display_height = 288;		}	      else if (norm == 1)		{		  mjpeg_info ("VCD output format requested in NTSC norm");		  display_height = 240;		}	      else		mjpeg_error_exit1		  ("No norm specified, cannot determine VCD output size. Please use the -n option!");	    }	  if (strcmp (optarg, SVCD_KEYWORD) == 0)	    {	      output = 1;	      svcd = 1;	      vcd = 0;		// if user gives VCD, SVCD and DVD keywords, take last one only into account	      dvd = 0;	      display_width = 480;	      if (norm == 0)		{		  mjpeg_info		    ("SVCD output format requested in PAL/SECAM norm");		  display_height = 576;		}	      else if (norm == 1)		{		  mjpeg_info ("SVCD output format requested in NTSC norm");		  display_height = 480;		}	      else		mjpeg_error_exit1		  ("No norm specified, cannot determine SVCD output size. Please use the -n option!");	    }	  if (strcmp (optarg, DVD_KEYWORD) == 0)	    {	      output = 1;	      vcd = 0;	      svcd = 0;		// if user gives VCD, SVCD and DVD keywords, take last one only into account	      dvd = 1;	      display_width = 720;	      if (norm == 0)		{		  mjpeg_info		    ("DVD output format requested in PAL/SECAM norm");		  display_height = 576;		}	      else if (norm == 1)		{		  mjpeg_info ("DVD output format requested in NTSC norm");		  display_height = 480;		}	      else		mjpeg_error_exit1		  ("No norm specified, cannot determine DVD output size. Please use the -n option!");	    }	  if (strncmp (optarg, SIZE_KEYWORD, 5) == 0)	    {	      output = 1;	      if (sscanf (optarg, "SIZE_%ux%u", &ui1, &ui2) == 2)		{		  // Coherence check: sizes must be multiple of 2		  if ((ui1 % 2 == 0) && (ui2 % 2 == 0))		    {		      display_width = ui1;		      display_height = ui2;		      size_keyword = 1;		    }		  else		    mjpeg_error_exit1		      ("Unconsistent SIZE keyword, not multiple of 2: %s",		       optarg);		  // A second check will eventually be done when output interlacing is finally known		}	      else		mjpeg_error_exit1		  ("Wrong number of argument to SIZE keyword: %s", optarg);	    }	  // Theoritically, this should go into yuvcorrect, but I hesitate to do so	  if (strcmp (optarg, HIRESSTILL) == 0)	    {	      output = 1;	      interlaced = Y4M_ILACE_NONE;	      display_width = 704;	      if (norm == 0)		{		  mjpeg_info		    ("HIRESSTILL output format requested in PAL/SECAM norm");		  display_height = 576;		}	      else if (norm == 1)		{		  mjpeg_info ("HIRESSTILL output format requested in NTSC norm");		  display_height = 480;		}	      else		mjpeg_error_exit1		  ("No norm specified, cannot determine HIRESSTILL output size. Please use the -n option!");	    }	   if (strcmp (optarg, LOSVCDSTILL) == 0)	    {	      output = 1;	      interlaced = Y4M_ILACE_NONE;	      display_width = 480;	      if (norm == 0)		{		  mjpeg_info		    ("LOSVCDSTILL output format requested in PAL/SECAM norm");		  display_height = 576;		}	      else if (norm == 1)		{		  mjpeg_info ("LOSVCDSTILL output format requested in NTSC norm");		  display_height = 480;		}	      else		mjpeg_error_exit1		  ("No norm specified, cannot determine LOSVCDSTILL output size. Please use the -n option!");	    }	  if (strcmp (optarg, LOVCDSTILL) == 0)

⌨️ 快捷键说明

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