Mercurial > mplayer.hg
annotate libvo/vo_gif89a.c @ 27082:2a486144b5c7
remove some useless functions from vidix api
author | ben |
---|---|
date | Fri, 20 Jun 2008 20:21:31 +0000 |
parents | c9e9ac2008c2 |
children | 2113bd9c6bd9 |
rev | line source |
---|---|
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
1 /* |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
2 MPlayer video driver for animated gif output |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
3 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
4 (C) 2002 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
5 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
6 Written by Joey Parrish <joey@nicewarrior.org> |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
7 Based on vo_directfb2.c |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
8 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
9 This library is free software; you can redistribute it and/or |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
10 modify it under the terms of the GNU Lesser General Public |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
11 License as published by the Free Software Foundation; either |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
12 version 2 of the License, or (at your option) any later version. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
13 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
14 This library is distributed in the hope that it will be useful, |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
15 but WITHOUT ANY WARRANTY; without even the implied warranty of |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
17 Lesser General Public License for more details. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
18 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
19 You should have received a copy of the GNU Lesser General Public |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
20 License along with this library; if not, write to the |
19614 | 21 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
22 Boston, MA 02110-1301 USA. | |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
23 */ |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
24 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
25 /* Notes: |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
26 * when setting output framerate, frames will be ignored as needed |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
27 * to achieve the desired rate. no frames will be duplicated. |
6053 | 28 * |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
29 * output framerate can be specified as a float |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
30 * value now, instead of just an int. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
31 * |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
32 * adjustments will be made to both the frame drop cycle and the |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
33 * delay per frame to achieve the desired output framerate. |
6053 | 34 * |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
35 * time values are in centiseconds, because that's |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
36 * what the gif spec uses for it's delay values. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
37 * |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
38 * preinit looks for arguments in one of the following formats (in this order): |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
39 * fps:filename -- sets the framerate (float) and output file |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
40 * fps -- sets the framerate (float), default file out.gif |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
41 * filename -- defaults to 5 fps, sets output file |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
42 * (none) -- defaults to 5 fps, output file out.gif |
6053 | 43 * |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
44 * trying to put the filename before the framerate will result in the |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
45 * entire argument being interpretted as the filename. |
6053 | 46 */ |
47 | |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
48 #include <gif_lib.h> |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
49 |
6053 | 50 #include <stdio.h> |
51 #include <stdlib.h> | |
52 #include <string.h> | |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
53 #include <unistd.h> |
6053 | 54 |
55 #include "config.h" | |
16721 | 56 #include "subopt-helper.h" |
6053 | 57 #include "video_out.h" |
58 #include "video_out_internal.h" | |
16721 | 59 #include "mp_msg.h" |
6053 | 60 |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
61 #define MPLAYER_VERSION 0.90 |
9540 | 62 #define VO_GIF_REVISION 6 |
6053 | 63 |
25216 | 64 static const vo_info_t info = { |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
65 "animated GIF output", |
6053 | 66 "gif89a", |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
67 "Joey Parrish joey@nicewarrior.org", |
6053 | 68 "" |
69 }; | |
70 | |
25220
c9e9ac2008c2
Mark the vo_functions_t definitions as const where possible.
reimar
parents:
25216
diff
changeset
|
71 const LIBVO_EXTERN(gif89a) |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
8123
diff
changeset
|
72 |
6053 | 73 |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
74 // how many frames per second we are aiming for during output. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
75 static float target_fps; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
76 // default value for output fps. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
77 static const float default_fps = 5.00; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
78 // the ideal gif delay per frame. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
79 static float ideal_delay; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
80 // the ideal time thus far. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
81 static float ideal_time; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
82 // actual time thus far. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
83 static int real_time; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
84 // nominal framedrop cycle length in frames |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
85 static float frame_cycle; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
86 // position in the framedrop cycle |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
87 static int cycle_pos; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
88 // adjustment of the framedrop cycle |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
89 static float frame_adj; |
6053 | 90 |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
91 // the output width and height |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
92 static uint32_t img_width; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
93 static uint32_t img_height; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
94 // image data for slice rendering |
8665 | 95 static uint8_t *slice_data = NULL; |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
96 // reduced image data for flip_page |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
97 static uint8_t *reduce_data = NULL; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
98 // reduced color map for flip_page |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
99 static ColorMapObject *reduce_cmap = NULL; |
6053 | 100 |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
101 // a pointer to the gif structure |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
102 static GifFileType *new_gif = NULL; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
103 // a string to contain the filename of the output gif |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
104 static char *gif_filename = NULL; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
105 // the default output filename |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
106 #define DEFAULT_FILE "out.gif" |
6053 | 107 |
16721 | 108 static opt_t subopts[] = { |
109 {"output", OPT_ARG_MSTRZ, &gif_filename, NULL, 0}, | |
110 {"fps", OPT_ARG_FLOAT, &target_fps, NULL, 0}, | |
111 {NULL, 0, NULL, NULL, 0} | |
112 }; | |
113 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
114 static int preinit(const char *arg) |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
115 { |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
116 target_fps = 0; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
117 |
16721 | 118 if (subopt_parse(arg, subopts) != 0) { |
119 mp_msg(MSGT_VO, MSGL_FATAL, | |
120 "\n-vo gif89a command line help:\n" | |
121 "Example: mplayer -vo gif89a:output=file.gif:fps=4.9\n" | |
122 "\nOptions:\n" | |
123 " output=<filename>\n" | |
124 " Specify the output file. The default is out.gif.\n" | |
125 " fps=<rate>\n" | |
126 " Specify the target framerate. The default is 5.0.\n" | |
127 "\n"); | |
128 return -1; | |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
129 } |
6053 | 130 |
16721 | 131 if (target_fps > vo_fps) |
132 target_fps = vo_fps; // i will not duplicate frames. | |
133 | |
134 if (target_fps <= 0) { | |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
135 target_fps = default_fps; |
16721 | 136 mp_msg(MSGT_VO, MSGL_V, "GIF89a: default, %.2f fps\n", target_fps); |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
137 } else { |
16721 | 138 mp_msg(MSGT_VO, MSGL_V, "GIF89a: output fps forced to %.2f\n", target_fps); |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
139 } |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
140 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
141 ideal_delay = 100 / target_fps; // in centiseconds |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
142 frame_cycle = vo_fps / target_fps; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
143 // we make one output frame every (frame_cycle) frames, on average. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
144 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
145 if (gif_filename == NULL) { |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
146 gif_filename = strdup(DEFAULT_FILE); |
16721 | 147 mp_msg(MSGT_VO, MSGL_V, "GIF89a: default, file \"%s\"\n", gif_filename); |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
148 } else { |
16721 | 149 mp_msg(MSGT_VO, MSGL_V, "GIF89a: file forced to \"%s\"\n", gif_filename); |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
150 } |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
151 |
16721 | 152 mp_msg(MSGT_VO, MSGL_DBG2, "GIF89a: Preinit OK\n"); |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
153 return 0; |
6053 | 154 } |
155 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
156 static int config(uint32_t s_width, uint32_t s_height, uint32_t d_width, |
15212
05aa13cdf92f
replace VO and VF numeric flags with #defined identifiers
henry
parents:
11865
diff
changeset
|
157 uint32_t d_height, uint32_t flags, char *title, |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
158 uint32_t format) |
6053 | 159 { |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
160 #ifdef HAVE_GIF_4 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
161 // these are control blocks for the gif looping extension. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
162 char LB1[] = "NETSCAPE2.0"; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
163 char LB2[] = { 1, 0, 0 }; |
6078
4a9c7041141d
cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
6053
diff
changeset
|
164 #endif |
4a9c7041141d
cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
6053
diff
changeset
|
165 |
17366 | 166 mp_msg(MSGT_VO, MSGL_DBG2, "GIF89a: Config entered [%dx%d]\n", s_width,s_height); |
16721 | 167 mp_msg(MSGT_VO, MSGL_DBG2, "GIF89a: With requested format: %s\n", vo_format_name(format)); |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
168 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
169 // save these for later. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
170 img_width = s_width; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
171 img_height = s_height; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
172 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
173 // multiple configs without uninit are not allowed. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
174 // this is because config opens a new gif file. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
175 if (vo_config_count > 0) { |
16721 | 176 mp_msg(MSGT_VO, MSGL_V, "GIF89a: Reconfigure attempted.\n"); |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
177 return 0; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
178 } |
8665 | 179 // reconfigure need not be a fatal error, so return 0. |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
180 // multiple configs without uninit will result in two |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
181 // movies concatenated in one gif file. the output |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
182 // gif will have the dimensions of the first movie. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
183 |
9540 | 184 if (format != IMGFMT_RGB24) { |
16721 | 185 mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: Error - given unsupported colorspace.\n"); |
9540 | 186 return 1; |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
187 } |
9540 | 188 |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
189 // the EGifSetGifVersion line causes segfaults in certain |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
190 // earlier versions of libungif. i don't know exactly which, |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
191 // but certainly in all those before v4. if you have problems, |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
192 // you need to upgrade your gif library. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
193 #ifdef HAVE_GIF_4 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
194 EGifSetGifVersion("89a"); |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
195 #else |
16721 | 196 mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: Your version of libungif needs to be upgraded.\n"); |
197 mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: Some functionality has been disabled.\n"); | |
6078
4a9c7041141d
cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
6053
diff
changeset
|
198 #endif |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
199 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
200 new_gif = EGifOpenFileName(gif_filename, 0); |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
201 if (new_gif == NULL) { |
16721 | 202 mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: error opening file \"%s\" for output.\n", gif_filename); |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
203 return 1; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
204 } |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
205 |
9540 | 206 slice_data = malloc(img_width * img_height * 3); |
207 if (slice_data == NULL) { | |
16721 | 208 mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: malloc failed.\n"); |
9540 | 209 return 1; |
210 } | |
211 | |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
212 reduce_data = malloc(img_width * img_height); |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
213 if (reduce_data == NULL) { |
16721 | 214 free(slice_data); slice_data = NULL; |
215 mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: malloc failed.\n"); | |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
216 return 1; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
217 } |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
218 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
219 reduce_cmap = MakeMapObject(256, NULL); |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
220 if (reduce_cmap == NULL) { |
16721 | 221 free(slice_data); slice_data = NULL; |
222 free(reduce_data); reduce_data = NULL; | |
223 mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: malloc failed.\n"); | |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
224 return 1; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
225 } |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
226 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
227 // initialize the delay and framedrop variables. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
228 ideal_time = 0; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
229 real_time = 0; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
230 cycle_pos = 0; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
231 frame_adj = 0; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
232 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
233 // set the initial width and height info. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
234 EGifPutScreenDesc(new_gif, s_width, s_height, 256, 0, reduce_cmap); |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
235 #ifdef HAVE_GIF_4 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
236 // version 3 of libungif does not support multiple control blocks. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
237 // looping requires multiple control blocks. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
238 // therefore, looping is only enabled for v4 and up. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
239 EGifPutExtensionFirst(new_gif, 0xFF, 11, LB1); |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
240 EGifPutExtensionLast(new_gif, 0, 3, LB2); |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
241 #endif |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
242 |
16721 | 243 mp_msg(MSGT_VO, MSGL_DBG2, "GIF89a: Config finished.\n"); |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
244 return 0; |
6053 | 245 } |
246 | |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
247 // we do not draw osd. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
248 void draw_osd() {} |
6053 | 249 |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
250 // we do not handle events. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
251 static void check_events(void) {} |
6053 | 252 |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
253 static int gif_reduce(int width, int height, uint8_t *src, uint8_t *dst, GifColorType *colors) |
6053 | 254 { |
255 unsigned char Ra[width * height]; | |
256 unsigned char Ga[width * height]; | |
257 unsigned char Ba[width * height]; | |
258 unsigned char *R, *G, *B; | |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
259 int size = 256; |
6053 | 260 int i; |
261 | |
262 R = Ra; G = Ga; B = Ba; | |
263 for (i = 0; i < width * height; i++) | |
264 { | |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
265 *R++ = *src++; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
266 *G++ = *src++; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
267 *B++ = *src++; |
6053 | 268 } |
269 | |
270 R = Ra; G = Ga; B = Ba; | |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
271 return QuantizeBuffer(width, height, &size, R, G, B, dst, colors); |
6053 | 272 } |
273 | |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
274 static void flip_page(void) |
6053 | 275 { |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
276 char CB[4]; // control block |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
277 int delay = 0; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
278 int ret; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
279 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
280 cycle_pos++; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
281 if (cycle_pos < frame_cycle - frame_adj) |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
282 return; // we are skipping this frame |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
283 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
284 // quantize the image |
9540 | 285 ret = gif_reduce(img_width, img_height, slice_data, reduce_data, reduce_cmap->Colors); |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
286 if (ret == GIF_ERROR) { |
16721 | 287 mp_msg(MSGT_VO, MSGL_ERR, "GIF89a: Quantize failed.\n"); |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
288 return; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
289 } |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
290 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
291 // calculate frame delays and frame skipping |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
292 ideal_time += ideal_delay; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
293 delay = (int)(ideal_time - real_time); |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
294 real_time += delay; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
295 frame_adj += cycle_pos; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
296 frame_adj -= frame_cycle; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
297 cycle_pos = 0; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
298 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
299 // set up the delay control block |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
300 CB[0] = (char)(delay >> 8); |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
301 CB[1] = (char)(delay & 0xff); |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
302 CB[2] = 0; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
303 CB[3] = 0; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
304 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
305 // put the control block with delay info |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
306 EGifPutExtension(new_gif, 0xF9, 0x04, CB); |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
307 // put the image description |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
308 EGifPutImageDesc(new_gif, 0, 0, img_width, img_height, 0, reduce_cmap); |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
309 // put the image itself |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
310 EGifPutLine(new_gif, reduce_data, img_width * img_height); |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
311 } |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
312 |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
313 static int draw_frame(uint8_t *src[]) |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
314 { |
9540 | 315 return 1; |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
316 } |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
317 |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
318 static int draw_slice(uint8_t *src[], int stride[], int w, int h, int x, int y) |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
319 { |
9540 | 320 uint8_t *dst, *frm; |
321 int i; | |
8665 | 322 dst = slice_data + (img_width * y + x) * 3; |
9540 | 323 frm = src[0]; |
324 for (i = 0; i < h; i++) { | |
325 memcpy(dst, frm, w * 3); | |
326 dst += (img_width * 3); | |
327 frm += stride[0]; | |
328 } | |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
329 return 0; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
330 } |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
331 |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
332 static int query_format(uint32_t format) |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
333 { |
9540 | 334 if (format == IMGFMT_RGB24) |
335 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_TIMER | VFCAP_ACCEPT_STRIDE; | |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
336 return 0; |
6053 | 337 } |
338 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
339 static int control(uint32_t request, void *data, ...) |
6053 | 340 { |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
341 if (request == VOCTRL_QUERY_FORMAT) { |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
342 return query_format(*((uint32_t*)data)); |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
343 } |
9540 | 344 if (request == VOCTRL_DUPLICATE_FRAME) { |
345 flip_page(); | |
346 return VO_TRUE; | |
347 } | |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
348 return VO_NOTIMPL; |
6053 | 349 } |
350 | |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
351 static void uninit(void) |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
352 { |
16721 | 353 mp_msg(MSGT_VO, MSGL_DBG2, "GIF89a: Uninit entered\n"); |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
354 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
355 if (new_gif != NULL) { |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
356 char temp[256]; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
357 // comment the gif and close it |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
358 snprintf(temp, 256, "MPlayer gif output v%2.2f-%d (c) %s\r\n", |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
359 MPLAYER_VERSION, VO_GIF_REVISION, |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
360 "joey@nicewarrior.org"); |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
361 EGifPutComment(new_gif, temp); |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
362 EGifCloseFile(new_gif); // also frees gif storage space. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
363 } |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
364 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
365 // free our allocated ram |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
366 if (gif_filename != NULL) free(gif_filename); |
8665 | 367 if (slice_data != NULL) free(slice_data); |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
368 if (reduce_data != NULL) free(reduce_data); |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
369 if (reduce_cmap != NULL) FreeMapObject(reduce_cmap); |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
370 |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
371 // set the pointers back to null. |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
372 new_gif = NULL; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
373 gif_filename = NULL; |
8665 | 374 slice_data = NULL; |
8514
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
375 reduce_data = NULL; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
376 reduce_cmap = NULL; |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
377 } |
a1ff87c254ff
I have rewritten the gif89a vo in order to solve some problems I had
arpi
parents:
8148
diff
changeset
|
378 |