summaryrefslogtreecommitdiff
path: root/src/plot/24bpp.c
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2016-09-04 14:55:49 +0100
committerVincent Sanders <vince@kyllikki.org>2016-09-04 14:55:49 +0100
commit6fe884b805a97e4185703afb62de4da8bdf3edde (patch)
treede810a26840a82ce80240845bb8403f57a3a8a36 /src/plot/24bpp.c
parent327f0f92b6ce25591568535d3b8a33b5e11e8698 (diff)
downloadlibnsfb-6fe884b805a97e4185703afb62de4da8bdf3edde.tar.gz
libnsfb-6fe884b805a97e4185703afb62de4da8bdf3edde.tar.bz2
Make endianess detection more robust
This moves the byte order detection into the internal plot header and makes teh detection much more robust searching for more macros in common use. This should fix compilation on big endian openBSD systems Thanks to Anthony J. Bentley for a patch used as inspiration for this change
Diffstat (limited to 'src/plot/24bpp.c')
-rw-r--r--src/plot/24bpp.c46
1 files changed, 32 insertions, 14 deletions
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))