diff --git a/examples/bezier.c b/examples/bezier.c new file mode 100644 index 0000000..ed0ada7 --- /dev/null +++ b/examples/bezier.c @@ -0,0 +1,47 @@ +#include "config.h" +#include "common.h" + +#include +#include +#include + +#include + +int main(int argc, char *argv[]) +{ + char *srcname = NULL, *dstname = NULL; + pipi_image_t *img, *newimg; + int ret = 0; + if(argc < 2) + { + fprintf(stderr, "%s: too few arguments\n", argv[0]); + fprintf(stderr, "Usage: %s \n", argv[0]); + return EXIT_FAILURE; + } + + srcname = argv[1]; + dstname = argv[2]; + + img = pipi_load(srcname); + + if(!img) { + fprintf(stderr, "Can't open %s for reading\n", srcname); + return -1; + } + + newimg = pipi_copy(img); + pipi_free(img); + + int w = pipi_get_image_width(newimg); + int h = pipi_get_image_height(newimg); + + + pipi_draw_bezier4(newimg , 1, 1, w-1, 1, w-1, h-1, 1, h-1 , 0x00FF0000, 20, 1); + + pipi_save(newimg, dstname); + + pipi_free(newimg); + + return ret; +} + diff --git a/pipi/paint/bezier.c b/pipi/paint/bezier.c new file mode 100644 index 0000000..b8616ef --- /dev/null +++ b/pipi/paint/bezier.c @@ -0,0 +1,59 @@ +/* + * libpipi Proper image processing implementation library + * Copyright (c) 2004-2008 Sam Hocevar + * 2008 Jean-Yves Lamoureux +#include +#include + +#include "pipi.h" +#include "pipi_internals.h" + + +int pipi_draw_bezier4(pipi_image_t *img , + int x1, int y1, + int x2, int y2, + int x3, int y3, + int x4, int y4, + uint32_t c, int n, int aa) +{ + if(img->last_modified == PIPI_PIXELS_RGBA_C) + { + float t; + float x= x1, y= y1; + float lx, ly; + for(t=0; t<1; t+=(1.0f/n)) + { + float a = t; + float b = 1 - t; + + lx = x; ly = y; + + x = (x1*(b*b*b)) + 3*x2*(b*b)*a + 3*x4*b*(a*a) + x3*(a*a*a); + y = (y1*(b*b*b)) + 3*y2*(b*b)*a + 3*y4*b*(a*a) + y3*(a*a*a); + + pipi_draw_line(img , lx, ly, x, y, c, aa); + } + pipi_draw_line(img , x, y, x3, y3, c, aa); + } + + return 0; +}