Mercurial > mplayer.hg
annotate libvo/vo_jpeg.c @ 13196:ba82b6e04e83
#ifdef simplification and higher consistency
author | diego |
---|---|
date | Mon, 30 Aug 2004 00:42:27 +0000 |
parents | b872a27aea9e |
children | 43fe55f36522 |
rev | line source |
---|---|
5648 | 1 /* |
12857 | 2 * vo_jpeg.c, JPEG Renderer for MPlayer |
5648 | 3 * |
5649 | 4 * Copyright 2002 by Pontscho (pontscho@makacs.poliod.hu) |
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
|
5 * 25/04/2003: Spring cleanup -- alex |
13158 | 6 * 04/08/2004: Added multiple subdirectory support -- ivop@euronet.nl |
5648 | 7 * |
8 */ | |
9 | |
10 #include <stdio.h> | |
11 #include <stdlib.h> | |
12 #include <string.h> | |
13 #include <errno.h> | |
14 | |
15 #include <jpeglib.h> | |
16 | |
17 #include "config.h" | |
13158 | 18 #include "mp_msg.h" |
5648 | 19 #include "video_out.h" |
20 #include "video_out_internal.h" | |
13158 | 21 #include "mplayer.h" /* for exit_player() */ |
22 #include "help_mp.h" | |
23 | |
24 #include <sys/stat.h> | |
25 #include <sys/types.h> | |
26 #include <unistd.h> | |
27 | |
28 /* Used for temporary buffers to store file- and pathnames */ | |
29 #define BUFLENGTH 512 | |
5648 | 30 |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7487
diff
changeset
|
31 static vo_info_t info= |
5648 | 32 { |
33 "JPEG file", | |
34 "jpeg", | |
35 "Zoltan Ponekker (pontscho@makacs.poliod.hu)", | |
36 "" | |
37 }; | |
38 | |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7487
diff
changeset
|
39 LIBVO_EXTERN (jpeg) |
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7487
diff
changeset
|
40 |
5648 | 41 static int image_width; |
42 static int image_height; | |
43 | |
44 int jpeg_baseline = 1; | |
45 int jpeg_progressive_mode = 0; | |
46 int jpeg_optimize = 100; | |
47 int jpeg_smooth = 0; | |
48 int jpeg_quality = 75; | |
5659 | 49 char * jpeg_outdir = "."; |
13158 | 50 char * jpeg_subdirs = NULL; |
51 int jpeg_maxfiles=1000; | |
5648 | 52 |
53 static int framenum=0; | |
54 | |
7124
eca7dbad0166
finally removed query_vaa, bes_da and vo_tune_info - the obsoleted libvo api
alex
parents:
6751
diff
changeset
|
55 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) |
5648 | 56 { |
13158 | 57 char buf[BUFLENGTH]; |
58 struct stat stat_p; | |
59 | |
60 /* Create outdir. If it already exists, test if it's a writable directory */ | |
61 | |
62 snprintf (buf, BUFLENGTH, "%s", jpeg_outdir); | |
63 | |
64 if (mkdir (buf, 0755)<0) { | |
65 switch (errno) { /* use switch in case other errors need to be caught and handled in the future */ | |
66 case EEXIST: | |
67 if ( stat(buf, &stat_p) < 0 ) { | |
68 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, MSGTR_VO_JPEG_GenericError, strerror(errno) ); | |
69 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name, MSGTR_VO_JPEG_UnableToAccess,buf); | |
70 exit_player(MSGTR_Exit_error); | |
71 } | |
72 if ( !S_ISDIR(stat_p.st_mode) ) { | |
73 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name, buf, MSGTR_VO_JPEG_ExistsButNoDirectory); | |
74 exit_player(MSGTR_Exit_error); | |
75 } | |
76 if ( !(stat_p.st_mode & S_IWUSR) ) { | |
77 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name, MSGTR_VO_JPEG_DirExistsButNotWritable); | |
78 exit_player(MSGTR_Exit_error); | |
79 } | |
80 | |
81 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, MSGTR_VO_JPEG_DirExistsAndIsWritable); | |
82 break; | |
83 | |
84 default: | |
85 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, MSGTR_VO_JPEG_GenericError, strerror(errno) ); | |
86 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name, MSGTR_VO_JPEG_CantCreateDirectory); | |
87 exit_player(MSGTR_Exit_error); | |
88 } /* end switch */ | |
89 } else { | |
90 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name, MSGTR_VO_JPEG_DirectoryCreateSuccess); | |
91 } /* end if */ | |
92 | |
93 image_height=height; | |
94 image_width=width; | |
5648 | 95 |
96 return 0; | |
97 } | |
98 | |
99 static uint32_t jpeg_write( uint8_t * name,uint8_t * buffer ) | |
100 { | |
101 FILE * o; | |
102 struct jpeg_compress_struct cinfo; | |
103 struct jpeg_error_mgr jerr; | |
104 JSAMPROW row_pointer[1]; | |
105 int row_stride; | |
106 | |
107 if ( !buffer ) return 1; | |
108 if ( (o=fopen( name,"wb" )) == NULL ) return 1; | |
109 | |
110 cinfo.err=jpeg_std_error(&jerr); | |
111 jpeg_create_compress(&cinfo); | |
112 jpeg_stdio_dest( &cinfo,o ); | |
113 | |
114 cinfo.image_width=image_width; | |
115 cinfo.image_height=image_height; | |
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
|
116 cinfo.input_components=3; |
5648 | 117 cinfo.in_color_space=JCS_RGB; |
8267 | 118 |
119 jpeg_set_defaults( &cinfo ); | |
120 jpeg_set_quality( &cinfo,jpeg_quality,jpeg_baseline ); | |
5648 | 121 cinfo.optimize_coding=jpeg_optimize; |
122 cinfo.smoothing_factor=jpeg_smooth; | |
8267 | 123 |
5648 | 124 if ( jpeg_progressive_mode ) jpeg_simple_progression( &cinfo ); |
125 jpeg_start_compress( &cinfo,TRUE ); | |
126 | |
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
|
127 row_stride = image_width * 3; |
5648 | 128 while ( cinfo.next_scanline < cinfo.image_height ) |
129 { | |
130 row_pointer[0]=&buffer[ cinfo.next_scanline * row_stride ]; | |
131 (void)jpeg_write_scanlines( &cinfo,row_pointer,1 ); | |
132 } | |
133 | |
134 jpeg_finish_compress( &cinfo ); | |
135 fclose( o ); | |
136 jpeg_destroy_compress( &cinfo ); | |
137 | |
138 return 0; | |
139 } | |
140 | |
141 static uint32_t draw_frame(uint8_t * src[]) | |
142 { | |
13158 | 143 static uint32_t framecounter=0, subdircounter=0; |
144 char buf[BUFLENGTH]; | |
6751 | 145 uint8_t *dst= src[0]; |
13158 | 146 static char subdirname[BUFLENGTH] = ""; |
147 struct stat stat_p; | |
148 | |
149 /* Start writing to new subdirectory after a certain amount of frames */ | |
150 if ( framecounter == jpeg_maxfiles ) { | |
151 framecounter = 0; | |
152 } | |
153 | |
154 /* If framecounter is zero (or reset to zero), increment subdirectory number | |
155 * and create the subdirectory. | |
156 * If jpeg_subdirs is not set, do nothing and resort to old behaviour. */ | |
157 if ( !framecounter && jpeg_subdirs ) { | |
158 snprintf (subdirname, BUFLENGTH, "%s%08d", jpeg_subdirs, ++subdircounter); | |
159 snprintf (buf, BUFLENGTH, "%s/%s", jpeg_outdir, subdirname); | |
160 if (mkdir (buf, 0755)<0) { | |
161 switch (errno) { /* use switch in case other errors need to be caught and handled in the future */ | |
162 case EEXIST: | |
163 if ( stat(buf, &stat_p) < 0 ) { | |
164 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, MSGTR_VO_JPEG_GenericError, strerror(errno) ); | |
165 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name, MSGTR_VO_JPEG_UnableToAccess, buf); | |
166 exit_player(MSGTR_Exit_error); | |
167 } | |
168 if ( !S_ISDIR(stat_p.st_mode) ) { | |
169 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s %s\n", info.short_name, buf, MSGTR_VO_JPEG_ExistsButNoDirectory); | |
170 exit_player(MSGTR_Exit_error); | |
171 } | |
172 if ( !(stat_p.st_mode & S_IWUSR) ) { | |
173 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s - %s\n", info.short_name, buf, MSGTR_VO_JPEG_DirExistsButNotWritable); | |
174 exit_player(MSGTR_Exit_error); | |
175 } | |
176 | |
177 mp_msg(MSGT_VO, MSGL_INFO, "\n%s: %s - %s\n", info.short_name, buf, MSGTR_VO_JPEG_DirExistsAndIsWritable); | |
178 break; | |
179 | |
180 default: | |
181 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, MSGTR_VO_JPEG_GenericError, strerror(errno) ); | |
182 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s - %s.\n", info.short_name, buf, MSGTR_VO_JPEG_CantCreateDirectory); | |
183 exit_player(MSGTR_Exit_error); | |
184 break; | |
185 } | |
186 } /* switch */ | |
187 } /* if !framecounter && jpeg_subdirs */ | |
188 | |
189 | |
190 framenum++; | |
191 | |
192 /* snprintf the full pathname of the outputfile */ | |
193 snprintf (buf, BUFLENGTH, "%s/%s/%08d.jpg", jpeg_outdir, subdirname, framenum); | |
194 | |
195 framecounter++; | |
5648 | 196 |
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
|
197 return jpeg_write( buf,src[0] ); |
5648 | 198 } |
199 | |
200 static void draw_osd(void) | |
201 { | |
202 } | |
203 | |
204 static void flip_page (void) | |
205 { | |
206 } | |
207 | |
208 static uint32_t draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y ) | |
209 { | |
210 return 0; | |
211 } | |
212 | |
213 static uint32_t query_format(uint32_t format) | |
214 { | |
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
|
215 if (format == IMGFMT_RGB24) |
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
|
216 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW; |
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
|
217 |
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
|
218 return 0; |
5648 | 219 } |
220 | |
221 static void uninit(void) | |
222 { | |
223 } | |
224 | |
225 static void check_events(void) | |
226 { | |
227 } | |
228 | |
229 static uint32_t preinit(const char *arg) | |
230 { | |
231 return 0; | |
232 } | |
233 | |
234 static uint32_t control(uint32_t request, void *data, ...) | |
235 { | |
236 switch (request) | |
237 { | |
238 case VOCTRL_QUERY_FORMAT: | |
239 return query_format(*((uint32_t*)data)); | |
240 } | |
241 return VO_NOTIMPL; | |
242 } | |
13158 | 243 |
244 #undef BUFLENGTH | |
245 |