]> gitweb.factorcode.org Git - factor.git/commitdiff
colors: using 255 * round >integer for hex conversion
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 11 Jan 2022 05:28:57 +0000 (21:28 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 11 Jan 2022 05:28:57 +0000 (21:28 -0800)
basis/html/streams/streams.factor
basis/windows/types/types.factor
basis/windows/uniscribe/uniscribe.factor
extra/color-table/color-table.factor
extra/google/charts/charts.factor
extra/tinyvg/tinyvg.factor

index 3590db7e56125d790364f499892b5b35a48e94e7..efe51db989b7fd160193a2624348999941f78a26 100644 (file)
@@ -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, "; " % ;
index 780be34e89f6b34eedcecfac5622a41be4461431..e6edc14dd178138d577507b777d321b0198647d4 100644 (file)
@@ -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 <rgba> ;
+    >RGB< [ 255 /f ] tri@ 1.0 <rgba> ;
 
 STRUCT: TEXTMETRICW
     { tmHeight LONG }
index 6bf3f18a01d702076d93a865b9ea8e04ad4b4cec..6bc7a05008fdb8f108afc591be1e914ce52baa69 100644 (file)
@@ -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! ]
index ea7d6f5d63b428f862c006a1cebec2dda745d910..03914c67d3ab45d67958538dbefbe9bbd7301697 100644 (file)
@@ -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 <string> ]
 
 : rgba>hex ( rgba -- hex )
     [ red>> ] [ green>> ] [ blue>> ] tri
-    [ 255 * >integer ] tri@ "%02X%02X%02X" sprintf ;
+    [ 255 * round >integer ] tri@ "%02X%02X%02X" sprintf ;
 
 PRIVATE>
 
index 038c114666578a78654e729109572de324354204..02d00f624f5ef055d3a0baad95facffd7a4ac791 100644 (file)
@@ -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 {
index 9407b937f8034b6bd1cf985f1178c18c6b609005..8500bd8830a6ca2d870c08a24ac593ae002c97c4 100644 (file)
@@ -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 <rgba> ;
 
 : 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>