Mercurial > mplayer.hg
comparison libmpcodecs/vf_rgbtest.c @ 11894:4c24bad2a86b
rgb test pattern generator, so we could change everything to match alex's definition of rgb/bgr
author | michael |
---|---|
date | Fri, 30 Jan 2004 17:38:15 +0000 |
parents | |
children | be7ed0dfe056 |
comparison
equal
deleted
inserted
replaced
11893:cf34e63146bf | 11894:4c24bad2a86b |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include <inttypes.h> | |
5 | |
6 #include "../config.h" | |
7 #include "../mp_msg.h" | |
8 | |
9 #include "img_format.h" | |
10 #include "mp_image.h" | |
11 #include "vf.h" | |
12 | |
13 #include "../libvo/fastmemcpy.h" | |
14 | |
15 //===========================================================================// | |
16 | |
17 struct vf_priv_s { | |
18 unsigned int fmt; | |
19 }; | |
20 | |
21 static unsigned int getfmt(unsigned int outfmt){ | |
22 switch(outfmt){ | |
23 case IMGFMT_RGB15: | |
24 case IMGFMT_RGB16: | |
25 case IMGFMT_RGB24: | |
26 case IMGFMT_RGB32: | |
27 case IMGFMT_BGR15: | |
28 case IMGFMT_BGR16: | |
29 case IMGFMT_BGR24: | |
30 case IMGFMT_BGR32: | |
31 return outfmt; | |
32 } | |
33 return 0; | |
34 } | |
35 | |
36 static void put_pixel(uint8_t *buf, int x, int y, int stride, int r, int g, int b, int fmt){ | |
37 switch(fmt){ | |
38 case IMGFMT_RGB15: ((uint16_t*)(buf + y*stride))[x]= ((r>>3)<<10) | ((g>>3)<<5) | (b>>3); | |
39 break; | |
40 case IMGFMT_BGR15: ((uint16_t*)(buf + y*stride))[x]= ((b>>3)<<10) | ((g>>3)<<5) | (r>>3); | |
41 break; | |
42 case IMGFMT_RGB16: ((uint16_t*)(buf + y*stride))[x]= ((r>>3)<<11) | ((g>>2)<<5) | (b>>3); | |
43 break; | |
44 case IMGFMT_BGR16: ((uint16_t*)(buf + y*stride))[x]= ((b>>3)<<11) | ((g>>2)<<5) | (r>>3); | |
45 break; | |
46 /* case IMGFMT_RGB32_ME: ((uint32_t*)(buf + y*stride))[x]= (r<<16) | (g<<8) | b; | |
47 break; | |
48 case IMGFMT_BGR32_ME: ((uint32_t*)(buf + y*stride))[x]= (b<<16) | (g<<8) | r; | |
49 break;*/ | |
50 case IMGFMT_RGB24: | |
51 buf[3*x + y*stride + 0]= r; | |
52 buf[3*x + y*stride + 1]= g; | |
53 buf[3*x + y*stride + 2]= b; | |
54 break; | |
55 case IMGFMT_BGR24: | |
56 buf[3*x + y*stride + 0]= b; | |
57 buf[3*x + y*stride + 1]= g; | |
58 buf[3*x + y*stride + 2]= r; | |
59 break; | |
60 case IMGFMT_RGB32: | |
61 buf[4*x + y*stride + 0]= r; | |
62 buf[4*x + y*stride + 1]= g; | |
63 buf[4*x + y*stride + 2]= b; | |
64 break; | |
65 case IMGFMT_BGR32: | |
66 buf[4*x + y*stride + 0]= b; | |
67 buf[4*x + y*stride + 1]= g; | |
68 buf[4*x + y*stride + 2]= r; | |
69 break; | |
70 /* case IMGFMT_ARGB32: | |
71 buf[4*x + y*stride + 1]= r; | |
72 buf[4*x + y*stride + 2]= g; | |
73 buf[4*x + y*stride + 3]= b; | |
74 break; | |
75 case IMGFMT_ABGR32: | |
76 buf[4*x + y*stride + 1]= b; | |
77 buf[4*x + y*stride + 2]= g; | |
78 buf[4*x + y*stride + 3]= r; | |
79 break;*/ | |
80 } | |
81 } | |
82 | |
83 static int config(struct vf_instance_s* vf, | |
84 int width, int height, int d_width, int d_height, | |
85 unsigned int flags, unsigned int outfmt){ | |
86 vf->priv->fmt=getfmt(outfmt); | |
87 mp_msg(MSGT_VFILTER,MSGL_V,"rgb test format:%s\n", vo_format_name(outfmt)); | |
88 return vf_next_config(vf,width,height,d_width,d_height,flags,vf->priv->fmt); | |
89 } | |
90 | |
91 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ | |
92 mp_image_t *dmpi; | |
93 int x, y; | |
94 | |
95 // hope we'll get DR buffer: | |
96 dmpi=vf_get_image(vf->next,vf->priv->fmt, | |
97 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, | |
98 mpi->w, mpi->h); | |
99 | |
100 for(y=0; y<mpi->h; y++){ | |
101 for(x=0; x<mpi->w; x++){ | |
102 int c= 256*x/mpi->w; | |
103 int r=0,g=0,b=0; | |
104 | |
105 if(3*y<mpi->h) r=c; | |
106 else if(3*y<2*mpi->h) g=c; | |
107 else b=c; | |
108 | |
109 put_pixel(dmpi->planes[0], x, y, dmpi->stride[0], r, g, b, vf->priv->fmt); | |
110 } | |
111 } | |
112 | |
113 return vf_next_put_image(vf,dmpi); | |
114 } | |
115 | |
116 //===========================================================================// | |
117 | |
118 static int query_format(struct vf_instance_s* vf, unsigned int outfmt){ | |
119 unsigned int fmt=getfmt(outfmt); | |
120 if(!fmt) return 0; | |
121 return vf_next_query_format(vf,fmt) & (~VFCAP_CSP_SUPPORTED_BY_HW); | |
122 } | |
123 | |
124 static int open(vf_instance_t *vf, char* args){ | |
125 vf->config=config; | |
126 vf->put_image=put_image; | |
127 vf->query_format=query_format; | |
128 vf->priv=malloc(sizeof(struct vf_priv_s)); | |
129 return 1; | |
130 } | |
131 | |
132 vf_info_t vf_info_rgbtest = { | |
133 "rgbtest", | |
134 "rgbtest", | |
135 "Michael Niedermayer", | |
136 "", | |
137 open, | |
138 NULL | |
139 }; | |
140 | |
141 //===========================================================================// |