From 1b09f93777bb30cffc7af9314a51446bf9b06408 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Mon, 10 Jan 2022 21:28:57 -0800 Subject: [PATCH] colors: using 255 * round >integer for hex conversion --- basis/html/streams/streams.factor | 6 +++--- basis/windows/types/types.factor | 6 +++--- basis/windows/uniscribe/uniscribe.factor | 9 +++++---- extra/color-table/color-table.factor | 8 ++++---- extra/google/charts/charts.factor | 6 +++--- extra/tinyvg/tinyvg.factor | 4 ++-- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/basis/html/streams/streams.factor b/basis/html/streams/streams.factor index 3590db7e56..efe51db989 100644 --- a/basis/html/streams/streams.factor +++ b/basis/html/streams/streams.factor @@ -2,8 +2,8 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors assocs combinators destructors fry html io io.backend io.pathnames io.styles kernel macros make math -math.order math.parser namespaces sequences strings words -splitting xml xml.syntax ; +math.functions math.order math.parser namespaces sequences +strings words splitting xml xml.syntax ; IN: html.streams GENERIC: url-of ( object -- url ) @@ -36,7 +36,7 @@ TUPLE: html-sub-stream < html-writer style parent ; : hex-color, ( color -- ) [ red>> ] [ green>> ] [ blue>> ] tri - [ 255 * >integer >hex 2 CHAR: 0 pad-head % ] tri@ ; + [ 255 * round >integer >hex 2 CHAR: 0 pad-head % ] tri@ ; : fg-css, ( color -- ) "color: #" % hex-color, "; " % ; diff --git a/basis/windows/types/types.factor b/basis/windows/types/types.factor index 780be34e89..e6edc14dd1 100644 --- a/basis/windows/types/types.factor +++ b/basis/windows/types/types.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: alien.c-types alien.syntax classes.struct colors io.encodings.utf16n io.encodings.utf8 kernel math math.bitwise -math.vectors sequences ; +math.functions math.vectors sequences ; FROM: alien.c-types => float short ; IN: windows.types @@ -379,9 +379,9 @@ TYPEDEF: DWORD* LPCOLORREF [ -16 shift 0xff bitand ] tri ; : color>RGB ( color -- COLORREF ) - >rgba-components drop [ 255 * >integer ] tri@ RGB ; + >rgba-components drop [ 255 round * >integer ] tri@ RGB ; : RGB>color ( COLORREF -- color ) - >RGB< [ 1/255. * >float ] tri@ 1.0 ; + >RGB< [ 255 /f ] tri@ 1.0 ; STRUCT: TEXTMETRICW { tmHeight LONG } diff --git a/basis/windows/uniscribe/uniscribe.factor b/basis/windows/uniscribe/uniscribe.factor index 6bf3f18a01..6bc7a05008 100644 --- a/basis/windows/uniscribe/uniscribe.factor +++ b/basis/windows/uniscribe/uniscribe.factor @@ -4,9 +4,10 @@ USING: accessors alien.c-types alien.data arrays assocs byte-arrays cache classes.struct colors combinators destructors fonts images init io.encodings.string io.encodings.utf16n kernel -literals locals math math.bitwise namespaces sequences -specialized-arrays windows.errors windows.fonts windows.gdi32 -windows.offscreen windows.ole32 windows.types windows.usp10 ; +literals locals math math.bitwise math.functions namespaces +sequences specialized-arrays windows.errors windows.fonts +windows.gdi32 windows.offscreen windows.ole32 windows.types +windows.usp10 ; SPECIALIZED-ARRAY: uint32_t IN: windows.uniscribe @@ -106,7 +107,7 @@ PRIVATE> ! transparency. :: color-to-alpha ( image color -- image' ) color >rgba-components :> alpha - [ 255 * >integer ] tri@ 3byte-array uint32_t deref 24 bits :> rgb + [ 255 * round >integer ] tri@ 3byte-array uint32_t deref 24 bits :> rgb image bitmap>> uint32_t cast-array alpha 1 < [ [ 0xff bitand alpha * >integer 24 shift rgb bitor ] map! ] diff --git a/extra/color-table/color-table.factor b/extra/color-table/color-table.factor index ea7d6f5d63..03914c67d3 100644 --- a/extra/color-table/color-table.factor +++ b/extra/color-table/color-table.factor @@ -1,9 +1,9 @@ ! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors colors combinators combinators.smart formatting -kernel literals math models sorting.human sorting.slots strings ui -ui.gadgets.scrollers ui.gadgets.search-tables ui.gadgets.tables -; +kernel literals math math.functions models sorting.human +sorting.slots strings ui ui.gadgets.scrollers +ui.gadgets.search-tables ui.gadgets.tables ; IN: color-table ! ui.gadgets.tables demo @@ -15,7 +15,7 @@ CONSTANT: full-block-string $[ 10 CHAR: full-block ] : rgba>hex ( rgba -- hex ) [ red>> ] [ green>> ] [ blue>> ] tri - [ 255 * >integer ] tri@ "%02X%02X%02X" sprintf ; + [ 255 * round >integer ] tri@ "%02X%02X%02X" sprintf ; PRIVATE> diff --git a/extra/google/charts/charts.factor b/extra/google/charts/charts.factor index 038c114666..02d00f624f 100644 --- a/extra/google/charts/charts.factor +++ b/extra/google/charts/charts.factor @@ -3,8 +3,8 @@ USING: accessors arrays assocs combinators formatting http.client images.http images.loader images.loader.private -images.viewer kernel math math.order present sequences splitting -urls ; +images.viewer kernel math math.functions math.order present +sequences splitting urls ; IN: google.charts @@ -72,7 +72,7 @@ PRIVATE> : rgba>hex ( rgba -- hex ) [ red>> ] [ green>> ] [ blue>> ] tri - [ 255 * >integer ] tri@ "%02X%02X%02X" sprintf ; + [ 255 * round >integer ] tri@ "%02X%02X%02X" sprintf ; : chart>url ( chart -- url ) [ URL" http://chart.googleapis.com/chart" clone ] dip { diff --git a/extra/tinyvg/tinyvg.factor b/extra/tinyvg/tinyvg.factor index 9407b937f8..8500bd8830 100644 --- a/extra/tinyvg/tinyvg.factor +++ b/extra/tinyvg/tinyvg.factor @@ -3,7 +3,7 @@ USING: accessors colors combinators endian generalizations io io.encodings.binary io.files io.streams.byte-array kernel math -math.bitwise namespaces sequences ; +math.bitwise math.functions namespaces sequences ; IN: tinyvg @@ -38,7 +38,7 @@ ERROR: invalid-length n ; [ read1 255 /f ] 4 call-n ; : write-rgba-8888 ( rgba -- ) - >rgba-components [ 255 * >integer write1 ] 4 napply ; + >rgba-components [ 255 * round >integer write1 ] 4 napply ; : read-rgb-565 ( -- rgba ) 2 read le> -- 2.34.1