No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

131 líneas
2.9 KiB

  1. /*
  2. * libpipi Proper image processing implementation library
  3. * Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
  4. * 2008 Jean-Yves Lamoureux <jylam@lnxscene.org
  5. * All Rights Reserved
  6. *
  7. * $Id$
  8. *
  9. * This library is free software. It comes without any warranty, to
  10. * the extent permitted by applicable law. You can redistribute it
  11. * and/or modify it under the terms of the Do What The Fuck You Want
  12. * To Public License, Version 2, as published by Sam Hocevar. See
  13. * http://sam.zoy.org/wtfpl/COPYING for more details.
  14. */
  15. /*
  16. * aline_template.c: antialiased (Wu) line rendering template
  17. */
  18. float x1 = s->x1, y1 = s->y1, x2 = s->x2, y2 = s->y2;
  19. float g, xd, yd, xgap, xend, yend, xf, yf, val1, val2;
  20. int x, y, ix1, ix2, iy1, iy2;
  21. xd = x2 - x1;
  22. yd = y2 - y1;
  23. /* "Horizontal" line (X greater than Y)*/
  24. if (fabsf(xd) > fabsf(yd)) {
  25. if (x1 > x2)
  26. {
  27. float tmp;
  28. tmp = x1; x1 = x2; x2 = tmp;
  29. tmp = y1; y1 = y2; y2 = tmp;
  30. xd = (x2-x1);
  31. yd = (y2-y1);
  32. }
  33. g = yd/xd;
  34. xend = truncf(x1+0.5);
  35. yend = y1 + g*(xend-x1);
  36. xgap = fractinvf(x1+0.5);
  37. ix1 = (int)xend;
  38. iy1 = (int)yend;
  39. val1 = fractinvf(yend)*xgap;
  40. val2 = fractf(yend)*xgap;
  41. PLOT(ix1, iy1, val1);
  42. PLOT(ix1, (iy1+1)<y1?(iy1+1):iy1, val2);
  43. yf = yend+g;
  44. xend = truncf(x2+0.5);
  45. yend = y2 + g*(xend-x2);
  46. xgap = fractinvf(x2-0.5);
  47. ix2 = (int)xend;
  48. iy2 = (int)yend;
  49. val1 = fractinvf(yend)*xgap;
  50. val2 = fractf(yend)*xgap;
  51. PLOT(ix2, iy2, val1);
  52. PLOT(ix2, iy2+1<y2?iy2+1:iy2, val2);
  53. for (x = (ix1+1); x < ix2; x++)
  54. {
  55. float focus;
  56. val1 = fractinvf(yf);
  57. val2 = fractf(yf);
  58. focus = (1.0 - fabsf(val1-val2));
  59. val1 += 0.3*focus;
  60. val2 += 0.3*focus;
  61. PLOT(x, yf, val1);
  62. PLOT(x, yf+1, val2);
  63. yf = yf + g;
  64. }
  65. }
  66. /* "Vertical" line (Y greater than X)*/
  67. else {
  68. if (x1 > x2)
  69. {
  70. float tmp;
  71. tmp = x1; x1 = x2; x2 = tmp;
  72. tmp = y1; y1 = y2; y2 = tmp;
  73. xd = (x2-x1);
  74. yd = (y2-y1);
  75. }
  76. g = xd/yd;
  77. xend = truncf(x1+0.5);
  78. yend = y1 + g*(xend-x1);
  79. xgap = fractf(x1+0.5);
  80. ix1 = (int)xend;
  81. iy1 = (int)yend;
  82. val1 = fractinvf(yend)*xgap;
  83. val2 = fractf(yend)*xgap;
  84. PLOT(ix1, iy1, val1);
  85. PLOT(ix1, (iy1+1)<y1?(iy1+1):iy1, val2);
  86. xf = xend + g;
  87. xend = truncf(x2+0.5);
  88. yend = y2 + g*(xend-x2);
  89. xgap = fractinvf(x2-0.5);
  90. ix2 = (int)xend;
  91. iy2 = (int)yend;
  92. val1 = fractinvf(yend)*xgap;
  93. val2 = fractf(yend)*xgap;
  94. PLOT(ix2, iy2, val1);
  95. PLOT(ix2, (iy2+1)<y2?(iy2+1):iy2, val2);
  96. for (y = (iy1+1); y < iy2; y++)
  97. {
  98. float focus;
  99. int vx = xf;
  100. val1 = fractinvf(xf);
  101. val2 = fractf(xf);
  102. focus = (1.0 - fabsf(val1-val2));
  103. val1 += 0.3*focus;
  104. val2 += 0.3*focus;
  105. PLOT(vx, y, val1);
  106. vx++;
  107. PLOT(vx, y, val2);
  108. xf = xf + g;
  109. }
  110. }