throw exceptions on png types we dont support
							parent
							
								
									241e6a64bf
								
							
						
					
					
						commit
						89ccc4b00a
					
				| 
						 | 
					@ -200,7 +200,9 @@ PRIVATE>
 | 
				
			||||||
: reverse-png-filter ( lines -- filtered )
 | 
					: reverse-png-filter ( lines -- filtered )
 | 
				
			||||||
    dup first [ 0 ] replicate prefix
 | 
					    dup first [ 0 ] replicate prefix
 | 
				
			||||||
    [ { 0 0 } prepend  ] map
 | 
					    [ { 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 )
 | 
					: zlib-inflate ( bytes -- bytes )
 | 
				
			||||||
    bs:<lsb0-bit-reader>
 | 
					    bs:<lsb0-bit-reader>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -65,14 +65,42 @@ ERROR: bad-checksum ;
 | 
				
			||||||
: zlib-data ( png-image -- bytes ) 
 | 
					: zlib-data ( png-image -- bytes ) 
 | 
				
			||||||
    chunks>> [ type>> "IDAT" = ] find nip data>> ;
 | 
					    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 ]
 | 
					        [ dim>> first 3 * 1 + group reverse-png-filter ]
 | 
				
			||||||
        [ swap >byte-array >>bitmap drop ]
 | 
					        [ swap >byte-array >>bitmap drop ]
 | 
				
			||||||
        [ RGB >>component-order drop ]
 | 
					        [ RGB >>component-order drop ]
 | 
				
			||||||
        [ ]
 | 
					        [ ]
 | 
				
			||||||
    } cleave ;
 | 
					    } 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 )
 | 
					: load-png ( path -- image )
 | 
				
			||||||
    [ binary <file-reader> ] [ file-info size>> ] bi
 | 
					    [ binary <file-reader> ] [ file-info size>> ] bi
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue