Mercurial > mplayer.hg
annotate libmpcodecs/vf_bmovl.c @ 34757:da38eb1e2069
subassconvert: handle "\r\n" line ends
Previously the code converting text subtitles to ASS format converted newline
characters, and only those, to ASS "new line" markup. If the subtitles
contained "\r\n", the "\r" was thus left in the text. In previous libass
versions the "\r" was not visible, but in the current one it produces an empty
box. Improve the conversion to remove the "\r" in that case. Also treat a lone
"\r" as a newline.
Picked from mplayer2/3e0a2705
author | cboesch |
---|---|
date | Sat, 07 Apr 2012 11:17:09 +0000 |
parents | a972c1a4a012 |
children |
rev | line source |
---|---|
27509
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
24969
diff
changeset
|
1 /* |
28924
d5d66bff938a
cosmetics: Remove file names from file header, it only causes trouble.
diego
parents:
27509
diff
changeset
|
2 * BitMap OVerLay video filter for MPlayer |
7855 | 3 * |
4 * (C) 2002 Per Wigren <wigren@home.se> | |
27509
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
24969
diff
changeset
|
5 * |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
24969
diff
changeset
|
6 * This file is part of MPlayer. |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
24969
diff
changeset
|
7 * |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
24969
diff
changeset
|
8 * MPlayer is free software; you can redistribute it and/or modify |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
24969
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
24969
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
24969
diff
changeset
|
11 * (at your option) any later version. |
7855 | 12 * |
27509
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
24969
diff
changeset
|
13 * MPlayer is distributed in the hope that it will be useful, |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
24969
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
24969
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
24969
diff
changeset
|
16 * GNU General Public License for more details. |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
24969
diff
changeset
|
17 * |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
24969
diff
changeset
|
18 * You should have received a copy of the GNU General Public License along |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
24969
diff
changeset
|
19 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
24969
diff
changeset
|
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
24969
diff
changeset
|
21 */ |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
24969
diff
changeset
|
22 |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
24969
diff
changeset
|
23 /* |
7855 | 24 * Use MPlayer as a framebuffer to read bitmaps and commands from a FIFO |
25 * and display them in the window. | |
26 * | |
7895 | 27 * Commands are: |
7855 | 28 * |
7895 | 29 * RGBA32 width height xpos ypos alpha clear |
30 * * Followed by width*height*4 bytes of raw RGBA32 data. | |
31 * ABGR32 width height xpos ypos alpha clear | |
32 * * Followed by width*height*4 bytes of raw ABGR32 data. | |
33 * RGB24 width height xpos ypos alpha clear | |
34 * * Followed by width*height*3 bytes of raw RGB32 data. | |
35 * BGR24 width height xpos ypos alpha clear | |
36 * * Followed by width*height*3 bytes of raw BGR32 data. | |
7855 | 37 * |
7895 | 38 * ALPHA width height xpos ypos alpha |
39 * * Change alpha for area | |
40 * CLEAR width height xpos ypos | |
41 * * Clear area | |
42 * OPAQUE | |
43 * * Disable all alpha transparency! | |
44 * Send "ALPHA 0 0 0 0 0" to enable again! | |
45 * HIDE | |
46 * * Hide bitmap | |
47 * SHOW | |
48 * * Show bitmap | |
7855 | 49 * |
50 * Arguments are: | |
51 * width, height Size of image/area | |
52 * xpos, ypos Start blitting at X/Y position | |
53 * alpha Set alpha difference. 0 means same as original. | |
54 * 255 makes everything opaque | |
55 * -255 makes everything transparent | |
56 * If you set this to -255 you can then send a sequence of | |
57 * ALPHA-commands to set the area to -225, -200, -175 etc | |
58 * for a nice fade-in-effect! ;) | |
59 * clear Clear the framebuffer before blitting. 1 means clear. | |
60 * If 0, the image will just be blitted on top of the old | |
61 * one, so you don't need to send 1,8MB of RGBA32 data | |
62 * everytime a small part of the screen is updated. | |
63 * | |
64 * Arguments for the filter are hidden:opaque:fifo | |
65 * For example 1:0:/tmp/myfifo.fifo will start the filter hidden, transparent | |
66 * and use /tmp/myfifo.fifo as the fifo. | |
67 * | |
68 * If you find bugs, please send me patches! ;) | |
69 * | |
70 * This filter was developed for use in Freevo (http://freevo.sf.net), but | |
71 * anyone is free to use it! ;) | |
72 * | |
73 */ | |
74 | |
75 #include <stdio.h> | |
76 #include <stdlib.h> | |
77 #include <string.h> | |
78 #include <unistd.h> | |
79 #include <errno.h> | |
80 #include <sys/stat.h> | |
81 #include <sys/types.h> | |
7858 | 82 #include <sys/time.h> |
7855 | 83 #include <fcntl.h> |
17630 | 84 #include "config.h" |
7855 | 85 #include "mp_image.h" |
86 #include "vf.h" | |
87 #include "img_format.h" | |
9832 | 88 |
17012 | 89 #include "mp_msg.h" |
22377
fd54975f9135
Use libavutil's av_clip* instead of unreadable MIN/MAX chaos.
reimar
parents:
19166
diff
changeset
|
90 #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
|
91 |
17012 | 92 #include "libvo/fastmemcpy.h" |
7855 | 93 |
94 #define IS_RAWIMG 0x100 | |
95 #define IS_IMG 0x200 | |
96 | |
97 #define NONE 0x000 | |
98 #define IMG_RGBA32 0x101 | |
99 #define IMG_ABGR32 0x102 | |
100 #define IMG_RGB24 0x103 | |
101 #define IMG_BGR24 0x104 | |
102 #define IMG_PNG 0x201 | |
103 #define CMD_CLEAR 0x001 | |
104 #define CMD_ALPHA 0x002 | |
105 | |
106 #define TRUE 1 | |
107 #define FALSE 0 | |
108 | |
109 #define INRANGE(a,b,c) ( ((a) < (b)) ? (b) : ( ((a) > (c)) ? (c) : (a) ) ) | |
110 | |
9131
67d28a3f918a
The code for converting RGB to YUV in bmovl is slow because it uses
arpi
parents:
9110
diff
changeset
|
111 #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
|
112 #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
|
113 #define rgb2v(R,G,B) ( (( 450*R - 376*G - 73*B) >> 10) + 128 ) |
7855 | 114 |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
115 #define DBG(a) (mp_msg(MSGT_VFILTER, MSGL_DBG2, "DEBUG: %d\n", a)) |
7855 | 116 |
117 struct vf_priv_s { | |
118 int w, h, x1, y1, x2, y2; | |
119 struct { | |
120 unsigned char *y, *u, *v, *a, *oa; | |
121 } bitmap; | |
122 int stream_fd; | |
123 fd_set stream_fdset; | |
124 int opaque, hidden; | |
125 }; | |
126 | |
127 static int | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
128 query_format(struct vf_instance *vf, unsigned int fmt){ |
7855 | 129 if(fmt==IMGFMT_YV12) return VFCAP_CSP_SUPPORTED; |
130 return 0; | |
131 } | |
132 | |
133 | |
134 static int | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
135 config(struct vf_instance *vf, |
7855 | 136 int width, int height, int d_width, int d_height, |
137 unsigned int flags, unsigned int outfmt) | |
138 { | |
139 vf->priv->bitmap.y = malloc( width*height ); | |
140 vf->priv->bitmap.u = malloc( width*height/4 ); | |
141 vf->priv->bitmap.v = malloc( width*height/4 ); | |
142 vf->priv->bitmap.a = malloc( width*height ); | |
143 vf->priv->bitmap.oa = malloc( width*height ); | |
144 if(!( vf->priv->bitmap.y && | |
145 vf->priv->bitmap.u && | |
146 vf->priv->bitmap.v && | |
147 vf->priv->bitmap.a && | |
148 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
|
149 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
|
150 return FALSE; |
7855 | 151 } |
152 | |
153 // Set default to black... | |
154 memset( vf->priv->bitmap.u, 128, width*height/4 ); | |
155 memset( vf->priv->bitmap.v, 128, width*height/4 ); | |
156 | |
157 vf->priv->w = vf->priv->x1 = width; | |
158 vf->priv->h = vf->priv->y1 = height; | |
159 vf->priv->y2 = vf->priv->x2 = 0; | |
160 | |
161 return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt); | |
162 } | |
163 | |
164 static void | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
165 uninit(struct vf_instance *vf) |
7855 | 166 { |
167 if(vf->priv) { | |
168 free(vf->priv->bitmap.y); | |
169 free(vf->priv->bitmap.u); | |
170 free(vf->priv->bitmap.v); | |
171 free(vf->priv->bitmap.a); | |
172 free(vf->priv->bitmap.oa); | |
16886
ea32158ad57b
close stream_fd on uninit. Fixes bugzilla bug #400.
reimar
parents:
11620
diff
changeset
|
173 if (vf->priv->stream_fd >= 0) |
ea32158ad57b
close stream_fd on uninit. Fixes bugzilla bug #400.
reimar
parents:
11620
diff
changeset
|
174 close(vf->priv->stream_fd); |
7855 | 175 free(vf->priv); |
176 } | |
177 } | |
178 | |
179 static int | |
180 _read_cmd(int fd, char *cmd, char *args) { | |
181 int done=FALSE, pos=0; | |
182 char tmp; | |
183 | |
184 while(!done) { | |
185 if(! read( fd, &tmp, 1 ) ) return FALSE; | |
186 if( (tmp>='A' && tmp<='Z') || (tmp>='0' && tmp<='9') ) | |
187 cmd[pos]=tmp; | |
188 else if(tmp == ' ') { | |
189 cmd[pos]='\0'; | |
190 done=TRUE; | |
191 } | |
192 else if(tmp == '\n') { | |
193 cmd[pos]='\0'; | |
194 args[0]='\0'; | |
195 return TRUE; | |
196 } | |
197 if(pos++>20) { | |
198 cmd[0]='\0'; | |
199 return TRUE; | |
200 } | |
201 } | |
202 done=FALSE; pos=0; | |
203 while(!done) { | |
204 if(! read( fd, &tmp, 1 ) ) return FALSE; | |
205 if( (tmp >= ' ') && (pos<100) ) args[pos]=tmp; | |
206 else { | |
207 args[pos]='\0'; | |
208 done=TRUE; | |
209 } | |
210 pos++; | |
211 } | |
212 return TRUE; | |
213 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28924
diff
changeset
|
214 |
7855 | 215 |
216 static int | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
217 put_image(struct vf_instance *vf, mp_image_t* mpi, double pts){ |
7855 | 218 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
|
219 int have, got, want; |
7855 | 220 int xpos=0, ypos=0, pos=0; |
221 unsigned char red=0, green=0, blue=0; | |
222 int alpha; | |
223 mp_image_t* dmpi; | |
224 | |
225 dmpi = vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_TEMP, | |
226 MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE, | |
227 mpi->w, mpi->h); | |
228 | |
19166
d36048cad8c4
in some cases, vf_bmovl produces junk due to source and
gpoirier
parents:
17906
diff
changeset
|
229 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
|
230 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
|
231 memcpy_pic( dmpi->planes[2], mpi->planes[2], mpi->chroma_width, mpi->chroma_height, dmpi->stride[2], mpi->stride[2] ); |
7855 | 232 |
233 if(vf->priv->stream_fd >= 0) { | |
234 struct timeval tv; | |
11015
5331f38c8db7
correct handling of select ret=0, patch by Jonas Jensen <jbj@knef.dk>
alex
parents:
10337
diff
changeset
|
235 int ready; |
7855 | 236 |
237 FD_SET( vf->priv->stream_fd, &vf->priv->stream_fdset ); | |
238 tv.tv_sec=0; tv.tv_usec=0; | |
239 | |
11015
5331f38c8db7
correct handling of select ret=0, patch by Jonas Jensen <jbj@knef.dk>
alex
parents:
10337
diff
changeset
|
240 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
|
241 if(ready > 0) { |
7855 | 242 // We've got new data from the FIFO |
243 | |
244 char cmd[20], args[100]; | |
245 int imgw,imgh,imgx,imgy,clear,imgalpha,pxsz=1,command; | |
246 unsigned char *buffer = NULL; | |
247 | |
248 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
|
249 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
|
250 return FALSE; |
7855 | 251 } |
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: Got: %s+%s\n", cmd, args); |
7855 | 253 |
254 command=NONE; | |
255 if ( strncmp(cmd,"RGBA32",6)==0 ) { pxsz=4; command = IMG_RGBA32; } | |
256 else if( strncmp(cmd,"ABGR32",6)==0 ) { pxsz=4; command = IMG_ABGR32; } | |
257 else if( strncmp(cmd,"RGB24" ,5)==0 ) { pxsz=3; command = IMG_RGB24; } | |
258 else if( strncmp(cmd,"BGR24" ,5)==0 ) { pxsz=3; command = IMG_BGR24; } | |
259 else if( strncmp(cmd,"CLEAR" ,5)==0 ) { pxsz=1; command = CMD_CLEAR; } | |
260 else if( strncmp(cmd,"ALPHA" ,5)==0 ) { pxsz=1; command = CMD_ALPHA; } | |
261 else if( strncmp(cmd,"OPAQUE",6)==0 ) vf->priv->opaque=TRUE; | |
262 else if( strncmp(cmd,"SHOW", 4)==0 ) vf->priv->hidden=FALSE; | |
263 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
|
264 else if( strncmp(cmd,"FLUSH" ,5)==0 ) return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); |
7855 | 265 else { |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
266 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
|
267 return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); |
7855 | 268 } |
269 | |
270 if(command == CMD_ALPHA) { | |
271 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
|
272 mp_msg(MSGT_VFILTER, MSGL_DBG2, "\nDEBUG: ALPHA: %d %d %d %d %d\n\n", |
7855 | 273 imgw, imgh, imgx, imgy, imgalpha); |
274 if(imgw==0 && imgh==0) vf->priv->opaque=FALSE; | |
275 } | |
276 | |
277 if(command & IS_RAWIMG) { | |
278 sscanf( args, "%d %d %d %d %d %d", | |
279 &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
|
280 mp_msg(MSGT_VFILTER, MSGL_DBG2, "\nDEBUG: RAWIMG: %d %d %d %d %d %d\n\n", |
7855 | 281 imgw, imgh, imgx, imgy, imgalpha, clear); |
282 | |
283 buffer = malloc(imgw*imgh*pxsz); | |
284 if(!buffer) { | |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
285 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
|
286 return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); |
7855 | 287 } |
11620
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
288 /* 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
|
289 want = (imgw*imgh*pxsz); |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
290 have = 0; |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
291 while (have < want) { |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
292 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
|
293 if (got == 0) { |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
294 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
|
295 break; |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
296 } |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
297 if (got < 0) { |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
298 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
|
299 break; |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
300 } |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
301 have += got; |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
302 } |
39ae20e6ad9d
fix bug when bmovl can't read the whole pic at once
attila
parents:
11015
diff
changeset
|
303 mp_msg(MSGT_VFILTER, MSGL_DBG2, "Got %d bytes... (wanted %d)\n", have, want ); |
7855 | 304 |
305 if(clear) { | |
306 memset( vf->priv->bitmap.y, 0, vf->priv->w*vf->priv->h ); | |
307 memset( vf->priv->bitmap.u, 128, vf->priv->w*vf->priv->h/4 ); | |
308 memset( vf->priv->bitmap.v, 128, vf->priv->w*vf->priv->h/4 ); | |
309 memset( vf->priv->bitmap.a, 0, vf->priv->w*vf->priv->h ); | |
310 memset( vf->priv->bitmap.oa, 0, vf->priv->w*vf->priv->h ); | |
311 vf->priv->x1 = dmpi->width; | |
312 vf->priv->y1 = dmpi->height; | |
313 vf->priv->x2 = vf->priv->y2 = 0; | |
314 } | |
315 // 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
|
316 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
|
317 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
|
318 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
|
319 vf->priv->y2 = av_clip(imgy + imgh, vf->priv->y2, vf->priv->h); |
7855 | 320 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28924
diff
changeset
|
321 |
7855 | 322 if( command == CMD_CLEAR ) { |
323 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
|
324 mp_msg(MSGT_VFILTER, MSGL_DBG2, "\nDEBUG: CLEAR: %d %d %d %d\n\n", imgw, imgh, imgx, imgy); |
7855 | 325 |
326 for( ypos=imgy ; (ypos < (imgy+imgh)) && (ypos < vf->priv->y2) ; ypos++ ) { | |
327 memset( vf->priv->bitmap.y + (ypos*vf->priv->w) + imgx, 0, imgw ); | |
328 memset( vf->priv->bitmap.a + (ypos*vf->priv->w) + imgx, 0, imgw ); | |
329 memset( vf->priv->bitmap.oa + (ypos*vf->priv->w) + imgx, 0, imgw ); | |
330 if(ypos%2) { | |
331 memset( vf->priv->bitmap.u + ((ypos/2)*dmpi->stride[1]) + (imgx/2), 128, imgw/2 ); | |
332 memset( vf->priv->bitmap.v + ((ypos/2)*dmpi->stride[2]) + (imgx/2), 128, imgw/2 ); | |
333 } | |
334 } // Recalculate area that contains graphics | |
335 if( (imgx <= vf->priv->x1) && ( (imgw+imgx) >= vf->priv->x2) ) { | |
336 if( (imgy <= vf->priv->y1) && ( (imgy+imgh) >= vf->priv->y1) ) | |
337 vf->priv->y1 = imgy+imgh; | |
338 if( (imgy <= vf->priv->y2) && ( (imgy+imgh) >= vf->priv->y2) ) | |
339 vf->priv->y2 = imgy; | |
340 } | |
341 if( (imgy <= vf->priv->y1) && ( (imgy+imgh) >= vf->priv->y2) ) { | |
342 if( (imgx <= vf->priv->x1) && ( (imgx+imgw) >= vf->priv->x1) ) | |
343 vf->priv->x1 = imgx+imgw; | |
344 if( (imgx <= vf->priv->x2) && ( (imgx+imgw) >= vf->priv->x2) ) | |
345 vf->priv->x2 = imgx; | |
346 } | |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17630
diff
changeset
|
347 return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); |
7855 | 348 } |
349 | |
350 for( buf_y=0 ; (buf_y < imgh) && (buf_y < (vf->priv->h-imgy)) ; buf_y++ ) { | |
351 for( buf_x=0 ; (buf_x < (imgw*pxsz)) && (buf_x < ((vf->priv->w+imgx)*pxsz)) ; buf_x += pxsz ) { | |
352 if(command & IS_RAWIMG) buf_pos = (buf_y * imgw * pxsz) + buf_x; | |
353 pos = ((buf_y+imgy) * vf->priv->w) + ((buf_x/pxsz)+imgx); | |
354 | |
355 switch(command) { | |
356 case IMG_RGBA32: | |
357 red = buffer[buf_pos+0]; | |
358 green = buffer[buf_pos+1]; | |
359 blue = buffer[buf_pos+2]; | |
360 alpha = buffer[buf_pos+3]; | |
361 break; | |
362 case IMG_ABGR32: | |
363 alpha = buffer[buf_pos+0]; | |
364 blue = buffer[buf_pos+1]; | |
365 green = buffer[buf_pos+2]; | |
366 red = buffer[buf_pos+3]; | |
367 break; | |
368 case IMG_RGB24: | |
369 red = buffer[buf_pos+0]; | |
370 green = buffer[buf_pos+1]; | |
371 blue = buffer[buf_pos+2]; | |
372 alpha = 0xFF; | |
373 break; | |
374 case IMG_BGR24: | |
375 blue = buffer[buf_pos+0]; | |
376 green = buffer[buf_pos+1]; | |
377 red = buffer[buf_pos+2]; | |
378 alpha = 0xFF; | |
379 break; | |
380 case CMD_ALPHA: | |
381 vf->priv->bitmap.a[pos] = INRANGE((vf->priv->bitmap.oa[pos]+imgalpha),0,255); | |
382 break; | |
383 default: | |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
384 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
|
385 return FALSE; |
7855 | 386 } |
387 if( command & IS_RAWIMG ) { | |
388 vf->priv->bitmap.y[pos] = rgb2y(red,green,blue); | |
389 vf->priv->bitmap.oa[pos] = alpha; | |
390 vf->priv->bitmap.a[pos] = INRANGE((alpha+imgalpha),0,255); | |
391 if((buf_y%2) && ((buf_x/pxsz)%2)) { | |
392 pos = ( ((buf_y+imgy)/2) * dmpi->stride[1] ) + (((buf_x/pxsz)+imgx)/2); | |
393 vf->priv->bitmap.u[pos] = rgb2u(red,green,blue); | |
394 vf->priv->bitmap.v[pos] = rgb2v(red,green,blue); | |
395 } | |
396 } | |
397 } // for buf_x | |
398 } // for buf_y | |
399 free (buffer); | |
11015
5331f38c8db7
correct handling of select ret=0, patch by Jonas Jensen <jbj@knef.dk>
alex
parents:
10337
diff
changeset
|
400 } else if(ready < 0) { |
5331f38c8db7
correct handling of select ret=0, patch by Jonas Jensen <jbj@knef.dk>
alex
parents:
10337
diff
changeset
|
401 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
|
402 } |
7855 | 403 } |
404 | |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17630
diff
changeset
|
405 if(vf->priv->hidden) return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); |
7855 | 406 |
407 if(vf->priv->opaque) { // Just copy buffer memory to screen | |
408 for( ypos=vf->priv->y1 ; ypos < vf->priv->y2 ; ypos++ ) { | |
23457
a124f3abc1ec
Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents:
22752
diff
changeset
|
409 fast_memcpy( dmpi->planes[0] + (ypos*dmpi->stride[0]) + vf->priv->x1, |
7855 | 410 vf->priv->bitmap.y + (ypos*vf->priv->w) + vf->priv->x1, |
411 vf->priv->x2 - vf->priv->x1 ); | |
412 if(ypos%2) { | |
23457
a124f3abc1ec
Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents:
22752
diff
changeset
|
413 fast_memcpy( dmpi->planes[1] + ((ypos/2)*dmpi->stride[1]) + (vf->priv->x1/2), |
7855 | 414 vf->priv->bitmap.u + (((ypos/2)*(vf->priv->w)/2)) + (vf->priv->x1/2), |
415 (vf->priv->x2 - vf->priv->x1)/2 ); | |
23457
a124f3abc1ec
Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents:
22752
diff
changeset
|
416 fast_memcpy( dmpi->planes[2] + ((ypos/2)*dmpi->stride[2]) + (vf->priv->x1/2), |
7855 | 417 vf->priv->bitmap.v + (((ypos/2)*(vf->priv->w)/2)) + (vf->priv->x1/2), |
418 (vf->priv->x2 - vf->priv->x1)/2 ); | |
419 } | |
420 } | |
421 } else { // Blit the bitmap to the videoscreen, pixel for pixel | |
422 for( ypos=vf->priv->y1 ; ypos < vf->priv->y2 ; ypos++ ) { | |
423 for ( xpos=vf->priv->x1 ; xpos < vf->priv->x2 ; xpos++ ) { | |
424 pos = (ypos * dmpi->stride[0]) + xpos; | |
425 | |
426 alpha = vf->priv->bitmap.a[pos]; | |
427 | |
428 if (alpha == 0) continue; // Completly transparent pixel | |
429 | |
430 if (alpha == 255) { // Opaque pixel | |
431 dmpi->planes[0][pos] = vf->priv->bitmap.y[pos]; | |
432 if ((ypos%2) && (xpos%2)) { | |
433 pos = ( (ypos/2) * dmpi->stride[1] ) + (xpos/2); | |
434 dmpi->planes[1][pos] = vf->priv->bitmap.u[pos]; | |
435 dmpi->planes[2][pos] = vf->priv->bitmap.v[pos]; | |
436 } | |
437 } else { // Alphablended pixel | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28924
diff
changeset
|
438 dmpi->planes[0][pos] = |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28924
diff
changeset
|
439 ((255 - alpha) * (int)dmpi->planes[0][pos] + |
9110
7924a60d833b
This is a simple patch to change the alpha blending code in bmovl to use
arpi
parents:
8878
diff
changeset
|
440 alpha * (int)vf->priv->bitmap.y[pos]) >> 8; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28924
diff
changeset
|
441 |
7855 | 442 if ((ypos%2) && (xpos%2)) { |
443 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
|
444 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28924
diff
changeset
|
445 dmpi->planes[1][pos] = |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28924
diff
changeset
|
446 ((255 - alpha) * (int)dmpi->planes[1][pos] + |
9110
7924a60d833b
This is a simple patch to change the alpha blending code in bmovl to use
arpi
parents:
8878
diff
changeset
|
447 alpha * (int)vf->priv->bitmap.u[pos]) >> 8; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28924
diff
changeset
|
448 |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28924
diff
changeset
|
449 dmpi->planes[2][pos] = |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28924
diff
changeset
|
450 ((255 - alpha) * (int)dmpi->planes[2][pos] + |
9110
7924a60d833b
This is a simple patch to change the alpha blending code in bmovl to use
arpi
parents:
8878
diff
changeset
|
451 alpha * (int)vf->priv->bitmap.v[pos]) >> 8; |
7855 | 452 } |
453 } | |
454 } // for xpos | |
455 } // for ypos | |
456 } // 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
|
457 return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); |
7855 | 458 } // put_image |
459 | |
460 static int | |
30638
a7b908875c14
Rename open() vf initialization function to vf_open().
diego
parents:
29263
diff
changeset
|
461 vf_open(vf_instance_t *vf, char *args) |
7855 | 462 { |
463 char filename[1000]; | |
464 | |
465 vf->config = config; | |
466 vf->put_image = put_image; | |
467 vf->query_format = query_format; | |
468 vf->uninit = uninit; | |
469 | |
470 vf->priv = malloc(sizeof(struct vf_priv_s)); | |
471 | |
10337 | 472 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
|
473 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
|
474 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
|
475 return FALSE; |
7855 | 476 } |
477 | |
478 vf->priv->stream_fd = open(filename, O_RDWR); | |
479 if(vf->priv->stream_fd >= 0) { | |
480 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
|
481 mp_msg(MSGT_VFILTER, MSGL_INFO, "vf_bmovl: Opened fifo %s as FD %d\n", filename, vf->priv->stream_fd); |
7855 | 482 } else { |
8878
12e69a0d5a67
may not be perfect but it's certainly a start. feel free to change
rfelker
parents:
7895
diff
changeset
|
483 mp_msg(MSGT_VFILTER, MSGL_WARN, "vf_bmovl: Error! Couldn't open FIFO %s: %s\n", filename, strerror(errno)); |
7855 | 484 vf->priv->stream_fd = -1; |
485 } | |
486 | |
487 return TRUE; | |
488 } | |
489 | |
24969
c2b7ba444ade
begin moving const filter data to .text/.rodata sections
rfelker
parents:
23457
diff
changeset
|
490 const vf_info_t vf_info_bmovl = { |
7855 | 491 "Read bitmaps from a FIFO and display them in window", |
492 "bmovl", | |
493 "Per Wigren", | |
494 "", | |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9131
diff
changeset
|
495 vf_open, |
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9131
diff
changeset
|
496 NULL |
7855 | 497 }; |