~ubuntu-branches/ubuntu/vivid/freerdp/vivid

« back to all changes in this revision

Viewing changes to libfreerdp/gdi/include/line.c

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2014-11-11 12:20:50 UTC
  • mfrom: (1.2.5)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20141111122050-7z628f4ab38qxad5
Tags: upstream-1.1.0~git20140921.1.440916e+dfsg1
ImportĀ upstreamĀ versionĀ 1.1.0~git20140921.1.440916e+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * FreeRDP: A Remote Desktop Protocol Implementation
 
3
 * GDI LineTo
 
4
 *
 
5
 * Copyright 2010-2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
 
6
 *
 
7
 * Licensed under the Apache License, Version 2.0 (the "License");
 
8
 * you may not use this file except in compliance with the License.
 
9
 * You may obtain a copy of the License at
 
10
 *
 
11
 *     http://www.apache.org/licenses/LICENSE-2.0
 
12
 *
 
13
 * Unless required by applicable law or agreed to in writing, software
 
14
 * distributed under the License is distributed on an "AS IS" BASIS,
 
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
16
 * See the License for the specific language governing permissions and
 
17
 * limitations under the License.
 
18
 */
 
19
 
 
20
/* do not include this file directly! */
 
21
 
 
22
int LINE_TO(HGDI_DC hdc, int nXEnd, int nYEnd)
 
23
{
 
24
        int x, y;
 
25
        int x1, y1;
 
26
        int x2, y2;
 
27
        int e, e2;
 
28
        int dx, dy;
 
29
        int sx, sy;
 
30
        int bx1, by1;
 
31
        int bx2, by2;
 
32
        PIXEL_TYPE pen;
 
33
        PIXEL_TYPE* pixel;
 
34
        HGDI_BITMAP bmp;
 
35
 
 
36
        x1 = hdc->pen->posX;
 
37
        y1 = hdc->pen->posY;
 
38
        x2 = nXEnd;
 
39
        y2 = nYEnd;
 
40
 
 
41
        dx = (x1 > x2) ? x1 - x2 : x2 - x1;
 
42
        dy = (y1 > y2) ? y1 - y2 : y2 - y1;
 
43
 
 
44
        sx = (x1 < x2) ? 1 : -1;
 
45
        sy = (y1 < y2) ? 1 : -1;
 
46
 
 
47
        e = dx - dy;
 
48
 
 
49
        x = x1;
 
50
        y = y1;
 
51
 
 
52
        bmp = (HGDI_BITMAP) hdc->selectedObject;
 
53
 
 
54
        if (hdc->clip->null)
 
55
        {
 
56
                bx1 = (x1 < x2) ? x1 : x2;
 
57
                by1 = (y1 < y2) ? y1 : y2;
 
58
                bx2 = (x1 > x2) ? x1 : x2;
 
59
                by2 = (y1 > y2) ? y1 : y2;
 
60
        }
 
61
        else
 
62
        {
 
63
                bx1 = hdc->clip->x;
 
64
                by1 = hdc->clip->y;
 
65
                bx2 = bx1 + hdc->clip->w - 1;
 
66
                by2 = by1 + hdc->clip->h - 1;
 
67
        }
 
68
 
 
69
        bx1 = MAX(bx1, 0);
 
70
        by1 = MAX(by1, 0);
 
71
        bx2 = MIN(bx2, bmp->width - 1);
 
72
        by2 = MIN(by2, bmp->height - 1);
 
73
 
 
74
        pen = GDI_GET_PEN_COLOR(hdc->pen);
 
75
 
 
76
        while (1)
 
77
        {
 
78
                if (!(x == x2 && y == y2))
 
79
                {
 
80
                        if ((x >= bx1 && x <= bx2) && (y >= by1 && y <= by2))
 
81
                        {
 
82
                                pixel = GDI_GET_POINTER(bmp, x, y);
 
83
                                SET_PIXEL_ROP2(pixel, &pen);
 
84
                        }
 
85
                }
 
86
                else
 
87
                {
 
88
                        break;
 
89
                }
 
90
 
 
91
                e2 = 2 * e;
 
92
 
 
93
                if (e2 > -dy)
 
94
                {
 
95
                        e -= dy;
 
96
                        x += sx;
 
97
                }
 
98
 
 
99
                if (e2 < dx)
 
100
                {
 
101
                        e += dx;
 
102
                        y += sy;
 
103
                }
 
104
        }
 
105
 
 
106
        return 1;
 
107
}
 
108
 
 
109
/*
 
110
#undef LINE_TO
 
111
#undef PIXEL_TYPE
 
112
#undef SET_PIXEL_ROP2
 
113
#undef GDI_GET_POINTER
 
114
#undef GDI_GET_PEN_COLOR
 
115
*/