fix tiff/bitmaps color order

db4
Doug Coleman 2009-02-10 17:17:36 -06:00
parent 8086a44bb0
commit 970953be1f
4 changed files with 40 additions and 11 deletions

View File

@ -3,16 +3,19 @@
USING: accessors kernel ; USING: accessors kernel ;
IN: images.backend IN: images.backend
TUPLE: image width height depth pitch buffer ; SINGLETONS: BGR RGB BGRA RGBA ABGR ARGB RGBX XRGB BGRX XBGR ;
TUPLE: image width height depth pitch component-order buffer ;
GENERIC: load-image* ( path tuple -- image ) GENERIC: load-image* ( path tuple -- image )
: load-image ( path class -- image ) : load-image ( path class -- image )
new load-image* ; new load-image* ;
: new-image ( width height depth buffer class -- image ) : new-image ( width height depth component-order buffer class -- image )
new new
swap >>buffer swap >>buffer
swap >>component-order
swap >>depth swap >>depth
swap >>height swap >>height
swap >>width ; inline swap >>width ; inline

View File

@ -97,8 +97,18 @@ M: bitmap-magic summary
: load-bitmap ( path -- bitmap ) : load-bitmap ( path -- bitmap )
load-bitmap-data process-bitmap-data ; load-bitmap-data process-bitmap-data ;
ERROR: unknown-component-order bitmap ;
: bitmap>component-order ( bitmap -- object )
bit-count>> {
{ 32 [ BGRA ] }
{ 24 [ BGR ] }
{ 8 [ BGR ] }
[ unknown-component-order ]
} case ;
: bitmap>image ( bitmap -- bitmap-image ) : bitmap>image ( bitmap -- bitmap-image )
{ [ width>> ] [ height>> ] [ bit-count>> ] [ buffer>> ] } cleave { [ width>> ] [ height>> ] [ bit-count>> ] [ bitmap>component-order ] [ buffer>> ] } cleave
bitmap-image new-image ; bitmap-image new-image ;
M: bitmap-image load-image* ( path bitmap -- bitmap-image ) M: bitmap-image load-image* ( path bitmap -- bitmap-image )

View File

@ -1,7 +1,7 @@
! 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 combinators io io.encodings.binary io.files USING: accessors combinators io io.encodings.binary io.files
kernel pack endian tools.hexdump constructors sequences arrays kernel pack endian constructors sequences arrays
sorting.slots math.order math.parser prettyprint classes sorting.slots math.order math.parser prettyprint classes
io.binary assocs math math.bitwise byte-arrays grouping io.binary assocs math math.bitwise byte-arrays grouping
images.backend ; images.backend ;
@ -260,17 +260,27 @@ ERROR: bad-small-ifd-type n ;
: strips>buffer ( ifd -- ifd ) : strips>buffer ( ifd -- ifd )
dup strips>> concat >>buffer ; dup strips>> concat >>buffer ;
ERROR: unknown-component-order ifd ;
: ifd-component-order ( ifd -- byte-order )
bits-per-sample find-tag sum {
{ 32 [ RGBA ] }
[ unknown-component-order ]
} case ;
: ifd>image ( ifd -- image ) : ifd>image ( ifd -- image )
{ {
[ image-width find-tag ] [ image-width find-tag ]
[ image-length find-tag ] [ image-length find-tag ]
[ bits-per-sample find-tag sum ] [ bits-per-sample find-tag sum ]
[ ifd-component-order ]
[ buffer>> ] [ buffer>> ]
} cleave tiff-image new-image ; } cleave tiff-image new-image ;
: parsed-tiff>images ( tiff -- sequence ) : parsed-tiff>images ( tiff -- sequence )
ifds>> [ ifd>image ] map ; ifds>> [ ifd>image ] map ;
: load-tiff ( path -- parsed-tiff ) : load-tiff ( path -- parsed-tiff )
binary [ binary [
<parsed-tiff> <parsed-tiff>

View File

@ -22,12 +22,18 @@ M: image-gadget draw-gadget* ( gadget -- )
\ image-gadget new-gadget \ image-gadget new-gadget
swap >>image ; swap >>image ;
: bits>gl-params ( n -- gl-bgr gl-format ) : gl-component-order ( singletons -- n )
{ {
{ 32 [ GL_BGRA GL_UNSIGNED_BYTE ] } { BGR [ GL_BGR ] }
{ 24 [ GL_BGR GL_UNSIGNED_BYTE ] } { RGB [ GL_BGR ] }
{ 8 [ GL_BGR GL_UNSIGNED_BYTE ] } { BGRA [ GL_BGRA ] }
{ 4 [ GL_BGR GL_UNSIGNED_BYTE ] } { RGBA [ GL_RGBA ] }
! { RGBX [ GL_RGBX ] }
! { BGRX [ GL_BGRX ] }
! { ARGB [ GL_ARGB ] }
! { ABGR [ GL_ABGR ] }
! { XRGB [ GL_XRGB ] }
! { XBGR [ GL_XBGR ] }
} case ; } case ;
M: bitmap-image draw-image ( bitmap -- ) M: bitmap-image draw-image ( bitmap -- )
@ -44,7 +50,7 @@ M: bitmap-image draw-image ( bitmap -- )
] ]
[ width>> abs ] [ width>> abs ]
[ height>> abs ] [ height>> abs ]
[ depth>> bits>gl-params ] [ component-order>> gl-component-order GL_UNSIGNED_BYTE ]
[ buffer>> ] [ buffer>> ]
} cleave glDrawPixels ; } cleave glDrawPixels ;
@ -56,7 +62,7 @@ M: tiff-image draw-image ( tiff -- )
{ {
[ height>> ] [ height>> ]
[ width>> ] [ width>> ]
[ depth>> bits>gl-params ] [ component-order>> gl-component-order GL_UNSIGNED_BYTE ]
[ buffer>> ] [ buffer>> ]
} cleave glDrawPixels ; } cleave glDrawPixels ;