summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/plot.h49
-rw-r--r--src/plot/24bpp.c46
-rw-r--r--src/plot/32bpp-xbgr8888.c55
-rw-r--r--src/plot/32bpp-xrgb8888.c52
4 files changed, 162 insertions, 40 deletions
diff --git a/src/plot.h b/src/plot.h
index 4b1545d..6e67ca6 100644
--- a/src/plot.h
+++ b/src/plot.h
@@ -1,4 +1,52 @@
+/*
+ * 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
+ */
+
+/**
+ * \file internal plotter interace.
+ */
+#ifndef LIBNSFB_PLOT_H
+#define LIBNSFB_PLOT_H
+
+/*
+ * Do the best we can to determine integer byte ordering
+ *
+ * This series of tests attempts to determine, at compile time, if the integer
+ * ordering in memory is big or little endian. This allows the plotters to make
+ * assumptions about memory ordering to greatly improve software rendering
+ * performance.
+ *
+ * \note This utterly ignores PDP endianess
+ */
+#undef NSFB_BE_BYTE_ORDER
+#if defined(_WIN32)
+ /* windows does not have endian.h but uses these macros */
+ #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+ #define NSFB_BE_BYTE_ORDER
+ #endif
+#else /* defined(_WIN32) */
+ #include <endian.h>
+ #if defined(__BYTE_ORDER__)
+ #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+ #define NSFB_BE_BYTE_ORDER
+ #endif
+ #elif defined(__BYTE_ORDER)
+ #if __BYTE_ORDER == __BIG_ENDIAN
+ #define NSFB_BE_BYTE_ORDER
+ #endif
+ #elif defined(BYTE_ORDER)
+ #if BYTE_ORDER == BIG_ENDIAN
+ #define NSFB_BE_BYTE_ORDER
+ #endif
+ #else
+ #error "Endian determination failed"
+ #endif
+#endif
/** Clears plotting area to a flat colour (if needed)
*/
@@ -127,3 +175,4 @@ typedef struct nsfb_plotter_fns_s {
bool select_plotters(nsfb_t *nsfb);
+#endif
diff --git a/src/plot/24bpp.c b/src/plot/24bpp.c
index 011765a..651abe1 100644
--- a/src/plot/24bpp.c
+++ b/src/plot/24bpp.c
@@ -9,13 +9,6 @@
#include <stdbool.h>
#include <stdlib.h>
-#ifndef _WIN32
-#include <endian.h>
-#else
-#define __BYTE_ORDER __BYTE_ORDER__
-#define __BIG_ENDIAN __ORDER_BIG_ENDIAN__
-#endif
-
#include "libnsfb.h"
#include "libnsfb_plot.h"
#include "libnsfb_plot_util.h"
@@ -23,24 +16,43 @@
#include "nsfb.h"
#include "plot.h"
-static inline uint8_t *
-get_xy_loc(nsfb_t *nsfb, int x, int y)
+/**
+ * Get the address of a logical location on the framebuffer
+ */
+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)
+#ifdef NSFB_BE_BYTE_ORDER
+
+/**
+ * convert a 24bpp big endian pixel value to netsurf colour
+ */
+static inline nsfb_colour_t pixel_to_colour(uint32_t pixel)
{
return (pixel >> 8) & ~0xFF000000U;
}
-/* convert a colour value to a 32bpp pixel value ready for screen output */
+/**
+ * convert a colour value to a big endian 24bpp pixel value
+ *
+ * The resulting value is ready for screen output
+ */
static inline uint32_t colour_to_pixel(nsfb_colour_t c)
{
return (c << 8);
}
-#else /* __BYTE_ORDER == __BIG_ENDIAN */
+
+#else
+
+/**
+ * convert a 24bpp little endian pixel value to netsurf colour
+ *
+ * \param nsfb The framebuffer
+ * \param pixel The pixel values
+ * \return The netsurf colour value.
+ */
static inline nsfb_colour_t pixel_to_colour(uint32_t pixel)
{
return ((pixel & 0xFF) << 16) |
@@ -48,11 +60,17 @@ static inline nsfb_colour_t pixel_to_colour(uint32_t pixel)
((pixel & 0xFF0000) >> 16);
}
-/* convert a colour value to a 32bpp pixel value ready for screen output */
+/**
+ * convert a colour value to a little endian 24bpp pixel value
+ *
+ * \param c The netsurf colour
+ * \return A 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))
diff --git a/src/plot/32bpp-xbgr8888.c b/src/plot/32bpp-xbgr8888.c
index a0ed066..2492054 100644
--- a/src/plot/32bpp-xbgr8888.c
+++ b/src/plot/32bpp-xbgr8888.c
@@ -10,13 +10,6 @@
#include <stdbool.h>
#include <stdlib.h>
-#ifndef _WIN32
-#include <endian.h>
-#else
-#define __BYTE_ORDER __BYTE_ORDER__
-#define __BIG_ENDIAN __ORDER_BIG_ENDIAN__
-#endif
-
#include "libnsfb.h"
#include "libnsfb_plot.h"
#include "libnsfb_plot_util.h"
@@ -24,37 +17,71 @@
#include "nsfb.h"
#include "plot.h"
+#define UNUSED __attribute__((unused))
-#define UNUSED __attribute__((unused))
+/**
+ * Get the address of a logical location on the framebuffer
+ */
static inline uint32_t *get_xy_loc(nsfb_t *nsfb, int x, int y)
{
return (void *)(nsfb->ptr + (y * nsfb->linelen) + (x << 2));
}
-#if __BYTE_ORDER == __BIG_ENDIAN
+#ifdef NSFB_BE_BYTE_ORDER
+
+/**
+ * convert a 32bpp big endian pixel value to netsurf colour
+ *
+ * \param nsfb The framebuffer
+ * \param pixel The pixel value
+ * \return The netsurf colour value.
+ */
static inline nsfb_colour_t pixel_to_colour(UNUSED nsfb_t *nsfb, uint32_t pixel)
{
- /* TODO: FIX */
+ /** \todo fix this conversion as it is probably wrong */
return (pixel >> 8) & ~0xFF000000U;
}
-/* convert a colour value to a 32bpp pixel value ready for screen output */
+/**
+ * convert a colour value to a big endian 32bpp pixel value
+ *
+ * \param nsfb The framebuffer
+ * \param c The framebuffer colour
+ * \return A pixel value ready for screen output.
+ */
static inline uint32_t colour_to_pixel(UNUSED nsfb_t *nsfb, nsfb_colour_t c)
{
- return ((c & 0xFF) << 24) | ((c & 0xFF00) << 8) | ((c & 0xFF0000) >> 8);
+ return ((c & 0xFF) << 24) | ((c & 0xFF00) << 8) | ((c & 0xFF0000) >> 8);
}
-#else /* __BYTE_ORDER == __BIG_ENDIAN */
+
+#else
+
+/**
+ * convert a 32bpp little endian pixel value to netsurf colour
+ *
+ * \param nsfb The framebuffer
+ * \param pixel The pixel value
+ * \return The netsurf colour value.
+ */
static inline nsfb_colour_t pixel_to_colour(UNUSED nsfb_t *nsfb, uint32_t pixel)
{
return pixel | 0xFF000000U;
}
-/* convert a colour value to a 32bpp pixel value ready for screen output */
+
+/**
+ * convert a colour value to a little endian 32bpp pixel value
+ *
+ * \param nsfb The framebuffer
+ * \param c The netsurf colour
+ * \return A pixel value ready for screen output.
+ */
static inline uint32_t colour_to_pixel(UNUSED nsfb_t *nsfb, nsfb_colour_t c)
{
return c;
}
+
#endif
#define PLOT_TYPE uint32_t
diff --git a/src/plot/32bpp-xrgb8888.c b/src/plot/32bpp-xrgb8888.c
index 476f6b2..6f77f44 100644
--- a/src/plot/32bpp-xrgb8888.c
+++ b/src/plot/32bpp-xrgb8888.c
@@ -10,13 +10,6 @@
#include <stdbool.h>
#include <stdlib.h>
-#ifndef _WIN32
-#include <endian.h>
-#else
-#define __BYTE_ORDER __BYTE_ORDER__
-#define __BIG_ENDIAN __ORDER_BIG_ENDIAN__
-#endif
-
#include "libnsfb.h"
#include "libnsfb_plot.h"
#include "libnsfb_plot_util.h"
@@ -24,26 +17,53 @@
#include "nsfb.h"
#include "plot.h"
+#define UNUSED __attribute__((unused))
-#define UNUSED __attribute__((unused))
+/**
+ * Get the address of a logical location on the framebuffer
+ */
static inline uint32_t *get_xy_loc(nsfb_t *nsfb, int x, int y)
{
return (void *)(nsfb->ptr + (y * nsfb->linelen) + (x << 2));
}
-#if __BYTE_ORDER == __BIG_ENDIAN
+
+#ifdef NSFB_BE_BYTE_ORDER
+
+/**
+ * convert a 32bpp big endian pixel value to netsurf colour
+ *
+ * \param nsfb The framebuffer
+ * \param pixel The pixel value
+ * \return The netsurf colour value.
+ */
static inline nsfb_colour_t pixel_to_colour(UNUSED nsfb_t *nsfb, uint32_t pixel)
{
return (pixel >> 8) & ~0xFF000000U;
}
-/* convert a colour value to a 32bpp pixel value ready for screen output */
+/**
+ * convert a colour value to a big endian 32bpp pixel value
+ *
+ * \param nsfb The framebuffer
+ * \param c The framebuffer colour
+ * \return A pixel value ready for screen output.
+ */
static inline uint32_t colour_to_pixel(UNUSED nsfb_t *nsfb, nsfb_colour_t c)
{
return (c << 8);
}
-#else /* __BYTE_ORDER == __BIG_ENDIAN */
+
+#else
+
+/**
+ * convert a 32bpp little endian pixel value to netsurf colour
+ *
+ * \param nsfb The framebuffer
+ * \param pixel The pixel value
+ * \return The netsurf colour value.
+ */
static inline nsfb_colour_t pixel_to_colour(UNUSED nsfb_t *nsfb, uint32_t pixel)
{
return ((pixel & 0xFF) << 16) |
@@ -51,11 +71,19 @@ static inline nsfb_colour_t pixel_to_colour(UNUSED nsfb_t *nsfb, uint32_t pixel)
((pixel & 0xFF0000) >> 16);
}
-/* convert a colour value to a 32bpp pixel value ready for screen output */
+
+/**
+ * convert a colour value to a little endian 32bpp pixel value
+ *
+ * \param nsfb The framebuffer
+ * \param c The netsurf colour
+ * \return A pixel value ready for screen output.
+ */
static inline uint32_t colour_to_pixel(UNUSED nsfb_t *nsfb, nsfb_colour_t c)
{
return ((c & 0xff0000) >> 16) | (c & 0xff00) | ((c & 0xff) << 16);
}
+
#endif
#define PLOT_TYPE uint32_t