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