1 #define __NR_PLAIN_STUFF_C__
3 /*
4 * Miscellaneous simple rendering utilities
5 *
6 * Author:
7 * Lauris Kaplinski <lauris@ximian.com>
8 *
9 * Copyright (C) 2001 Lauris Kaplinski and Ximian, Inc.
10 *
11 * Released under GNU GPL
12 */
14 #include <glib/gmessages.h>
15 #include <libnr/nr-pixops.h>
16 #include "nr-plain-stuff.h"
18 #define NR_DEFAULT_CHECKERSIZEP2 2
19 #define NR_DEFAULT_CHECKERCOLOR0 0xbfbfbfff
20 #define NR_DEFAULT_CHECKERCOLOR1 0x808080ff
22 void
23 nr_render_checkerboard_rgb (guchar *px, gint w, gint h, gint rs, gint xoff, gint yoff)
24 {
25 g_return_if_fail (px != NULL);
27 nr_render_checkerboard_rgb_custom (px, w, h, rs, xoff, yoff, NR_DEFAULT_CHECKERCOLOR0, NR_DEFAULT_CHECKERCOLOR1, NR_DEFAULT_CHECKERSIZEP2);
28 }
30 void
31 nr_render_checkerboard_rgb_custom (guchar *px, gint w, gint h, gint rs, gint xoff, gint yoff, guint32 c0, guint32 c1, gint sizep2)
32 {
33 gint x, y, m;
34 guint r0, g0, b0;
35 guint r1, g1, b1;
37 g_return_if_fail (px != NULL);
38 g_return_if_fail (sizep2 >= 0);
39 g_return_if_fail (sizep2 <= 8);
41 xoff &= 0x1ff;
42 yoff &= 0x1ff;
43 m = 0x1 << sizep2;
44 r0 = NR_RGBA32_R (c0);
45 g0 = NR_RGBA32_G (c0);
46 b0 = NR_RGBA32_B (c0);
47 r1 = NR_RGBA32_R (c1);
48 g1 = NR_RGBA32_G (c1);
49 b1 = NR_RGBA32_B (c1);
51 for (y = 0; y < h; y++) {
52 guchar *p;
53 p = px;
54 for (x = 0; x < w; x++) {
55 if (((x + xoff) ^ (y + yoff)) & m) {
56 *p++ = r0;
57 *p++ = g0;
58 *p++ = b0;
59 } else {
60 *p++ = r1;
61 *p++ = g1;
62 *p++ = b1;
63 }
64 }
65 px += rs;
66 }
67 }
69 void
70 nr_render_rgba32_rgb (guchar *px, gint w, gint h, gint rs, gint xoff, gint yoff, guint32 c)
71 {
72 guint32 c0, c1;
73 gint a, r, g, b, cr, cg, cb;
75 g_return_if_fail (px != NULL);
77 r = NR_RGBA32_R (c);
78 g = NR_RGBA32_G (c);
79 b = NR_RGBA32_B (c);
80 a = NR_RGBA32_A (c);
82 cr = NR_COMPOSEN11_1111 (r, a, NR_RGBA32_R (NR_DEFAULT_CHECKERCOLOR0));
83 cg = NR_COMPOSEN11_1111 (g, a, NR_RGBA32_G (NR_DEFAULT_CHECKERCOLOR0));
84 cb = NR_COMPOSEN11_1111 (b, a, NR_RGBA32_B (NR_DEFAULT_CHECKERCOLOR0));
85 c0 = (cr << 24) | (cg << 16) | (cb << 8) | 0xff;
87 cr = NR_COMPOSEN11_1111 (r, a, NR_RGBA32_R (NR_DEFAULT_CHECKERCOLOR1));
88 cg = NR_COMPOSEN11_1111 (g, a, NR_RGBA32_G (NR_DEFAULT_CHECKERCOLOR1));
89 cb = NR_COMPOSEN11_1111 (b, a, NR_RGBA32_B (NR_DEFAULT_CHECKERCOLOR1));
90 c1 = (cr << 24) | (cg << 16) | (cb << 8) | 0xff;
92 nr_render_checkerboard_rgb_custom (px, w, h, rs, xoff, yoff, c0, c1, NR_DEFAULT_CHECKERSIZEP2);
93 }