From 6fe884b805a97e4185703afb62de4da8bdf3edde Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 4 Sep 2016 14:55:49 +0100 Subject: 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 --- src/plot.h | 49 +++++++++++++++++++++++++++++++++++++++++ src/plot/24bpp.c | 46 +++++++++++++++++++++++++++------------ src/plot/32bpp-xbgr8888.c | 55 +++++++++++++++++++++++++++++++++++------------ src/plot/32bpp-xrgb8888.c | 52 +++++++++++++++++++++++++++++++++----------- 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 + * + * 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 + #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 #include -#ifndef _WIN32 -#include -#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 #include -#ifndef _WIN32 -#include -#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 #include -#ifndef _WIN32 -#include -#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 -- cgit v1.2.3 From bce2c233988e86ad034f6e0c8b96385db0d47a2e Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 4 Sep 2016 15:12:40 +0100 Subject: cope with mac os X having the endian header somewhere else --- src/plot.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/plot.h b/src/plot.h index 6e67ca6..65ef264 100644 --- a/src/plot.h +++ b/src/plot.h @@ -29,7 +29,13 @@ #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #define NSFB_BE_BYTE_ORDER #endif -#else /* defined(_WIN32) */ +#elif defined(OS_MACOSX) +/* mac os x has the include somewhere different */ + #include + #if BYTE_ORDER == BIG_ENDIAN + #define NSFB_BE_BYTE_ORDER + #endif +#else #include #if defined(__BYTE_ORDER__) #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -- cgit v1.2.3 From 6742ef25b910a3a69cce5c9bfd8b9a64b8e7f121 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 4 Sep 2016 15:18:14 +0100 Subject: use correct macro to detect mac os x --- src/plot.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plot.h b/src/plot.h index 65ef264..2beca42 100644 --- a/src/plot.h +++ b/src/plot.h @@ -29,8 +29,8 @@ #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #define NSFB_BE_BYTE_ORDER #endif -#elif defined(OS_MACOSX) -/* mac os x has the include somewhere different */ +#elif defined(__APPLE__) + /* mac os x has the include somewhere different */ #include #if BYTE_ORDER == BIG_ENDIAN #define NSFB_BE_BYTE_ORDER -- cgit v1.2.3 From 9fc2238945747b27858a34c26c7c64cf895df7e8 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 4 Sep 2016 15:21:48 +0100 Subject: use the darwin specific macros for endian checking This is necessary to avoid issues around having the correct macros defined in the darwin environment. --- src/plot.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plot.h b/src/plot.h index 2beca42..2fd2ebf 100644 --- a/src/plot.h +++ b/src/plot.h @@ -32,7 +32,7 @@ #elif defined(__APPLE__) /* mac os x has the include somewhere different */ #include - #if BYTE_ORDER == BIG_ENDIAN + #if __DARWIN_BYTE_ORDER == __DARWIN_BIG_ENDIAN #define NSFB_BE_BYTE_ORDER #endif #else -- cgit v1.2.3 From 3271d2753e88ec8ea4e4cbc2eeb0cc88a21071f7 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 19 Nov 2016 09:31:20 +0000 Subject: Prepare for release of 0.1.5 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index bea4fa3..d669bae 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # Component settings COMPONENT := nsfb -COMPONENT_VERSION := 0.1.4 +COMPONENT_VERSION := 0.1.5 # Default to a static library COMPONENT_TYPE ?= lib-static -- cgit v1.2.3 From 167205c109291aa1957ba64667efa12ce53bba5d Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 19 Nov 2016 09:39:07 +0000 Subject: Add missing files --- COPYING | 20 ++++++++++++++++++++ README | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 COPYING create mode 100644 README diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..a90a8a7 --- /dev/null +++ b/COPYING @@ -0,0 +1,20 @@ +Copyright (C) 2009-2016 Vincent Sanders +Copyright (C) 2009-2016 Michael Drake + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README b/README new file mode 100644 index 0000000..732e850 --- /dev/null +++ b/README @@ -0,0 +1,45 @@ +Libnsfb - NetSurf Framebuffer Library +===================================== + +Overview +-------- + + Libnsfb is a framebuffer drawing library with a simple interface, + providing a consistent API across a number of framebuffer implementations. + +Requirements +------------ + + Libnsfb requires the following tools: + + + A C99 capable C compiler + + GNU make or compatible + + Pkg-config + + Libnsfb also requires the following libraries to be installed: + + + SDL 1.2 (for the SDL backend) + + libxcb* (for the X11 backend) + +Compilation +----------- + + If necessary, modify the toolchain settings in the Makefile. + Invoke make: + $ make + +Verification +------------ + + To verify that the parser is working, it is necessary to specify a + different makefile target than that used for normal compilation, thus: + + $ make test + +API documentation +----------------- + + Currently, there is none. However, the code is well commented and the + public API may be found in the "include" directory. The testcase sources + may also be of use in working out how to use it. + -- cgit v1.2.3