1507
|
1 /* Paranormal - A highly customizable audio visualization library
|
|
2 * Copyright (C) 2001 Jamie Gennis <jgennis@mindspring.com>
|
|
3 *
|
|
4 * This library is free software; you can redistribute it and/or
|
|
5 * modify it under the terms of the GNU Library General Public
|
|
6 * License as published by the Free Software Foundation; either
|
|
7 * version 2 of the License, or (at your option) any later version.
|
|
8 *
|
|
9 * This library is distributed in the hope that it will be useful,
|
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12 * Library General Public License for more details.
|
|
13 *
|
|
14 * You should have received a copy of the GNU Library General Public
|
|
15 * License along with this library; if not, write to the Free
|
|
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
17 */
|
|
18
|
|
19 #include <glib.h>
|
|
20 #include "pnimagecontext.h"
|
|
21 #include "pnlistoption.h"
|
|
22
|
|
23 static void pn_image_context_class_init (PnImageContextClass *class);
|
|
24 static void pn_image_context_init (PnImageContext *image_context,
|
|
25 PnImageContextClass *class);
|
|
26 /* GObject methods */
|
|
27 static void pn_image_context_finalize (GObject *gobject);
|
|
28
|
|
29 /* PnActuator methods */
|
|
30 static void pn_image_context_prepare (PnImageContext *image_context,
|
|
31 PnImage *image);
|
|
32 static void pn_image_context_execute (PnImageContext *image_context,
|
|
33 PnImage *image,
|
|
34 PnAudioData *audio_data);
|
|
35
|
|
36 static PnActuatorClass *parent_class = NULL;
|
|
37
|
|
38 GType
|
|
39 pn_image_context_get_type (void)
|
|
40 {
|
|
41 static GType image_context_type = 0;
|
|
42
|
|
43 if (! image_context_type)
|
|
44 {
|
|
45 static const GTypeInfo image_context_info =
|
|
46 {
|
|
47 sizeof (PnImageContextClass),
|
|
48 NULL, /* base_init */
|
|
49 NULL, /* base_finalize */
|
|
50 (GClassInitFunc) pn_image_context_class_init,
|
|
51 NULL, /* class_finalize */
|
|
52 NULL, /* class_data */
|
|
53 sizeof (PnImageContext),
|
|
54 0, /* n_preallocs */
|
|
55 (GInstanceInitFunc) pn_image_context_init
|
|
56 };
|
|
57
|
|
58 /* FIXME: should this be dynamic? */
|
|
59 image_context_type = g_type_register_static (PN_TYPE_CONTAINER,
|
|
60 "PnImageContext",
|
|
61 &image_context_info,
|
|
62 0);
|
|
63 }
|
|
64 return image_context_type;
|
|
65 }
|
|
66
|
|
67 static void
|
|
68 pn_image_context_class_init (PnImageContextClass *class)
|
|
69 {
|
|
70 GObjectClass *gobject_class;
|
|
71 PnObjectClass *object_class;
|
|
72 PnUserObjectClass *user_object_class;
|
|
73 PnActuatorClass *actuator_class;
|
|
74
|
|
75 parent_class = g_type_class_peek_parent (class);
|
|
76
|
|
77 gobject_class = (GObjectClass *) class;
|
|
78 object_class = (PnObjectClass *) class;
|
|
79 user_object_class = (PnUserObjectClass *) class;
|
|
80 actuator_class = (PnActuatorClass *) class;
|
|
81
|
|
82 /* GObject methods */
|
|
83 gobject_class->finalize = pn_image_context_finalize;
|
|
84
|
|
85 /* PnActuator methods */
|
|
86 actuator_class->prepare = (PnActuatorPrepFunc) pn_image_context_prepare;
|
|
87 actuator_class->execute = (PnActuatorExecFunc) pn_image_context_execute;
|
|
88 }
|
|
89
|
|
90 static void
|
|
91 pn_image_context_finalize (GObject *gobject)
|
|
92 {
|
|
93 PnImageContext *image_context;
|
|
94
|
|
95 image_context = (PnImageContext *) gobject;
|
|
96
|
|
97 if (image_context->image)
|
|
98 pn_object_unref (PN_OBJECT (image_context->image));
|
|
99 }
|
|
100
|
|
101 static void
|
|
102 pn_image_context_init (PnImageContext *image_context, PnImageContextClass *class)
|
|
103 {
|
|
104 PnListOption *input_mode_opt, *output_mode_opt;
|
|
105 guint i;
|
|
106
|
|
107 /* Set up the name and description */
|
|
108 pn_user_object_set_name (PN_USER_OBJECT (image_context), "Container.Image_Context");
|
|
109 pn_user_object_set_description (PN_USER_OBJECT (image_context),
|
|
110 "A container that executes all its actuators sequentially");
|
|
111
|
|
112 /* Set up the options */
|
|
113 input_mode_opt = pn_list_option_new ("input_mode", "The blend mode to be used when getting the image "
|
|
114 "from the parent context");
|
|
115 output_mode_opt = pn_list_option_new ("output_mode", "The blend mode to be used when writing the image "
|
|
116 "to the parent context");
|
|
117
|
|
118 for (i=0; i<pn_image_blend_mode_count; i++)
|
|
119 {
|
|
120 pn_list_option_add_item (input_mode_opt, pn_image_blend_mode_strings[i]);
|
|
121 pn_list_option_add_item (output_mode_opt, pn_image_blend_mode_strings[i]);
|
|
122 }
|
|
123
|
|
124 pn_list_option_set_index (input_mode_opt, 0); /* default mode: Ignore */
|
|
125 pn_list_option_set_index (output_mode_opt, 1); /* default mode: Replace */
|
|
126
|
|
127 pn_actuator_add_option (PN_ACTUATOR (image_context), PN_OPTION (input_mode_opt));
|
|
128 pn_actuator_add_option (PN_ACTUATOR (image_context), PN_OPTION (output_mode_opt));
|
|
129
|
|
130 /* Create the new image */
|
|
131 image_context->image = pn_image_new ();
|
|
132 pn_object_ref (PN_OBJECT (image_context->image));
|
|
133 pn_object_sink (PN_OBJECT (image_context->image));
|
|
134 }
|
|
135
|
|
136 static void
|
|
137 pn_image_context_prepare (PnImageContext *image_context, PnImage *image)
|
|
138 {
|
|
139 g_return_if_fail (image_context != NULL);
|
|
140 g_return_if_fail (PN_IS_IMAGE_CONTEXT (image_context));
|
|
141 g_return_if_fail (image != NULL);
|
|
142 g_return_if_fail (PN_IS_IMAGE (image));
|
|
143
|
|
144 pn_image_set_size (image_context->image, pn_image_get_width (image), pn_image_get_height (image));
|
|
145
|
|
146 if (PN_ACTUATOR_CLASS (parent_class)->prepare)
|
|
147 PN_ACTUATOR_CLASS (parent_class)->prepare (PN_ACTUATOR (image_context), image);
|
|
148 }
|
|
149
|
|
150 static void
|
|
151 pn_image_context_execute (PnImageContext *image_context, PnImage *image,
|
|
152 PnAudioData *audio_data)
|
|
153 {
|
|
154 guint i;
|
|
155 GArray *actuators;
|
|
156 PnListOption *input_mode_opt, *output_mode_opt;
|
|
157
|
|
158 g_return_if_fail (image_context != NULL);
|
|
159 g_return_if_fail (PN_IS_IMAGE_CONTEXT (image_context));
|
|
160 g_return_if_fail (image != NULL);
|
|
161 g_return_if_fail (PN_IS_IMAGE (image));
|
|
162 g_return_if_fail (audio_data != NULL);
|
|
163
|
|
164 actuators = ((PnContainer *) (image_context))->actuators;;
|
|
165
|
|
166 input_mode_opt = (PnListOption *) pn_actuator_get_option_by_index (PN_ACTUATOR (image_context),
|
|
167 PN_IMAGE_CONTEXT_OPT_INPUT_MODE);
|
|
168 output_mode_opt = (PnListOption *) pn_actuator_get_option_by_index (PN_ACTUATOR (image_context),
|
|
169 PN_IMAGE_CONTEXT_OPT_OUTPUT_MODE);
|
|
170
|
|
171 /* Get the image from the parent context */
|
|
172 pn_image_render_image (image_context->image, image, (PnBlendMode) pn_list_option_get_index (input_mode_opt));
|
|
173
|
|
174 for (i=0; i<actuators->len; i++)
|
|
175 pn_actuator_execute (g_array_index (actuators, PnActuator *, i), image_context->image, audio_data);
|
|
176
|
|
177 /* Write the image to the parent context */
|
|
178 pn_image_render_image (image, image_context->image, (PnBlendMode) pn_list_option_get_index (output_mode_opt));
|
|
179
|
|
180 if (PN_ACTUATOR_CLASS (parent_class)->execute)
|
|
181 PN_ACTUATOR_CLASS (parent_class)->execute(PN_ACTUATOR (image_context), image, audio_data);
|
|
182 }
|
|
183
|
|
184 PnImageContext*
|
|
185 pn_image_context_new (void)
|
|
186 {
|
|
187 return (PnImageContext *) g_object_new (PN_TYPE_IMAGE_CONTEXT, NULL);
|
|
188 }
|