! Copyright (C) 2009 Doug Coleman, Daniel Ehrenberg. ! See http://factorcode.org/license.txt for BSD license. USING: combinators kernel accessors sequences math arrays ; IN: images SINGLETONS: A L LA BGR RGB BGRA RGBA ABGR ARGB RGBX XRGB BGRX XBGR INTENSITY DEPTH R RG ubyte-components ushort-components half-components float-components byte-integer-components ubyte-integer-components short-integer-components ushort-integer-components int-integer-components uint-integer-components ; UNION: component-order A L LA BGR RGB BGRA RGBA ABGR ARGB RGBX XRGB BGRX XBGR INTENSITY DEPTH R RG ; UNION: component-type ubyte-components ushort-components half-components float-components byte-integer-components ubyte-integer-components short-integer-components ushort-integer-components int-integer-components uint-integer-components ; UNION: unnormalized-integer-components byte-integer-components ubyte-integer-components short-integer-components ushort-integer-components int-integer-components uint-integer-components ; UNION: alpha-channel BGRA RGBA ABGR ARGB LA A INTENSITY ; TUPLE: image dim component-order component-type upside-down? bitmap ; : ( -- image ) image new ; inline : has-alpha? ( image -- ? ) component-order>> alpha-channel? ; GENERIC: load-image* ( path class -- image ) DEFER: bytes-per-pixel > first * + ] [ bytes-per-pixel [ * dup ] keep + ] [ bitmap>> ] tri ; : set-subseq ( new-value from to victim -- ) 0 swap copy ; inline PRIVATE> : bytes-per-pixel ( image -- n ) [ component-order>> component-count ] [ component-type>> bytes-per-component ] bi * ; : pixel-at ( x y image -- pixel ) pixel@ subseq ; : set-pixel-at ( pixel x y image -- ) pixel@ set-subseq ;