summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libnsfb_event.h2
-rw-r--r--src/24bpp_plotters.c469
-rw-r--r--src/Makefile4
-rw-r--r--src/frontend_linux.c68
-rw-r--r--src/plot/16bpp.c (renamed from src/16bpp_plotters.c)24
-rw-r--r--src/plot/1bpp.c (renamed from src/1bpp_plotters.c)0
-rw-r--r--src/plot/24bpp.c442
-rw-r--r--src/plot/32bpp.c (renamed from src/32bpp_plotters.c)0
-rw-r--r--src/plot/8bpp.c (renamed from src/8bpp_plotters.c)24
-rw-r--r--src/plot/Makefile4
-rw-r--r--src/plot/api.c (renamed from src/plot.c)0
-rw-r--r--src/plot/generic.c (renamed from src/plotters.c)0
-rw-r--r--src/plot/util.c (renamed from src/plot_util.c)0
-rw-r--r--test/plottest.c16
14 files changed, 578 insertions, 475 deletions
diff --git a/include/libnsfb_event.h b/include/libnsfb_event.h
index 5ad80f9..ea2b2bf 100644
--- a/include/libnsfb_event.h
+++ b/include/libnsfb_event.h
@@ -8,8 +8,8 @@ enum nsfb_event_type_e {
};
+/** keycodes which mostly map to ascii chars */
enum nsfb_key_code_e {
- /* keycodes which map to ascii chars */
NSFB_KEY_UNKNOWN = 0,
NSFB_KEY_BACKSPACE = 8,
NSFB_KEY_TAB = 9,
diff --git a/src/24bpp_plotters.c b/src/24bpp_plotters.c
deleted file mode 100644
index 777b896..0000000
--- a/src/24bpp_plotters.c
+++ /dev/null
@@ -1,469 +0,0 @@
-/*
- * Copyright 2008 Vincent Sanders <vince@simtec.co.uk>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <sys/types.h>
-#include <stdint.h>
-#include <string.h>
-#include <limits.h>
-
-#include "utils/log.h"
-#include "utils/utf8.h"
-#include "desktop/plotters.h"
-
-#include "framebuffer/fb_gui.h"
-#include "framebuffer/fb_plotters.h"
-#include "framebuffer/fb_bitmap.h"
-#include "framebuffer/fb_font.h"
-
-static inline uint8_t *
-fb_8bpp_get_xy_loc(int x, int y)
-{
- return (uint8_t *)(framebuffer->ptr +
- (y * framebuffer->linelen) +
- (x));
-}
-
-
-static bool fb_8bpp_line(int x0, int y0, int x1, int y1, int width,
- colour c, bool dotted, bool dashed)
-{
- LOG(("%d, %d, %d, %d, %d, 0x%lx, %d, %d",
- x0, y0, x1, y1, width, (unsigned long)c, dotted, dashed));
-
- return true;
-}
-
-static bool fb_8bpp_rectangle(int x0, int y0, int width, int height,
- int line_width, colour c, bool dotted, bool dashed)
-{
- fb_8bpp_line(x0, y0, x0 + width, y0, line_width, c, dotted, dashed);
- fb_8bpp_line(x0, y0 + height, x0 + width, y0 + height, line_width, c, dotted, dashed);
- fb_8bpp_line(x0, y0, x0, y0 + height, line_width, c, dotted, dashed);
- fb_8bpp_line(x0 + width, y0, x0 + width, y0 + height, line_width, c, dotted, dashed);
- return true;
-}
-
-static bool fb_8bpp_polygon(const int *p, unsigned int n, colour fill)
-{
- /*LOG(("%p, %d, 0x%lx", p,n,fill));*/
- return fb_plotters_polygon(p, n, fill, fb_8bpp_line);
-}
-
-static colour calc_colour(uint8_t c)
-{
- return framebuffer->palette[c];
-}
-
-
-static int
-find_closest_palette_entry(colour c)
-{
- colour palent;
- int col;
-
- int dr, dg, db; /* delta red, green blue values */
-
- int cur_distance;
- int best_distance = INT_MAX;
- int best_col = 0;
-
- for (col = 0; col < 256; col++) {
- palent = framebuffer->palette[col];
-
- dr = (c & 0xFF) - (palent & 0xFF);
- dg = ((c >> 8) & 0xFF) - ((palent >> 8) & 0xFF);
- db = ((c >> 16) & 0xFF) - ((palent >> 16) & 0xFF);
- cur_distance = ((dr * dr) + (dg * dg) + (db *db));
- if (cur_distance < best_distance) {
- best_distance = cur_distance;
- best_col = col;
- }
- }
-
- return best_col;
-}
-
-static inline uint8_t fb_colour_to_pixel(colour c)
-{
- return find_closest_palette_entry(c);
-}
-
-static inline colour fb_8bpp_to_colour(uint8_t pixel)
-{
- return framebuffer->palette[pixel];
-}
-
-static bool fb_8bpp_fill(int x0, int y0, int x1, int y1, colour c)
-{
- int y;
- uint8_t ent;
- uint8_t *pvideo;
-
- if (!fb_plotters_clip_rect_ctx(&x0, &y0, &x1, &y1))
- return true; /* fill lies outside current clipping region */
-
- pvideo = fb_8bpp_get_xy_loc(x0, y0);
-
- ent = find_closest_palette_entry(c);
-
- for (y = y0; y < y1; y++) {
- memset(pvideo, ent, x1 - x0);
- pvideo += framebuffer->linelen;
- }
-
- return true;
-}
-
-static bool fb_8bpp_clg(colour c)
-{
- LOG(("colour %lx", (unsigned long)c));
- fb_8bpp_fill(fb_plot_ctx.x0,
- fb_plot_ctx.y0,
- fb_plot_ctx.x1,
- fb_plot_ctx.y1,
- c);
- return true;
-}
-
-#ifdef FB_USE_FREETYPE
-
-static bool
-fb_8bpp_draw_ft_monobitmap(FT_Bitmap *bp, int x, int y, colour c)
-{
- return false;
-}
-
-static bool
-fb_8bpp_draw_ft_bitmap(FT_Bitmap *bp, int x, int y, colour c)
-{
- uint8_t *pvideo;
- uint8_t *pixel = (uint8_t *)bp->buffer;
- colour abpixel; /* alphablended pixel */
- int xloop, yloop;
- int x0,y0,x1,y1;
- int xoff, yoff; /* x and y offset into image */
- int height = bp->rows;
- int width = bp->width;
- uint32_t fgcol;
-
- /* The part of the scaled image actually displayed is cropped to the
- * current context.
- */
- x0 = x;
- y0 = y;
- x1 = x + width;
- y1 = y + height;
-
- if (!fb_plotters_clip_rect_ctx(&x0, &y0, &x1, &y1))
- return true;
-
- if (height > (y1 - y0))
- height = (y1 - y0);
-
- if (width > (x1 - x0))
- width = (x1 - x0);
-
- xoff = x0 - x;
- yoff = y0 - y;
-
- /* plot the image */
- pvideo = fb_8bpp_get_xy_loc(x0, y0);
-
- fgcol = c & 0xFFFFFF;
-
- for (yloop = 0; yloop < height; yloop++) {
- for (xloop = 0; xloop < width; xloop++) {
- abpixel = (pixel[((yoff + yloop) * bp->pitch) + xloop + xoff] << 24) | fgcol;
- if ((abpixel & 0xFF000000) != 0) {
- if ((abpixel & 0xFF000000) != 0xFF000000) {
- abpixel = fb_plotters_ablend(abpixel,
- fb_8bpp_to_colour(*(pvideo + xloop)));
- }
-
- *(pvideo + xloop) = fb_colour_to_pixel(abpixel);
-
- }
- }
- pvideo += framebuffer->linelen;
- }
-
- return true;
-}
-
-static bool fb_8bpp_text(int x, int y, const struct css_style *style,
- const char *text, size_t length, colour bg, colour c)
-{
- uint32_t ucs4;
- size_t nxtchr = 0;
- FT_Glyph glyph;
- FT_BitmapGlyph bglyph;
-
- while (nxtchr < length) {
- ucs4 = utf8_to_ucs4(text + nxtchr, length - nxtchr);
- nxtchr = utf8_next(text, length, nxtchr);
-
- glyph = fb_getglyph(style, ucs4);
- if (glyph == NULL)
- continue;
- if (glyph->format == FT_GLYPH_FORMAT_BITMAP) {
- bglyph = (FT_BitmapGlyph)glyph;
-
- /* now, draw to our target surface */
- if (bglyph->bitmap.pixel_mode == FT_PIXEL_MODE_MONO) {
- fb_8bpp_draw_ft_monobitmap(&bglyph->bitmap,
- x + bglyph->left,
- y - bglyph->top,
- c);
- } else {
- fb_8bpp_draw_ft_bitmap(&bglyph->bitmap,
- x + bglyph->left,
- y - bglyph->top,
- c);
- }
- }
- x += glyph->advance.x >> 16;
-
- }
- return true;
-
-}
-#else
-static bool fb_8bpp_text(int x, int y, const struct css_style *style,
- const char *text, size_t length, colour bg, colour c)
-{
- const struct fb_font_desc* fb_font = fb_get_font(style);
- const uint32_t *font_data;
- uint32_t row;
-
- int xloop, yloop;
- size_t chr;
-
- uint8_t *pvideo;
- uint8_t fgcol;
-
- unsigned char *buffer = NULL;
- int x0,y0,x1,y1;
- int xoff, yoff; /* x and y offset into image */
- int height = fb_font->height;
-
- /* aquire thge text in local font encoding */
- utf8_to_font_encoding(fb_font, text, length, (char **)&buffer);
- if (!buffer)
- return true;
- length = strlen((char *)buffer);
-
-
- /* y is given to the fonts baseline we need it to the fonts top */
- y-=((fb_font->height * 75)/100);
-
- y+=1; /* the coord is the bottom-left of the pixels offset by 1 to make
- * it work since fb coords are the top-left of pixels
- */
-
- /* The part of the text displayed is cropped to the current context. */
- x0 = x;
- y0 = y;
- x1 = x + (fb_font->width * length);
- y1 = y + fb_font->height;
-
- if (!fb_plotters_clip_rect_ctx(&x0, &y0, &x1, &y1))
- return true; /* text lies outside current clipping region */
-
- /* find width and height to plot */
- if (height > (y1 - y0))
- height = (y1 - y0);
-
- xoff = x0 - x;
- yoff = y0 - y;
-
- fgcol = find_closest_palette_entry(c);
-
- /*LOG(("x %d, y %d, style %p, txt %.*s , len %d, bg 0x%lx, fg 0x%lx",
- x,y,style,length,text,length,bg,c));*/
-
- for (chr = 0; chr < length; chr++, x += fb_font->width) {
- if ((x + fb_font->width) > x1)
- break;
-
- if (x < x0)
- continue;
-
- pvideo = fb_8bpp_get_xy_loc(x, y0);
-
- /* move our font-data to the correct position */
- font_data = fb_font->data + (buffer[chr] * fb_font->height);
-
- for (yloop = 0; yloop < height; yloop++) {
- row = font_data[yoff + yloop];
- for (xloop = fb_font->width; xloop > 0 ; xloop--) {
- if ((row & 1) != 0)
- *(pvideo + xloop) = fgcol;
- row = row >> 1;
- }
- pvideo += framebuffer->linelen;
- }
- }
-
- free(buffer);
- return true;
-}
-#endif
-
-static bool fb_8bpp_disc(int x, int y, int radius, colour c, bool filled)
-{
- LOG(("x %d, y %d, rad %d, c 0x%lx, fill %d", x, y, radius, (unsigned long)c, filled));
- return true;
-}
-
-static bool fb_8bpp_arc(int x, int y, int radius, int angle1, int angle2,
- colour c)
-{
- LOG(("x %d, y %d, radius %d, angle1 %d, angle2 %d, c 0x%lx",
- x, y, radius, angle1, angle2, (unsigned long)c));
- return true;
-}
-
-
-
-static bool fb_8bpp_bitmap(int x, int y, int width, int height,
- struct bitmap *bitmap, colour bg,
- struct content *content)
-{
- uint8_t *pvideo;
- colour *pixel = (colour *)bitmap->pixdata;
- colour abpixel; /* alphablended pixel */
- int xloop, yloop;
- int x0,y0,x1,y1;
- int xoff, yoff; /* x and y offset into image */
-
- /* LOG(("x %d, y %d, width %d, height %d, bitmap %p, content %p",
- x,y,width,height,bitmap,content));*/
-
- /* TODO here we should scale the image from bitmap->width to width, for
- * now simply crop.
- */
- if (width > bitmap->width)
- width = bitmap->width;
-
- if (height > bitmap->height)
- height = bitmap->height;
-
- /* The part of the scaled image actually displayed is cropped to the
- * current context.
- */
- x0 = x;
- y0 = y;
- x1 = x + width;
- y1 = y + height;
-
- if (!fb_plotters_clip_rect_ctx(&x0, &y0, &x1, &y1))
- return true;
-
- if (height > (y1 - y0))
- height = (y1 - y0);
-
- if (width > (x1 - x0))
- width = (x1 - x0);
-
- xoff = x0 - x;
- yoff = (y0 - y) * bitmap->width;
- height = height * bitmap->width + yoff;
-
- /* plot the image */
- pvideo = fb_8bpp_get_xy_loc(x0, y0);
-
- if (bitmap->opaque) {
- for (yloop = yoff; yloop < height; yloop += bitmap->width) {
- for (xloop = 0; xloop < width; xloop++) {
- abpixel = pixel[yloop + xloop + xoff];
- *(pvideo + xloop) = fb_colour_to_pixel(abpixel);
- }
- pvideo += framebuffer->linelen;
- }
- } else {
- for (yloop = yoff; yloop < height; yloop += bitmap->width) {
- for (xloop = 0; xloop < width; xloop++) {
- abpixel = pixel[yloop + xloop + xoff];
- if ((abpixel & 0xFF000000) != 0) {
- if ((abpixel & 0xFF000000) != 0xFF000000) {
- abpixel = fb_plotters_ablend(abpixel,
- fb_8bpp_to_colour(*(pvideo + xloop)));
- }
-
- *(pvideo + xloop) = fb_colour_to_pixel(abpixel);
- }
- }
- pvideo += framebuffer->linelen;
- }
- }
-
- return true;
-}
-
-static bool fb_8bpp_bitmap_tile(int x, int y, int width, int height,
- struct bitmap *bitmap, colour bg,
- bool repeat_x, bool repeat_y,
- struct content *content)
-{
- return fb_plotters_bitmap_tile(x, y, width, height,
- bitmap, bg, repeat_x, repeat_y,
- content, fb_8bpp_bitmap);
-}
-
-static bool fb_8bpp_flush(void)
-{
- LOG(("%s()\n", __func__));
- return true;
-}
-
-static bool fb_8bpp_path(const float *p,
- unsigned int n,
- colour fill,
- float width,
- colour c,
- const float transform[6])
-{
- LOG(("%f, %d, 0x%lx, %f, 0x%lx, %f",
- *p, n, (unsigned long)fill, width, (unsigned long)c, *transform));
-
- return true;
-}
-
-const struct plotter_table framebuffer_8bpp_plot = {
- .clg = fb_8bpp_clg,
- .rectangle = fb_8bpp_rectangle,
- .line = fb_8bpp_line,
- .polygon = fb_8bpp_polygon,
- .fill = fb_8bpp_fill,
- .clip = fb_clip,
- .text = fb_8bpp_text,
- .disc = fb_8bpp_disc,
- .arc = fb_8bpp_arc,
- .bitmap = fb_8bpp_bitmap,
- .bitmap_tile = fb_8bpp_bitmap_tile,
- .flush = fb_8bpp_flush,
- .path = fb_8bpp_path,
- .option_knockout = true,
-};
-
-
-/*
- * Local Variables:
- * c-basic-offset:8
- * End:
- */
diff --git a/src/Makefile b/src/Makefile
index 9774acd..f573d7a 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 plot_util.c plotters.c 32bpp_plotters.c 16bpp_plotters.c 8bpp_plotters.c
-
+DIR_SOURCES := libnsfb.c frontend.c frontend_sdl.c frontend_vnc.c frontend_able.c frontend_ram.c cursor.c
+#frontend_linux.c
include build/makefiles/Makefile.subdir
diff --git a/src/frontend_linux.c b/src/frontend_linux.c
index e65c888..e6e7601 100644
--- a/src/frontend_linux.c
+++ b/src/frontend_linux.c
@@ -37,7 +37,14 @@ static int linux_set_geometry(nsfb_t *nsfb, int width, int height, int bpp)
static int linux_initialise(nsfb_t *nsfb)
{
- UNUSED(nsfb);
+ if (nsfb->frontend_priv != NULL)
+ return -1;
+
+ /* sanity checked depth. */
+ if ((nsfb->bpp != 32) && (nsfb->bpp != 16) && (nsfb->bpp != 8))
+ return -1;
+
+
return 0;
}
@@ -55,10 +62,69 @@ static bool linux_input(nsfb_t *nsfb, nsfb_event_t *event, int timeout)
return false;
}
+static int linux_claim(nsfb_t *nsfb, nsfb_bbox_t *box)
+{
+ struct nsfb_cursor_s *cursor = nsfb->cursor;
+
+ if ((cursor != NULL) &&
+ (cursor->plotted == true) &&
+ (nsfb_plot_bbox_intersect(box, &cursor->loc))) {
+
+ nsfb->plotter_fns->bitmap(nsfb,
+ &cursor->savloc,
+ cursor->sav,
+ cursor->sav_width,
+ cursor->sav_height,
+ cursor->sav_width,
+ false);
+ cursor->plotted = false;
+ }
+ return 0;
+}
+
+static int linux_cursor(nsfb_t *nsfb, struct nsfb_cursor_s *cursor)
+{
+ nsfb_bbox_t sclip;
+
+ if ((cursor != NULL) && (cursor->plotted == true)) {
+ sclip = nsfb->clip;
+
+ nsfb->plotter_fns->set_clip(nsfb, NULL);
+
+ nsfb->plotter_fns->bitmap(nsfb,
+ &cursor->savloc,
+ cursor->sav,
+ cursor->sav_width,
+ cursor->sav_height,
+ cursor->sav_width,
+ false);
+
+ nsfb_cursor_plot(nsfb, cursor);
+
+ nsfb->clip = sclip;
+ }
+ return true;
+}
+
+
+static int linux_release(nsfb_t *nsfb, nsfb_bbox_t *box)
+{
+ struct nsfb_cursor_s *cursor = nsfb->cursor;
+
+ if ((cursor != NULL) && (cursor->plotted == false)) {
+ nsfb_cursor_plot(nsfb, cursor);
+ }
+
+ return 0;
+}
+
const nsfb_frontend_rtns_t linux_rtns = {
.initialise = linux_initialise,
.finalise = linux_finalise,
.input = linux_input,
+ .claim = linux_claim,
+ .release = linux_release,
+ .cursor = linux_cursor,
.geometry = linux_set_geometry,
};
diff --git a/src/16bpp_plotters.c b/src/plot/16bpp.c
index b9ff186..8feb095 100644
--- a/src/16bpp_plotters.c
+++ b/src/plot/16bpp.c
@@ -406,6 +406,29 @@ bitmap(nsfb_t *nsfb,
}
+static bool readrect(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t *buffer)
+{
+ uint16_t *pvideo;
+ int xloop, yloop;
+ int width;
+
+ if (!nsfb_plot_clip_ctx(nsfb, rect)) {
+ return true;
+ }
+
+ width = rect->x1 - rect->x0;
+
+ pvideo = get_xy_loc(nsfb, rect->x0, rect->y0);
+
+ for (yloop = rect->y0; yloop < rect->y1; yloop += 1) {
+ for (xloop = 0; xloop < width; xloop++) {
+ *buffer = pixel_to_colour(*(pvideo + xloop));
+ buffer++;
+ }
+ pvideo += (nsfb->linelen >> 1);
+ }
+ return true;
+}
const nsfb_plotter_fns_t _nsfb_16bpp_plotters = {
@@ -415,6 +438,7 @@ const nsfb_plotter_fns_t _nsfb_16bpp_plotters = {
.bitmap = bitmap,
.glyph8 = glyph8,
.glyph1 = glyph1,
+ .readrect = readrect,
};
/*
diff --git a/src/1bpp_plotters.c b/src/plot/1bpp.c
index bd511e7..bd511e7 100644
--- a/src/1bpp_plotters.c
+++ b/src/plot/1bpp.c
diff --git a/src/plot/24bpp.c b/src/plot/24bpp.c
new file mode 100644
index 0000000..0fa53e9
--- /dev/null
+++ b/src/plot/24bpp.c
@@ -0,0 +1,442 @@
+/*
+ * Copyright 2009 Vincent Sanders <vince@simtec.co.uk>
+ *
+ * This file is part of libnsfb, http://www.netsurf-browser.org/
+ * Licenced under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ */
+
+#include <stdbool.h>
+#include <endian.h>
+#include <stdlib.h>
+
+#include "libnsfb.h"
+#include "libnsfb_plot.h"
+#include "libnsfb_plot_util.h"
+
+#include "nsfb.h"
+#include "plot.h"
+
+static inline uint8_t *
+get_xy_loc(nsfb_t *nsfb, int x, int y)
+{
+ return (uint8_t *)(nsfb->ptr + (y * nsfb->linelen) + (x * 3));
+}
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+static inline nsfb_colour_t pixel_to_colour(uint8_t pixel)
+{
+ return (pixel >> 8) & ~0xFF000000U;
+}
+
+/* convert a colour value to a 32bpp pixel value ready for screen output */
+static inline uint32_t colour_to_pixel(nsfb_colour_t c)
+{
+ return (c << 8);
+}
+#else /* __BYTE_ORDER == __BIG_ENDIAN */
+static inline nsfb_colour_t pixel_to_colour(uint32_t pixel)
+{
+ return ((pixel & 0xFF) << 16) |
+ ((pixel & 0xFF00)) |
+ ((pixel & 0xFF0000) >> 16);
+}
+
+/* convert a colour value to a 32bpp pixel value ready for screen output */
+static inline uint32_t colour_to_pixel(nsfb_colour_t c)
+{
+ return ((c & 0xff0000) >> 16) | (c & 0xff00) | ((c & 0xff) << 16);
+}
+#endif
+
+#define SIGN(x) ((x<0) ? -1 : ((x>0) ? 1 : 0))
+
+static bool
+line(nsfb_t *nsfb, int linec, nsfb_bbox_t *line, nsfb_plot_pen_t *pen)
+{
+ int w;
+ uint32_t ent;
+ uint32_t *pvideo;
+ int x, y, i;
+ int dx, dy, sdy;
+ int dxabs, dyabs;
+
+ ent = colour_to_pixel(pen->stroke_colour);
+
+ for (;linec > 0; linec--) {
+
+ if (line->y0 == line->y1) {
+ /* horizontal line special cased */
+
+ 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;
+
+ } 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 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;
+
+ 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;
+}
+
+
+
+static bool fill(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t c)
+{
+ int w;
+ uint32_t *pvid;
+ uint32_t ent;
+ uint32_t llen;
+ uint32_t width;
+ uint32_t height;
+
+ if (!nsfb_plot_clip_ctx(nsfb, rect))
+ return true; /* fill lies outside current clipping region */
+
+ ent = colour_to_pixel(c);
+ width = rect->x1 - rect->x0;
+ height = rect->y1 - rect->y0;
+ llen = (nsfb->linelen >> 2) - width;
+
+ pvid = get_xy_loc(nsfb, rect->x0, rect->y0);
+
+ while (height-- > 0) {
+ w = width;
+ while (w >= 16) {
+ *pvid++ = ent; *pvid++ = ent;
+ *pvid++ = ent; *pvid++ = ent;
+ *pvid++ = ent; *pvid++ = ent;
+ *pvid++ = ent; *pvid++ = ent;
+ *pvid++ = ent; *pvid++ = ent;
+ *pvid++ = ent; *pvid++ = ent;
+ *pvid++ = ent; *pvid++ = ent;
+ *pvid++ = ent; *pvid++ = ent;
+ w-=16;
+ }
+ while (w >= 4) {
+ *pvid++ = ent; *pvid++ = ent;
+ *pvid++ = ent; *pvid++ = ent;
+ w-=4;
+ }
+ while (w > 0) {
+ *pvid++ = ent;
+ w--;
+ }
+ pvid += llen;
+ }
+
+ return true;
+}
+
+
+
+
+static bool point(nsfb_t *nsfb, int x, int y, nsfb_colour_t c)
+{
+ uint32_t *pvideo;
+
+ /* check point lies within clipping region */
+ if ((x < nsfb->clip.x0) ||
+ (x >= nsfb->clip.x1) ||
+ (y < nsfb->clip.y0) ||
+ (y >= nsfb->clip.y1))
+ return true;
+
+ pvideo = get_xy_loc(nsfb, x, y);
+
+ if ((c & 0xFF000000) != 0) {
+ if ((c & 0xFF000000) != 0xFF000000) {
+ c = nsfb_plot_ablend(c, pixel_to_colour(*pvideo));
+ }
+
+ *pvideo = colour_to_pixel(c);
+ }
+ return true;
+}
+
+static bool
+glyph1(nsfb_t *nsfb,
+ nsfb_bbox_t *loc,
+ const uint8_t *pixel,
+ int pitch,
+ nsfb_colour_t c)
+{
+ uint32_t *pvideo;
+ int xloop, yloop;
+ int xoff, yoff; /* x and y offset into image */
+ int x = loc->x0;
+ int y = loc->y0;
+ int width = loc->x1 - loc->x0;
+ int height = loc->y1 - loc->y0;
+ uint32_t fgcol;
+ const uint8_t *fntd;
+ uint8_t row;
+
+ if (!nsfb_plot_clip_ctx(nsfb, loc))
+ return true;
+
+ if (height > (loc->y1 - loc->y0))
+ height = (loc->y1 - loc->y0);
+
+ if (width > (loc->x1 - loc->x0))
+ width = (loc->x1 - loc->x0);
+
+ xoff = loc->x0 - x;
+ yoff = loc->y0 - y;
+
+ pvideo = get_xy_loc(nsfb, loc->x0, loc->y0);
+
+ fgcol = colour_to_pixel(c);
+
+ for (yloop = yoff; yloop < height; yloop++) {
+ fntd = pixel + (yloop * (pitch>>3)) + (xoff>>3);
+ row = (*fntd++) << (xoff & 3);
+ for (xloop = xoff; xloop < width ; xloop++) {
+ if (((xloop % 8) == 0) && (xloop != 0)) {
+ row = *fntd++;
+ }
+
+ if ((row & 0x80) != 0) {
+ *(pvideo + xloop) = fgcol;
+ }
+ row = row << 1;
+
+ }
+
+ pvideo += (nsfb->linelen >> 2);
+ }
+
+ return true;
+}
+
+static bool
+glyph8(nsfb_t *nsfb,
+ nsfb_bbox_t *loc,
+ const uint8_t *pixel,
+ int pitch,
+ nsfb_colour_t c)
+{
+ uint32_t *pvideo;
+ nsfb_colour_t abpixel; /* alphablended pixel */
+ int xloop, yloop;
+ int xoff, yoff; /* x and y offset into image */
+ int x = loc->x0;
+ int y = loc->y0;
+ int width = loc->x1 - loc->x0;
+ int height = loc->y1 - loc->y0;
+ uint32_t fgcol;
+
+ if (!nsfb_plot_clip_ctx(nsfb, loc))
+ return true;
+
+ if (height > (loc->y1 - loc->y0))
+ height = (loc->y1 - loc->y0);
+
+ if (width > (loc->x1 - loc->x0))
+ width = (loc->x1 - loc->x0);
+
+ xoff = loc->x0 - x;
+ yoff = loc->y0 - y;
+
+ pvideo = get_xy_loc(nsfb, loc->x0, loc->y0);
+
+ fgcol = c & 0xFFFFFF;
+
+ for (yloop = 0; yloop < height; yloop++) {
+ for (xloop = 0; xloop < width; xloop++) {
+ abpixel = (pixel[((yoff + yloop) * pitch) + xloop + xoff] << 24) | fgcol;
+ if ((abpixel & 0xFF000000) != 0) {
+ /* pixel is not transparent */
+ if ((abpixel & 0xFF000000) != 0xFF000000) {
+ abpixel = nsfb_plot_ablend(abpixel,
+ pixel_to_colour(*(pvideo + xloop)));
+ }
+
+ *(pvideo + xloop) = colour_to_pixel(abpixel);
+ }
+ }
+ pvideo += (nsfb->linelen >> 2);
+ }
+
+ return true;
+}
+
+static bool
+bitmap(nsfb_t *nsfb,
+ const nsfb_bbox_t *loc,
+ const nsfb_colour_t *pixel,
+ int bmp_width,
+ int bmp_height,
+ int bmp_stride,
+ bool alpha)
+{
+ uint32_t *pvideo;
+ nsfb_colour_t abpixel = 0; /* alphablended pixel */
+ int xloop, yloop;
+ int xoff, yoff; /* x and y offset into image */
+ int x = loc->x0;
+ int y = loc->y0;
+ int width = loc->x1 - loc->x0;
+ int height = loc->y1 - loc->y0;
+ nsfb_bbox_t clipped; /* clipped display */
+
+ /* TODO here we should scale the image from bmp_width to width, for
+ * now simply crop.
+ */
+ if (width > bmp_width)
+ width = bmp_width;
+
+ if (height > bmp_height)
+ height = bmp_height;
+
+ /* The part of the scaled image actually displayed is cropped to the
+ * current context.
+ */
+ clipped.x0 = x;
+ clipped.y0 = y;
+ clipped.x1 = x + width;
+ clipped.y1 = y + height;
+
+ if (!nsfb_plot_clip_ctx(nsfb, &clipped)) {
+ return true;
+ }
+
+ if (height > (clipped.y1 - clipped.y0))
+ height = (clipped.y1 - clipped.y0);
+
+ 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;
+
+ /* plot the image */
+ pvideo = get_xy_loc(nsfb, clipped.x0, clipped.y0);
+
+ if (alpha) {
+ for (yloop = yoff; yloop < height; yloop += bmp_stride) {
+ for (xloop = 0; xloop < width; xloop++) {
+ abpixel = pixel[yloop + xloop + xoff];
+ if ((abpixel & 0xFF000000) != 0) {
+ if ((abpixel & 0xFF000000) != 0xFF000000) {
+ abpixel = nsfb_plot_ablend(abpixel,
+ pixel_to_colour(*(pvideo + xloop)));
+ }
+
+ *(pvideo + xloop) = colour_to_pixel(abpixel);
+ }
+ }
+ pvideo += (nsfb->linelen >> 2);
+ }
+ } else {
+ for (yloop = yoff; yloop < height; yloop += bmp_stride) {
+ for (xloop = 0; xloop < width; xloop++) {
+ abpixel = pixel[yloop + xloop + xoff];
+ *(pvideo + xloop) = colour_to_pixel(abpixel);
+ }
+ pvideo += (nsfb->linelen >> 2);
+ }
+ }
+ return true;
+}
+
+static bool readrect(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t *buffer)
+{
+ uint32_t *pvideo;
+ int xloop, yloop;
+ int width;
+
+ if (!nsfb_plot_clip_ctx(nsfb, rect)) {
+ return true;
+ }
+
+ width = rect->x1 - rect->x0;
+
+ pvideo = get_xy_loc(nsfb, rect->x0, rect->y0);
+
+ for (yloop = rect->y0; yloop < rect->y1; yloop += 1) {
+ for (xloop = 0; xloop < width; xloop++) {
+ *buffer = pixel_to_colour(*(pvideo + xloop));
+ buffer++;
+ }
+ pvideo += (nsfb->linelen >> 2);
+ }
+ return true;
+}
+
+const nsfb_plotter_fns_t _nsfb_24bpp_plotters = {
+ .line = line,
+ .fill = fill,
+ .point = point,
+ .bitmap = bitmap,
+ .glyph8 = glyph8,
+ .glyph1 = glyph1,
+ .readrect = readrect,
+};
+
+/*
+ * Local Variables:
+ * c-basic-offset:8
+ * End:
+ */
diff --git a/src/32bpp_plotters.c b/src/plot/32bpp.c
index 243cdb4..243cdb4 100644
--- a/src/32bpp_plotters.c
+++ b/src/plot/32bpp.c
diff --git a/src/8bpp_plotters.c b/src/plot/8bpp.c
index b29d241..c95565c 100644
--- a/src/8bpp_plotters.c
+++ b/src/plot/8bpp.c
@@ -380,6 +380,29 @@ bitmap(nsfb_t *nsfb,
}
+static bool readrect(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t *buffer)
+{
+ uint8_t *pvideo;
+ int xloop, yloop;
+ int width;
+
+ if (!nsfb_plot_clip_ctx(nsfb, rect)) {
+ return true;
+ }
+
+ width = rect->x1 - rect->x0;
+
+ pvideo = get_xy_loc(nsfb, rect->x0, rect->y0);
+
+ for (yloop = rect->y0; yloop < rect->y1; yloop += 1) {
+ for (xloop = 0; xloop < width; xloop++) {
+ *buffer = pixel_to_colour(nsfb,*(pvideo + xloop));
+ buffer++;
+ }
+ pvideo += nsfb->linelen;
+ }
+ return true;
+}
@@ -391,6 +414,7 @@ const nsfb_plotter_fns_t _nsfb_8bpp_plotters = {
.bitmap = bitmap,
.glyph8 = glyph8,
.glyph1 = glyph1,
+ .readrect = readrect,
};
diff --git a/src/plot/Makefile b/src/plot/Makefile
new file mode 100644
index 0000000..0c51c02
--- /dev/null
+++ b/src/plot/Makefile
@@ -0,0 +1,4 @@
+# Sources
+DIR_SOURCES := api.c util.c generic.c 32bpp.c 16bpp.c 8bpp.c
+
+include build/makefiles/Makefile.subdir
diff --git a/src/plot.c b/src/plot/api.c
index 4de25c9..4de25c9 100644
--- a/src/plot.c
+++ b/src/plot/api.c
diff --git a/src/plotters.c b/src/plot/generic.c
index d04559e..d04559e 100644
--- a/src/plotters.c
+++ b/src/plot/generic.c
diff --git a/src/plot_util.c b/src/plot/util.c
index cf2ec9b..cf2ec9b 100644
--- a/src/plot_util.c
+++ b/src/plot/util.c
diff --git a/test/plottest.c b/test/plottest.c
index 8be921e..74134c4 100644
--- a/test/plottest.c
+++ b/test/plottest.c
@@ -70,6 +70,7 @@ const struct {
int main(int argc, char **argv)
{
nsfb_t *nsfb;
+ int bpp;
nsfb_event_t event;
nsfb_bbox_t box;
nsfb_bbox_t box2;
@@ -80,8 +81,13 @@ int main(int argc, char **argv)
int loop;
nsfb_plot_pen_t pen;
- UNUSED(argc);
- UNUSED(argv);
+ if (argc < 2) {
+ bpp = 32;
+ } else {
+ bpp = atoi(argv[1]);
+ if (bpp == 0)
+ bpp = 32;
+ }
nsfb = nsfb_init(NSFB_FRONTEND_SDL);
if (nsfb == NULL) {
@@ -89,6 +95,12 @@ int main(int argc, char **argv)
return 1;
}
+ if (nsfb_set_geometry(nsfb, 0, 0, bpp) == -1) {
+ fprintf(stderr, "Unable to set geometry\n");
+ nsfb_finalise(nsfb);
+ return 3;
+ }
+
if (nsfb_init_frontend(nsfb) == -1) {
fprintf(stderr, "Unable to initialise nsfb frontend\n");
return 2;