common.c

来自「VLC媒体播放程序」· C语言 代码 · 共 555 行 · 第 1/2 页

C
555
字号
            if ( i_scale_y - w1 <= i_scale_x ) {	/* Average spans 2 pixels. */	w2 = i_scale_y - w1;	for (i = 0; i < PIXEL_SIZE; i++ ) {	  *p_dst = ( (*p_src1 * w1) + (*p_src2 * w2) ) / i_scale_y;	  p_src1++; p_src2++; p_dst++;	}      } else {	/* Average spans 3 pixels. */	unsigned int w0 = w1;	unsigned int w1 = i_scale_x;	uint8_t *p_src0 = p_src1;	w2 = i_scale_y - w0 - w1;	p_src1 = p_src2;	p_src2 += PIXEL_SIZE;		for (i = 0; i < PIXEL_SIZE; i++ ) {	  *p_dst = ( (*p_src0 * w0) + (*p_src1 * w1) + (*p_src2 * w2) ) 		     / i_scale_y;	  p_src0++; p_src1++; p_src2++; p_dst++;	}	i_col++;      }      i_used = w2;      if (i_scale_x == i_used) {	/* End of last pixel was end of p_src2. */	p_src1 = p_src2;	p_src2 += PIXEL_SIZE;	i_col++;	i_used = 0;      }    }  }  p_spu->i_width = i_new_width;  if ( p_sys && p_sys->i_debug & DECODE_DBG_TRANSFORM )  {     ogt_yuvt_t *p_source = (ogt_yuvt_t *) p_spu->p_sys->p_data;    for ( i_row=0; i_row < p_spu->i_height; i_row++ ) {      for ( i_col=0; i_col < p_spu->i_width; i_col++ ) {	printf("%1x", p_source->s.t);	p_source++;      }      printf("\n");    }  }}/**   The video may be scaled. However subtitle bitmaps assume an 1:1   aspect ratio. So unless the user has specified otherwise, we   need to scale to compensate for or undo the effects of video   output scaling.      Perhaps this should go in the Render routine? The advantage would   be that it will deal with a dynamically changing aspect ratio.   The downside is having to scale many times for each render call.   We also expand palette entries here, unless we are dealing with a    palettized chroma (e.g. RGB2).*/void VCDSubHandleScaling( subpicture_t *p_spu, decoder_t *p_dec ){  vlc_object_t * p_input = p_spu->p_sys->p_input;  vout_thread_t *p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT,                                            FIND_CHILD );  unsigned int i_aspect_x, i_aspect_y;  uint8_t *p_dest = (uint8_t *)p_spu->p_sys->p_data;  if (p_vout) {    /* Check for user-configuration override. */    unsigned int i_new_aspect;        if ( p_vout->output.i_chroma == VLC_FOURCC('R','G','B','2') ) {      /* This is an unscaled palettized format. We don't allow          user scaling here. And to make the render process faster,         we don't expand the palette entries into a color value.       */      return;    }            InlinePalette( p_dest, p_dec->p_sys );    i_new_aspect = VCDSubGetAROverride( p_input, p_vout );    if (i_new_aspect == VOUT_ASPECT_FACTOR) {      /* For scaling 1:1, nothing needs to be done. Note this means         subtitles will get scaled the same way the video does.      */      ;    } else {      if (0 == i_new_aspect) {        /* Counteract the effects of background video scaling when           there is scaling. That's why x and y are reversed from           the else branch in the call below.        */        switch( p_vout->output.i_chroma )          {            /* chromas in which scaling is done outside of our               blending routine, so we need to compensate for those               effects before blending gets called: */          case VLC_FOURCC('I','4','2','0'):          case VLC_FOURCC('I','Y','U','V'):          case VLC_FOURCC('Y','V','1','2'):          case VLC_FOURCC('Y','U','Y','2'):            break;                        /* chromas in which scaling is done in our blending                routine and thus we don't do it here: */          case VLC_FOURCC('R','V','1','6'):          case VLC_FOURCC('R','V','2','4'):          case VLC_FOURCC('R','V','3','2'):          case VLC_FOURCC('R','G','B','2'):            return;            break;                      default:            msg_Err( p_vout, "unknown chroma %x",                      p_vout->output.i_chroma );            return;            break;          }        /* We get here only for scaled chromas. */        vout_AspectRatio( p_vout->render.i_aspect, &i_aspect_y,                           &i_aspect_x );      } else {        /* User knows best? */        vout_AspectRatio( i_new_aspect, &i_aspect_x, &i_aspect_y );      }      VCDSubScaleX( p_dec, p_spu, i_aspect_x, i_aspect_y );    }  }}/** * DestroySPU: subpicture destructor */void VCDSubDestroySPU( subpicture_t *p_spu ){    if( p_spu->p_sys->p_input )    {        /* Detach from our input thread */        vlc_object_release( p_spu->p_sys->p_input );    }    vlc_mutex_destroy( &p_spu->p_sys->lock );    free( p_spu->p_sys );}/*****************************************************************************  This callback is called from the input thread when we need cropping *****************************************************************************/int VCDSubCropCallback( vlc_object_t *p_object, char const *psz_var,                         vlc_value_t oldval, vlc_value_t newval, void *p_data ){    VCDSubUpdateSPU( (subpicture_t *)p_data, p_object );    return VLC_SUCCESS;}/*****************************************************************************  update subpicture settings *****************************************************************************  This function is called from CropCallback and at initialization time, to  retrieve crop information from the input. *****************************************************************************/void VCDSubUpdateSPU( subpicture_t *p_spu, vlc_object_t *p_object ){    vlc_value_t val;    p_spu->p_sys->b_crop = val.b_bool;    if( !p_spu->p_sys->b_crop )    {        return;    }    if ( VLC_SUCCESS == var_Get( p_object, "x-start", &val ) )      p_spu->p_sys->i_x_start = val.i_int;    if ( VLC_SUCCESS == var_Get( p_object, "y-start", &val ) )      p_spu->p_sys->i_y_start = val.i_int;    if ( VLC_SUCCESS == var_Get( p_object, "x-end", &val ) )      p_spu->p_sys->i_x_end = val.i_int;    if ( VLC_SUCCESS == var_Get( p_object, "y-end", &val ) )      p_spu->p_sys->i_y_end = val.i_int;}/*    Dump an a subtitle image to standard output - for debugging. */void VCDSubDumpImage( uint8_t *p_image, uint32_t i_height, uint32_t i_width ){  uint8_t *p = p_image;  unsigned int i_row;    /* scanline row number */  unsigned int i_column; /* scanline column number */  printf("-------------------------------------\n++");  for ( i_row=0; i_row < i_height; i_row ++ ) {    for ( i_column=0; i_column<i_width; i_column++ ) {      printf("%1d", *p++ & 0x03);    }    printf("\n++");  }  printf("\n-------------------------------------\n");}#ifdef HAVE_LIBPNG#define PALETTE_SIZE  4/* Note the below assumes the above is a power of 2 */#define PALETTE_SIZE_MASK (PALETTE_SIZE-1)/*    Dump an a subtitle image to a Portable Network Graphics (PNG) file.   All we do here is convert YUV palette entries to RGB, expand   the image into a linear RGB pixel array, and call the routine   that does the PNG writing. */void VCDSubDumpPNG( uint8_t *p_image, decoder_t *p_dec,	       uint32_t i_height, uint32_t i_width, const char *filename,	       png_text *text_ptr, int i_text_count ){  decoder_sys_t *p_sys = p_dec->p_sys;  uint8_t *p = p_image;  uint8_t *image_data = malloc(RGB_SIZE * i_height * i_width );  uint8_t *q = image_data;  unsigned int i_row;    /* scanline row number */  unsigned int i_column; /* scanline column number */  uint8_t rgb_palette[PALETTE_SIZE * RGB_SIZE];  int i;  dbg_print( (DECODE_DBG_CALL), "%s", filename);    if (NULL == image_data) return;  /* Convert palette YUV into RGB. */  for (i=0; i<PALETTE_SIZE; i++) {    ogt_yuvt_t *p_yuv     = &(p_sys->p_palette[i]);    uint8_t   *p_rgb_out  = &(rgb_palette[i*RGB_SIZE]);    yuv2rgb( p_yuv, p_rgb_out );  }    /* Convert palette entries into linear RGB array. */  for ( i_row=0; i_row < i_height; i_row ++ ) {    for ( i_column=0; i_column<i_width; i_column++ ) {      uint8_t *p_rgb = &rgb_palette[ ((*p)&PALETTE_SIZE_MASK)*RGB_SIZE ];      *q++ = p_rgb[0];      *q++ = p_rgb[1];      *q++ = p_rgb[2];      p++;    }  }    write_png( filename, i_height, i_width, image_data, text_ptr, i_text_count );  free(image_data);}#endif /*HAVE_LIBPNG*//*  * Local variables: *  c-file-style: "gnu" *  tab-width: 8 *  indent-tabs-mode: nil * End: */

⌨️ 快捷键说明

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