diff --git a/inst/include/nara.h b/inst/include/nara.h index f18411c..0eb1339 100644 --- a/inst/include/nara.h +++ b/inst/include/nara.h @@ -82,4 +82,28 @@ static inline void nr_circle(uint32_t *nr, int height, int width, int xm, int ym fun(nr, height, width, xm, ym, r, fill, color); } - \ No newline at end of file + + + +// void fill_polygon_c_new(uint32_t *nr, int height, int width, uint32_t color, int *x, int *y, int npoints); + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// void fill_polygon_c_new(uint32_t *nr, int height, int width, uint32_t color, int *x, int *y, int npoints); +// @param nr pointer to the integer data of a native raster +// @param height,width dimensions of nativeRaster +// @param color packed integer representing RGBA colour +// @param fill packed integer representing RGBA fill +// @param x,y integer vectors of coordinates +// @param npoints length of x and y vectors +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +static inline void nr_polygon(uint32_t *nr, int height, int width, uint32_t color, int *x, int *y, int npoints) { + static SEXP (*fun)(uint32_t *nr, int height, int width, uint32_t color, int *x, int *y, int npoints) = NULL; + + if (fun == NULL) { + fun = (SEXP (*)(uint32_t *nr, int height, int width, uint32_t color, int *x, int *y, int npoints)) R_GetCCallable("nara", "nr_polygon"); + } + + fun(nr, height, width, color, x, y, npoints); +} + + diff --git a/src/init.c b/src/init.c index 384e98a..2841b41 100644 --- a/src/init.c +++ b/src/init.c @@ -108,6 +108,7 @@ extern void draw_point_c(uint32_t *nr, int height, int width, uint32_t color, in extern void draw_line_c(uint32_t *nr, int height, int width, uint32_t color, int x0, int y0, int x1, int y1) ; extern void draw_point_sequence_c(uint32_t *nr, int height, int width, uint32_t color, int x1, int x2, int y); extern void draw_circle_c(uint32_t *nr, int height, int width, int xm, int ym, int r, uint32_t fill, uint32_t color); +extern void fill_polygon_c_new(uint32_t *nr, int height, int width, uint32_t color, int *x, int *y, int npoints); void R_init_nara(DllInfo *info) { R_registerRoutines( @@ -122,10 +123,11 @@ void R_init_nara(DllInfo *info) { //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Make the C code available to other packages //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - R_RegisterCCallable("nara", "nr_point" , (DL_FUNC) &draw_point_c); - R_RegisterCCallable("nara", "nr_line" , (DL_FUNC) &draw_line_c); - R_RegisterCCallable("nara", "nr_hline" , (DL_FUNC) &draw_point_sequence_c); - R_RegisterCCallable("nara", "nr_circle", (DL_FUNC) &draw_circle_c); + R_RegisterCCallable("nara", "nr_point" , (DL_FUNC) &draw_point_c); + R_RegisterCCallable("nara", "nr_line" , (DL_FUNC) &draw_line_c); + R_RegisterCCallable("nara", "nr_hline" , (DL_FUNC) &draw_point_sequence_c); + R_RegisterCCallable("nara", "nr_circle" , (DL_FUNC) &draw_circle_c); + R_RegisterCCallable("nara", "nr_polygon", (DL_FUNC) &fill_polygon_c_new); }