Advertisement
Guest User

Untitled

a guest
Jan 12th, 2017
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. static void ICODE_ATTR draw_antialiased_line(int x0, int y0, int x1, int y1)
  2. {
  3. /* fixed-point Wu's algorithm, modified for integer-only endpoints */
  4.  
  5. /* passed to plot() to avoid re-calculation */
  6. unsigned short l = 0, r = LCD_WIDTH, u = 0, d = LCD_HEIGHT;
  7. if(clipped)
  8. {
  9. l = clip_rect.x;
  10. r = clip_rect.x + clip_rect.width;
  11. u = clip_rect.y;
  12. d = clip_rect.y + clip_rect.height;
  13. }
  14.  
  15. bool steep = ABS(y1 - y0) > ABS(x1 - x0);
  16. int tmp;
  17. if(steep)
  18. {
  19. SWAP(x0, y0, tmp);
  20. SWAP(x1, y1, tmp);
  21. }
  22. if(x0 > x1)
  23. {
  24. SWAP(x0, x1, tmp);
  25. SWAP(y0, y1, tmp);
  26. }
  27.  
  28. int dx, dy;
  29. dx = x1 - x0;
  30. dy = y1 - y0;
  31.  
  32. if(!(dx << FRACBITS))
  33. return; /* bail out */
  34.  
  35. long gradient = fp_div(dy << FRACBITS, dx << FRACBITS, FRACBITS);
  36. long intery = (y0 << FRACBITS);
  37.  
  38. unsigned color = rb->lcd_get_foreground();
  39. unsigned long r1, g1, b1;
  40. r1 = RGB_UNPACK_RED(color);
  41. g1 = RGB_UNPACK_GREEN(color);
  42. b1 = RGB_UNPACK_BLUE(color);
  43.  
  44. /* main loop */
  45. if(steep)
  46. {
  47. for(int x = x0; x <= x1; ++x, intery += gradient)
  48. {
  49. unsigned y = intery >> FRACBITS;
  50. unsigned alpha = fp_fpart(intery, FRACBITS) >> (FRACBITS - 8);
  51.  
  52. plot(y, x, (1 << 8) - alpha, r1, g1, b1, l, r, u, d);
  53. plot(y + 1, x, alpha, r1, g1, b1, l, r, u, d);
  54. }
  55. }
  56. else
  57. {
  58. for(int x = x0; x <= x1; ++x, intery += gradient)
  59. {
  60. unsigned y = intery >> FRACBITS;
  61. unsigned alpha = fp_fpart(intery, FRACBITS) >> (FRACBITS - 8);
  62.  
  63. plot(x, y, (1 << 8) - alpha, r1, g1, b1, l, r, u, d);
  64. plot(x, y + 1, alpha, r1, g1, b1, l, r, u, d);
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement