trying to make sense of png filter modes
parent
117a0e2ac7
commit
71952f702a
|
@ -14,6 +14,18 @@ TUPLE: loading-png
|
||||||
width height bit-depth color-type compression-method
|
width height bit-depth color-type compression-method
|
||||||
filter-method interlace-method uncompressed ;
|
filter-method interlace-method uncompressed ;
|
||||||
|
|
||||||
|
CONSTANT: filter-none 0
|
||||||
|
CONSTANT: filter-sub 1
|
||||||
|
CONSTANT: filter-up 2
|
||||||
|
CONSTANT: filter-average 3
|
||||||
|
CONSTANT: filter-paeth 4
|
||||||
|
|
||||||
|
CONSTANT: greyscale 0
|
||||||
|
CONSTANT: truecolor 2
|
||||||
|
CONSTANT: indexed-color 3
|
||||||
|
CONSTANT: greyscale-alpha 4
|
||||||
|
CONSTANT: truecolor-alpha 6
|
||||||
|
|
||||||
: <loading-png> ( -- image )
|
: <loading-png> ( -- image )
|
||||||
loading-png new
|
loading-png new
|
||||||
V{ } clone >>chunks ;
|
V{ } clone >>chunks ;
|
||||||
|
@ -66,6 +78,7 @@ ERROR: bad-checksum ;
|
||||||
|
|
||||||
ERROR: unknown-color-type n ;
|
ERROR: unknown-color-type n ;
|
||||||
ERROR: unimplemented-color-type image ;
|
ERROR: unimplemented-color-type image ;
|
||||||
|
ERROR: unknown-filter-method image ;
|
||||||
|
|
||||||
: inflate-data ( loading-png -- bytes )
|
: inflate-data ( loading-png -- bytes )
|
||||||
find-compressed-bytes zlib-inflate ;
|
find-compressed-bytes zlib-inflate ;
|
||||||
|
@ -77,9 +90,15 @@ ERROR: unimplemented-color-type image ;
|
||||||
[ unknown-color-type ]
|
[ unknown-color-type ]
|
||||||
} case ;
|
} case ;
|
||||||
|
|
||||||
|
: filter-png ( groups loading-png -- byte-array )
|
||||||
|
filter-method>> {
|
||||||
|
{ filter-none [ reverse-png-filter ] }
|
||||||
|
[ unknown-filter-method ]
|
||||||
|
} case ;
|
||||||
|
|
||||||
: png-image-bytes ( loading-png -- byte-array )
|
: png-image-bytes ( loading-png -- byte-array )
|
||||||
[ inflate-data ] [ png-group-width ] bi group
|
[ [ inflate-data ] [ png-group-width ] bi group ]
|
||||||
reverse-png-filter ;
|
[ filter-png ] bi ;
|
||||||
|
|
||||||
: decode-greyscale ( loading-png -- loading-png )
|
: decode-greyscale ( loading-png -- loading-png )
|
||||||
unimplemented-color-type ;
|
unimplemented-color-type ;
|
||||||
|
@ -127,11 +146,11 @@ ERROR: invalid-color-type/bit-depth loading-png ;
|
||||||
|
|
||||||
: decode-png ( loading-png -- loading-png )
|
: decode-png ( loading-png -- loading-png )
|
||||||
dup color-type>> {
|
dup color-type>> {
|
||||||
{ 0 [ validate-greyscale decode-greyscale ] }
|
{ greyscale [ validate-greyscale decode-greyscale ] }
|
||||||
{ 2 [ validate-truecolor decode-truecolor ] }
|
{ truecolor [ validate-truecolor decode-truecolor ] }
|
||||||
{ 3 [ validate-indexed-color decode-indexed-color ] }
|
{ indexed-color [ validate-indexed-color decode-indexed-color ] }
|
||||||
{ 4 [ validate-greyscale-alpha decode-greyscale-alpha ] }
|
{ greyscale-alpha [ validate-greyscale-alpha decode-greyscale-alpha ] }
|
||||||
{ 6 [ validate-truecolor-alpha decode-truecolor-alpha ] }
|
{ truecolor-alpha [ validate-truecolor-alpha decode-truecolor-alpha ] }
|
||||||
[ unknown-color-type ]
|
[ unknown-color-type ]
|
||||||
} case ;
|
} case ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue