2 * vo_tga.c: targa output
4 * this video output module write targa uncompressed file in 15, 24 and 32 bit bgr format.
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 ...
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).
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).
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
21 * maybe is possible (with a compilation switch) to avoid the fill of the alpha channel
22 * and work outside mplayer (if needed)
24 * Daniele Forghieri ( guru@digitalfantasy.it )
35 #include "video_out.h"
36 #include "video_out_internal.h"
38 /* This must be changed for Motorola type processor ? */
39 #define TGA_ALPHA32 0xff000000
41 static vo_info_t info
=
45 "Daniele Forghieri - guru@digitalfantasy.it",
53 static int frame_num
= 0;
54 static void *line_buff
;
56 static void tga_make_header(uint8_t *h
, int dx
, int dy
, int bpp
)
61 for(i
= 0; i
< 18; i
++) {
72 *h
= (dx
>> 8) & 0xff;
80 *h
= (dy
>> 8) & 0xff;
99 static int write_tga( char *file
, int bpp
, int dx
, int dy
, uint8_t *buf
, int stride
)
104 fo
= fopen(file
, "wb");
109 tga_make_header(hdr
, dx
, dy
, bpp
);
110 if (fwrite(hdr
, sizeof(hdr
), 1, fo
) == 1) {
113 wb
= ((bpp
+ 7) / 8) * dx
;
115 /* Setup the alpha channel for every pixel */
123 for(x
= 0; x
< dx
; x
++) {
124 *d
++ = *s
++ | TGA_ALPHA32
;
126 if (fwrite(line_buff
, wb
, 1, fo
) != 1) {
136 if (fwrite(buf
, wb
, 1, fo
) != 1) {
155 fprintf(stderr
, "Error writing file [%s]\n", file
);
160 static uint32_t draw_image(mp_image_t
* mpi
)
164 snprintf (file
, 20, "%08d.tga", ++frame_num
);
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
)
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);
186 static void draw_osd(void)
190 static void flip_page (void)
195 static uint32_t draw_slice(uint8_t *srcimg
[], int stride
[], int w
,int h
,int x
,int y
)
200 static uint32_t draw_frame(uint8_t * src
[])
205 static uint32_t query_format(uint32_t format
)
211 return VFCAP_CSP_SUPPORTED
| VFCAP_CSP_SUPPORTED_BY_HW
;
216 static void uninit(void)
218 if(line_buff
){ free(line_buff
); line_buff
=NULL
; }
221 static void check_events(void)
225 static uint32_t preinit(const char *arg
)
228 printf("vo_tga: Unknown subdevice: %s\n",arg
);
234 static uint32_t control(uint32_t request
, void *data
, ...)
237 case VOCTRL_DRAW_IMAGE
:
238 return draw_image(data
);
240 case VOCTRL_QUERY_FORMAT
:
241 return query_format(*((uint32_t*)data
));