1 // Copyright 2004 David Hilvert <dhilvert@auricle.dyndns.org>,
2 // <dhilvert@ugcs.caltech.edu>
4 /* This file is part of the Anti-Lamenessing Engine.
6 The Anti-Lamenessing Engine is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 The Anti-Lamenessing Engine is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with the Anti-Lamenessing Engine; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * vise_core.h: Manages instances of vise.
25 #ifndef __vise_core_h__
26 #define __vise_core_h__
34 * Vise_core initializes, and maintains shared variables for, all instances of
40 static unsigned int active_size
;
41 static ale_real scale_factor
;
46 * Set the VISE scale factor.
48 static void set_scale(ale_real factor
) {
49 scale_factor
= factor
;
53 * Add a new video stabilization engine.
55 static void add(render
*chain
, const char *type
, const char *prefix
, const char *suffix
) {
58 * Instantiate an engine of the appropriate type.
60 if (!strcmp(type
, "identity")) {
63 * Identity is a moving average 0 frames to either side.
65 active
= (vise
**) realloc(active
, ++active_size
* sizeof(vise
*));
68 fprintf(stderr
, "\n\n*** VISE: Unable to allocate memory ***\n\n\n");
71 active
[active_size
- 1] = new ma(chain
, 0, prefix
, suffix
, scale_factor
);
73 } else if (!strncmp(type
, "ma:", 3)) {
76 * Moving average with an unsigned range parameter.
81 if(sscanf(type
+ 3, "%u", &range
) != 1) {
82 fprintf(stderr
, "\n\n*** VISE: 'ma:' type requires an unsigned argument. ***\n\n\n");
86 active
= (vise
**) realloc(active
, ++active_size
* sizeof(vise
*));
89 fprintf(stderr
, "\n\n*** VISE: Unable to allocate memory ***\n\n\n");
92 active
[active_size
- 1] = new ma(chain
, range
, prefix
, suffix
, scale_factor
);
93 } else if (!strncmp(type
, "sf:", 3)) {
96 * Single frame with an unsigned frame parameter.
101 if(sscanf(type
+ 3, "%u", &frame
) != 1) {
102 fprintf(stderr
, "\n\n*** VISE: 'sf:' type requires an unsigned argument. ***\n\n\n");
106 active
= (vise
**) realloc(active
, ++active_size
* sizeof(vise
*));
108 if (active
== NULL
) {
109 fprintf(stderr
, "\n\n*** VISE: Unable to allocate memory ***\n\n\n");
112 active
[active_size
- 1] = new sf(chain
, frame
, prefix
, suffix
, scale_factor
);
115 fprintf(stderr
, "\n\n*** VISE: Unknown type '%s' ***\n\n\n", type
);
122 * Add a new image to the rendering queue.
124 static void frame_queue_add(unsigned int frame_number
) {
127 * Process the current queue.
129 for (unsigned int i
= 0; i
< active_size
; i
++) {
130 int lag
= active
[i
]->lag();
132 if ((int) frame_number
- lag
>= 0)
133 active
[i
]->render_frame(frame_number
- lag
);
137 * If this is the last frame, then complete all rendering.
139 if (frame_number
== image_rw::count() - 1)
140 for (unsigned int i
= 0; i
< active_size
; i
++)
141 for (int j
= active
[i
]->lag() - 1; j
>= 0; j
--)
142 active
[i
]->render_frame(frame_number
- j
);