Document lmin and lmax lavcopts; mpeg vrc_buf_size values
[mplayer/greg.git] / libvo / vo_tga.c
blob7d3b9d59938f95f4531405c3de404bbe469233c5
1 /*
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
19 * care.
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 )
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <errno.h>
32 #include <math.h>
34 #include "config.h"
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 =
43 "Targa output",
44 "tga",
45 "Daniele Forghieri - guru@digitalfantasy.it",
50 LIBVO_EXTERN (tga)
52 /* locals vars */
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)
59 int i;
61 for(i = 0; i < 18; i++) {
62 switch (i) {
63 case 2:
64 *h = 0x02;
65 break;
67 case 12:
68 *h = dx & 0xff;
69 break;
71 case 13:
72 *h = (dx >> 8) & 0xff;
73 break;
75 case 14:
76 *h = dy & 0xff;
77 break;
79 case 15:
80 *h = (dy >> 8) & 0xff;
81 break;
83 case 16:
84 *h = bpp;
85 break;
87 case 17:
88 *h = 0x20;
89 break;
91 default:
92 *h = 0;
94 ++h;
99 static int write_tga( char *file, int bpp, int dx, int dy, uint8_t *buf, int stride)
101 int er;
102 FILE *fo;
104 fo = fopen(file, "wb");
105 if (fo != NULL) {
106 uint8_t hdr[18];
108 er = 0;
109 tga_make_header(hdr, dx, dy, bpp);
110 if (fwrite(hdr, sizeof(hdr), 1, fo) == 1) {
111 int wb;
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;
121 s = (uint32_t *)buf;
122 d = line_buff;
123 for(x = 0; x < dx; x++) {
124 *d++ = *s++ | TGA_ALPHA32;
126 if (fwrite(line_buff, wb, 1, fo) != 1) {
127 er = 4;
128 break;
130 buf += stride;
134 else {
135 while (dy-- > 0) {
136 if (fwrite(buf, wb, 1, fo) != 1) {
137 er = 4;
138 break;
140 buf += stride;
144 else {
145 er = 2;
148 fclose(fo);
150 else {
151 er = 1;
154 if (er) {
155 fprintf(stderr, "Error writing file [%s]\n", file);
157 return(er);
160 static uint32_t draw_image(mp_image_t* mpi)
162 char file[20 + 1];
164 snprintf (file, 20, "%08d.tga", ++frame_num);
166 write_tga( file,
167 mpi->bpp,
168 mpi->w,
169 mpi->h,
170 mpi->planes[0],
171 mpi->stride[0]);
173 return VO_TRUE;
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);
183 return 0;
186 static void draw_osd(void)
190 static void flip_page (void)
192 return;
195 static uint32_t draw_slice(uint8_t *srcimg[], int stride[], int w,int h,int x,int y)
197 return -1;
200 static uint32_t draw_frame(uint8_t * src[])
202 return -1;
205 static uint32_t query_format(uint32_t format)
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;
213 return 0;
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)
227 if(arg) {
228 printf("vo_tga: Unknown subdevice: %s\n",arg);
229 return ENOSYS;
231 return 0;
234 static uint32_t control(uint32_t request, void *data, ...)
236 switch (request) {
237 case VOCTRL_DRAW_IMAGE:
238 return draw_image(data);
240 case VOCTRL_QUERY_FORMAT:
241 return query_format(*((uint32_t*)data));
243 return VO_NOTIMPL;