Gitweb links:

...log 
http://git.netsurf-browser.org/netsurf.git/shortlog/e34f1c8b3372fb96f2fa6a26ec7f5e04a7fa6523
...commit 
http://git.netsurf-browser.org/netsurf.git/commit/e34f1c8b3372fb96f2fa6a26ec7f5e04a7fa6523
...tree 
http://git.netsurf-browser.org/netsurf.git/tree/e34f1c8b3372fb96f2fa6a26ec7f5e04a7fa6523

The branch, master has been updated
       via  e34f1c8b3372fb96f2fa6a26ec7f5e04a7fa6523 (commit)
       via  49a515c8089e345552afd86d5675144745bc06bb (commit)
      from  b47a897699daa83f1725fa23cdd16ee56328ac60 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=e34f1c8b3372fb96f2fa6a26ec7f5e04a7fa6523
commit e34f1c8b3372fb96f2fa6a26ec7f5e04a7fa6523
Author: Vincent Sanders <[email protected]>
Commit: Vincent Sanders <[email protected]>

    ensure background fraction is a proper fraction

diff --git a/utils/nscolour.c b/utils/nscolour.c
index 0b36bab..a071752 100644
--- a/utils/nscolour.c
+++ b/utils/nscolour.c
@@ -68,24 +68,31 @@ static nserror nscolour__get(
 {
        nserror res;
        bool dark_mode;
-       colour bg_temp;
+       colour bg_sys;
 
        assert(name_bg != NULL);
        assert(name_fg != NULL);
        assert(bg != NULL);
        assert(fg != NULL);
 
-       res = ns_system_colour_char(name_bg, &bg_temp);
+       /* user configured background colour */
+       res = ns_system_colour_char(name_bg, &bg_sys);
        if (res != NSERROR_OK) {
                return res;
        }
 
+       /* user configured foreground colour */
        res = ns_system_colour_char(name_fg, fg);
        if (res != NSERROR_OK) {
                return res;
        }
 
-       *bg = mix_colour(bg_temp, *fg, 255 * bg_num / bg_den);
+       /* if there is a valid background fraction apply it */
+       if (bg_num < bg_den) {
+               *bg = mix_colour(bg_sys, *fg, 255 * bg_num / bg_den);
+       } else {
+               *bg = bg_sys;
+       }
 
        dark_mode = colour_lightness(*fg) > colour_lightness(*bg);
 
@@ -114,7 +121,7 @@ static nserror nscolour__get(
        }
 
        if (border != NULL) {
-               *border = mix_colour(*fg, bg_temp, 255 * 8 / 32);
+               *border = mix_colour(*fg, bg_sys, 255 * 8 / 32);
        }
 
        return NSERROR_OK;


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=49a515c8089e345552afd86d5675144745bc06bb
commit 49a515c8089e345552afd86d5675144745bc06bb
Author: Vincent Sanders <[email protected]>
Commit: Vincent Sanders <[email protected]>

    Improve colour_lightness
    
    Clearly document what colour_lightness does.
    Fix the blue component value multiplier to be in bounds and correct value

diff --git a/include/netsurf/plot_style.h b/include/netsurf/plot_style.h
index c406092..bfc0805 100644
--- a/include/netsurf/plot_style.h
+++ b/include/netsurf/plot_style.h
@@ -125,12 +125,12 @@ typedef struct plot_font_style {
 
 
 /* Darken a colour by taking seven eighths of each channel's intensity */
-#define half_darken_colour(c1)                                         \
+#define half_darken_colour(c1)                                         \
        ((((7 * (c1 & 0xff00ff)) >> 3) & 0xff00ff) |                    \
         (((7 * (c1 & 0x00ff00)) >> 3) & 0x00ff00))
 
 /* Darken a colour by taking three quarters of each channel's intensity */
-#define darken_colour(c1)                                              \
+#define darken_colour(c1)                                              \
        ((((3 * (c1 & 0xff00ff)) >> 2) & 0xff00ff) |                    \
         (((3 * (c1 & 0x00ff00)) >> 2) & 0x00ff00))
 
@@ -164,11 +164,24 @@ typedef struct plot_font_style {
        (((((c0 & 0xff00ff) + (c1 & 0xff00ff)) >> 1) & 0xff00ff) |      \
         ((((c0 & 0x00ff00) + (c1 & 0x00ff00)) >> 1) & 0x00ff00))
 
-/* Get the percieved lightness of the supplied colour, c0. */
+/**
+ * Obtain the luminance of a colour according to ITU BT.601
+ *
+ * ITU BT.601 formula is
+ * Y = 0.299 R + 0.587 G + 0.114 B
+ * actual values are
+ * Y = 76/255 R + 150/255 G + 29/255 B
+ * Y = 0.298 R + 0.588 G + 0.113 B
+ *
+ * @note if additional performance is required this could be altered to
+ *       Y = 0.375 R + 0.5 G + 0.125 B
+ *       with
+ *       Y = (R << 1 + R + G << 2 + B) >> 3
+ */
 #define colour_lightness(c0)                                           \
        ((((c0 & 0x0000ff) *  77) >>  8) +                              \
         (((c0 & 0x00ff00) * 151) >> 16) +                              \
-        (((c0 & 0xff0000) *  28) >> 24))
+        (((c0 & 0xff0000) *  30) >> 24))
 
 /* Choose either black or white, depending on which is nearest to the
  * percieved lightness of the supplied colour, c0. */


-----------------------------------------------------------------------

Summary of changes:
 include/netsurf/plot_style.h |   21 +++++++++++++++++----
 utils/nscolour.c             |   15 +++++++++++----
 2 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/include/netsurf/plot_style.h b/include/netsurf/plot_style.h
index c406092..bfc0805 100644
--- a/include/netsurf/plot_style.h
+++ b/include/netsurf/plot_style.h
@@ -125,12 +125,12 @@ typedef struct plot_font_style {
 
 
 /* Darken a colour by taking seven eighths of each channel's intensity */
-#define half_darken_colour(c1)                                         \
+#define half_darken_colour(c1)                                         \
        ((((7 * (c1 & 0xff00ff)) >> 3) & 0xff00ff) |                    \
         (((7 * (c1 & 0x00ff00)) >> 3) & 0x00ff00))
 
 /* Darken a colour by taking three quarters of each channel's intensity */
-#define darken_colour(c1)                                              \
+#define darken_colour(c1)                                              \
        ((((3 * (c1 & 0xff00ff)) >> 2) & 0xff00ff) |                    \
         (((3 * (c1 & 0x00ff00)) >> 2) & 0x00ff00))
 
@@ -164,11 +164,24 @@ typedef struct plot_font_style {
        (((((c0 & 0xff00ff) + (c1 & 0xff00ff)) >> 1) & 0xff00ff) |      \
         ((((c0 & 0x00ff00) + (c1 & 0x00ff00)) >> 1) & 0x00ff00))
 
-/* Get the percieved lightness of the supplied colour, c0. */
+/**
+ * Obtain the luminance of a colour according to ITU BT.601
+ *
+ * ITU BT.601 formula is
+ * Y = 0.299 R + 0.587 G + 0.114 B
+ * actual values are
+ * Y = 76/255 R + 150/255 G + 29/255 B
+ * Y = 0.298 R + 0.588 G + 0.113 B
+ *
+ * @note if additional performance is required this could be altered to
+ *       Y = 0.375 R + 0.5 G + 0.125 B
+ *       with
+ *       Y = (R << 1 + R + G << 2 + B) >> 3
+ */
 #define colour_lightness(c0)                                           \
        ((((c0 & 0x0000ff) *  77) >>  8) +                              \
         (((c0 & 0x00ff00) * 151) >> 16) +                              \
-        (((c0 & 0xff0000) *  28) >> 24))
+        (((c0 & 0xff0000) *  30) >> 24))
 
 /* Choose either black or white, depending on which is nearest to the
  * percieved lightness of the supplied colour, c0. */
diff --git a/utils/nscolour.c b/utils/nscolour.c
index 0b36bab..a071752 100644
--- a/utils/nscolour.c
+++ b/utils/nscolour.c
@@ -68,24 +68,31 @@ static nserror nscolour__get(
 {
        nserror res;
        bool dark_mode;
-       colour bg_temp;
+       colour bg_sys;
 
        assert(name_bg != NULL);
        assert(name_fg != NULL);
        assert(bg != NULL);
        assert(fg != NULL);
 
-       res = ns_system_colour_char(name_bg, &bg_temp);
+       /* user configured background colour */
+       res = ns_system_colour_char(name_bg, &bg_sys);
        if (res != NSERROR_OK) {
                return res;
        }
 
+       /* user configured foreground colour */
        res = ns_system_colour_char(name_fg, fg);
        if (res != NSERROR_OK) {
                return res;
        }
 
-       *bg = mix_colour(bg_temp, *fg, 255 * bg_num / bg_den);
+       /* if there is a valid background fraction apply it */
+       if (bg_num < bg_den) {
+               *bg = mix_colour(bg_sys, *fg, 255 * bg_num / bg_den);
+       } else {
+               *bg = bg_sys;
+       }
 
        dark_mode = colour_lightness(*fg) > colour_lightness(*bg);
 
@@ -114,7 +121,7 @@ static nserror nscolour__get(
        }
 
        if (border != NULL) {
-               *border = mix_colour(*fg, bg_temp, 255 * 8 / 32);
+               *border = mix_colour(*fg, bg_sys, 255 * 8 / 32);
        }
 
        return NSERROR_OK;


-- 
NetSurf Browser
_______________________________________________
netsurf-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to