Mercurial > mplayer.hg
annotate libmpcodecs/vf_palette.c @ 7202:b414c2e34b2e
removed buggy fd<0 check for disallowing dumpstream/cache
author | arpi |
---|---|
date | Sat, 31 Aug 2002 15:44:41 +0000 |
parents | 447066802e64 |
children | e7ddd1923b67 |
rev | line source |
---|---|
5774 | 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 "../postproc/rgb2rgb.h" | |
14 | |
15 //===========================================================================// | |
16 | |
17 static unsigned int bgr_list[]={ | |
18 IMGFMT_BGR32, | |
19 IMGFMT_BGR24, | |
20 IMGFMT_BGR16, | |
21 IMGFMT_BGR15, | |
6188 | 22 0 |
5774 | 23 }; |
24 static unsigned int rgb_list[]={ | |
25 IMGFMT_RGB32, | |
26 IMGFMT_RGB24, | |
27 IMGFMT_RGB16, | |
28 IMGFMT_RGB15, | |
6188 | 29 0 |
5774 | 30 }; |
31 | |
6232 | 32 static unsigned int gray_pal[256]; |
33 | |
5774 | 34 static unsigned int find_best(struct vf_instance_s* vf, unsigned int fmt){ |
35 unsigned int best=0; | |
36 int ret; | |
37 unsigned int* p; | |
38 if(fmt==IMGFMT_BGR8) p=bgr_list; | |
39 else if(fmt==IMGFMT_RGB8) p=rgb_list; | |
40 else return 0; | |
41 while(*p){ | |
42 ret=vf->next->query_format(vf->next,*p); | |
43 mp_msg(MSGT_VFILTER,MSGL_V,"[%s] query(%s) -> %d\n",vf->info->name,vo_format_name(*p),ret&3); | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
44 if(ret&VFCAP_CSP_SUPPORTED_BY_HW){ best=*p; break;} // no conversion -> bingo! |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
45 if(ret&VFCAP_CSP_SUPPORTED && !best) best=*p; // best with conversion |
5774 | 46 ++p; |
47 } | |
48 return best; | |
49 } | |
50 | |
51 //===========================================================================// | |
52 | |
53 struct vf_priv_s { | |
54 unsigned int fmt; | |
55 }; | |
56 | |
57 static int config(struct vf_instance_s* vf, | |
58 int width, int height, int d_width, int d_height, | |
59 unsigned int flags, unsigned int outfmt){ | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
60 if (!vf->priv->fmt) |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
61 vf->priv->fmt=find_best(vf,outfmt); |
5774 | 62 if(!vf->priv->fmt){ |
63 // no matching fmt, so force one... | |
64 if(outfmt==IMGFMT_RGB8) vf->priv->fmt=IMGFMT_RGB32; | |
65 else if(outfmt==IMGFMT_BGR8) vf->priv->fmt=IMGFMT_BGR32; | |
66 else return 0; | |
67 } | |
68 return vf_next_config(vf,width,height,d_width,d_height,flags,vf->priv->fmt); | |
69 } | |
70 | |
71 static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){ | |
72 mp_image_t *dmpi; | |
6481 | 73 |
5774 | 74 // hope we'll get DR buffer: |
75 dmpi=vf_get_image(vf->next,vf->priv->fmt, | |
76 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, | |
77 mpi->w, mpi->h); | |
78 | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
79 if (!mpi->planes[1]) |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
80 { |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
81 mp_msg(MSGT_VFILTER,MSGL_V,"[%s] no palette given, assuming builtin grayscale one\n",vf->info->name); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
82 mpi->planes[1] = (unsigned char*)gray_pal; |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
83 } |
6232 | 84 |
5774 | 85 if(mpi->w==mpi->stride[0] && dmpi->w*(dmpi->bpp>>3)==dmpi->stride[0]){ |
86 // no stride conversion needed | |
87 switch(dmpi->imgfmt&255){ | |
88 case 15: | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
89 if (mpi->flags & MP_IMGFLAG_SWAPPED) |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
90 palette8tobgr15(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
91 else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
92 palette8torgb15(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); |
5774 | 93 break; |
94 case 16: | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
95 if (mpi->flags & MP_IMGFLAG_SWAPPED) |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
96 palette8tobgr16(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
97 else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
98 palette8torgb16(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); |
5774 | 99 break; |
100 case 24: | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
101 if (mpi->flags & MP_IMGFLAG_SWAPPED) |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
102 palette8tobgr24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
103 else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
104 palette8torgb24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); |
5774 | 105 break; |
106 case 32: | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
107 if (mpi->flags & MP_IMGFLAG_SWAPPED) |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
108 palette8tobgr32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
109 else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
110 palette8torgb32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); |
5774 | 111 break; |
112 } | |
113 } else { | |
114 int y; | |
115 for(y=0;y<mpi->h;y++){ | |
116 unsigned char* src=mpi->planes[0]+y*mpi->stride[0]; | |
117 unsigned char* dst=dmpi->planes[0]+y*dmpi->stride[0]; | |
118 switch(dmpi->imgfmt&255){ | |
119 case 15: | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
120 if (mpi->flags & MP_IMGFLAG_SWAPPED) |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
121 palette8tobgr15(src,dst,mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
122 else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
123 palette8torgb15(src,dst,mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
124 break; |
5774 | 125 case 16: |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
126 if (mpi->flags & MP_IMGFLAG_SWAPPED) |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
127 palette8tobgr16(src,dst,mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
128 else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
129 palette8torgb16(src,dst,mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
130 break; |
5774 | 131 case 24: |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
132 if (mpi->flags & MP_IMGFLAG_SWAPPED) |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
133 palette8tobgr24(src,dst,mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
134 else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
135 palette8torgb24(src,dst,mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
136 break; |
5774 | 137 case 32: |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
138 if (mpi->flags & MP_IMGFLAG_SWAPPED) |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
139 palette8tobgr32(src,dst,mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
140 else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
141 palette8torgb32(src,dst,mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
142 break; |
5774 | 143 } |
144 } | |
145 } | |
146 | |
147 vf_next_put_image(vf,dmpi); | |
148 } | |
149 | |
150 //===========================================================================// | |
151 | |
152 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ | |
153 int best=find_best(vf,fmt); | |
154 if(!best) return 0; // no match | |
155 return vf->next->query_format(vf->next,best); | |
156 } | |
157 | |
158 static int open(vf_instance_t *vf, char* args){ | |
6232 | 159 unsigned int i; |
5774 | 160 vf->config=config; |
161 vf->put_image=put_image; | |
162 vf->query_format=query_format; | |
163 vf->priv=malloc(sizeof(struct vf_priv_s)); | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
164 memset(vf->priv, 0, sizeof(struct vf_priv_s)); |
6232 | 165 for(i=0;i<256;i++) gray_pal[i]=0x01010101*i; |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
166 if (args) |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
167 { |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
168 if (!strcasecmp(args,"rgb15")) vf->priv->fmt=IMGFMT_RGB15; else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
169 if (!strcasecmp(args,"rgb16")) vf->priv->fmt=IMGFMT_RGB16; else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
170 if (!strcasecmp(args,"rgb24")) vf->priv->fmt=IMGFMT_RGB24; else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
171 if (!strcasecmp(args,"rgb32")) vf->priv->fmt=IMGFMT_RGB32; else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
172 if (!strcasecmp(args,"bgr15")) vf->priv->fmt=IMGFMT_BGR15; else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
173 if (!strcasecmp(args,"bgr16")) vf->priv->fmt=IMGFMT_BGR16; else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
174 if (!strcasecmp(args,"bgr24")) vf->priv->fmt=IMGFMT_BGR24; else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
175 if (!strcasecmp(args,"bgr32")) vf->priv->fmt=IMGFMT_BGR32; else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
176 { |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
177 printf("Unknown forced format name: '%s'\n", args); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
178 return(0); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
179 } |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
180 } |
5774 | 181 return 1; |
182 } | |
183 | |
184 vf_info_t vf_info_palette = { | |
185 "8bpp indexed (using palette) -> BGR 15/16/24/32 conversion", | |
186 "palette", | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
187 "A'rpi & Alex", |
5774 | 188 "", |
189 open | |
190 }; | |
191 | |
192 //===========================================================================// |