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