... |
... |
@@ -83,36 +83,22 @@ swap( long int* a, long int* b ) |
83
|
83
|
void
|
84
|
84
|
dense_render_line( dense_worker* worker, TPos tox, TPos toy )
|
85
|
85
|
{
|
86
|
|
- // printf("line from: %d, %d to %d, %d\n", worker->prev_x, worker->prev_y,
|
87
|
|
- // to_x, to_y);
|
88
|
|
-
|
89
|
86
|
|
90
|
87
|
FT26D6 fx = worker->prev_x>>2;
|
91
|
88
|
FT26D6 fy = worker->prev_y>>2;
|
92
|
|
-
|
93
|
|
-
|
94
|
|
- // float from_x = fx;
|
95
|
|
- // float from_y = fy;
|
96
|
89
|
|
97
|
90
|
FT26D6 from_x = fx;
|
98
|
91
|
FT26D6 from_y = fy;
|
99
|
92
|
|
100
|
|
-
|
101
|
|
- // from_x /= 64.0;
|
102
|
|
- // from_y /= 64.0;
|
103
|
|
-
|
104
|
93
|
FT26D6 tx = tox>>2;
|
105
|
94
|
FT26D6 ty = toy>>2;
|
106
|
95
|
|
107
|
|
- if ( fy == ty )
|
108
|
|
- return;
|
109
|
|
-
|
110
|
|
- // float to_x = tx / 64.0;
|
111
|
|
- // float to_y = ty / 64.0;
|
112
|
96
|
FT26D6 to_x = tx;
|
113
|
97
|
FT26D6 to_y = ty;
|
114
|
98
|
|
115
|
|
-
|
|
99
|
+ // from_x/y and to_x/y are coordinates in 26.6 format
|
|
100
|
+ if ( from_y == to_y )
|
|
101
|
+ return;
|
116
|
102
|
|
117
|
103
|
//printf("line from: %f, %f to %f, %f\n", from_x, from_y, to_x, to_y);
|
118
|
104
|
|
... |
... |
@@ -128,7 +114,7 @@ dense_render_line( dense_worker* worker, TPos tox, TPos toy ) |
128
|
114
|
if ( from_y >= worker->m_h<<6 || to_y <= 0 )
|
129
|
115
|
return;
|
130
|
116
|
|
131
|
|
- //float dxdy = ( to_x - from_x ) / (float)( to_y - from_y );
|
|
117
|
+
|
132
|
118
|
FT26D6 deltax,deltay;
|
133
|
119
|
deltax = to_x - from_x;
|
134
|
120
|
deltay = to_y - from_y;
|
... |
... |
@@ -139,26 +125,38 @@ dense_render_line( dense_worker* worker, TPos tox, TPos toy ) |
139
|
125
|
from_y = 0;
|
140
|
126
|
}
|
141
|
127
|
|
142
|
|
- // TODO: test, imp line
|
|
128
|
+ // This condition is important apparently
|
143
|
129
|
if ( to_y > worker->m_h<<6 )
|
144
|
130
|
{
|
145
|
131
|
to_x -= (( to_y - worker->m_h<<6 ) * deltax/deltay);
|
146
|
132
|
to_y = worker->m_h<<6;
|
147
|
133
|
}
|
148
|
134
|
|
149
|
|
- int x = from_x;
|
|
135
|
+
|
|
136
|
+ FT26D6 x = from_x;
|
|
137
|
+
|
|
138
|
+ // y-coordinate of first pixel of line
|
150
|
139
|
int y0 = from_y>>6;
|
|
140
|
+
|
|
141
|
+ // y-coordinate of last pixel of line
|
151
|
142
|
int y_limit = (to_y + 0x3f)>>6;
|
152
|
|
- FT20D12* m_a = worker->m_a;
|
|
143
|
+ FT20D12* m_a = worker->m_a;
|
153
|
144
|
|
154
|
145
|
for ( int y = y0; y < y_limit; y++ )
|
155
|
146
|
{
|
156
|
|
- // printf("y is %d\n", y);
|
157
|
147
|
int linestart = y * worker->m_w;
|
|
148
|
+
|
|
149
|
+ // dy is the height of the line present in the current scanline
|
158
|
150
|
FT26D6 dy = min( (y + 1)<<6, to_y ) - max( y<<6, from_y );
|
|
151
|
+
|
|
152
|
+ // x coordinate where the line leaves the current scanline
|
159
|
153
|
FT26D6 xnext = x + dy * deltax/deltay;
|
|
154
|
+
|
|
155
|
+ // height with sign
|
160
|
156
|
FT26D6 d = dy * dir;
|
161
|
157
|
|
|
158
|
+ // x0 is the x coordinate of the start of line in current scanline
|
|
159
|
+ // x1 is the x coordinate of the end of line in current scanline
|
162
|
160
|
FT26D6 x0, x1;
|
163
|
161
|
if ( x < xnext )
|
164
|
162
|
{
|
... |
... |
@@ -171,48 +169,43 @@ dense_render_line( dense_worker* worker, TPos tox, TPos toy ) |
171
|
169
|
x1 = x;
|
172
|
170
|
}
|
173
|
171
|
|
174
|
|
- /*
|
175
|
|
- It's possible for x0 to be negative on the last scanline because of
|
176
|
|
- floating-point inaccuracy That would cause an out-of-bounds array access at
|
177
|
|
- index -1.
|
178
|
|
- */
|
179
|
|
- // float x0floor = x0 <= 0.0f ? 0.0f : (float)floor( x0 );
|
180
|
|
-
|
|
172
|
+ // x coordinate of the leftmost intersected pixel in the scanline
|
181
|
173
|
int x0i = x0>>6;
|
182
|
174
|
FT26D6 x0floor = x0i<<6;
|
183
|
175
|
|
184
|
176
|
|
185
|
177
|
// float x1ceil = (float)ceil( x1 );
|
|
178
|
+ // x coordinate of the rightmost intersected pixel in the scanline
|
186
|
179
|
int x1i = (x1+0x3f)>>6;
|
187
|
180
|
FT26D6 x1ceil = x1i <<6;
|
188
|
181
|
|
189
|
182
|
if ( x1i <= x0i + 1 )
|
190
|
183
|
{
|
|
184
|
+ // average of x coordinates of trapezium with origin at left of pixel
|
191
|
185
|
FT26D6 xmf = ( ( x + xnext )>>1) - x0floor;
|
|
186
|
+
|
|
187
|
+ // average of x coordinates of trapezium with origin at right of pixel
|
192
|
188
|
m_a[linestart + x0i] += d * ((1<<6) - xmf);
|
193
|
189
|
m_a[linestart + ( x0i + 1 )] += d * xmf;
|
194
|
190
|
}
|
195
|
191
|
else
|
196
|
192
|
{
|
197
|
|
- // float s = 1.0f / ( x1 - x0 );
|
198
|
|
- // float x0f = x0 - x0floor;
|
199
|
|
- // float a0 = 0.5f * s * ( 1.0f - x0f ) * ( 1.0f - x0f );
|
200
|
|
- // float x1f = x1 - x1ceil + 1.0f;
|
201
|
|
- // float am = 0.5f * s * x1f * x1f;
|
202
|
193
|
|
|
194
|
+ // total horizontal length of line in current scanline, might be replaced by deltax
|
203
|
195
|
FT26D6 oneOverS = x1 - x0;
|
204
|
196
|
FT26D6 x0f = x0 - x0floor;
|
205
|
197
|
|
206
|
|
-
|
|
198
|
+ // 64 - x0f is the horizontal length of line in first pixel
|
207
|
199
|
FT26D6 oneMinusX0f = (1<<6) - x0f;
|
|
200
|
+
|
|
201
|
+ // Stores area of triangle in first pixel divided by d
|
208
|
202
|
FT26D6 a0 = ((oneMinusX0f * oneMinusX0f) >> 1) / oneOverS;
|
|
203
|
+
|
|
204
|
+ // x1f is the horizontal length in the last pixel
|
209
|
205
|
FT26D6 x1f = x1 - x1ceil + (1<<6);
|
210
|
206
|
FT26D6 am = ((x1f * x1f) >> 1) / oneOverS;
|
211
|
207
|
|
212
|
|
- // printf("x0 is %lld, x1 is %lld\n",x0,x1 );
|
213
|
|
-
|
214
|
|
-
|
215
|
|
-
|
|
208
|
+ // d * a0 is area of triangle in first pixel
|
216
|
209
|
m_a[linestart + x0i] += d * a0;
|
217
|
210
|
|
218
|
211
|
if ( x1i == x0i + 2 )
|
... |
... |
@@ -224,12 +217,15 @@ dense_render_line( dense_worker* worker, TPos tox, TPos toy ) |
224
|
217
|
|
225
|
218
|
FT26D6 dTimesS = (d << 12) / oneOverS;
|
226
|
219
|
|
227
|
|
- for ( FT26D6 xi = x0i + 2; xi < x1i - 1; xi++ )
|
|
220
|
+ for ( FT26D6 xi = x0i + 2; xi < x1i - 1; xi++ ){
|
|
221
|
+ // Increase area for successive pixels by dy/dx
|
228
|
222
|
m_a[linestart + xi] += dTimesS;
|
|
223
|
+ }
|
229
|
224
|
|
230
|
225
|
FT26D6 a2 = a1 + (( x1i - x0i - 3 )<<12)/oneOverS;
|
231
|
226
|
m_a[linestart + ( x1i - 1 )] += d * ( (1<<6) - a2 - am );
|
232
|
227
|
}
|
|
228
|
+ // Area in last pixel of scanline
|
233
|
229
|
m_a[linestart + x1i] += d * am;
|
234
|
230
|
}
|
235
|
231
|
x = xnext;
|
... |
... |
@@ -459,22 +455,6 @@ dense_render_glyph( dense_worker* worker, const FT_Bitmap* target ) |
459
|
455
|
dest++;
|
460
|
456
|
}
|
461
|
457
|
|
462
|
|
- // float value = 0.0f;
|
463
|
|
- // while ( dest < dest_end )
|
464
|
|
- // {
|
465
|
|
- // value += *source++;
|
466
|
|
- // if ( value > 0.0f )
|
467
|
|
- // {
|
468
|
|
- // int n = (int)( fabs( value ) * 255.0f + 0.5f );
|
469
|
|
- // if ( n > 255 )
|
470
|
|
- // n = 255;
|
471
|
|
- // *dest = (unsigned char)n;
|
472
|
|
- // }
|
473
|
|
- // else
|
474
|
|
- // *dest = 0;
|
475
|
|
- // dest++;
|
476
|
|
- // }
|
477
|
|
-
|
478
|
458
|
free(worker->m_a);
|
479
|
459
|
return error;
|
480
|
460
|
}
|