summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshish Gupta <ashmew2@gmail.com>2017-04-02 13:17:29 (GMT)
committer Ashish Gupta <ashmew2@gmail.com>2017-04-02 13:17:29 (GMT)
commite5f4fcde2a7140a82d480867241fddfb3ef62368 (patch)
tree9e7d11873cc331e3805e288a92becfffcc558439
parent18c18d139e7ba8251d6b6c3d62ef1407ff3fc4ad (diff)
parent167205c109291aa1957ba64667efa12ce53bba5d (diff)
downloadlibnsfb-e5f4fcde2a7140a82d480867241fddfb3ef62368.tar.gz
libnsfb-e5f4fcde2a7140a82d480867241fddfb3ef62368.tar.bz2
Merge libnsfb master
-rw-r--r--COPYING20
-rw-r--r--Makefile2
-rw-r--r--README45
-rw-r--r--src/plot.h55
-rw-r--r--src/plot/24bpp.c46
-rw-r--r--src/plot/32bpp-xbgr8888.c55
-rw-r--r--src/plot/32bpp-xrgb8888.c52
7 files changed, 234 insertions, 41 deletions
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..a90a8a7
--- a/dev/null
+++ b/COPYING
@@ -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.
diff --git a/Makefile b/Makefile
index b4eaee6..6c0741c 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/README b/README
new file mode 100644
index 0000000..732e850
--- a/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.
+
diff --git a/src/plot.h b/src/plot.h
index 4b1545d..2fd2ebf 100644
--- a/src/plot.h
+++ b/src/plot.h
@@ -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