options: change -alang and -slang to use string list type
[mplayer.git] / libmpcodecs / vf_rgbtest.c
blob917993417537892f66a790af2de85bed04fe7d0e
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <inttypes.h>
24 #include "config.h"
25 #include "mp_msg.h"
27 #include "img_format.h"
28 #include "mp_image.h"
29 #include "vf.h"
31 //===========================================================================//
33 struct vf_priv_s {
34 unsigned int fmt;
35 int w, h;
38 static unsigned int getfmt(unsigned int outfmt){
39 switch(outfmt){
40 case IMGFMT_RGB12:
41 case IMGFMT_RGB15:
42 case IMGFMT_RGB16:
43 case IMGFMT_RGB24:
44 case IMGFMT_RGBA:
45 case IMGFMT_ARGB:
46 case IMGFMT_BGR12:
47 case IMGFMT_BGR15:
48 case IMGFMT_BGR16:
49 case IMGFMT_BGR24:
50 case IMGFMT_BGRA:
51 case IMGFMT_ABGR:
52 return outfmt;
54 return 0;
57 static void put_pixel(uint8_t *buf, int x, int y, int stride, int r, int g, int b, int fmt){
58 switch(fmt){
59 case IMGFMT_BGR12: ((uint16_t*)(buf + y*stride))[x]=
60 ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4);
61 break;
62 case IMGFMT_RGB12: ((uint16_t*)(buf + y*stride))[x]=
63 ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4);
64 break;
65 case IMGFMT_BGR15: ((uint16_t*)(buf + y*stride))[x]= ((r>>3)<<10) | ((g>>3)<<5) | (b>>3);
66 break;
67 case IMGFMT_RGB15: ((uint16_t*)(buf + y*stride))[x]= ((b>>3)<<10) | ((g>>3)<<5) | (r>>3);
68 break;
69 case IMGFMT_BGR16: ((uint16_t*)(buf + y*stride))[x]= ((r>>3)<<11) | ((g>>2)<<5) | (b>>3);
70 break;
71 case IMGFMT_RGB16: ((uint16_t*)(buf + y*stride))[x]= ((b>>3)<<11) | ((g>>2)<<5) | (r>>3);
72 break;
73 case IMGFMT_RGB24:
74 buf[3*x + y*stride + 0]= r;
75 buf[3*x + y*stride + 1]= g;
76 buf[3*x + y*stride + 2]= b;
77 break;
78 case IMGFMT_BGR24:
79 buf[3*x + y*stride + 0]= b;
80 buf[3*x + y*stride + 1]= g;
81 buf[3*x + y*stride + 2]= r;
82 break;
83 case IMGFMT_RGBA:
84 buf[4*x + y*stride + 0]= r;
85 buf[4*x + y*stride + 1]= g;
86 buf[4*x + y*stride + 2]= b;
87 break;
88 case IMGFMT_BGRA:
89 buf[4*x + y*stride + 0]= b;
90 buf[4*x + y*stride + 1]= g;
91 buf[4*x + y*stride + 2]= r;
92 break;
93 case IMGFMT_ARGB:
94 buf[4*x + y*stride + 1]= r;
95 buf[4*x + y*stride + 2]= g;
96 buf[4*x + y*stride + 3]= b;
97 break;
98 case IMGFMT_ABGR:
99 buf[4*x + y*stride + 1]= b;
100 buf[4*x + y*stride + 2]= g;
101 buf[4*x + y*stride + 3]= r;
102 break;
106 static int config(struct vf_instance *vf,
107 int width, int height, int d_width, int d_height,
108 unsigned int flags, unsigned int outfmt){
109 if (vf->priv->w > 0) { d_width = width = vf->priv->w; }
110 if (vf->priv->h > 0) { d_height = height = vf->priv->h; }
111 vf->priv->fmt=getfmt(outfmt);
112 mp_msg(MSGT_VFILTER,MSGL_V,"rgb test format:%s\n", vo_format_name(outfmt));
113 return vf_next_config(vf,width,height,d_width,d_height,flags,vf->priv->fmt);
116 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
117 mp_image_t *dmpi;
118 int x, y;
119 int w = vf->priv->w > 0 ? vf->priv->w : mpi->w;
120 int h = vf->priv->h > 0 ? vf->priv->h : mpi->h;
122 // hope we'll get DR buffer:
123 dmpi=vf_get_image(vf->next,vf->priv->fmt,
124 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
125 w, h);
127 for(y=0; y<h; y++){
128 for(x=0; x<w; x++){
129 int c= 256*x/w;
130 int r=0,g=0,b=0;
132 if(3*y<h) r=c;
133 else if(3*y<2*h) g=c;
134 else b=c;
136 put_pixel(dmpi->planes[0], x, y, dmpi->stride[0], r, g, b, vf->priv->fmt);
140 return vf_next_put_image(vf,dmpi, pts);
143 //===========================================================================//
145 static int query_format(struct vf_instance *vf, unsigned int outfmt){
146 unsigned int fmt=getfmt(outfmt);
147 if(!fmt) return 0;
148 return vf_next_query_format(vf,fmt) & (~VFCAP_CSP_SUPPORTED_BY_HW);
151 static int vf_open(vf_instance_t *vf, char *args){
152 vf->config=config;
153 vf->put_image=put_image;
154 vf->query_format=query_format;
155 vf->priv=malloc(sizeof(struct vf_priv_s));
156 vf->priv->w = vf->priv->h = 0;
157 if (args)
158 sscanf(args, "%d:%d", &vf->priv->w, &vf->priv->h);
159 return 1;
162 const vf_info_t vf_info_rgbtest = {
163 "rgbtest",
164 "rgbtest",
165 "Michael Niedermayer",
167 vf_open,
168 NULL
171 //===========================================================================//