comparison libmpcodecs/vf_1bpp.c @ 7755:7637b72ef1f9

new filter: 1bpp - converts 1bpp image to yuv/rgb 8/16/32 bpp
author arpi
date Wed, 16 Oct 2002 18:40:03 +0000
parents
children 3c1d30a1afc0
comparison
equal deleted inserted replaced
7754:0568245deeb8 7755:7637b72ef1f9
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_Y800,
19 IMGFMT_Y8,
20 IMGFMT_BGR8,
21 IMGFMT_RGB8,
22
23 IMGFMT_YVU9,
24 IMGFMT_411P,
25 IMGFMT_YV12,
26 IMGFMT_I420,
27 IMGFMT_IYUV,
28 IMGFMT_422P,
29 IMGFMT_444P,
30
31 IMGFMT_YUY2,
32 IMGFMT_BGR15,
33 IMGFMT_RGB15,
34 IMGFMT_BGR16,
35 IMGFMT_RGB16,
36
37 IMGFMT_BGR32,
38 IMGFMT_RGB32,
39
40 // IMGFMT_BGR24,
41 // IMGFMT_RGB24,
42 0
43 };
44
45 static unsigned int find_best(struct vf_instance_s* vf){
46 unsigned int best=0;
47 int ret;
48 unsigned int* p=bgr_list;
49 while(*p){
50 ret=vf->next->query_format(vf->next,*p);
51 mp_msg(MSGT_VFILTER,MSGL_V,"[%s] query(%s) -> %d\n",vf->info->name,vo_format_name(*p),ret&3);
52 if(ret&VFCAP_CSP_SUPPORTED_BY_HW){ best=*p; break;} // no conversion -> bingo!
53 if(ret&VFCAP_CSP_SUPPORTED && !best) best=*p; // best with conversion
54 ++p;
55 }
56 return best;
57 }
58
59 //===========================================================================//
60
61 struct vf_priv_s {
62 unsigned int fmt;
63 };
64
65 static int config(struct vf_instance_s* vf,
66 int width, int height, int d_width, int d_height,
67 unsigned int flags, unsigned int outfmt){
68 if (!vf->priv->fmt)
69 vf->priv->fmt=find_best(vf);
70 if(!vf->priv->fmt){
71 // no matching fmt, so force one...
72 if(outfmt==IMGFMT_RGB8) vf->priv->fmt=IMGFMT_RGB32;
73 else if(outfmt==IMGFMT_BGR8) vf->priv->fmt=IMGFMT_BGR32;
74 else return 0;
75 }
76 return vf_next_config(vf,width,height,d_width,d_height,flags,vf->priv->fmt);
77 }
78
79 static int bittab[8]={128,64,32,16,8,4,2,1};
80
81 static void convert(mp_image_t *mpi, mp_image_t *dmpi, int value0, int value1,int bpp){
82 int y;
83 for(y=0;y<mpi->h;y++){
84 unsigned char* src=mpi->planes[0]+mpi->stride[0]*y;
85 switch(bpp){
86 case 1: {
87 unsigned char* dst=dmpi->planes[0]+dmpi->stride[0]*y;
88 int x;
89 for(x=0;x<mpi->w;x++)
90 dst[x]=(src[x>>3]&bittab[x&7]) ? value1 : value0;
91 break; }
92 case 2: {
93 uint16_t* dst=(uint16_t*)(dmpi->planes[0]+dmpi->stride[0]*y);
94 int x;
95 for(x=0;x<mpi->w;x++)
96 dst[x]=(src[x>>3]&bittab[x&7]) ? value1 : value0;
97 break; }
98 case 4: {
99 uint32_t* dst=(uint32_t*)(dmpi->planes[0]+dmpi->stride[0]*y);
100 int x;
101 for(x=0;x<mpi->w;x++)
102 dst[x]=(src[x>>3]&bittab[x&7]) ? value1 : value0;
103 break; }
104 }
105 }
106 }
107
108 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){
109 mp_image_t *dmpi;
110
111 // hope we'll get DR buffer:
112 dmpi=vf_get_image(vf->next,vf->priv->fmt,
113 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
114 mpi->w, mpi->h);
115
116 switch(dmpi->imgfmt){
117 case IMGFMT_Y800:
118 case IMGFMT_Y8:
119 case IMGFMT_BGR8:
120 case IMGFMT_RGB8:
121 convert(mpi,dmpi,0,255,1);
122 break;
123 case IMGFMT_YVU9:
124 case IMGFMT_411P:
125 case IMGFMT_YV12:
126 case IMGFMT_I420:
127 case IMGFMT_IYUV:
128 case IMGFMT_422P:
129 case IMGFMT_444P:
130 convert(mpi,dmpi,0,255,1);
131 memset(dmpi->planes[1],128,dmpi->stride[1]*dmpi->chroma_height);
132 memset(dmpi->planes[2],128,dmpi->stride[2]*dmpi->chroma_height);
133 break;
134 case IMGFMT_YUY2:
135 convert(mpi,dmpi,0x8000,0x80ff,2);
136 break;
137 case IMGFMT_BGR15:
138 case IMGFMT_RGB15:
139 convert(mpi,dmpi,0,0x7fff,2);
140 break;
141 case IMGFMT_BGR16:
142 case IMGFMT_RGB16:
143 convert(mpi,dmpi,0,0xffff,2);
144 break;
145 case IMGFMT_BGR32:
146 case IMGFMT_RGB32:
147 convert(mpi,dmpi,0,0x00ffffff,4);
148 break;
149 default:
150 mp_msg(MSGT_VFILTER,MSGL_ERR,"Unhandled format: 0x%X\n",dmpi->imgfmt);
151 return NULL;
152 }
153
154 return vf_next_put_image(vf,dmpi);
155 }
156
157 //===========================================================================//
158
159 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
160 int best;
161 if(fmt!=IMGFMT_RGB1 && fmt!=IMGFMT_BGR1) return 0;
162 best=find_best(vf);
163 if(!best) return 0; // no match
164 return vf->next->query_format(vf->next,best);
165 }
166
167 static int open(vf_instance_t *vf, char* args){
168 unsigned int i;
169 vf->config=config;
170 vf->put_image=put_image;
171 vf->query_format=query_format;
172 vf->priv=malloc(sizeof(struct vf_priv_s));
173 memset(vf->priv, 0, sizeof(struct vf_priv_s));
174 return 1;
175 }
176
177 vf_info_t vf_info_1bpp = {
178 "1bpp bitmap -> YUV/BGR 8/15/16/32 conversion",
179 "1bpp",
180 "A'rpi",
181 "",
182 open
183 };
184
185 //===========================================================================//