~centralelyon2010/inkscape/imagelinks2

« back to all changes in this revision

Viewing changes to src/display/nr-plain-stuff.cpp

  • Committer: JazzyNico
  • Date: 2011-08-29 20:25:30 UTC
  • Revision ID: nicoduf@yahoo.fr-20110829202530-6deuoz11q90usldv
Code refactoring and merging with trunk (revision 10599).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#define __NR_PLAIN_STUFF_C__
2
 
 
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
 
 */
13
 
 
14
 
#include <glib/gmessages.h>
15
 
#include <libnr/nr-pixops.h>
16
 
#include "nr-plain-stuff.h"
17
 
 
18
 
#define NR_DEFAULT_CHECKERSIZEP2 2
19
 
#define NR_DEFAULT_CHECKERCOLOR0 0xbfbfbfff
20
 
#define NR_DEFAULT_CHECKERCOLOR1 0x808080ff
21
 
 
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);
26
 
 
27
 
        nr_render_checkerboard_rgb_custom (px, w, h, rs, xoff, yoff, NR_DEFAULT_CHECKERCOLOR0, NR_DEFAULT_CHECKERCOLOR1, NR_DEFAULT_CHECKERSIZEP2);
28
 
}
29
 
 
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;
36
 
 
37
 
        g_return_if_fail (px != NULL);
38
 
        g_return_if_fail (sizep2 >= 0);
39
 
        g_return_if_fail (sizep2 <= 8);
40
 
 
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);
50
 
 
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
 
}
68
 
 
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;
74
 
 
75
 
        g_return_if_fail (px != NULL);
76
 
 
77
 
        r = NR_RGBA32_R (c);
78
 
        g = NR_RGBA32_G (c);
79
 
        b = NR_RGBA32_B (c);
80
 
        a = NR_RGBA32_A (c);
81
 
 
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;
86
 
 
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;
91
 
 
92
 
        nr_render_checkerboard_rgb_custom (px, w, h, rs, xoff, yoff, c0, c1, NR_DEFAULT_CHECKERSIZEP2);
93
 
}
94