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