Mercurial > mplayer.hg
annotate libmpcodecs/vf_bmovl.c @ 22633:0160251d350a
Remove redundant rule for creating .o files from .c files, it's builtin.
author | diego |
---|---|
date | Sat, 17 Mar 2007 00:05:38 +0000 |
parents | fd54975f9135 |
children | 3d83d77f5a6b |
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> |
17630 | 66 #include "config.h" |
7855 | 67 #include "mp_image.h" |
68 #include "vf.h" | |
69 #include "img_format.h" | |
9832 | 70 |
71 #ifndef HAVE_NO_POSIX_SELECT | |
7855 | 72 |
17012 | 73 #include "mp_msg.h" |
22377
fd54975f9135
Use libavutil's av_clip* instead of unreadable MIN/MAX chaos.
reimar
parents:
19166
diff
changeset
|
74 #include "libavutil/common.h" |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
75 |
17012 | 76 #include "libvo/fastmemcpy.h" |
7855 | 77 |
78 #define IS_RAWIMG 0x100 | |
79 #define IS_IMG 0x200 | |
80 | |
81 #define NONE 0x000 | |
82 #define IMG_RGBA32 0x101 | |
83 #define IMG_ABGR32 0x102 | |
84 #define IMG_RGB24 0x103 | |
85 #define IMG_BGR24 0x104 | |
86 #define IMG_PNG 0x201 | |
87 #define CMD_CLEAR 0x001 | |
88 #define CMD_ALPHA 0x002 | |
89 | |
90 #define TRUE 1 | |
91 #define FALSE 0 | |
92 | |
93 #define INRANGE(a,b,c) ( ((a) < (b)) ? (b) : ( ((a) > (c)) ? (c) : (a) ) ) | |
94 | |
9131
67d28a3f918a
The code for converting RGB to YUV in bmovl is slow because it uses
arpi
parents:
9110
diff
changeset
|
95 #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
|
96 #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
|
97 #define rgb2v(R,G,B) ( (( 450*R - 376*G - 73*B) >> 10) + 128 ) |
7855 | 98 |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
99 #define DBG(a) (mp_msg(MSGT_VFILTER, MSGL_DBG2, "DEBUG: %d\n", a)) |
7855 | 100 |
101 struct vf_priv_s { | |
102 int w, h, x1, y1, x2, y2; | |
103 struct { | |
104 unsigned char *y, *u, *v, *a, *oa; | |
105 } bitmap; | |
106 int stream_fd; | |
107 fd_set stream_fdset; | |
108 int opaque, hidden; | |
109 }; | |
110 | |
111 static int | |
112 query_format(struct vf_instance_s* vf, unsigned int fmt){ | |
113 if(fmt==IMGFMT_YV12) return VFCAP_CSP_SUPPORTED; | |
114 return 0; | |
115 } | |
116 | |
117 | |
118 static int | |
119 config(struct vf_instance_s* vf, | |
120 int width, int height, int d_width, int d_height, | |
121 unsigned int flags, unsigned int outfmt) | |
122 { | |
123 vf->priv->bitmap.y = malloc( width*height ); | |
124 vf->priv->bitmap.u = malloc( width*height/4 ); | |
125 vf->priv->bitmap.v = malloc( width*height/4 ); | |
126 vf->priv->bitmap.a = malloc( width*height ); | |
127 vf->priv->bitmap.oa = malloc( width*height ); | |
128 if(!( vf->priv->bitmap.y && | |
129 vf->priv->bitmap.u && | |
130 vf->priv->bitmap.v && | |
131 vf->priv->bitmap.a && | |
132 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
|
133 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
|
134 return FALSE; |
7855 | 135 } |
136 | |
137 // Set default to black... | |
138 memset( vf->priv->bitmap.u, 128, width*height/4 ); | |
139 memset( vf->priv->bitmap.v, 128, width*height/4 ); | |
140 | |
141 vf->priv->w = vf->priv->x1 = width; | |
142 vf->priv->h = vf->priv->y1 = height; | |
143 vf->priv->y2 = vf->priv->x2 = 0; | |
144 | |
145 return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt); | |
146 } | |
147 | |
148 static void | |
149 uninit(struct vf_instance_s *vf) | |
150 { | |
151 if(vf->priv) { | |
152 free(vf->priv->bitmap.y); | |
153 free(vf->priv->bitmap.u); | |
154 free(vf->priv->bitmap.v); | |
155 free(vf->priv->bitmap.a); | |
156 free(vf->priv->bitmap.oa); | |
16886
ea32158ad57b
close stream_fd on uninit. Fixes bugzilla bug #400.
reimar
parents:
11620
diff
changeset
|
157 if (vf->priv->stream_fd >= 0) |
ea32158ad57b
close stream_fd on uninit. Fixes bugzilla bug #400.
reimar
parents:
11620
diff
changeset
|
158 close(vf->priv->stream_fd); |
7855 | 159 free(vf->priv); |
160 } | |
161 } | |
162 | |
163 static int | |
164 _read_cmd(int fd, char *cmd, char *args) { | |
165 int done=FALSE, pos=0; | |
166 char tmp; | |
167 | |
168 while(!done) { | |
169 if(! read( fd, &tmp, 1 ) ) return FALSE; | |
170 if( (tmp>='A' && tmp<='Z') || (tmp>='0' && tmp<='9') ) | |
171 cmd[pos]=tmp; | |
172 else if(tmp == ' ') { | |
173 cmd[pos]='\0'; | |
174 done=TRUE; | |
175 } | |
176 else if(tmp == '\n') { | |
177 cmd[pos]='\0'; | |
178 args[0]='\0'; | |
179 return TRUE; | |
180 } | |
181 if(pos++>20) { | |
182 cmd[0]='\0'; | |
183 return TRUE; | |
184 } | |
185 } | |
186 done=FALSE; pos=0; | |
187 while(!done) { | |
188 if(! read( fd, &tmp, 1 ) ) return FALSE; | |
189 if( (tmp >= ' ') && (pos<100) ) args[pos]=tmp; | |
190 else { | |
191 args[pos]='\0'; | |
192 done=TRUE; | |
193 } | |
194 pos++; | |
195 } | |
196 return TRUE; | |
197 } | |
198 | |
199 | |
200 static int | |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17630
diff
changeset
|
201 put_image(struct vf_instance_s* vf, mp_image_t* mpi, double pts){ |
7855 | 202 int buf_x=0, buf_y=0, buf_pos=0; |
11620
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
203 int have, got, want; |
7855 | 204 int xpos=0, ypos=0, pos=0; |
205 unsigned char red=0, green=0, blue=0; | |
206 int alpha; | |
207 mp_image_t* dmpi; | |
208 | |
209 dmpi = vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_TEMP, | |
210 MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE, | |
211 mpi->w, mpi->h); | |
212 | |
19166
d36048cad8c4
in some cases, vf_bmovl produces junk due to source and
gpoirier
parents:
17906
diff
changeset
|
213 memcpy_pic( dmpi->planes[0], mpi->planes[0], mpi->width, mpi->height, dmpi->stride[0], mpi->stride[0] ); |
d36048cad8c4
in some cases, vf_bmovl produces junk due to source and
gpoirier
parents:
17906
diff
changeset
|
214 memcpy_pic( dmpi->planes[1], mpi->planes[1], mpi->chroma_width, mpi->chroma_height, dmpi->stride[1], mpi->stride[1] ); |
d36048cad8c4
in some cases, vf_bmovl produces junk due to source and
gpoirier
parents:
17906
diff
changeset
|
215 memcpy_pic( dmpi->planes[2], mpi->planes[2], mpi->chroma_width, mpi->chroma_height, dmpi->stride[2], mpi->stride[2] ); |
7855 | 216 |
217 if(vf->priv->stream_fd >= 0) { | |
218 struct timeval tv; | |
11015
5331f38c8db7
correct handling of select ret=0, patch by Jonas Jensen <jbj@knef.dk>
alex
parents:
10337
diff
changeset
|
219 int ready; |
7855 | 220 |
221 FD_SET( vf->priv->stream_fd, &vf->priv->stream_fdset ); | |
222 tv.tv_sec=0; tv.tv_usec=0; | |
223 | |
11015
5331f38c8db7
correct handling of select ret=0, patch by Jonas Jensen <jbj@knef.dk>
alex
parents:
10337
diff
changeset
|
224 ready = select( vf->priv->stream_fd+1, &vf->priv->stream_fdset, NULL, NULL, &tv ); |
5331f38c8db7
correct handling of select ret=0, patch by Jonas Jensen <jbj@knef.dk>
alex
parents:
10337
diff
changeset
|
225 if(ready > 0) { |
7855 | 226 // We've got new data from the FIFO |
227 | |
228 char cmd[20], args[100]; | |
229 int imgw,imgh,imgx,imgy,clear,imgalpha,pxsz=1,command; | |
230 unsigned char *buffer = NULL; | |
231 | |
232 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
|
233 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
|
234 return FALSE; |
7855 | 235 } |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
236 mp_msg(MSGT_VFILTER, MSGL_DBG2, "\nDEBUG: Got: %s+%s\n", cmd, args); |
7855 | 237 |
238 command=NONE; | |
239 if ( strncmp(cmd,"RGBA32",6)==0 ) { pxsz=4; command = IMG_RGBA32; } | |
240 else if( strncmp(cmd,"ABGR32",6)==0 ) { pxsz=4; command = IMG_ABGR32; } | |
241 else if( strncmp(cmd,"RGB24" ,5)==0 ) { pxsz=3; command = IMG_RGB24; } | |
242 else if( strncmp(cmd,"BGR24" ,5)==0 ) { pxsz=3; command = IMG_BGR24; } | |
243 else if( strncmp(cmd,"CLEAR" ,5)==0 ) { pxsz=1; command = CMD_CLEAR; } | |
244 else if( strncmp(cmd,"ALPHA" ,5)==0 ) { pxsz=1; command = CMD_ALPHA; } | |
245 else if( strncmp(cmd,"OPAQUE",6)==0 ) vf->priv->opaque=TRUE; | |
246 else if( strncmp(cmd,"SHOW", 4)==0 ) vf->priv->hidden=FALSE; | |
247 else if( strncmp(cmd,"HIDE", 4)==0 ) vf->priv->hidden=TRUE; | |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17630
diff
changeset
|
248 else if( strncmp(cmd,"FLUSH" ,5)==0 ) return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); |
7855 | 249 else { |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
250 mp_msg(MSGT_VFILTER, MSGL_WARN, "\nvf_bmovl: Unknown command: '%s'. Ignoring.\n", cmd); |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17630
diff
changeset
|
251 return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); |
7855 | 252 } |
253 | |
254 if(command == CMD_ALPHA) { | |
255 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
|
256 mp_msg(MSGT_VFILTER, MSGL_DBG2, "\nDEBUG: ALPHA: %d %d %d %d %d\n\n", |
7855 | 257 imgw, imgh, imgx, imgy, imgalpha); |
258 if(imgw==0 && imgh==0) vf->priv->opaque=FALSE; | |
259 } | |
260 | |
261 if(command & IS_RAWIMG) { | |
262 sscanf( args, "%d %d %d %d %d %d", | |
263 &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
|
264 mp_msg(MSGT_VFILTER, MSGL_DBG2, "\nDEBUG: RAWIMG: %d %d %d %d %d %d\n\n", |
7855 | 265 imgw, imgh, imgx, imgy, imgalpha, clear); |
266 | |
267 buffer = malloc(imgw*imgh*pxsz); | |
268 if(!buffer) { | |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
269 mp_msg(MSGT_VFILTER, MSGL_WARN, "\nvf_bmovl: Couldn't allocate temporary buffer! Skipping...\n\n"); |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17630
diff
changeset
|
270 return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); |
7855 | 271 } |
11620
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
272 /* pipes/sockets might need multiple calls to read(): */ |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
273 want = (imgw*imgh*pxsz); |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
274 have = 0; |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
275 while (have < want) { |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
276 got = read( vf->priv->stream_fd, buffer+have, want-have ); |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
277 if (got == 0) { |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
278 mp_msg(MSGT_VFILTER, MSGL_WARN, "\nvf_bmovl: premature EOF...\n\n"); |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
279 break; |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
280 } |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
281 if (got < 0) { |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
282 mp_msg(MSGT_VFILTER, MSGL_WARN, "\nvf_bmovl: read error: %s\n\n", strerror(errno)); |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
283 break; |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
284 } |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
285 have += got; |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
286 } |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
287 mp_msg(MSGT_VFILTER, MSGL_DBG2, "Got %d bytes... (wanted %d)\n", have, want ); |
7855 | 288 |
289 if(clear) { | |
290 memset( vf->priv->bitmap.y, 0, vf->priv->w*vf->priv->h ); | |
291 memset( vf->priv->bitmap.u, 128, vf->priv->w*vf->priv->h/4 ); | |
292 memset( vf->priv->bitmap.v, 128, vf->priv->w*vf->priv->h/4 ); | |
293 memset( vf->priv->bitmap.a, 0, vf->priv->w*vf->priv->h ); | |
294 memset( vf->priv->bitmap.oa, 0, vf->priv->w*vf->priv->h ); | |
295 vf->priv->x1 = dmpi->width; | |
296 vf->priv->y1 = dmpi->height; | |
297 vf->priv->x2 = vf->priv->y2 = 0; | |
298 } | |
299 // Define how much of our bitmap that contains graphics! | |
22377
fd54975f9135
Use libavutil's av_clip* instead of unreadable MIN/MAX chaos.
reimar
parents:
19166
diff
changeset
|
300 vf->priv->x1 = av_clip(imgx, 0, vf->priv->x1); |
fd54975f9135
Use libavutil's av_clip* instead of unreadable MIN/MAX chaos.
reimar
parents:
19166
diff
changeset
|
301 vf->priv->y1 = av_clip(imgy, 0, vf->priv->y1); |
fd54975f9135
Use libavutil's av_clip* instead of unreadable MIN/MAX chaos.
reimar
parents:
19166
diff
changeset
|
302 vf->priv->x2 = av_clip(imgx + imgw, vf->priv->x2, vf->priv->w); |
fd54975f9135
Use libavutil's av_clip* instead of unreadable MIN/MAX chaos.
reimar
parents:
19166
diff
changeset
|
303 vf->priv->y2 = av_clip(imgy + imgh, vf->priv->y2, vf->priv->h); |
7855 | 304 } |
305 | |
306 if( command == CMD_CLEAR ) { | |
307 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
|
308 mp_msg(MSGT_VFILTER, MSGL_DBG2, "\nDEBUG: CLEAR: %d %d %d %d\n\n", imgw, imgh, imgx, imgy); |
7855 | 309 |
310 for( ypos=imgy ; (ypos < (imgy+imgh)) && (ypos < vf->priv->y2) ; ypos++ ) { | |
311 memset( vf->priv->bitmap.y + (ypos*vf->priv->w) + imgx, 0, imgw ); | |
312 memset( vf->priv->bitmap.a + (ypos*vf->priv->w) + imgx, 0, imgw ); | |
313 memset( vf->priv->bitmap.oa + (ypos*vf->priv->w) + imgx, 0, imgw ); | |
314 if(ypos%2) { | |
315 memset( vf->priv->bitmap.u + ((ypos/2)*dmpi->stride[1]) + (imgx/2), 128, imgw/2 ); | |
316 memset( vf->priv->bitmap.v + ((ypos/2)*dmpi->stride[2]) + (imgx/2), 128, imgw/2 ); | |
317 } | |
318 } // Recalculate area that contains graphics | |
319 if( (imgx <= vf->priv->x1) && ( (imgw+imgx) >= vf->priv->x2) ) { | |
320 if( (imgy <= vf->priv->y1) && ( (imgy+imgh) >= vf->priv->y1) ) | |
321 vf->priv->y1 = imgy+imgh; | |
322 if( (imgy <= vf->priv->y2) && ( (imgy+imgh) >= vf->priv->y2) ) | |
323 vf->priv->y2 = imgy; | |
324 } | |
325 if( (imgy <= vf->priv->y1) && ( (imgy+imgh) >= vf->priv->y2) ) { | |
326 if( (imgx <= vf->priv->x1) && ( (imgx+imgw) >= vf->priv->x1) ) | |
327 vf->priv->x1 = imgx+imgw; | |
328 if( (imgx <= vf->priv->x2) && ( (imgx+imgw) >= vf->priv->x2) ) | |
329 vf->priv->x2 = imgx; | |
330 } | |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17630
diff
changeset
|
331 return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); |
7855 | 332 } |
333 | |
334 for( buf_y=0 ; (buf_y < imgh) && (buf_y < (vf->priv->h-imgy)) ; buf_y++ ) { | |
335 for( buf_x=0 ; (buf_x < (imgw*pxsz)) && (buf_x < ((vf->priv->w+imgx)*pxsz)) ; buf_x += pxsz ) { | |
336 if(command & IS_RAWIMG) buf_pos = (buf_y * imgw * pxsz) + buf_x; | |
337 pos = ((buf_y+imgy) * vf->priv->w) + ((buf_x/pxsz)+imgx); | |
338 | |
339 switch(command) { | |
340 case IMG_RGBA32: | |
341 red = buffer[buf_pos+0]; | |
342 green = buffer[buf_pos+1]; | |
343 blue = buffer[buf_pos+2]; | |
344 alpha = buffer[buf_pos+3]; | |
345 break; | |
346 case IMG_ABGR32: | |
347 alpha = buffer[buf_pos+0]; | |
348 blue = buffer[buf_pos+1]; | |
349 green = buffer[buf_pos+2]; | |
350 red = buffer[buf_pos+3]; | |
351 break; | |
352 case IMG_RGB24: | |
353 red = buffer[buf_pos+0]; | |
354 green = buffer[buf_pos+1]; | |
355 blue = buffer[buf_pos+2]; | |
356 alpha = 0xFF; | |
357 break; | |
358 case IMG_BGR24: | |
359 blue = buffer[buf_pos+0]; | |
360 green = buffer[buf_pos+1]; | |
361 red = buffer[buf_pos+2]; | |
362 alpha = 0xFF; | |
363 break; | |
364 case CMD_ALPHA: | |
365 vf->priv->bitmap.a[pos] = INRANGE((vf->priv->bitmap.oa[pos]+imgalpha),0,255); | |
366 break; | |
367 default: | |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
368 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
|
369 return FALSE; |
7855 | 370 } |
371 if( command & IS_RAWIMG ) { | |
372 vf->priv->bitmap.y[pos] = rgb2y(red,green,blue); | |
373 vf->priv->bitmap.oa[pos] = alpha; | |
374 vf->priv->bitmap.a[pos] = INRANGE((alpha+imgalpha),0,255); | |
375 if((buf_y%2) && ((buf_x/pxsz)%2)) { | |
376 pos = ( ((buf_y+imgy)/2) * dmpi->stride[1] ) + (((buf_x/pxsz)+imgx)/2); | |
377 vf->priv->bitmap.u[pos] = rgb2u(red,green,blue); | |
378 vf->priv->bitmap.v[pos] = rgb2v(red,green,blue); | |
379 } | |
380 } | |
381 } // for buf_x | |
382 } // for buf_y | |
383 free (buffer); | |
11015
5331f38c8db7
correct handling of select ret=0, patch by Jonas Jensen <jbj@knef.dk>
alex
parents:
10337
diff
changeset
|
384 } else if(ready < 0) { |
5331f38c8db7
correct handling of select ret=0, patch by Jonas Jensen <jbj@knef.dk>
alex
parents:
10337
diff
changeset
|
385 mp_msg(MSGT_VFILTER, MSGL_WARN, "\nvf_bmovl: Error %d in fifo: %s\n\n", errno, strerror(errno)); |
5331f38c8db7
correct handling of select ret=0, patch by Jonas Jensen <jbj@knef.dk>
alex
parents:
10337
diff
changeset
|
386 } |
7855 | 387 } |
388 | |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17630
diff
changeset
|
389 if(vf->priv->hidden) return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); |
7855 | 390 |
391 if(vf->priv->opaque) { // Just copy buffer memory to screen | |
392 for( ypos=vf->priv->y1 ; ypos < vf->priv->y2 ; ypos++ ) { | |
393 memcpy( dmpi->planes[0] + (ypos*dmpi->stride[0]) + vf->priv->x1, | |
394 vf->priv->bitmap.y + (ypos*vf->priv->w) + vf->priv->x1, | |
395 vf->priv->x2 - vf->priv->x1 ); | |
396 if(ypos%2) { | |
397 memcpy( dmpi->planes[1] + ((ypos/2)*dmpi->stride[1]) + (vf->priv->x1/2), | |
398 vf->priv->bitmap.u + (((ypos/2)*(vf->priv->w)/2)) + (vf->priv->x1/2), | |
399 (vf->priv->x2 - vf->priv->x1)/2 ); | |
400 memcpy( dmpi->planes[2] + ((ypos/2)*dmpi->stride[2]) + (vf->priv->x1/2), | |
401 vf->priv->bitmap.v + (((ypos/2)*(vf->priv->w)/2)) + (vf->priv->x1/2), | |
402 (vf->priv->x2 - vf->priv->x1)/2 ); | |
403 } | |
404 } | |
405 } else { // Blit the bitmap to the videoscreen, pixel for pixel | |
406 for( ypos=vf->priv->y1 ; ypos < vf->priv->y2 ; ypos++ ) { | |
407 for ( xpos=vf->priv->x1 ; xpos < vf->priv->x2 ; xpos++ ) { | |
408 pos = (ypos * dmpi->stride[0]) + xpos; | |
409 | |
410 alpha = vf->priv->bitmap.a[pos]; | |
411 | |
412 if (alpha == 0) continue; // Completly transparent pixel | |
413 | |
414 if (alpha == 255) { // Opaque pixel | |
415 dmpi->planes[0][pos] = vf->priv->bitmap.y[pos]; | |
416 if ((ypos%2) && (xpos%2)) { | |
417 pos = ( (ypos/2) * dmpi->stride[1] ) + (xpos/2); | |
418 dmpi->planes[1][pos] = vf->priv->bitmap.u[pos]; | |
419 dmpi->planes[2][pos] = vf->priv->bitmap.v[pos]; | |
420 } | |
421 } 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
|
422 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
|
423 ((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
|
424 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
|
425 |
7855 | 426 if ((ypos%2) && (xpos%2)) { |
427 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
|
428 |
7924a60d833b
This is a simple patch to change the alpha blending code in bmovl to use
arpi
parents:
8878
diff
changeset
|
429 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
|
430 ((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
|
431 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
|
432 |
7924a60d833b
This is a simple patch to change the alpha blending code in bmovl to use
arpi
parents:
8878
diff
changeset
|
433 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
|
434 ((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
|
435 alpha * (int)vf->priv->bitmap.v[pos]) >> 8; |
7855 | 436 } |
437 } | |
438 } // for xpos | |
439 } // for ypos | |
440 } // if !opaque | |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17630
diff
changeset
|
441 return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); |
7855 | 442 } // put_image |
443 | |
444 static int | |
445 vf_open(vf_instance_t* vf, char* args) | |
446 { | |
447 char filename[1000]; | |
448 | |
449 vf->config = config; | |
450 vf->put_image = put_image; | |
451 vf->query_format = query_format; | |
452 vf->uninit = uninit; | |
453 | |
454 vf->priv = malloc(sizeof(struct vf_priv_s)); | |
455 | |
10337 | 456 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
|
457 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
|
458 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
|
459 return FALSE; |
7855 | 460 } |
461 | |
462 vf->priv->stream_fd = open(filename, O_RDWR); | |
463 if(vf->priv->stream_fd >= 0) { | |
464 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
|
465 mp_msg(MSGT_VFILTER, MSGL_INFO, "vf_bmovl: Opened fifo %s as FD %d\n", filename, vf->priv->stream_fd); |
7855 | 466 } else { |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
467 mp_msg(MSGT_VFILTER, MSGL_WARN, "vf_bmovl: Error! Couldn't open FIFO %s: %s\n", filename, strerror(errno)); |
7855 | 468 vf->priv->stream_fd = -1; |
469 } | |
470 | |
471 return TRUE; | |
472 } | |
473 | |
474 vf_info_t vf_info_bmovl = { | |
475 "Read bitmaps from a FIFO and display them in window", | |
476 "bmovl", | |
477 "Per Wigren", | |
478 "", | |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9131
diff
changeset
|
479 vf_open, |
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9131
diff
changeset
|
480 NULL |
7855 | 481 }; |
9832 | 482 |
483 #endif |