Redoing images.loader to work with jpeg

db4
Daniel Ehrenberg 2009-06-02 20:39:51 -05:00
parent 1162e337d9
commit ba5b582e01
7 changed files with 37 additions and 20 deletions

View File

@ -3,7 +3,7 @@
USING: accessors alien alien.c-types arrays byte-arrays columns USING: accessors alien alien.c-types arrays byte-arrays columns
combinators fry grouping io io.binary io.encodings.binary io.files combinators fry grouping io io.binary io.encodings.binary io.files
kernel macros math math.bitwise math.functions namespaces sequences kernel macros math math.bitwise math.functions namespaces sequences
strings images endian summary locals ; strings images endian summary locals images.loader ;
IN: images.bitmap IN: images.bitmap
: assert-sequence= ( a b -- ) : assert-sequence= ( a b -- )
@ -129,6 +129,8 @@ ERROR: unknown-component-order bitmap ;
M: bitmap-image load-image* ( path loading-bitmap -- bitmap ) M: bitmap-image load-image* ( path loading-bitmap -- bitmap )
swap load-bitmap-data loading-bitmap>bitmap-image ; swap load-bitmap-data loading-bitmap>bitmap-image ;
"bmp" bitmap-image register-image-class
PRIVATE> PRIVATE>
: bitmap>color-index ( bitmap -- byte-array ) : bitmap>color-index ( bitmap -- byte-array )

View File

@ -1,6 +1,6 @@
! Copyright (C) 2009 Doug Coleman, Daniel Ehrenberg. ! Copyright (C) 2009 Doug Coleman, Daniel Ehrenberg.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: combinators kernel accessors sequences math ; USING: combinators kernel accessors sequences math arrays ;
IN: images IN: images
SINGLETONS: L LA BGR RGB BGRA RGBA ABGR ARGB RGBX XRGB BGRX XBGR SINGLETONS: L LA BGR RGB BGRA RGBA ABGR ARGB RGBX XRGB BGRX XBGR
@ -36,10 +36,17 @@ TUPLE: image dim component-order upside-down? bitmap ;
GENERIC: load-image* ( path tuple -- image ) GENERIC: load-image* ( path tuple -- image )
: make-image ( bitmap -- image )
! bitmap is a sequence of sequences of pixels which are RGBA
<image>
over [ first length ] [ length ] bi 2array >>dim
RGBA >>component-order
swap concat concat B{ } like >>bitmap ;
<PRIVATE <PRIVATE
: pixel@ ( x y image -- start end bitmap ) : pixel@ ( x y image -- start end bitmap )
[ dim>> second * + ] [ dim>> first * + ]
[ component-order>> bytes-per-pixel [ * dup ] keep + ] [ component-order>> bytes-per-pixel [ * dup ] keep + ]
[ bitmap>> ] tri ; [ bitmap>> ] tri ;

View File

@ -6,7 +6,7 @@ images.processing io io.binary io.encodings.binary io.files
io.streams.byte-array kernel locals math math.bitwise io.streams.byte-array kernel locals math math.bitwise
math.constants math.functions math.matrices math.order math.constants math.functions math.matrices math.order
math.ranges math.vectors memoize multiline namespaces math.ranges math.vectors memoize multiline namespaces
sequences sequences.deep ; sequences sequences.deep images.loader ;
IN: images.jpeg IN: images.jpeg
QUALIFIED-WITH: bitstreams bs QUALIFIED-WITH: bitstreams bs
@ -302,3 +302,5 @@ PRIVATE>
M: jpeg-image load-image* ( path jpeg-image -- bitmap ) M: jpeg-image load-image* ( path jpeg-image -- bitmap )
drop load-jpeg ; drop load-jpeg ;
{ "jpg" "jpeg" } [ jpeg-image register-image-class ] each

View File

