images.png: Support for reading iCCP chunks with color profiles
To fix #1529 you need to read the color profile from the image and then do something with it.locals-and-roots
parent
7c7d314e49
commit
af53fdd3d0
|
@ -1,6 +1,7 @@
|
||||||
! Copyright (C) 2009 Doug Coleman, Keith Lazuka
|
! Copyright (C) 2009 Doug Coleman, Keith Lazuka
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: images.testing io.directories images.png sequences ;
|
USING: accessors images.png images.testing io.directories
|
||||||
|
io.encodings.binary io.files sequences tools.test ;
|
||||||
IN: images.png.tests
|
IN: images.png.tests
|
||||||
|
|
||||||
! Test files from PngSuite (http://www.libpng.org/pub/png/pngsuite.html)
|
! Test files from PngSuite (http://www.libpng.org/pub/png/pngsuite.html)
|
||||||
|
@ -75,6 +76,10 @@ IN: images.png.tests
|
||||||
"z06n2c08.png"
|
"z06n2c08.png"
|
||||||
"z09n2c08.png"
|
"z09n2c08.png"
|
||||||
} [ png-image decode-test ] each
|
} [ png-image decode-test ] each
|
||||||
|
|
||||||
|
{ "ICC Profile" } [
|
||||||
|
"1529.png" binary <file-reader> load-png icc-profile>> name>>
|
||||||
|
] unit-test
|
||||||
] with-directory
|
] with-directory
|
||||||
|
|
||||||
! Test pngsuite
|
! Test pngsuite
|
||||||
|
@ -245,7 +250,6 @@ IN: images.png.tests
|
||||||
"z06n2c08.png"
|
"z06n2c08.png"
|
||||||
"z09n2c08.png"
|
"z09n2c08.png"
|
||||||
} [ png-image decode-test ] each
|
} [ png-image decode-test ] each
|
||||||
|
|
||||||
] with-directory
|
] with-directory
|
||||||
|
|
||||||
"vocab:images/testing/png/suite/bads" [
|
"vocab:images/testing/png/suite/bads" [
|
||||||
|
|
|
@ -1,21 +1,22 @@
|
||||||
! Copyright (C) 2009 Doug Coleman.
|
! Copyright (C) 2009 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors arrays assocs byte-arrays checksums
|
USING: accessors arrays assocs checksums checksums.crc32 combinators
|
||||||
checksums.crc32 combinators compression.inflate fry grouping
|
compression.inflate fry grouping images images.loader io io.binary
|
||||||
images images.loader io io.binary io.encodings.ascii
|
io.encodings.8-bit.latin1 io.encodings.ascii io.encodings.binary
|
||||||
io.encodings.binary io.encodings.string io.streams.byte-array
|
io.encodings.string io.streams.byte-array io.streams.throwing kernel
|
||||||
io.streams.throwing kernel locals math math.bitwise
|
locals math math.bitwise math.functions sequences sorting splitting ;
|
||||||
math.functions math.order math.ranges sequences sorting ;
|
|
||||||
QUALIFIED: bitstreams
|
QUALIFIED: bitstreams
|
||||||
IN: images.png
|
IN: images.png
|
||||||
|
|
||||||
SINGLETON: png-image
|
SINGLETON: png-image
|
||||||
"png" png-image ?register-image-class
|
"png" png-image ?register-image-class
|
||||||
|
|
||||||
|
TUPLE: icc-profile name data ;
|
||||||
|
|
||||||
TUPLE: loading-png
|
TUPLE: loading-png
|
||||||
chunks
|
chunks
|
||||||
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 icc-profile ;
|
||||||
|
|
||||||
CONSTANT: filter-none 0
|
CONSTANT: filter-none 0
|
||||||
CONSTANT: filter-sub 1
|
CONSTANT: filter-sub 1
|
||||||
|
@ -77,6 +78,9 @@ ERROR: bad-checksum ;
|
||||||
: find-chunks ( loading-png string -- chunk )
|
: find-chunks ( loading-png string -- chunk )
|
||||||
[ chunks>> ] dip '[ type>> _ = ] filter ;
|
[ chunks>> ] dip '[ type>> _ = ] filter ;
|
||||||
|
|
||||||
|
: read-png-string ( -- str )
|
||||||
|
{ 0 } read-until drop latin1 decode ;
|
||||||
|
|
||||||
: parse-ihdr-chunk ( loading-png -- loading-png )
|
: parse-ihdr-chunk ( loading-png -- loading-png )
|
||||||
dup "IHDR" find-chunk data>> {
|
dup "IHDR" find-chunk data>> {
|
||||||
[ [ 0 4 ] dip subseq be> >>width ]
|
[ [ 0 4 ] dip subseq be> >>width ]
|
||||||
|
@ -88,6 +92,16 @@ ERROR: bad-checksum ;
|
||||||
[ [ 12 ] dip nth >>interlace-method ]
|
[ [ 12 ] dip nth >>interlace-method ]
|
||||||
} cleave ;
|
} cleave ;
|
||||||
|
|
||||||
|
: <icc-profile> ( byte-array -- icc-profile )
|
||||||
|
binary [
|
||||||
|
read-png-string read1 drop contents zlib-inflate
|
||||||
|
] with-byte-reader icc-profile boa ;
|
||||||
|
|
||||||
|
: parse-iccp-chunk ( loading-png -- loading-png )
|
||||||
|
dup "iCCP" find-chunk [
|
||||||
|
data>> <icc-profile> >>icc-profile
|
||||||
|
] when* ;
|
||||||
|
|
||||||
: find-compressed-bytes ( loading-png -- bytes )
|
: find-compressed-bytes ( loading-png -- bytes )
|
||||||
"IDAT" find-chunks [ data>> ] map concat ;
|
"IDAT" find-chunks [ data>> ] map concat ;
|
||||||
|
|
||||||
|
@ -353,6 +367,7 @@ ERROR: invalid-color-type/bit-depth loading-png ;
|
||||||
read-png-header
|
read-png-header
|
||||||
read-png-chunks
|
read-png-chunks
|
||||||
parse-ihdr-chunk
|
parse-ihdr-chunk
|
||||||
|
parse-iccp-chunk
|
||||||
] throw-on-eof
|
] throw-on-eof
|
||||||
] with-input-stream ;
|
] with-input-stream ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue