Mercurial > mplayer.hg
annotate libvo/vo_tga.c @ 21875:d81cf0be50f0
Frametime was being read from the wrong offset, compare
http://www.onicos.com/staff/iz/formats/gif.html#gceb
patch by John Koleszar, jkoleszar on2 com
author | diego |
---|---|
date | Sat, 13 Jan 2007 06:00:34 +0000 |
parents | a107276371a8 |
children | cac6e3b0d2e5 |
rev | line source |
---|---|
10689 | 1 /* |
2 * vo_tga.c: targa output | |
3 * | |
4 * this video output module write targa uncompressed file in 15, 24 and 32 bit bgr format. | |
5 * | |
6 * to select the output format use the format filter: | |
7 * mplayer -vo tga -vf format=bgr15 ... | |
8 * mplayer -vo tga -vf format=bgr24 ... | |
9 * mplayer -vo tga -vf format=bgr32 ... | |
10 * | |
11 * The 16 bit file are loaded without problem from Gimp and ImageMagick but give an error | |
12 * with entice (a visualizer from the enlightenment package that use the imlib2 package). | |
13 * | |
12573 | 14 * In 32 bit mode the alpha channel is set to 255 (0xff). For big endian |
15 * machines, TGA_ALPHA32 changes from 0xff000000 to 0x000000ff, and TGA_SHIFT32 from 0 to 8. | |
10689 | 16 * |
17 * I need to fill the alpha channel because entice consider that alpha channel (and displays | |
18 * nothing, only the background!), but ImageMacick (the program display) or gimp doesn't | |
19 * care. | |
20 * | |
21 * maybe is possible (with a compilation switch) to avoid the fill of the alpha channel | |
22 * and work outside mplayer (if needed) | |
23 * | |
24 * Daniele Forghieri ( guru@digitalfantasy.it ) | |
25 * | |
26 */ | |
27 | |
28 #include <stdio.h> | |
29 #include <stdlib.h> | |
30 #include <string.h> | |
31 #include <errno.h> | |
32 #include <math.h> | |
33 | |
34 #include "config.h" | |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
16171
diff
changeset
|
35 #include "mp_msg.h" |
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
16171
diff
changeset
|
36 #include "help_mp.h" |
10689 | 37 #include "video_out.h" |
38 #include "video_out_internal.h" | |
39 | |
12573 | 40 #ifdef WORDS_BIGENDIAN |
41 #define TGA_ALPHA32 0x000000ff | |
42 #define TGA_SHIFT32 8 | |
43 #else | |
10689 | 44 #define TGA_ALPHA32 0xff000000 |
12573 | 45 #define TGA_SHIFT32 0 |
46 #endif | |
10689 | 47 |
48 static vo_info_t info = | |
49 { | |
50 "Targa output", | |
51 "tga", | |
52 "Daniele Forghieri - guru@digitalfantasy.it", | |
53 "" | |
54 }; | |
55 | |
56 | |
57 LIBVO_EXTERN (tga) | |
58 | |
59 /* locals vars */ | |
60 static int frame_num = 0; | |
61 static void *line_buff; | |
62 | |
63 static void tga_make_header(uint8_t *h, int dx, int dy, int bpp) | |
64 { | |
65 | |
66 int i; | |
67 | |
68 for(i = 0; i < 18; i++) { | |
69 switch (i) { | |
70 case 2: | |
71 *h = 0x02; | |
72 break; | |
73 | |
74 case 12: | |
75 *h = dx & 0xff; | |
76 break; | |
77 | |
78 case 13: | |
79 *h = (dx >> 8) & 0xff; | |
80 break; | |
81 | |
82 case 14: | |
83 *h = dy & 0xff; | |
84 break; | |
85 | |
86 case 15: | |
87 *h = (dy >> 8) & 0xff; | |
88 break; | |
89 | |
90 case 16: | |
91 *h = bpp; | |
92 break; | |
93 | |
94 case 17: | |
95 *h = 0x20; | |
96 break; | |
97 | |
98 default: | |
99 *h = 0; | |
100 } | |
101 ++h; | |
102 } | |
103 | |
104 } | |
105 | |
106 static int write_tga( char *file, int bpp, int dx, int dy, uint8_t *buf, int stride) | |
107 { | |
108 int er; | |
109 FILE *fo; | |
110 | |
111 fo = fopen(file, "wb"); | |
112 if (fo != NULL) { | |
113 uint8_t hdr[18]; | |
114 | |
115 er = 0; | |
116 tga_make_header(hdr, dx, dy, bpp); | |
117 if (fwrite(hdr, sizeof(hdr), 1, fo) == 1) { | |
118 int wb; | |
119 | |
120 wb = ((bpp + 7) / 8) * dx; | |
121 if (bpp == 32) { | |
122 /* Setup the alpha channel for every pixel */ | |
123 while (dy-- > 0) { | |
124 uint32_t *d; | |
125 uint32_t *s; | |
126 int x; | |
127 | |
128 s = (uint32_t *)buf; | |
129 d = line_buff; | |
130 for(x = 0; x < dx; x++) { | |
12573 | 131 *d++ = ((*s++) << TGA_SHIFT32) | TGA_ALPHA32; |
10689 | 132 } |
133 if (fwrite(line_buff, wb, 1, fo) != 1) { | |
134 er = 4; | |
135 break; | |
136 } | |
137 buf += stride; | |
138 } | |
139 | |
140 } | |
141 else { | |
142 while (dy-- > 0) { | |
143 if (fwrite(buf, wb, 1, fo) != 1) { | |
144 er = 4; | |
145 break; | |
146 } | |
147 buf += stride; | |
148 } | |
149 } | |
150 } | |
151 else { | |
152 er = 2; | |
153 } | |
154 | |
155 fclose(fo); | |
156 } | |
157 else { | |
158 er = 1; | |
159 } | |
160 | |
161 if (er) { | |
162 fprintf(stderr, "Error writing file [%s]\n", file); | |
163 } | |
164 return(er); | |
165 } | |
166 | |
167 static uint32_t draw_image(mp_image_t* mpi) | |
168 { | |
169 char file[20 + 1]; | |
170 | |
171 snprintf (file, 20, "%08d.tga", ++frame_num); | |
172 | |
173 write_tga( file, | |
174 mpi->bpp, | |
175 mpi->w, | |
176 mpi->h, | |
177 mpi->planes[0], | |
178 mpi->stride[0]); | |
179 | |
180 return VO_TRUE; | |
181 } | |
182 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
183 static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) |
10689 | 184 { |
185 /* buffer for alpha */ | |
186 if(line_buff){ free(line_buff); line_buff=NULL; } | |
187 if (format == (IMGFMT_BGR | 32)) { | |
188 line_buff = malloc(width * 4); | |
189 } | |
190 return 0; | |
191 } | |
192 | |
193 static void draw_osd(void) | |
194 { | |
195 } | |
196 | |
197 static void flip_page (void) | |
198 { | |
199 return; | |
200 } | |
201 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
202 static int draw_slice(uint8_t *srcimg[], int stride[], int w,int h,int x,int y) |
10689 | 203 { |
204 return -1; | |
205 } | |
206 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
207 static int draw_frame(uint8_t * src[]) |
10689 | 208 { |
209 return -1; | |
210 } | |
211 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
212 static int query_format(uint32_t format) |
10689 | 213 { |
214 switch(format){ | |
215 case IMGFMT_BGR|15: | |
216 case IMGFMT_BGR|24: | |
217 case IMGFMT_BGR|32: | |
218 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW; | |
219 } | |
220 return 0; | |
221 } | |
222 | |
223 static void uninit(void) | |
224 { | |
225 if(line_buff){ free(line_buff); line_buff=NULL; } | |
226 } | |
227 | |
228 static void check_events(void) | |
229 { | |
230 } | |
231 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
232 static int preinit(const char *arg) |
10689 | 233 { |
234 if(arg) { | |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
16171
diff
changeset
|
235 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_TGA_UnknownSubdevice,arg); |
10689 | 236 return ENOSYS; |
237 } | |
238 return 0; | |
239 } | |
240 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
241 static int control(uint32_t request, void *data, ...) |
10689 | 242 { |
243 switch (request) { | |
244 case VOCTRL_DRAW_IMAGE: | |
245 return draw_image(data); | |
246 | |
247 case VOCTRL_QUERY_FORMAT: | |
248 return query_format(*((uint32_t*)data)); | |
249 } | |
250 return VO_NOTIMPL; | |
251 } |