~medibuntu-maintainers/mplayer/medibuntu.maverick

0.2.1 by Reinhard Tartler
Import upstream version 1.0~rc2+svn20090303
1
/*
2
 * TARGA video output
1 by Sebastian Dröge
Import upstream version 0.99+1.0pre7try2+cvs20051205
3
 *
0.2.1 by Reinhard Tartler
Import upstream version 1.0~rc2+svn20090303
4
 * This video output module writes TARGA uncompressed files in 15, 24 and 32
5
 * bit BGR format.
1 by Sebastian Dröge
Import upstream version 0.99+1.0pre7try2+cvs20051205
6
 *
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 ...
11
 *
0.2.1 by Reinhard Tartler
Import upstream version 1.0~rc2+svn20090303
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).
15
 *
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.
19
 *
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.
23
 *
24
 * Maybe it is possible (with a compilation switch) to avoid the fill of
25
 * the alpha channel and work outside MPlayer (if needed).
1 by Sebastian Dröge
Import upstream version 0.99+1.0pre7try2+cvs20051205
26
 *
27
 *    Daniele Forghieri ( guru@digitalfantasy.it )
28
 *
0.2.1 by Reinhard Tartler
Import upstream version 1.0~rc2+svn20090303
29
 * This file is part of MPlayer.
30
 *
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.
35
 *
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.
40
 *
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.
1 by Sebastian Dröge
Import upstream version 0.99+1.0pre7try2+cvs20051205
44
 */
