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

📄 spudec.c

📁 自己移植的linux下的流媒体播放器原代码,支持mms协议,支持ftp和http协议.
💻 C
📖 第 1 页 / 共 3 页
字号:
	unsigned int scaley = 0x100 * dys / spu->orig_frame_height;	spu->scaled_start_col = spu->start_col * scalex / 0x100;	spu->scaled_start_row = spu->start_row * scaley / 0x100;	spu->scaled_width = spu->width * scalex / 0x100;	spu->scaled_height = spu->height * scaley / 0x100;	/* Kludge: draw_alpha needs width multiple of 8 */	spu->scaled_stride = (spu->scaled_width + 7) & ~7;	if (spu->scaled_image_size < spu->scaled_stride * spu->scaled_height) {	  if (spu->scaled_image) {	    free(spu->scaled_image);	    spu->scaled_image_size = 0;	  }	  spu->scaled_image = malloc(2 * spu->scaled_stride * spu->scaled_height);	  if (spu->scaled_image) {	    spu->scaled_image_size = spu->scaled_stride * spu->scaled_height;	    spu->scaled_aimage = spu->scaled_image + spu->scaled_image_size;	  }	}	if (spu->scaled_image) {	  unsigned int x, y;	  if (spu->scaled_width <= 1 || spu->scaled_height <= 1) {	    goto nothing_to_do;	  }	  switch(spu_aamode&15) {	  case 4:	  sws_spu_image(spu->scaled_image, spu->scaled_aimage,		  spu->scaled_width, spu->scaled_height, spu->scaled_stride,		  spu->image, spu->aimage, spu->width, spu->height, spu->stride);	  break;	  case 3:	  table_x = calloc(spu->scaled_width, sizeof(scale_pixel));	  table_y = calloc(spu->scaled_height, sizeof(scale_pixel));	  if (!table_x || !table_y) {	    mp_msg(MSGT_SPUDEC, MSGL_FATAL, "Fatal: spudec_draw_scaled: calloc failed\n");	  }	  scale_table(0, 0, spu->width - 1, spu->scaled_width - 1, table_x);	  scale_table(0, 0, spu->height - 1, spu->scaled_height - 1, table_y);	  for (y = 0; y < spu->scaled_height; y++)	    for (x = 0; x < spu->scaled_width; x++)	      scale_image(x, y, table_x, table_y, spu);	  free(table_x);	  free(table_y);	  break;	  case 0:	  /* no antialiasing */	  for (y = 0; y < spu->scaled_height; ++y) {	    int unscaled_y = y * 0x100 / scaley;	    int strides = spu->stride * unscaled_y;	    int scaled_strides = spu->scaled_stride * y;	    for (x = 0; x < spu->scaled_width; ++x) {	      int unscaled_x = x * 0x100 / scalex;	      spu->scaled_image[scaled_strides + x] = spu->image[strides + unscaled_x];	      spu->scaled_aimage[scaled_strides + x] = spu->aimage[strides + unscaled_x];	    }	  }	  break;	  case 1:	  {	    /* Intermediate antialiasing. */	    for (y = 0; y < spu->scaled_height; ++y) {	      const unsigned int unscaled_top = y * spu->orig_frame_height / dys;	      unsigned int unscaled_bottom = (y + 1) * spu->orig_frame_height / dys;	      if (unscaled_bottom >= spu->height)		unscaled_bottom = spu->height - 1;	      for (x = 0; x < spu->scaled_width; ++x) {		const unsigned int unscaled_left = x * spu->orig_frame_width / dxs;		unsigned int unscaled_right = (x + 1) * spu->orig_frame_width / dxs;		unsigned int color = 0;		unsigned int alpha = 0;		unsigned int walkx, walky;		unsigned int base, tmp;		if (unscaled_right >= spu->width)		  unscaled_right = spu->width - 1;		for (walky = unscaled_top; walky <= unscaled_bottom; ++walky)		  for (walkx = unscaled_left; walkx <= unscaled_right; ++walkx) {		    base = walky * spu->stride + walkx;		    tmp = canon_alpha(spu->aimage[base]);		    alpha += tmp;		    color += tmp * spu->image[base];		  }		base = y * spu->scaled_stride + x;		spu->scaled_image[base] = alpha ? color / alpha : 0;		spu->scaled_aimage[base] =		  alpha * (1 + unscaled_bottom - unscaled_top) * (1 + unscaled_right - unscaled_left);		/* spu->scaled_aimage[base] =		  alpha * dxs * dys / spu->orig_frame_width / spu->orig_frame_height; */		if (spu->scaled_aimage[base]) {		  spu->scaled_aimage[base] = 256 - spu->scaled_aimage[base];		  if (spu->scaled_aimage[base] + spu->scaled_image[base] > 255)		    spu->scaled_image[base] = 256 - spu->scaled_aimage[base];		}	      }	    }	  }	  break;	  case 2:	  {	    /* Best antialiasing.  Very slow. */	    /* Any pixel (x, y) represents pixels from the original	       rectangular region comprised between the columns	       unscaled_y and unscaled_y + 0x100 / scaley and the rows	       unscaled_x and unscaled_x + 0x100 / scalex	       The original rectangular region that the scaled pixel	       represents is cut in 9 rectangular areas like this:	       	       +---+-----------------+---+	       | 1 |        2        | 3 |	       +---+-----------------+---+	       |   |                 |   |	       | 4 |        5        | 6 |	       |   |                 |   |	       +---+-----------------+---+	       | 7 |        8        | 9 |	       +---+-----------------+---+	       The width of the left column is at most one pixel and	       it is never null and its right column is at a pixel	       boundary.  The height of the top row is at most one	       pixel it is never null and its bottom row is at a	       pixel boundary. The width and height of region 5 are	       integral values.  The width of the right column is	       what remains and is less than one pixel.  The height	       of the bottom row is what remains and is less than	       one pixel.	       The row above 1, 2, 3 is unscaled_y.  The row between	       1, 2, 3 and 4, 5, 6 is top_low_row.  The row between 4,	       5, 6 and 7, 8, 9 is (unsigned int)unscaled_y_bottom.	       The row beneath 7, 8, 9 is unscaled_y_bottom.	       The column left of 1, 4, 7 is unscaled_x.  The column	       between 1, 4, 7 and 2, 5, 8 is left_right_column.  The	       column between 2, 5, 8 and 3, 6, 9 is (unsigned	       int)unscaled_x_right.  The column right of 3, 6, 9 is	       unscaled_x_right. */	    const double inv_scalex = (double) 0x100 / scalex;	    const double inv_scaley = (double) 0x100 / scaley;	    for (y = 0; y < spu->scaled_height; ++y) {	      const double unscaled_y = y * inv_scaley;	      const double unscaled_y_bottom = unscaled_y + inv_scaley;	      const unsigned int top_low_row = MIN(unscaled_y_bottom, unscaled_y + 1.0);	      const double top = top_low_row - unscaled_y;	      const unsigned int height = unscaled_y_bottom > top_low_row		? (unsigned int) unscaled_y_bottom - top_low_row		: 0;	      const double bottom = unscaled_y_bottom > top_low_row		? unscaled_y_bottom - floor(unscaled_y_bottom)		: 0.0;	      for (x = 0; x < spu->scaled_width; ++x) {		const double unscaled_x = x * inv_scalex;		const double unscaled_x_right = unscaled_x + inv_scalex;		const unsigned int left_right_column = MIN(unscaled_x_right, unscaled_x + 1.0);		const double left = left_right_column - unscaled_x;		const unsigned int width = unscaled_x_right > left_right_column		  ? (unsigned int) unscaled_x_right - left_right_column		  : 0;		const double right = unscaled_x_right > left_right_column		  ? unscaled_x_right - floor(unscaled_x_right)		  : 0.0;		double color = 0.0;		double alpha = 0.0;		double tmp;		unsigned int base;		/* Now use these informations to compute a good alpha,                   and lightness.  The sum is on each of the 9                   region's surface and alpha and lightness.		  transformed alpha = sum(surface * alpha) / sum(surface)		  transformed color = sum(surface * alpha * color) / sum(surface * alpha)		*/		/* 1: top left part */		base = spu->stride * (unsigned int) unscaled_y;		tmp = left * top * canon_alpha(spu->aimage[base + (unsigned int) unscaled_x]);		alpha += tmp;		color += tmp * spu->image[base + (unsigned int) unscaled_x];		/* 2: top center part */		if (width > 0) {		  unsigned int walkx;		  for (walkx = left_right_column; walkx < (unsigned int) unscaled_x_right; ++walkx) {		    base = spu->stride * (unsigned int) unscaled_y + walkx;		    tmp = /* 1.0 * */ top * canon_alpha(spu->aimage[base]);		    alpha += tmp;		    color += tmp * spu->image[base];		  }		}		/* 3: top right part */		if (right > 0.0) {		  base = spu->stride * (unsigned int) unscaled_y + (unsigned int) unscaled_x_right;		  tmp = right * top * canon_alpha(spu->aimage[base]);		  alpha += tmp;		  color += tmp * spu->image[base];		}		/* 4: center left part */		if (height > 0) {		  unsigned int walky;		  for (walky = top_low_row; walky < (unsigned int) unscaled_y_bottom; ++walky) {		    base = spu->stride * walky + (unsigned int) unscaled_x;		    tmp = left /* * 1.0 */ * canon_alpha(spu->aimage[base]);		    alpha += tmp;		    color += tmp * spu->image[base];		  }		}		/* 5: center part */		if (width > 0 && height > 0) {		  unsigned int walky;		  for (walky = top_low_row; walky < (unsigned int) unscaled_y_bottom; ++walky) {		    unsigned int walkx;		    base = spu->stride * walky;		    for (walkx = left_right_column; walkx < (unsigned int) unscaled_x_right; ++walkx) {		      tmp = /* 1.0 * 1.0 * */ canon_alpha(spu->aimage[base + walkx]);		      alpha += tmp;		      color += tmp * spu->image[base + walkx];		    }		  }		    		}		/* 6: center right part */		if (right > 0.0 && height > 0) {		  unsigned int walky;		  for (walky = top_low_row; walky < (unsigned int) unscaled_y_bottom; ++walky) {		    base = spu->stride * walky + (unsigned int) unscaled_x_right;		    tmp = right /* * 1.0 */ * canon_alpha(spu->aimage[base]);		    alpha += tmp;		    color += tmp * spu->image[base];		  }		}		/* 7: bottom left part */		if (bottom > 0.0) {		  base = spu->stride * (unsigned int) unscaled_y_bottom + (unsigned int) unscaled_x;		  tmp = left * bottom * canon_alpha(spu->aimage[base]);		  alpha += tmp;		  color += tmp * spu->image[base];		}		/* 8: bottom center part */		if (width > 0 && bottom > 0.0) {		  unsigned int walkx;		  base = spu->stride * (unsigned int) unscaled_y_bottom;		  for (walkx = left_right_column; walkx < (unsigned int) unscaled_x_right; ++walkx) {		    tmp = /* 1.0 * */ bottom * canon_alpha(spu->aimage[base + walkx]);		    alpha += tmp;		    color += tmp * spu->image[base + walkx];		  }		}		/* 9: bottom right part */		if (right > 0.0 && bottom > 0.0) {		  base = spu->stride * (unsigned int) unscaled_y_bottom + (unsigned int) unscaled_x_right;		  tmp = right * bottom * canon_alpha(spu->aimage[base]);		  alpha += tmp;		  color += tmp * spu->image[base];		}		/* Finally mix these transparency and brightness information suitably */		base = spu->scaled_stride * y + x;		spu->scaled_image[base] = alpha > 0 ? color / alpha : 0;		spu->scaled_aimage[base] = alpha * scalex * scaley / 0x10000;		if (spu->scaled_aimage[base]) {		  spu->scaled_aimage[base] = 256 - spu->scaled_aimage[base];		  if (spu->scaled_aimage[base] + spu->scaled_image[base] > 255)		    spu->scaled_image[base] = 256 - spu->scaled_aimage[base];		}	      }	    }	  }	  }nothing_to_do:	  /* Kludge: draw_alpha needs width multiple of 8. */	  if (spu->scaled_width < spu->scaled_stride)	    for (y = 0; y < spu->scaled_height; ++y) {	      memset(spu->scaled_aimage + y * spu->scaled_stride + spu->scaled_width, 0,		     spu->scaled_stride - spu->scaled_width);	    }	  spu->scaled_frame_width = dxs;	  spu->scaled_frame_height = dys;	}      }      if (spu->scaled_image){        switch (spu_alignment) {        case 0:          spu->scaled_start_row = dys*sub_pos/100;	  if (spu->scaled_start_row + spu->scaled_height > dys)	    spu->scaled_start_row = dys - spu->scaled_height;	  break;	case 1:          spu->scaled_start_row = dys*sub_pos/100 - spu->scaled_height/2;          if (sub_pos < 50) {	    if (spu->scaled_start_row < 0) spu->scaled_start_row = 0;	  } else {	    if (spu->scaled_start_row + spu->scaled_height > dys)	      spu->scaled_start_row = dys - spu->scaled_height;	  }	  break;        case 2:          spu->scaled_start_row = dys*sub_pos/100 - spu->scaled_height;	  if (spu->scaled_start_row < 0) spu->scaled_start_row = 0;	  break;	}	draw_alpha(spu->scaled_start_col, spu->scaled_start_row, spu->scaled_width, spu->scaled_height,		   spu->scaled_image, spu->scaled_aimage, spu->scaled_stride);	spu->spu_changed = 0;      }    }  }  else  {    mp_msg(MSGT_SPUDEC,MSGL_DBG2,"SPU not displayed: start_pts=%d  end_pts=%d  now_pts=%d\n",        spu->start_pts, spu->end_pts, spu->now_pts);  }}void spudec_update_palette(void * this, unsigned int *palette){  spudec_handle_t *spu = (spudec_handle_t *) this;  if (spu && palette) {    memcpy(spu->global_palette, palette, sizeof(spu->global_palette));    if(spu->hw_spu)      spu->hw_spu->control(VOCTRL_SET_SPU_PALETTE,spu->global_palette);  }}void spudec_set_font_factor(void * this, double factor){  spudec_handle_t *spu = (spudec_handle_t *) this;  spu->font_start_level = (int)(0xF0-(0xE0*factor));}void *spudec_new_scaled(unsigned int *palette, unsigned int frame_width, unsigned int frame_height){  return spudec_new_scaled_vobsub(palette, NULL, 0, frame_width, frame_height);}/* get palette custom color, width, height from .idx file */void *spudec_new_scaled_vobsub(unsigned int *palette, unsigned int *cuspal, unsigned int custom, unsigned int frame_width, unsigned int frame_height){  spudec_handle_t *this = calloc(1, sizeof(spudec_handle_t));  if (this){    //(fprintf(stderr,"VobSub Custom Palette: %d,%d,%d,%d", this->cuspal[0], this->cuspal[1], this->cuspal[2],this->cuspal[3]);    this->packet = NULL;    this->image = NULL;    this->scaled_image = NULL;    /* XXX Although the video frame is some size, the SPU frame is       always maximum size i.e. 720 wide and 576 or 480 high */    this->orig_frame_width = 720;    this->orig_frame_height = (frame_height == 480 || frame_height == 240) ? 480 : 576;    this->custom = custom;    // set up palette:    this->auto_palette = 1;    if (palette){      memcpy(this->global_palette, palette, sizeof(this->global_palette));      this->auto_palette = 0;    }    this->custom = custom;    if (custom && cuspal) {      memcpy(this->cuspal, cuspal, sizeof(this->cuspal));      this->auto_palette = 0;    }    // forced subtitles default: show all subtitles    this->forced_subs_only=0;    this->is_forced_sub=0;  }  else    mp_msg(MSGT_SPUDEC,MSGL_FATAL, "FATAL: spudec_init: calloc");  return this;}void *spudec_new(unsigned int *palette){    return spudec_new_scaled(palette, 0, 0);}void spudec_free(void *this){  spudec_handle_t *spu = (spudec_handle_t*)this;  if (spu) {    while (spu->queue_head)      spudec_free_packet(spudec_dequeue_packet(spu));    if (spu->packet)      free(spu->packet);    if (spu->scaled_image)	free(spu->scaled_image);    if (spu->image)      free(spu->image);    free(spu);  }}void spudec_set_hw_spu(void *this, vo_functions_t *hw_spu){  spudec_handle_t *spu = (spudec_handle_t*)this;  if (!spu)    return;  spu->hw_spu = hw_spu;  hw_spu->control(VOCTRL_SET_SPU_PALETTE,spu->global_palette);}

⌨️ 快捷键说明

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