Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://coin3d.github.io
https://www.kongsberg.com/en/kogt/
simage_avi.c
Go to the documentation of this file.
1 #include <config.h>
2 #ifdef SIMAGE_AVIENC_SUPPORT
3 
4 /*
5  * Copyright (c) Kongsberg Oil & Gas Technologies
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #include <stdio.h>
21 #include <string.h>
22 
23 #include <simage_private.h>
24 #include <simage_avi.h>
25 #include <avi_encode.h>
26 
27 int
28 avienc_movie_create(const char * filename, s_movie * movie, s_params * params)
29 {
30  void * handle;
31 
32  int width;
33  int height;
34  int fps;
35  const char *preferences_filename;
36  const char *mime_type;
37 
38  width = height = fps = 0;
39  preferences_filename = NULL;
40  mime_type = NULL;
41 
42  s_params_get(params,
43  "mime-type", S_STRING_PARAM_TYPE, &mime_type, NULL);
44 
45  if (!mime_type ||
46  ((strcmp(mime_type, "video/x-msvideo") != 0) &&
47  (strcmp(mime_type, "video/msvideo") != 0) &&
48  (strcmp(mime_type, "video/avi") != 0))) {
49  return 0;
50  }
51 
52  /* Note 20020321 thammer:
53  I was unable to find any RFC with a MIME video subtype for avi-files.
54  However, the three subtypes above seems to be widely used.
55  Some examples:
56  Mosaic - http://archive.ncsa.uiuc.edu/SDG/Software/Mosaic/Docs/extension-map.html
57  Netscape - http://developer.netscape.com/docs/manuals/enterprise/40/nsapi/0c_mime.htm#1017298
58  - http://www.ulis.ac.jp/newsys/man/mimetypes.html
59  Jumpline - http://support.jumpline.com/mimetype_list.phtml <Extensive list of extension <-> mimetype mappings>
60  Pure Mac - http://www.eskimo.com/~pristine/extkey.html
61  */
62 
63  s_params_get(params,
64  "parameter file", S_STRING_PARAM_TYPE, &preferences_filename, NULL);
65 
66  s_params_get(params,
67  "width", S_INTEGER_PARAM_TYPE, &width, NULL);
68 
69  s_params_get(params,
70  "height", S_INTEGER_PARAM_TYPE, &height, NULL);
71 
72  s_params_get(params,
73  "fps", S_INTEGER_PARAM_TYPE, &fps, NULL);
74 
75  /*
76  if preferences_filename == NULL or a file named preferences_filename does not exist,
77  a GUI dialog box will pop up and ask for preferences (compression method and parameters)
78  if preferences_filename != NULL and user didn't press [Cancel]
79  preferences will be saved to a new file named preferences_filename
80  else (a file named preferences_filename exists)
81  the preferences will be read from the specified file and no GUI will pop up
82 
83  */
84 
85  handle = (void *)avi_begin_encode(filename, width, height, fps, preferences_filename);
86 
87  if (handle == NULL) return 0;
88 
89  s_params_set(s_movie_params(movie), "avienc handle", S_POINTER_PARAM_TYPE, handle, 0);
90  return 1;
91 }
92 
93 int
94 avienc_movie_put(s_movie * movie, s_image * image, s_params * params)
95 {
96  void * handle;
97  int retval;
98  s_image *temp;
99 
100  if (s_params_get(s_movie_params(movie), "avienc handle", S_POINTER_PARAM_TYPE, &handle, 0)) {
101  int mod;
102  int order;
103  order = s_image_get_component_order(image);
104  if (order == SIMAGE_ORDER_BGR)
105  return avi_encode_bitmap(handle, s_image_data(image), 0);
106  else {
107  if ( (params != NULL) &&
108  (s_params_get(params, "allow image modification", S_INTEGER_PARAM_TYPE, &mod, 0) &&
109  mod) ) {
110  if (avi_encode_bitmap(handle, s_image_data(image), 1)) {
112  return 1;
113  }
114  else
115  return 0;
116  }
117  else {
118  /* Default to making a copy of the data */
119  temp = s_image_create(s_image_width(image), s_image_height(image),
120  s_image_components(image), NULL);
121  s_image_set(temp, s_image_width(image), s_image_height(image),
122  s_image_components(image), s_image_data(image), 1);
123  retval = avi_encode_bitmap(handle, s_image_data(temp), 1);
124  s_image_destroy(temp);
125  return retval;
126  }
127  }
128  }
129  return 0;
130 }
131 
132 void
134 {
135  void * handle;
136  if (s_params_get(s_movie_params(movie), "avienc handle", S_POINTER_PARAM_TYPE, &handle, 0)) {
137  avi_end_encode(handle);
138  }
139 }
140 
141 #endif /* SIMAGE_AVIENC_SUPPORT */
s_params * s_movie_params(s_movie *movie)
Definition: movie.c:190
int s_image_set_component_order(s_image *image, int order)
Definition: simage12.c:94
void s_params_set(s_params *params,...)
Definition: params.c:187
int s_params_get(s_params *params,...)
Definition: params.c:251
char * filename
Definition: stream.c:38
s_image * s_image_create(int w, int h, int components, unsigned char *prealloc)
Definition: simage12.c:30
int avienc_movie_create(const char *filename, s_movie *movie, s_params *params)
void s_image_destroy(s_image *image)
Definition: simage12.c:56
int s_image_get_component_order(s_image *image)
Definition: simage12.c:102
int s_image_components(s_image *image)
Definition: simage12.c:86
void s_image_set(s_image *image, int w, int h, int components, unsigned char *data, int copydata)
Definition: simage12.c:126
int s_image_width(s_image *image)
Definition: simage12.c:72
void avienc_movie_close(s_movie *movie)
int avi_encode_bitmap(void *handle, unsigned char *buf, int rgb2bgr)
unsigned char * s_image_data(s_image *image)
Definition: simage12.c:108
int avi_end_encode(void *handle)
int avienc_movie_put(s_movie *movie, s_image *image, s_params *params)
void * avi_begin_encode(const char *filename, int width, int height, int fps, const char *preferences_filename)
s_params * params
Definition: stream.c:48
int s_image_height(s_image *image)
Definition: simage12.c:79