Whitespace-only cosmetics: get rid of all remaining tabs
[mplayer/glamo.git] / libmpcodecs / vf_rgbtest.c
blobf038bba622d1bb093534829741c6834c37686887
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <inttypes.h>
6 #include "config.h"
7 #include "mp_msg.h"
9 #include "img_format.h"
10 #include "mp_image.h"
11 #include "vf.h"
13 #include "libvo/fastmemcpy.h"
15 //===========================================================================//
17 struct vf_priv_s {
18 unsigned int fmt;
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_RGBA:
27 case IMGFMT_ARGB:
28 case IMGFMT_BGR15:
29 case IMGFMT_BGR16:
30 case IMGFMT_BGR24:
31 case IMGFMT_BGRA:
32 case IMGFMT_ABGR:
33 return outfmt;
35 return 0;
38 static void put_pixel(uint8_t *buf, int x, int y, int stride, int r, int g, int b, int fmt){
39 switch(fmt){
40 case IMGFMT_BGR15: ((uint16_t*)(buf + y*stride))[x]= ((r>>3)<<10) | ((g>>3)<<5) | (b>>3);
41 break;
42 case IMGFMT_RGB15: ((uint16_t*)(buf + y*stride))[x]= ((b>>3)<<10) | ((g>>3)<<5) | (r>>3);
43 break;
44 case IMGFMT_BGR16: ((uint16_t*)(buf + y*stride))[x]= ((r>>3)<<11) | ((g>>2)<<5) | (b>>3);
45 break;
46 case IMGFMT_RGB16: ((uint16_t*)(buf + y*stride))[x]= ((b>>3)<<11) | ((g>>2)<<5) | (r>>3);
47 break;
48 case IMGFMT_RGB24:
49 buf[3*x + y*stride + 0]= r;
50 buf[3*x + y*stride + 1]= g;
51 buf[3*x + y*stride + 2]= b;
52 break;
53 case IMGFMT_BGR24:
54 buf[3*x + y*stride + 0]= b;
55 buf[3*x + y*stride + 1]= g;
56 buf[3*x + y*stride + 2]= r;
57 break;
58 case IMGFMT_RGBA:
59 buf[4*x + y*stride + 0]= r;
60 buf[4*x + y*stride + 1]= g;
61 buf[4*x + y*stride + 2]= b;
62 break;
63 case IMGFMT_BGRA:
64 buf[4*x + y*stride + 0]= b;
65 buf[4*x + y*stride + 1]= g;
66 buf[4*x + y*stride + 2]= r;
67 break;
68 case IMGFMT_ARGB:
69 buf[4*x + y*stride + 1]= r;
70 buf[4*x + y*stride + 2]= g;
71 buf[4*x + y*stride + 3]= b;
72 break;
73 case IMGFMT_ABGR:
74 buf[4*x + y*stride + 1]= b;
75 buf[4*x + y*stride + 2]= g;
76 buf[4*x + y*stride + 3]= r;
77 break;
81 static int config(struct vf_instance_s* vf,
82 int width, int height, int d_width, int d_height,
83 unsigned int flags, unsigned int outfmt){
84 vf->priv->fmt=getfmt(outfmt);
85 mp_msg(MSGT_VFILTER,MSGL_V,"rgb test format:%s\n", vo_format_name(outfmt));
86 return vf_next_config(vf,width,height,d_width,d_height,flags,vf->priv->fmt);
89 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){
90 mp_image_t *dmpi;
91 int x, y;
93 // hope we'll get DR buffer:
94 dmpi=vf_get_image(vf->next,vf->priv->fmt,
95 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
96 mpi->w, mpi->h);
98 for(y=0; y<mpi->h; y++){
99 for(x=0; x<mpi->w; x++){
100 int c= 256*x/mpi->w;
101 int r=0,g=0,b=0;
103 if(3*y<mpi->h) r=c;
104 else if(3*y<2*mpi->h) g=c;
105 else b=c;
107 put_pixel(dmpi->planes[0], x, y, dmpi->stride[0], r, g, b, vf->priv->fmt);
111 return vf_next_put_image(vf,dmpi, pts);
114 //===========================================================================//
116 static int query_format(struct vf_instance_s* vf, unsigned int outfmt){
117 unsigned int fmt=getfmt(outfmt);
118 if(!fmt) return 0;
119 return vf_next_query_format(vf,fmt) & (~VFCAP_CSP_SUPPORTED_BY_HW);
122 static int open(vf_instance_t *vf, char* args){
123 vf->config=config;
124 vf->put_image=put_image;
125 vf->query_format=query_format;
126 vf->priv=malloc(sizeof(struct vf_priv_s));
127 return 1;
130 vf_info_t vf_info_rgbtest = {
131 "rgbtest",
132 "rgbtest",
133 "Michael Niedermayer",
135 open,
136 NULL
139 //===========================================================================//