throw exceptions on png types we dont support

db4
Doug Coleman 2009-05-16 08:46:41 -05:00
parent 241e6a64bf
commit 89ccc4b00a
2 changed files with 33 additions and 3 deletions
basis
compression/inflate
images/png

View File

@ -200,7 +200,9 @@ PRIVATE>
: reverse-png-filter ( lines -- filtered )
dup first [ 0 ] replicate prefix
[ { 0 0 } prepend ] map
2 clump [ first2 dup [ third ] [ 0 2 rot set-nth ] bi png-unfilter-line ] map concat ;
2 clump [
first2 dup [ third ] [ 0 2 rot set-nth ] bi png-unfilter-line
] map concat ;
: zlib-inflate ( bytes -- bytes )
bs:<lsb0-bit-reader>

View File

@ -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