+++ /dev/null
-Doug Coleman
\ No newline at end of file
+++ /dev/null
-! Copyright (C) 2009 Doug Coleman.
-! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel grouping fry sequences combinators
-math ;
-IN: images.backend
-
-SINGLETONS: BGR RGB BGRA RGBA ABGR ARGB RGBX XRGB BGRX XBGR ;
-
-TUPLE: image dim component-order bitmap ;
-
-TUPLE: normalized-image < image ;
-
-GENERIC: load-image* ( path tuple -- image )
-
-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 ;
-
-GENERIC: normalize-scan-line-order ( image -- image )
-
-M: image normalize-scan-line-order ;
-: normalize-image ( image -- image )
- normalize-component-order
- normalize-scan-line-order ;
-
-: new-image ( dim component-order bitmap class -- image )
- new
- swap >>bitmap
- swap >>component-order
- swap >>dim ; inline
IN: images.bitmap.tests
: test-bitmap24 ( -- path )
- "resource:extra/images/test-images/thiswayup24.bmp" ;
+ "resource:basis/images/test-images/thiswayup24.bmp" ;
: test-bitmap8 ( -- path )
- "resource:extra/images/test-images/rgb8bit.bmp" ;
+ "resource:basis/images/test-images/rgb8bit.bmp" ;
: test-bitmap4 ( -- path )
- "resource:extra/images/test-images/rgb4bit.bmp" ;
+ "resource:basis/images/test-images/rgb4bit.bmp" ;
: test-bitmap1 ( -- path )
- "resource:extra/images/test-images/1bit.bmp" ;
+ "resource:basis/images/test-images/1bit.bmp" ;
[ t ]
[
combinators fry grouping io io.binary io.encodings.binary
io.files kernel libc macros math math.bitwise math.functions
namespaces opengl opengl.gl prettyprint sequences strings
-summary ui ui.gadgets.panes images.backend ;
+summary ui ui.gadgets.panes images ;
IN: images.bitmap
TUPLE: bitmap-image < image ;
[ unknown-component-order ]
} case ;
-M: bitmap >image ( bitmap -- bitmap-image )
+: >image ( bitmap -- bitmap-image )
{
[ [ width>> ] [ height>> ] bi 2array ]
[ bitmap>component-order ]
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: constructors kernel splitting unicode.case combinators
-accessors images.bitmap images.tiff images.backend io.backend
-io.pathnames ;
+USING: kernel accessors grouping sequences combinators ;
IN: images
-ERROR: unknown-image-extension extension ;
+SINGLETONS: BGR RGB BGRA RGBA ABGR ARGB RGBX XRGB BGRX XBGR ;
-: image-class ( path -- class )
- file-extension >lower {
- { "bmp" [ bitmap-image ] }
- { "tiff" [ tiff-image ] }
- [ unknown-image-extension ]
- } case ;
+TUPLE: image dim component-order bitmap ;
-: load-image ( path -- image )
- dup image-class new load-image* ;
+GENERIC: load-image* ( path tuple -- image )
-: <image> ( path -- image )
- load-image normalize-image ;
+: normalize-component-order ( image -- image )
+ dup component-order>>
+ {
+ { RGBA [ ] }
+ { 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 ;
+
+GENERIC: normalize-scan-line-order ( image -- image )
+
+M: image normalize-scan-line-order ;
+
+: normalize-image ( image -- image )
+ normalize-component-order
+ normalize-scan-line-order ;
+
+: new-image ( dim component-order bitmap class -- image )
+ new
+ swap >>bitmap
+ swap >>component-order
+ swap >>dim ; inline
--- /dev/null
+Doug Coleman
--- /dev/null
+! Copyright (C) 2009 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: constructors kernel splitting unicode.case combinators
+accessors images.bitmap images.tiff images io.backend
+io.pathnames ;
+IN: images.loader
+
+ERROR: unknown-image-extension extension ;
+
+: image-class ( path -- class )
+ file-extension >lower {
+ { "bmp" [ bitmap-image ] }
+ { "tiff" [ tiff-image ] }
+ [ unknown-image-extension ]
+ } case ;
+
+: load-image ( path -- image )
+ dup image-class new load-image* ;
+
+: <image> ( path -- image )
+ load-image normalize-image ;
USING: accessors combinators io io.encodings.binary io.files kernel
pack endian constructors sequences arrays math.order math.parser
prettyprint classes io.binary assocs math math.bitwise byte-arrays
-grouping images.backend ;
+grouping images ;
IN: images.tiff
TUPLE: tiff-image < image ;
[ unknown-component-order ]
} case ;
-M: ifd >image ( ifd -- image )
+: ifd>image ( ifd -- image )
{
[ [ image-width find-tag ] [ image-length find-tag ] bi 2array ]
[ ifd-component-order ]
[ bitmap>> ]
} cleave tiff-image new-image ;
-M: parsed-tiff >image ( image -- image )
- ifds>> [ >image ] map first ;
+: tiff>image ( image -- image )
+ ifds>> [ ifd>image ] map first ;
: load-tiff ( path -- parsed-tiff )
binary [
! tiff files can store several images -- we just take the first for now
M: tiff-image load-image* ( path tiff-image -- image )
- drop load-tiff >image ;
+ drop load-tiff tiff>image ;
! Copyright (C) 2007 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors images images.backend io.pathnames kernel
+USING: accessors images images.loader io.pathnames kernel
namespaces opengl opengl.gl sequences strings ui ui.gadgets
ui.gadgets.panes ui.render ;
IN: images.viewer