 
 QUALIFIED-WITH: bitstreams bs
 
-TUPLE: jpeg-image < image
+SINGLETON: jpeg-image
+
+TUPLE: loading-jpeg < image
     { headers }
     { bitstream }
     { color-info initial: { f f f f } }


ERROR: not-a-jpeg-image ;

PRIVATE>

M: jpeg-image stream>image ( stream jpeg-image -- bitmap )
    drop [
        parse-marker { SOI } = [ not-a-jpeg-image ] unless
        parse-headers
        contents <jpeg-image>
    ] with-input-stream
    dup jpeg-image [
        baseline-parse
        baseline-decompress
    ] with-variable ;


<PRIVATE

: <loading-jpeg> ( headers bitstream -- image )
    loading-jpeg new swap >>bitstream swap >>headers ;

SINGLETONS: SOF DHT DAC RST SOI EOI SOS DQT DNL DRI DHP EXP
APP JPG COM TEM RES ;
