~centralelyon2010/inkscape/imagelinks2

« back to all changes in this revision

Viewing changes to src/libnr/nr-pixblock-line.cpp

  • Committer: mental
  • Date: 2006-01-16 02:36:01 UTC
  • Revision ID: mental@users.sourceforge.net-20060116023601-wkr0h7edl5veyudq
moving trunk for module inkscape

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#define __NR_PIXBLOCK_LINE_C__
 
2
 
 
3
/*
 
4
 * Pixel buffer rendering library
 
5
 *
 
6
 * Authors:
 
7
 *   Lauris Kaplinski <lauris@kaplinski.com>
 
8
 *
 
9
 * This code is in public domain
 
10
 */
 
11
 
 
12
#include <libnr/nr-pixops.h>
 
13
#include <libnr/nr-pixblock-pixel.h>
 
14
 
 
15
void
 
16
nr_pixblock_draw_line_rgba32 (NRPixBlock *d, long x0, long y0, long x1, long y1, short first, unsigned long rgba)
 
17
{
 
18
        long deltax, deltay, xinc1, xinc2, yinc1, yinc2;
 
19
        long den, num, numadd, numpixels;
 
20
        long x, y, curpixel;
 
21
        /* Pixblock */
 
22
        int dbpp;
 
23
        NRPixBlock spb;
 
24
        unsigned char *spx;
 
25
 
 
26
        if (x1 >= x0) {
 
27
                deltax = x1 - x0;
 
28
                xinc1 = 1;
 
29
                xinc2 = 1;
 
30
        } else {
 
31
                deltax = x0 - x1;
 
32
                xinc1 = -1;
 
33
                xinc2 = -1;
 
34
        }
 
35
 
 
36
        if (y1 >= y0) {
 
37
                deltay = y1 - y0;
 
38
                yinc1 = 1;
 
39
                yinc2 = 1;
 
40
        } else {
 
41
                deltay = y0 - y1;
 
42
                yinc1 = -1;
 
43
                yinc2 = -1;
 
44
        }
 
45
 
 
46
        if (deltax >= deltay) {
 
47
                xinc1 = 0;
 
48
                yinc2 = 0;
 
49
                den = deltax;
 
50
                num = deltax / 2;
 
51
                numadd = deltay;
 
52
                numpixels = deltax;
 
53
        } else {
 
54
                xinc2 = 0;
 
55
                yinc1 = 0;
 
56
                den = deltay;
 
57
                num = deltay / 2;
 
58
                numadd = deltax;
 
59
                numpixels = deltay;
 
60
        }
 
61
 
 
62
        /* We can be quite sure 1x1 pixblock is TINY */
 
63
        nr_pixblock_setup_fast (&spb, NR_PIXBLOCK_MODE_R8G8B8A8N, 0, 0, 1, 1, 0);
 
64
        spb.empty = 0;
 
65
        spx = NR_PIXBLOCK_PX (&spb);
 
66
        spx[0] = NR_RGBA32_R (rgba);
 
67
        spx[1] = NR_RGBA32_G (rgba);
 
68
        spx[2] = NR_RGBA32_B (rgba);
 
69
        spx[3] = NR_RGBA32_A (rgba);
 
70
 
 
71
        dbpp = NR_PIXBLOCK_BPP (d);
 
72
 
 
73
        x = x0;
 
74
        y = y0;
 
75
 
 
76
        for (curpixel = 0; curpixel <= numpixels; curpixel++) {
 
77
                if ((x >= d->area.x0) && (y >= d->area.y0) && (x < d->area.x1) && (y < d->area.y1)) {
 
78
                        nr_compose_pixblock_pixblock_pixel (d, NR_PIXBLOCK_PX (d) + (y - d->area.y0) * d->rs + (x - d->area.x0) * dbpp, &spb, spx);
 
79
                }
 
80
                num += numadd;
 
81
                if (num >= den) {
 
82
                        num -= den;
 
83
                        x += xinc1;
 
84
                        y += yinc1;
 
85
                }
 
86
                x += xinc2;
 
87
                y += yinc2;
 
88
        }
 
89
 
 
90
        nr_pixblock_release (&spb);
 
91
}
 
92