Use proper length specifiers in mp_msg calls, fixes the warnings:
[mplayer/greg.git] / libmpcodecs / vf_rgbtest.c
blob4be591e48c6d59829c354252bffeb7edabac1ae1
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;
19 static unsigned int getfmt(unsigned int outfmt){
20 switch(outfmt){
21 case IMGFMT_RGB15:
22 case IMGFMT_RGB16:
23 case IMGFMT_RGB24:
24 case IMGFMT_RGBA:
25 case IMGFMT_ARGB:
26 case IMGFMT_BGR15:
27 case IMGFMT_BGR16:
28 case IMGFMT_BGR24:
29 case IMGFMT_BGRA:
30 case IMGFMT_ABGR:
31 return outfmt;
33 return 0;
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_BGR15: ((uint16_t*)(buf + y*stride))[x]= ((r>>3)<<10) | ((g>>3)<<5) | (b>>3);
39 break;
40 case IMGFMT_RGB15: ((uint16_t*)(buf + y*stride))[x]= ((b>>3)<<10) | ((g>>3)<<5) | (r>>3);
41 break;
42 case IMGFMT_BGR16: ((uint16_t*)(buf + y*stride))[x]= ((r>>3)<<11) | ((g>>2)<<5) | (b>>3);
43 break;
44 case IMGFMT_RGB16: ((uint16_t*)(buf + y*stride))[x]= ((b>>3)<<11) | ((g>>2)<<5) | (r>>3);
45 break;
46 case IMGFMT_RGB24:
47 buf[3*x + y*stride + 0]= r;
48 buf[3*x + y*stride + 1]= g;
49 buf[3*x + y*stride + 2]= b;
50 break;
51 case IMGFMT_BGR24:
52 buf[3*x + y*stride + 0]= b;
53 buf[3*x + y*stride + 1]= g;
54 buf[3*x + y*stride + 2]= r;
55 break;
56 case IMGFMT_RGBA:
57 buf[4*x + y*stride + 0]= r;
58 buf[4*x + y*stride + 1]= g;
59 buf[4*x + y*stride + 2]= b;
60 break;
61 case IMGFMT_BGRA:
62 buf[4*x + y*stride + 0]= b;
63 buf[4*x + y*stride + 1]= g;
64 buf[4*x + y*stride + 2]= r;
65 break;
66 case IMGFMT_ARGB:
67 buf[4*x + y*stride + 1]= r;
68 buf[4*x + y*stride + 2]= g;
69 buf[4*x + y*stride + 3]= b;
70 break;
71 case IMGFMT_ABGR:
72 buf[4*x + y*stride + 1]= b;
73 buf[4*x + y*stride + 2]= g;
74 buf[4*x + y*stride + 3]= r;
75 break;
79 static int config(struct vf_instance_s* vf,
80 int width, int height, int d_width, int d_height,
81 unsigned int flags, unsigned int outfmt){
82 vf->priv->fmt=getfmt(outfmt);
83 mp_msg(MSGT_VFILTER,MSGL_V,"rgb test format:%s\n", vo_format_name(outfmt));
84 return vf_next_config(vf,width,height,d_width,d_height,flags,vf->priv->fmt);
87 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){
88 mp_image_t *dmpi;
89 int x, y;
91 // hope we'll get DR buffer:
92 dmpi=vf_get_image(vf->next,vf->priv->fmt,
93 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
94 mpi->w, mpi->h);
96 for(y=0; y<mpi->h; y++){
97 for(x=0; x<mpi->w; x++){
98 int c= 256*x/mpi->w;
99 int r=0,g=0,b=0;
101 if(3*y<mpi->h) r=c;
102 else if(3*y<2*mpi->h) g=c;
103 else b=c;
105 put_pixel(dmpi->planes[0], x, y, dmpi->stride[0], r, g, b, vf->priv->fmt);
109 return vf_next_put_image(vf,dmpi, pts);
112 //===========================================================================//
114 static int query_format(struct vf_instance_s* vf, unsigned int outfmt){
115 unsigned int fmt=getfmt(outfmt);
116 if(!fmt) return 0;
117 return vf_next_query_format(vf,fmt) & (~VFCAP_CSP_SUPPORTED_BY_HW);
120 static int open(vf_instance_t *vf, char* args){
121 vf->config=config;
122 vf->put_image=put_image;
123 vf->query_format=query_format;
124 vf->priv=malloc(sizeof(struct vf_priv_s));
125 return 1;
128 const vf_info_t vf_info_rgbtest = {
129 "rgbtest",
130 "rgbtest",
131 "Michael Niedermayer",
133 open,
134 NULL
137 //===========================================================================//