         { 281 [ max-sample-value ] }
         { 282 [ first x-resolution ] }
         { 283 [ first y-resolution ] }
-        { 284 [ planar-configuration ] }
+        { 284 [ lookup-planar-configuration planar-configuration ] }
         { 285 [ page-name ] }
         { 286 [ x-position ] }
         { 287 [ y-position ] }

        { 266 [ fill-order ] }
        { 269 [ ascii decode document-name ] }
        { 270 [ ascii decode image-description ] }
        { 271 [ ascii decode make ] }
        { 272 [ ascii decode model ] }
        { 273 [ strip-offsets ] }
        { 274 [ orientation ] }
        { 277 [ samples-per-pixel ] }

        ] with-tiff-endianness
    ] with-file-reader ;

: process-chunky-ifd ( ifd -- )
    read-strips
    uncompress-strips
    strips>bitmap
    fix-bitmap-endianness
    strips-predictor
    dup extra-samples tag? [ handle-alpha-data ] when
    drop ;

: process-planar-ifd ( ifd -- )
    "planar ifd not supported" throw ;

: dispatch-planar-configuration ( ifd planar-configuration -- )
    {
        { planar-configuration-chunky [ process-chunky-ifd ] }
        { planar-configuration-planar [ process-planar-ifd ] }
    } case ;

: process-ifd ( ifd -- )
    dup planar-configuration find-tag* [
        dispatch-planar-configuration
    ] [
        drop "no planar configuration" throw
    ] if ;

: process-tif-ifds ( parsed-tiff -- )
    ifds>> [ process-ifd ] each ;

: load-tiff ( path -- parsed-tiff )
    [ load-tiff-ifds dup ] keep
    binary [
        [ process-tif-ifds ] with-tiff-endianness
    ] with-file-reader ;

! tiff files can store several images -- we just take the first for now
M: tiff-image load-image* ( path tiff-image -- image )
