ui: initialize alignment display parameters, so that these do not assume
[Ale.git] / d2 / vise_core.h
blob2ddfc9e8b49f982abefcc9dbd87fdfcfdf03d658
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__
28 #include "vise.h"
29 #include "image.h"
30 #include "vise/ma.h"
31 #include "vise/sf.h"
34 * Vise_core initializes, and maintains shared variables for, all instances of
35 * vise.
38 class vise_core {
39 static vise **active;
40 static unsigned int active_size;
41 static ale_real scale_factor;
43 public:
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 *));
66 assert(active);
67 if (active == NULL) {
68 fprintf(stderr, "\n\n*** VISE: Unable to allocate memory ***\n\n\n");
69 exit(1);
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.
79 unsigned int range;
81 if(sscanf(type + 3, "%u", &range) != 1) {
82 fprintf(stderr, "\n\n*** VISE: 'ma:' type requires an unsigned argument. ***\n\n\n");
83 exit(1);
86 active = (vise **) realloc(active, ++active_size * sizeof(vise *));
87 assert(active);
88 if (active == NULL) {
89 fprintf(stderr, "\n\n*** VISE: Unable to allocate memory ***\n\n\n");
90 exit(1);
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.
99 unsigned int frame;
101 if(sscanf(type + 3, "%u", &frame) != 1) {
102 fprintf(stderr, "\n\n*** VISE: 'sf:' type requires an unsigned argument. ***\n\n\n");
103 exit(1);
106 active = (vise **) realloc(active, ++active_size * sizeof(vise *));
107 assert(active);
108 if (active == NULL) {
109 fprintf(stderr, "\n\n*** VISE: Unable to allocate memory ***\n\n\n");
110 exit(1);
112 active[active_size - 1] = new sf(chain, frame, prefix, suffix, scale_factor);
114 } else {
115 fprintf(stderr, "\n\n*** VISE: Unknown type '%s' ***\n\n\n", type);
116 exit(1);
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);
146 #endif