From f0bc2e117631345fa4d82203014ef8b902daf6e0 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 13 Feb 2009 19:11:07 -0600 Subject: [PATCH] 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 --- .../core-graphics/core-graphics-tests.factor | 4 ++-- basis/core-graphics/core-graphics.factor | 14 +++++++---- basis/core-text/core-text.factor | 17 ++++---------- basis/opengl/textures/textures.factor | 23 +++++++------------ 4 files changed, 25 insertions(+), 33 deletions(-) diff --git a/basis/core-graphics/core-graphics-tests.factor b/basis/core-graphics/core-graphics-tests.factor index a45e21163a..c54dc0a98b 100644 --- a/basis/core-graphics/core-graphics-tests.factor +++ b/basis/core-graphics/core-graphics-tests.factor @@ -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 \ No newline at end of file +[ t ] [ { 100 200 } [ drop ] make-bitmap-image image? ] unit-test \ No newline at end of file diff --git a/basis/core-graphics/core-graphics.factor b/basis/core-graphics/core-graphics.factor index 23d4126d66..19d8b8116a 100644 --- a/basis/core-graphics/core-graphics.factor +++ b/basis/core-graphics/core-graphics.factor @@ -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 dim -- image ) + + swap >>dim + swap >>bitmap + little-endian? ARGB BGRA ? >>component-order ; + PRIVATE> -: with-bitmap-context ( dim quot -- data ) +: make-bitmap-image ( dim quot -- image ) [ [ [ &CGContextRelease ] keep ] dip - [ nip call ] [ drop bitmap-data ] 3bi + [ nip call ] [ drop [ bitmap-data ] keep ] 3bi ] with-destructors ; inline diff --git a/basis/core-text/core-text.factor b/basis/core-text/core-text.factor index 57e1f375b8..227c6e97d5 100644 --- a/basis/core-text/core-text.factor +++ b/basis/core-text/core-text.factor @@ -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 ; -: ( dim bitmap -- image ) - - swap >>bitmap - swap >>dim - BGRA >>component-order - native-endianness >>byte-order ; - :: ( font string -- line ) [ [let* | open-font [ font cache-font CFRetain |CFRelease ] line [ string open-font font foreground>> |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 + ] make-bitmap-image ] f line boa ] with-destructors ; diff --git a/basis/opengl/textures/textures.factor b/basis/opengl/textures/textures.factor index 63a83ab8af..4b23167427 100644 --- a/basis/opengl/textures/textures.factor +++ b/basis/opengl/textures/textures.factor @@ -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 ; : ( image -- texture ) [ - { - [ dim>> ] - [ bitmap>> ] - [ component-order>> component-order>format ] - [ byte-order>> byte-order>type ] - } cleave make-texture + [ dim>> ] + [ bitmap>> ] + [ component-order>> component-order>format ] + tri make-texture ] [ dim>> ] bi over make-texture-display-list f texture boa ;