annotate Plugins/Visualization/paranormal/pn/pnrotozoom.c @ 1729:3ee4c6d45c27 trunk

[svn] Fixed unused variable and missing type conversion
author js
date Sat, 16 Sep 2006 19:37:08 -0700
parents 0c5fdcf3f947
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1507
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
1 /* Paranormal - A highly customizable audio visualization library
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
2 * Copyright (C) 2001 Jamie Gennis <jgennis@mindspring.com>
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
3 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
4 * This library is free software; you can redistribute it and/or
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
5 * modify it under the terms of the GNU Library General Public
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
6 * License as published by the Free Software Foundation; either
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
7 * version 2 of the License, or (at your option) any later version.
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
8 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
9 * This library is distributed in the hope that it will be useful,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
12 * Library General Public License for more details.
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
13 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
14 * You should have received a copy of the GNU Library General Public
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
15 * License along with this library; if not, write to the Free
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
17 */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
18
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
19 #include <stdio.h>
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
20 #include <math.h>
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
21
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
22 #include <glib.h>
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
23 #include "pnrotozoom.h"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
24 #include "pnstringoption.h"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
25 #include "pnscript.h"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
26 #include "pnsymboltable.h"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
27 #include "pncpu.h"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
28
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
29 static void pn_roto_zoom_class_init (PnRotoZoomClass *class);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
30 static void pn_roto_zoom_init (PnRotoZoom *roto_zoom,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
31 PnRotoZoomClass *class);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
32
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
33 /* PnObject signals */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
34 static void pn_roto_zoom_destroy (PnObject *object);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
35
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
36 /* PnActuator methods */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
37 static void pn_roto_zoom_prepare (PnRotoZoom *roto_zoom,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
38 PnImage *image);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
39 static void pn_roto_zoom_execute (PnRotoZoom *roto_zoom,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
40 PnImage *image,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
41 PnAudioData *audio_data);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
42
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
43 static PnActuatorClass *parent_class = NULL;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
44
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
45 GType
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
46 pn_roto_zoom_get_type (void)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
47 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
48 static GType roto_zoom_type = 0;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
49
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
50 if (! roto_zoom_type)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
51 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
52 static const GTypeInfo roto_zoom_info =
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
53 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
54 sizeof (PnRotoZoomClass),
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
55 NULL, /* base_init */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
56 NULL, /* base_finalize */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
57 (GClassInitFunc) pn_roto_zoom_class_init,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
58 NULL, /* class_finalize */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
59 NULL, /* class_data */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
60 sizeof (PnRotoZoom),
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
61 0, /* n_preallocs */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
62 (GInstanceInitFunc) pn_roto_zoom_init
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
63 };
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
64
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
65 /* FIXME: should this be dynamic? */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
66 roto_zoom_type = g_type_register_static (PN_TYPE_ACTUATOR,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
67 "PnRotoZoom",
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
68 &roto_zoom_info,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
69 0);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
70 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
71 return roto_zoom_type;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
72 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
73
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
74 static void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
75 pn_roto_zoom_class_init (PnRotoZoomClass *class)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
76 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
77 PnObjectClass *object_class;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
78 PnUserObjectClass *user_object_class;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
79 PnActuatorClass *actuator_class;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
80
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
81 parent_class = g_type_class_peek_parent (class);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
82
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
83 object_class = (PnObjectClass *) class;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
84 user_object_class = (PnUserObjectClass *) class;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
85 actuator_class = (PnActuatorClass *) class;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
86
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
87 /* PnObject signals */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
88 object_class->destroy = pn_roto_zoom_destroy;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
89
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
90 /* PnActuator methods */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
91 actuator_class->prepare = (PnActuatorPrepFunc) pn_roto_zoom_prepare;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
92 actuator_class->execute = (PnActuatorExecFunc) pn_roto_zoom_execute;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
93 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
94
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
95 static void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
96 pn_roto_zoom_init (PnRotoZoom *roto_zoom, PnRotoZoomClass *class)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
97 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
98 PnStringOption *init_script_opt, *frame_script_opt;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
99
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
100 /* Set up the name and description */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
101 pn_user_object_set_name (PN_USER_OBJECT (roto_zoom), "Transform.Roto_Zoom");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
102 pn_user_object_set_description (PN_USER_OBJECT (roto_zoom),
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
103 "Rotate and zoom the image");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
104
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
105 /* Set up the options */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
106 init_script_opt = pn_string_option_new ("init_script", "The initialization script");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
107 frame_script_opt = pn_string_option_new ("frame_script", "The per-frame script");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
108
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
109 pn_actuator_add_option (PN_ACTUATOR (roto_zoom), PN_OPTION (init_script_opt));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
110 pn_actuator_add_option (PN_ACTUATOR (roto_zoom), PN_OPTION (frame_script_opt));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
111
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
112 /* Create the script objects and symbol table */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
113 roto_zoom->init_script = pn_script_new ();
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
114 pn_object_ref (PN_OBJECT (roto_zoom->init_script));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
115 pn_object_sink (PN_OBJECT (roto_zoom->init_script));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
116 roto_zoom->frame_script = pn_script_new ();
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
117 pn_object_ref (PN_OBJECT (roto_zoom->frame_script));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
118 pn_object_sink (PN_OBJECT (roto_zoom->frame_script));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
119 roto_zoom->symbol_table = pn_symbol_table_new ();
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
120 pn_object_ref (PN_OBJECT (roto_zoom->symbol_table));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
121 pn_object_sink (PN_OBJECT (roto_zoom->symbol_table));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
122
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
123 /* Get the variables from the symbol table */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
124 roto_zoom->zoom_var = pn_symbol_table_ref_variable_by_name (roto_zoom->symbol_table, "zoom");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
125 roto_zoom->theta_var = pn_symbol_table_ref_variable_by_name (roto_zoom->symbol_table, "theta");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
126 roto_zoom->volume_var = pn_symbol_table_ref_variable_by_name (roto_zoom->symbol_table, "volume");
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
127 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
128
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
129 static void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
130 pn_roto_zoom_destroy (PnObject *object)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
131 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
132 PnRotoZoom *roto_zoom;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
133
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
134 roto_zoom = (PnRotoZoom *) object;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
135
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
136 pn_object_unref (PN_OBJECT (roto_zoom->init_script));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
137 pn_object_unref (PN_OBJECT (roto_zoom->frame_script));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
138 pn_object_unref (PN_OBJECT (roto_zoom->symbol_table));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
139 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
140
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
141 static void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
142 pn_roto_zoom_prepare (PnRotoZoom *roto_zoom, PnImage *image)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
143 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
144 PnStringOption *init_script_opt, *frame_script_opt;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
145
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
146 g_return_if_fail (roto_zoom != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
147 g_return_if_fail (PN_IS_ROTO_ZOOM (roto_zoom));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
148 g_return_if_fail (image != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
149 g_return_if_fail (PN_IS_IMAGE (image));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
150
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
151 /* Parse the script strings */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
152 init_script_opt =
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
153 (PnStringOption *) pn_actuator_get_option_by_index (PN_ACTUATOR (roto_zoom),
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
154 PN_ROTO_ZOOM_OPT_INIT_SCRIPT);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
155 frame_script_opt =
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
156 (PnStringOption *) pn_actuator_get_option_by_index (PN_ACTUATOR (roto_zoom),
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
157 PN_ROTO_ZOOM_OPT_FRAME_SCRIPT);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
158
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
159 pn_script_parse_string (roto_zoom->init_script, roto_zoom->symbol_table,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
160 pn_string_option_get_value (init_script_opt));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
161 pn_script_parse_string (roto_zoom->frame_script, roto_zoom->symbol_table,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
162 pn_string_option_get_value (frame_script_opt));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
163
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
164 /* Set up in-script vars for no rotozooming */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
165 PN_VARIABLE_VALUE (roto_zoom->zoom_var) = 1.0;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
166 PN_VARIABLE_VALUE (roto_zoom->theta_var) = 0.0;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
167
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
168 /* Run the init script */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
169 pn_script_execute (roto_zoom->init_script);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
170
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
171 if (PN_ACTUATOR_CLASS (parent_class)->prepare)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
172 PN_ACTUATOR_CLASS (parent_class)->prepare (PN_ACTUATOR (roto_zoom), image);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
173 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
174
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
175 static void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
176 pn_roto_zoom_execute (PnRotoZoom *roto_zoom, PnImage *image, PnAudioData *audio_data)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
177 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
178 gint width, height, stride;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
179 gdouble ax, ay, bx, by, cx, cy;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
180 gint xdx, xdy, ydx, ydy;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
181 gint xx, xy, yx, yy;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
182 gint i, j;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
183 gdouble zoom, theta, r;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
184
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
185 PnColor *src, *dest;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
186
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
187 g_return_if_fail (roto_zoom != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
188 g_return_if_fail (PN_IS_ROTO_ZOOM (roto_zoom));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
189 g_return_if_fail (image != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
190 g_return_if_fail (PN_IS_IMAGE (image));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
191 g_return_if_fail (audio_data != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
192 g_return_if_fail (PN_IS_AUDIO_DATA (audio_data));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
193
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
194 width = pn_image_get_width (image);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
195 height = pn_image_get_height (image);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
196 stride = pn_image_get_pitch (image) >> 2;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
197 src = pn_image_get_image_buffer (image);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
198 dest = pn_image_get_transform_buffer (image);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
199
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
200 /* set up the volume in-script variable */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
201 PN_VARIABLE_VALUE (roto_zoom->volume_var) = pn_audio_data_get_volume (audio_data);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
202
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
203 /* run the frame scipt */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
204 pn_script_execute (roto_zoom->frame_script);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
205
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
206 /* get the in-script variable values */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
207 zoom = PN_VARIABLE_VALUE (roto_zoom->zoom_var);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
208 theta = PN_VARIABLE_VALUE (roto_zoom->theta_var);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
209
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
210 if (zoom == 0.0)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
211 return;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
212
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
213 r = G_SQRT2 / zoom;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
214
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
215 ax = r * cos ((G_PI * .75) + theta);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
216 ay = r * sin ((G_PI * .75) + theta);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
217 bx = r * cos ((G_PI * .25) + theta);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
218 by = r * sin ((G_PI * .25) + theta);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
219 cx = r * cos ((G_PI * 1.25) + theta);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
220 cy = r * sin ((G_PI * 1.25) + theta);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
221
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
222 /* fprintf (stderr, "ax: %f, ay: %f\n", ax, ay); */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
223 /* fprintf (stderr, "bx: %f, by: %f\n", bx, by); */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
224 /* fprintf (stderr, "cx: %f, cy: %f\n", cx, cy); */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
225
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
226 ax = ((width-1)<<8) * ((ax + 1) * .5);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
227 ay = ((height-1)<<8) * ((-ay + 1) * .5);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
228 bx = ((width-1)<<8) * ((bx + 1) * .5);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
229 by = ((height-1)<<8) * ((-by + 1) * .5);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
230 cx = ((width-1)<<8) * ((cx + 1) * .5);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
231 cy = ((height-1)<<8) * ((-cy + 1) * .5);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
232
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
233 /* fprintf (stderr, "ax': %f, ay': %f\n", ax, ay); */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
234 /* fprintf (stderr, "bx': %f, by': %f\n", bx, by); */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
235 /* fprintf (stderr, "cx': %f, cy': %f\n", cx, cy); */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
236
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
237 xdx = (bx - ax) / (width-1);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
238 xdy = (by - ay) / (width-1);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
239 ydx = (cx - ax) / (height-1);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
240 ydy = (cy - ay) / (height-1);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
241
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
242 /* fprintf (stderr, "xdx: %i, xdy: %i\n", xdx, xdy); */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
243 /* fprintf (stderr, "ydx: %i, ydy: %i\n", ydx, ydy); */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
244
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
245 yx = ax;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
246 yy = ay;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
247
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
248 for (j=0; j<height; j++)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
249 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
250 while (yx < 0) yx += width<<8;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
251 while (yy < 0) yy += height<<8;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
252 while (yx >= width<<8) yx -= width<<8;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
253 while (yy >= height<<8) yy -= height<<8;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
254
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
255 xx = yx;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
256 xy = yy;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
257
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
258 for (i=0; i<width; i++)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
259 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
260 guint r, g, b, offset;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
261 guint xfrac, yfrac;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
262
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
263 while (xx < 0) xx += width<<8;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
264 while (xy < 0) xy += height<<8;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
265 while (xx >= width<<8) xx -= width<<8;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
266 while (xy >= height<<8) xy -= height<<8;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
267
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
268 offset = (xy >> 8) * stride + (xx >> 8);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
269 xfrac = xx & 0xff;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
270 yfrac = xy & 0xff;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
271
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
272 r = src[offset].red * (256 - xfrac) * (256 - yfrac);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
273 g = src[offset].green * (256 - xfrac) * (256 - yfrac);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
274 b = src[offset].blue * (256 - xfrac) * (256 - yfrac);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
275
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
276 if (xx >> 8 < width-1)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
277 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
278 r += src[offset+1].red * xfrac * (256 - yfrac);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
279 g += src[offset+1].green * xfrac * (256 - yfrac);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
280 b += src[offset+1].blue * xfrac * (256 - yfrac);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
281 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
282 else
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
283 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
284 r += src[(xy>>8) * stride].red * xfrac * (256 - yfrac);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
285 g += src[(xy>>8) * stride].green * xfrac * (256 - yfrac);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
286 b += src[(xy>>8) * stride].blue * xfrac * (256 - yfrac);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
287 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
288
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
289 if (xy >> 8 < height-1)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
290 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
291 r += src[offset+stride].red * (256 - xfrac) * yfrac;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
292 g += src[offset+stride].green * (256 - xfrac) * yfrac;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
293 b += src[offset+stride].blue * (256 - xfrac) * yfrac;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
294 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
295 else
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
296 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
297 r += src[xx>>8].red * (256 - xfrac) * yfrac;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
298 g += src[xx>>8].green * (256 - xfrac) * yfrac;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
299 b += src[xx>>8].blue * (256 - xfrac) * yfrac;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
300 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
301
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
302 if (xx >> 8 < width-1 && xy >> 8 < height-1)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
303 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
304 r += src[offset+stride+1].red * xfrac * yfrac;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
305 g += src[offset+stride+1].green * xfrac * yfrac;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
306 b += src[offset+stride+1].blue * xfrac * yfrac;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
307 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
308 else
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
309 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
310 r += src[0].red * xfrac * yfrac;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
311 g += src[0].green * xfrac * yfrac;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
312 b += src[0].blue * xfrac * yfrac;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
313 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
314
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
315 dest[j * stride + i].red = r >> 16;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
316 dest[j * stride + i].green = g >> 16;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
317 dest[j * stride + i].blue = b >> 16;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
318
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
319 xx += xdx;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
320 xy += xdy;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
321 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
322
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
323 yx += ydx;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
324 yy += ydy;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
325 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
326
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
327 /* fprintf (stderr, "xx: %i, xy: %i\n", xx, xy); */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
328
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
329 pn_image_apply_transform (image);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
330
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
331 if (PN_ACTUATOR_CLASS (parent_class)->execute != NULL)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
332 PN_ACTUATOR_CLASS (parent_class)->execute (PN_ACTUATOR (roto_zoom), image, audio_data);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
333 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
334
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
335 PnRotoZoom*
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
336 pn_roto_zoom_new (void)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
337 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
338 return (PnRotoZoom *) g_object_new (PN_TYPE_ROTO_ZOOM, NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
339 }