From: Jonathan P. <jp...@dc...> - 2005-07-14 22:53:38
|
On 14 Jul 2005, at 21:08, Ralph Brorsen wrote: > The main event here is of course "$1 = StringValuePtr($input);", > which should, as I understand it return a char pointer to the > string data which bitmapRep.bitmapData() returned. The reason it is > converted to a Ruby string, I assume, is because RubyCocoa sees the > char *, and thinks it is a string. Perhaps the string is copied to > an internal buffer? As you've identified, the return value of bitmapData is being converted to a ruby string. The easiest solution (since you're already dealing with some native code) may be to pass the NSBitmapImageRep pointer to your native code and get the pointer to the bitmapData from within your native code. A better solution would involve some changes to RubyCocoa to better support this. You could do the 'easy' solution from Objective C++ or link in a small bit of Objective C code to do the work for you. The Objective C object pointer (of type 'id' or whatever your object is - e.g., 'NSBitmapImageRep*') is available by calling __ocid__ on the ruby object. So, from within your native code you could do something like: id ocobj = (id) NUM2UINT( rb_funcall(obj, rb_intern("__ocid__"), 0) ); unsigned char *pixels = [(NSBitmapImageRep*) ocobj bitmapFormat]; Another option would be to call into RubyCocoa to get it to do this for you. There's a function 'rbobj_get_ocid' which does what you want (in a more robust fashion). The C function prototype (from mdl_osxobjc.h) is: id rbobj_get_ocid (VALUE rcv); Provided you can get the linker to be happy with this (e.g., by linking your native code against RubyCocoa too) it should work. I'm sorry if the above is a bit vague. I've not tested it (just typed into email), but something along those lines should work. Jonathan |