Make function Gsm_Long_Term_Synthesis_Filtering() static, only used in xa_gsm.c.
[mplayer/greg.git] / libmpcodecs / vf_1bpp.c
blobb564b82a6e803c242235a711a1d5774b59f390a4
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <inttypes.h>
24 #include "config.h"
25 #include "mp_msg.h"
27 #include "img_format.h"
28 #include "mp_image.h"
29 #include "vf.h"
31 //===========================================================================//
33 static const unsigned int bgr_list[]={
34 IMGFMT_Y800,
35 IMGFMT_Y8,
36 IMGFMT_BGR8,
37 IMGFMT_RGB8,
39 IMGFMT_YVU9,
40 IMGFMT_411P,
41 IMGFMT_YV12,
42 IMGFMT_I420,
43 IMGFMT_IYUV,
44 IMGFMT_422P,
45 IMGFMT_444P,
47 IMGFMT_YUY2,
48 IMGFMT_BGR15,
49 IMGFMT_RGB15,
50 IMGFMT_BGR16,
51 IMGFMT_RGB16,
53 IMGFMT_BGR32,
54 IMGFMT_RGB32,
56 // IMGFMT_BGR24,
57 // IMGFMT_RGB24,
61 static unsigned int find_best(struct vf_instance *vf){
62 unsigned int best=0;
63 int ret;
64 const unsigned int* p=bgr_list;
65 while(*p){
66 ret=vf->next->query_format(vf->next,*p);
67 mp_msg(MSGT_VFILTER,MSGL_V,"[%s] query(%s) -> %d\n",vf->info->name,vo_format_name(*p),ret&3);
68 if(ret&VFCAP_CSP_SUPPORTED_BY_HW){ best=*p; break;} // no conversion -> bingo!
69 if(ret&VFCAP_CSP_SUPPORTED && !best) best=*p; // best with conversion
70 ++p;
72 return best;
75 //===========================================================================//
77 struct vf_priv_s {
78 unsigned int fmt;
81 static int config(struct vf_instance *vf,
82 int width, int height, int d_width, int d_height,
83 unsigned int flags, unsigned int outfmt){
84 if (!vf->priv->fmt)
85 vf->priv->fmt=find_best(vf);
86 if(!vf->priv->fmt){
87 // no matching fmt, so force one...
88 if(outfmt==IMGFMT_RGB8) vf->priv->fmt=IMGFMT_RGB32;
89 else if(outfmt==IMGFMT_BGR8) vf->priv->fmt=IMGFMT_BGR32;
90 else return 0;
92 return vf_next_config(vf,width,height,d_width,d_height,flags,vf->priv->fmt);
95 static const int bittab[8]={128,64,32,16,8,4,2,1};
97 static void convert(mp_image_t *mpi, mp_image_t *dmpi, int value0, int value1,int bpp){
98 int y;
99 for(y=0;y<mpi->h;y++){
100 unsigned char* src=mpi->planes[0]+mpi->stride[0]*y;
101 switch(bpp){
102 case 1: {
103 unsigned char* dst=dmpi->planes[0]+dmpi->stride[0]*y;
104 int x;
105 for(x=0;x<mpi->w;x++)
106 dst[x]=(src[x>>3]&bittab[x&7]) ? value1 : value0;
107 break; }
108 case 2: {
109 uint16_t* dst=(uint16_t*)(dmpi->planes[0]+dmpi->stride[0]*y);
110 int x;
111 for(x=0;x<mpi->w;x++)
112 dst[x]=(src[x>>3]&bittab[x&7]) ? value1 : value0;
113 break; }
114 case 4: {
115 uint32_t* dst=(uint32_t*)(dmpi->planes[0]+dmpi->stride[0]*y);
116 int x;
117 for(x=0;x<mpi->w;x++)
118 dst[x]=(src[x>>3]&bittab[x&7]) ? value1 : value0;
119 break; }
124 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
125 mp_image_t *dmpi;
127 // hope we'll get DR buffer:
128 dmpi=vf_get_image(vf->next,vf->priv->fmt,
129 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
130 mpi->w, mpi->h);
132 switch(dmpi->imgfmt){
133 case IMGFMT_Y800:
134 case IMGFMT_Y8:
135 case IMGFMT_BGR8:
136 case IMGFMT_RGB8:
137 convert(mpi,dmpi,0,255,1);
138 break;
139 case IMGFMT_YVU9:
140 case IMGFMT_411P:
141 case IMGFMT_YV12:
142 case IMGFMT_I420:
143 case IMGFMT_IYUV:
144 case IMGFMT_422P:
145 case IMGFMT_444P:
146 convert(mpi,dmpi,0,255,1);
147 memset(dmpi->planes[1],128,dmpi->stride[1]*dmpi->chroma_height);
148 memset(dmpi->planes[2],128,dmpi->stride[2]*dmpi->chroma_height);
149 break;
150 case IMGFMT_YUY2:
151 convert(mpi,dmpi,0x8000,0x80ff,2);
152 break;
153 case IMGFMT_BGR15:
154 case IMGFMT_RGB15:
155 convert(mpi,dmpi,0,0x7fff,2);
156 break;
157 case IMGFMT_BGR16:
158 case IMGFMT_RGB16:
159 convert(mpi,dmpi,0,0xffff,2);
160 break;
161 case IMGFMT_BGR32:
162 case IMGFMT_RGB32:
163 convert(mpi,dmpi,0,0x00ffffff,4);
164 break;
165 default:
166 mp_msg(MSGT_VFILTER,MSGL_ERR,"Unhandled format: 0x%X\n",dmpi->imgfmt);
167 return 0;
170 return vf_next_put_image(vf,dmpi, pts);
173 //===========================================================================//
175 static int query_format(struct vf_instance *vf, unsigned int fmt){
176 int best;
177 if(fmt!=IMGFMT_RGB1 && fmt!=IMGFMT_BGR1) return 0;
178 best=find_best(vf);
179 if(!best) return 0; // no match
180 return vf->next->query_format(vf->next,best);
183 static int vf_open(vf_instance_t *vf, char *args){
184 vf->config=config;
185 vf->put_image=put_image;
186 vf->query_format=query_format;
187 vf->priv=malloc(sizeof(struct vf_priv_s));
188 memset(vf->priv, 0, sizeof(struct vf_priv_s));
189 return 1;
192 const vf_info_t vf_info_1bpp = {
193 "1bpp bitmap -> YUV/BGR 8/15/16/32 conversion",
194 "1bpp",
195 "A'rpi",
197 vf_open,
198 NULL
201 //===========================================================================//