2010-07-07 01:37:14 -04:00
|
|
|
! (c)2010 Joe Groff bsd license
|
|
|
|
USING: accessors alien.c-types alien.data alien.enums
|
2011-09-02 01:29:14 -04:00
|
|
|
classes.struct destructors images images.loader kernel locals
|
|
|
|
math windows.com windows.gdiplus windows.streams windows.types
|
|
|
|
typed byte-arrays grouping sequences ;
|
2011-09-24 22:19:34 -04:00
|
|
|
FROM: system => os windows? ;
|
2011-11-02 12:38:03 -04:00
|
|
|
IN: images.loader.gdiplus
|
2010-07-07 01:37:14 -04:00
|
|
|
|
|
|
|
SINGLETON: gdi+-image
|
2011-09-24 22:19:34 -04:00
|
|
|
|
|
|
|
os windows? [
|
2014-03-14 12:17:13 -04:00
|
|
|
{ "png" "tif" "tiff" "gif" "jpg" "jpeg" "bmp" "ico" }
|
|
|
|
[ gdi+-image register-image-class ] each
|
2011-09-24 22:19:34 -04:00
|
|
|
] when
|
2010-07-07 01:37:14 -04:00
|
|
|
|
|
|
|
<PRIVATE
|
|
|
|
: <GpRect> ( x y w h -- rect )
|
|
|
|
GpRect <struct-boa> ; inline
|
|
|
|
|
|
|
|
: stream>gdi+-bitmap ( stream -- bitmap )
|
|
|
|
stream>IStream &com-release
|
|
|
|
{ void* } [ GdipCreateBitmapFromStream check-gdi+-status ]
|
2011-08-27 18:53:07 -04:00
|
|
|
with-out-parameters &GdipFree ;
|
2010-07-07 01:37:14 -04:00
|
|
|
|
|
|
|
: gdi+-bitmap-width ( bitmap -- w )
|
|
|
|
{ UINT } [ GdipGetImageWidth check-gdi+-status ]
|
2011-08-27 18:53:07 -04:00
|
|
|
with-out-parameters ;
|
2010-07-07 01:37:14 -04:00
|
|
|
: gdi+-bitmap-height ( bitmap -- w )
|
|
|
|
{ UINT } [ GdipGetImageHeight check-gdi+-status ]
|
2011-08-27 18:53:07 -04:00
|
|
|
with-out-parameters ;
|
2010-07-07 01:37:14 -04:00
|
|
|
: gdi+-lock-bitmap ( bitmap rect mode format -- data )
|
|
|
|
{ BitmapData } [ GdipBitmapLockBits check-gdi+-status ]
|
2011-08-27 18:53:07 -04:00
|
|
|
with-out-parameters ;
|
2010-07-07 01:37:14 -04:00
|
|
|
|
|
|
|
:: gdi+-bitmap>data ( bitmap -- w h pixels )
|
|
|
|
bitmap [ gdi+-bitmap-width ] [ gdi+-bitmap-height ] bi :> ( w h )
|
|
|
|
bitmap 0 0 w h <GpRect> ImageLockModeRead enum>number
|
|
|
|
PixelFormat32bppARGB gdi+-lock-bitmap :> bitmap-data
|
2010-07-07 16:54:24 -04:00
|
|
|
bitmap-data [ Scan0>> ] [ Stride>> ] [ Height>> * ] tri
|
2010-07-07 01:37:14 -04:00
|
|
|
memory>byte-array :> pixels
|
|
|
|
bitmap bitmap-data GdipBitmapUnlockBits check-gdi+-status
|
|
|
|
w h pixels ;
|
|
|
|
|
|
|
|
:: data>image ( w h pixels -- image )
|
|
|
|
image new
|
|
|
|
{ w h } >>dim
|
|
|
|
pixels >>bitmap
|
2010-07-07 17:51:16 -04:00
|
|
|
BGRA >>component-order
|
2010-07-07 01:37:14 -04:00
|
|
|
ubyte-components >>component-type
|
|
|
|
f >>upside-down? ;
|
|
|
|
|
|
|
|
PRIVATE>
|
|
|
|
|
2012-08-25 14:44:40 -04:00
|
|
|
M: gdi+-image stream>image*
|
|
|
|
drop
|
|
|
|
start-gdi+ &stop-gdi+ drop
|
|
|
|
stream>gdi+-bitmap
|
|
|
|
gdi+-bitmap>data
|
|
|
|
data>image ;
|