From da9f17aa78b7b41424a546a2cf8b2a785f9a030f Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sat, 9 Jan 2010 00:11:35 +0000 Subject: strip legacy plotter interface cleanup line plotting interface move plotter interface structs to apropriate header svn path=/trunk/libnsfb/; revision=9798 --- Makefile | 1 - include/frontend.h | 1 + include/libnsfb.h | 15 ---- include/libnsfb_legacy_plot.h | 74 -------------------- include/libnsfb_plot.h | 42 ++++++++++- include/nsfb_plot.h | 5 +- src/16bpp_plotters.c | 159 +++++++++++++++++++++--------------------- src/32bpp_plotters.c | 158 +++++++++++++++++++++-------------------- src/8bpp_plotters.c | 153 ++++++++++++++++++++-------------------- src/Makefile | 2 +- src/frontend.c | 2 +- src/frontend_able.c | 1 + src/frontend_linux.c | 1 + src/frontend_ram.c | 1 + src/frontend_sdl.c | 1 + src/frontend_vnc.c | 1 + src/legacy_plot.c | 114 ------------------------------ src/libnsfb.c | 1 + src/plot.c | 14 +++- src/plot_util.c | 1 + src/plotters.c | 149 +++++++++++++++++++++------------------ test/bezier.c | 6 +- test/plottest.c | 21 +++--- 23 files changed, 403 insertions(+), 520 deletions(-) delete mode 100644 include/libnsfb_legacy_plot.h delete mode 100644 src/legacy_plot.c diff --git a/Makefile b/Makefile index df23598..57fa975 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,6 @@ I := /include INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libnsfb.h INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libnsfb_plot.h INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libnsfb_plot_util.h -INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libnsfb_legacy_plot.h INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libnsfb_event.h INSTALL_ITEMS := $(INSTALL_ITEMS) $(I):include/libnsfb_cursor.h INSTALL_ITEMS := $(INSTALL_ITEMS) /lib/pkgconfig:lib$(COMPONENT).pc.in diff --git a/include/frontend.h b/include/frontend.h index f477996..fba407f 100644 --- a/include/frontend.h +++ b/include/frontend.h @@ -1,6 +1,7 @@ /* libnsfb framebuffer frontend support */ #include "libnsfb.h" +#include "libnsfb_plot.h" #include "nsfb.h" /* frontend default options */ diff --git a/include/libnsfb.h b/include/libnsfb.h index 41490ad..8174350 100644 --- a/include/libnsfb.h +++ b/include/libnsfb.h @@ -15,21 +15,6 @@ typedef struct nsfb_cursor_s nsfb_cursor_t; typedef struct nsfb_s nsfb_t; - -/** representation of a colour. - * - * The colour value comprises of four components arranged in the order ABGR: - * bits 24-31 are the alpha value and represent the opacity. 0 is - * transparent i.e. there would be no change in the target surface if - * this colour were to be used and 0xFF is opaque. - * - * bits 16-23 are the Blue component of the colour. - * - * bits 8-15 are the Green component of the colour. - * - * bits 0-7 are the Red component of the colour. - */ -typedef uint32_t nsfb_colour_t; typedef struct nsfb_event_s nsfb_event_t; /** co-ordinate for plotting operations */ diff --git a/include/libnsfb_legacy_plot.h b/include/libnsfb_legacy_plot.h deleted file mode 100644 index 276acea..0000000 --- a/include/libnsfb_legacy_plot.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2009 Vincent Sanders - * - * This file is part of libnsfb, http://www.netsurf-browser.org/ - * Licenced under the MIT License, - * http://www.opensource.org/licenses/mit-license.php - * - * This is the exported legacy plotter interface for the libnsfb graphics - * library. This interface should *not* be used for new projects. It is not - * thread safe as the framebuffer context is held as a global and not passed. - */ - -#ifndef _LIBNSFB_LEGACY_PLOT_H -#define _LIBNSFB_LEGACY_PLOT_H 1 - -/** Set the framebuffer context for all legacy plot operations. - */ -bool nsfb_lplot_ctx(nsfb_t *nsfb); - -/** Sets a clip rectangle for subsequent plots. - * - * Sets a clipping area which constrains all subsequent plotting operations. - * The clipping area must lie within the framebuffer visible screen or false - * will be returned and the new clipping area not set. - */ -bool nsfb_lplot_clip(int x0, int y0, int x1, int y1); - -/** Clears plotting area to a flat colour. - */ -bool nsfb_lplot_clg(nsfb_colour_t c); - -/** Plots a rectangle outline. - * - * The line can be solid, dotted or dashed. Top left corner at (x0,y0) and - * rectangle has given width and height. - */ -bool nsfb_lplot_rectangle(int x0, int y0, int width, int height, int line_width, nsfb_colour_t c, bool dotted, bool dashed); - -/** Plots a filled rectangle. - * - * Top left corner at (x0,y0), bottom right corner at (x1,y1). Note: (x0,y0) is - * inside filled area, but (x1,y1) is below and to the right. - */ -bool nsfb_lplot_fill(int x0, int y0, int x1, int y1, nsfb_colour_t c); - -/** Plots a line. - * - * Draw a line from (x0,y0) to (x1,y1). Coordinates are at centre of line - * width/thickness. - */ -bool nsfb_lplot_line(int x0, int y0, int x1, int y1, int line_width, nsfb_colour_t c, bool dotted, bool dashed); - - -/** Plots a filled polygon. - * - * Plots a filled polygon with straight lines between points. The lines around - * the edge of the ploygon are not plotted. The polygon is filled with a - * non-zero winding rule. - * - */ -bool nsfb_lplot_polygon(const int *p, unsigned int n, nsfb_colour_t fillc); - -/** Plots a circle. - */ -bool nsfb_lplot_disc(int x, int y, int radius, nsfb_colour_t c, bool filled); - -/** Plots an arc. - * - * around (x,y), from anticlockwise from angle1 to angle2. Angles are measured - * anticlockwise from horizontal, in degrees. - */ -bool nsfb_lplot_arc(int x, int y, int radius, int angle1, int angle2, nsfb_colour_t c); - -#endif /* _LIBNSFB_LEGACY_PLOT_H */ diff --git a/include/libnsfb_plot.h b/include/libnsfb_plot.h index 1d420b0..ef53934 100644 --- a/include/libnsfb_plot.h +++ b/include/libnsfb_plot.h @@ -11,6 +11,40 @@ #ifndef _LIBNSFB_PLOT_H #define _LIBNSFB_PLOT_H 1 +/** representation of a colour. + * + * The colour value comprises of four components arranged in the order ABGR: + * bits 24-31 are the alpha value and represent the opacity. 0 is + * transparent i.e. there would be no change in the target surface if + * this colour were to be used and 0xFF is opaque. + * + * bits 16-23 are the Blue component of the colour. + * + * bits 8-15 are the Green component of the colour. + * + * bits 0-7 are the Red component of the colour. + */ +typedef uint32_t nsfb_colour_t; + +/** + * Type of plot operation + */ +typedef enum nsfb_plot_optype_e { + NFSB_PLOT_OPTYPE_NONE = 0, /**< No operation */ + NFSB_PLOT_OPTYPE_SOLID, /**< Solid colour */ + NFSB_PLOT_OPTYPE_PATTERN, /**< Pattern plot */ +} nsfb_plot_optype_t; + +/** pen colour and raster operation for plotting primatives. */ +typedef struct nsfb_plot_pen_s { + nsfb_plot_optype_t stroke_type; /**< Stroke plot type */ + int stroke_width; /**< Width of stroke, in pixels */ + nsfb_colour_t stroke_colour; /**< Colour of stroke */ + uint32_t stroke_pattern; + nsfb_plot_optype_t fill_type; /**< Fill plot type */ + nsfb_colour_t fill_colour; /**< Colour of fill */ +} nsfb_plot_pen_t; + /** Sets a clip rectangle for subsequent plots. * * Sets a clipping area which constrains all subsequent plotting operations. @@ -45,7 +79,13 @@ bool nsfb_plot_rectangle_fill(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t c); * Draw a line from (x0,y0) to (x1,y1). Coordinates are at centre of line * width/thickness. */ -bool nsfb_plot_line(nsfb_t *nsfb, nsfb_bbox_t *line, int line_width, nsfb_colour_t c, bool dotted, bool dashed); +bool nsfb_plot_line(nsfb_t *nsfb, nsfb_bbox_t *line, nsfb_plot_pen_t *pen); + +/** Plots a number of lines. + * + * Draw a series of lines. + */ +bool nsfb_plot_lines(nsfb_t *nsfb, int linec, nsfb_bbox_t *line, nsfb_plot_pen_t *pen); /** Plots a filled polygon. * diff --git a/include/nsfb_plot.h b/include/nsfb_plot.h index 52af7cd..8b39cc5 100644 --- a/include/nsfb_plot.h +++ b/include/nsfb_plot.h @@ -10,10 +10,9 @@ typedef bool (nsfb_plotfn_clg_t)(nsfb_t *nsfb, nsfb_colour_t c); */ typedef bool (nsfb_plotfn_rectangle_t)(nsfb_t *nsfb, nsfb_bbox_t *rect, int line_width, nsfb_colour_t c, bool dotted, bool dashed); -/** Plots a line from (x0,y0) to (x1,y1). Coordinates are at - * centre of line width/thickness. +/** Plots a line using a given pen. */ -typedef bool (nsfb_plotfn_line_t)(nsfb_t *nsfb, nsfb_bbox_t *line, int line_width, nsfb_colour_t c, bool dotted, bool dashed); +typedef bool (nsfb_plotfn_line_t)(nsfb_t *nsfb, int linec, nsfb_bbox_t *line, nsfb_plot_pen_t *pen); /** Plots a filled polygon with straight lines between points. * The lines around the edge of the ploygon are not plotted. The diff --git a/src/16bpp_plotters.c b/src/16bpp_plotters.c index 6497f91..a223e23 100644 --- a/src/16bpp_plotters.c +++ b/src/16bpp_plotters.c @@ -11,6 +11,7 @@ #include #include "libnsfb.h" +#include "libnsfb_plot.h" #include "libnsfb_plot_util.h" #include "nsfb.h" @@ -39,12 +40,7 @@ static inline uint16_t colour_to_pixel(nsfb_colour_t c) static bool -line(nsfb_t *nsfb, - nsfb_bbox_t *line, - int line_width, - nsfb_colour_t c, - bool dotted, - bool dashed) +line(nsfb_t *nsfb, int linec, nsfb_bbox_t *line, nsfb_plot_pen_t *pen) { int w; uint16_t ent; @@ -53,76 +49,81 @@ line(nsfb_t *nsfb, int dx, dy, sdy; int dxabs, dyabs; - line_width = line_width; - dotted = dotted; - dashed = dashed; + ent = colour_to_pixel(pen->stroke_colour); - ent = colour_to_pixel(c); + for (;linec > 0; linec--) { - if (line->y0 == line->y1) { - /* horizontal line special cased */ - if (!nsfb_plot_clip_ctx(nsfb, line)) - return true; /* line outside clipping */ + if (line->y0 == line->y1) { + /* horizontal line special cased */ - pvideo = get_xy_loc(nsfb, line->x0, line->y0); + if (!nsfb_plot_clip_ctx(nsfb, line)) { + /* line outside clipping */ + line++; + continue; + } + + pvideo = get_xy_loc(nsfb, line->x0, line->y0); - w = line->x1 - line->x0; - while (w-- > 0) - *(pvideo + w) = ent; + w = line->x1 - line->x0; + while (w-- > 0) + *(pvideo + w) = ent; - return true; - } else { - /* standard bresenham line */ - if (!nsfb_plot_clip_line_ctx(nsfb, line)) - return true; /* line outside clipping */ + } else { + /* standard bresenham line */ + if (!nsfb_plot_clip_line_ctx(nsfb, line)) { + /* line outside clipping */ + line++; + continue; + } - /* the horizontal distance of the line */ - dx = line->x1 - line->x0; - dxabs = abs (dx); + /* the horizontal distance of the line */ + dx = line->x1 - line->x0; + dxabs = abs (dx); - /* the vertical distance of the line */ - dy = line->y1 - line->y0; - dyabs = abs (dy); + /* the vertical distance of the line */ + dy = line->y1 - line->y0; + dyabs = abs (dy); - sdy = dx ? SIGN(dy) * SIGN(dx) : SIGN(dy); + sdy = dx ? SIGN(dy) * SIGN(dx) : SIGN(dy); + + if (dx >= 0) + pvideo = get_xy_loc(nsfb, line->x0, line->y0); + else + pvideo = get_xy_loc(nsfb, line->x1, line->y1); + + x = dyabs >> 1; + y = dxabs >> 1; + + if (dxabs >= dyabs) { + /* the line is more horizontal than vertical */ + for (i = 0; i < dxabs; i++) { + *pvideo = ent; - if (dx >= 0) - pvideo = get_xy_loc(nsfb, line->x0, line->y0); - else - pvideo = get_xy_loc(nsfb, line->x1, line->y1); - - x = dyabs >> 1; - y = dxabs >> 1; - - if (dxabs >= dyabs) { - /* the line is more horizontal than vertical */ - for (i = 0; i < dxabs; i++) { - *pvideo = ent; - - pvideo++; - y += dyabs; - if (y >= dxabs) { - y -= dxabs; - pvideo += sdy * (nsfb->linelen>>1); - } - } - } else { - /* the line is more vertical than horizontal */ - for (i = 0; i < dyabs; i++) { - *pvideo = ent; - pvideo += sdy * (nsfb->linelen >> 1); - - x += dxabs; - if (x >= dyabs) { - x -= dyabs; pvideo++; + y += dyabs; + if (y >= dxabs) { + y -= dxabs; + pvideo += sdy * (nsfb->linelen>>1); + } + } + } else { + /* the line is more vertical than horizontal */ + for (i = 0; i < dyabs; i++) { + *pvideo = ent; + pvideo += sdy * (nsfb->linelen >> 1); + + x += dxabs; + if (x >= dyabs) { + x -= dyabs; + pvideo++; + } } } - } + } + line++; } - - return true; + return true; } @@ -189,7 +190,7 @@ static bool fill(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t c) pvid16 += llen; } } - return true; + return true; } @@ -213,7 +214,7 @@ static bool point(nsfb_t *nsfb, int x, int y, nsfb_colour_t c) *pvideo = colour_to_pixel(c); } - return true; + return true; } static bool @@ -225,7 +226,7 @@ glyph1(nsfb_t *nsfb, { uint16_t *pvideo; int xloop, yloop; - int xoff, yoff; /* x and y offset into image */ + int xoff, yoff; /* x and y offset into image */ int x = loc->x0; int y = loc->y0; int width = loc->x1 - loc->x0; @@ -243,8 +244,8 @@ glyph1(nsfb_t *nsfb, if (width > (loc->x1 - loc->x0)) width = (loc->x1 - loc->x0); - xoff = loc->x0 - x; - yoff = loc->y0 - y; + xoff = loc->x0 - x; + yoff = loc->y0 - y; pvideo = get_xy_loc(nsfb, loc->x0, loc->y0); @@ -268,7 +269,7 @@ glyph1(nsfb_t *nsfb, pvideo += (nsfb->linelen >> 1); } - return true; + return true; } static bool @@ -281,7 +282,7 @@ glyph8(nsfb_t *nsfb, uint16_t *pvideo; nsfb_colour_t abpixel; /* alphablended pixel */ int xloop, yloop; - int xoff, yoff; /* x and y offset into image */ + int xoff, yoff; /* x and y offset into image */ int x = loc->x0; int y = loc->y0; int width = loc->x1 - loc->x0; @@ -297,8 +298,8 @@ glyph8(nsfb_t *nsfb, if (width > (loc->x1 - loc->x0)) width = (loc->x1 - loc->x0); - xoff = loc->x0 - x; - yoff = loc->y0 - y; + xoff = loc->x0 - x; + yoff = loc->y0 - y; pvideo = get_xy_loc(nsfb, loc->x0, loc->y0); @@ -320,7 +321,7 @@ glyph8(nsfb_t *nsfb, pvideo += (nsfb->linelen >> 1); } - return true; + return true; } static bool @@ -335,7 +336,7 @@ bitmap(nsfb_t *nsfb, uint16_t *pvideo; nsfb_colour_t abpixel; /* alphablended pixel */ int xloop, yloop; - int xoff, yoff; /* x and y offset into image */ + int xoff, yoff; /* x and y offset into image */ int x = loc->x0; int y = loc->y0; int width = loc->x1 - loc->x0; @@ -370,9 +371,9 @@ bitmap(nsfb_t *nsfb, width = (clipped.x1 - clipped.x0); - xoff = clipped.x0 - x; - yoff = (clipped.y0 - y) * bmp_width; - height = height * bmp_width + yoff; + xoff = clipped.x0 - x; + yoff = (clipped.y0 - y) * bmp_width; + height = height * bmp_width + yoff; /* plot the image */ pvideo = get_xy_loc(nsfb, clipped.x0, clipped.y0); @@ -402,15 +403,15 @@ bitmap(nsfb_t *nsfb, } } - return true; + return true; } const nsfb_plotter_fns_t _nsfb_16bpp_plotters = { - .line = line, - .fill = fill, + .line = line, + .fill = fill, .point = point, .bitmap = bitmap, .glyph8 = glyph8, diff --git a/src/32bpp_plotters.c b/src/32bpp_plotters.c index daa8598..d86821c 100644 --- a/src/32bpp_plotters.c +++ b/src/32bpp_plotters.c @@ -11,6 +11,7 @@ #include #include "libnsfb.h" +#include "libnsfb_plot.h" #include "libnsfb_plot_util.h" #include "nsfb.h" @@ -52,12 +53,7 @@ static inline uint32_t colour_to_pixel(nsfb_colour_t c) #define SIGN(x) ((x<0) ? -1 : ((x>0) ? 1 : 0)) static bool -line(nsfb_t *nsfb, - nsfb_bbox_t *line, - int line_width, - nsfb_colour_t c, - bool dotted, - bool dashed) +line(nsfb_t *nsfb, int linec, nsfb_bbox_t *line, nsfb_plot_pen_t *pen) { int w; uint32_t ent; @@ -66,74 +62,82 @@ line(nsfb_t *nsfb, int dx, dy, sdy; int dxabs, dyabs; - line_width = line_width; - dotted = dotted; - dashed = dashed; + ent = colour_to_pixel(pen->stroke_colour); - ent = colour_to_pixel(c); + for (;linec > 0; linec--) { - if (!nsfb_plot_clip_ctx(nsfb, line)) - return true; /* line outside clipping */ + if (line->y0 == line->y1) { + /* horizontal line special cased */ - if (line->y0 == line->y1) { - /* horizontal line special cased */ - pvideo = get_xy_loc(nsfb, line->x0, line->y0); + if (!nsfb_plot_clip_ctx(nsfb, line)) { + /* line outside clipping */ + line++; + continue; + } - w = line->x1 - line->x0; - while (w-- > 0) - *(pvideo + w) = ent; + pvideo = get_xy_loc(nsfb, line->x0, line->y0); - return true; - } else { - /* standard bresenham line */ + w = line->x1 - line->x0; + while (w-- > 0) + *(pvideo + w) = ent; + + } else { + /* standard bresenham line */ - /* the horizontal distance of the line */ - dx = line->x1 - line->x0; - dxabs = abs (dx); + if (!nsfb_plot_clip_line_ctx(nsfb, line)) { + /* line outside clipping */ + line++; + continue; + } - /* the vertical distance of the line */ - dy = line->y1 - line->y0; - dyabs = abs (dy); + /* the horizontal distance of the line */ + dx = line->x1 - line->x0; + dxabs = abs (dx); - sdy = dx ? SIGN(dy) * SIGN(dx) : SIGN(dy); + /* the vertical distance of the line */ + dy = line->y1 - line->y0; + dyabs = abs (dy); + + sdy = dx ? SIGN(dy) * SIGN(dx) : SIGN(dy); + + if (dx >= 0) + pvideo = get_xy_loc(nsfb, line->x0, line->y0); + else + pvideo = get_xy_loc(nsfb, line->x1, line->y1); + + x = dyabs >> 1; + y = dxabs >> 1; + + if (dxabs >= dyabs) { + /* the line is more horizontal than vertical */ + for (i = 0; i < dxabs; i++) { + *pvideo = ent; - if (dx >= 0) - pvideo = get_xy_loc(nsfb, line->x0, line->y0); - else - pvideo = get_xy_loc(nsfb, line->x1, line->y1); - - x = dyabs >> 1; - y = dxabs >> 1; - - if (dxabs >= dyabs) { - /* the line is more horizontal than vertical */ - for (i = 0; i < dxabs; i++) { - *pvideo = ent; - - pvideo++; - y += dyabs; - if (y >= dxabs) { - y -= dxabs; - pvideo += sdy * (nsfb->linelen>>2); - } - } - } else { - /* the line is more vertical than horizontal */ - for (i = 0; i < dyabs; i++) { - *pvideo = ent; - pvideo += sdy * (nsfb->linelen >> 2); - - x += dxabs; - if (x >= dyabs) { - x -= dyabs; pvideo++; + y += dyabs; + if (y >= dxabs) { + y -= dxabs; + pvideo += sdy * (nsfb->linelen>>2); + } + } + } else { + /* the line is more vertical than horizontal */ + for (i = 0; i < dyabs; i++) { + *pvideo = ent; + pvideo += sdy * (nsfb->linelen >> 2); + + x += dxabs; + if (x >= dyabs) { + x -= dyabs; + pvideo++; + } } } - } + } + line++; } - - return true; + return true; } @@ -182,7 +186,7 @@ static bool fill(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t c) pvid += llen; } - return true; + return true; } @@ -208,7 +212,7 @@ static bool point(nsfb_t *nsfb, int x, int y, nsfb_colour_t c) *pvideo = colour_to_pixel(c); } - return true; + return true; } static bool @@ -220,7 +224,7 @@ glyph1(nsfb_t *nsfb, { uint32_t *pvideo; int xloop, yloop; - int xoff, yoff; /* x and y offset into image */ + int xoff, yoff; /* x and y offset into image */ int x = loc->x0; int y = loc->y0; int width = loc->x1 - loc->x0; @@ -238,8 +242,8 @@ glyph1(nsfb_t *nsfb, if (width > (loc->x1 - loc->x0)) width = (loc->x1 - loc->x0); - xoff = loc->x0 - x; - yoff = loc->y0 - y; + xoff = loc->x0 - x; + yoff = loc->y0 - y; pvideo = get_xy_loc(nsfb, loc->x0, loc->y0); @@ -263,7 +267,7 @@ glyph1(nsfb_t *nsfb, pvideo += (nsfb->linelen >> 2); } - return true; + return true; } static bool @@ -276,7 +280,7 @@ glyph8(nsfb_t *nsfb, uint32_t *pvideo; nsfb_colour_t abpixel; /* alphablended pixel */ int xloop, yloop; - int xoff, yoff; /* x and y offset into image */ + int xoff, yoff; /* x and y offset into image */ int x = loc->x0; int y = loc->y0; int width = loc->x1 - loc->x0; @@ -292,8 +296,8 @@ glyph8(nsfb_t *nsfb, if (width > (loc->x1 - loc->x0)) width = (loc->x1 - loc->x0); - xoff = loc->x0 - x; - yoff = loc->y0 - y; + xoff = loc->x0 - x; + yoff = loc->y0 - y; pvideo = get_xy_loc(nsfb, loc->x0, loc->y0); @@ -315,7 +319,7 @@ glyph8(nsfb_t *nsfb, pvideo += (nsfb->linelen >> 2); } - return true; + return true; } static bool @@ -330,7 +334,7 @@ bitmap(nsfb_t *nsfb, uint32_t *pvideo; nsfb_colour_t abpixel = 0; /* alphablended pixel */ int xloop, yloop; - int xoff, yoff; /* x and y offset into image */ + int xoff, yoff; /* x and y offset into image */ int x = loc->x0; int y = loc->y0; int width = loc->x1 - loc->x0; @@ -364,9 +368,9 @@ bitmap(nsfb_t *nsfb, if (width > (clipped.x1 - clipped.x0)) width = (clipped.x1 - clipped.x0); - xoff = clipped.x0 - x; - yoff = (clipped.y0 - y) * bmp_width; - height = height * bmp_stride + yoff; + xoff = clipped.x0 - x; + yoff = (clipped.y0 - y) * bmp_width; + height = height * bmp_stride + yoff; /* plot the image */ pvideo = get_xy_loc(nsfb, clipped.x0, clipped.y0); @@ -395,7 +399,7 @@ bitmap(nsfb_t *nsfb, pvideo += (nsfb->linelen >> 2); } } - return true; + return true; } static bool readrect(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t *buffer) @@ -423,8 +427,8 @@ static bool readrect(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t *buffer) } const nsfb_plotter_fns_t _nsfb_32bpp_plotters = { - .line = line, - .fill = fill, + .line = line, + .fill = fill, .point = point, .bitmap = bitmap, .glyph8 = glyph8, diff --git a/src/8bpp_plotters.c b/src/8bpp_plotters.c index 307e4a7..ec72174 100644 --- a/src/8bpp_plotters.c +++ b/src/8bpp_plotters.c @@ -13,6 +13,7 @@ #include #include "libnsfb.h" +#include "libnsfb_plot.h" #include "libnsfb_plot_util.h" #include "nsfb.h" @@ -61,12 +62,7 @@ colour_to_pixel(nsfb_t *nsfb, nsfb_colour_t c) #define SIGN(x) ((x<0) ? -1 : ((x>0) ? 1 : 0)) static bool -line(nsfb_t *nsfb, - nsfb_bbox_t *line, - int line_width, - nsfb_colour_t c, - bool dotted, - bool dashed) +line(nsfb_t *nsfb, int linec, nsfb_bbox_t *line, nsfb_plot_pen_t *pen) { int w; uint8_t ent; @@ -75,76 +71,83 @@ line(nsfb_t *nsfb, int dx, dy, sdy; int dxabs, dyabs; - line_width = line_width; - dotted = dotted; - dashed = dashed; + ent = colour_to_pixel(nsfb, pen->stroke_colour); - ent = colour_to_pixel(nsfb, c); + for (;linec > 0; linec--) { + + if (line->y0 == line->y1) { + /* horizontal line special cased */ - if (line->y0 == line->y1) { - /* horizontal line special cased */ - if (!nsfb_plot_clip_ctx(nsfb, line)) - return true; /* line outside clipping */ + if (!nsfb_plot_clip_ctx(nsfb, line)) { + /* line outside clipping */ + line++; + continue; + } - pvideo = get_xy_loc(nsfb, line->x0, line->y0); + pvideo = get_xy_loc(nsfb, line->x0, line->y0); - w = line->x1 - line->x0; - while (w-- > 0) - *(pvideo + w) = ent; + w = line->x1 - line->x0; + while (w-- > 0) + *(pvideo + w) = ent; - return true; - } else { - /* standard bresenham line */ - if (!nsfb_plot_clip_line_ctx(nsfb, line)) - return true; /* line outside clipping */ + } else { + /* standard bresenham line */ - /* the horizontal distance of the line */ - dx = line->x1 - line->x0; - dxabs = abs (dx); + if (!nsfb_plot_clip_line_ctx(nsfb, line)) { + /* line outside clipping */ + line++; + continue; + } - /* the vertical distance of the line */ - dy = line->y1 - line->y0; - dyabs = abs (dy); + /* the horizontal distance of the line */ + dx = line->x1 - line->x0; + dxabs = abs (dx); - sdy = dx ? SIGN(dy) * SIGN(dx) : SIGN(dy); + /* the vertical distance of the line */ + dy = line->y1 - line->y0; + dyabs = abs (dy); - if (dx >= 0) - pvideo = get_xy_loc(nsfb, line->x0, line->y0); - else - pvideo = get_xy_loc(nsfb, line->x1, line->y1); + sdy = dx ? SIGN(dy) * SIGN(dx) : SIGN(dy); - x = dyabs >> 1; - y = dxabs >> 1; + if (dx >= 0) + pvideo = get_xy_loc(nsfb, line->x0, line->y0); + else + pvideo = get_xy_loc(nsfb, line->x1, line->y1); - if (dxabs >= dyabs) { - /* the line is more horizontal than vertical */ - for (i = 0; i < dxabs; i++) { - *pvideo = ent; + x = dyabs >> 1; + y = dxabs >> 1; + + if (dxabs >= dyabs) { + /* the line is more horizontal than vertical */ + for (i = 0; i < dxabs; i++) { + *pvideo = ent; - pvideo++; - y += dyabs; - if (y >= dxabs) { - y -= dxabs; - pvideo += sdy * nsfb->linelen; - } - } - } else { - /* the line is more vertical than horizontal */ - for (i = 0; i < dyabs; i++) { - *pvideo = ent; - pvideo += sdy * nsfb->linelen; - - x += dxabs; - if (x >= dyabs) { - x -= dyabs; pvideo++; + y += dyabs; + if (y >= dxabs) { + y -= dxabs; + pvideo += sdy * nsfb->linelen; + } + } + } else { + /* the line is more vertical than horizontal */ + for (i = 0; i < dyabs; i++) { + *pvideo = ent; + pvideo += sdy * nsfb->linelen; + + x += dxabs; + if (x >= dyabs) { + x -= dyabs; + pvideo++; + } } } - } + } + line++; } - return true; + return true; } static bool fill(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t c) @@ -165,7 +168,7 @@ static bool fill(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t c) pvideo += nsfb->linelen; } - return true; + return true; } static bool point(nsfb_t *nsfb, int x, int y, nsfb_colour_t c) @@ -188,7 +191,7 @@ static bool point(nsfb_t *nsfb, int x, int y, nsfb_colour_t c) *pvideo = colour_to_pixel(nsfb, c); } - return true; + return true; } static bool @@ -200,7 +203,7 @@ glyph1(nsfb_t *nsfb, { uint8_t *pvideo; int xloop, yloop; - int xoff, yoff; /* x and y offset into image */ + int xoff, yoff; /* x and y offset into image */ int x = loc->x0; int y = loc->y0; int width = loc->x1 - loc->x0; @@ -218,8 +221,8 @@ glyph1(nsfb_t *nsfb, if (width > (loc->x1 - loc->x0)) width = (loc->x1 - loc->x0); - xoff = loc->x0 - x; - yoff = loc->y0 - y; + xoff = loc->x0 - x; + yoff = loc->y0 - y; pvideo = get_xy_loc(nsfb, loc->x0, loc->y0); @@ -243,7 +246,7 @@ glyph1(nsfb_t *nsfb, pvideo += nsfb->linelen; } - return true; + return true; } static bool @@ -256,7 +259,7 @@ glyph8(nsfb_t *nsfb, uint8_t *pvideo; nsfb_colour_t abpixel; /* alphablended pixel */ int xloop, yloop; - int xoff, yoff; /* x and y offset into image */ + int xoff, yoff; /* x and y offset into image */ int x = loc->x0; int y = loc->y0; int width = loc->x1 - loc->x0; @@ -272,8 +275,8 @@ glyph8(nsfb_t *nsfb, if (width > (loc->x1 - loc->x0)) width = (loc->x1 - loc->x0); - xoff = loc->x0 - x; - yoff = loc->y0 - y; + xoff = loc->x0 - x; + yoff = loc->y0 - y; pvideo = get_xy_loc(nsfb, loc->x0, loc->y0); @@ -295,7 +298,7 @@ glyph8(nsfb_t *nsfb, pvideo += nsfb->linelen; } - return true; + return true; } static bool @@ -310,7 +313,7 @@ bitmap(nsfb_t *nsfb, uint8_t *pvideo; nsfb_colour_t abpixel = 0; /* alphablended pixel */ int xloop, yloop; - int xoff, yoff; /* x and y offset into image */ + int xoff, yoff; /* x and y offset into image */ int x = loc->x0; int y = loc->y0; int width = loc->x1 - loc->x0; @@ -343,9 +346,9 @@ bitmap(nsfb_t *nsfb, if (width > (clipped.x1 - clipped.x0)) width = (clipped.x1 - clipped.x0); - xoff = clipped.x0 - x; - yoff = (clipped.y0 - y) * bmp_width; - height = height * bmp_stride + yoff; + xoff = clipped.x0 - x; + yoff = (clipped.y0 - y) * bmp_width; + height = height * bmp_stride + yoff; /* plot the image */ pvideo = get_xy_loc(nsfb, clipped.x0, clipped.y0); @@ -374,7 +377,7 @@ bitmap(nsfb_t *nsfb, pvideo += nsfb->linelen; } } - return true; + return true; } @@ -383,8 +386,8 @@ bitmap(nsfb_t *nsfb, const nsfb_plotter_fns_t _nsfb_8bpp_plotters = { - .line = line, - .fill = fill, + .line = line, + .fill = fill, .point = point, .bitmap = bitmap, .glyph8 = glyph8, diff --git a/src/Makefile b/src/Makefile index af1c780..9774acd 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,5 @@ # Sources -DIR_SOURCES := libnsfb.c frontend.c frontend_sdl.c frontend_linux.c frontend_vnc.c frontend_able.c frontend_ram.c cursor.c plot.c legacy_plot.c plot_util.c plotters.c 32bpp_plotters.c 16bpp_plotters.c 8bpp_plotters.c +DIR_SOURCES := libnsfb.c frontend.c frontend_sdl.c frontend_linux.c frontend_vnc.c frontend_able.c frontend_ram.c cursor.c plot.c plot_util.c plotters.c 32bpp_plotters.c 16bpp_plotters.c 8bpp_plotters.c include build/makefiles/Makefile.subdir diff --git a/src/frontend.c b/src/frontend.c index 1390163..630def9 100644 --- a/src/frontend.c +++ b/src/frontend.c @@ -45,7 +45,7 @@ static int frontend_defaults(nsfb_t *nsfb) { nsfb->width = 800; nsfb->height = 600; - nsfb->bpp = 16; + nsfb->bpp = 32; /* select default sw plotters for bpp */ select_plotters(nsfb); diff --git a/src/frontend_able.c b/src/frontend_able.c index 0e92104..d7b9226 100644 --- a/src/frontend_able.c +++ b/src/frontend_able.c @@ -10,6 +10,7 @@ #include #include "libnsfb.h" +#include "libnsfb_plot.h" #include "libnsfb_event.h" #include "nsfb.h" #include "frontend.h" diff --git a/src/frontend_linux.c b/src/frontend_linux.c index ce34cec..d80fc43 100644 --- a/src/frontend_linux.c +++ b/src/frontend_linux.c @@ -11,6 +11,7 @@ #include "libnsfb.h" #include "libnsfb_event.h" +#include "libnsfb_plot.h" #include "nsfb.h" #include "frontend.h" #include "plotters.h" diff --git a/src/frontend_ram.c b/src/frontend_ram.c index 82cb29b..0948a5d 100644 --- a/src/frontend_ram.c +++ b/src/frontend_ram.c @@ -10,6 +10,7 @@ #include #include "libnsfb.h" +#include "libnsfb_plot.h" #include "libnsfb_event.h" #include "nsfb.h" #include "frontend.h" diff --git a/src/frontend_sdl.c b/src/frontend_sdl.c index d40eb7b..359728c 100644 --- a/src/frontend_sdl.c +++ b/src/frontend_sdl.c @@ -12,6 +12,7 @@ #include "libnsfb.h" #include "libnsfb_event.h" +#include "libnsfb_plot.h" #include "libnsfb_plot_util.h" #include "nsfb.h" diff --git a/src/frontend_vnc.c b/src/frontend_vnc.c index 46040b2..eb6d6ff 100644 --- a/src/frontend_vnc.c +++ b/src/frontend_vnc.c @@ -11,6 +11,7 @@ #include "libnsfb.h" #include "libnsfb_event.h" +#include "libnsfb_plot.h" #include "nsfb.h" #include "frontend.h" diff --git a/src/legacy_plot.c b/src/legacy_plot.c deleted file mode 100644 index fc7a7ef..0000000 --- a/src/legacy_plot.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2009 Vincent Sanders - * - * This file is part of libnsfb, http://www.netsurf-browser.org/ - * Licenced under the MIT License, - * http://www.opensource.org/licenses/mit-license.php - * - * This is the exported plotter interface for the libnsfb graphics library. - */ - -#include - -#include "libnsfb.h" -#include "libnsfb_plot.h" -#include "libnsfb_legacy_plot.h" -#include "nsfb.h" -#include "nsfb_plot.h" - -/* legacy interface global context */ -static nsfb_t *gnsfb; - -bool nsfb_lplot_ctx(nsfb_t *nsfb) -{ - gnsfb = nsfb; - return true; -} - -bool nsfb_lplot_clip(int x0, int y0, int x1, int y1) -{ - nsfb_bbox_t clip; - clip.x0 = x0; - clip.y0 = y0; - clip.x1 = x1; - clip.y1 = y1; - - return gnsfb->plotter_fns->set_clip(gnsfb, &clip); -} - -bool nsfb_lplot_line(int x0, int y0, int x1, int y1, int line_width, - nsfb_colour_t c, bool dotted, bool dashed) -{ - nsfb_bbox_t line; - line.x0 = x0; - line.y0 = y0; - line.x1 = x1; - line.y1 = y1; - return gnsfb->plotter_fns->line(gnsfb, &line, line_width, c, dotted, dashed); -} - -bool nsfb_lplot_rectangle(int x0, - int y0, - int width, - int height, - int line_width, - nsfb_colour_t c, - bool dotted, - bool dashed) -{ - nsfb_bbox_t rect; - rect.x0 = x0; - rect.y0 = y0; - rect.x1 = x0 + width; - rect.y1 = y0 + height; - - return gnsfb->plotter_fns->rectangle(gnsfb, &rect, line_width, c, dotted, dashed); - -} - -bool nsfb_lplot_polygon(const int *p, unsigned int n, nsfb_colour_t fillc) -{ - return gnsfb->plotter_fns->polygon(gnsfb, p, n, fillc); -} - -bool nsfb_lplot_fill(int x0, int y0, int x1, int y1, nsfb_colour_t c) -{ - nsfb_bbox_t rect; - rect.x0 = x0; - rect.y0 = y0; - rect.x1 = x1; - rect.y1 = y1; - - return gnsfb->plotter_fns->fill(gnsfb, &rect, c); -} - -bool nsfb_lplot_clg(nsfb_colour_t c) -{ - return gnsfb->plotter_fns->clg(gnsfb, c); -} - - -bool -nsfb_lplot_disc(int x, int y, int radius, nsfb_colour_t c, bool filled) -{ - nsfb_bbox_t ellipse; - ellipse.x0 = x - radius; - ellipse.y0 = y - radius; - ellipse.x1 = x + radius; - ellipse.y1 = y + radius; - - if (filled) - return gnsfb->plotter_fns->ellipse_fill(gnsfb, &ellipse, c); - else - return gnsfb->plotter_fns->ellipse(gnsfb, &ellipse, c); -} - -bool -nsfb_lplot_arc(int x, int y, int radius, int angle1, int angle2, - nsfb_colour_t c) -{ - return gnsfb->plotter_fns->arc(gnsfb, x, y, radius, angle1, angle2, c); -} - - - diff --git a/src/libnsfb.c b/src/libnsfb.c index b3a1903..781eaab 100644 --- a/src/libnsfb.c +++ b/src/libnsfb.c @@ -11,6 +11,7 @@ #include #include "libnsfb.h" +#include "libnsfb_plot.h" #include "libnsfb_event.h" #include "nsfb.h" #include "frontend.h" diff --git a/src/plot.c b/src/plot.c index 6303127..90404cc 100644 --- a/src/plot.c +++ b/src/plot.c @@ -63,9 +63,19 @@ bool nsfb_plot_rectangle_fill(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t c) * Draw a line from (x0,y0) to (x1,y1). Coordinates are at centre of line * width/thickness. */ -bool nsfb_plot_line(nsfb_t *nsfb, nsfb_bbox_t *line, int line_width, nsfb_colour_t c, bool dotted, bool dashed) +bool nsfb_plot_line(nsfb_t *nsfb, nsfb_bbox_t *line, nsfb_plot_pen_t *pen) { - return nsfb->plotter_fns->line(nsfb, line, line_width, c, dotted, dashed); + return nsfb->plotter_fns->line(nsfb, 1, line, pen); +} + +/** Plots more than one line. + * + * Draw a line from (x0,y0) to (x1,y1). Coordinates are at centre of line + * width/thickness. + */ +bool nsfb_plot_lines(nsfb_t *nsfb, int linec, nsfb_bbox_t *line, nsfb_plot_pen_t *pen) +{ + return nsfb->plotter_fns->line(nsfb, linec, line, pen); } /** Plots a filled polygon. diff --git a/src/plot_util.c b/src/plot_util.c index c30597b..cf2ec9b 100644 --- a/src/plot_util.c +++ b/src/plot_util.c @@ -1,6 +1,7 @@ #include #include "libnsfb.h" +#include "libnsfb_plot.h" #include "libnsfb_plot_util.h" #include "nsfb.h" diff --git a/src/plotters.c b/src/plotters.c index 60826d3..91c3b7b 100644 --- a/src/plotters.c +++ b/src/plotters.c @@ -17,6 +17,7 @@ #include #include "libnsfb.h" +#include "libnsfb_plot.h" #include "libnsfb_plot_util.h" #include "nsfb.h" @@ -155,7 +156,8 @@ static bool find_span(const int *p, int n, int x, int y, int *x0, int *x1) * \param c fill colour * \return true if no errors */ -static bool polygon(nsfb_t *nsfb, const int *p, unsigned int n, nsfb_colour_t c) +static bool +polygon(nsfb_t *nsfb, const int *p, unsigned int n, nsfb_colour_t c) { int poly_x0, poly_y0; /* Bounding box top left corner */ int poly_x1, poly_y1; /* Bounding box bottom right corner */ @@ -164,6 +166,7 @@ static bool polygon(nsfb_t *nsfb, const int *p, unsigned int n, nsfb_colour_t c) int y; /* current y coordinate */ int y_max; /* bottom of plot area */ nsfb_bbox_t fline; + nsfb_plot_pen_t pen; /* find no. of vertex values */ int v = n * 2; @@ -172,6 +175,8 @@ static bool polygon(nsfb_t *nsfb, const int *p, unsigned int n, nsfb_colour_t c) if (n <= 2) return true; + pen.stroke_colour = c; + /* Find polygon bounding box */ poly_x0 = poly_x1 = *p; poly_y0 = poly_y1 = p[1]; @@ -226,8 +231,7 @@ static bool polygon(nsfb_t *nsfb, const int *p, unsigned int n, nsfb_colour_t c) fline.y1 = y; /* draw this filled span on current row */ - nsfb->plotter_fns->line(nsfb, &fline, 1, c, false, - false); + nsfb->plotter_fns->line(nsfb, 1, &fline, &pen); /* don't look for more spans if already at end of clip * region or polygon */ @@ -241,35 +245,38 @@ static bool polygon(nsfb_t *nsfb, const int *p, unsigned int n, nsfb_colour_t c) return true; } -static bool rectangle(nsfb_t *nsfb, nsfb_bbox_t *rect, - int line_width, nsfb_colour_t c, - bool dotted, bool dashed) +static bool +rectangle(nsfb_t *nsfb, nsfb_bbox_t *rect, + int line_width, nsfb_colour_t c, + bool dotted, bool dashed) { - nsfb_bbox_t side; - - side = *rect; - side.y1 = side.y0; - - nsfb->plotter_fns->line(nsfb, &side, line_width, c, dotted, dashed); - - side = *rect; - side.y0 = side.y1; + nsfb_bbox_t side[4]; + nsfb_plot_pen_t pen; - nsfb->plotter_fns->line(nsfb, &side, line_width, c, dotted, dashed); - - side = *rect; - side.x1 = side.x0; + pen.stroke_colour = c; + pen.stroke_width = line_width; + if (dotted || dashed) { + pen.stroke_type = NFSB_PLOT_OPTYPE_PATTERN; + } else { + pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID; + } - nsfb->plotter_fns->line(nsfb, &side, line_width, c, dotted, dashed); + side[0] = *rect; + side[1] = *rect; + side[2] = *rect; + side[3] = *rect; - side = *rect; - side.x0 = side.x1; + side[0].y1 = side[0].y0; + side[1].y0 = side[1].y1; + side[2].x1 = side[2].x0; + side[3].x0 = side[3].x1; - return nsfb->plotter_fns->line(nsfb, &side, line_width, c, dotted, dashed); + return nsfb->plotter_fns->line(nsfb, 4, side, &pen); } /* plotter routine for ellipse points */ -static void ellipsepoints(nsfb_t *nsfb, int cx, int cy, int x, int y, nsfb_colour_t c) +static void +ellipsepoints(nsfb_t *nsfb, int cx, int cy, int x, int y, nsfb_colour_t c) { nsfb->plotter_fns->point(nsfb, cx + x, cy + y, c); nsfb->plotter_fns->point(nsfb, cx - x, cy + y, c); @@ -277,30 +284,33 @@ static void ellipsepoints(nsfb_t *nsfb, int cx, int cy, int x, int y, nsfb_colou nsfb->plotter_fns->point(nsfb, cx - x, cy - y, c); } -static void ellipsefill(nsfb_t *nsfb, int cx, int cy, int x, int y, nsfb_colour_t c) +static void +ellipsefill(nsfb_t *nsfb, int cx, int cy, int x, int y, nsfb_colour_t c) { - nsfb_bbox_t fline; - fline.x0 = cx - x; - fline.x1 = cx + x; - fline.y0 = fline.y1 = cy + y; - nsfb->plotter_fns->line(nsfb, &fline, 1, c, false, false); + nsfb_bbox_t fline[2]; + nsfb_plot_pen_t pen; + + pen.stroke_colour = c; + + fline[0].x0 = fline[1].x0 = cx - x; + fline[0].x1 = fline[1].x1 = cx + x; + fline[0].y0 = fline[0].y1 = cy + y; + fline[1].y0 = fline[1].y1 = cy - y; - fline.x0 = cx - x; - fline.x1 = cx + x; - fline.y0 = fline.y1 = cy - y; - nsfb->plotter_fns->line(nsfb, &fline, 1, c, false, false); + nsfb->plotter_fns->line(nsfb, 2, fline, &pen); } #define ROUND(a) ((int)(a+0.5)) -static bool ellipse_midpoint(nsfb_t *nsfb, - int cx, - int cy, - int rx, - int ry, - nsfb_colour_t c, - void (ellipsefn)(nsfb_t *nsfb, int cx, int cy, int x, int y, nsfb_colour_t c)) +static bool +ellipse_midpoint(nsfb_t *nsfb, + int cx, + int cy, + int rx, + int ry, + nsfb_colour_t c, + void (ellipsefn)(nsfb_t *nsfb, int cx, int cy, int x, int y, nsfb_colour_t c)) { int rx2 = rx * rx; int ry2 = ry * ry; @@ -348,7 +358,8 @@ static bool ellipse_midpoint(nsfb_t *nsfb, /* plotter routine for 8way circle symetry */ -static void circlepoints(nsfb_t *nsfb, int cx, int cy, int x, int y, nsfb_colour_t c) +static void +circlepoints(nsfb_t *nsfb, int cx, int cy, int x, int y, nsfb_colour_t c) { nsfb->plotter_fns->point(nsfb, cx + x, cy + y, c); nsfb->plotter_fns->point(nsfb, cx - x, cy + y, c); @@ -360,28 +371,25 @@ static void circlepoints(nsfb_t *nsfb, int cx, int cy, int x, int y, nsfb_colour nsfb->plotter_fns->point(nsfb, cx - y, cy - x, c); } -static void circlefill(nsfb_t *nsfb, int cx, int cy, int x, int y, nsfb_colour_t c) +static void +circlefill(nsfb_t *nsfb, int cx, int cy, int x, int y, nsfb_colour_t c) { - nsfb_bbox_t fline; - fline.x0 = cx - x; - fline.x1 = cx + x; - fline.y0 = fline.y1 = cy + y; - nsfb->plotter_fns->line(nsfb, &fline, 1, c, false, false); - - fline.x0 = cx - x; - fline.x1 = cx + x; - fline.y0 = fline.y1 = cy - y; - nsfb->plotter_fns->line(nsfb, &fline, 1, c, false, false); - - fline.x0 = cx - y; - fline.x1 = cx + y; - fline.y0 = fline.y1 = cy + x; - nsfb->plotter_fns->line(nsfb, &fline, 1, c, false, false); - - fline.x0 = cx - y; - fline.x1 = cx + y; - fline.y0 = fline.y1 = cy - x; - nsfb->plotter_fns->line(nsfb, &fline, 1, c, false, false); + nsfb_bbox_t fline[4]; + nsfb_plot_pen_t pen; + + pen.stroke_colour = c; + + fline[0].x0 = fline[1].x0 = cx - x; + fline[0].x1 = fline[1].x1 = cx + x; + fline[0].y0 = fline[0].y1 = cy + y; + fline[1].y0 = fline[1].y1 = cy - y; + + fline[2].x0 = fline[3].x0 = cx - y; + fline[2].x1 = fline[3].x1 = cx + y; + fline[2].y0 = fline[2].y1 = cy + x; + fline[3].y0 = fline[3].y1 = cy - x; + + nsfb->plotter_fns->line(nsfb, 4, fline, &pen); } static bool circle_midpoint(nsfb_t *nsfb, @@ -508,9 +516,11 @@ static bool arc(nsfb_t *nsfb, int x, int y, int radius, int angle1, int angle2, #define N_SEG 30 -static bool cubic(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_point_t *ctrlb, nsfb_colour_t cl) +static bool +cubic(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_point_t *ctrlb, nsfb_colour_t cl) { nsfb_bbox_t line; + nsfb_plot_pen_t pen; unsigned int seg_loop; double t; @@ -522,6 +532,8 @@ static bool cubic(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_po double x; double y; + pen.stroke_colour = cl; + x = curve->x0; y = curve->y0; @@ -544,7 +556,7 @@ static bool cubic(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_po line.x1 = x; line.y1 = y; - nsfb->plotter_fns->line(nsfb, &line, 1, cl, false, false); + nsfb->plotter_fns->line(nsfb, 1, &line, &pen); } return true; @@ -553,6 +565,7 @@ static bool cubic(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_po static bool quadratic(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_colour_t cl) { nsfb_bbox_t line; + nsfb_plot_pen_t pen; unsigned int seg_loop; double t; @@ -563,6 +576,8 @@ static bool quadratic(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsf double x; double y; + pen.stroke_colour = cl; + x = curve->x0; y = curve->y0; @@ -584,7 +599,7 @@ static bool quadratic(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsf line.x1 = x; line.y1 = y; - nsfb->plotter_fns->line(nsfb, &line, 1, cl, false, false); + nsfb->plotter_fns->line(nsfb, 1, &line, &pen); } return true; @@ -592,7 +607,7 @@ static bool quadratic(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsf bool select_plotters(nsfb_t *nsfb) { - const nsfb_plotter_fns_t *table; + const nsfb_plotter_fns_t *table = NULL; switch (nsfb->bpp) { /* case 1: diff --git a/test/bezier.c b/test/bezier.c index d44779b..c523da8 100644 --- a/test/bezier.c +++ b/test/bezier.c @@ -22,6 +22,7 @@ int main(int argc, char **argv) nsfb_point_t ctrla; nsfb_point_t ctrlb; int loop; + nsfb_plot_pen_t pen; UNUSED(argc); UNUSED(argv); @@ -64,6 +65,7 @@ int main(int argc, char **argv) nsfb_plot_cubic_bezier(nsfb, &box2, &ctrla, &ctrlb, 0xff000000); } + pen.stroke_colour = 0xff000000; box2.x0=400; box2.y0=100; @@ -71,7 +73,7 @@ int main(int argc, char **argv) box2.x1=600; box2.y1=400; - nsfb_plot_line(nsfb, &box2, 1, 0xff000000, false, false); + nsfb_plot_line(nsfb, &box2, &pen); box2.x0=800; box2.y0=100; @@ -79,7 +81,7 @@ int main(int argc, char **argv) box2.x1=600; box2.y1=400; - nsfb_plot_line(nsfb, &box2, 1, 0xff000000, false, false); + nsfb_plot_line(nsfb, &box2, &pen); box2.x0=400; box2.y0=100; diff --git a/test/plottest.c b/test/plottest.c index 3fc4d83..8be921e 100644 --- a/test/plottest.c +++ b/test/plottest.c @@ -78,6 +78,7 @@ int main(int argc, char **argv) int fbstride; int p[] = { 300,300, 350,350, 400,300, 450,250, 400,200}; int loop; + nsfb_plot_pen_t pen; UNUSED(argc); UNUSED(argv); @@ -109,36 +110,40 @@ int main(int argc, char **argv) nsfb_plot_clg(nsfb, 0xffffff00 | loop); } - /* draw radial lines from the origin */ + /* draw black radial lines from the origin */ + pen.stroke_colour = 0xff000000; for (loop = 0; loop < box.x1; loop += 20) { box2 = box; box2.x1 = loop; - nsfb_plot_line(nsfb, &box2, 1, 0xff000000, false, false); + nsfb_plot_line(nsfb, &box2, &pen); } - /* draw radial lines from the bottom right */ + /* draw blue radial lines from the bottom right */ + pen.stroke_colour = 0xffff0000; for (loop = 0; loop < box.x1; loop += 20) { box2 = box; box2.x0 = loop; - nsfb_plot_line(nsfb, &box2, 1, 0xffff0000, false, false); + nsfb_plot_line(nsfb, &box2, &pen); } - /* draw radial lines from the bottom left */ + /* draw green radial lines from the bottom left */ + pen.stroke_colour = 0xff00ff00; for (loop = 0; loop < box.x1; loop += 20) { box2.x0 = box.x0; box2.x1 = loop; box2.y0 = box.y1; box2.y1 = box.y0; - nsfb_plot_line(nsfb, &box2, 1, 0xff00ff00, false, false); + nsfb_plot_line(nsfb, &box2, &pen); } - /* draw radial lines from the top right */ + /* draw red radial lines from the top right */ + pen.stroke_colour = 0xff0000ff; for (loop = 0; loop < box.x1; loop += 20) { box2.x0 = box.x1; box2.x1 = loop; box2.y0 = box.y0; box2.y1 = box.y1; - nsfb_plot_line(nsfb, &box2, 1, 0xff0000ff, false, false); + nsfb_plot_line(nsfb, &box2, &pen); } /* draw an unclipped rectangle */ -- cgit v1.2.3