Better error images for non-baseline JPEGs.

bugfix: Handles more than one table per DHT chunk.
db4
Marc Fauconneau 2009-08-30 17:29:40 +09:00
parent bf15648b4d
commit 5a20dee2aa
1 changed files with 11 additions and 8 deletions

View File

@ -6,7 +6,7 @@ images.processing io io.binary io.encodings.binary io.files
io.streams.byte-array kernel locals math math.bitwise io.streams.byte-array kernel locals math math.bitwise
math.constants math.functions math.matrices math.order math.constants math.functions math.matrices math.order
math.ranges math.vectors memoize multiline namespaces math.ranges math.vectors memoize multiline namespaces
sequences sequences.deep images.loader ; sequences sequences.deep images.loader io.streams.limited ;
IN: images.jpeg IN: images.jpeg
QUALIFIED-WITH: bitstreams bs QUALIFIED-WITH: bitstreams bs
@ -118,18 +118,18 @@ TUPLE: jpeg-color-info
] with-byte-reader ; ] with-byte-reader ;
: decode-huff-table ( chunk -- ) : decode-huff-table ( chunk -- )
data>> data>> [ binary <byte-reader> ] [ length ] bi
binary stream-throws limit
[ [
1 ! %fixme: Should handle multiple tables at once [ input-stream get [ count>> ] [ limit>> ] bi < ]
[ [
read4/4 swap 2 * + read4/4 swap 2 * +
16 read 16 read
dup [ ] [ + ] map-reduce read dup [ ] [ + ] map-reduce read
binary [ [ read [ B{ } ] unless* ] { } map-as ] with-byte-reader binary [ [ read [ B{ } ] unless* ] { } map-as ] with-byte-reader
swap jpeg> huff-tables>> set-nth swap jpeg> huff-tables>> set-nth
] times ] while
] with-byte-reader ; ] with-input-stream* ;
: decode-scan ( chunk -- ) : decode-scan ( chunk -- )
data>> data>>
@ -148,7 +148,10 @@ TUPLE: jpeg-color-info
: singleton-first ( seq -- elt ) : singleton-first ( seq -- elt )
[ length 1 assert= ] [ first ] bi ; [ length 1 assert= ] [ first ] bi ;
ERROR: not-a-baseline-jpeg-image ;
: baseline-parse ( -- ) : baseline-parse ( -- )
jpeg> headers>> [ type>> { SOF 0 } = ] any? [ not-a-baseline-jpeg-image ] unless
jpeg> headers>> jpeg> headers>>
{ {
[ [ type>> { SOF 0 } = ] filter singleton-first decode-frame ] [ [ type>> { SOF 0 } = ] filter singleton-first decode-frame ]
@ -221,7 +224,7 @@ MEMO: dct-matrix-blas ( -- m ) dct-matrix >float-blas-matrix ;
: V.M ( x A -- x.A ) Mtranspose swap M.V ; : V.M ( x A -- x.A ) Mtranspose swap M.V ;
: idct-blas ( b -- b' ) >float-blas-vector dct-matrix-blas V.M ; : idct-blas ( b -- b' ) >float-blas-vector dct-matrix-blas V.M ;
: idct ( b -- b' ) idct-blas ; : idct ( b -- b' ) idct-factor ;
:: draw-block ( block x,y color-id jpeg-image -- ) :: draw-block ( block x,y color-id jpeg-image -- )
block dup length>> sqrt >fixnum group flip block dup length>> sqrt >fixnum group flip