Mercurial > mplayer.hg
annotate libmpcodecs/vf_bmovl.c @ 10834:cf404c558dd5
adaptors are not ports
author | attila |
---|---|
date | Sun, 07 Sep 2003 14:45:10 +0000 |
parents | 744d56a47d09 |
children | 5331f38c8db7 |
rev | line source |
---|---|
7855 | 1 /* vf_bmovl.c v0.9.1 - BitMap OVerLay videofilter for MPlayer |
2 * | |
3 * (C) 2002 Per Wigren <wigren@home.se> | |
4 * Licenced under the GNU General Public License | |
5 * | |
6 * Use MPlayer as a framebuffer to read bitmaps and commands from a FIFO | |
7 * and display them in the window. | |
8 * | |
7895 | 9 * Commands are: |
7855 | 10 * |
7895 | 11 * RGBA32 width height xpos ypos alpha clear |
12 * * Followed by width*height*4 bytes of raw RGBA32 data. | |
13 * ABGR32 width height xpos ypos alpha clear | |
14 * * Followed by width*height*4 bytes of raw ABGR32 data. | |
15 * RGB24 width height xpos ypos alpha clear | |
16 * * Followed by width*height*3 bytes of raw RGB32 data. | |
17 * BGR24 width height xpos ypos alpha clear | |
18 * * Followed by width*height*3 bytes of raw BGR32 data. | |
7855 | 19 * |
7895 | 20 * ALPHA width height xpos ypos alpha |
21 * * Change alpha for area | |
22 * CLEAR width height xpos ypos | |
23 * * Clear area | |
24 * OPAQUE | |
25 * * Disable all alpha transparency! | |
26 * Send "ALPHA 0 0 0 0 0" to enable again! | |
27 * HIDE | |
28 * * Hide bitmap | |
29 * SHOW | |
30 * * Show bitmap | |
7855 | 31 * |
32 * Arguments are: | |
33 * width, height Size of image/area | |
34 * xpos, ypos Start blitting at X/Y position | |
35 * alpha Set alpha difference. 0 means same as original. | |
36 * 255 makes everything opaque | |
37 * -255 makes everything transparent | |
38 * If you set this to -255 you can then send a sequence of | |
39 * ALPHA-commands to set the area to -225, -200, -175 etc | |
40 * for a nice fade-in-effect! ;) | |
41 * clear Clear the framebuffer before blitting. 1 means clear. | |
42 * If 0, the image will just be blitted on top of the old | |
43 * one, so you don't need to send 1,8MB of RGBA32 data | |
44 * everytime a small part of the screen is updated. | |
45 * | |
46 * Arguments for the filter are hidden:opaque:fifo | |
47 * For example 1:0:/tmp/myfifo.fifo will start the filter hidden, transparent | |
48 * and use /tmp/myfifo.fifo as the fifo. | |
49 * | |
50 * If you find bugs, please send me patches! ;) | |
51 * | |
52 * This filter was developed for use in Freevo (http://freevo.sf.net), but | |
53 * anyone is free to use it! ;) | |
54 * | |
55 */ | |
56 | |
57 #include <stdio.h> | |
58 #include <stdlib.h> | |
59 #include <string.h> | |
60 #include <unistd.h> | |
61 #include <errno.h> | |
62 #include <sys/stat.h> | |
63 #include <sys/types.h> | |
7858 | 64 #include <sys/time.h> |
7855 | 65 #include <fcntl.h> |
66 #include "mp_image.h" | |
67 #include "vf.h" | |
68 #include "img_format.h" | |
9832 | 69 #include "../config.h" |
70 | |
71 #ifndef HAVE_NO_POSIX_SELECT | |
7855 | 72 |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
73 #include "../mp_msg.h" |
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
74 |
7855 | 75 #include "../libvo/fastmemcpy.h" |
76 | |
77 #define IS_RAWIMG 0x100 | |
78 #define IS_IMG 0x200 | |
79 | |
80 #define NONE 0x000 | |
81 #define IMG_RGBA32 0x101 | |
82 #define IMG_ABGR32 0x102 | |
83 #define IMG_RGB24 0x103 | |
84 #define IMG_BGR24 0x104 | |
85 #define IMG_PNG 0x201 | |
86 #define CMD_CLEAR 0x001 | |
87 #define CMD_ALPHA 0x002 | |
88 | |
89 #define TRUE 1 | |
90 #define FALSE 0 | |
91 | |
92 #define MAX(a,b) ((a) > (b) ? (a) : (b)) | |
93 #define MIN(a,b) ((a) < (b) ? (a) : (b)) | |
94 #define INRANGE(a,b,c) ( ((a) < (b)) ? (b) : ( ((a) > (c)) ? (c) : (a) ) ) | |
95 | |
9131
67d28a3f918a
The code for converting RGB to YUV in bmovl is slow because it uses
arpi
parents:
9110
diff
changeset
|
96 #define rgb2y(R,G,B) ( (( 263*R + 516*G + 100*B) >> 10) + 16 ) |
67d28a3f918a
The code for converting RGB to YUV in bmovl is slow because it uses
arpi
parents:
9110
diff
changeset
|
97 #define rgb2u(R,G,B) ( ((-152*R - 298*G + 450*B) >> 10) + 128 ) |
67d28a3f918a
The code for converting RGB to YUV in bmovl is slow because it uses
arpi
parents:
9110
diff
changeset
|
98 #define rgb2v(R,G,B) ( (( 450*R - 376*G - 73*B) >> 10) + 128 ) |
7855 | 99 |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
100 #define DBG(a) (mp_msg(MSGT_VFILTER, MSGL_DBG2, "DEBUG: %d\n", a)) |
7855 | 101 |
102 struct vf_priv_s { | |
103 int w, h, x1, y1, x2, y2; | |
104 struct { | |
105 unsigned char *y, *u, *v, *a, *oa; | |
106 } bitmap; | |
107 int stream_fd; | |
108 fd_set stream_fdset; | |
109 int opaque, hidden; | |
110 }; | |
111 | |
112 static int | |
113 query_format(struct vf_instance_s* vf, unsigned int fmt){ | |
114 if(fmt==IMGFMT_YV12) return VFCAP_CSP_SUPPORTED; | |
115 return 0; | |
116 } | |
117 | |
118 | |
119 static int | |
120 config(struct vf_instance_s* vf, | |
121 int width, int height, int d_width, int d_height, | |
122 unsigned int flags, unsigned int outfmt) | |
123 { | |
124 vf->priv->bitmap.y = malloc( width*height ); | |
125 vf->priv->bitmap.u = malloc( width*height/4 ); | |
126 vf->priv->bitmap.v = malloc( width*height/4 ); | |
127 vf->priv->bitmap.a = malloc( width*height ); | |
128 vf->priv->bitmap.oa = malloc( width*height ); | |
129 if(!( vf->priv->bitmap.y && | |
130 vf->priv->bitmap.u && | |
131 vf->priv->bitmap.v && | |
132 vf->priv->bitmap.a && | |
133 vf->priv->bitmap.oa )) { | |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
134 mp_msg(MSGT_VFILTER, MSGL_ERR, "vf_bmovl: Could not allocate memory for bitmap buffer: %s\n", strerror(errno) ); |
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
135 return FALSE; |
7855 | 136 } |
137 | |
138 // Set default to black... | |
139 memset( vf->priv->bitmap.u, 128, width*height/4 ); | |
140 memset( vf->priv->bitmap.v, 128, width*height/4 ); | |
141 | |
142 vf->priv->w = vf->priv->x1 = width; | |
143 vf->priv->h = vf->priv->y1 = height; | |
144 vf->priv->y2 = vf->priv->x2 = 0; | |
145 | |
146 return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt); | |
147 } | |
148 | |
149 static void | |
150 uninit(struct vf_instance_s *vf) | |
151 { | |
152 if(vf->priv) { | |
153 free(vf->priv->bitmap.y); | |
154 free(vf->priv->bitmap.u); | |
155 free(vf->priv->bitmap.v); | |
156 free(vf->priv->bitmap.a); | |
157 free(vf->priv->bitmap.oa); | |
158 free(vf->priv); | |
159 } | |
160 } | |
161 | |
162 static int | |
163 _read_cmd(int fd, char *cmd, char *args) { | |
164 int done=FALSE, pos=0; | |
165 char tmp; | |
166 | |
167 while(!done) { | |
168 if(! read( fd, &tmp, 1 ) ) return FALSE; | |
169 if( (tmp>='A' && tmp<='Z') || (tmp>='0' && tmp<='9') ) | |
170 cmd[pos]=tmp; | |
171 else if(tmp == ' ') { | |
172 cmd[pos]='\0'; | |
173 done=TRUE; | |
174 } | |
175 else if(tmp == '\n') { | |
176 cmd[pos]='\0'; | |
177 args[0]='\0'; | |
178 return TRUE; | |
179 } | |
180 if(pos++>20) { | |
181 cmd[0]='\0'; | |
182 return TRUE; | |
183 } | |
184 } | |
185 done=FALSE; pos=0; | |
186 while(!done) { | |
187 if(! read( fd, &tmp, 1 ) ) return FALSE; | |
188 if( (tmp >= ' ') && (pos<100) ) args[pos]=tmp; | |
189 else { | |
190 args[pos]='\0'; | |
191 done=TRUE; | |
192 } | |
193 pos++; | |
194 } | |
195 return TRUE; | |
196 } | |
197 | |
198 | |
199 static int | |
200 put_image(struct vf_instance_s* vf, mp_image_t* mpi){ | |
201 int buf_x=0, buf_y=0, buf_pos=0; | |
202 int xpos=0, ypos=0, pos=0; | |
203 unsigned char red=0, green=0, blue=0; | |
204 int alpha; | |
205 mp_image_t* dmpi; | |
206 | |
207 dmpi = vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_TEMP, | |
208 MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE, | |
209 mpi->w, mpi->h); | |
210 | |
211 memcpy( dmpi->planes[0], mpi->planes[0], mpi->stride[0] * mpi->height); | |
212 memcpy( dmpi->planes[1], mpi->planes[1], mpi->stride[1] * mpi->chroma_height); | |
213 memcpy( dmpi->planes[2], mpi->planes[2], mpi->stride[2] * mpi->chroma_height); | |
214 | |
215 if(vf->priv->stream_fd >= 0) { | |
216 struct timeval tv; | |
217 | |
218 FD_SET( vf->priv->stream_fd, &vf->priv->stream_fdset ); | |
219 tv.tv_sec=0; tv.tv_usec=0; | |
220 | |
221 if( select( vf->priv->stream_fd+1, &vf->priv->stream_fdset, NULL, NULL, &tv ) > 0) { | |
222 // We've got new data from the FIFO | |
223 | |
224 char cmd[20], args[100]; | |
225 int imgw,imgh,imgx,imgy,clear,imgalpha,pxsz=1,command; | |
226 unsigned char *buffer = NULL; | |
227 | |
228 if(! _read_cmd( vf->priv->stream_fd, cmd, args) ) { | |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
229 mp_msg(MSGT_VFILTER, MSGL_ERR, "\nvf_bmovl: Error reading commands: %s\n\n", strerror(errno)); |
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
230 return FALSE; |
7855 | 231 } |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
232 mp_msg(MSGT_VFILTER, MSGL_DBG2, "\nDEBUG: Got: %s+%s\n", cmd, args); |
7855 | 233 |
234 command=NONE; | |
235 if ( strncmp(cmd,"RGBA32",6)==0 ) { pxsz=4; command = IMG_RGBA32; } | |
236 else if( strncmp(cmd,"ABGR32",6)==0 ) { pxsz=4; command = IMG_ABGR32; } | |
237 else if( strncmp(cmd,"RGB24" ,5)==0 ) { pxsz=3; command = IMG_RGB24; } | |
238 else if( strncmp(cmd,"BGR24" ,5)==0 ) { pxsz=3; command = IMG_BGR24; } | |
239 else if( strncmp(cmd,"CLEAR" ,5)==0 ) { pxsz=1; command = CMD_CLEAR; } | |
240 else if( strncmp(cmd,"ALPHA" ,5)==0 ) { pxsz=1; command = CMD_ALPHA; } | |
241 else if( strncmp(cmd,"OPAQUE",6)==0 ) vf->priv->opaque=TRUE; | |
242 else if( strncmp(cmd,"SHOW", 4)==0 ) vf->priv->hidden=FALSE; | |
243 else if( strncmp(cmd,"HIDE", 4)==0 ) vf->priv->hidden=TRUE; | |
244 else if( strncmp(cmd,"FLUSH" ,5)==0 ) return vf_next_put_image(vf, dmpi); | |
245 else { | |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
246 mp_msg(MSGT_VFILTER, MSGL_WARN, "\nvf_bmovl: Unknown command: '%s'. Ignoring.\n", cmd); |
7855 | 247 return vf_next_put_image(vf, dmpi); |
248 } | |
249 | |
250 if(command == CMD_ALPHA) { | |
251 sscanf( args, "%d %d %d %d %d", &imgw, &imgh, &imgx, &imgy, &imgalpha); | |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
252 mp_msg(MSGT_VFILTER, MSGL_DBG2, "\nDEBUG: ALPHA: %d %d %d %d %d\n\n", |
7855 | 253 imgw, imgh, imgx, imgy, imgalpha); |
254 if(imgw==0 && imgh==0) vf->priv->opaque=FALSE; | |
255 } | |
256 | |
257 if(command & IS_RAWIMG) { | |
258 sscanf( args, "%d %d %d %d %d %d", | |
259 &imgw, &imgh, &imgx, &imgy, &imgalpha, &clear); | |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
260 mp_msg(MSGT_VFILTER, MSGL_DBG2, "\nDEBUG: RAWIMG: %d %d %d %d %d %d\n\n", |
7855 | 261 imgw, imgh, imgx, imgy, imgalpha, clear); |
262 | |
263 buffer = malloc(imgw*imgh*pxsz); | |
264 if(!buffer) { | |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
265 mp_msg(MSGT_VFILTER, MSGL_WARN, "\nvf_bmovl: Couldn't allocate temporary buffer! Skipping...\n\n"); |
7855 | 266 return vf_next_put_image(vf, dmpi); |
267 } | |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
268 mp_msg(MSGT_VFILTER, MSGL_DBG2, "Got %d bytes...\n", read( vf->priv->stream_fd, buffer, (imgw*imgh*pxsz) ) ); |
7855 | 269 |
270 if(clear) { | |
271 memset( vf->priv->bitmap.y, 0, vf->priv->w*vf->priv->h ); | |
272 memset( vf->priv->bitmap.u, 128, vf->priv->w*vf->priv->h/4 ); | |
273 memset( vf->priv->bitmap.v, 128, vf->priv->w*vf->priv->h/4 ); | |
274 memset( vf->priv->bitmap.a, 0, vf->priv->w*vf->priv->h ); | |
275 memset( vf->priv->bitmap.oa, 0, vf->priv->w*vf->priv->h ); | |
276 vf->priv->x1 = dmpi->width; | |
277 vf->priv->y1 = dmpi->height; | |
278 vf->priv->x2 = vf->priv->y2 = 0; | |
279 } | |
280 // Define how much of our bitmap that contains graphics! | |
281 vf->priv->x1 = MAX( 0, MIN(vf->priv->x1, imgx) ); | |
282 vf->priv->y1 = MAX( 0, MIN(vf->priv->y1, imgy) ); | |
283 vf->priv->x2 = MIN( vf->priv->w, MAX(vf->priv->x2, ( imgx + imgw)) ); | |
284 vf->priv->y2 = MIN( vf->priv->h, MAX(vf->priv->y2, ( imgy + imgh)) ); | |
285 } | |
286 | |
287 if( command == CMD_CLEAR ) { | |
288 sscanf( args, "%d %d %d %d", &imgw, &imgh, &imgx, &imgy); | |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
289 mp_msg(MSGT_VFILTER, MSGL_DBG2, "\nDEBUG: CLEAR: %d %d %d %d\n\n", imgw, imgh, imgx, imgy); |
7855 | 290 |
291 for( ypos=imgy ; (ypos < (imgy+imgh)) && (ypos < vf->priv->y2) ; ypos++ ) { | |
292 memset( vf->priv->bitmap.y + (ypos*vf->priv->w) + imgx, 0, imgw ); | |
293 memset( vf->priv->bitmap.a + (ypos*vf->priv->w) + imgx, 0, imgw ); | |
294 memset( vf->priv->bitmap.oa + (ypos*vf->priv->w) + imgx, 0, imgw ); | |
295 if(ypos%2) { | |
296 memset( vf->priv->bitmap.u + ((ypos/2)*dmpi->stride[1]) + (imgx/2), 128, imgw/2 ); | |
297 memset( vf->priv->bitmap.v + ((ypos/2)*dmpi->stride[2]) + (imgx/2), 128, imgw/2 ); | |
298 } | |
299 } // Recalculate area that contains graphics | |
300 if( (imgx <= vf->priv->x1) && ( (imgw+imgx) >= vf->priv->x2) ) { | |
301 if( (imgy <= vf->priv->y1) && ( (imgy+imgh) >= vf->priv->y1) ) | |
302 vf->priv->y1 = imgy+imgh; | |
303 if( (imgy <= vf->priv->y2) && ( (imgy+imgh) >= vf->priv->y2) ) | |
304 vf->priv->y2 = imgy; | |
305 } | |
306 if( (imgy <= vf->priv->y1) && ( (imgy+imgh) >= vf->priv->y2) ) { | |
307 if( (imgx <= vf->priv->x1) && ( (imgx+imgw) >= vf->priv->x1) ) | |
308 vf->priv->x1 = imgx+imgw; | |
309 if( (imgx <= vf->priv->x2) && ( (imgx+imgw) >= vf->priv->x2) ) | |
310 vf->priv->x2 = imgx; | |
311 } | |
312 return vf_next_put_image(vf, dmpi); | |
313 } | |
314 | |
315 for( buf_y=0 ; (buf_y < imgh) && (buf_y < (vf->priv->h-imgy)) ; buf_y++ ) { | |
316 for( buf_x=0 ; (buf_x < (imgw*pxsz)) && (buf_x < ((vf->priv->w+imgx)*pxsz)) ; buf_x += pxsz ) { | |
317 if(command & IS_RAWIMG) buf_pos = (buf_y * imgw * pxsz) + buf_x; | |
318 pos = ((buf_y+imgy) * vf->priv->w) + ((buf_x/pxsz)+imgx); | |
319 | |
320 switch(command) { | |
321 case IMG_RGBA32: | |
322 red = buffer[buf_pos+0]; | |
323 green = buffer[buf_pos+1]; | |
324 blue = buffer[buf_pos+2]; | |
325 alpha = buffer[buf_pos+3]; | |
326 break; | |
327 case IMG_ABGR32: | |
328 alpha = buffer[buf_pos+0]; | |
329 blue = buffer[buf_pos+1]; | |
330 green = buffer[buf_pos+2]; | |
331 red = buffer[buf_pos+3]; | |
332 break; | |
333 case IMG_RGB24: | |
334 red = buffer[buf_pos+0]; | |
335 green = buffer[buf_pos+1]; | |
336 blue = buffer[buf_pos+2]; | |
337 alpha = 0xFF; | |
338 break; | |
339 case IMG_BGR24: | |
340 blue = buffer[buf_pos+0]; | |
341 green = buffer[buf_pos+1]; | |
342 red = buffer[buf_pos+2]; | |
343 alpha = 0xFF; | |
344 break; | |
345 case CMD_ALPHA: | |
346 vf->priv->bitmap.a[pos] = INRANGE((vf->priv->bitmap.oa[pos]+imgalpha),0,255); | |
347 break; | |
348 default: | |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
349 mp_msg(MSGT_VFILTER, MSGL_ERR, "vf_bmovl: Internal error!\n"); |
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
350 return FALSE; |
7855 | 351 } |
352 if( command & IS_RAWIMG ) { | |
353 vf->priv->bitmap.y[pos] = rgb2y(red,green,blue); | |
354 vf->priv->bitmap.oa[pos] = alpha; | |
355 vf->priv->bitmap.a[pos] = INRANGE((alpha+imgalpha),0,255); | |
356 if((buf_y%2) && ((buf_x/pxsz)%2)) { | |
357 pos = ( ((buf_y+imgy)/2) * dmpi->stride[1] ) + (((buf_x/pxsz)+imgx)/2); | |
358 vf->priv->bitmap.u[pos] = rgb2u(red,green,blue); | |
359 vf->priv->bitmap.v[pos] = rgb2v(red,green,blue); | |
360 } | |
361 } | |
362 } // for buf_x | |
363 } // for buf_y | |
364 free (buffer); | |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
365 } else if(errno) mp_msg(MSGT_VFILTER, MSGL_WARN, "\nvf_bmovl: Error %d in fifo: %s\n\n", errno, strerror(errno)); |
7855 | 366 } |
367 | |
368 if(vf->priv->hidden) return vf_next_put_image(vf, dmpi); | |
369 | |
370 if(vf->priv->opaque) { // Just copy buffer memory to screen | |
371 for( ypos=vf->priv->y1 ; ypos < vf->priv->y2 ; ypos++ ) { | |
372 memcpy( dmpi->planes[0] + (ypos*dmpi->stride[0]) + vf->priv->x1, | |
373 vf->priv->bitmap.y + (ypos*vf->priv->w) + vf->priv->x1, | |
374 vf->priv->x2 - vf->priv->x1 ); | |
375 if(ypos%2) { | |
376 memcpy( dmpi->planes[1] + ((ypos/2)*dmpi->stride[1]) + (vf->priv->x1/2), | |
377 vf->priv->bitmap.u + (((ypos/2)*(vf->priv->w)/2)) + (vf->priv->x1/2), | |
378 (vf->priv->x2 - vf->priv->x1)/2 ); | |
379 memcpy( dmpi->planes[2] + ((ypos/2)*dmpi->stride[2]) + (vf->priv->x1/2), | |
380 vf->priv->bitmap.v + (((ypos/2)*(vf->priv->w)/2)) + (vf->priv->x1/2), | |
381 (vf->priv->x2 - vf->priv->x1)/2 ); | |
382 } | |
383 } | |
384 } else { // Blit the bitmap to the videoscreen, pixel for pixel | |
385 for( ypos=vf->priv->y1 ; ypos < vf->priv->y2 ; ypos++ ) { | |
386 for ( xpos=vf->priv->x1 ; xpos < vf->priv->x2 ; xpos++ ) { | |
387 pos = (ypos * dmpi->stride[0]) + xpos; | |
388 | |
389 alpha = vf->priv->bitmap.a[pos]; | |
390 | |
391 if (alpha == 0) continue; // Completly transparent pixel | |
392 | |
393 if (alpha == 255) { // Opaque pixel | |
394 dmpi->planes[0][pos] = vf->priv->bitmap.y[pos]; | |
395 if ((ypos%2) && (xpos%2)) { | |
396 pos = ( (ypos/2) * dmpi->stride[1] ) + (xpos/2); | |
397 dmpi->planes[1][pos] = vf->priv->bitmap.u[pos]; | |
398 dmpi->planes[2][pos] = vf->priv->bitmap.v[pos]; | |
399 } | |
400 } else { // Alphablended pixel | |
9110
7924a60d833b
This is a simple patch to change the alpha blending code in bmovl to use
arpi
parents:
8878
diff
changeset
|
401 dmpi->planes[0][pos] = |
7924a60d833b
This is a simple patch to change the alpha blending code in bmovl to use
arpi
parents:
8878
diff
changeset
|
402 ((255 - alpha) * (int)dmpi->planes[0][pos] + |
7924a60d833b
This is a simple patch to change the alpha blending code in bmovl to use
arpi
parents:
8878
diff
changeset
|
403 alpha * (int)vf->priv->bitmap.y[pos]) >> 8; |
7924a60d833b
This is a simple patch to change the alpha blending code in bmovl to use
arpi
parents:
8878
diff
changeset
|
404 |
7855 | 405 if ((ypos%2) && (xpos%2)) { |
406 pos = ( (ypos/2) * dmpi->stride[1] ) + (xpos/2); | |
9110
7924a60d833b
This is a simple patch to change the alpha blending code in bmovl to use
arpi
parents:
8878
diff
changeset
|
407 |
7924a60d833b
This is a simple patch to change the alpha blending code in bmovl to use
arpi
parents:
8878
diff
changeset
|
408 dmpi->planes[1][pos] = |
7924a60d833b
This is a simple patch to change the alpha blending code in bmovl to use
arpi
parents:
8878
diff
changeset
|
409 ((255 - alpha) * (int)dmpi->planes[1][pos] + |
7924a60d833b
This is a simple patch to change the alpha blending code in bmovl to use
arpi
parents:
8878
diff
changeset
|
410 alpha * (int)vf->priv->bitmap.u[pos]) >> 8; |
7924a60d833b
This is a simple patch to change the alpha blending code in bmovl to use
arpi
parents:
8878
diff
changeset
|
411 |
7924a60d833b
This is a simple patch to change the alpha blending code in bmovl to use
arpi
parents:
8878
diff
changeset
|
412 dmpi->planes[2][pos] = |
7924a60d833b
This is a simple patch to change the alpha blending code in bmovl to use
arpi
parents:
8878
diff
changeset
|
413 ((255 - alpha) * (int)dmpi->planes[2][pos] + |
7924a60d833b
This is a simple patch to change the alpha blending code in bmovl to use
arpi
parents:
8878
diff
changeset
|
414 alpha * (int)vf->priv->bitmap.v[pos]) >> 8; |
7855 | 415 } |
416 } | |
417 } // for xpos | |
418 } // for ypos | |
419 } // if !opaque | |
420 return vf_next_put_image(vf, dmpi); | |
421 } // put_image | |
422 | |
423 static int | |
424 vf_open(vf_instance_t* vf, char* args) | |
425 { | |
426 char filename[1000]; | |
427 | |
428 vf->config = config; | |
429 vf->put_image = put_image; | |
430 vf->query_format = query_format; | |
431 vf->uninit = uninit; | |
432 | |
433 vf->priv = malloc(sizeof(struct vf_priv_s)); | |
434 | |
10337 | 435 if(!args || sscanf(args, "%d:%d:%s", &vf->priv->hidden, &vf->priv->opaque, filename) < 3 ) { |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
436 mp_msg(MSGT_VFILTER, MSGL_ERR, "vf_bmovl: Bad arguments!\n"); |
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
437 mp_msg(MSGT_VFILTER, MSGL_ERR, "vf_bmovl: Arguments are 'bool hidden:bool opaque:string fifo'\n"); |
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
438 return FALSE; |
7855 | 439 } |
440 | |
441 vf->priv->stream_fd = open(filename, O_RDWR); | |
442 if(vf->priv->stream_fd >= 0) { | |
443 FD_ZERO( &vf->priv->stream_fdset ); | |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
444 mp_msg(MSGT_VFILTER, MSGL_INFO, "vf_bmovl: Opened fifo %s as FD %d\n", filename, vf->priv->stream_fd); |
7855 | 445 } else { |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
446 mp_msg(MSGT_VFILTER, MSGL_WARN, "vf_bmovl: Error! Couldn't open FIFO %s: %s\n", filename, strerror(errno)); |
7855 | 447 vf->priv->stream_fd = -1; |
448 } | |
449 | |
450 return TRUE; | |
451 } | |
452 | |
453 vf_info_t vf_info_bmovl = { | |
454 "Read bitmaps from a FIFO and display them in window", | |
455 "bmovl", | |
456 "Per Wigren", | |
457 "", | |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9131
diff
changeset
|
458 vf_open, |
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9131
diff
changeset
|
459 NULL |
7855 | 460 }; |
9832 | 461 |
462 #endif |