iOS: Converting UIImage to RGBA8 Bitmaps and Back

Edited 8/24/11: Fixed a bug with alpha transparency not being preserved. Thanks for the tip Scott! Updated the gist and github project to test transparent images.

Edited 12/13/10: Updated the code on github/gist to fix static analyzer warnings. Changed a function name to conform to the Apple standard.

When I started working with iPhone I was working with Objective-C and C++. I created a library in C++ and needed access to a bitmap array so that I could perform image processing. In order to do so I had to create some helper functions to convert between UIImage objects and the RGBA8 bitmap arrays.

Here are the updated routines that should work on iPhone 4.1 and iPad 3.2. The iPhone 4 has a high resolution screen requires setting a scaling factor for high resolution images. I've added support to set the scaling factor based on the devices mainScreen scaling factor

UPDATE: 9/23/10 My code to work with the Retina display was incorrect, it ran fine on iPad with 3.2, but it didn't do anything "high-res" on iPhone 4. I was using the following:

__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200

but it isn't safe, when I run it for a universal App 4.1/3.2 it will always return 40100, and the expression didn't make sense. (Side Note) I took this check from Apple's website when iPad 3.2 was actually ahead of iPhone 3.1.X, but that doesn't help with iPhone 4.1 being ahead of iPad 3.2.

The issue with iPad is that the imageWithCGImage:scale:orientation: selector doesn't exist on iOS 3.2, most likely it will on iOS 4.2, so the following code should be safe. Some methods in iOS 4.1 don't exist in iOS 3.2, so you need to check to see if a newer method exists before trying to execute it. There are two methods you can use depending on the class/instance (+/-) modifier on the function definition.

+ (BOOL)respondsToSelector:(SEL)aSelector   // (+) Class method check
+ (BOOL)instancesRespondToSelector:(SEL)aSelector   // (-) Instance method check

imageWithCGImage:scale:orientation is a class method, so we need to use respondsToSelector: The correct code to scale the CGImage is below:

if([UIImage respondsToSelector:@selector(imageWithCGImage:scale:orientation:)]) {
	float scale = [[UIScreen mainScreen] scale];
	image = [UIImage imageWithCGImage:imageRef scale:scale orientation:UIImageOrientationUp];
} else {
	image = [UIImage imageWithCGImage:imageRef];
}

