• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavfilter/libmpcodecs/vf_rgbtest.c

Go to the documentation of this file.
00001 /*
00002  * This file is part of MPlayer.
00003  *
00004  * MPlayer is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * MPlayer is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License along
00015  * with MPlayer; if not, write to the Free Software Foundation, Inc.,
00016  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00017  */
00018 
00019 #include <stdio.h>
00020 #include <stdlib.h>
00021 #include <string.h>
00022 #include <inttypes.h>
00023 
00024 #include "config.h"
00025 #include "mp_msg.h"
00026 
00027 #include "img_format.h"
00028 #include "mp_image.h"
00029 #include "vf.h"
00030 
00031 //===========================================================================//
00032 
00033 struct vf_priv_s {
00034     unsigned int fmt;
00035     int w, h;
00036 };
00037 
00038 static unsigned int getfmt(unsigned int outfmt){
00039     switch(outfmt){
00040     case IMGFMT_RGB12:
00041     case IMGFMT_RGB15:
00042     case IMGFMT_RGB16:
00043     case IMGFMT_RGB24:
00044     case IMGFMT_RGBA:
00045     case IMGFMT_ARGB:
00046     case IMGFMT_BGR12:
00047     case IMGFMT_BGR15:
00048     case IMGFMT_BGR16:
00049     case IMGFMT_BGR24:
00050     case IMGFMT_BGRA:
00051     case IMGFMT_ABGR:
00052         return outfmt;
00053     }
00054     return 0;
00055 }
00056 
00057 static void put_pixel(uint8_t *buf, int x, int y, int stride, int r, int g, int b, int fmt){
00058     switch(fmt){
00059     case IMGFMT_BGR12: ((uint16_t*)(buf + y*stride))[x]=
00060                            ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4);
00061     break;
00062     case IMGFMT_RGB12: ((uint16_t*)(buf + y*stride))[x]=
00063                            ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4);
00064     break;
00065     case IMGFMT_BGR15: ((uint16_t*)(buf + y*stride))[x]= ((r>>3)<<10) | ((g>>3)<<5) | (b>>3);
00066     break;
00067     case IMGFMT_RGB15: ((uint16_t*)(buf + y*stride))[x]= ((b>>3)<<10) | ((g>>3)<<5) | (r>>3);
00068     break;
00069     case IMGFMT_BGR16: ((uint16_t*)(buf + y*stride))[x]= ((r>>3)<<11) | ((g>>2)<<5) | (b>>3);
00070     break;
00071     case IMGFMT_RGB16: ((uint16_t*)(buf + y*stride))[x]= ((b>>3)<<11) | ((g>>2)<<5) | (r>>3);
00072     break;
00073     case IMGFMT_RGB24:
00074         buf[3*x + y*stride + 0]= r;
00075         buf[3*x + y*stride + 1]= g;
00076         buf[3*x + y*stride + 2]= b;
00077     break;
00078     case IMGFMT_BGR24:
00079         buf[3*x + y*stride + 0]= b;
00080         buf[3*x + y*stride + 1]= g;
00081         buf[3*x + y*stride + 2]= r;
00082     break;
00083     case IMGFMT_RGBA:
00084         buf[4*x + y*stride + 0]= r;
00085         buf[4*x + y*stride + 1]= g;
00086         buf[4*x + y*stride + 2]= b;
00087     break;
00088     case IMGFMT_BGRA:
00089         buf[4*x + y*stride + 0]= b;
00090         buf[4*x + y*stride + 1]= g;
00091         buf[4*x + y*stride + 2]= r;
00092     break;
00093     case IMGFMT_ARGB:
00094         buf[4*x + y*stride + 1]= r;
00095         buf[4*x + y*stride + 2]= g;
00096         buf[4*x + y*stride + 3]= b;
00097     break;
00098     case IMGFMT_ABGR:
00099         buf[4*x + y*stride + 1]= b;
00100         buf[4*x + y*stride + 2]= g;
00101         buf[4*x + y*stride + 3]= r;
00102     break;
00103     }
00104 }
00105 
00106 static int config(struct vf_instance *vf,
00107         int width, int height, int d_width, int d_height,
00108         unsigned int flags, unsigned int outfmt){
00109     if (vf->priv->w > 0) { d_width  = width  = vf->priv->w; }
00110     if (vf->priv->h > 0) { d_height = height = vf->priv->h; }
00111     vf->priv->fmt=getfmt(outfmt);
00112     mp_msg(MSGT_VFILTER,MSGL_V,"rgb test format:%s\n", vo_format_name(outfmt));
00113     return vf_next_config(vf,width,height,d_width,d_height,flags,vf->priv->fmt);
00114 }
00115 
00116 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
00117     mp_image_t *dmpi;
00118     int x, y;
00119     int w = vf->priv->w > 0 ? vf->priv->w : mpi->w;
00120     int h = vf->priv->h > 0 ? vf->priv->h : mpi->h;
00121 
00122     // hope we'll get DR buffer:
00123     dmpi=vf_get_image(vf->next,vf->priv->fmt,
00124         MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
00125         w, h);
00126 
00127      for(y=0; y<h; y++){
00128          for(x=0; x<w; x++){
00129              int c= 256*x/w;
00130              int r=0,g=0,b=0;
00131 
00132              if(3*y<h)        r=c;
00133              else if(3*y<2*h) g=c;
00134              else                  b=c;
00135 
00136              put_pixel(dmpi->planes[0], x, y, dmpi->stride[0], r, g, b, vf->priv->fmt);
00137          }
00138      }
00139 
00140     return vf_next_put_image(vf,dmpi, pts);
00141 }
00142 
00143 //===========================================================================//
00144 
00145 static int query_format(struct vf_instance *vf, unsigned int outfmt){
00146     unsigned int fmt=getfmt(outfmt);
00147     if(!fmt) return 0;
00148     return vf_next_query_format(vf,fmt) & (~VFCAP_CSP_SUPPORTED_BY_HW);
00149 }
00150 
00151 static int vf_open(vf_instance_t *vf, char *args){
00152     vf->config=config;
00153     vf->put_image=put_image;
00154     vf->query_format=query_format;
00155     vf->priv=malloc(sizeof(struct vf_priv_s));
00156     vf->priv->w = vf->priv->h = 0;
00157     if (args)
00158         sscanf(args, "%d:%d", &vf->priv->w, &vf->priv->h);
00159     return 1;
00160 }
00161 
00162 const vf_info_t vf_info_rgbtest = {
00163     "rgbtest",
00164     "rgbtest",
00165     "Michael Niedermayer",
00166     "",
00167     vf_open,
00168     NULL
00169 };
00170 
00171 //===========================================================================//

Generated on Fri Feb 22 2013 07:24:30 for FFmpeg by  doxygen 1.7.1