vf_bmovl.c
来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C语言 代码 · 共 480 行 · 第 1/2 页
C
480 行
else if( strncmp(cmd,"CLEAR" ,5)==0 ) { pxsz=1; command = CMD_CLEAR; } else if( strncmp(cmd,"ALPHA" ,5)==0 ) { pxsz=1; command = CMD_ALPHA; } else if( strncmp(cmd,"OPAQUE",6)==0 ) vf->priv->opaque=TRUE; else if( strncmp(cmd,"SHOW", 4)==0 ) vf->priv->hidden=FALSE; else if( strncmp(cmd,"HIDE", 4)==0 ) vf->priv->hidden=TRUE; else if( strncmp(cmd,"FLUSH" ,5)==0 ) return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); else { mp_msg(MSGT_VFILTER, MSGL_WARN, "\nvf_bmovl: Unknown command: '%s'. Ignoring.\n", cmd); return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); } if(command == CMD_ALPHA) { sscanf( args, "%d %d %d %d %d", &imgw, &imgh, &imgx, &imgy, &imgalpha); mp_msg(MSGT_VFILTER, MSGL_DBG2, "\nDEBUG: ALPHA: %d %d %d %d %d\n\n", imgw, imgh, imgx, imgy, imgalpha); if(imgw==0 && imgh==0) vf->priv->opaque=FALSE; } if(command & IS_RAWIMG) { sscanf( args, "%d %d %d %d %d %d", &imgw, &imgh, &imgx, &imgy, &imgalpha, &clear); mp_msg(MSGT_VFILTER, MSGL_DBG2, "\nDEBUG: RAWIMG: %d %d %d %d %d %d\n\n", imgw, imgh, imgx, imgy, imgalpha, clear); buffer = malloc(imgw*imgh*pxsz); if(!buffer) { mp_msg(MSGT_VFILTER, MSGL_WARN, "\nvf_bmovl: Couldn't allocate temporary buffer! Skipping...\n\n"); return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); } /* pipes/sockets might need multiple calls to read(): */ want = (imgw*imgh*pxsz); have = 0; while (have < want) { got = read( vf->priv->stream_fd, buffer+have, want-have ); if (got == 0) { mp_msg(MSGT_VFILTER, MSGL_WARN, "\nvf_bmovl: premature EOF...\n\n"); break; } if (got < 0) { mp_msg(MSGT_VFILTER, MSGL_WARN, "\nvf_bmovl: read error: %s\n\n", strerror(errno)); break; } have += got; } mp_msg(MSGT_VFILTER, MSGL_DBG2, "Got %d bytes... (wanted %d)\n", have, want ); if(clear) { memset( vf->priv->bitmap.y, 0, vf->priv->w*vf->priv->h ); memset( vf->priv->bitmap.u, 128, vf->priv->w*vf->priv->h/4 ); memset( vf->priv->bitmap.v, 128, vf->priv->w*vf->priv->h/4 ); memset( vf->priv->bitmap.a, 0, vf->priv->w*vf->priv->h ); memset( vf->priv->bitmap.oa, 0, vf->priv->w*vf->priv->h ); vf->priv->x1 = dmpi->width; vf->priv->y1 = dmpi->height; vf->priv->x2 = vf->priv->y2 = 0; } // Define how much of our bitmap that contains graphics! vf->priv->x1 = av_clip(imgx, 0, vf->priv->x1); vf->priv->y1 = av_clip(imgy, 0, vf->priv->y1); vf->priv->x2 = av_clip(imgx + imgw, vf->priv->x2, vf->priv->w); vf->priv->y2 = av_clip(imgy + imgh, vf->priv->y2, vf->priv->h); } if( command == CMD_CLEAR ) { sscanf( args, "%d %d %d %d", &imgw, &imgh, &imgx, &imgy); mp_msg(MSGT_VFILTER, MSGL_DBG2, "\nDEBUG: CLEAR: %d %d %d %d\n\n", imgw, imgh, imgx, imgy); for( ypos=imgy ; (ypos < (imgy+imgh)) && (ypos < vf->priv->y2) ; ypos++ ) { memset( vf->priv->bitmap.y + (ypos*vf->priv->w) + imgx, 0, imgw ); memset( vf->priv->bitmap.a + (ypos*vf->priv->w) + imgx, 0, imgw ); memset( vf->priv->bitmap.oa + (ypos*vf->priv->w) + imgx, 0, imgw ); if(ypos%2) { memset( vf->priv->bitmap.u + ((ypos/2)*dmpi->stride[1]) + (imgx/2), 128, imgw/2 ); memset( vf->priv->bitmap.v + ((ypos/2)*dmpi->stride[2]) + (imgx/2), 128, imgw/2 ); } } // Recalculate area that contains graphics if( (imgx <= vf->priv->x1) && ( (imgw+imgx) >= vf->priv->x2) ) { if( (imgy <= vf->priv->y1) && ( (imgy+imgh) >= vf->priv->y1) ) vf->priv->y1 = imgy+imgh; if( (imgy <= vf->priv->y2) && ( (imgy+imgh) >= vf->priv->y2) ) vf->priv->y2 = imgy; } if( (imgy <= vf->priv->y1) && ( (imgy+imgh) >= vf->priv->y2) ) { if( (imgx <= vf->priv->x1) && ( (imgx+imgw) >= vf->priv->x1) ) vf->priv->x1 = imgx+imgw; if( (imgx <= vf->priv->x2) && ( (imgx+imgw) >= vf->priv->x2) ) vf->priv->x2 = imgx; } return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); } for( buf_y=0 ; (buf_y < imgh) && (buf_y < (vf->priv->h-imgy)) ; buf_y++ ) { for( buf_x=0 ; (buf_x < (imgw*pxsz)) && (buf_x < ((vf->priv->w+imgx)*pxsz)) ; buf_x += pxsz ) { if(command & IS_RAWIMG) buf_pos = (buf_y * imgw * pxsz) + buf_x; pos = ((buf_y+imgy) * vf->priv->w) + ((buf_x/pxsz)+imgx); switch(command) { case IMG_RGBA32: red = buffer[buf_pos+0]; green = buffer[buf_pos+1]; blue = buffer[buf_pos+2]; alpha = buffer[buf_pos+3]; break; case IMG_ABGR32: alpha = buffer[buf_pos+0]; blue = buffer[buf_pos+1]; green = buffer[buf_pos+2]; red = buffer[buf_pos+3]; break; case IMG_RGB24: red = buffer[buf_pos+0]; green = buffer[buf_pos+1]; blue = buffer[buf_pos+2]; alpha = 0xFF; break; case IMG_BGR24: blue = buffer[buf_pos+0]; green = buffer[buf_pos+1]; red = buffer[buf_pos+2]; alpha = 0xFF; break; case CMD_ALPHA: vf->priv->bitmap.a[pos] = INRANGE((vf->priv->bitmap.oa[pos]+imgalpha),0,255); break; default: mp_msg(MSGT_VFILTER, MSGL_ERR, "vf_bmovl: Internal error!\n"); return FALSE; } if( command & IS_RAWIMG ) { vf->priv->bitmap.y[pos] = rgb2y(red,green,blue); vf->priv->bitmap.oa[pos] = alpha; vf->priv->bitmap.a[pos] = INRANGE((alpha+imgalpha),0,255); if((buf_y%2) && ((buf_x/pxsz)%2)) { pos = ( ((buf_y+imgy)/2) * dmpi->stride[1] ) + (((buf_x/pxsz)+imgx)/2); vf->priv->bitmap.u[pos] = rgb2u(red,green,blue); vf->priv->bitmap.v[pos] = rgb2v(red,green,blue); } } } // for buf_x } // for buf_y free (buffer); } else if(ready < 0) { mp_msg(MSGT_VFILTER, MSGL_WARN, "\nvf_bmovl: Error %d in fifo: %s\n\n", errno, strerror(errno)); } } if(vf->priv->hidden) return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); if(vf->priv->opaque) { // Just copy buffer memory to screen for( ypos=vf->priv->y1 ; ypos < vf->priv->y2 ; ypos++ ) { fast_memcpy( dmpi->planes[0] + (ypos*dmpi->stride[0]) + vf->priv->x1, vf->priv->bitmap.y + (ypos*vf->priv->w) + vf->priv->x1, vf->priv->x2 - vf->priv->x1 ); if(ypos%2) { fast_memcpy( dmpi->planes[1] + ((ypos/2)*dmpi->stride[1]) + (vf->priv->x1/2), vf->priv->bitmap.u + (((ypos/2)*(vf->priv->w)/2)) + (vf->priv->x1/2), (vf->priv->x2 - vf->priv->x1)/2 ); fast_memcpy( dmpi->planes[2] + ((ypos/2)*dmpi->stride[2]) + (vf->priv->x1/2), vf->priv->bitmap.v + (((ypos/2)*(vf->priv->w)/2)) + (vf->priv->x1/2), (vf->priv->x2 - vf->priv->x1)/2 ); } } } else { // Blit the bitmap to the videoscreen, pixel for pixel for( ypos=vf->priv->y1 ; ypos < vf->priv->y2 ; ypos++ ) { for ( xpos=vf->priv->x1 ; xpos < vf->priv->x2 ; xpos++ ) { pos = (ypos * dmpi->stride[0]) + xpos; alpha = vf->priv->bitmap.a[pos]; if (alpha == 0) continue; // Completly transparent pixel if (alpha == 255) { // Opaque pixel dmpi->planes[0][pos] = vf->priv->bitmap.y[pos]; if ((ypos%2) && (xpos%2)) { pos = ( (ypos/2) * dmpi->stride[1] ) + (xpos/2); dmpi->planes[1][pos] = vf->priv->bitmap.u[pos]; dmpi->planes[2][pos] = vf->priv->bitmap.v[pos]; } } else { // Alphablended pixel dmpi->planes[0][pos] = ((255 - alpha) * (int)dmpi->planes[0][pos] + alpha * (int)vf->priv->bitmap.y[pos]) >> 8; if ((ypos%2) && (xpos%2)) { pos = ( (ypos/2) * dmpi->stride[1] ) + (xpos/2); dmpi->planes[1][pos] = ((255 - alpha) * (int)dmpi->planes[1][pos] + alpha * (int)vf->priv->bitmap.u[pos]) >> 8; dmpi->planes[2][pos] = ((255 - alpha) * (int)dmpi->planes[2][pos] + alpha * (int)vf->priv->bitmap.v[pos]) >> 8; } } } // for xpos } // for ypos } // if !opaque return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);} // put_imagestatic intvf_open(vf_instance_t* vf, char* args){ char filename[1000]; vf->config = config; vf->put_image = put_image; vf->query_format = query_format; vf->uninit = uninit; vf->priv = malloc(sizeof(struct vf_priv_s)); if(!args || sscanf(args, "%d:%d:%s", &vf->priv->hidden, &vf->priv->opaque, filename) < 3 ) { mp_msg(MSGT_VFILTER, MSGL_ERR, "vf_bmovl: Bad arguments!\n"); mp_msg(MSGT_VFILTER, MSGL_ERR, "vf_bmovl: Arguments are 'bool hidden:bool opaque:string fifo'\n"); return FALSE; } vf->priv->stream_fd = open(filename, O_RDWR); if(vf->priv->stream_fd >= 0) { FD_ZERO( &vf->priv->stream_fdset ); mp_msg(MSGT_VFILTER, MSGL_INFO, "vf_bmovl: Opened fifo %s as FD %d\n", filename, vf->priv->stream_fd); } else { mp_msg(MSGT_VFILTER, MSGL_WARN, "vf_bmovl: Error! Couldn't open FIFO %s: %s\n", filename, strerror(errno)); vf->priv->stream_fd = -1; } return TRUE;}vf_info_t vf_info_bmovl = { "Read bitmaps from a FIFO and display them in window", "bmovl", "Per Wigren", "", vf_open, NULL};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?