Changeset 2788 for libpipi


Ignore:
Timestamp:
Aug 28, 2008, 3:54:52 PM (12 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 ?
Location:
libpipi/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • libpipi/trunk/examples/Makefile.am

    r2776 r2788  
    33AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/pipi
    44
    5 bin_PROGRAMS = edd img2rubik sharpen floodfill line
     5bin_PROGRAMS = edd img2rubik sharpen floodfill line bezier
    66
    77edd_SOURCES = edd.c
     
    1919line_SOURCES = line.c
    2020line_LDADD = ../pipi/libpipi.la
     21
     22bezier_SOURCES = bezier.c
     23bezier_LDADD = ../pipi/libpipi.la
  • libpipi/trunk/examples/line.c

    r2783 r2788  
    3838    while(count--) {
    3939        pipi_draw_line(newimg,
    40                        rand() % w, rand() % h,
     40                       rand()  , rand() % h,
    4141                       rand() % w, rand() % h,
    4242                       rand(),
  • libpipi/trunk/pipi/Makefile.am

    r2780 r2788  
    4545        paint/floodfill.c \
    4646        paint/line.c paint/line_template.h paint/aline_template.h \
     47        paint/bezier.c \
    4748        paint/tile.c
    4849
  • libpipi/trunk/pipi/paint/aline_template.h

    r2783 r2788  
    7171
    7272        PLOT(x, yf, val1);
    73         PLOT(x, yf+1, val2);
     73        PLOT(x, (yf+1)<y1?(yf+1):yf, val2);
    7474
    7575        yf = yf + g;
  • 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}
  • libpipi/trunk/pipi/pipi.h

    r2778 r2788  
    157157extern int pipi_draw_polyline(pipi_image_t *, int const[], int const[],
    158158                              int , uint32_t, int);
     159extern int pipi_draw_bezier4(pipi_image_t *,int, int, int, int, int, int, int, int, uint32_t, int, int);
    159160extern pipi_image_t *pipi_reduce(pipi_image_t *, int, double const *);
    160161
Note: See TracChangeset for help on using the changeset viewer.