45
46
#include <stdio.h>
47
#include <stdlib.h>
48
#include <string.h>
49
#include <errno.h>
50
#include <math.h>
51
52
#include "config.h"
1.1.2 by Reinhard Tartler
Import upstream version 0.99+1.0pre8
53
#include "mp_msg.h"
54
#include "help_mp.h"
1 by Sebastian Dröge
Import upstream version 0.99+1.0pre7try2+cvs20051205
55
#include "video_out.h"
56
#include "video_out_internal.h"
57
0.2.1 by Reinhard Tartler
Import upstream version 1.0~rc2+svn20090303
58
static const vo_info_t info =
1 by Sebastian Dröge
Import upstream version 0.99+1.0pre7try2+cvs20051205
59
{
60
	"Targa output",
61
	"tga",
62
	"Daniele Forghieri - guru@digitalfantasy.it",
63
	""
64
};
65
66
0.2.1 by Reinhard Tartler
Import upstream version 1.0~rc2+svn20090303
67
const LIBVO_EXTERN (tga)
1 by Sebastian Dröge
Import upstream version 0.99+1.0pre7try2+cvs20051205
68
69
/* locals vars */
70
static int      frame_num = 0;
71
static void     *line_buff;
72
73
static void tga_make_header(uint8_t *h, int dx, int dy, int bpp)
74
{
75
76
    int  i;
77
78
    for(i = 0; i < 18; i++) {
79
        switch (i) {
80
        case 2:
81
            *h = 0x02;
82
            break;
83
84
        case 12:
85
            *h = dx & 0xff;
86
            break;
87
88
        case 13:
89
            *h = (dx >> 8) & 0xff;
90
            break;
91
92
        case 14:
93
            *h = dy & 0xff;
94
            break;
95
96
        case 15:
97
            *h = (dy >> 8) & 0xff;
98
            break;
99
100
        case 16:
101
            *h = bpp;
102
            break;
103
104
        case 17:
105
            *h = 0x20;
106
            break;
107
108
        default:
109
            *h = 0;
110
        }
111
        ++h;
112
    }
113
114
}
115
116
static int write_tga( char *file, int bpp, int dx, int dy, uint8_t *buf, int stride)
117
{
118
    int   er;
119
    FILE  *fo;
120
121
    fo = fopen(file, "wb");
122
    if (fo != NULL) {
123
        uint8_t hdr[18];
124
125
        er = 0;
126
        tga_make_header(hdr, dx, dy, bpp);
127
        if (fwrite(hdr, sizeof(hdr), 1, fo) == 1) {
128
            int    wb;
129
130
            wb = ((bpp + 7) / 8) * dx;
131
            if (bpp == 32) {
132
                /* Setup the alpha channel for every pixel */
133
                while (dy-- > 0) {
1.1.4 by Mario Limonciello
Import upstream version 1.0~rc2
134
                    uint8_t    *d;
135
                    uint8_t    *s;
1 by Sebastian Dröge
Import upstream version 0.99+1.0pre7try2+cvs20051205
136
                    int         x;
137
1.1.4 by Mario Limonciello
Import upstream version 1.0~rc2
138
                    s = buf;
1 by Sebastian Dröge
Import upstream version 0.99+1.0pre7try2+cvs20051205
139
                    d = line_buff;
140
                    for(x = 0; x < dx; x++) {
1.1.7 by Reinhard Tartler
Import upstream version 1.0~rc4~try1
141
                    #if HAVE_BIGENDIAN
1.1.4 by Mario Limonciello
Import upstream version 1.0~rc2
142
                        d[0] = s[3];
143
                        d[1] = s[2];
144
                        d[2] = s[1];
145
                        d[3] = 0xff;
146
                    #else
147
                        d[0] = 0xff;
148
                        d[1] = s[1];
149
                        d[2] = s[2];
150
                        d[3] = s[3];
151
                    #endif
152
                        d+=4;
153
                        s+=4;
1 by Sebastian Dröge
Import upstream version 0.99+1.0pre7try2+cvs20051205
154
                    }
155
                    if (fwrite(line_buff, wb, 1, fo) != 1) {
156
                        er = 4;
157
                        break;
158
                    }
159
                    buf += stride;
160
                }
161
162
            }
163
            else {
164
                while (dy-- > 0) {
165
                    if (fwrite(buf, wb, 1, fo) != 1) {
166
                        er = 4;
167
                        break;
168
                    }
169
                    buf += stride;
170
                }
171
            }
172
        }
173
        else {
174
            er = 2;
175
        }
176
177
        fclose(fo);
178
    }
179
    else {
180
        er = 1;
181
    }
182
183
    if (er) {
184
        fprintf(stderr, "Error writing file [%s]\n", file);
185
    }
0.2.1 by Reinhard Tartler
Import upstream version 1.0~rc2+svn20090303
186
    return er;
1 by Sebastian Dröge
Import upstream version 0.99+1.0pre7try2+cvs20051205
187
}
188
189
static uint32_t draw_image(mp_image_t* mpi)
190
{
191
    char    file[20 + 1];
192
193
    snprintf (file, 20, "%08d.tga", ++frame_num);
194
195
    write_tga( file,
196
               mpi->bpp,
197
               mpi->w,
198
               mpi->h,
199
               mpi->planes[0],
200
               mpi->stride[0]);
201
202
    return VO_TRUE;
203
}
204
205
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
{
207
    /* buffer for alpha */
208
    if(line_buff){ free(line_buff); line_buff=NULL; }
209
    if (format == (IMGFMT_BGR | 32)) {
210
        line_buff = malloc(width * 4);
211
    }
212
    return 0;
213
}
214
215
static void draw_osd(void)
216
{
217
}
218
219
static void flip_page (void)
220
{
221
    return;
222
}
223
224
static int draw_slice(uint8_t *srcimg[], int stride[], int w,int h,int x,int y)
225
{
226
    return -1;
227
}
228
229
static int draw_frame(uint8_t * src[])
230
{
231
    return -1;
232
}
233
234
static int query_format(uint32_t format)
235
{
236
    switch(format){
237
        case IMGFMT_BGR|15:
238
        case IMGFMT_BGR|24:
239
        case IMGFMT_BGR|32:
240
            return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
241
    }
242
    return 0;
243
}
244
245
static void uninit(void)
246
{
247
    if(line_buff){ free(line_buff); line_buff=NULL; }
248
}
249
250
static void check_events(void)
251
{
252
}
253
254
static int preinit(const char *arg)
255
{
256
    if(arg) {
1.1.2 by Reinhard Tartler
Import upstream version 0.99+1.0pre8
257
	mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_TGA_UnknownSubdevice,arg);
1 by Sebastian Dröge
Import upstream version 0.99+1.0pre7try2+cvs20051205
258
	return ENOSYS;
259
    }
260
    return 0;
261
}
262
263
static int control(uint32_t request, void *data, ...)
264
{
265
  switch (request) {
266
      case VOCTRL_DRAW_IMAGE:
267
          return draw_image(data);
268
269
      case VOCTRL_QUERY_FORMAT:
270
          return query_format(*((uint32_t*)data));
271
  }
272
  return VO_NOTIMPL;
273
}