Mercurial > mplayer.hg
annotate libvo/vo_jpeg.c @ 13234:7056d7cfcd02
just some debugging junk i'd like to have in there for now :)
author | rfelker |
---|---|
date | Thu, 02 Sep 2004 23:51:05 +0000 |
parents | 43fe55f36522 |
children | 933b45ad31d5 |
rev | line source |
---|---|
13217 | 1 /* ------------------------------------------------------------------------- */ |
2 | |
5648 | 3 /* |
12857 | 4 * vo_jpeg.c, JPEG Renderer for MPlayer |
5648 | 5 * |
13217 | 6 * |
7 * Changelog | |
8 * | |
9 * Original version: Copyright 2002 by Pontscho (pontscho@makacs.poliod.hu) | |
10 * 2003-04-25 Spring cleanup -- Alex | |
11 * 2004-08-04 Added multiple subdirectory support -- Ivo (ivop@euronet.nl) | |
12 * 2004-09-01 Cosmetics update -- Ivo | |
5648 | 13 * |
14 */ | |
15 | |
13217 | 16 /* ------------------------------------------------------------------------- */ |
17 | |
18 /* Global Includes */ | |
19 | |
5648 | 20 #include <stdio.h> |
21 #include <stdlib.h> | |
22 #include <string.h> | |
23 #include <errno.h> | |
13217 | 24 #include <jpeglib.h> |
25 #include <sys/stat.h> | |
26 #include <sys/types.h> | |
27 #include <unistd.h> | |
5648 | 28 |
13217 | 29 /* ------------------------------------------------------------------------- */ |
30 | |
31 /* Local Includes */ | |
5648 | 32 |
33 #include "config.h" | |
13158 | 34 #include "mp_msg.h" |
5648 | 35 #include "video_out.h" |
36 #include "video_out_internal.h" | |
13158 | 37 #include "mplayer.h" /* for exit_player() */ |
38 #include "help_mp.h" | |
39 | |
13217 | 40 /* ------------------------------------------------------------------------- */ |
41 | |
42 /* Defines */ | |
13158 | 43 |
44 /* Used for temporary buffers to store file- and pathnames */ | |
45 #define BUFLENGTH 512 | |
5648 | 46 |
13217 | 47 /* ------------------------------------------------------------------------- */ |
48 | |
49 /* Info */ | |
50 | |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7487
diff
changeset
|
51 static vo_info_t info= |
5648 | 52 { |
53 "JPEG file", | |
54 "jpeg", | |
55 "Zoltan Ponekker (pontscho@makacs.poliod.hu)", | |
56 "" | |
57 }; | |
58 | |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7487
diff
changeset
|
59 LIBVO_EXTERN (jpeg) |
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7487
diff
changeset
|
60 |
13217 | 61 /* ------------------------------------------------------------------------- */ |
62 | |
63 /* Global Variables */ | |
64 | |
5648 | 65 static int image_width; |
66 static int image_height; | |
67 | |
68 int jpeg_baseline = 1; | |
69 int jpeg_progressive_mode = 0; | |
70 int jpeg_optimize = 100; | |
71 int jpeg_smooth = 0; | |
72 int jpeg_quality = 75; | |
13217 | 73 char *jpeg_outdir = "."; |
74 char *jpeg_subdirs = NULL; | |
75 int jpeg_maxfiles = 1000; | |
5648 | 76 |
13217 | 77 static int framenum = 0; |
78 | |
79 /* ------------------------------------------------------------------------- */ | |
5648 | 80 |
13217 | 81 static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, |
82 uint32_t d_height, uint32_t fullscreen, char *title, | |
83 uint32_t format) | |
5648 | 84 { |
13217 | 85 char buf[BUFLENGTH]; |
86 struct stat stat_p; | |
13158 | 87 |
13217 | 88 /* Create outdir. |
89 * If it already exists, test if it's a writable directory */ | |
90 | |
91 snprintf(buf, BUFLENGTH, "%s", jpeg_outdir); | |
13158 | 92 |
13217 | 93 if ( mkdir(buf, 0755) < 0 ) { |
94 switch (errno) { /* use switch in case other errors need to be caught | |
95 and handled in the future */ | |
96 case EEXIST: | |
97 if ( stat(buf, &stat_p ) < 0 ) { | |
98 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, | |
99 MSGTR_VO_JPEG_GenericError, strerror(errno) ); | |
100 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name, | |
101 MSGTR_VO_JPEG_UnableToAccess,buf); | |
102 exit_player(MSGTR_Exit_error); | |
103 } | |
104 if ( !S_ISDIR(stat_p.st_mode) ) { | |
105 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name, | |
106 buf, MSGTR_VO_JPEG_ExistsButNoDirectory); | |
107 exit_player(MSGTR_Exit_error); | |
108 } | |
109 if ( !(stat_p.st_mode & S_IWUSR) ) { | |
110 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name, | |
111 MSGTR_VO_JPEG_DirExistsButNotWritable); | |
112 exit_player(MSGTR_Exit_error); | |
113 } | |
114 | |
115 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, | |
116 MSGTR_VO_JPEG_DirExistsAndIsWritable); | |
117 break; | |
13158 | 118 |
13217 | 119 default: |
120 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, | |
121 MSGTR_VO_JPEG_GenericError, strerror(errno) ); | |
122 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name, | |
123 MSGTR_VO_JPEG_CantCreateDirectory); | |
124 exit_player(MSGTR_Exit_error); | |
125 } /* end switch */ | |
126 } else { | |
127 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, | |
128 MSGTR_VO_JPEG_DirectoryCreateSuccess); | |
129 } /* end if */ | |
13158 | 130 |
13217 | 131 image_height = height; |
132 image_width = width; | |
5648 | 133 |
13217 | 134 return 0; |
5648 | 135 } |
136 | |
13217 | 137 /* ------------------------------------------------------------------------- */ |
5648 | 138 |
13217 | 139 static uint32_t jpeg_write(uint8_t * name, uint8_t * buffer) |
140 { | |
141 FILE *outfile; | |
142 struct jpeg_compress_struct cinfo; | |
143 struct jpeg_error_mgr jerr; | |
144 JSAMPROW row_pointer[1]; | |
145 int row_stride; | |
5648 | 146 |
13217 | 147 if ( !buffer ) return 1; |
148 if ( (outfile = fopen(name, "wb") ) == NULL ) { | |
149 return 1; | |
150 } | |
8267 | 151 |
13217 | 152 cinfo.err = jpeg_std_error(&jerr); |
153 jpeg_create_compress(&cinfo); | |
154 jpeg_stdio_dest(&cinfo, outfile); | |
155 | |
156 cinfo.image_width = image_width; | |
157 cinfo.image_height = image_height; | |
158 cinfo.input_components = 3; | |
159 cinfo.in_color_space = JCS_RGB; | |
160 | |
161 jpeg_set_defaults(&cinfo); | |
162 jpeg_set_quality(&cinfo,jpeg_quality, jpeg_baseline); | |
163 cinfo.optimize_coding = jpeg_optimize; | |
164 cinfo.smoothing_factor = jpeg_smooth; | |
5648 | 165 |
13217 | 166 if ( jpeg_progressive_mode ) { |
167 jpeg_simple_progression(&cinfo); | |
168 } | |
169 | |
170 jpeg_start_compress(&cinfo, TRUE); | |
171 | |
172 row_stride = image_width * 3; | |
173 while (cinfo.next_scanline < cinfo.image_height) { | |
174 row_pointer[0] = &buffer[cinfo.next_scanline * row_stride]; | |
175 (void)jpeg_write_scanlines(&cinfo, row_pointer,1); | |
176 } | |
5648 | 177 |
13217 | 178 jpeg_finish_compress(&cinfo); |
179 fclose(outfile); | |
180 jpeg_destroy_compress(&cinfo); | |
181 | |
182 return 0; | |
5648 | 183 } |
184 | |
13217 | 185 /* ------------------------------------------------------------------------- */ |
186 | |
187 static uint32_t draw_frame(uint8_t *src[]) | |
5648 | 188 { |
13217 | 189 static uint32_t framecounter = 0, subdircounter = 0; |
190 char buf[BUFLENGTH]; | |
191 uint8_t *dst = src[0]; | |
192 static char subdirname[BUFLENGTH] = ""; | |
193 struct stat stat_p; | |
13158 | 194 |
13217 | 195 /* Start writing to new subdirectory after a certain amount of frames */ |
196 if ( framecounter == jpeg_maxfiles ) { | |
197 framecounter = 0; | |
198 } | |
13158 | 199 |
13217 | 200 /* If framecounter is zero (or reset to zero), increment subdirectory |
201 * number and create the subdirectory. | |
202 * If jpeg_subdirs is not set, do nothing and resort to old behaviour. */ | |
203 if ( !framecounter && jpeg_subdirs ) { | |
204 snprintf(subdirname, BUFLENGTH, "%s%08d", jpeg_subdirs, | |
205 ++subdircounter); | |
206 snprintf(buf, BUFLENGTH, "%s/%s", jpeg_outdir, subdirname); | |
207 if ( mkdir(buf, 0755) < 0 ) { | |
208 switch (errno) { /* use switch in case other errors need to be | |
209 caught and handled in the future */ | |
210 case EEXIST: | |
211 if ( stat(buf, &stat_p) < 0 ) { | |
212 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", | |
213 info.short_name, MSGTR_VO_JPEG_GenericError, | |
214 strerror(errno) ); | |
215 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", | |
216 info.short_name, MSGTR_VO_JPEG_UnableToAccess, | |
217 buf); | |
218 exit_player(MSGTR_Exit_error); | |
219 } | |
220 if ( !S_ISDIR(stat_p.st_mode) ) { | |
221 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s %s\n", | |
222 info.short_name, buf, | |
223 MSGTR_VO_JPEG_ExistsButNoDirectory); | |
224 exit_player(MSGTR_Exit_error); | |
225 } | |
226 if ( !(stat_p.st_mode & S_IWUSR) ) { | |
227 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s - %s\n", | |
228 info.short_name, buf, | |
229 MSGTR_VO_JPEG_DirExistsButNotWritable); | |
230 exit_player(MSGTR_Exit_error); | |
231 } | |
232 | |
233 mp_msg(MSGT_VO, MSGL_INFO, "\n%s: %s - %s\n", | |
234 info.short_name, buf, | |
235 MSGTR_VO_JPEG_DirExistsAndIsWritable); | |
236 break; | |
237 | |
238 default: | |
239 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, | |
240 MSGTR_VO_JPEG_GenericError, strerror(errno) ); | |
241 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s - %s.\n", | |
242 info.short_name, buf, | |
243 MSGTR_VO_JPEG_CantCreateDirectory); | |
244 exit_player(MSGTR_Exit_error); | |
245 break; | |
246 } | |
247 } /* switch */ | |
248 } /* if !framecounter && jpeg_subdirs */ | |
249 | |
250 framenum++; | |
13158 | 251 |
13217 | 252 /* snprintf the full pathname of the outputfile */ |
253 snprintf(buf, BUFLENGTH, "%s/%s/%08d.jpg", jpeg_outdir, subdirname, | |
254 framenum); | |
255 | |
256 framecounter++; | |
257 | |
258 return jpeg_write(buf, src[0]); | |
259 } | |
13158 | 260 |
13217 | 261 /* ------------------------------------------------------------------------- */ |
5648 | 262 |
263 static void draw_osd(void) | |
264 { | |
265 } | |
266 | |
13217 | 267 /* ------------------------------------------------------------------------- */ |
268 | |
5648 | 269 static void flip_page (void) |
270 { | |
271 } | |
272 | |
13217 | 273 /* ------------------------------------------------------------------------- */ |
274 | |
275 static uint32_t draw_slice(uint8_t *src[], int stride[], int w, int h, | |
276 int x, int y) | |
5648 | 277 { |
13217 | 278 return 0; |
5648 | 279 } |
280 | |
13217 | 281 /* ------------------------------------------------------------------------- */ |
282 | |
5648 | 283 static uint32_t query_format(uint32_t format) |
284 { | |
13217 | 285 if (format == IMGFMT_RGB24) { |
286 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW; | |
287 } | |
288 | |
9989
98791b90215a
Spring cleanup: supporting only RGB24 as input (native jpeg lib supports only that, maybe we could later add nativ YCbCr (YUV) support, but not swscale ones)
alex
parents:
9019
diff
changeset
|
289 return 0; |
5648 | 290 } |
291 | |
13217 | 292 /* ------------------------------------------------------------------------- */ |
293 | |
5648 | 294 static void uninit(void) |
295 { | |
296 } | |
297 | |
13217 | 298 /* ------------------------------------------------------------------------- */ |
299 | |
5648 | 300 static void check_events(void) |
301 { | |
302 } | |
303 | |
13217 | 304 /* ------------------------------------------------------------------------- */ |
305 | |
5648 | 306 static uint32_t preinit(const char *arg) |
307 { | |
13217 | 308 return 0; |
5648 | 309 } |
310 | |
13217 | 311 /* ------------------------------------------------------------------------- */ |
312 | |
5648 | 313 static uint32_t control(uint32_t request, void *data, ...) |
314 { | |
13217 | 315 switch (request) { |
316 case VOCTRL_QUERY_FORMAT: | |
317 return query_format(*((uint32_t*)data)); | |
318 } | |
319 return VO_NOTIMPL; | |
5648 | 320 } |
13158 | 321 |
13217 | 322 /* ------------------------------------------------------------------------- */ |
323 | |
13158 | 324 #undef BUFLENGTH |
325 | |
13217 | 326 /* ------------------------------------------------------------------------- */ |
327 |