summaryrefslogtreecommitdiffstats
path: root/libvo
diff options
context:
space:
mode:
authorarpi_esp <arpi_esp@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-03-24 04:36:17 +0000
committerarpi_esp <arpi_esp@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-03-24 04:36:17 +0000
commite72b62f8cc189053efe7e42078d7fa0f04dd425e (patch)
tree5fa3c0644fde7f0ef4ccf88cfe0f5e7f5a28edd0 /libvo
parent96edb007a565f7fc9a50f1ba64ae24e05f903fbc (diff)
downloadmpv-e72b62f8cc189053efe7e42078d7fa0f04dd425e.tar.bz2
mpv-e72b62f8cc189053efe7e42078d7fa0f04dd425e.tar.xz
grey+alpha rendering support (for .sub)
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@203 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libvo')
-rw-r--r--libvo/mga_common.c89
-rw-r--r--libvo/sub.c71
-rw-r--r--libvo/video_out.c2
-rw-r--r--libvo/vo_mga.c1
-rw-r--r--libvo/vo_x11.c23
-rw-r--r--libvo/vo_xmga.c2
6 files changed, 127 insertions, 61 deletions
diff --git a/libvo/mga_common.c b/libvo/mga_common.c
index 4fc5084d60..8779c68d19 100644
--- a/libvo/mga_common.c
+++ b/libvo/mga_common.c
@@ -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;
+
+ if (mga_vid_config.format==MGA_VID_FORMAT_YV12){
+
+ 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;
+ }
-static void
-write_frame_g200(uint8_t *y,uint8_t *cr, uint8_t *cb)
-{
- uint8_t *dest;
- uint32_t bespitch,h,w;
+ } 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;
+ }
- 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++)
- {
- 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;
}
diff --git a/libvo/sub.c b/libvo/sub.c
new file mode 100644
index 0000000000..1ab62fcc6f
--- /dev/null
+++ b/libvo/sub.c
@@ -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;
+ }
+
+}
+
diff --git a/libvo/video_out.c b/libvo/video_out.c
index a5483d3126..e35dbec893 100644
--- a/libvo/video_out.c
+++ b/libvo/video_out.c
@@ -87,4 +87,4 @@ vo_functions_t* video_out_drivers[] =
NULL
};
-
+#include "sub.c"
diff --git a/libvo/vo_mga.c b/libvo/vo_mga.c
index 888cb1bf69..86d05814d9 100644
--- a/libvo/vo_mga.c
+++ b/libvo/vo_mga.c
@@ -105,6 +105,7 @@ printf("vo: uninit!\n");
static void flip_page(void)
{
+ vo_draw_text(draw_alpha);
vo_mga_flip_page();
}
diff --git a/libvo/vo_x11.c b/libvo/vo_x11.c
index 2d2a19b1bc..bf8b5abe14 100644
--- a/libvo/vo_x11.c
+++ b/libvo/vo_x11.c
@@ -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 );
}
diff --git a/libvo/vo_xmga.c b/libvo/vo_xmga.c
index 6fc0719ec5..eaa5ba72b1 100644
--- a/libvo/vo_xmga.c
+++ b/libvo/vo_xmga.c
@@ -151,6 +151,8 @@ static void flip_page(void){
timer=t;
#endif
+ vo_draw_text(draw_alpha);
+
check_events();
vo_mga_flip_page();
}