diff options
Diffstat (limited to 'src/8bpp_plotters.c')
-rw-r--r-- | src/8bpp_plotters.c | 153 |
1 files changed, 78 insertions, 75 deletions
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 <string.h> #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, |