]> gitweb.factorcode.org Git - factor.git/commitdiff
images.normalization: reorder-components should fail if component-order is not a...
authorKeith Lazuka <klazuka@gmail.com>
Fri, 9 Oct 2009 19:50:57 +0000 (15:50 -0400)
committerKeith Lazuka <klazuka@gmail.com>
Fri, 9 Oct 2009 19:58:36 +0000 (15:58 -0400)
basis/images/bitmap/bitmap.factor
extra/images/normalization/normalization-docs.factor
extra/images/normalization/normalization-tests.factor
extra/images/normalization/normalization.factor

index 39241f5978bf1d342470dbf89064b935b01f7222..f14dd3290c81f6c3b5ac7538aafe598bb59f9058 100755 (executable)
@@ -64,5 +64,5 @@ SINGLETON: bmp-image
     ] bi ;
 
 M: bmp-image image>stream
-    drop BGR reorder-colors output-bmp ;
+    drop BGR reorder-components output-bmp ;
 
index 8b78d7a51f6238613142b5c7e66e843d461c0ee6..8ed4b659edb7a5860705f9fd32ce77952f842bdc 100644 (file)
@@ -10,13 +10,15 @@ HELP: normalize-image
 }
 { $description "Converts the image to RGBA with ubyte-components. If the image is upside-down, it will be flipped right side up such that the 1st byte in the bitmap slot's byte array corresponds to the first color component of the pixel in the upper-left corner of the image." } ;
 
-HELP: reorder-colors
+HELP: reorder-components
 { $values
     { "image" image } { "component-order" component-order }
     { "image" image }
 }
 { $description "Convert the bitmap in " { $snippet "image" } " such that the pixel sample layout corresponds to " { $snippet "component-order" } ". If the destination layout cannot find a corresponding value from the source layout, the value " { $snippet "255" } " will be substituted for that byte." }
-{ $warning "The image's " { $snippet "component-type" } " will be changed to " { $snippet "ubyte-components" } " if it is not already in that format." } ;
+{ $warning "The image's " { $snippet "component-type" } " will be changed to " { $snippet "ubyte-components" } " if it is not already in that format."
+$nl
+"You cannot use this word to reorder " { $link DEPTH } ", " { $link DEPTH-STENCIL } " or " { $link INTENSITY } " component orders." } ;
 
 ARTICLE: "images.normalization" "Image normalization"
 "The " { $vocab-link "images.normalization" } " vocab can be used to convert between " { $link image } " representations."
@@ -24,6 +26,6 @@ $nl
 "You can normalize any image to a RGBA with ubyte-components representation:"
 { $subsections normalize-image }
 "Convert an image's pixel layout to match an arbitrary " { $link component-order } ":"
-{ $subsections reorder-colors } ;
+{ $subsections reorder-components } ;
 
 ABOUT: "images.normalization"
index 4fd49c5490bbfe7d324446707455de621d6e5d76..c85aed413f925f25a82563177ff8f6b6792ed8a7 100644 (file)
@@ -60,7 +60,7 @@ IN: images.normalization.tests
 [ B{ 3 2 1 0 7 6 5 4 } ]
 [ B{ 0 1 2 3 4 5 6 7 } RGBA ABGR permute ] unit-test
 
-! A little ad hoc testing
+! Edge cases
 
 [ B{ 0 4 } ]
 [ B{ 0 1 2 3 4 5 6 7 } RGBA R permute ] unit-test
@@ -74,3 +74,35 @@ IN: images.normalization.tests
 [ B{ 255 255 255 255 255 255 255 255 } ]
 [ B{ 0 1 } L RGBA permute ] unit-test
 
+! Invalid inputs
+
+[
+    T{ image f { 1 1 } DEPTH ubyte-components f B{ 0 } }
+    RGB reorder-components
+] must-fail
+
+[
+    T{ image f { 1 1 } DEPTH-STENCIL ubyte-components f B{ 0 } }
+    RGB reorder-components
+] must-fail
+
+[
+    T{ image f { 1 1 } INTENSITY ubyte-components f B{ 0 } }
+    RGB reorder-components
+] must-fail
+
+[
+    T{ image f { 1 1 } RGB ubyte-components f B{ 0 0 0 } }
+    DEPTH reorder-components
+] must-fail
+
+[
+    T{ image f { 1 1 } RGB ubyte-components f B{ 0 0 0 } }
+    DEPTH-STENCIL reorder-components
+] must-fail
+
+[
+    T{ image f { 1 1 } RGB ubyte-components f B{ 0 0 0 } }
+    INTENSITY reorder-components
+] must-fail
+
index cb921010aaa07b3f034b4682598510e3a4c34a6f..0beaa1de1d13afa13d965d9a51597154953adf71 100755 (executable)
@@ -32,7 +32,7 @@ CONSTANT: fill-value 255
         [ pad4 src dst permutation shuffle dst length head ]
         map concat ] ;
 
-: (reorder-colors) ( image src-order dest-order -- image )
+: (reorder-components) ( image src-order dest-order -- image )
     [ permute ] 2curry change-bitmap ;
 
 GENERIC: normalize-component-type* ( image component-type -- image )
@@ -63,17 +63,23 @@ M: ubyte-components normalize-component-type*
         f >>upside-down?
     ] when ;
 
+: validate-request ( src-order dst-order -- src-order dst-order )
+    [
+        [ { DEPTH DEPTH-STENCIL INTENSITY } member? ] bi@
+        or [ "Invalid component-order" throw ] when
+    ] 2keep ;
+
 PRIVATE>
 
-: reorder-colors ( image component-order -- image )
+: reorder-components ( image component-order -- image )
     [
         dup component-type>> '[ _ normalize-component-type* ] change-bitmap
         dup component-order>>
     ] dip
-    [ (reorder-colors) ] keep >>component-order ;
+    validate-request [ (reorder-components) ] keep >>component-order ;
 
 : normalize-image ( image -- image )
     [ >byte-array ] change-bitmap
-    RGBA reorder-colors
+    RGBA reorder-components
     normalize-scan-line-order ;