summaryrefslogtreecommitdiff
path: root/src/32bpp_plotters.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/32bpp_plotters.c')
-rw-r--r--src/32bpp_plotters.c158
1 files changed, 81 insertions, 77 deletions
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 <stdlib.h>
#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,