@ -1,22 +1,22 @@
! Copyright (C) 2009 Doug Coleman. ! Copyright (C) 2009 Doug Coleman, Daniel Ehrenberg.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: constructors kernel splitting unicode.case combinators USING: constructors kernel splitting unicode.case combinators
accessors images.bitmap images.tiff images io.pathnames accessors images io.pathnames namespaces assocs ;
images.png ;
IN: images.loader IN: images.loader
ERROR: unknown-image-extension extension ; ERROR: unknown-image-extension extension ;
<PRIVATE
SYMBOL: types
types [ H{ } clone ] initialize
: image-class ( path -- class ) : image-class ( path -- class )
file-extension >lower { file-extension >lower types get ?at
{ "bmp" [ bitmap-image ] } [ unknown-image-extension ] unless ;
{ "tif" [ tiff-image ] } PRIVATE>
{ "tiff" [ tiff-image ] }
! { "jpg" [ jpeg-image ] } : register-image-class ( extension class -- )
! { "jpeg" [ jpeg-image ] } swap types get set-at ;
{ "png" [ png-image ] }
[ unknown-image-extension ]
} case ;
: load-image ( path -- image ) : load-image ( path -- image )
dup image-class new load-image* ; dup image-class new load-image* ;

View File

@ -3,7 +3,8 @@
USING: accessors constructors images io io.binary io.encodings.ascii USING: accessors constructors images io io.binary io.encodings.ascii
io.encodings.binary io.encodings.string io.files io.files.info kernel io.encodings.binary io.encodings.string io.files io.files.info kernel
sequences io.streams.limited fry combinators arrays math sequences io.streams.limited fry combinators arrays math
checksums checksums.crc32 compression.inflate grouping byte-arrays ; checksums checksums.crc32 compression.inflate grouping byte-arrays
images.loader ;
IN: images.png IN: images.png
TUPLE: png-image < image chunks TUPLE: png-image < image chunks
@ -115,3 +116,5 @@ ERROR: unimplemented-color-type image ;
M: png-image load-image* M: png-image load-image*
drop load-png ; drop load-png ;
"png" png-image register-image-class

View File

@ -5,7 +5,8 @@ compression.lzw constructors endian fry grouping images io
io.binary io.encodings.ascii io.encodings.binary io.binary io.encodings.ascii io.encodings.binary
io.encodings.string io.encodings.utf8 io.files kernel math io.encodings.string io.encodings.utf8 io.files kernel math
math.bitwise math.order math.parser pack prettyprint sequences math.bitwise math.order math.parser pack prettyprint sequences
strings math.vectors specialized-arrays.float locals ; strings math.vectors specialized-arrays.float locals
images.loader ;
IN: images.tiff IN: images.tiff
TUPLE: tiff-image < image ; TUPLE: tiff-image < image ;
@ -561,3 +562,5 @@ ERROR: unknown-component-order ifd ;
! tiff files can store several images -- we just take the first for now ! tiff files can store several images -- we just take the first for now
M: tiff-image load-image* ( path tiff-image -- image ) M: tiff-image load-image* ( path tiff-image -- image )
drop load-tiff tiff>image ; drop load-tiff tiff>image ;
{ "tif" "tiff" } [ tiff-image register-image-class ] each

View File

@ -2,7 +2,7 @@
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: namespaces cache images images.loader accessors assocs USING: namespaces cache images images.loader accessors assocs
kernel opengl opengl.gl opengl.textures ui.gadgets.worlds kernel opengl opengl.gl opengl.textures ui.gadgets.worlds
memoize ; memoize images.tiff ;
IN: ui.images IN: ui.images
TUPLE: image-name path ; TUPLE: image-name path ;
@ -29,4 +29,4 @@ PRIVATE>
rendered-image draw-scaled-texture ; rendered-image draw-scaled-texture ;
: image-dim ( image-name -- dim ) : image-dim ( image-name -- dim )
cached-image dim>> ; cached-image dim>> ;