@@ -73,35 +73,37 @@ pub fn drawLine(comptime T: type, image: Image(T), p1: Point2d, p2: Point2d, wid
73
73
const y = @floor (dy );
74
74
const x = @floor (dx );
75
75
if (y >= 0 and y <= rows - 1 ) {
76
- c2 .a = @intFromFloat ((1 - (dy - y )) * max_alpha );
77
76
var j = - half_width ;
78
77
while (j <= half_width ) : (j += 1 ) {
79
78
const py = y + j ;
80
79
const pos = as (usize , py ) * image .cols + as (usize , x );
81
80
if (py >= 0 and py < rows ) {
81
+ var c1 : Rgba = Color .convert (Rgba , image .data [pos ]);
82
82
if (j == - half_width or j == half_width ) {
83
- var c1 : Rgba = Color . convert ( Rgba , image . data [ pos ] );
83
+ c2 . a = @intFromFloat (( 1 - ( dy - y )) * max_alpha );
84
84
c1 .blend (c2 );
85
85
image .data [pos ] = Color .convert (T , c1 );
86
86
} else {
87
- image .data [pos ] = color ;
87
+ c1 .blend (c2 );
88
+ image .data [pos ] = Color .convert (T , c1 );
88
89
}
89
90
}
90
91
}
91
92
}
92
93
if (y + 1 >= 0 and y + 1 <= rows - 1 ) {
93
- c2 .a = @intFromFloat ((dy - y ) * max_alpha );
94
94
var j = - half_width ;
95
95
while (j <= half_width ) : (j += 1 ) {
96
96
const py = y + 1 + j ;
97
97
if (py >= 0 and py < rows ) {
98
98
const pos = as (usize , py ) * image .cols + as (usize , x );
99
+ var c1 : Rgba = Color .convert (Rgba , image .data [pos ]);
99
100
if (j == - half_width or j == half_width ) {
100
- var c1 : Rgba = Color . convert ( Rgba , image . data [ pos ] );
101
+ c2 . a = @intFromFloat (( dy - y ) * max_alpha );
101
102
c1 .blend (c2 );
102
103
image .data [pos ] = Color .convert (T , c1 );
103
104
} else {
104
- image .data [pos ] = color ;
105
+ c1 .blend (c2 );
106
+ image .data [pos ] = Color .convert (T , c1 );
105
107
}
106
108
}
107
109
}
@@ -118,18 +120,19 @@ pub fn drawLine(comptime T: type, image: Image(T), p1: Point2d, p2: Point2d, wid
118
120
const y = @floor (dy );
119
121
const x = @floor (dx );
120
122
if (x >= 0 and x <= cols - 1 ) {
121
- c2 .a = @intFromFloat ((1 - (dx - x )) * max_alpha );
122
123
var j = - half_width ;
123
124
while (j <= half_width ) : (j += 1 ) {
124
125
const px = x + j ;
125
126
const pos = as (usize , y ) * image .cols + as (usize , px );
126
127
if (px >= 0 and px < cols ) {
128
+ var c1 : Rgba = Color .convert (Rgba , image .data [pos ]);
127
129
if (j == - half_width or j == half_width ) {
128
- var c1 : Rgba = Color . convert ( Rgba , image . data [ pos ] );
130
+ c2 . a = @intFromFloat (( 1 - ( dx - x )) * max_alpha );
129
131
c1 .blend (c2 );
130
132
image .data [pos ] = Color .convert (T , c1 );
131
133
} else {
132
- image .data [pos ] = color ;
134
+ c1 .blend (c2 );
135
+ image .data [pos ] = Color .convert (T , c1 );
133
136
}
134
137
}
135
138
}
@@ -141,12 +144,13 @@ pub fn drawLine(comptime T: type, image: Image(T), p1: Point2d, p2: Point2d, wid
141
144
const px = x + 1 + j ;
142
145
const pos = as (usize , y ) * image .cols + as (usize , px );
143
146
if (px >= 0 and px < cols ) {
147
+ var c1 : Rgba = Color .convert (Rgba , image .data [pos ]);
144
148
if (j == - half_width or j == half_width ) {
145
- var c1 : Rgba = Color .convert (Rgba , image .data [pos ]);
146
149
c1 .blend (c2 );
147
150
image .data [pos ] = Color .convert (T , c1 );
148
151
} else {
149
- image .data [pos ] = color ;
152
+ c1 .blend (c2 );
153
+ image .data [pos ] = Color .convert (T , c1 );
150
154
}
151
155
}
152
156
}
0 commit comments