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

libavfilter/libmpcodecs/vf_test.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
00003  *
00004  * This file is part of MPlayer.
00005  *
00006  * MPlayer is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * MPlayer is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License along
00017  * with MPlayer; if not, write to the Free Software Foundation, Inc.,
00018  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00019  */
00020 
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <inttypes.h>
00025 
00026 #include "config.h"
00027 #include "mp_msg.h"
00028 #include "help_mp.h"
00029 
00030 #include "img_format.h"
00031 #include "mp_image.h"
00032 #include "vf.h"
00033 
00034 //===========================================================================//
00035 
00036 #include <inttypes.h>
00037 #include <math.h>
00038 
00039 #define MAX(a,b) ((a) > (b) ? (a) : (b))
00040 #define MIN(a,b) ((a) < (b) ? (a) : (b))
00041 #define ABS(a,b) ((a) > 0 ? (a) : -(a))
00042 
00043 #define WIDTH 512
00044 #define HEIGHT 512
00045 
00046 struct vf_priv_s {
00047     int frame_num;
00048 };
00049 
00050 static int config(struct vf_instance *vf,
00051         int width, int height, int d_width, int d_height,
00052         unsigned int flags, unsigned int outfmt){
00053 
00054     if(vf_next_query_format(vf,IMGFMT_YV12)<=0){
00055         mp_msg(MSGT_VFILTER, MSGL_WARN, MSGTR_MPCODECS_WarnNextFilterDoesntSupport, "YV12");
00056         return 0;
00057     }
00058 
00059     //hmm whats the meaning of these ... ;)
00060     d_width= width= WIDTH;
00061     d_height= height= HEIGHT;
00062 
00063     return vf_next_config(vf,width,height,d_width,d_height,flags,IMGFMT_YV12);
00064 }
00065 
00066 static double c[64];
00067 
00068 static void initIdct(void)
00069 {
00070         int i;
00071 
00072         for (i=0; i<8; i++)
00073         {
00074                 double s= i==0 ? sqrt(0.125) : 0.5;
00075                 int j;
00076 
00077                 for(j=0; j<8; j++)
00078                         c[i*8+j]= s*cos((3.141592654/8.0)*i*(j+0.5));
00079         }
00080 }
00081 
00082 
00083 static void idct(uint8_t *dst, int dstStride, int src[64])
00084 {
00085         int i, j, k;
00086         double tmp[64];
00087 
00088         for(i=0; i<8; i++)
00089         {
00090                 for(j=0; j<8; j++)
00091                 {
00092                         double sum= 0.0;
00093 
00094                         for(k=0; k<8; k++)
00095                                 sum+= c[k*8+j]*src[8*i+k];
00096 
00097                         tmp[8*i+j]= sum;
00098                 }
00099         }
00100 
00101         for(j=0; j<8; j++)
00102         {
00103                 for(i=0; i<8; i++)
00104                 {
00105                         int v;
00106                         double sum= 0.0;
00107 
00108                         for(k=0; k<8; k++)
00109                                 sum+= c[k*8+i]*tmp[8*k+j];
00110 
00111                         v= (int)floor(sum+0.5);
00112                         if(v<0) v=0;
00113                         else if(v>255) v=255;
00114 
00115                         dst[dstStride*i + j] = v;
00116                 }
00117         }
00118 }
00119 
00120 static void drawDc(uint8_t *dst, int stride, int color, int w, int h)
00121 {
00122         int y;
00123         for(y=0; y<h; y++)
00124         {
00125                 int x;
00126                 for(x=0; x<w; x++)
00127                 {
00128                         dst[x + y*stride]= color;
00129                 }
00130         }
00131 }
00132 
00133 static void drawBasis(uint8_t *dst, int stride, int amp, int freq, int dc)
00134 {
00135         int src[64];
00136 
00137         memset(src, 0, 64*sizeof(int));
00138         src[0]= dc;
00139         if(amp) src[freq]= amp;
00140         idct(dst, stride, src);
00141 }
00142 
00143 static void drawCbp(uint8_t *dst[3], int stride[3], int cbp, int amp, int dc)
00144 {
00145         if(cbp&1) drawBasis(dst[0]              , stride[0], amp, 1, dc);
00146         if(cbp&2) drawBasis(dst[0]+8            , stride[0], amp, 1, dc);
00147         if(cbp&4) drawBasis(dst[0]+  8*stride[0], stride[0], amp, 1, dc);
00148         if(cbp&8) drawBasis(dst[0]+8+8*stride[0], stride[0], amp, 1, dc);
00149         if(cbp&16)drawBasis(dst[1]              , stride[1], amp, 1, dc);
00150         if(cbp&32)drawBasis(dst[2]              , stride[2], amp, 1, dc);
00151 }
00152 
00153 static void dc1Test(uint8_t *dst, int stride, int w, int h, int off)
00154 {
00155         const int step= MAX(256/(w*h/256), 1);
00156         int y;
00157         int color=off;
00158         for(y=0; y<h; y+=16)
00159         {
00160                 int x;
00161                 for(x=0; x<w; x+=16)
00162                 {
00163                         drawDc(dst + x + y*stride, stride, color, 8, 8);
00164                         color+=step;
00165                 }
00166         }
00167 }
00168 
00169 static void freq1Test(uint8_t *dst, int stride, int off)
00170 {
00171         int y;
00172         int freq=0;
00173         for(y=0; y<8*16; y+=16)
00174         {
00175                 int x;
00176                 for(x=0; x<8*16; x+=16)
00177                 {
00178                         drawBasis(dst + x + y*stride, stride, 4*(96+off), freq, 128*8);
00179                         freq++;
00180                 }
00181         }
00182 }
00183 
00184 static void amp1Test(uint8_t *dst, int stride, int off)
00185 {
00186         int y;
00187         int amp=off;
00188         for(y=0; y<16*16; y+=16)
00189         {
00190                 int x;
00191                 for(x=0; x<16*16; x+=16)
00192                 {
00193                         drawBasis(dst + x + y*stride, stride, 4*(amp), 1, 128*8);
00194                         amp++;
00195                 }
00196         }
00197 }
00198 
00199 static void cbp1Test(uint8_t *dst[3], int stride[3], int off)
00200 {
00201         int y;
00202         int cbp=0;
00203         for(y=0; y<16*8; y+=16)
00204         {
00205                 int x;
00206                 for(x=0; x<16*8; x+=16)
00207                 {
00208                         uint8_t *dst1[3];
00209                         dst1[0]= dst[0] + x*2 + y*2*stride[0];
00210                         dst1[1]= dst[1] + x + y*stride[1];
00211                         dst1[2]= dst[2] + x + y*stride[2];
00212 
00213                         drawCbp(dst1, stride, cbp, (64+off)*4, 128*8);
00214                         cbp++;
00215                 }
00216         }
00217 }
00218 
00219 static void mv1Test(uint8_t *dst, int stride, int off)
00220 {
00221         int y;
00222         for(y=0; y<16*16; y++)
00223         {
00224                 int x;
00225                 if(y&16) continue;
00226                 for(x=0; x<16*16; x++)
00227                 {
00228                         dst[x + y*stride]= x + off*8/(y/32+1);
00229                 }
00230         }
00231 }
00232 
00233 static void ring1Test(uint8_t *dst, int stride, int off)
00234 {
00235         int y;
00236         int color=0;
00237         for(y=off; y<16*16; y+=16)
00238         {
00239                 int x;
00240                 for(x=off; x<16*16; x+=16)
00241                 {
00242                         drawDc(dst + x + y*stride, stride, ((x+y)&16) ? color : -color, 16, 16);
00243 //                        dst[x + y*stride]= 255 + (off&1);
00244                         color++;
00245                 }
00246         }
00247 }
00248 
00249 static void ring2Test(uint8_t *dst, int stride, int off)
00250 {
00251         int y;
00252         for(y=0; y<16*16; y++)
00253         {
00254                 int x;
00255                 for(x=0; x<16*16; x++)
00256                 {
00257                         double d= sqrt((x-8*16)*(x-8*16) + (y-8*16)*(y-8*16));
00258                         double r= d/20 - (int)(d/20);
00259                         if(r<off/30.0)
00260                         {
00261                                 dst[x + y*stride]= 255;
00262                                 dst[x + y*stride+256]= 0;
00263                         }
00264                         else{
00265                                 dst[x + y*stride]= x;
00266                                 dst[x + y*stride+256]= x;
00267                         }
00268                 }
00269         }
00270 }
00271 
00272 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
00273     mp_image_t *dmpi;
00274     int frame= vf->priv->frame_num;
00275 
00276     // hope we'll get DR buffer:
00277     dmpi=vf_get_image(vf->next,IMGFMT_YV12,
00278         MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
00279         WIDTH, HEIGHT);
00280 
00281     // clean
00282     memset(dmpi->planes[0], 0, dmpi->stride[0]*dmpi->h);
00283     memset(dmpi->planes[1], 128, dmpi->stride[1]*dmpi->h>>dmpi->chroma_y_shift);
00284     memset(dmpi->planes[2], 128, dmpi->stride[2]*dmpi->h>>dmpi->chroma_y_shift);
00285 
00286     if(frame%30)
00287     {
00288         switch(frame/30)
00289         {
00290         case 0:   dc1Test(dmpi->planes[0], dmpi->stride[0], 256, 256, frame%30); break;
00291         case 1:   dc1Test(dmpi->planes[1], dmpi->stride[1], 256, 256, frame%30); break;
00292         case 2: freq1Test(dmpi->planes[0], dmpi->stride[0], frame%30); break;
00293         case 3: freq1Test(dmpi->planes[1], dmpi->stride[1], frame%30); break;
00294         case 4:  amp1Test(dmpi->planes[0], dmpi->stride[0], frame%30); break;
00295         case 5:  amp1Test(dmpi->planes[1], dmpi->stride[1], frame%30); break;
00296         case 6:  cbp1Test(dmpi->planes   , dmpi->stride   , frame%30); break;
00297         case 7:   mv1Test(dmpi->planes[0], dmpi->stride[0], frame%30); break;
00298         case 8: ring1Test(dmpi->planes[0], dmpi->stride[0], frame%30); break;
00299         case 9: ring2Test(dmpi->planes[0], dmpi->stride[0], frame%30); break;
00300         }
00301     }
00302 
00303     frame++;
00304     vf->priv->frame_num= frame;
00305     return vf_next_put_image(vf,dmpi, pts);
00306 }
00307 
00308 //===========================================================================//
00309 
00310 static int query_format(struct vf_instance *vf, unsigned int fmt){
00311     return vf_next_query_format(vf,IMGFMT_YV12) & (~VFCAP_CSP_SUPPORTED_BY_HW);
00312 }
00313 
00314 static int vf_open(vf_instance_t *vf, char *args){
00315     vf->config=config;
00316     vf->put_image=put_image;
00317     vf->query_format=query_format;
00318     vf->priv=malloc(sizeof(struct vf_priv_s));
00319     vf->priv->frame_num= args ? atoi(args) : 0;
00320     initIdct();
00321     return 1;
00322 }
00323 
00324 const vf_info_t vf_info_test = {
00325     "test pattern generator",
00326     "test",
00327     "Michael Niedermayer",
00328     "",
00329     vf_open,
00330     NULL
00331 };
00332 
00333 //===========================================================================//

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