mirror of
https://github.com/mpv-player/mpv
synced 2025-01-20 21:07:29 +01:00
grey+alpha rendering support (for .sub)
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@203 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
96edb007a5
commit
e72b62f8cc
@ -7,64 +7,40 @@ static mga_vid_config_t mga_vid_config;
|
||||
static uint8_t *vid_data, *frames[4];
|
||||
static int f;
|
||||
|
||||
static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){
|
||||
int x,y;
|
||||
uint32_t bespitch = (mga_vid_config.src_width + 31) & ~31;
|
||||
|
||||
static void
|
||||
write_frame_g200(uint8_t *y,uint8_t *cr, uint8_t *cb)
|
||||
{
|
||||
uint8_t *dest;
|
||||
uint32_t bespitch,h,w;
|
||||
if (mga_vid_config.format==MGA_VID_FORMAT_YV12){
|
||||
|
||||
dest = vid_data;
|
||||
bespitch = (mga_vid_config.src_width + 31) & ~31;
|
||||
for(y=0;y<h;y++){
|
||||
uint8_t *dst = vid_data + bespitch * (y0+y) + x0;
|
||||
for(x=0;x<w;x++){
|
||||
// dst[x]=(dst[x]*srca[x]+src[x]*(srca[x]^255))>>8;
|
||||
if(srca[x])
|
||||
dst[x]=(dst[x]*(srca[x]^255)+src[x]*(srca[x]))>>8;
|
||||
}
|
||||
src+=stride;
|
||||
srca+=stride;
|
||||
}
|
||||
|
||||
for(h=0; h < mga_vid_config.src_height; h++)
|
||||
{
|
||||
memcpy(dest, y, mga_vid_config.src_width);
|
||||
y += mga_vid_config.src_width;
|
||||
dest += bespitch;
|
||||
}
|
||||
} else {
|
||||
|
||||
for(y=0;y<h;y++){
|
||||
uint8_t *dst = vid_data + 2*(bespitch * (y0+y) + x0);
|
||||
for(x=0;x<w;x++){
|
||||
// dst[x]=(dst[x]*srca[x]+src[x]*(srca[x]^255))>>8;
|
||||
if(srca[x])
|
||||
dst[2*x]=(dst[2*x]*(srca[x]^255)+src[x]*(srca[x]))>>8;
|
||||
}
|
||||
src+=stride;
|
||||
srca+=stride;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for(h=0; h < mga_vid_config.src_height/2; h++)
|
||||
{
|
||||
for(w=0; w < mga_vid_config.src_width/2; w++)
|
||||
{
|
||||
*dest++ = *cb++;
|
||||
*dest++ = *cr++;
|
||||
}
|
||||
dest += bespitch - mga_vid_config.src_width;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
write_frame_g400(uint8_t *y,uint8_t *cr, uint8_t *cb)
|
||||
{
|
||||
uint8_t *dest;
|
||||
uint32_t bespitch,h;
|
||||
|
||||
dest = vid_data;
|
||||
bespitch = (mga_vid_config.src_width + 31) & ~31;
|
||||
|
||||
for(h=0; h < mga_vid_config.src_height; h++)
|
||||
{
|
||||
memcpy(dest, y, mga_vid_config.src_width);
|
||||
y += mga_vid_config.src_width;
|
||||
dest += bespitch;
|
||||
}
|
||||
|
||||
for(h=0; h < mga_vid_config.src_height/2; h++)
|
||||
{
|
||||
memcpy(dest, cb, mga_vid_config.src_width/2);
|
||||
cb += mga_vid_config.src_width/2;
|
||||
dest += bespitch/2;
|
||||
}
|
||||
|
||||
for(h=0; h < mga_vid_config.src_height/2; h++)
|
||||
{
|
||||
memcpy(dest, cr, mga_vid_config.src_width/2);
|
||||
cr += mga_vid_config.src_width/2;
|
||||
dest += bespitch/2;
|
||||
}
|
||||
}
|
||||
|
||||
//static void
|
||||
//write_slice_g200(uint8_t *y,uint8_t *cr, uint8_t *cb,uint32_t slice_num)
|
||||
@ -200,13 +176,6 @@ draw_frame(uint8_t *src[])
|
||||
{
|
||||
if (mga_vid_config.format==MGA_VID_FORMAT_YUY2)
|
||||
write_frame_yuy2(src[0]);
|
||||
else
|
||||
if (mga_vid_config.card_type == MGA_G200)
|
||||
write_frame_g200(src[0], src[2], src[1]);
|
||||
else
|
||||
write_frame_g400(src[0], src[2], src[1]);
|
||||
|
||||
//flip_page();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
71
libvo/sub.c
Normal file
71
libvo/sub.c
Normal file
@ -0,0 +1,71 @@
|
||||
|
||||
typedef struct {
|
||||
unsigned char *bmp;
|
||||
unsigned char *pal;
|
||||
int w,h,c;
|
||||
} raw_file;
|
||||
|
||||
raw_file* load_raw(char *name){
|
||||
int bpp;
|
||||
raw_file* raw=malloc(sizeof(raw_file));
|
||||
unsigned char head[32];
|
||||
FILE *f=fopen(name,"rb");
|
||||
if(!f) return NULL; // can't open
|
||||
if(fread(head,32,1,f)<1) return NULL; // too small
|
||||
if(memcmp(head,"mhwanh",6)) return NULL; // not raw file
|
||||
raw->w=head[8]*256+head[9];
|
||||
raw->h=head[10]*256+head[11];
|
||||
raw->c=head[12]*256+head[13];
|
||||
if(raw->c>256) return NULL; // too many colors!?
|
||||
printf("RAW: %d x %d, %d colors\n",raw->w,raw->h,raw->c);
|
||||
if(raw->c){
|
||||
raw->pal=malloc(raw->c*3);
|
||||
fread(raw->pal,3,raw->c,f);
|
||||
bpp=1;
|
||||
} else {
|
||||
raw->pal=NULL;
|
||||
bpp=3;
|
||||
}
|
||||
raw->bmp=malloc(raw->h*raw->w*bpp);
|
||||
fread(raw->bmp,raw->h*raw->w*bpp,1,f);
|
||||
fclose(f);
|
||||
return raw;
|
||||
}
|
||||
|
||||
static int vo_font_loaded=-1;
|
||||
static raw_file* vo_font_bmp=NULL;
|
||||
static raw_file* vo_font_alpha=NULL;
|
||||
|
||||
void vo_load_font(char *bmpname,char *alphaname){
|
||||
vo_font_loaded=0;
|
||||
if(!(vo_font_bmp=load_raw(bmpname)))
|
||||
printf("vo: Can't load font BMP\n"); else
|
||||
if(!(vo_font_alpha=load_raw(alphaname)))
|
||||
printf("vo: Can't load font Alpha\n"); else
|
||||
vo_font_loaded=1;
|
||||
}
|
||||
|
||||
int vo_sub_lines=2;
|
||||
char* vo_sub_text[8];
|
||||
|
||||
|
||||
void vo_draw_text(void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)){
|
||||
int i;
|
||||
int y=100;
|
||||
|
||||
if(vo_sub_lines<=0) return; // no text
|
||||
|
||||
if(vo_font_loaded==-1) vo_load_font("font_b.raw","font_a.raw");
|
||||
if(!vo_font_loaded) return; // no font
|
||||
|
||||
// if(!vo_font_bmp) vo_load_font("mplayer_font_lowres_bitmap.raw","mplayer_font_lowres_alpha.raw");
|
||||
|
||||
for(i=0;i<vo_sub_lines;i++){
|
||||
char* text="Hello World!"; //vo_sub_text[i];
|
||||
draw_alpha(100,y,50,vo_font_bmp->h,vo_font_bmp->bmp,vo_font_alpha->bmp,vo_font_bmp->w);
|
||||
// x11_draw_alpha(100,y,50,vo_font_bmp->h,vo_font_bmp->bmp,vo_font_alpha->bmp,vo_font_bmp->w);
|
||||
y+=50;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -87,4 +87,4 @@ vo_functions_t* video_out_drivers[] =
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
#include "sub.c"
|
||||
|
@ -105,6 +105,7 @@ printf("vo: uninit!\n");
|
||||
|
||||
static void flip_page(void)
|
||||
{
|
||||
vo_draw_text(draw_alpha);
|
||||
vo_mga_flip_page();
|
||||
}
|
||||
|
||||
|
@ -328,7 +328,30 @@ static void Display_Image( XImage *myximage,uint8_t *ImageData )
|
||||
#endif
|
||||
}
|
||||
|
||||
static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){
|
||||
int dbpp=( bpp+7 )/8;
|
||||
int x,y;
|
||||
|
||||
for(y=0;y<h;y++){
|
||||
uint8_t *dst = ImageData+ dbpp*((y+y0)*image_width+x0);
|
||||
for(x=0;x<w;x++){
|
||||
// dst[x]=(dst[x]*srca[x]+src[x]*(srca[x]^255))>>8;
|
||||
if(srca[x]){
|
||||
dst[0]=(dst[0]*(srca[x]^255)+src[x]*(srca[x]))>>8;
|
||||
dst[1]=(dst[1]*(srca[x]^255)+src[x]*(srca[x]))>>8;
|
||||
dst[2]=(dst[2]*(srca[x]^255)+src[x]*(srca[x]))>>8;
|
||||
}
|
||||
dst+=dbpp;
|
||||
}
|
||||
src+=stride;
|
||||
srca+=stride;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void flip_page( void ){
|
||||
vo_draw_text(draw_alpha);
|
||||
check_events();
|
||||
Display_Image( myximage,ImageData );
|
||||
}
|
||||
|
@ -151,6 +151,8 @@ static void flip_page(void){
|
||||
timer=t;
|
||||
#endif
|
||||
|
||||
vo_draw_text(draw_alpha);
|
||||
|
||||
check_events();
|
||||
vo_mga_flip_page();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user