Browse Source

* Moved *line_template.c to .h files to avoid problems with autotools (sam)

* Added antialiasing support to polylines
 * Ho, and previous commit (r2777) contains width/height/pitch accessors to pipi_image_t, too. LOL.


git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2778 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
jylam 16 years ago
parent
commit
0a06b0af5f
4 changed files with 34 additions and 13 deletions
  1. +0
    -0
      pipi/paint/aline_template.h
  2. +33
    -12
      pipi/paint/line.c
  3. +0
    -0
      pipi/paint/line_template.h
  4. +1
    -1
      pipi/pipi.h

pipi/paint/aline_template.c → pipi/paint/aline_template.h View File


+ 33
- 12
pipi/paint/line.c View File

@@ -108,18 +108,39 @@ int pipi_draw_line(pipi_image_t *img , int x1, int y1, int x2, int y2, uint32_t




int pipi_draw_polyline(pipi_image_t *img, int const x[], int const y[], int pipi_draw_polyline(pipi_image_t *img, int const x[], int const y[],
int n, uint32_t c)
int n, uint32_t c, int aa)
{ {
int i; int i;
struct line s; struct line s;


if(img->last_modified == PIPI_PIXELS_RGBA_C) if(img->last_modified == PIPI_PIXELS_RGBA_C)
{ {
uint32_t *dstdata;
dstdata = (uint32_t *)pipi_getpixels(img, PIPI_PIXELS_RGBA_C)->pixels;
s.color32 = c;
s.buf_u32 = dstdata;
s.draw = draw_aliased_line_u32;
if(!aa)
{
uint32_t *dstdata;
dstdata = (uint32_t *)pipi_getpixels(img, PIPI_PIXELS_RGBA_C)->pixels;
s.color32 = c;
s.buf_u32 = dstdata;
s.draw = draw_aliased_line_u32;
}
else
{
float *dstdata;
dstdata = (float *)pipi_getpixels(img, PIPI_PIXELS_RGBA_F)->pixels;
s.colorf[2] = ((c&0x00FF0000)>>16)/255.0f; /* XXX FIXME */
s.colorf[1] = ((c&0x0000FF00)>>8)/255.0f; /* XXX FIXME */
s.colorf[0] = (c&0x000000FF)/255.0f; /* XXX FIXME */
s.buf_f = dstdata;
s.draw = draw_antialiased_line_float;
}
}
else if(img->last_modified == PIPI_PIXELS_Y_F)
{
float *dstdata;
dstdata = (float *)pipi_getpixels(img, PIPI_PIXELS_Y_F)->pixels;
s.colorf[0] = c/255.0f; /* XXX FIXME */
s.buf_f = dstdata;
s.draw = aa==0?draw_aliased_line_gray:draw_antialiased_line_gray;
} }
else else
{ {
@@ -129,7 +150,7 @@ int pipi_draw_polyline(pipi_image_t *img, int const x[], int const y[],
s.colorf[1] = (c&0x0000FF00)/255.0f; /* XXX FIXME */ s.colorf[1] = (c&0x0000FF00)/255.0f; /* XXX FIXME */
s.colorf[2] = (c&0x000000FF)/255.0f; /* XXX FIXME */ s.colorf[2] = (c&0x000000FF)/255.0f; /* XXX FIXME */
s.buf_f = dstdata; s.buf_f = dstdata;
s.draw = draw_aliased_line_float;
s.draw = aa==0?draw_aliased_line_float:draw_antialiased_line_float;
img->last_modified = PIPI_PIXELS_RGBA_F; img->last_modified = PIPI_PIXELS_RGBA_F;
} }


@@ -228,7 +249,7 @@ static void draw_aliased_line_u32(pipi_image_t *img, struct line* s)
{ {
#undef ASSIGN #undef ASSIGN
#define ASSIGN(x, y, w) s->buf_u32[x+y*w] = s->color32; #define ASSIGN(x, y, w) s->buf_u32[x+y*w] = s->color32;
#include "line_template.c"
#include "line_template.h"
} }
static void draw_aliased_line_float(pipi_image_t *img, struct line* s) static void draw_aliased_line_float(pipi_image_t *img, struct line* s)
{ {
@@ -236,13 +257,13 @@ static void draw_aliased_line_float(pipi_image_t *img, struct line* s)
#define ASSIGN(x, y, w) s->buf_f[(x*4)+y*(w*4)] = s->colorf[0]; \ #define ASSIGN(x, y, w) s->buf_f[(x*4)+y*(w*4)] = s->colorf[0]; \
s->buf_f[1 + (x*4)+y*(w*4)] = s->colorf[1]; \ s->buf_f[1 + (x*4)+y*(w*4)] = s->colorf[1]; \
s->buf_f[2 + (x*4)+y*(w*4)] = s->colorf[2]; s->buf_f[2 + (x*4)+y*(w*4)] = s->colorf[2];
#include "line_template.c"
#include "line_template.h"
} }
static void draw_aliased_line_gray(pipi_image_t *img, struct line* s) static void draw_aliased_line_gray(pipi_image_t *img, struct line* s)
{ {
#undef ASSIGN #undef ASSIGN
#define ASSIGN(x, y, w) s->buf_f[x+y*w] = s->colorf[0]; #define ASSIGN(x, y, w) s->buf_f[x+y*w] = s->colorf[0];
#include "line_template.c"
#include "line_template.h"
} }


/* Xiaolin Wu's line algorithm, as seen at http://portal.acm.org/citation.cfm?id=122734 */ /* Xiaolin Wu's line algorithm, as seen at http://portal.acm.org/citation.cfm?id=122734 */
@@ -265,7 +286,7 @@ static void draw_antialiased_line_float(pipi_image_t *img, struct line* s)
(c*s->colorf[1]) + (1-c) * s->buf_f[(1+((int)(x)*4))+((int)(y))*(img->w*4)]; \ (c*s->colorf[1]) + (1-c) * s->buf_f[(1+((int)(x)*4))+((int)(y))*(img->w*4)]; \
s->buf_f[(2+((int)(x)*4))+((int)(y))*(img->w*4)] = \ s->buf_f[(2+((int)(x)*4))+((int)(y))*(img->w*4)] = \
(c*s->colorf[2]) + (1-c) * s->buf_f[(2+((int)(x)*4))+((int)(y))*(img->w*4)]; (c*s->colorf[2]) + (1-c) * s->buf_f[(2+((int)(x)*4))+((int)(y))*(img->w*4)];
#include "aline_template.c"
#include "aline_template.h"
} }




@@ -274,5 +295,5 @@ static void draw_antialiased_line_gray(pipi_image_t *img, struct line* s)
#undef PLOT #undef PLOT
#define PLOT(x, y, c) s->buf_f[((int)(x))+((int)(y))*img->w] = \ #define PLOT(x, y, c) s->buf_f[((int)(x))+((int)(y))*img->w] = \
(c*s->colorf[0]) + (1-c) * s->buf_f[((int)(x))+((int)(y))*img->w]; (c*s->colorf[0]) + (1-c) * s->buf_f[((int)(x))+((int)(y))*img->w];
#include "aline_template.c"
#include "aline_template.h"
} }

pipi/paint/line_template.c → pipi/paint/line_template.h View File


+ 1
- 1
pipi/pipi.h View File

@@ -155,7 +155,7 @@ extern int pipi_flood_fill(pipi_image_t *,
int, int, float, float, float, float); int, int, float, float, float, float);
extern int pipi_draw_line(pipi_image_t *, int, int, int, int, uint32_t, int); extern int pipi_draw_line(pipi_image_t *, int, int, int, int, uint32_t, int);
extern int pipi_draw_polyline(pipi_image_t *, int const[], int const[], extern int pipi_draw_polyline(pipi_image_t *, int const[], int const[],
int , uint32_t);
int , uint32_t, int);
extern pipi_image_t *pipi_reduce(pipi_image_t *, int, double const *); extern pipi_image_t *pipi_reduce(pipi_image_t *, int, double const *);


extern pipi_image_t *pipi_dither_ediff(pipi_image_t *, pipi_image_t *, extern pipi_image_t *pipi_dither_ediff(pipi_image_t *, pipi_image_t *,


Loading…
Cancel
Save