factor/basis/images/backend/backend.factor

52 lines
1.4 KiB
Factor
Raw Normal View History

! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
2009-02-10 19:48:10 -05:00
USING: accessors kernel grouping fry sequences combinators
2009-02-10 21:49:10 -05:00
math ;
IN: images.backend
2009-02-10 18:17:36 -05:00
SINGLETONS: BGR RGB BGRA RGBA ABGR ARGB RGBX XRGB BGRX XBGR ;
2009-02-10 19:42:21 -05:00
TUPLE: image dim component-order bitmap ;
TUPLE: normalized-image < image ;
GENERIC: load-image* ( path tuple -- image )
2009-02-10 19:42:21 -05:00
GENERIC: >image ( object -- image )
: no-op ( -- ) ;
: normalize-component-order ( image -- image )
dup component-order>>
{
{ RGBA [ no-op ] }
{ BGRA [
[
[ 4 <sliced-groups> [ [ 0 3 ] dip <slice> reverse-here ] each ]
[ RGBA >>component-order ] bi
] change-bitmap
] }
{ RGB [
[ 3 <sliced-groups> [ 255 suffix ] map concat ] change-bitmap
] }
{ BGR [
[
3 <sliced-groups> dup [ [ 0 3 ] dip <slice> reverse-here ] each
[ 255 suffix ] map concat
] change-bitmap
] }
} case RGBA >>component-order ;
2009-02-10 19:48:10 -05:00
GENERIC: normalize-scan-line-order ( image -- image )
M: image normalize-scan-line-order ;
2009-02-10 19:42:21 -05:00
: normalize-image ( image -- image )
2009-02-10 19:48:10 -05:00
normalize-component-order
normalize-scan-line-order ;
2009-02-10 19:42:21 -05:00
: new-image ( dim component-order bitmap class -- image )
new
2009-02-10 19:42:21 -05:00
swap >>bitmap
2009-02-10 18:17:36 -05:00
swap >>component-order
2009-02-10 19:42:21 -05:00
swap >>dim ; inline