|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- /*
- * libpipi Proper image processing implementation library
- * Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
- * 2008 Jean-Yves Lamoureux <jylam@lnxscene.org
- * All Rights Reserved
- *
- * $Id$
- *
- * This library is free software. It comes without any warranty, to
- * the extent permitted by applicable law. You can redistribute it
- * and/or modify it under the terms of the Do What The Fuck You Want
- * To Public License, Version 2, as published by Sam Hocevar. See
- * http://sam.zoy.org/wtfpl/COPYING for more details.
- */
-
- /*
- * aline_template.c: antialiased (Wu) line rendering template
- */
-
- float x1 = s->x1, y1 = s->y1, x2 = s->x2, y2 = s->y2;
- float g, xd, yd, xgap, xend, yend, xf, yf, val1, val2;
- int x, y, ix1, ix2, iy1, iy2;
-
- xd = x2 - x1;
- yd = y2 - y1;
-
- /* "Horizontal" line (X greater than Y)*/
- if (fabsf(xd) > fabsf(yd)) {
- if (x1 > x2)
- {
- float tmp;
- tmp = x1; x1 = x2; x2 = tmp;
- tmp = y1; y1 = y2; y2 = tmp;
- xd = (x2-x1);
- yd = (y2-y1);
- }
- g = yd/xd;
-
- xend = truncf(x1+0.5);
- yend = y1 + g*(xend-x1);
- xgap = fractinvf(x1+0.5);
- ix1 = (int)xend;
- iy1 = (int)yend;
- val1 = fractinvf(yend)*xgap;
- val2 = fractf(yend)*xgap;
-
- PLOT(ix1, iy1, val1);
- PLOT(ix1, (iy1+1)<y1?(iy1+1):iy1, val2);
-
- yf = yend+g;
- xend = truncf(x2+0.5);
- yend = y2 + g*(xend-x2);
- xgap = fractinvf(x2-0.5);
- ix2 = (int)xend;
- iy2 = (int)yend;
- val1 = fractinvf(yend)*xgap;
- val2 = fractf(yend)*xgap;
-
- PLOT(ix2, iy2, val1);
- PLOT(ix2, iy2+1<y2?iy2+1:iy2, val2);
-
- for (x = (ix1+1); x < ix2; x++)
- {
- float focus;
-
- val1 = fractinvf(yf);
- val2 = fractf(yf);
- focus = (1.0 - fabsf(val1-val2));
- val1 += 0.3*focus;
- val2 += 0.3*focus;
-
- PLOT(x, yf, val1);
- PLOT(x, yf+1, val2);
-
- yf = yf + g;
- }
- }
- /* "Vertical" line (Y greater than X)*/
- else {
- if (x1 > x2)
- {
- float tmp;
- tmp = x1; x1 = x2; x2 = tmp;
- tmp = y1; y1 = y2; y2 = tmp;
- xd = (x2-x1);
- yd = (y2-y1);
- }
-
- g = xd/yd;
-
- xend = truncf(x1+0.5);
- yend = y1 + g*(xend-x1);
- xgap = fractf(x1+0.5);
- ix1 = (int)xend;
- iy1 = (int)yend;
- val1 = fractinvf(yend)*xgap;
- val2 = fractf(yend)*xgap;
-
- PLOT(ix1, iy1, val1);
- PLOT(ix1, (iy1+1)<y1?(iy1+1):iy1, val2);
-
- xf = xend + g;
-
- xend = truncf(x2+0.5);
- yend = y2 + g*(xend-x2);
- xgap = fractinvf(x2-0.5);
- ix2 = (int)xend;
- iy2 = (int)yend;
- val1 = fractinvf(yend)*xgap;
- val2 = fractf(yend)*xgap;
-
- PLOT(ix2, iy2, val1);
- PLOT(ix2, (iy2+1)<y2?(iy2+1):iy2, val2);
-
-
- for (y = (iy1+1); y < iy2; y++)
- {
- float focus;
- int vx = xf;
- val1 = fractinvf(xf);
- val2 = fractf(xf);
- focus = (1.0 - fabsf(val1-val2));
- val1 += 0.3*focus;
- val2 += 0.3*focus;
- PLOT(vx, y, val1);
- vx++;
- PLOT(vx, y, val2);
- xf = xf + g;
- }
- }
|