vo_directfb2.c
来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C语言 代码 · 共 1,516 行 · 第 1/3 页
C
1,516 行
primary = NULL; }/* mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Releasing DirectFB library\n"); dfb->Release (dfb);*/ mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Uninit done.\n");}static uint32_t directfb_set_video_eq(char *data, int value) //data==name{ DFBColorAdjustment ca; float factor = (float)0xffff / 200.0; DFBDisplayLayerDescription desc; unlock(); if (layer) { layer->GetDescription(layer,&desc); ca.flags=DCAF_NONE; if (! strcmp( data,"brightness" )) { if (desc.caps & DLCAPS_BRIGHTNESS) { ca.brightness = value * factor +0x8000; ca.flags |= DCAF_BRIGHTNESS; mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: SetVEq Brightness 0x%X %i\n",ca.brightness,value); } else return VO_FALSE; } if (! strcmp( data,"contrast" )) { if ((desc.caps & DLCAPS_CONTRAST)) { ca.contrast = value * factor + 0x8000; ca.flags |= DCAF_CONTRAST; mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: SetVEq Contrast 0x%X %i\n",ca.contrast,value); } else return VO_FALSE; } if (! strcmp( data,"hue" )) { if ((desc.caps & DLCAPS_HUE)) { ca.hue = value * factor + 0x8000; ca.flags |= DCAF_HUE; mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: SetVEq Hue 0x%X %i\n",ca.hue,value); } else return VO_FALSE; } if (! strcmp( data,"saturation" )) { if ((desc.caps & DLCAPS_SATURATION)) { ca.saturation = value * factor + 0x8000; ca.flags |= DCAF_SATURATION; mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: SetVEq Saturation 0x%X %i\n",ca.saturation,value); } else return VO_FALSE; } if (ca.flags != DCAF_NONE) { layer->SetColorAdjustment(layer,&ca); return VO_TRUE; }} return VO_FALSE;}static uint32_t directfb_get_video_eq(char *data, int *value) // data==name{ DFBColorAdjustment ca; float factor = 200.0 / (float)0xffff; DFBDisplayLayerDescription desc; if (layer) { unlock(); layer->GetDescription(layer,&desc); layer->GetColorAdjustment(layer,&ca); if (! strcmp( data,"brightness" )) { if (desc.caps & DLCAPS_BRIGHTNESS) { *value = (int) ((ca.brightness-0x8000) * factor); mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: GetVEq Brightness 0x%X %i\n",ca.brightness,*value); return VO_TRUE; } else return VO_FALSE; } if (! strcmp( data,"contrast" )) { if ((desc.caps & DLCAPS_CONTRAST)) { *value = (int) ((ca.contrast-0x8000) * factor); mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: GetVEq Contrast 0x%X %i\n",ca.contrast,*value); return VO_TRUE; } else return VO_FALSE; } if (! strcmp( data,"hue" )) { if ((desc.caps & DLCAPS_HUE)) { *value = (int) ((ca.hue-0x8000) * factor); mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: GetVEq Hue 0x%X %i\n",ca.hue,*value); return VO_TRUE; } else return VO_FALSE; } if (! strcmp( data,"saturation" )) { if ((desc.caps & DLCAPS_SATURATION)) { *value = (int) ((ca.saturation-0x8000) * factor); mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: GetVEq Saturation 0x%X %i\n",ca.saturation,*value); return VO_TRUE; } else return VO_FALSE; }} return VO_FALSE;}static uint32_t get_image(mp_image_t *mpi){ int err; void *dst; int pitch;// if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: get_image() called\n"); if(mpi->flags&MP_IMGFLAG_READABLE) return VO_FALSE; // slow video ram if(mpi->type==MP_IMGTYPE_STATIC) return VO_FALSE; // it is not static// printf("width=%d vs. pitch=%d, flags=0x%X \n",mpi->width,pitch,mpi->flags); if((mpi->width==pitch) || (mpi->flags&(MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH))){ // we're lucky or codec accepts stride => ok, let's go! if (frame) { err = frame->Lock(frame,DSLF_WRITE|DSLF_READ,&dst,&pitch); framelocked=1; } else { err = primary->Lock(primary,DSLF_WRITE,&dst,&pitch); primarylocked=1; } if (err) { mp_msg(MSGT_VO, MSGL_ERR,"DirectFB: DR lock failed!"); return VO_FALSE; }; if(mpi->flags&MP_IMGFLAG_PLANAR){ //YV12 format mpi->planes[0]=dst; if(mpi->flags&MP_IMGFLAG_SWAPPED){ mpi->planes[1]=dst + pitch*height; mpi->planes[2]=mpi->planes[1] + pitch*height/4; } else { mpi->planes[2]=dst + pitch*height; mpi->planes[1]=mpi->planes[2] + pitch*height/4; } mpi->width=width; mpi->stride[0]=pitch; mpi->stride[1]=mpi->stride[2]=pitch/2; } else { //YUY2 and RGB formats mpi->planes[0]=dst; mpi->width=width; mpi->stride[0]=pitch; } // center image if (!frame) { if(mpi->flags&MP_IMGFLAG_PLANAR){ mpi->planes[0]= dst + yoffset * pitch + xoffset; mpi->planes[1]+= (yoffset * pitch) >> 2 + xoffset >> 1; mpi->planes[2]+= (yoffset * pitch) >> 2 + xoffset >> 1; } else { mpi->planes[0]=dst + yoffset * pitch + xoffset * (mpi->bpp >> 3); } } mpi->flags|=MP_IMGFLAG_DIRECT;// if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: get_image() SUCCESS -> Direct Rendering ENABLED\n"); return VO_TRUE; } return VO_FALSE;}static int draw_slice(uint8_t *src[], int stride[], int w, int h, int x, int y){ int i; unsigned int pitch; void *dst; void *dst2; void *srcp; unsigned int p;// if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: draw_slice entered\n"); unlock(); if (frame) { DFBCHECK (frame->Lock(frame,DSLF_WRITE|DSLF_READ,&dst,&pitch)); framelocked = 1; } else { DFBCHECK (primary->Lock(primary,DSLF_WRITE,&dst,&pitch)); primarylocked = 1; }; p=min(w,pitch); dst += y*pitch + x; dst2 = dst + pitch*height - y*pitch + y*pitch/4 - x/2; srcp = src[0]; for (i=0;i<h;i++) { fast_memcpy(dst,srcp,p); dst += pitch; srcp += stride[0]; } if (pixel_format == DSPF_YV12) { dst = dst2; srcp = src[2]; p = p/2; for (i=0;i<h/2;i++) { fast_memcpy(dst,srcp,p); dst += pitch/2; srcp += stride[2]; } dst = dst2 + pitch*height/4; srcp = src[1]; for (i=0;i<h/2;i++) { fast_memcpy(dst,srcp,p); dst += pitch/2; srcp += stride[1]; } } else { dst = dst2; srcp = src[1]; p = p/2; for (i=0;i<h/2;i++) { fast_memcpy(dst,srcp,p); dst += pitch/2; srcp += stride[1]; } dst = dst2 + pitch*height/4; srcp = src[2]; for (i=0;i<h/2;i++) { fast_memcpy(dst,srcp,p); dst += pitch/2; srcp += stride[2]; } } unlock(); return 0;}static uint32_t put_image(mp_image_t *mpi){// static IDirectFBSurface *tmp = NULL;// DFBSurfaceDescription dsc;// DFBRectangle rect; // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image entered %i %i %i %i %i %i\n",mpi->x,mpi->y,mpi->w,mpi->h,mpi->width,mpi->height); unlock(); // already out? if((mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK))) {// if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image - nothing todo\n"); return VO_TRUE; } if (mpi->flags&MP_IMGFLAG_PLANAR) { // memcpy all planes - sad but necessary int i; unsigned int pitch; void *dst; void *src; unsigned int p;// if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image - planar branch\n"); if (frame) { DFBCHECK (frame->Lock(frame,DSLF_WRITE|DSLF_READ,&dst,&pitch)); framelocked = 1; } else { DFBCHECK (primary->Lock(primary,DSLF_WRITE,&dst,&pitch)); primarylocked = 1; }; p=min(mpi->w,pitch); src = mpi->planes[0]+mpi->y*mpi->stride[0]+mpi->x; for (i=0;i<mpi->h;i++) { fast_memcpy(dst+i*pitch,src+i*mpi->stride[0],p); } if (pixel_format == DSPF_YV12) { dst += pitch*height; p = p/2; src = mpi->planes[2]+mpi->y*mpi->stride[2]+mpi->x/2; for (i=0;i<mpi->h/2;i++) { fast_memcpy(dst+i*pitch/2,src+i*mpi->stride[2],p); } dst += pitch*height/4; src = mpi->planes[1]+mpi->y*mpi->stride[1]+mpi->x/2; for (i=0;i<mpi->h/2;i++) { fast_memcpy(dst+i*pitch/2,src+i*mpi->stride[1],p); } } else { dst += pitch*height; p = p/2; src = mpi->planes[1]+mpi->y*mpi->stride[1]+mpi->x/2; for (i=0;i<mpi->h/2;i++) { fast_memcpy(dst+i*pitch/2,src+i*mpi->stride[1],p); } dst += pitch*height/4; src = mpi->planes[2]+mpi->y*mpi->stride[2]+mpi->x/2; for (i=0;i<mpi->h/2;i++) { fast_memcpy(dst+i*pitch/2,src+i*mpi->stride[2],p); } } unlock(); } else {// I had to disable native directfb blit because it wasn't working under some conditions :-(/* dsc.flags = DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_WIDTH | DSDESC_PREALLOCATED; dsc.preallocated[0].data = mpi->planes[0]; dsc.preallocated[0].pitch = mpi->stride[0]; dsc.width = mpi->width; dsc.height = mpi->height; dsc.pixelformat = convformat(mpi->imgfmt); DFBCHECK (dfb->CreateSurface( dfb, &dsc, &tmp)); rect.x=mpi->x; rect.y=mpi->y; rect.w=mpi->w; rect.h=mpi->h; if (frame) { DFBCHECK (tmp->Blit(tmp,frame,&rect,0,0)); } else { DFBCHECK (tmp->Blit(tmp,primary,&rect,xoffset,yoffset)); }; tmp->Release(tmp);*/ unsigned int pitch; void *dst;// if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image - non planar branch\n"); if (frame) { DFBCHECK (frame->Lock(frame,DSLF_WRITE,&dst,&pitch)); framelocked = 1; mem2agpcpy_pic(dst,mpi->planes[0] + mpi->y * mpi->stride[0] + mpi->x * (mpi->bpp >> 3) ,mpi->w * (mpi->bpp >> 3),mpi->h,pitch,mpi->stride[0]); } else { DFBCHECK (primary->Lock(primary,DSLF_WRITE,&dst,&pitch)); primarylocked = 1; mem2agpcpy_pic(dst + yoffset * pitch + xoffset * (mpi->bpp >> 3),mpi->planes[0] + mpi->y * mpi->stride[0] + mpi->x * (mpi->bpp >> 3) ,mpi->w * (mpi->bpp >> 3),mpi->h,pitch,mpi->stride[0]); }; unlock(); } return VO_TRUE;}static int control(uint32_t request, void *data, ...){ switch (request) { case VOCTRL_QUERY_FORMAT: return query_format(*((uint32_t*)data)); case VOCTRL_GET_IMAGE: return get_image(data); case VOCTRL_DRAW_IMAGE: return put_image(data); case VOCTRL_SET_EQUALIZER: { va_list ap; int value; va_start(ap, data); value = va_arg(ap, int); va_end(ap); return(directfb_set_video_eq(data, value)); } case VOCTRL_GET_EQUALIZER: { va_list ap; int *value; va_start(ap, data); value = va_arg(ap, int*); va_end(ap); return(directfb_get_video_eq(data, value)); } }; return VO_NOTIMPL;}// unused functionstatic int draw_frame(uint8_t *src[]){ return -1;}// hopefully will be removed soonstatic void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, unsigned char *srca, int stride){ void *dst; int pitch; unlock(); // isn't it silly I have to unlock surface and then lock it again :-) if (frame) { DFBCHECK (frame->Lock(frame,DSLF_WRITE|DSLF_READ,&dst,&pitch)); framelocked = 1; } else { DFBCHECK (primary->Lock(primary,DSLF_WRITE,&dst,&pitch)); primarylocked = 1; }; switch(pixel_format) { case DSPF_RGB32: case DSPF_ARGB: vo_draw_alpha_rgb32(w,h,src,srca,stride,((uint8_t *) dst)+pitch*y0 + 4*x0,pitch); break; case DSPF_RGB24: vo_draw_alpha_rgb24(w,h,src,srca,stride,((uint8_t *) dst)+pitch*y0 + 3*x0,pitch); break; case DSPF_RGB16: vo_draw_alpha_rgb16(w,h,src,srca,stride,((uint8_t *) dst)+pitch*y0 + 2*x0,pitch); break;#if DIRECTFBVERSION > DFB_VERSION(0,9,15) case DSPF_ARGB1555:#else case DSPF_RGB15:#endif vo_draw_alpha_rgb15(w,h,src,srca,stride,((uint8_t *) dst)+pitch*y0 + 2*x0,pitch); break; case DSPF_YUY2: vo_draw_alpha_yuy2(w,h,src,srca,stride,((uint8_t *) dst) + pitch*y0 + 2*x0,pitch); break; case DSPF_UYVY: vo_draw_alpha_yuy2(w,h,src,srca,stride,((uint8_t *) dst) + pitch*y0 + 2*x0 + 1,pitch); break; case DSPF_I420: case DSPF_YV12: vo_draw_alpha_yv12(w,h,src,srca,stride,((uint8_t *) dst) + pitch*y0 + 1*x0,pitch); break; } unlock();}static void draw_osd(void){ vo_draw_text(width,height,draw_alpha);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?