[ad#Large Box]

It might help if there was some images to explain what's happening if you don't use this imageWithCGImage:scale:orientation: on the iPhone 4 with the correct scale factor. It should be 2.0 on Retina displays (iPhone 4 or the new iPod Touch) and 1.0 on the 3G, 3GS, and iPad. float scale = [[UIScreen mainScreen] scale]; will provide the correct scale factor for the device. The first image has jaggies in it, while the second does not. The third image, an iPhone 3G/3GS, also does not have jaggies.

[caption id="attachment_697" align="aligncenter" width="451" caption="iPhone 4 with default scale of 1.0 causes the image to be enlarged and with jaggies."][/caption]

[caption id="attachment_698" align="aligncenter" width="451" caption="iPhone 4 with scaling of 2.0 makes the image half the size and removes the jaggies"][/caption]

[caption id="attachment_692" align="aligncenter" width="414" caption="iPhone 3G/3GS with scaling set to 1.0"][/caption]

I hope it helps other people with image processing on the iPhone/iPad. It's based on some previous tutorials using OpenGL, which I fixed (memory leaks) and modified to work with unsigned char arrays (bitmap).

[ad#Link Banner]

Grab the two files here or the sample Universal iOS App project:

Example Usage:

NSString *path = (NSString*)[[NSBundle mainBundle] pathForResource:@"Icon4" ofType:@"png"];
UIImage *image = [UIImage imageWithContentsOfFile:path];
int width = image.size.width;
int height = image.size.height;

    // Create a bitmap
unsigned char *bitmap = [ImageHelper convertUIImageToBitmapRGBA8:image];

    // Create a UIImage using the bitmap
UIImage *imageCopy = [ImageHelper convertBitmapRGBA8ToUIImage:bitmap withWidth:width withHeight:height];

    // Display the image copy on the GUI
UIImageView *imageView = [[UIImageView alloc] initWithImage:imageCopy];

    // Cleanup
free(bitmap);

Below is the full source code for converting between bitmap and UIImage:

ImageHelper.h

ImageHelper.m

[ad#Large Box]

C++ Logging and building Boost for iPhone/iPad 3.2 and MacOSX

In my effort to write more robust and maintainable code I have been searching for a cross-platform C++ logging utility. I'm working on a C++ static library for iPhone/iPad 3.2/Mac/Windows and I needed a way to log what was happening in my library. Along the way I was forced to build Boost for iPhone, iPhone Simulator, and the Mac.

Why logging?

Mobile devices lack a console when detached from a development machine, so it's hard to track down issues. I needed a system that could log at multiple levels (Debug1, Debug2, Info, Error, Warning) and be thread safe. Multiple logger levels allow a developer to turn up/down the detail of information that is stored, which in turn affect performance with I/O writes. A developer with logging information can better track down crashes and other issues during an applications lifetime.

Why Boost Logger Library v2?

I struggled trying to get a logger working. After many failed attempts with Pantheios, log4cxx, log4cpp, and glog, I settled on the Boost Logger Library v2 because I was able to "compile" for iPhone/iPad 3.2 and Mac OSX. Most of the loggers required other dependencies that would need to be rebuilt for iPhone and didn't directly support iPhone.

The Boost Logger is all header files so it doesn't require "compiling," which made it much easier to get working. However, it does require a few Boost libraries that need to be compiled. The Boost Logging needs the following libraries: filesystem, system, and threading depending on what functionality is used.

Step 1: Building Boost for iPhone/iPad and iPhone Simulator 3.2

A few Boost libraries need compiling for the iPhone/iPad and the iPhone Simulator in order to link against the Boost Logger. Matt Galloway provided a demo on how to compile Boost 1.41/1.42 for iPhone/iPhone Simulator. Here are the steps I used for Boost 1.42 based on his tutorial.

[ad#Large Box]

  1. Get Boost 1.42
  2. Extract Boost:
  3. tar xzf boost_1_42_0.tar.gz
  4. Create a user-config.jam file in your user directory (~/user-config.jam) such as /Users/paulsolt/user-config.jam with the following. (Note:  this config file needs to be rename or moved during the MacOSX bjam build)
  5. ~/user-config.jam

    using darwin : 4.2.1~iphone
       : /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv7 -mthumb -fvisibility=hidden -fvisibility-inlines-hidden
       : 
       : arm iphone iphone-3.2
       ;
    
    using darwin : 4.2.1~iphonesim
       : /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386 -fvisibility=hidden -fvisibility-inlines-hidden
       : 
       : x86 iphone iphonesim-3.2
       ;
  6. Make sure the file boost_1_42_0/tools/build/v2/tools/darwin.jam has the following information:
  7. tools/build/v2/tools/darwin.jam
    ## The MacOSX versions we can target.
    .macosx-versions =
        10.6 10.5 10.4 10.3 10.2 10.1
        iphone-3.2 iphonesim-3.2
        iphone-3.1.3 iphonesim-3.1.3
        iphone-3.1.2 iphonesim-3.1.2
        iphone-3.1 iphonesim-3.1
        iphone-3.0 iphonesim-3.0
        iphone-2.2.1 iphonesim-2.2.1
        iphone-2.2 iphonesim-2.2
        iphone-2.1 iphonesim-2.1
        iphone-2.0 iphonesim-2.0
        iphone-1.x
        ;
  8. Change directories to the Boost directory that you downloaded:
  9. cd /path/to/boost_1_42_0
  10. Run the following commands to compile the iPhone and iPhone Simulator Boost libraries. I only need filesystem, system, and thread to be use Boost logging for the iPhone, so I don't build everything. Run ./bootstrap.sh --help or ./bjam --help for more options. I built the binaries to a location in my development folder to include in my project dependencies.
  11. ./bootstrap.sh --with-libraries=filesystem,system,thread

    ./bjam --prefix=${HOME}/dev/boost/iphone toolset=darwin architecture=arm target-os=iphone macosx-version=iphone-3.2 define=_LITTLE_ENDIAN link=static install
    ./bjam --prefix=${HOME}/dev/boost/iphoneSimulator toolset=darwin architecture=x86 target-os=iphone macosx-version=iphonesim-3.2 link=static install
  12. Update: Create a universal Boost Library using the lipo tool. In this example I'm assuming the binaries that were created have the following names. The names from the bjam generation will be different, based on your own configuration.End Update
  13. [ad#Link Banner]

    lipo -create libboost_filesystem_iphone.a libboost_filesystem_iphonesimulator.a -output libboost_filesystem_iphone_universal.a
    
    lipo -create libboost_system_iphone.a libboost_system_iphonesimulator.a -output libboost_system_iphone_universal.a
    
    lipo -create libboost_thread_iphone.a libboost_thread_iphonesimulator.a -output libboost_thread_iphone_universal.a
    
  14. I'm working on a cross-platform project and my directory structure looks like the following structure. I copied the include and lib files for iPhone and iPhone Simulator into the appropriate directories. The dependency structure allows me to checkout the project on another machine and have relative references to Boost and other dependencies.
  15.    |-ArtworkEvolution
       |---Xcode
       |-----BoostLoggingTest
       |---dependencies
       |-----iphone
       |-------debug
       |-------release
       |---------include
       |-----------boost
       |---------lib
       |-----iphone-simulator
       |-------debug
       |-------release
       |---------include
       |-----------boost
       |---------lib
       |-----macosx
       |-------debug
       |-------release
       |---------include
       |-----------boost
       |-----------libs
       |-----win32
       |---docs
       |---source
       |---tests
  16. Download the Boost Logging Library v2 and unzip it.
  17. Copy and paste the logging folder into each include/boost folder for iPhone and iPhone Simulator dependency folders like in my directory structure. After you unzip the header files are located in the folder logging/boost/logging.

Step 2:  Creating the Xcode Project

With the iPhone and iPhone Simulator Boost libraries in hand we're ready to make an Xcode project. Due to the difference in the iPhone and iPhone Simulator libraries we'll need to make two targets. One will build linking against the iPhone Boost libraries (arm) and the other against the iPhone Boost Simulator libraries (x86).

Update: You don't need to create two targets, as we can use the lipo tool to make a universal iPhone/iPhone Simulator library file. The universal library file can be shared between iPhone and iPhone Simulator build configurations. See the instructions for using lipo to create the universal library files in the previous section. However, I will keep the two target instructions up as an alternate approach for Xcode project development, if you choose not to use the lipo tool.

End Update

[ad#Link Banner]

1. Create a new iPhone project (view based)

2. There will be two targets: "BoostLoggingTest Device" and "BoostLogging Test Simulator" each will reference different headers and libraries. Duplicate the starting target and rename each target respectively.

[caption id="attachment_566" align="aligncenter" width="492" caption="Duplicate target to make iPhone/iPhoneSimulator targets"][/caption]

3. Add the libraries that we compiled into two groups: device and simulator under Resources. Right-click on the group "Simulator" or "Device" and select "Add Existing Files". Search for the library .a files that you copied into the iphone and iphone-simulator directories. These resources should be added relative to the project folder.

4. Drag the appropriate libraries to each Target. We need two targets since the architecture is different on the iPhone device (arm) versus the iPhone Simulator (Intel x86).

[caption id="attachment_569" align="aligncenter" width="476" caption="Drag the device libraries to the device target."][/caption]

[caption id="attachment_570" align="aligncenter" width="476" caption="Drag simulator dependencies to the iPhone simulator target"][/caption]

5. Add the "Header Search Path" for each target. For me the relative path will be two directories up from the Xcode project folders:  ../../dependencies/iphone/release/include and ../../dependencies/iphone-simulator/release/include. Right-click on each Target in the left pane and click on "Get Info" -> Build -> Type "Header" in the search field -> Edit the list of paths.

[caption id="attachment_571" align="aligncenter" width="512" caption="Add the Device Target Header Search path for the boost libraries"][/caption]

[caption id="attachment_572" align="aligncenter" width="518" caption="Add the simulator targets Header Search Paths"][/caption]

6. Change the base SDK of each target. For the Device you need to use iPhone Device 3.2 and the Simulator Target needs iPhone Simulator 3.2 or later.

[caption id="attachment_573" align="aligncenter" width="431" caption="Set the Device Target to iPhone Device 3.2"][/caption]

[caption id="attachment_574" align="aligncenter" width="431" caption="Set the Simulator Target to iPhone Simulator 3.2"][/caption]

7. Now you have two different targets. One is for the iPhone Device and the other is for the iPhone Simulator. We did this because we built separate binaries for Boost on the iPhone (arm) and simulator (x86) platforms.

8. Set the project's Active SDK to use the Base SDK (top left of Xcode). Now it will automatically choose the iPhone Device or iPhone Simulator based on the Base SDK of each Target you select.

9. Logging on the iPhone requires that we use the full path to the file within the application sandbox. Use the following Objective-C code to get it:

[ad#Link Banner]

NSString *docsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *path = [docsDirectory stringByAppendingPathComponent:@"err.txt"];
const char *outputFilename = [path UTF8String];

10. I modified one of the Boost Logging samples to use the full file path on the iPhone. Rename the main.m as main.mm to use Objective-C/C++ and copy paste the following:  main.mm code

11. If everything compiled and ran on the Device you can get the application data from the Xcode Organizer (Option+Command+O) Navigate to Devices and then look in Applications for the test application. Just drag the "Application Data" to your desktop to download it from the device. Your logs should appear in the Documents folder.

Part 3: Build Boost for Mac OS X 10.6 - 4 way fat (32/64 PPC and 32/64 Intel)

1. Build boost for Mac OS X. Note:  If you setup the user-config.jam file for iPhone Boost build, rename or move the file to a different folder than your home directory, otherwise ignore this command.

mv ~/user-config.jam ~/user-config.jam.INACTIVE
cd /path/to/boost_1_42_0
./bootstrap.sh --with-libraries=filesystem,system,thread
./bjam --prefix=${HOME}/dev/boost/macosx toolset=darwin architecture=combined address-model=32_64 link=static install

2. Copy the output into your dependency structure and add the Boost Logging Library headers into the include/boost folder. (Same procedure as with iPhone)

3. Setup a Xcode project or target with the appropriate header search path, Boost Mac OSX libraries in the same way we setup the iPhone Xcode project.

Note: If you get warnings about hidden symbols and default settings open the Xcode project for and make sure that the "Inline Methods Hidden" and "Symbols Hidden by Default" are unchecked. Clicking on/off might fix any Xcode warnings.

References:

[ad#Large Box]

iPhone Development with OpenGL

Here's my second presentation on iPhone Development at RIT for the Computer Science Community (CSC).If you enjoyed it let me know. I decided to look into graphics and OpenGL for the presentation.

Slides: iPhone Development II - Paul Solt

Demo: Triangle Demo: OpenGL ES on iPhone

[caption id="attachment_372" align="aligncenter" width="290" caption="OpenGL ES Triangle Demo"]OpenGL ES Triangle Demo[/caption]

The first demo is a basic OpenGL ES iPhone project using vertex/color arrays and an orthogonal view. It's based on the tutorials from Jeff LaMarche This is the starting point for any iPhone OpenGL ES project. It'll give you a window that you can draw in and manipulate OpenGL state. Use Jeff's xcode project template to make this process painless and easy to get started. It's easier than using GLUT!

Demo: Cocos2D for iPhone: Cocos2D iPhone Graphics Demo

[caption id="attachment_368" align="aligncenter" width="554" caption="Cocos2D Demo for iPhone"]Cocos2D Demo for iPhone[/caption]

A 2D graphics package to aid graphical applications on the iPhone. It provides some really neat animation support along with project templates to make setup a breeze. Cocos2D comes with two separate physics packages that you can incorporate into your game. The demo shows an animation trigger when the user pressed on the screen. Animations can be built from simple actions and combined to create a complex animation. It's perfect for a platformer.

[ad#Link Banner]

Demo: Raytracing on the iPhone

[caption id="attachment_382" align="aligncenter" width="290" caption="Raytracing with Photon Mapping"]Raytracing with Photon Mapping with correct aspect ratio[/caption]

I ported my computer graphics II ray tracer from OpenGL/GLUT to OpenGL ES on the iPhone. The performance is very slow on the iPhone 3G (133-230 seconds), but that's to be expected with the given hardware. In the simulator it can render a scene in about 15 seconds. This demo shows how the performance of the actual device is vastly different from the iPhone simulator. I'm sure I can rework portions of the ray tracer to be more efficient, but that wasn't the goal of the quick port.

Resources:

[ad#Large Box]

iPhone Development Talk

Today I gave a presentation on iPhone Development at RIT for the Computer Science Community (CSC).If you enjoyed it let me know. I'm looking into starting an informal iPhone Dev workshop for more topics. iphone

Here are the slides and Xcode projects:

Slides:  iPhone Development - Paul Solt

1. Demo: Hello World Pusher:  Foo2

2. Demo: Touch Input:  Stalker

3. Demo: Robot Remote Control:  See my previous post

*The Touch Input demo was based on a demo given during the Stanford iPhone courses available on iTunes here.

Resources:

[ad#Large Box]

iPhone Player/Stage Remote Control

Here's the iPhone Player/Stage Remote Control project! There's a .pdf that describes how to setup Xcode in the .zip file.

[caption id="attachment_456" align="aligncenter" width="539" caption="Controlling a Robot over Wi-Fi"][/caption]

[caption id="attachment_455" align="aligncenter" width="496" caption="A Virtual Robot in a Virtual World"][/caption]

The goal of this project was to use the Player/Stage robotics code on the iPhone to communicate and control robots. I discuss how to setup the Xcode development environment. There are two example Xcode projects. The first one is an Objective-C project that wraps around the C++ Player/Stage code. The second project is a very primitive C++ program running on the iPhone without any UI. Both of these Xcode projects are fully documented and will serve as a starting point to iPhone Player/Stage development.

iPhone Player/Stage Remote Control Project: iPhonePlayerStage

Feel free to ask questions and let me know how you use the code.

[ad#Large Box]

iPhone Default User Settings Null?

I wanted to set default values for my application using a Settings.bundle and I ran into an interesting issue with iPhone SDK 2.2. If you don't run the Settings application before your application runs for the first time, then the default settings are not set. It turns out that you'll need to manually set them on the first time the application is run.

Setting defaults to the default value...

I'm not sure why there isn't a function that can set the values for me, but after digging I found someone who ran into the same dilema. I don't want to have multiple locations with default values (code and a Settings.bundle), so I found a programmatic way to set all the default values if they haven't been set.

- (void)registerDefaultsFromSettingsBundle {
    NSString *settingsBundle = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"];
    if(!settingsBundle) {
        NSLog(@"Could not find Settings.bundle");
        return;
    }

    NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[settingsBundle stringByAppendingPathComponent:@"Root.plist"]];
    NSArray *preferences = [settings objectForKey:@"PreferenceSpecifiers"];

    NSMutableDictionary *defaultsToRegister = [[NSMutableDictionary alloc] initWithCapacity:[preferences count]];
    for(NSDictionary *prefSpecification in preferences) {
        NSString *key = [prefSpecification objectForKey:@"Key"];
        if(key) {
            [defaultsToRegister setObject:[prefSpecification objectForKey:@"DefaultValue"] forKey:key];
        }
    }
    [[NSUserDefaults standardUserDefaults] registerDefaults:defaultsToRegister];
    [defaultsToRegister release];
}

All you have to do is call the above function if one of your Standard User Defaults returns null. Make the call once your application finishes loading like so:

- (void)applicationDidFinishLaunching:(UIApplication *)application {
	// Get the application user default values
	NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
	NSString *server = [user stringForKey:@"server_address"];
	if(!server) {
		// If the default value doesn't exist then we need to manually set them.
		[self registerDefaultsFromSettingsBundle];
		server = [[NSUserDefaults standardUserDefaults] stringForKey:@"server_address"];
	}
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
}

References:

[ad#Large Box]

Player/Stage, MacPorts, and iPhone

Today I worked on setting up Player/Stage on my Macbook Pro with Leopard 10.5.6 and I ran into a few issues. I was using Macports 1.710 and I was attempting to install player-stage-player (2.03 2.1.2) and player-stage-stage (2.03 2.1.1) following a short guide at http://bentham.k2.t.u-tokyo.ac.jp/notebook/?p=247

If it's your first time using macports it can take a long time. I waited 2+ hours to download/build/install dependencies

I used the command:

$ sudo port install playerstage-player playerstage-stage

However it errored out at the end with the message:

$ sudo port install playerstage-player playerstage-stage
--->  Building playerstage-player
Error: Target org.macports.build returned: shell command " cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_science_playerstage-player/work/player-2.0.4" && make all " returned error 2
Command output: building '_playerc' extension
swigging playerc.i to playerc_wrap.c
swig -python -o playerc_wrap.c playerc.i
playerc.i:44: Warning(124): Specifying the language name in %typemap is deprecated - use #ifdef SWIG instead.
playerc.i:82: Warning(124): Specifying the language name in %typemap is deprecated - use #ifdef SWIG instead.
playerc.i:121: Warning(124): Specifying the language name in %typemap is deprecated - use #ifdef SWIG instead.
playerc.i:127: Warning(124): Specifying the language name in %typemap is deprecated - use #ifdef SWIG instead.
gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DMACOSX -I/usr/include/ffi -DENABLE_DTRACE -arch i386 -arch ppc -pipe -I./../.. -I../../../.. -I/System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -c playerc_wrap.c -o build/temp.macosx-10.5-i386-2.5/playerc_wrap.o
playerc_wrap.c: In function '_wrap_playerc_mclient_client_set':
playerc_wrap.c:40301: warning: assignment from incompatible pointer type
playerc_wrap.c: In function '_wrap_playerc_mclient_addclient':
playerc_wrap.c:40504: warning: passing argument 2 of 'playerc_mclient_addclient' from incompatible pointer type
playerc_wrap.c: In function '_wrap_playerc_mclient_client_set':
playerc_wrap.c:40301: warning: assignment from incompatible pointer type
playerc_wrap.c: In function '_wrap_playerc_mclient_addclient':
playerc_wrap.c:40504: warning: passing argument 2 of 'playerc_mclient_addclient' from incompatible pointer type
gcc -Wl,-F. -bundle -undefined dynamic_lookup -arch i386 -arch ppc build/temp.macosx-10.5-i386-2.5/playerc_wrap.o -L./../../.libs -L../../../../libplayerxdr/.libs -L../../../../libplayercore/.libs -L../../../../libplayerjpeg/.libs -lplayerxdr -lplayerc -lplayerjpeg -ljpeg -lplayererror -o build/lib.macosx-10.5-i386-2.5/_playerc.so
ld: library not found for -ljpeg
collect2: ld returned 1 exit status
ld: library not found for -ljpeg
collect2: ld returned 1 exit status
lipo: can't open input file: /var/tmp//ccI9TvVp.out
(No such file or directory)
error: command 'gcc' failed with exit status 1
make[6]: *** [pythonbuild] Error 1
make[5]: *** [all] Error 2
make[4]: *** [all-recursive] Error 1
make[3]: *** [all-recursive] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

Error: Status 1 encountered during processing.

[ad# Link Banner]

So I searched around the MacPorts website and I came across the ticket #18891, which basically said to run the following command to change the version of python being used from 3.0 to 2.5.

$ sudo port install python_select && sudo python_select python25
Skipping org.macports.activate (python_select +darwin_9) since this
port is already active
--->  Cleaning python_select
Selecting version "python25" for python

Following that command I was able to finish installing Player/Stage via MacPorts by using the orginal port command.

$ sudo port install playerstage-player playerstage-stage
--->  Building playerstage-player
--->  Staging playerstage-player into destroot
--->  Installing playerstage-player @2.0.4_2
--->  Activating playerstage-player @2.0.4_2
--->  Cleaning playerstage-player
--->  Fetching playerstage-stage
--->  Attempting to fetch stage-2.0.3.tar.bz2 from
http://voxel.dl.sourceforge.net/playerstage
--->  Verifying checksum(s) for playerstage-stage
--->  Extracting playerstage-stage
--->  Configuring playerstage-stage
--->  Building playerstage-stage
--->  Staging playerstage-stage into destroot
--->  Installing playerstage-stage @2.0.3_0
--->  Activating playerstage-stage @2.0.3_0
--->  Cleaning playerstage-stage

I tried to use player stage from MacPorts.

$ player /opt/local/var/macports/software/playerstage-stage\
/*/opt/local/share/stage/worlds/simple.cfg

And I received the error:

rr: unable to open color database /usr/X11R6/lib/X11/rgb.txt
 : No such file or directory (stage.c stg_lookup_color)

Following the advice from http://bentham.k2.t.u-tokyo.ac.jp/notebook/?cat=5 I added the following link.

$ sudo ln -s /usr/X11/share/X11/rgb.txt /usr/X11R6/lib/X11/rgb.txt

Now I am able to create a player server and connect with a client with the commands:

$ player /opt/local/var/macports/software/playerstage-stage\
/*/opt/local/share/stage/worlds/simple.cfg

/opt/local/var/macports/software/playerstage-player\
/*/opt/local/share/player/examples/libplayerc++/laserobstacleavoid

With the ability to run player/stage I will post again on my progress as I use an iPhone to run the Player client, rather than my Macbook Pro.

[caption id="attachment_209" align="alignleft" width="443" caption="Player client running on iPhone with Player/Stage."]Player client running on iPhone with Player/Stage.[/caption]

[ad#Large Box]