Mercurial > mplayer.hg
annotate libvo/vo_tga.c @ 23912:de63d6fc46dd
Use goto instead of useless recursion that might fill up the stack
author | reimar |
---|---|
date | Mon, 30 Jul 2007 13:48:08 +0000 |
parents | cac6e3b0d2e5 |
children | 3aee342be929 |
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 | |
40 static vo_info_t info = | |
41 { | |
42 "Targa output", | |
43 "tga", | |
44 "Daniele Forghieri - guru@digitalfantasy.it", | |
45 "" | |
46 }; | |
47 | |
48 | |
49 LIBVO_EXTERN (tga) | |
50 | |
51 /* locals vars */ | |
52 static int frame_num = 0; | |
53 static void *line_buff; | |
54 | |
55 static void tga_make_header(uint8_t *h, int dx, int dy, int bpp) | |
56 { | |
57 | |
58 int i; | |
59 | |
60 for(i = 0; i < 18; i++) { | |
61 switch (i) { | |
62 case 2: | |
63 *h = 0x02; | |
64 break; | |
65 | |
66 case 12: | |
67 *h = dx & 0xff; | |
68 break; | |
69 | |
70 case 13: | |
71 *h = (dx >> 8) & 0xff; | |
72 break; | |
73 | |
74 case 14: | |
75 *h = dy & 0xff; | |
76 break; | |
77 | |
78 case 15: | |
79 *h = (dy >> 8) & 0xff; | |
80 break; | |
81 | |
82 case 16: | |
83 *h = bpp; | |
84 break; | |
85 | |
86 case 17: | |
87 *h = 0x20; | |
88 break; | |
89 | |
90 default: | |
91 *h = 0; | |
92 } | |
93 ++h; | |
94 } | |
95 | |
96 } | |
97 | |
98 static int write_tga( char *file, int bpp, int dx, int dy, uint8_t *buf, int stride) | |
99 { | |
100 int er; | |
101 FILE *fo; | |
102 | |
103 fo = fopen(file, "wb"); | |
104 if (fo != NULL) { | |
105 uint8_t hdr[18]; | |
106 | |
107 er = 0; | |
108 tga_make_header(hdr, dx, dy, bpp); | |
109 if (fwrite(hdr, sizeof(hdr), 1, fo) == 1) { | |
110 int wb; | |
111 | |
112 wb = ((bpp + 7) / 8) * dx; | |
113 if (bpp == 32) { | |
114 /* Setup the alpha channel for every pixel */ | |
115 while (dy-- > 0) { | |
22026 | 116 uint8_t *d; |
117 uint8_t *s; | |
10689 | 118 int x; |
119 | |
22026 | 120 s = buf; |
10689 | 121 d = line_buff; |
122 for(x = 0; x < dx; x++) { | |
22026 | 123 #ifdef WORDS_BIGENDIAN |
124 d[0] = s[3]; | |
125 d[1] = s[2]; | |
126 d[2] = s[1]; | |
127 d[3] = 0xff; | |
128 #else | |
129 d[0] = 0xff; | |
130 d[1] = s[1]; | |
131 d[2] = s[2]; | |
132 d[3] = s[3]; | |
133 #endif | |
134 d+=4; | |
135 s+=4; | |
10689 | 136 } |
137 if (fwrite(line_buff, wb, 1, fo) != 1) { | |
138 er = 4; | |
139 break; | |
140 } | |
141 buf += stride; | |
142 } | |
143 | |
144 } | |
145 else { | |
146 while (dy-- > 0) { | |
147 if (fwrite(buf, wb, 1, fo) != 1) { | |
148 er = 4; | |
149 break; | |
150 } | |
151 buf += stride; | |
152 } | |
153 } | |
154 } | |
155 else { | |
156 er = 2; | |
157 } | |
158 | |
159 fclose(fo); | |
160 } | |
161 else { | |
162 er = 1; | |
163 } | |
164 | |
165 if (er) { | |
166 fprintf(stderr, "Error writing file [%s]\n", file); | |
167 } | |
168 return(er); | |
169 } | |
170 | |
171 static uint32_t draw_image(mp_image_t* mpi) | |
172 { | |
173 char file[20 + 1]; | |
174 | |
175 snprintf (file, 20, "%08d.tga", ++frame_num); | |
176 | |
177 write_tga( file, | |
178 mpi->bpp, | |
179 mpi->w, | |
180 mpi->h, | |
181 mpi->planes[0], | |
182 mpi->stride[0]); | |
183 | |
184 return VO_TRUE; | |
185 } | |
186 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
187 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 | 188 { |
189 /* buffer for alpha */ | |
190 if(line_buff){ free(line_buff); line_buff=NULL; } | |
191 if (format == (IMGFMT_BGR | 32)) { | |
192 line_buff = malloc(width * 4); | |
193 } | |
194 return 0; | |
195 } | |
196 | |
197 static void draw_osd(void) | |
198 { | |
199 } | |
200 | |
201 static void flip_page (void) | |
202 { | |
203 return; | |
204 } | |
205 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
206 static int draw_slice(uint8_t *srcimg[], int stride[], int w,int h,int x,int y) |
10689 | 207 { |
208 return -1; | |
209 } | |
210 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
211 static int draw_frame(uint8_t * src[]) |
10689 | 212 { |
213 return -1; | |
214 } | |
215 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
216 static int query_format(uint32_t format) |
10689 | 217 { |
218 switch(format){ | |
219 case IMGFMT_BGR|15: | |
220 case IMGFMT_BGR|24: | |
221 case IMGFMT_BGR|32: | |
222 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW; | |
223 } | |
224 return 0; | |
225 } | |
226 | |
227 static void uninit(void) | |
228 { | |
229 if(line_buff){ free(line_buff); line_buff=NULL; } | |
230 } | |
231 | |
232 static void check_events(void) | |
233 { | |
234 } | |
235 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
236 static int preinit(const char *arg) |
10689 | 237 { |
238 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
|
239 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_TGA_UnknownSubdevice,arg); |
10689 | 240 return ENOSYS; |
241 } | |
242 return 0; | |
243 } | |
244 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
245 static int control(uint32_t request, void *data, ...) |
10689 | 246 { |
247 switch (request) { | |
248 case VOCTRL_DRAW_IMAGE: | |
249 return draw_image(data); | |
250 | |
251 case VOCTRL_QUERY_FORMAT: | |
252 return query_format(*((uint32_t*)data)); | |
253 } | |
254 return VO_NOTIMPL; | |
255 } |