diff options
-rw-r--r-- | COPYING | 20 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | README | 45 | ||||
-rw-r--r-- | src/plot.h | 55 | ||||
-rw-r--r-- | src/plot/24bpp.c | 46 | ||||
-rw-r--r-- | src/plot/32bpp-xbgr8888.c | 55 | ||||
-rw-r--r-- | src/plot/32bpp-xrgb8888.c | 52 |
7 files changed, 234 insertions, 41 deletions
@@ -0,0 +1,20 @@ +Copyright (C) 2009-2016 Vincent Sanders <vince@netsurf-browser.org> +Copyright (C) 2009-2016 Michael Drake <tlsa@netsurf-browser.org> + +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. @@ -6,7 +6,7 @@ # Component settings COMPONENT := nsfb -COMPONENT_VERSION := 0.1.3 +COMPONENT_VERSION := 0.1.5 # Default to a static library COMPONENT_TYPE ?= lib-static @@ -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. + @@ -1,4 +1,58 @@ +/* + * 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 +#elif defined(__APPLE__) + /* mac os x has the include somewhere different */ + #include <machine/endian.h> + #if __DARWIN_BYTE_ORDER == __DARWIN_BIG_ENDIAN + #define NSFB_BE_BYTE_ORDER + #endif +#else + #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 +181,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 |