+++ /dev/null
-! Copyright (C) 2010, 2011 Joe Groff, Slava Pestov.
-! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.data cocoa cocoa.classes cocoa.messages
-combinators core-foundation.data core-graphics
-core-graphics.types fry locals images images.loader io kernel
-math sequences ;
-FROM: system => os macosx? ;
-IN: images.cocoa
-
-SINGLETON: ns-image
-
-os macosx? [
- "png" ns-image register-image-class
- "tif" ns-image register-image-class
- "tiff" ns-image register-image-class
- "gif" ns-image register-image-class
- "jpg" ns-image register-image-class
- "jpeg" ns-image register-image-class
- "bmp" ns-image register-image-class
- "ico" ns-image register-image-class
-] when
-
-: <CGImage> ( byte-array -- image-rep )
- [ NSBitmapImageRep ] dip
- <CFData> -> autorelease
- -> imageRepWithData:
- -> CGImage ;
-
-:: CGImage>image ( image -- image )
- image CGImageGetWidth :> w
- image CGImageGetHeight :> h
- { w h } [
- 0 0 w h <CGRect> image CGContextDrawImage
- ] make-bitmap-image ;
-
-M: ns-image stream>image
- drop stream-contents <CGImage> CGImage>image ;
+++ /dev/null
-Image loading using MacOS X's native Cocoa APIs
+++ /dev/null
-! (c)2010 Joe Groff bsd license\r
-USING: accessors alien.c-types alien.data alien.enums\r
-classes.struct destructors images images.loader kernel locals\r
-math windows.com windows.gdiplus windows.streams windows.types\r
-typed byte-arrays grouping sequences ;\r
-FROM: system => os windows? ;\r
-IN: images.gdiplus\r
-\r
-SINGLETON: gdi+-image\r
-\r
-os windows? [\r
- "png" gdi+-image register-image-class\r
- "tif" gdi+-image register-image-class\r
- "tiff" gdi+-image register-image-class\r
- "gif" gdi+-image register-image-class\r
- "jpg" gdi+-image register-image-class\r
- "jpeg" gdi+-image register-image-class\r
- "bmp" gdi+-image register-image-class\r
- "ico" gdi+-image register-image-class\r
-] when\r
-\r
-<PRIVATE\r
-: <GpRect> ( x y w h -- rect )\r
- GpRect <struct-boa> ; inline\r
-\r
-: stream>gdi+-bitmap ( stream -- bitmap )\r
- stream>IStream &com-release\r
- { void* } [ GdipCreateBitmapFromStream check-gdi+-status ]\r
- with-out-parameters &GdipFree ;\r
-\r
-: gdi+-bitmap-width ( bitmap -- w )\r
- { UINT } [ GdipGetImageWidth check-gdi+-status ]\r
- with-out-parameters ;\r
-: gdi+-bitmap-height ( bitmap -- w )\r
- { UINT } [ GdipGetImageHeight check-gdi+-status ]\r
- with-out-parameters ;\r
-: gdi+-lock-bitmap ( bitmap rect mode format -- data )\r
- { BitmapData } [ GdipBitmapLockBits check-gdi+-status ]\r
- with-out-parameters ;\r
-\r
-:: gdi+-bitmap>data ( bitmap -- w h pixels )\r
- bitmap [ gdi+-bitmap-width ] [ gdi+-bitmap-height ] bi :> ( w h )\r
- bitmap 0 0 w h <GpRect> ImageLockModeRead enum>number\r
- PixelFormat32bppARGB gdi+-lock-bitmap :> bitmap-data\r
- bitmap-data [ Scan0>> ] [ Stride>> ] [ Height>> * ] tri\r
- memory>byte-array :> pixels\r
- bitmap bitmap-data GdipBitmapUnlockBits check-gdi+-status\r
- w h pixels ;\r
- \r
-:: data>image ( w h pixels -- image )\r
- image new\r
- { w h } >>dim\r
- pixels >>bitmap\r
- BGRA >>component-order\r
- ubyte-components >>component-type\r
- f >>upside-down? ;\r
-\r
-PRIVATE>\r
-\r
-M: gdi+-image stream>image\r
- drop [\r
- start-gdi+ &stop-gdi+ drop\r
- stream>gdi+-bitmap\r
- gdi+-bitmap>data\r
- data>image\r
- ] with-destructors ;\r
+++ /dev/null
-Philipp Brüschweiler
+++ /dev/null
-! Copyright (C) 2010 Philipp Brüschweiler.
-! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types alien.data arrays combinators
-destructors gdk.pixbuf.ffi gobject.ffi grouping images
-images.loader io kernel locals math sequences
-specialized-arrays ;
-FROM: system => os linux freebsd netbsd openbsd ;
-IN: images.gtk
-SPECIALIZED-ARRAY: uchar
-
-SINGLETON: gtk-image
-
-os { linux freebsd netbsd openbsd } member? [
- "png" gtk-image register-image-class
- "tif" gtk-image register-image-class
- "tiff" gtk-image register-image-class
- "gif" gtk-image register-image-class
- "jpg" gtk-image register-image-class
- "jpeg" gtk-image register-image-class
- "bmp" gtk-image register-image-class
- "ico" gtk-image register-image-class
-] when
-
-<PRIVATE
-
-: image-data ( GdkPixbuf -- data )
- {
- [ gdk_pixbuf_get_pixels ]
- [ gdk_pixbuf_get_width ]
- [ gdk_pixbuf_get_height ]
- [ gdk_pixbuf_get_rowstride ]
- [ gdk_pixbuf_get_n_channels ]
- [ gdk_pixbuf_get_bits_per_sample ]
- } cleave
- [let :> ( pixels w h rowstride channels bps )
- bps channels * 7 + 8 /i w * :> bytes-per-row
-
- bytes-per-row rowstride =
- [ pixels h rowstride * memory>byte-array ]
- [
- pixels rowstride h * uchar <c-direct-array>
- rowstride <sliced-groups>
- [ bytes-per-row head-slice ] map concat
- ] if
- ] ;
-
-: component-type ( GdkPixbuf -- component-type )
- gdk_pixbuf_get_bits_per_sample {
- { 8 [ ubyte-components ] }
- { 16 [ ushort-components ] }
- { 32 [ uint-components ] }
- } case ;
-
-: GdkPixbuf>image ( GdkPixbuf -- image )
- [ image new ] dip
- {
- [ [ gdk_pixbuf_get_width ] [ gdk_pixbuf_get_height ] bi 2array >>dim ]
- [ image-data >>bitmap ]
- [ gdk_pixbuf_get_has_alpha RGBA RGB ? >>component-order ]
- [ component-type >>component-type ]
- } cleave
- f >>premultiplied-alpha?
- f >>upside-down? ;
-
-PRIVATE>
-
-M: gtk-image stream>image
- drop [
- stream-contents data>GInputStream &g_object_unref
- GInputStream>GdkPixbuf &g_object_unref
- GdkPixbuf>image
- ] with-destructors ;
+++ /dev/null
-linux
-bsd
+++ /dev/null
-Image loading using GTK's GdkPixbuf API
--- /dev/null
+! Copyright (C) 2010, 2011 Joe Groff, Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors alien.data cocoa cocoa.classes cocoa.messages
+combinators core-foundation.data core-graphics
+core-graphics.types fry locals images images.loader io kernel
+math sequences ;
+FROM: system => os macosx? ;
+IN: images.loader.cocoa
+
+SINGLETON: ns-image
+
+os macosx? [
+ "png" ns-image register-image-class
+ "tif" ns-image register-image-class
+ "tiff" ns-image register-image-class
+ "gif" ns-image register-image-class
+ "jpg" ns-image register-image-class
+ "jpeg" ns-image register-image-class
+ "bmp" ns-image register-image-class
+ "ico" ns-image register-image-class
+] when
+
+: <CGImage> ( byte-array -- image-rep )
+ [ NSBitmapImageRep ] dip
+ <CFData> -> autorelease
+ -> imageRepWithData:
+ -> CGImage ;
+
+:: CGImage>image ( image -- image )
+ image CGImageGetWidth :> w
+ image CGImageGetHeight :> h
+ { w h } [
+ 0 0 w h <CGRect> image CGContextDrawImage
+ ] make-bitmap-image ;
+
+M: ns-image stream>image
+ drop stream-contents <CGImage> CGImage>image ;
--- /dev/null
+Image loading using MacOS X's native Cocoa APIs
--- /dev/null
+! (c)2010 Joe Groff bsd license\r
+USING: accessors alien.c-types alien.data alien.enums\r
+classes.struct destructors images images.loader kernel locals\r
+math windows.com windows.gdiplus windows.streams windows.types\r
+typed byte-arrays grouping sequences ;\r
+FROM: system => os windows? ;\r
+IN: images.loader.gdiplus\r
+\r
+SINGLETON: gdi+-image\r
+\r
+os windows? [\r
+ "png" gdi+-image register-image-class\r
+ "tif" gdi+-image register-image-class\r
+ "tiff" gdi+-image register-image-class\r
+ "gif" gdi+-image register-image-class\r
+ "jpg" gdi+-image register-image-class\r
+ "jpeg" gdi+-image register-image-class\r
+ "bmp" gdi+-image register-image-class\r
+ "ico" gdi+-image register-image-class\r
+] when\r
+\r
+<PRIVATE\r
+: <GpRect> ( x y w h -- rect )\r
+ GpRect <struct-boa> ; inline\r
+\r
+: stream>gdi+-bitmap ( stream -- bitmap )\r
+ stream>IStream &com-release\r
+ { void* } [ GdipCreateBitmapFromStream check-gdi+-status ]\r
+ with-out-parameters &GdipFree ;\r
+\r
+: gdi+-bitmap-width ( bitmap -- w )\r
+ { UINT } [ GdipGetImageWidth check-gdi+-status ]\r
+ with-out-parameters ;\r
+: gdi+-bitmap-height ( bitmap -- w )\r
+ { UINT } [ GdipGetImageHeight check-gdi+-status ]\r
+ with-out-parameters ;\r
+: gdi+-lock-bitmap ( bitmap rect mode format -- data )\r
+ { BitmapData } [ GdipBitmapLockBits check-gdi+-status ]\r
+ with-out-parameters ;\r
+\r
+:: gdi+-bitmap>data ( bitmap -- w h pixels )\r
+ bitmap [ gdi+-bitmap-width ] [ gdi+-bitmap-height ] bi :> ( w h )\r
+ bitmap 0 0 w h <GpRect> ImageLockModeRead enum>number\r
+ PixelFormat32bppARGB gdi+-lock-bitmap :> bitmap-data\r
+ bitmap-data [ Scan0>> ] [ Stride>> ] [ Height>> * ] tri\r
+ memory>byte-array :> pixels\r
+ bitmap bitmap-data GdipBitmapUnlockBits check-gdi+-status\r
+ w h pixels ;\r
+ \r
+:: data>image ( w h pixels -- image )\r
+ image new\r
+ { w h } >>dim\r
+ pixels >>bitmap\r
+ BGRA >>component-order\r
+ ubyte-components >>component-type\r
+ f >>upside-down? ;\r
+\r
+PRIVATE>\r
+\r
+M: gdi+-image stream>image\r
+ drop [\r
+ start-gdi+ &stop-gdi+ drop\r
+ stream>gdi+-bitmap\r
+ gdi+-bitmap>data\r
+ data>image\r
+ ] with-destructors ;\r
--- /dev/null
+Philipp Brüschweiler
--- /dev/null
+! Copyright (C) 2010 Philipp Brüschweiler.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors alien.c-types alien.data arrays combinators
+destructors gdk.pixbuf.ffi gobject.ffi grouping images
+images.loader io kernel locals math sequences
+specialized-arrays ;
+FROM: system => os linux freebsd netbsd openbsd ;
+IN: images.loader.gtk
+SPECIALIZED-ARRAY: uchar
+
+SINGLETON: gtk-image
+
+os { linux freebsd netbsd openbsd } member? [
+ "png" gtk-image register-image-class
+ "tif" gtk-image register-image-class
+ "tiff" gtk-image register-image-class
+ "gif" gtk-image register-image-class
+ "jpg" gtk-image register-image-class
+ "jpeg" gtk-image register-image-class
+ "bmp" gtk-image register-image-class
+ "ico" gtk-image register-image-class
+] when
+
+<PRIVATE
+
+: image-data ( GdkPixbuf -- data )
+ {
+ [ gdk_pixbuf_get_pixels ]
+ [ gdk_pixbuf_get_width ]
+ [ gdk_pixbuf_get_height ]
+ [ gdk_pixbuf_get_rowstride ]
+ [ gdk_pixbuf_get_n_channels ]
+ [ gdk_pixbuf_get_bits_per_sample ]
+ } cleave
+ [let :> ( pixels w h rowstride channels bps )
+ bps channels * 7 + 8 /i w * :> bytes-per-row
+
+ bytes-per-row rowstride =
+ [ pixels h rowstride * memory>byte-array ]
+ [
+ pixels rowstride h * uchar <c-direct-array>
+ rowstride <sliced-groups>
+ [ bytes-per-row head-slice ] map concat
+ ] if
+ ] ;
+
+: component-type ( GdkPixbuf -- component-type )
+ gdk_pixbuf_get_bits_per_sample {
+ { 8 [ ubyte-components ] }
+ { 16 [ ushort-components ] }
+ { 32 [ uint-components ] }
+ } case ;
+
+: GdkPixbuf>image ( GdkPixbuf -- image )
+ [ image new ] dip
+ {
+ [ [ gdk_pixbuf_get_width ] [ gdk_pixbuf_get_height ] bi 2array >>dim ]
+ [ image-data >>bitmap ]
+ [ gdk_pixbuf_get_has_alpha RGBA RGB ? >>component-order ]
+ [ component-type >>component-type ]
+ } cleave
+ f >>premultiplied-alpha?
+ f >>upside-down? ;
+
+PRIVATE>
+
+M: gtk-image stream>image
+ drop [
+ stream-contents data>GInputStream &g_object_unref
+ GInputStream>GdkPixbuf &g_object_unref
+ GdkPixbuf>image
+ ] with-destructors ;
--- /dev/null
+linux
+bsd
--- /dev/null
+Image loading using GTK's GdkPixbuf API
<<
{
- { [ os macosx? ] [ "images.cocoa" require ] }
- { [ os windows? ] [ "images.gdiplus" require ] }
- [ "images.gtk" require ]
+ { [ os macosx? ] [ "images.loader.cocoa" require ] }
+ { [ os windows? ] [ "images.loader.gdiplus" require ] }
+ [ "images.loader.gtk" require ]
} cond
>>