Mercurial > mplayer.hg
annotate libvo/vo_tga.c @ 36310:7b135b3b8b38
Avoid dereferencing NULL pointer on close if we
never allocated a AVIOContext.
author | reimar |
---|---|
date | Mon, 05 Aug 2013 18:57:04 +0000 |
parents | ddb45e9443ec |
children | 5d3f93051de9 |
rev | line source |
---|---|
28446
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
1 /* |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
2 * TARGA video output |
10689 | 3 * |
28446
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
4 * This video output module writes TARGA uncompressed files in 15, 24 and 32 |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
5 * bit BGR format. |
10689 | 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 * | |
28446
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
12 * The 16 bit files are loaded without problem from Gimp and ImageMagick but |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
13 * give an error with entice (a visualizer from the enlightenment package |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
14 * that uses the imlib2 package). |
10689 | 15 * |
28446
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
16 * In 32-bit mode the alpha channel is set to 255 (0xff). For big-endian |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
17 * machines, TGA_ALPHA32 changes from 0xff000000 to 0x000000ff, and |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
18 * TGA_SHIFT32 from 0 to 8. |
10689 | 19 * |
28446
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
20 * I need to fill the alpha channel because entice considers that alpha |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
21 * channel (and displays nothing, only the background!), but ImageMagick |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
22 * (the program display) or gimp doesn't care. |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
23 * |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
24 * Maybe it is possible (with a compilation switch) to avoid the fill of |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
25 * the alpha channel and work outside MPlayer (if needed). |
10689 | 26 * |
27 * Daniele Forghieri ( guru@digitalfantasy.it ) | |
28 * | |
28446
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
29 * This file is part of MPlayer. |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
30 * |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
31 * MPlayer is free software; you can redistribute it and/or modify |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
32 * it under the terms of the GNU General Public License as published by |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
33 * the Free Software Foundation; either version 2 of the License, or |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
34 * (at your option) any later version. |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
35 * |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
36 * MPlayer is distributed in the hope that it will be useful, |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
37 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
39 * GNU General Public License for more details. |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
40 * |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
41 * You should have received a copy of the GNU General Public License along |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
42 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
26755
diff
changeset
|
43 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
10689 | 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" | |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
16171
diff
changeset
|
53 #include "mp_msg.h" |
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
16171
diff
changeset
|
54 #include "help_mp.h" |
10689 | 55 #include "video_out.h" |
56 #include "video_out_internal.h" | |
57 | |
25216 | 58 static const vo_info_t info = |
10689 | 59 { |
60 "Targa output", | |
61 "tga", | |
62 "Daniele Forghieri - guru@digitalfantasy.it", | |
63 "" | |
64 }; | |
65 | |
66 | |
25220
c9e9ac2008c2
Mark the vo_functions_t definitions as const where possible.
reimar
parents:
25216
diff
changeset
|
67 const LIBVO_EXTERN (tga) |
10689 | 68 |
69 /* locals vars */ | |
70 static int frame_num = 0; | |
71 | |
72 static void tga_make_header(uint8_t *h, int dx, int dy, int bpp) | |
73 { | |
74 | |
75 int i; | |
76 | |
77 for(i = 0; i < 18; i++) { | |
78 switch (i) { | |
79 case 2: | |
80 *h = 0x02; | |
81 break; | |
82 | |
83 case 12: | |
84 *h = dx & 0xff; | |
85 break; | |
86 | |
87 case 13: | |
88 *h = (dx >> 8) & 0xff; | |
89 break; | |
90 | |
91 case 14: | |
92 *h = dy & 0xff; | |
93 break; | |
94 | |
95 case 15: | |
96 *h = (dy >> 8) & 0xff; | |
97 break; | |
98 | |
99 case 16: | |
100 *h = bpp; | |
101 break; | |
102 | |
103 case 17: | |
104 *h = 0x20; | |
105 break; | |
106 | |
107 default: | |
108 *h = 0; | |
109 } | |
110 ++h; | |
111 } | |
112 | |
113 } | |
114 | |
115 static int write_tga( char *file, int bpp, int dx, int dy, uint8_t *buf, int stride) | |
116 { | |
117 int er; | |
118 FILE *fo; | |
119 | |
120 fo = fopen(file, "wb"); | |
121 if (fo != NULL) { | |
122 uint8_t hdr[18]; | |
123 | |
124 er = 0; | |
125 tga_make_header(hdr, dx, dy, bpp); | |
126 if (fwrite(hdr, sizeof(hdr), 1, fo) == 1) { | |
127 int wb; | |
128 | |
129 wb = ((bpp + 7) / 8) * dx; | |
130 while (dy-- > 0) { | |
131 if (fwrite(buf, wb, 1, fo) != 1) { | |
132 er = 4; | |
133 break; | |
134 } | |
135 buf += stride; | |
136 } | |
137 } | |
138 else { | |
139 er = 2; | |
140 } | |
141 | |
142 fclose(fo); | |
143 } | |
144 else { | |
145 er = 1; | |
146 } | |
147 | |
148 if (er) { | |
149 fprintf(stderr, "Error writing file [%s]\n", file); | |
150 } | |
26755
46f0b4d34fa1
cosmetics: Remove useless parentheses from from return statements.
diego
parents:
25220
diff
changeset
|
151 return er; |
10689 | 152 } |
153 | |
154 static uint32_t draw_image(mp_image_t* mpi) | |
155 { | |
156 char file[20 + 1]; | |
157 | |
158 snprintf (file, 20, "%08d.tga", ++frame_num); | |
159 | |
160 write_tga( file, | |
161 mpi->bpp, | |
162 mpi->w, | |
163 mpi->h, | |
164 mpi->planes[0], | |
165 mpi->stride[0]); | |
166 | |
167 return VO_TRUE; | |
168 } | |
169 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
170 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) |
10689 | 171 { |
172 return 0; | |
173 } | |
174 | |
175 static void draw_osd(void) | |
176 { | |
177 } | |
178 | |
179 static void flip_page (void) | |
180 { | |
181 return; | |
182 } | |
183 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
184 static int draw_slice(uint8_t *srcimg[], int stride[], int w,int h,int x,int y) |
10689 | 185 { |
186 return -1; | |
187 } | |
188 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
189 static int draw_frame(uint8_t * src[]) |
10689 | 190 { |
191 return -1; | |
192 } | |
193 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
194 static int query_format(uint32_t format) |
10689 | 195 { |
196 switch(format){ | |
31654 | 197 case IMGFMT_BGR15LE: |
31653 | 198 case IMGFMT_BGR24: |
31652
c49231cc0f95
Fix vo_tga RGB with alpha output on little-endian (blue and alpha were swapped),
reimar
parents:
29401
diff
changeset
|
199 case IMGFMT_BGRA: |
10689 | 200 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW; |
201 } | |
202 return 0; | |
203 } | |
204 | |
205 static void uninit(void) | |
206 { | |
207 } | |
208 | |
209 static void check_events(void) | |
210 { | |
211 } | |
212 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
213 static int preinit(const char *arg) |
10689 | 214 { |
215 if(arg) { | |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
16171
diff
changeset
|
216 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_TGA_UnknownSubdevice,arg); |
10689 | 217 return ENOSYS; |
218 } | |
219 return 0; | |
220 } | |
221 | |
33305
ddb45e9443ec
Remove the variable arguments from the libvo control() functions.
iive
parents:
31654
diff
changeset
|
222 static int control(uint32_t request, void *data) |
10689 | 223 { |
224 switch (request) { | |
225 case VOCTRL_DRAW_IMAGE: | |
226 return draw_image(data); | |
227 | |
228 case VOCTRL_QUERY_FORMAT: | |
229 return query_format(*((uint32_t*)data)); | |
230 } | |
231 return VO_NOTIMPL; | |
232 } |