options: move lavfdopts to option struct
[mplayer/glamo.git] / libvo / vo_tga.c
blob1c92b03207ece523001acfedd76bd57e3b6c6669
1 /*
2 * TARGA video output
4 * This video output module writes TARGA uncompressed files in 15, 24 and 32
5 * bit BGR format.
7 * to select the output format use the format filter:
8 * mplayer -vo tga -vf format=bgr15 ...
9 * mplayer -vo tga -vf format=bgr24 ...
10 * mplayer -vo tga -vf format=bgr32 ...
12 * The 16 bit files are loaded without problem from Gimp and ImageMagick but
13 * give an error with entice (a visualizer from the enlightenment package
14 * that uses the imlib2 package).
16 * In 32-bit mode the alpha channel is set to 255 (0xff). For big-endian
17 * machines, TGA_ALPHA32 changes from 0xff000000 to 0x000000ff, and
18 * TGA_SHIFT32 from 0 to 8.
20 * I need to fill the alpha channel because entice considers that alpha
21 * channel (and displays nothing, only the background!), but ImageMagick
22 * (the program display) or gimp doesn't care.
24 * Maybe it is possible (with a compilation switch) to avoid the fill of
25 * the alpha channel and work outside MPlayer (if needed).
27 * Daniele Forghieri ( guru@digitalfantasy.it )
29 * This file is part of MPlayer.
31 * MPlayer is free software; you can redistribute it and/or modify
32 * it under the terms of the GNU General Public License as published by
33 * the Free Software Foundation; either version 2 of the License, or
34 * (at your option) any later version.
36 * MPlayer is distributed in the hope that it will be useful,
37 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 * GNU General Public License for more details.
41 * You should have received a copy of the GNU General Public License along
42 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
43 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <string.h>
49 #include <errno.h>
50 #include <math.h>
52 #include "config.h"
53 #include "mp_msg.h"
54 #include "video_out.h"
55 #include "video_out_internal.h"
57 static const vo_info_t info =
59 "Targa output",
60 "tga",
61 "Daniele Forghieri - guru@digitalfantasy.it",
66 const LIBVO_EXTERN (tga)
68 /* locals vars */
69 static int frame_num = 0;
70 static void *line_buff;
72 static void tga_make_header(uint8_t *h, int dx, int dy, int bpp)
75 int i;
77 for(i = 0; i < 18; i++) {
78 switch (i) {
79 case 2:
80 *h = 0x02;
81 break;
83 case 12:
84 *h = dx & 0xff;
85 break;
87 case 13:
88 *h = (dx >> 8) & 0xff;
89 break;
91 case 14:
92 *h = dy & 0xff;
93 break;
95 case 15:
96 *h = (dy >> 8) & 0xff;
97 break;
99 case 16:
100 *h = bpp;
101 break;
103 case 17:
104 *h = 0x20;
105 break;
107 default:
108 *h = 0;
110 ++h;
115 static int write_tga( char *file, int bpp, int dx, int dy, uint8_t *buf, int stride)
117 int er;
118 FILE *fo;
120 fo = fopen(file, "wb");
121 if (fo != NULL) {
122 uint8_t hdr[18];
124 er = 0;
125 tga_make_header(hdr, dx, dy, bpp);
126 if (fwrite(hdr, sizeof(hdr), 1, fo) == 1) {
127 int wb;
129 wb = ((bpp + 7) / 8) * dx;
130 if (bpp == 32) {
131 /* Setup the alpha channel for every pixel */
132 while (dy-- > 0) {
133 uint8_t *d;
134 uint8_t *s;
135 int x;
137 s = buf;
138 d = line_buff;
139 for(x = 0; x < dx; x++) {
140 #if HAVE_BIGENDIAN
141 d[0] = s[3];
142 d[1] = s[2];
143 d[2] = s[1];
144 d[3] = 0xff;
145 #else
146 d[0] = 0xff;
147 d[1] = s[1];
148 d[2] = s[2];
149 d[3] = s[3];
150 #endif
151 d+=4;
152 s+=4;
154 if (fwrite(line_buff, wb, 1, fo) != 1) {
155 er = 4;
156 break;
158 buf += stride;
162 else {
163 while (dy-- > 0) {
164 if (fwrite(buf, wb, 1, fo) != 1) {
165 er = 4;
166 break;
168 buf += stride;
172 else {
173 er = 2;
176 fclose(fo);
178 else {
179 er = 1;
182 if (er) {
183 fprintf(stderr, "Error writing file [%s]\n", file);
185 return er;
188 static uint32_t draw_image(mp_image_t* mpi)
190 char file[20 + 1];
192 snprintf (file, 20, "%08d.tga", ++frame_num);
194 write_tga( file,
195 mpi->bpp,
196 mpi->w,
197 mpi->h,
198 mpi->planes[0],
199 mpi->stride[0]);
201 return VO_TRUE;
204 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)
206 /* buffer for alpha */
207 if(line_buff){ free(line_buff); line_buff=NULL; }
208 if (format == (IMGFMT_BGR | 32)) {
209 line_buff = malloc(width * 4);
211 return 0;
214 static void draw_osd(void)
218 static void flip_page (void)
220 return;
223 static int draw_slice(uint8_t *srcimg[], int stride[], int w,int h,int x,int y)
225 return -1;
228 static int draw_frame(uint8_t * src[])
230 return -1;
233 static int query_format(uint32_t format)
235 switch(format){
236 case IMGFMT_BGR|15:
237 case IMGFMT_BGR|24:
238 case IMGFMT_BGR|32:
239 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
241 return 0;
244 static void uninit(void)
246 if(line_buff){ free(line_buff); line_buff=NULL; }
249 static void check_events(void)
253 static int preinit(const char *arg)
255 if(arg) {
256 mp_tmsg(MSGT_VO,MSGL_WARN, "[VO_TGA] Unknown subdevice: %s.\n",arg);
257 return ENOSYS;
259 return 0;
262 static int control(uint32_t request, void *data)
264 switch (request) {
265 case VOCTRL_DRAW_IMAGE:
266 return draw_image(data);
268 case VOCTRL_QUERY_FORMAT:
269 return query_format(*((uint32_t*)data));
271 return VO_NOTIMPL;