1 #include <config.h>
2 #ifdef SIMAGE_AVIENC_SUPPORT
3
4 #include <stdio.h>
5 #include <string.h>
6
7 #include <simage_private.h>
8 #include <simage_avi.h>
9 #include <avi_encode.h>
10
11 int
avienc_movie_create(const char * filename,s_movie * movie,s_params * params)12 avienc_movie_create(const char * filename, s_movie * movie, s_params * params)
13 {
14 void * handle;
15
16 int width;
17 int height;
18 int fps;
19 const char *preferences_filename;
20 const char *mime_type;
21
22 width = height = fps = 0;
23 preferences_filename = NULL;
24 mime_type = NULL;
25
26 s_params_get(params,
27 "mime-type", S_STRING_PARAM_TYPE, &mime_type, NULL);
28
29 if (!mime_type ||
30 ((strcmp(mime_type, "video/x-msvideo") != 0) &&
31 (strcmp(mime_type, "video/msvideo") != 0) &&
32 (strcmp(mime_type, "video/avi") != 0))) {
33 return 0;
34 }
35
36 /* Note 20020321 thammer:
37 I was unable to find any RFC with a MIME video subtype for avi-files.
38 However, the three subtypes above seems to be widely used.
39 Some examples:
40 Mosaic - http://archive.ncsa.uiuc.edu/SDG/Software/Mosaic/Docs/extension-map.html
41 Netscape - http://developer.netscape.com/docs/manuals/enterprise/40/nsapi/0c_mime.htm#1017298
42 - http://www.ulis.ac.jp/newsys/man/mimetypes.html
43 Jumpline - http://support.jumpline.com/mimetype_list.phtml <Extensive list of extension <-> mimetype mappings>
44 Pure Mac - http://www.eskimo.com/~pristine/extkey.html
45 */
46
47 s_params_get(params,
48 "parameter file", S_STRING_PARAM_TYPE, &preferences_filename, NULL);
49
50 s_params_get(params,
51 "width", S_INTEGER_PARAM_TYPE, &width, NULL);
52
53 s_params_get(params,
54 "height", S_INTEGER_PARAM_TYPE, &height, NULL);
55
56 s_params_get(params,
57 "fps", S_INTEGER_PARAM_TYPE, &fps, NULL);
58
59 /*
60 if preferences_filename == NULL or a file named preferences_filename does not exist,
61 a GUI dialog box will pop up and ask for preferences (compression method and parameters)
62 if preferences_filename != NULL and user didn't press [Cancel]
63 preferences will be saved to a new file named preferences_filename
64 else (a file named preferences_filename exists)
65 the preferences will be read from the specified file and no GUI will pop up
66
67 */
68
69 handle = (void *)avi_begin_encode(filename, width, height, fps, preferences_filename);
70
71 if (handle == NULL) return 0;
72
73 s_params_set(s_movie_params(movie), "avienc handle", S_POINTER_PARAM_TYPE, handle, 0);
74 return 1;
75 }
76
77 int
avienc_movie_put(s_movie * movie,s_image * image,s_params * params)78 avienc_movie_put(s_movie * movie, s_image * image, s_params * params)
79 {
80 void * handle;
81 int retval;
82 s_image *temp;
83
84 if (s_params_get(s_movie_params(movie), "avienc handle", S_POINTER_PARAM_TYPE, &handle, 0)) {
85 int mod;
86 int order;
87 order = s_image_get_component_order(image);
88 if (order == SIMAGE_ORDER_BGR)
89 return avi_encode_bitmap(handle, s_image_data(image), 0);
90 else {
91 if ( (params != NULL) &&
92 (s_params_get(params, "allow image modification", S_INTEGER_PARAM_TYPE, &mod, 0) &&
93 mod) ) {
94 if (avi_encode_bitmap(handle, s_image_data(image), 1)) {
95 s_image_set_component_order(image, SIMAGE_ORDER_BGR);
96 return 1;
97 }
98 else
99 return 0;
100 }
101 else {
102 /* Default to making a copy of the data */
103 temp = s_image_create(s_image_width(image), s_image_height(image),
104 s_image_components(image), NULL);
105 s_image_set(temp, s_image_width(image), s_image_height(image),
106 s_image_components(image), s_image_data(image), 1);
107 retval = avi_encode_bitmap(handle, s_image_data(temp), 1);
108 s_image_destroy(temp);
109 return retval;
110 }
111 }
112 }
113 return 0;
114 }
115
116 void
avienc_movie_close(s_movie * movie)117 avienc_movie_close(s_movie * movie)
118 {
119 void * handle;
120 if (s_params_get(s_movie_params(movie), "avienc handle", S_POINTER_PARAM_TYPE, &handle, 0)) {
121 avi_end_encode(handle);
122 }
123 }
124
125 #endif /* SIMAGE_AVIENC_SUPPORT */
126