Get rid of nuppelvideo.h and its ugly packed struct and instead write the
[mplayer/glamo.git] / libmpcodecs / vf_rgbtest.c
blob4351956da24df200bc036ff6a4351b0028a0b645
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 //===========================================================================//
15 struct vf_priv_s {
16 unsigned int fmt;
17 int w, h;
20 static unsigned int getfmt(unsigned int outfmt){
21 switch(outfmt){
22 case IMGFMT_RGB15:
23 case IMGFMT_RGB16:
24 case IMGFMT_RGB24:
25 case IMGFMT_RGBA:
26 case IMGFMT_ARGB:
27 case IMGFMT_BGR15:
28 case IMGFMT_BGR16:
29 case IMGFMT_BGR24:
30 case IMGFMT_BGRA:
31 case IMGFMT_ABGR:
32 return outfmt;
34 return 0;
37 static void put_pixel(uint8_t *buf, int x, int y, int stride, int r, int g, int b, int fmt){
38 switch(fmt){
39 case IMGFMT_BGR15: ((uint16_t*)(buf + y*stride))[x]= ((r>>3)<<10) | ((g>>3)<<5) | (b>>3);
40 break;
41 case IMGFMT_RGB15: ((uint16_t*)(buf + y*stride))[x]= ((b>>3)<<10) | ((g>>3)<<5) | (r>>3);
42 break;
43 case IMGFMT_BGR16: ((uint16_t*)(buf + y*stride))[x]= ((r>>3)<<11) | ((g>>2)<<5) | (b>>3);
44 break;
45 case IMGFMT_RGB16: ((uint16_t*)(buf + y*stride))[x]= ((b>>3)<<11) | ((g>>2)<<5) | (r>>3);
46 break;
47 case IMGFMT_RGB24:
48 buf[3*x + y*stride + 0]= r;
49 buf[3*x + y*stride + 1]= g;
50 buf[3*x + y*stride + 2]= b;
51 break;
52 case IMGFMT_BGR24:
53 buf[3*x + y*stride + 0]= b;
54 buf[3*x + y*stride + 1]= g;
55 buf[3*x + y*stride + 2]= r;
56 break;
57 case IMGFMT_RGBA:
58 buf[4*x + y*stride + 0]= r;
59 buf[4*x + y*stride + 1]= g;
60 buf[4*x + y*stride + 2]= b;
61 break;
62 case IMGFMT_BGRA:
63 buf[4*x + y*stride + 0]= b;
64 buf[4*x + y*stride + 1]= g;
65 buf[4*x + y*stride + 2]= r;
66 break;
67 case IMGFMT_ARGB:
68 buf[4*x + y*stride + 1]= r;
69 buf[4*x + y*stride + 2]= g;
70 buf[4*x + y*stride + 3]= b;
71 break;
72 case IMGFMT_ABGR:
73 buf[4*x + y*stride + 1]= b;
74 buf[4*x + y*stride + 2]= g;
75 buf[4*x + y*stride + 3]= r;
76 break;
80 static int config(struct vf_instance_s* vf,
81 int width, int height, int d_width, int d_height,
82 unsigned int flags, unsigned int outfmt){
83 if (vf->priv->w > 0) { d_width = width = vf->priv->w; }
84 if (vf->priv->h > 0) { d_height = height = vf->priv->h; }
85 vf->priv->fmt=getfmt(outfmt);
86 mp_msg(MSGT_VFILTER,MSGL_V,"rgb test format:%s\n", vo_format_name(outfmt));
87 return vf_next_config(vf,width,height,d_width,d_height,flags,vf->priv->fmt);
90 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){
91 mp_image_t *dmpi;
92 int x, y;
93 int w = vf->priv->w > 0 ? vf->priv->w : mpi->w;
94 int h = vf->priv->h > 0 ? vf->priv->h : mpi->h;
96 // hope we'll get DR buffer:
97 dmpi=vf_get_image(vf->next,vf->priv->fmt,
98 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
99 w, h);
101 for(y=0; y<h; y++){
102 for(x=0; x<w; x++){
103 int c= 256*x/w;
104 int r=0,g=0,b=0;
106 if(3*y<h) r=c;
107 else if(3*y<2*h) g=c;
108 else b=c;
110 put_pixel(dmpi->planes[0], x, y, dmpi->stride[0], r, g, b, vf->priv->fmt);
114 return vf_next_put_image(vf,dmpi, pts);
117 //===========================================================================//
119 static int query_format(struct vf_instance_s* vf, unsigned int outfmt){
120 unsigned int fmt=getfmt(outfmt);
121 if(!fmt) return 0;
122 return vf_next_query_format(vf,fmt) & (~VFCAP_CSP_SUPPORTED_BY_HW);
125 static int open(vf_instance_t *vf, char* args){
126 vf->config=config;
127 vf->put_image=put_image;
128 vf->query_format=query_format;
129 vf->priv=malloc(sizeof(struct vf_priv_s));
130 vf->priv->w = vf->priv->h = 0;
131 if (args)
132 sscanf(args, "%d:%d", &vf->priv->w, &vf->priv->h);
133 return 1;
136 const vf_info_t vf_info_rgbtest = {
137 "rgbtest",
138 "rgbtest",
139 "Michael Niedermayer",
141 open,
142 NULL
145 //===========================================================================//