summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2022-03-26 15:11:32 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2022-03-27 09:58:21 +0100
commitaeead57677cbeaeaef5b73c5b02e6b2144a2bae2 (patch)
tree5c61023b5fdbe26e8f5ee2bf36bdeb0a32526f55
parentd00c049d0221c5b63a6a423d5adc7933ac1e758d (diff)
downloadnetsurf-aeead57677cbeaeaef5b73c5b02e6b2144a2bae2.tar.gz
netsurf-aeead57677cbeaeaef5b73c5b02e6b2144a2bae2.tar.bz2
Bitmap: Convert pixel_to_colour to layout-aware function.
-rw-r--r--desktop/bitmap.h28
1 files changed, 22 insertions, 6 deletions
diff --git a/desktop/bitmap.h b/desktop/bitmap.h
index 8756c50a1..107089f66 100644
--- a/desktop/bitmap.h
+++ b/desktop/bitmap.h
@@ -25,11 +25,9 @@
#include <nsutils/endian.h>
+#include "netsurf/types.h"
#include "netsurf/bitmap.h"
-/** The client bitmap format. */
-extern bitmap_fmt_t bitmap_fmt;
-
/** Pixel format: colour component order. */
struct bitmap_colour_layout {
uint8_t r; /**< Byte offset within pixel to red component. */
@@ -38,6 +36,12 @@ struct bitmap_colour_layout {
uint8_t a; /**< Byte offset within pixel to alpha component. */
};
+/** The client bitmap format. */
+extern bitmap_fmt_t bitmap_fmt;
+
+/** The client bitmap colour channel layout. */
+extern struct bitmap_colour_layout bitmap_layout;
+
/**
* Get the colour layout for the given bitmap format.
*
@@ -84,9 +88,21 @@ static inline struct bitmap_colour_layout bitmap__get_colour_layout(
}
}
-/* get a bitmap pixel (image/bitmap.h) into a plot colour */
-#define bitmap_pixel_to_colour(b) \
- b[0] | (b[1] << 8) | (b[2] << 16) | (b[3] << 24)
+/**
+ * Convert a bitmap pixel to a NetSurf colour (0xAARRGGBB).
+ *
+ * The bitmap must be in the client format.
+ *
+ * \param[in] Pointer to a pixel in the bitmap's pixel data.
+ * \return The corresponding NetSurf colour.
+ */
+static inline colour bitmap_pixel_to_colour(const uint8_t *pixel)
+{
+ return (pixel[bitmap_layout.r] << 0) |
+ (pixel[bitmap_layout.g] << 8) |
+ (pixel[bitmap_layout.b] << 16) |
+ (pixel[bitmap_layout.a] << 24);
+}
/**
* Sanitise bitmap pixel component layout.