annotate Plugins/Visualization/paranormal/pn/pnimage.c @ 1523:aa1e05d66f6d trunk

[svn] - it might help if i actually ran bison on the script parser eh :)
author nenolod
date Mon, 07 Aug 2006 21:47:55 -0700
parents 0c5fdcf3f947
children a898e415ad8f
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 <config.h>
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
20
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
21 #include <glib.h>
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
22 #include "pnimage.h"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
23 #include "pnerror.h"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
24 #include "pncpu.h"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
25
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
26 static void pn_image_class_init (PnImageClass *class);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
27 static void pn_image_init (PnImage *image,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
28 PnImageClass *class);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
29
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
30 /* GObject signals */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
31 static void pn_image_finalize (GObject *gobject);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
32
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
33 static PnObjectClass *parent_class = NULL;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
34
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
35 const gchar *pn_image_blend_mode_strings[] =
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
36 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
37 "Ignore",
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
38 "Replace",
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
39 "50/50"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
40 };
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
41 const guint pn_image_blend_mode_count = 3;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
42
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
43 GType
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
44 pn_image_get_type (void)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
45 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
46 static GType image_type = 0;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
47
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
48 if (! image_type)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
49 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
50 static const GTypeInfo image_info =
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
51 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
52 sizeof (PnImageClass),
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
53 NULL, /* base_init */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
54 NULL, /* base_finalize */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
55 (GClassInitFunc) pn_image_class_init,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
56 NULL, /* class_finalize */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
57 NULL, /* class_data */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
58 sizeof (PnImage),
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
59 0, /* n_preallocs */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
60 (GInstanceInitFunc) pn_image_init
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
61 };
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
62
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
63 /* FIXME: should this be dynamic? */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
64 image_type = g_type_register_static (PN_TYPE_OBJECT,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
65 "PnImage",
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
66 &image_info,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
67 0);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
68 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
69 return image_type;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
70 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
71
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
72 static void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
73 pn_image_class_init (PnImageClass *class)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
74 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
75 GObjectClass *gobject_class;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
76 PnObjectClass *object_class;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
77
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
78 parent_class = g_type_class_peek_parent (class);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
79
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
80 gobject_class = (GObjectClass *) class;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
81 object_class = (PnObjectClass *) class;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
82
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
83 /* GObject signals */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
84 gobject_class->finalize = pn_image_finalize;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
85 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
86
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
87 static void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
88 pn_image_init (PnImage *image, PnImageClass *class)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
89 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
90 image->render_mode = PN_BLEND_MODE_REPLACE;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
91 image->transform_mode = PN_BLEND_MODE_REPLACE;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
92 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
93
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
94 static void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
95 pn_image_finalize (GObject *gobject)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
96 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
97 PnImage *image;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
98
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
99 image = (PnImage *) gobject;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
100
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
101 if (image->image_buffer)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
102 g_free (image->image_buffer);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
103
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
104 if (image->transform_buffer)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
105 g_free (image->transform_buffer);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
106 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
107
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
108 /**
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
109 * pn_image_new
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
110 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
111 * Creates a new #PnImage object
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
112 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
113 * Returns: The new #PnImage object
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
114 */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
115 PnImage*
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
116 pn_image_new (void)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
117 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
118 return (PnImage *) g_object_new (PN_TYPE_IMAGE, NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
119 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
120
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
121 /**
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
122 * pn_image_new_width_size
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
123 * @width: the width of the new image
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
124 * @height: the hight of the new image
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
125 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
126 * Creates a new #PnImage object with the given dimensions
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
127 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
128 * Returns: The new #PnImage object
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
129 */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
130 PnImage*
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
131 pn_image_new_with_size (guint width, guint height)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
132 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
133 PnImage *image;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
134
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
135 image = (PnImage *) g_object_new (PN_TYPE_IMAGE, NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
136
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
137 pn_image_set_size (image, width, height);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
138
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
139 return image;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
140 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
141
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
142 /**
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
143 * pn_image_set_size
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
144 * @image: a #PnImage
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
145 * @width: the new width of the image
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
146 * @height: the new height of the image
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
147 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
148 * Sets the size of the image contained in a #PnImage object
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
149 */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
150 void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
151 pn_image_set_size (PnImage *image, guint width, guint height)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
152 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
153 guint pitch;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
154
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
155 g_return_if_fail (image != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
156 g_return_if_fail (PN_IS_IMAGE (image));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
157 g_return_if_fail (width > 0 && height > 0);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
158
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
159 pitch = width * sizeof (PnColor);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
160
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
161 /* Align each row to 8 bytes */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
162 if (pitch & 0x00000007)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
163 pitch = (pitch & 0xfffffff8) + 8;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
164
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
165 if (image->image_buffer)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
166 g_free (image->image_buffer);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
167
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
168 if (image->transform_buffer)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
169 g_free (image->transform_buffer);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
170
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
171 image->pitch = pitch;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
172 image->width = width;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
173 image->height = height;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
174 image->image_buffer = g_malloc0 (pitch * height);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
175 image->transform_buffer = g_malloc0 (pitch * height);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
176 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
177
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
178 /**
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
179 * pn_image_get_width
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
180 * @image: a #PnImage
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
181 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
182 * Gets the width of a #PnImage
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
183 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
184 * Returns: The width of the image
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
185 */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
186 guint
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
187 pn_image_get_width (PnImage *image)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
188 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
189 g_return_val_if_fail (image != NULL, 0);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
190 g_return_val_if_fail (PN_IS_IMAGE (image), 0);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
191
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
192 return image->width;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
193 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
194
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
195 /**
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
196 * pn_image_get_height
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
197 * @image: a #PnImage
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
198 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
199 * Gets the height of a #PnImage
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
200 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
201 * Returns: The height of the image
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
202 */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
203 guint
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
204 pn_image_get_height (PnImage *image)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
205 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
206 g_return_val_if_fail (image != NULL, 0);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
207 g_return_val_if_fail (PN_IS_IMAGE (image), 0);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
208
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
209 return image->height;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
210 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
211
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
212 /**
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
213 * pn_image_get_pitch
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
214 * @image: a #PnImage
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
215 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
216 * Gets the pitch (width in bytes) of a #PnImage
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
217 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
218 * Returns: The pitch of the image
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
219 */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
220 guint
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
221 pn_image_get_pitch (PnImage *image)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
222 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
223 g_return_val_if_fail (image != NULL, 0);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
224 g_return_val_if_fail (PN_IS_IMAGE (image), 0);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
225
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
226 return image->pitch;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
227 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
228
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
229 /**
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
230 * pn_image_set_render_mode
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
231 * @image: a #PnImage
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
232 * @render_mode: the blend mode to use
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
233 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
234 * Sets the blend mode to be used by render functions. The
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
235 * render functions are pn_image_render_pixel(),
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
236 * pn_image_render_pixel_by_offset(), and pn_image_render_line().
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
237 */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
238 void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
239 pn_image_set_render_mode (PnImage *image, PnBlendMode render_mode)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
240 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
241 g_return_if_fail (image != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
242 g_return_if_fail (PN_IS_IMAGE (image));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
243 g_return_if_fail (render_mode < PN_BLEND_MODE_LAST);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
244
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
245 image->render_mode = render_mode;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
246 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
247
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
248 /**
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
249 * pn_image_set_transform_mode
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
250 * @image: a #PnImage
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
251 * @transform_mode: the blend mode to use
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
252 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
253 * Sets the blend mode to be used by pn_image_apply_transform().
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
254 */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
255 void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
256 pn_image_set_transform_mode (PnImage *image, PnBlendMode transform_mode)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
257 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
258 g_return_if_fail (image != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
259 g_return_if_fail (PN_IS_IMAGE (image));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
260 g_return_if_fail (transform_mode < PN_BLEND_MODE_LAST);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
261
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
262 image->transform_mode = transform_mode;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
263 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
264
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
265 /**
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
266 * pn_image_get_image_buffer
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
267 * @image: a #PnImage
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
268 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
269 * Retrieves the image buffer (the 'front buffer') of a #PnImage.
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
270 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
271 * Returns: A pointer to the image buffer
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
272 */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
273 PnColor*
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
274 pn_image_get_image_buffer (PnImage *image)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
275 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
276 g_return_val_if_fail (image != NULL, NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
277 g_return_val_if_fail (PN_IS_IMAGE (image), NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
278
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
279 return image->image_buffer;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
280 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
281
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
282 /**
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
283 * pn_image_get_transform_buffer
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
284 * @image: a #PnImage
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
285 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
286 * Retrieves the transform buffer (the 'back buffer') of a #PnImage.
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
287 * The transform buffer should only be used internally by transform
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
288 * actuators. *EVERY* pixel in the transform buffer *MUST* be set.
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
289 * The transform buffer can be 'copied' to the image buffer using
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
290 * pn_image_apply_transform().
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
291 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
292 * Returns: A pointer to the transform buffer
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
293 */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
294 PnColor*
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
295 pn_image_get_transform_buffer (PnImage *image)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
296 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
297 g_return_val_if_fail (image != NULL, NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
298 g_return_val_if_fail (PN_IS_IMAGE (image), NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
299
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
300 return image->transform_buffer;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
301 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
302
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
303 /**
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
304 * pn_image_render_pixel
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
305 * @image: a #PnImage
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
306 * @x: the x coordinate (left being 0)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
307 * @y: the y coordinate (top being 0)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
308 * @color: the color
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
309 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
310 * Renders a pixel to the image buffer of a #PnImage. pn_image_set_render_mode()
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
311 * can be used to set the blend mode that is used by this function.
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
312 */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
313 void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
314 pn_image_render_pixel (PnImage *image, guint x, guint y, PnColor color)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
315 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
316 g_return_if_fail (image != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
317 g_return_if_fail (PN_IS_IMAGE (image));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
318 g_return_if_fail (image->image_buffer != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
319
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
320 if (x > image->width || y > image->height)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
321 return;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
322
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
323 switch (image->render_mode)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
324 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
325 case PN_BLEND_MODE_LAST: break;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
326 case PN_BLEND_MODE_IGNORE:
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
327 break;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
328
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
329 case PN_BLEND_MODE_REPLACE:
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
330 image->image_buffer[(y * (image->pitch>>2)) + x] = color;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
331 break;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
332
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
333 case PN_BLEND_MODE_5050:
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
334 image->image_buffer[(y * (image->pitch>>2)) + x].red =
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
335 (image->image_buffer[(y * (image->pitch>>2)) + x].red + color.red) >> 1;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
336 image->image_buffer[(y * (image->pitch>>2)) + x].green =
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
337 (image->image_buffer[(y * (image->pitch>>2)) + x].green + color.green) >> 1;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
338 image->image_buffer[(y * (image->pitch>>2)) + x].blue =
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
339 (image->image_buffer[(y * (image->pitch>>2)) + x].blue + color.blue) >> 1;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
340 break;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
341 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
342 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
343
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
344 /**
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
345 * pn_image_render_pixel_by_offset
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
346 * @image: a #PnImage
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
347 * @offset: the pixel offset (0 being the top left) NOTE: Use (pitch>>2) rather
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
348 * than width
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
349 * @color: the color
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
350 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
351 * Renders a pixel to the image buffer of a #PnImage based on a pixel offset rather than
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
352 * rectangular coordinates. This function should be used if there is a more optimum way
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
353 * to calculate the offset than multiplying at every pixel. pn_image_set_render_mode()
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
354 * can be used to set the blend mode that is used by this function.
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
355 */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
356 void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
357 pn_image_render_pixel_by_offset (PnImage *image, guint offset, PnColor color)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
358 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
359 g_return_if_fail (image != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
360 g_return_if_fail (PN_IS_IMAGE (image));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
361 g_return_if_fail (image->image_buffer != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
362
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
363 if (offset > (image->pitch>>2) * image->height)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
364 return;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
365
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
366 switch (image->render_mode)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
367 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
368 case PN_BLEND_MODE_LAST: break;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
369 case PN_BLEND_MODE_IGNORE:
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
370 break;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
371
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
372 case PN_BLEND_MODE_REPLACE:
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
373 image->image_buffer[offset] = color;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
374 break;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
375
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
376 case PN_BLEND_MODE_5050:
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
377 image->image_buffer[offset].red =
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
378 (image->image_buffer[offset].red + color.red) >> 1;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
379 image->image_buffer[offset].green =
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
380 (image->image_buffer[offset].green + color.green) >> 1;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
381 image->image_buffer[offset].blue =
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
382 (image->image_buffer[offset].blue + color.blue) >> 1;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
383 break;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
384 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
385 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
386
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
387 /* FIXME: Add clipping to this */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
388 /**
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
389 * pn_image_render_line
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
390 * @image: a #PnImage
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
391 * @x0: the x coordinate of the first point
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
392 * @y0: the y coordinate of the first point
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
393 * @x1: the x coordinate of the second point
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
394 * @y1: the y coordinate of the second point
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
395 * @color: the color
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
396 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
397 * Renders a line from (x0,y0) to (x1,y1) to the image buffer of a #PnImage.
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
398 * Currently ***NO CLIPPING IS CURRENTLY DONE!!!***
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
399 */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
400 void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
401 pn_image_render_line (PnImage *image, guint _x0, guint _y0, guint _x1, guint _y1, PnColor color)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
402 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
403 gint x0 = _x0;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
404 gint y0 = _y0;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
405 gint x1 = _x1;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
406 gint y1 = _y1;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
407
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
408 gint dy = y1 - y0;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
409 gint dx = x1 - x0;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
410 gint stepx, stepy;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
411 gint fraction;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
412
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
413 g_return_if_fail (image != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
414 g_return_if_fail (PN_IS_IMAGE (image));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
415 g_return_if_fail (image->image_buffer != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
416
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
417 if (dy < 0)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
418 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
419 dy = -dy;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
420 stepy = -(image->pitch>>2);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
421 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
422 else
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
423 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
424 stepy = image->pitch>>2;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
425 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
426 if (dx < 0)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
427 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
428 dx = -dx;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
429 stepx = -1;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
430 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
431 else
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
432 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
433 stepx = 1;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
434 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
435 dy <<= 1;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
436 dx <<= 1;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
437
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
438 y0 *= image->pitch>>2;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
439 y1 *= image->pitch>>2;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
440 pn_image_render_pixel_by_offset(image, x0+y0, color);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
441 if (dx > dy)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
442 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
443 fraction = dy - (dx >> 1);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
444 while (x0 != x1)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
445 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
446 if (fraction >= 0)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
447 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
448 y0 += stepy;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
449 fraction -= dx;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
450 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
451 x0 += stepx;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
452 fraction += dy;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
453 pn_image_render_pixel_by_offset (image, x0+y0, color);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
454 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
455 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
456 else
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
457 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
458 fraction = dx - (dy >> 1);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
459 while (y0 != y1)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
460 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
461 if (fraction >= 0)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
462 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
463 x0 += stepx;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
464 fraction -= dy;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
465 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
466 y0 += stepy;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
467 fraction += dx;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
468 pn_image_render_pixel_by_offset (image, x0+y0, color);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
469 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
470 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
471 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
472
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
473 static void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
474 pn_image_bufcopy_5050 (PnColor *dest, PnColor *src, guint bufsize)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
475 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
476 register guint i;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
477 register PnColor *d, *s;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
478
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
479 d = dest;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
480 s = src;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
481
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
482 for (i=0; i<bufsize; i++)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
483 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
484 d->red = (s->red + d->red) >> 1;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
485 d->green = (s->green + d->green) >> 1;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
486 d->blue = (s->blue + d->blue) >> 1;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
487 d++;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
488 s++;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
489 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
490 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
491
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
492 #ifdef PN_USE_MMX
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
493 static void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
494 pn_image_bufcopy_5050_mmx (PnColor *dest, PnColor *src, guint bufsize)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
495 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
496 __asm__ __volatile__ (
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
497 "pxor %%mm7,%%mm7\n\t" /* zero mm7 */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
498
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
499 "10:\n\t" /* The start of the loop */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
500
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
501 "movq (%0),%%mm0\n\t" /* Read the pixels */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
502 "movq (%1),%%mm2\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
503 "movq %%mm0,%%mm1\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
504 "movq %%mm2,%%mm3\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
505
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
506 "punpcklbw %%mm7,%%mm0\n\t" /* Unpack the pixels */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
507 "punpckhbw %%mm7,%%mm1\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
508 "punpcklbw %%mm7,%%mm2\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
509 "punpckhbw %%mm7,%%mm3\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
510
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
511 "paddw %%mm2,%%mm0\n\t" /* Add the pixels */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
512 "paddw %%mm3,%%mm1\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
513
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
514 "psrlw $1,%%mm0\n\t" /* Divide the pixels by 2 */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
515 "psrlw $1,%%mm1\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
516
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
517 "packuswb %%mm1,%%mm0\n\t" /* Pack it up & write it */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
518 "movq %%mm0,(%0)\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
519
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
520 "addl $8,%0\n\t" /* Advance the pointers */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
521 "addl $8,%1\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
522
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
523 "decl %2\n\t" /* See if we're done */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
524 "jnz 10b\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
525
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
526 "emms"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
527 : /* no outputs */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
528 : "r" (dest), "r" (src), "r" (bufsize >> 1)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
529 );
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
530 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
531
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
532 /* FIXME: Should this be in a separate #define PN_USE_MMXEXT ? */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
533 static void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
534 pn_image_bufcopy_5050_mmxext (PnColor *dest, PnColor *src, guint bufsize)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
535 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
536
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
537
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
538 __asm__ __volatile__ (
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
539 "10:\n\t" /* The non-unrolled loop */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
540
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
541 "decl %2\n\t" /* See if we're done */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
542 "js 20f\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
543
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
544 "movq (%0),%%mm0\n\t" /* Read the pixels */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
545 "movq (%1),%%mm1\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
546 "pavgb %%mm1,%%mm0\n\t" /* Average the pixels */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
547
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
548 "movq %%mm0,(%0)\n\t" /* Write the pixels */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
549
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
550 "addl $8,%0\n\t" /* Advance the pointers */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
551 "addl $8,%1\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
552
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
553 "20:\n\t" /* The unrolled loop */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
554
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
555 "decl %3\n\t" /* See if we're done */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
556 "js 30f\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
557
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
558 /* First 2 pixels */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
559 "movq (%0),%%mm0\n\t" /* Read the pixels */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
560 "movq (%1),%%mm1\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
561 "pavgb %%mm1,%%mm0\n\t" /* Average the pixels */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
562
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
563 /* Second 2 pixels */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
564 "movq 8(%0),%%mm2\n\t" /* Read the pixels */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
565 "movq 8(%1),%%mm3\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
566 "pavgb %%mm3,%%mm2\n\t" /* Average the pixels */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
567
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
568 /* Third 2 pixels */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
569 "movq 16(%0),%%mm4\n\t" /* Read the pixels */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
570 "movq 16(%1),%%mm5\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
571 "pavgb %%mm5,%%mm4\n\t" /* Average the pixels */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
572
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
573 /* Fourth 2 pixels */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
574 "movq 24(%0),%%mm6\n\t" /* Read the pixels */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
575 "movq 24(%1),%%mm7\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
576 "pavgb %%mm7,%%mm6\n\t" /* Average the pixels */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
577
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
578 /* Write them all */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
579 "movq %%mm0,(%0)\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
580 "movq %%mm2,8(%0)\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
581 "movq %%mm4,16(%0)\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
582 "movq %%mm6,24(%0)\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
583
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
584 "addl $32,%0\n\t" /* Advance the pointers */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
585 "addl $32,%1\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
586
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
587 "jmp 20b\n\t" /* And again */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
588
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
589 "30:\n\t"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
590
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
591 "emms"
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
592 : /* no outputs */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
593 : "r" (dest), "r" (src), "r" ((bufsize >> 1) & 0x3), "r" (bufsize >> 3)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
594 );
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
595 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
596
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
597 #endif /* PN_USE_MMX */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
598
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
599 /**
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
600 * pn_image_apply_transform
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
601 * @image: a #PnImage
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
602 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
603 * Renders the transform buffer onto the image buffer.
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
604 * pn_image_set_transform_mode() may be used to set the blend mode that is
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
605 * used by this function.
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
606 */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
607 void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
608 pn_image_apply_transform (PnImage *image)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
609 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
610 g_return_if_fail (image != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
611 g_return_if_fail (PN_IS_IMAGE (image));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
612
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
613 switch (image->transform_mode)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
614 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
615 case PN_BLEND_MODE_LAST:
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
616 case PN_BLEND_MODE_IGNORE:
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
617 return;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
618
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
619 case PN_BLEND_MODE_REPLACE:
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
620 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
621 PnColor *tmp = image->image_buffer;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
622 image->image_buffer = image->transform_buffer;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
623 image->transform_buffer = tmp;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
624 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
625 break;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
626
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
627 case PN_BLEND_MODE_5050:
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
628 #ifdef PN_USE_MMX
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
629 if (pn_cpu_get_caps () & PN_CPU_CAP_MMXEXT)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
630 pn_image_bufcopy_5050_mmxext (image->image_buffer, image->transform_buffer,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
631 image->height * (image->pitch >> 2));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
632 else if (pn_cpu_get_caps () & PN_CPU_CAP_MMX)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
633 pn_image_bufcopy_5050_mmx (image->image_buffer, image->transform_buffer,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
634 image->height * (image->pitch >> 2));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
635 else
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
636 #endif /* PN_USE_MMX */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
637 pn_image_bufcopy_5050 (image->image_buffer, image->transform_buffer,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
638 image->height * (image->pitch >> 2));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
639 break;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
640 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
641 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
642
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
643 /**
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
644 * pn_image_render_image
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
645 * @image: a #PnImage
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
646 * @src: the source image
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
647 * @blend_mode: the blend mode to use
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
648 *
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
649 * Renders the image buffer of @src onto the image buffer of an image.
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
650 */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
651 void
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
652 pn_image_render_image (PnImage *image, PnImage *src, PnBlendMode blend_mode)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
653 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
654 g_return_if_fail (image != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
655 g_return_if_fail (PN_IS_IMAGE (image));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
656 g_return_if_fail (src != NULL);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
657 g_return_if_fail (PN_IS_IMAGE (src));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
658 g_return_if_fail (blend_mode < PN_BLEND_MODE_LAST);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
659 g_return_if_fail (image->width == src->width);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
660 g_return_if_fail (image->height == src->height);
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
661
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
662 switch (blend_mode)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
663 {
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
664 case PN_BLEND_MODE_LAST:
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
665 case PN_BLEND_MODE_IGNORE:
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
666 return;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
667
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
668 case PN_BLEND_MODE_REPLACE:
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
669 memcpy (image->image_buffer, src->image_buffer, image->height * (image->pitch >> 2) * sizeof (PnColor));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
670 break;
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
671
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
672 case PN_BLEND_MODE_5050:
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
673 #ifdef PN_USE_MMX
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
674 if (pn_cpu_get_caps () & PN_CPU_CAP_MMXEXT)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
675 pn_image_bufcopy_5050_mmxext (image->image_buffer, src->image_buffer,
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
676 image->height * (image->pitch >> 2));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
677 else if (pn_cpu_get_caps () & PN_CPU_CAP_MMX)
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
678 pn_image_bufcopy_5050_mmx (image->image_buffer, src->image_buffer, image->height * (image->pitch >> 2));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
679 else
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
680 #endif /* PN_USE_MMX */
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
681 pn_image_bufcopy_5050 (image->image_buffer, src->image_buffer, image->height * (image->pitch >> 2));
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
682 }
0c5fdcf3f947 [svn] - incomplete stuff
nenolod
parents:
diff changeset
683 }