]> gitweb.factorcode.org Git - factor.git/commitdiff
colors.xyy: implement CIE xyY colors.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sat, 21 Jun 2014 03:22:11 +0000 (20:22 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sat, 21 Jun 2014 03:22:11 +0000 (20:22 -0700)
extra/colors/xyy/authors.txt [new file with mode: 0644]
extra/colors/xyy/summary.txt [new file with mode: 0644]
extra/colors/xyy/xyy-docs.factor [new file with mode: 0644]
extra/colors/xyy/xyy-tests.factor [new file with mode: 0644]
extra/colors/xyy/xyy.factor [new file with mode: 0644]

diff --git a/extra/colors/xyy/authors.txt b/extra/colors/xyy/authors.txt
new file mode 100644 (file)
index 0000000..e091bb8
--- /dev/null
@@ -0,0 +1 @@
+John Benediktsson
diff --git a/extra/colors/xyy/summary.txt b/extra/colors/xyy/summary.txt
new file mode 100644 (file)
index 0000000..8d39db0
--- /dev/null
@@ -0,0 +1 @@
+xyY colors
diff --git a/extra/colors/xyy/xyy-docs.factor b/extra/colors/xyy/xyy-docs.factor
new file mode 100644 (file)
index 0000000..20238a4
--- /dev/null
@@ -0,0 +1,14 @@
+USING: help.markup help.syntax ;
+IN: colors.xyy
+
+HELP: xyYa
+{ $class-description "The class of CIE xyY colors with an alpha channel." } ;
+
+ARTICLE: "colors.xyy" "xyY colors"
+"The " { $vocab-link "colors.xyy" } " vocabulary implements CIE xyY colors, together with an alpha channel."
+{ $subsections
+    xyYa
+    <xyYa>
+    >xyYa
+}
+{ $see-also "colors" } ;
diff --git a/extra/colors/xyy/xyy-tests.factor b/extra/colors/xyy/xyy-tests.factor
new file mode 100644 (file)
index 0000000..4907ae6
--- /dev/null
@@ -0,0 +1,19 @@
+! Copyright (C) 2014 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+
+USING: arrays colors kernel locals math.functions math.ranges
+sequences tools.test ;
+
+IN: colors.xyy
+
+{ t } [
+    0.0 1.0 0.1 <range> [| r |
+        0.0 1.0 0.1 <range> [| g |
+            0.0 1.0 0.1 <range> [| b |
+                r g b 1.0 <rgba> dup >xyYa >rgba
+                [ >rgba-components 4array ] bi@
+                [ 0.00001 ~ ] 2all?
+            ] all?
+        ] all?
+    ] all?
+] unit-test
diff --git a/extra/colors/xyy/xyy.factor b/extra/colors/xyy/xyy.factor
new file mode 100644 (file)
index 0000000..d4826bc
--- /dev/null
@@ -0,0 +1,40 @@
+! Copyright (C) 2014 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+
+USING: accessors colors colors.xyz kernel locals math ;
+
+IN: colors.xyy
+
+TUPLE: xyYa x y Y alpha ;
+
+C: <xyYa> xyYa
+
+M: xyYa >rgba
+    >xyza >rgba ;
+
+M: xyYa >xyza
+    [
+        [let
+            [ x>> ] [ y>> ] [ Y>> ] tri :> ( x y Y )
+            x y / Y *
+            Y
+            1 x - y - y / Y *
+        ]
+    ] [ alpha>> ] bi <xyza> ;
+
+GENERIC: >xyYa ( color -- xyYa )
+
+M: object >xyYa >xyza >xyYa ;
+
+M: xyYa >xyYa ; inline
+
+M: xyza >xyYa
+    [
+        [let
+            [ x>> ] [ y>> ] [ z>> ] tri :> ( x y z )
+            x y z + +
+            [ x swap / ]
+            [ y swap / ] bi
+            y
+        ]
+    ] [ alpha>> ] bi <xyYa> ;