Update core-graphics, core-text, opengl.textures for Doug's images API change; core-graphics:with-bitmap-context is now core-graphics:make-bitmap-image

db4
Slava Pestov 2009-02-13 19:11:07 -06:00
parent 056e7aa442
commit f0bc2e1176
4 changed files with 25 additions and 33 deletions

View File

@ -1,6 +1,6 @@
! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: tools.test core-graphics kernel byte-arrays ;
USING: tools.test core-graphics kernel images ;
IN: core-graphics.tests
[ t ] [ { 100 200 } [ drop ] with-bitmap-context byte-array? ] unit-test
[ t ] [ { 100 200 } [ drop ] make-bitmap-image image? ] unit-test

View File

@ -1,8 +1,8 @@
! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: alien.c-types alien.destructors alien.syntax
USING: alien.c-types alien.destructors alien.syntax accessors
destructors fry kernel math math.bitwise sequences libc colors
core-graphics.types core-foundation.utilities ;
images core-graphics.types core-foundation.utilities ;
IN: core-graphics
! CGImageAlphaInfo
@ -126,10 +126,16 @@ FUNCTION: void* CGBitmapContextGetData ( CGContextRef c ) ;
[ CGBitmapContextGetData ] [ bitmap-size ] bi*
memory>byte-array ;
: <bitmap-image> ( bitmap dim -- image )
<image>
swap >>dim
swap >>bitmap
little-endian? ARGB BGRA ? >>component-order ;
PRIVATE>
: with-bitmap-context ( dim quot -- data )
: make-bitmap-image ( dim quot -- image )
[
[ [ <CGBitmapContext> &CGContextRelease ] keep ] dip
[ nip call ] [ drop bitmap-data ] 3bi
[ nip call ] [ drop [ bitmap-data ] keep <bitmap-image> ] 3bi
] with-destructors ; inline

View File

@ -3,9 +3,9 @@
USING: arrays alien alien.c-types alien.syntax kernel destructors
accessors fry words hashtables strings sequences memoize assocs math
math.functions locals init namespaces combinators fonts colors cache
images endian core-foundation core-foundation.strings
core-foundation.attributed-strings core-foundation.utilities
core-graphics core-graphics.types core-text.fonts core-text.utilities ;
core-foundation core-foundation.strings core-foundation.attributed-strings
core-foundation.utilities core-graphics core-graphics.types
core-text.fonts core-text.utilities ;
IN: core-text
TYPEDEF: void* CTLineRef
@ -77,19 +77,13 @@ TUPLE: line font line metrics image disposed ;
: set-text-position ( context metrics -- )
[ 0 ] dip descent>> ceiling CGContextSetTextPosition ;
: <line-image> ( dim bitmap -- image )
<image>
swap >>bitmap
swap >>dim
BGRA >>component-order
native-endianness >>byte-order ;
:: <line> ( font string -- line )
[
[let* | open-font [ font cache-font CFRetain |CFRelease ]
line [ string open-font font foreground>> <CTLine> |CFRelease ]
metrics [ line compute-line-metrics ]
dim [ metrics bounds>dim ] |
open-font line metrics
dim [
{
[ font dim fill-background ]
@ -97,8 +91,7 @@ TUPLE: line font line metrics image disposed ;
[ metrics set-text-position ]
[ [ line ] dip CTLineDraw ]
} cleave
] with-bitmap-context
[ open-font line metrics dim ] dip <line-image>
] make-bitmap-image
]
f line boa
] with-destructors ;

View File

@ -54,25 +54,18 @@ TUPLE: texture texture display-list disposed ;
: make-texture-display-list ( dim texture -- dlist )
GL_COMPILE [ draw-textured-rect ] make-dlist ;
GENERIC: component-order>format ( component-order -- format )
GENERIC: component-order>format ( component-order -- format type )
M: RGBA component-order>format drop GL_RGBA ;
M: BGRA component-order>format drop GL_BGRA_EXT ;
: byte-order>type ( byte-order -- format )
native-endianness eq?
GL_UNSIGNED_INT_8_8_8_8_REV
GL_UNSIGNED_BYTE
? ;
M: RGBA component-order>format drop GL_RGBA GL_UNSIGNED_BYTE ;
M: ARGB component-order>format drop GL_BGRA_EXT GL_UNSIGNED_INT_8_8_8_8_REV ;
M: BGRA component-order>format drop GL_BGRA_EXT GL_UNSIGNED_INT_8_8_8_8 ;
: <texture> ( image -- texture )
[
{
[ dim>> ]
[ bitmap>> ]
[ component-order>> component-order>format ]
[ byte-order>> byte-order>type ]
} cleave make-texture
tri make-texture
] [ dim>> ] bi
over make-texture-display-list f texture boa ;