Ignore:
Timestamp:
Aug 28, 2008, 3:54:52 PM (14 years ago)
Author:
Jean-Yves Lamoureux
Message:
  • Added a bezier curve primitive (2 control points).
  • Fixed a float overflow in antialiased lines (this algorithm is a mess, and I need to rewrite it)
  • Wrote a bunch of craderies degueulasses to avoid having y1 already defined in math.h
  • Did I say this antialiased line implementation sucks ?
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpipi/trunk/pipi/paint/line.c

    r2787 r2788  
    2525#include <string.h>
    2626
     27#undef __USE_MISC  /* THAT sucks */
     28#undef __USE_XOPEN /* THAT sucks, too (avoid declaring y1 in math.h) */
     29#include <math.h>
     30
     31
    2732#include "pipi.h"
    2833#include "pipi_internals.h"
     
    269274/* Xiaolin Wu's line algorithm, as seen at http://portal.acm.org/citation.cfm?id=122734 */
    270275
    271 /* math.h doesn't like y0 (sucker) */
     276/* math.h doesn't like y1 (sucker) */
    272277float floorf(float x);
    273278float truncf(float x);
    274279float fabsf(float x);
     280
    275281static float fractf(float d) { return (d - floorf(d)); }
    276282static float fractinvf(float d) { return (1 - (d - floorf(d))); }
     
    287293    s->buf_f[qweg] = (c*s->colorf[1]) + (1-c) * s->buf_f[qweg]; \
    288294    s->buf_f[qweb] = (c*s->colorf[2]) + (1-c) * s->buf_f[qweb]; \
    289     if(s->buf_f[qwer] > 0.8f) s->buf_f[qwer] = 0.8f;   /* DEBUG LOL !*/ \
    290     if(s->buf_f[qwer] < 0.2f) s->buf_f[qwer] = 0.2f; \
    291     if(s->buf_f[qweg] > 0.8f) s->buf_f[qweg] = 0.8f; \
    292     if(s->buf_f[qweg] < 0.2f) s->buf_f[qweg] = 0.2f; \
    293     if(s->buf_f[qweb] > 0.8f) s->buf_f[qweb] = 0.8f; \
    294     if(s->buf_f[qweb] < 0.2f) s->buf_f[qweb] = 0.2f; \
    295   }
     295    if(s->buf_f[qwer] > 1.0f) s->buf_f[qwer] = 1.0f; \
     296    if(s->buf_f[qwer] < 0.0f || isnan(s->buf_f[qwer])) s->buf_f[qwer] = 0.0f; \
     297    if(s->buf_f[qweg] > 1.0f) s->buf_f[qweg] = 1.0f; \
     298    if(s->buf_f[qweg] < 0.0f || isnan(s->buf_f[qweg])) s->buf_f[qweg] = 0.0f; \
     299    if(s->buf_f[qweb] > 1.0f) s->buf_f[qweb] = 1.0f; \
     300    if(s->buf_f[qweb] < 0.0f || isnan(s->buf_f[qweb])) s->buf_f[qweb] = 0.0f;  }
     301
    296302#include "aline_template.h"
    297303}
     
    302308#undef  PLOT
    303309#define PLOT(x, y, c) s->buf_f[((int)(x))+((int)(y))*img->w] =  \
    304     (c*s->colorf[0]) + (1-c) * s->buf_f[((int)(x))+((int)(y))*img->w];
     310    (c*s->colorf[0]) + (1-c) * s->buf_f[((int)(x))+((int)(y))*img->w]; \
     311    if(s->buf_f[((int)(x))+((int)(y))*img->w] > 1.0f) s->buf_f[((int)(x))+((int)(y))*img->w] = 1.0f; \
     312    if(s->buf_f[((int)(x))+((int)(y))*img->w] < 0.0f) s->buf_f[((int)(x))+((int)(y))*img->w] = 0.0f; \
     313    if(isnan(s->buf_f[((int)(x))+((int)(y))*img->w])) s->buf_f[((int)(x))+((int)(y))*img->w] = 0.0f;
     314
    305315#include "aline_template.h"
    306316}
Note: See TracChangeset for help on using the changeset viewer.