📄 video_yuv.c
字号:
for( i_index = 0; i_index < 256; i_index++ ) { p_vout->yuv.yuv.p_rgb16[RED_OFFSET + i_index] = RGB2PIXEL( p_vout, pi_gamma[ i_index ], 0, 0 ); p_vout->yuv.yuv.p_rgb16[GREEN_OFFSET + i_index] = RGB2PIXEL( p_vout, 0, pi_gamma[ i_index ], 0 ); p_vout->yuv.yuv.p_rgb16[BLUE_OFFSET + i_index] = RGB2PIXEL( p_vout, 0, 0, pi_gamma[ i_index ] ); } break; case 3: case 4: p_vout->yuv.yuv.p_rgb32 = (u32 *)p_vout->yuv.p_base; for( i_index = 0; i_index < RED_MARGIN; i_index++ ) { p_vout->yuv.yuv.p_rgb32[RED_OFFSET - RED_MARGIN + i_index] = RGB2PIXEL( p_vout, pi_gamma[0], 0, 0 ); p_vout->yuv.yuv.p_rgb32[RED_OFFSET + 256 + i_index] = RGB2PIXEL( p_vout, pi_gamma[255], 0, 0 ); } for( i_index = 0; i_index < GREEN_MARGIN; i_index++ ) { p_vout->yuv.yuv.p_rgb32[GREEN_OFFSET - GREEN_MARGIN + i_index] = RGB2PIXEL( p_vout, 0, pi_gamma[0], 0 ); p_vout->yuv.yuv.p_rgb32[GREEN_OFFSET + 256 + i_index] = RGB2PIXEL( p_vout, 0, pi_gamma[255], 0 ); } for( i_index = 0; i_index < BLUE_MARGIN; i_index++ ) { p_vout->yuv.yuv.p_rgb32[BLUE_OFFSET - BLUE_MARGIN + i_index] = RGB2PIXEL( p_vout, 0, 0, pi_gamma[0] ); p_vout->yuv.yuv.p_rgb32[BLUE_OFFSET + BLUE_MARGIN + i_index] = RGB2PIXEL( p_vout, 0, 0, pi_gamma[255] ); } for( i_index = 0; i_index < 256; i_index++ ) { p_vout->yuv.yuv.p_rgb32[RED_OFFSET + i_index] = RGB2PIXEL( p_vout, pi_gamma[ i_index ], 0, 0 ); p_vout->yuv.yuv.p_rgb32[GREEN_OFFSET + i_index] = RGB2PIXEL( p_vout, 0, pi_gamma[ i_index ], 0 ); p_vout->yuv.yuv.p_rgb32[BLUE_OFFSET + i_index] = RGB2PIXEL( p_vout, 0, 0, pi_gamma[ i_index ] ); } break; } } /* * Set functions pointers */ if( p_vout->b_grayscale ) { /* Grayscale */ switch( p_vout->i_bytes_per_pixel ) { case 1: p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray8; p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertY4Gray8; p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertY4Gray8; break; case 2: p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray16; p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertY4Gray16; p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertY4Gray16; break; case 3: p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray24; p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertY4Gray24; p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertY4Gray24; break; case 4: p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertY4Gray32; p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertY4Gray32; p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertY4Gray32; break; } } else { /* Color */ switch( p_vout->i_bytes_per_pixel ) { case 1: p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertYUV420RGB8; p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertYUV422RGB8; p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertYUV444RGB8; break; case 2: p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertYUV420RGB16; p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertYUV422RGB16; p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertYUV444RGB16; break; case 3: p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertYUV420RGB24; p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertYUV422RGB24; p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertYUV444RGB24; break; case 4: p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertYUV420RGB32; p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertYUV422RGB32; p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertYUV444RGB32; break; } }}/***************************************************************************** * SetOffset: build offset array for conversion functions ***************************************************************************** * This function will build an offset array used in later conversion functions. * It will also set horizontal and vertical scaling indicators. *****************************************************************************/static void SetOffset( int i_width, int i_height, int i_pic_width, int i_pic_height, boolean_t *pb_h_scaling, int *pi_v_scaling, int *p_offset ){ int i_x; /* x position in destination */ int i_scale_count; /* modulo counter */ /* * Prepare horizontal offset array */ if( i_pic_width - i_width > 0 ) { /* Prepare scaling array for horizontal extension */ *pb_h_scaling = 1; i_scale_count = i_pic_width; for( i_x = i_width; i_x--; ) { while( (i_scale_count -= i_width) > 0 ) { *p_offset++ = 0; } *p_offset++ = 1; i_scale_count += i_pic_width; } } else if( i_pic_width - i_width < 0 ) { /* Prepare scaling array for horizontal reduction */ *pb_h_scaling = 1; i_scale_count = i_pic_width; for( i_x = i_pic_width; i_x--; ) { *p_offset = 1; while( (i_scale_count -= i_pic_width) >= 0 ) { *p_offset += 1; } p_offset++; i_scale_count += i_width; } } else { /* No horizontal scaling: YUV conversion is done directly to picture */ *pb_h_scaling = 0; } /* * Set vertical scaling indicator */ if( i_pic_height - i_height > 0 ) { *pi_v_scaling = 1; } else if( i_pic_height - i_height < 0 ) { *pi_v_scaling = -1; } else { *pi_v_scaling = 0; }}/***************************************************************************** * ConvertY4Gray8: grayscale YUV 4:x:x to RGB 8 bpp *****************************************************************************/static void ConvertY4Gray8( p_vout_thread_t p_vout, u8 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v, int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width, int i_matrix_coefficients ){ boolean_t b_horizontal_scaling; /* horizontal scaling type */ int i_vertical_scaling; /* vertical scaling type */ int i_x, i_y; /* horizontal and vertical indexes */ int i_scale_count; /* scale modulo counter */ int i_chroma_width; /* chroma width, not used */ u8 * p_gray; /* base conversion table */ u8 * p_pic_start; /* beginning of the current line for copy */ u8 * p_buffer_start; /* conversion buffer start */ u8 * p_buffer; /* conversion buffer pointer */ int * p_offset_start; /* offset array start */ int * p_offset; /* offset array pointer */ /* * Initialize some values - i_pic_line_width will store the line skip */ i_pic_line_width -= i_pic_width; p_gray = p_vout->yuv.yuv.p_gray8; p_buffer_start = p_vout->yuv.p_buffer; p_offset_start = p_vout->yuv.p_offset; SetOffset( i_width, i_height, i_pic_width, i_pic_height, &b_horizontal_scaling, &i_vertical_scaling, p_offset_start ); /* * Perform conversion */ i_scale_count = i_pic_height; for( i_y = 0; i_y < i_height; i_y++ ) { /* Mark beginnning of line for possible later line copy, and initialize * buffer */ p_pic_start = p_pic; p_buffer = b_horizontal_scaling ? p_buffer_start : p_pic; /* Do YUV conversion to buffer - YUV picture is always formed of 16 * pixels wide blocks */ for( i_x = i_width / 16; i_x--; ) { *p_buffer++ = p_gray[ *p_y++ ]; *p_buffer++ = p_gray[ *p_y++ ]; *p_buffer++ = p_gray[ *p_y++ ]; *p_buffer++ = p_gray[ *p_y++ ]; *p_buffer++ = p_gray[ *p_y++ ]; *p_buffer++ = p_gray[ *p_y++ ]; *p_buffer++ = p_gray[ *p_y++ ]; *p_buffer++ = p_gray[ *p_y++ ]; *p_buffer++ = p_gray[ *p_y++ ]; *p_buffer++ = p_gray[ *p_y++ ]; *p_buffer++ = p_gray[ *p_y++ ]; *p_buffer++ = p_gray[ *p_y++ ]; *p_buffer++ = p_gray[ *p_y++ ]; *p_buffer++ = p_gray[ *p_y++ ]; *p_buffer++ = p_gray[ *p_y++ ]; *p_buffer++ = p_gray[ *p_y++ ]; } /* Do horizontal and vertical scaling */ SCALE_WIDTH; SCALE_HEIGHT(400, 1); }}/***************************************************************************** * ConvertY4Gray16: grayscale YUV 4:x:x to RGB 2 Bpp *****************************************************************************/static void ConvertY4Gray16( p_vout_thread_t p_vout, u16 *p_pic, yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v, int i_width, int i_height, int i_pic_width, int i_pic_height, int i_pic_line_width, int i_matrix_coefficients ){ boolean_t b_horizontal_scaling; /* horizontal scaling type */ int i_vertical_scaling; /* vertical scaling type */ int i_x, i_y; /* horizontal and vertical indexes */ int i_scale_count; /* scale modulo counter */ int i_chroma_width; /* chroma width, not used */ u16 * p_gray; /* base conversion table */ u16 * p_pic_start; /* beginning of the current line for copy */ u16 * p_buffer_start; /* conversion buffer start */ u16 * p_buffer; /* conversion buffer pointer */ int * p_offset_start; /* offset array start */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -