]> gitweb.factorcode.org Git - factor.git/commitdiff
throw exceptions on png types we dont support
authorDoug Coleman <erg@jobim.local>
Sat, 16 May 2009 13:46:41 +0000 (08:46 -0500)
committerDoug Coleman <erg@jobim.local>
Sat, 16 May 2009 13:46:41 +0000 (08:46 -0500)
basis/compression/inflate/inflate.factor
basis/images/png/png.factor

index 3e67b11cc724778033db24ba7341a20fe7f5169a..3fe07b5994e5ba0ce1b695fbc387e21db8548834 100755 (executable)
@@ -200,7 +200,9 @@ PRIVATE>
 : reverse-png-filter ( lines -- filtered )\r
     dup first [ 0 ] replicate prefix\r
     [ { 0 0 } prepend  ] map\r
-    2 clump [ first2 dup [ third ] [ 0 2 rot set-nth ] bi png-unfilter-line ] map concat ;\r
+    2 clump [\r
+        first2 dup [ third ] [ 0 2 rot set-nth ] bi png-unfilter-line\r
+    ] map concat ;\r
 \r
 : zlib-inflate ( bytes -- bytes )\r
     bs:<lsb0-bit-reader>\r
index bf13c435460760f9836e204861158c49a01b38df..c5b84de221910ce78d119763422fa29fd09d7c5b 100755 (executable)
@@ -65,14 +65,42 @@ ERROR: bad-checksum ;
 : zlib-data ( png-image -- bytes ) 
     chunks>> [ type>> "IDAT" = ] find nip data>> ;
 
-: decode-png ( image -- image ) 
+ERROR: unknown-color-type n ;
+ERROR: unimplemented-color-type image ;
+
+: inflate-data ( image -- bytes )
+    zlib-data zlib-inflate ; 
+
+: decode-greyscale ( image -- image )
+    unimplemented-color-type ;
+
+: decode-truecolor ( image -- image )
     {
-        [ zlib-data zlib-inflate ] 
+        [ inflate-data ]
         [ dim>> first 3 * 1 + group reverse-png-filter ]
         [ swap >byte-array >>bitmap drop ]
         [ RGB >>component-order drop ]
         [ ]
     } cleave ;
+    
+: decode-indexed-color ( image -- image )
+    unimplemented-color-type ;
+
+: decode-greyscale-alpha ( image -- image )
+    unimplemented-color-type ;
+
+: decode-truecolor-alpha ( image -- image )
+    unimplemented-color-type ;
+
+: decode-png ( image -- image ) 
+    dup color-type>> {
+        { 0 [ decode-greyscale ] }
+        { 2 [ decode-truecolor ] }
+        { 3 [ decode-indexed-color ] }
+        { 4 [ decode-greyscale-alpha ] }
+        { 6 [ decode-truecolor-alpha ] }
+        [ unknown-color-type ]
+    } case ;
 
 : load-png ( path -- image )
     [ binary <file-reader> ] [ file-info size>> ] bi