Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void ICODE_ATTR draw_antialiased_line(int x0, int y0, int x1, int y1)
- {
- /* fixed-point Wu's algorithm, modified for integer-only endpoints */
- /* passed to plot() to avoid re-calculation */
- unsigned short l = 0, r = LCD_WIDTH, u = 0, d = LCD_HEIGHT;
- if(clipped)
- {
- l = clip_rect.x;
- r = clip_rect.x + clip_rect.width;
- u = clip_rect.y;
- d = clip_rect.y + clip_rect.height;
- }
- bool steep = ABS(y1 - y0) > ABS(x1 - x0);
- int tmp;
- if(steep)
- {
- SWAP(x0, y0, tmp);
- SWAP(x1, y1, tmp);
- }
- if(x0 > x1)
- {
- SWAP(x0, x1, tmp);
- SWAP(y0, y1, tmp);
- }
- int dx, dy;
- dx = x1 - x0;
- dy = y1 - y0;
- if(!(dx << FRACBITS))
- return; /* bail out */
- long gradient = fp_div(dy << FRACBITS, dx << FRACBITS, FRACBITS);
- long intery = (y0 << FRACBITS);
- unsigned color = rb->lcd_get_foreground();
- unsigned long r1, g1, b1;
- r1 = RGB_UNPACK_RED(color);
- g1 = RGB_UNPACK_GREEN(color);
- b1 = RGB_UNPACK_BLUE(color);
- /* main loop */
- if(steep)
- {
- for(int x = x0; x <= x1; ++x, intery += gradient)
- {
- unsigned y = intery >> FRACBITS;
- unsigned alpha = fp_fpart(intery, FRACBITS) >> (FRACBITS - 8);
- plot(y, x, (1 << 8) - alpha, r1, g1, b1, l, r, u, d);
- plot(y + 1, x, alpha, r1, g1, b1, l, r, u, d);
- }
- }
- else
- {
- for(int x = x0; x <= x1; ++x, intery += gradient)
- {
- unsigned y = intery >> FRACBITS;
- unsigned alpha = fp_fpart(intery, FRACBITS) >> (FRACBITS - 8);
- plot(x, y, (1 << 8) - alpha, r1, g1, b1, l, r, u, d);
- plot(x, y + 1, alpha, r1, g1, b1, l, r, u, d);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement