Mercurial > mplayer.hg
annotate libvo/vo_jpeg.c @ 13247:933b45ad31d5
Removal of -jpeg commandline option.
It's replaced by an options parser in the module itself. Instead of
mplayer -vo jpeg -jpeg options one now has to use mplayer -vo jpeg:options.
author | ivo |
---|---|
date | Sat, 04 Sep 2004 22:59:33 +0000 |
parents | 43fe55f36522 |
children | 7dfd84faaa09 |
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> | |
13247 | 28 #include <math.h> /* for log10() */ |
5648 | 29 |
13217 | 30 /* ------------------------------------------------------------------------- */ |
31 | |
32 /* Local Includes */ | |
5648 | 33 |
34 #include "config.h" | |
13158 | 35 #include "mp_msg.h" |
5648 | 36 #include "video_out.h" |
37 #include "video_out_internal.h" | |
13158 | 38 #include "mplayer.h" /* for exit_player() */ |
39 #include "help_mp.h" | |
40 | |
13217 | 41 /* ------------------------------------------------------------------------- */ |
42 | |
43 /* Defines */ | |
13158 | 44 |
45 /* Used for temporary buffers to store file- and pathnames */ | |
46 #define BUFLENGTH 512 | |
5648 | 47 |
13217 | 48 /* ------------------------------------------------------------------------- */ |
49 | |
50 /* Info */ | |
51 | |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7487
diff
changeset
|
52 static vo_info_t info= |
5648 | 53 { |
54 "JPEG file", | |
55 "jpeg", | |
56 "Zoltan Ponekker (pontscho@makacs.poliod.hu)", | |
57 "" | |
58 }; | |
59 | |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7487
diff
changeset
|
60 LIBVO_EXTERN (jpeg) |
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7487
diff
changeset
|
61 |
13217 | 62 /* ------------------------------------------------------------------------- */ |
63 | |
64 /* Global Variables */ | |
65 | |
5648 | 66 static int image_width; |
67 static int image_height; | |
68 | |
69 int jpeg_baseline = 1; | |
70 int jpeg_progressive_mode = 0; | |
71 int jpeg_optimize = 100; | |
72 int jpeg_smooth = 0; | |
73 int jpeg_quality = 75; | |
13217 | 74 char *jpeg_outdir = "."; |
75 char *jpeg_subdirs = NULL; | |
76 int jpeg_maxfiles = 1000; | |
5648 | 77 |
13217 | 78 static int framenum = 0; |
79 | |
80 /* ------------------------------------------------------------------------- */ | |
5648 | 81 |
13217 | 82 static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, |
83 uint32_t d_height, uint32_t fullscreen, char *title, | |
84 uint32_t format) | |
5648 | 85 { |
13217 | 86 char buf[BUFLENGTH]; |
87 struct stat stat_p; | |
13158 | 88 |
13217 | 89 /* Create outdir. |
90 * If it already exists, test if it's a writable directory */ | |
91 | |
92 snprintf(buf, BUFLENGTH, "%s", jpeg_outdir); | |
13158 | 93 |
13217 | 94 if ( mkdir(buf, 0755) < 0 ) { |
95 switch (errno) { /* use switch in case other errors need to be caught | |
96 and handled in the future */ | |
97 case EEXIST: | |
98 if ( stat(buf, &stat_p ) < 0 ) { | |
99 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, | |
100 MSGTR_VO_JPEG_GenericError, strerror(errno) ); | |
101 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name, | |
102 MSGTR_VO_JPEG_UnableToAccess,buf); | |
103 exit_player(MSGTR_Exit_error); | |
104 } | |
105 if ( !S_ISDIR(stat_p.st_mode) ) { | |
106 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name, | |
107 buf, MSGTR_VO_JPEG_ExistsButNoDirectory); | |
108 exit_player(MSGTR_Exit_error); | |
109 } | |
110 if ( !(stat_p.st_mode & S_IWUSR) ) { | |
111 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name, | |
112 MSGTR_VO_JPEG_DirExistsButNotWritable); | |
113 exit_player(MSGTR_Exit_error); | |
114 } | |
115 | |
116 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, | |
117 MSGTR_VO_JPEG_DirExistsAndIsWritable); | |
118 break; | |
13158 | 119 |
13217 | 120 default: |
121 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, | |
122 MSGTR_VO_JPEG_GenericError, strerror(errno) ); | |
123 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name, | |
124 MSGTR_VO_JPEG_CantCreateDirectory); | |
125 exit_player(MSGTR_Exit_error); | |
126 } /* end switch */ | |
127 } else { | |
128 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, | |
129 MSGTR_VO_JPEG_DirectoryCreateSuccess); | |
130 } /* end if */ | |
13158 | 131 |
13217 | 132 image_height = height; |
133 image_width = width; | |
5648 | 134 |
13217 | 135 return 0; |
5648 | 136 } |
137 | |
13217 | 138 /* ------------------------------------------------------------------------- */ |
5648 | 139 |
13217 | 140 static uint32_t jpeg_write(uint8_t * name, uint8_t * buffer) |
141 { | |
142 FILE *outfile; | |
143 struct jpeg_compress_struct cinfo; | |
144 struct jpeg_error_mgr jerr; | |
145 JSAMPROW row_pointer[1]; | |
146 int row_stride; | |
5648 | 147 |
13217 | 148 if ( !buffer ) return 1; |
149 if ( (outfile = fopen(name, "wb") ) == NULL ) { | |
150 return 1; | |
151 } | |
8267 | 152 |
13217 | 153 cinfo.err = jpeg_std_error(&jerr); |
154 jpeg_create_compress(&cinfo); | |
155 jpeg_stdio_dest(&cinfo, outfile); | |
156 | |
157 cinfo.image_width = image_width; | |
158 cinfo.image_height = image_height; | |
159 cinfo.input_components = 3; | |
160 cinfo.in_color_space = JCS_RGB; | |
161 | |
162 jpeg_set_defaults(&cinfo); | |
163 jpeg_set_quality(&cinfo,jpeg_quality, jpeg_baseline); | |
164 cinfo.optimize_coding = jpeg_optimize; | |
165 cinfo.smoothing_factor = jpeg_smooth; | |
5648 | 166 |
13217 | 167 if ( jpeg_progressive_mode ) { |
168 jpeg_simple_progression(&cinfo); | |
169 } | |
170 | |
171 jpeg_start_compress(&cinfo, TRUE); | |
172 | |
173 row_stride = image_width * 3; | |
174 while (cinfo.next_scanline < cinfo.image_height) { | |
175 row_pointer[0] = &buffer[cinfo.next_scanline * row_stride]; | |
176 (void)jpeg_write_scanlines(&cinfo, row_pointer,1); | |
177 } | |
5648 | 178 |
13217 | 179 jpeg_finish_compress(&cinfo); |
180 fclose(outfile); | |
181 jpeg_destroy_compress(&cinfo); | |
182 | |
183 return 0; | |
5648 | 184 } |
185 | |
13217 | 186 /* ------------------------------------------------------------------------- */ |
187 | |
188 static uint32_t draw_frame(uint8_t *src[]) | |
5648 | 189 { |
13217 | 190 static uint32_t framecounter = 0, subdircounter = 0; |
191 char buf[BUFLENGTH]; | |
192 uint8_t *dst = src[0]; | |
193 static char subdirname[BUFLENGTH] = ""; | |
194 struct stat stat_p; | |
13158 | 195 |
13217 | 196 /* Start writing to new subdirectory after a certain amount of frames */ |
197 if ( framecounter == jpeg_maxfiles ) { | |
198 framecounter = 0; | |
199 } | |
13158 | 200 |
13217 | 201 /* If framecounter is zero (or reset to zero), increment subdirectory |
202 * number and create the subdirectory. | |
203 * If jpeg_subdirs is not set, do nothing and resort to old behaviour. */ | |
204 if ( !framecounter && jpeg_subdirs ) { | |
205 snprintf(subdirname, BUFLENGTH, "%s%08d", jpeg_subdirs, | |
206 ++subdircounter); | |
207 snprintf(buf, BUFLENGTH, "%s/%s", jpeg_outdir, subdirname); | |
208 if ( mkdir(buf, 0755) < 0 ) { | |
209 switch (errno) { /* use switch in case other errors need to be | |
210 caught and handled in the future */ | |
211 case EEXIST: | |
212 if ( stat(buf, &stat_p) < 0 ) { | |
213 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", | |
214 info.short_name, MSGTR_VO_JPEG_GenericError, | |
215 strerror(errno) ); | |
216 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", | |
217 info.short_name, MSGTR_VO_JPEG_UnableToAccess, | |
218 buf); | |
219 exit_player(MSGTR_Exit_error); | |
220 } | |
221 if ( !S_ISDIR(stat_p.st_mode) ) { | |
222 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s %s\n", | |
223 info.short_name, buf, | |
224 MSGTR_VO_JPEG_ExistsButNoDirectory); | |
225 exit_player(MSGTR_Exit_error); | |
226 } | |
227 if ( !(stat_p.st_mode & S_IWUSR) ) { | |
228 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s - %s\n", | |
229 info.short_name, buf, | |
230 MSGTR_VO_JPEG_DirExistsButNotWritable); | |
231 exit_player(MSGTR_Exit_error); | |
232 } | |
233 | |
234 mp_msg(MSGT_VO, MSGL_INFO, "\n%s: %s - %s\n", | |
235 info.short_name, buf, | |
236 MSGTR_VO_JPEG_DirExistsAndIsWritable); | |
237 break; | |
238 | |
239 default: | |
240 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, | |
241 MSGTR_VO_JPEG_GenericError, strerror(errno) ); | |
242 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s - %s.\n", | |
243 info.short_name, buf, | |
244 MSGTR_VO_JPEG_CantCreateDirectory); | |
245 exit_player(MSGTR_Exit_error); | |
246 break; | |
247 } | |
248 } /* switch */ | |
249 } /* if !framecounter && jpeg_subdirs */ | |
250 | |
251 framenum++; | |
13158 | 252 |
13217 | 253 /* snprintf the full pathname of the outputfile */ |
254 snprintf(buf, BUFLENGTH, "%s/%s/%08d.jpg", jpeg_outdir, subdirname, | |
255 framenum); | |
256 | |
257 framecounter++; | |
258 | |
259 return jpeg_write(buf, src[0]); | |
260 } | |
13158 | 261 |
13217 | 262 /* ------------------------------------------------------------------------- */ |
5648 | 263 |
264 static void draw_osd(void) | |
265 { | |
266 } | |
267 | |
13217 | 268 /* ------------------------------------------------------------------------- */ |
269 | |
5648 | 270 static void flip_page (void) |
271 { | |
272 } | |
273 | |
13217 | 274 /* ------------------------------------------------------------------------- */ |
275 | |
276 static uint32_t draw_slice(uint8_t *src[], int stride[], int w, int h, | |
277 int x, int y) | |
5648 | 278 { |
13217 | 279 return 0; |
5648 | 280 } |
281 | |
13217 | 282 /* ------------------------------------------------------------------------- */ |
283 | |
5648 | 284 static uint32_t query_format(uint32_t format) |
285 { | |
13217 | 286 if (format == IMGFMT_RGB24) { |
287 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW; | |
288 } | |
289 | |
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
|
290 return 0; |
5648 | 291 } |
292 | |
13217 | 293 /* ------------------------------------------------------------------------- */ |
294 | |
5648 | 295 static void uninit(void) |
296 { | |
297 } | |
298 | |
13217 | 299 /* ------------------------------------------------------------------------- */ |
300 | |
5648 | 301 static void check_events(void) |
302 { | |
303 } | |
304 | |
13217 | 305 /* ------------------------------------------------------------------------- */ |
306 | |
5648 | 307 static uint32_t preinit(const char *arg) |
308 { | |
13247 | 309 char *buf; /* buf is used to store parsed string values */ |
310 int length; /* length is used when calculating the length of buf */ | |
311 int value; /* storage for parsed integer values */ | |
312 | |
313 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, | |
314 MSGTR_VO_JPEG_ParsingSuboptions); | |
315 | |
316 if (arg) { | |
317 | |
318 while (*arg != '\0') { | |
319 if (!strncmp(arg, ":", 1)) { | |
320 arg++; | |
321 continue; /* multiple ':' is not really an error */ | |
322 } if (!strncmp(arg, "progressive", 11)) { | |
323 arg += 11; | |
324 jpeg_progressive_mode = 1; | |
325 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, | |
326 MSGTR_VO_JPEG_ProgressiveJPEG); | |
327 } else if (!strncmp(arg, "noprogressive", 13)) { | |
328 arg += 13; | |
329 jpeg_progressive_mode = 0; | |
330 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, | |
331 MSGTR_VO_JPEG_NoProgressiveJPEG); | |
332 } else if (!strncmp(arg, "baseline", 8)) { | |
333 arg += 8; | |
334 jpeg_baseline = 1; | |
335 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, | |
336 MSGTR_VO_JPEG_BaselineJPEG); | |
337 } else if (!strncmp(arg, "nobaseline", 10)) { | |
338 arg += 10; | |
339 jpeg_baseline = 0; | |
340 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, | |
341 MSGTR_VO_JPEG_NoBaselineJPEG); | |
342 } else if (!strncmp(arg, "optimize=", 9)) { | |
343 arg += 9; | |
344 if (sscanf(arg, "%d", &value) == 1) { | |
345 if ( (value < 0 ) || (value > 100) ) { | |
346 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s %s.\n", | |
347 info.short_name, "optimize", | |
348 MSGTR_VO_JPEG_ValueOutOfRange, "[0-100]"); | |
349 exit_player(MSGTR_Exit_error); | |
350 } else { | |
351 jpeg_optimize = value; | |
352 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s --> %d\n", | |
353 info.short_name, "optimize", value); | |
354 } | |
355 } else { | |
356 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", | |
357 info.short_name, "optimize", | |
358 MSGTR_VO_JPEG_NoValueSpecified); | |
359 exit_player(MSGTR_Exit_error); | |
360 } | |
361 /* only here if value is set and sane */ | |
362 if (value) { | |
363 arg += (int)log10(value) + 1; | |
364 } else { | |
365 arg++; /* log10(0) fails */ | |
366 } | |
367 } else if (!strncmp(arg, "smooth=", 7)) { | |
368 arg += 7; | |
369 if (sscanf(arg, "%d", &value) == 1 ) { | |
370 if ( (value < 0) || (value > 100) ) { | |
371 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s %s.\n", | |
372 info.short_name, "smooth", | |
373 MSGTR_VO_JPEG_ValueOutOfRange, "[0-100]"); | |
374 exit_player(MSGTR_Exit_error); | |
375 } else { | |
376 jpeg_smooth = value; | |
377 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s --> %d\n", | |
378 info.short_name, "smooth", value); | |
379 } | |
380 } else { | |
381 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", | |
382 info.short_name, "smooth", | |
383 MSGTR_VO_JPEG_NoValueSpecified); | |
384 exit_player(MSGTR_Exit_error); | |
385 } | |
386 /* only here if value is set and sane */ | |
387 if (value) { | |
388 arg += (int)log10(value) + 1; | |
389 } else { | |
390 arg++; /* log10(0) fails */ | |
391 } | |
392 } else if (!strncmp(arg, "quality=", 8)) { | |
393 arg += 8; | |
394 if (sscanf(arg, "%d", &value) == 1) { | |
395 if ( (value < 0) || (value > 100) ) { | |
396 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s %s.\n", | |
397 info.short_name, "quality", | |
398 MSGTR_VO_JPEG_ValueOutOfRange, "[0-100]"); | |
399 exit_player(MSGTR_Exit_error); | |
400 } else { | |
401 jpeg_quality = value; | |
402 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s --> %d\n", | |
403 info.short_name, "quality", value); | |
404 } | |
405 } else { | |
406 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", | |
407 info.short_name, "quality", | |
408 MSGTR_VO_JPEG_NoValueSpecified); | |
409 exit_player(MSGTR_Exit_error); | |
410 } | |
411 /* only here if value is set and sane */ | |
412 if (value) { | |
413 arg += (int)log10(value) + 1; | |
414 } else { | |
415 arg++; /* log10(0) fails */ | |
416 } | |
417 } else if (!strncmp(arg, "outdir=", 7)) { | |
418 arg += 7; | |
419 buf = malloc(strlen(arg)+1); /* maximum length possible */ | |
420 if (!buf) { | |
421 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name, | |
422 MSGTR_MemAllocFailed); | |
423 exit_player(MSGTR_Exit_error); | |
424 } | |
425 if (sscanf(arg, "%[^:]", buf) == 1) { | |
426 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s --> %s\n", | |
427 info.short_name, "outdir", buf); | |
428 length = strlen(buf); | |
429 arg += length; | |
430 jpeg_outdir = malloc(length+1); | |
431 strncpy(jpeg_outdir, buf, length+1); | |
432 free(buf); | |
433 } else { | |
434 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", | |
435 info.short_name, "outdir", | |
436 MSGTR_VO_JPEG_NoValueSpecified); | |
437 exit_player(MSGTR_Exit_error); | |
438 } | |
439 } else if (!strncmp(arg, "subdirs=", 8)) { | |
440 arg += 8; | |
441 buf = malloc(strlen(arg)+1); /* maximum length possible */ | |
442 if (!buf) { | |
443 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name, | |
444 MSGTR_MemAllocFailed); | |
445 exit_player(MSGTR_Exit_error); | |
446 } | |
447 if (sscanf(arg, "%[^:]", buf) == 1) { | |
448 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s --> %s\n", | |
449 info.short_name, "subdirs", buf); | |
450 length = strlen(buf); | |
451 arg += length; | |
452 jpeg_subdirs = malloc(length+1); | |
453 strncpy(jpeg_subdirs, buf, length+1); | |
454 free(buf); | |
455 } else { | |
456 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", | |
457 info.short_name, "subdirs", | |
458 MSGTR_VO_JPEG_NoValueSpecified); | |
459 exit_player(MSGTR_Exit_error); | |
460 } | |
461 } else if (!strncmp(arg, "maxfiles=", 9)) { | |
462 arg += 9; | |
463 if (sscanf(arg, "%d", &value) == 1) { | |
464 if (value < 1) { | |
465 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s %s.\n", | |
466 info.short_name, "maxfiles", | |
467 MSGTR_VO_JPEG_ValueOutOfRange, ">=1"); | |
468 exit_player(MSGTR_Exit_error); | |
469 } else { | |
470 jpeg_maxfiles = value; | |
471 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s --> %d\n", | |
472 info.short_name, "maxfiles", value); | |
473 } | |
474 } else { | |
475 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", | |
476 info.short_name, "maxfiles", | |
477 MSGTR_VO_JPEG_NoValueSpecified); | |
478 exit_player(MSGTR_Exit_error); | |
479 } | |
480 /* only here if value is set and sane */ | |
481 if (value) { | |
482 arg += (int)log10(value) + 1; | |
483 } else { | |
484 arg++; /* log10(0) fails */ | |
485 } | |
486 } else { | |
487 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %-20s...\n", info.short_name, | |
488 MSGTR_VO_JPEG_UnknownOptions, arg); | |
489 exit_player(MSGTR_Exit_error); | |
490 } | |
491 } /* end while */ | |
492 } /* endif */ | |
493 | |
494 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, | |
495 MSGTR_VO_JPEG_SuboptionsParsedOK); | |
13217 | 496 return 0; |
5648 | 497 } |
498 | |
13217 | 499 /* ------------------------------------------------------------------------- */ |
500 | |
5648 | 501 static uint32_t control(uint32_t request, void *data, ...) |
502 { | |
13217 | 503 switch (request) { |
504 case VOCTRL_QUERY_FORMAT: | |
505 return query_format(*((uint32_t*)data)); | |
506 } | |
507 return VO_NOTIMPL; | |
5648 | 508 } |
13158 | 509 |
13217 | 510 /* ------------------------------------------------------------------------- */ |
511 | |
13158 | 512 #undef BUFLENGTH |
513 | |
13217 | 514 /* ------------------------------------------------------------------------- */ |
515 |