[Openmcl-devel] Advice needed: best way to fram a Lisp array into an ns-image

Ron Garret ron at awun.net
Sat Jan 19 00:15:50 PST 2008


On Jan 18, 2008, at 10:44 PM, R. Matthew Emerson wrote:

>
> On Jan 19, 2008, at 1:19 AM, Ron Garret wrote:
>
>>
>> On Jan 18, 2008, at 7:10 PM, Ron Garret wrote:
>>
>>> That's pretty much what I'm doing, so I guess that means I'm kinda  
>>> on
>>> the right track.
>>
>> Well, I thought I was on the right track.  I tried this:
>>
>> (defun stuff-pixels (pixels)
>> (bind ((x y bpp) (array-dimensions pixels)
>>        (:values v ptr) (make-heap-ivector (* x y bpp) '(unsigned- 
>> byte 8)))
>>   (dotimes (i (* x y bpp))
>>     (setf (aref v i) (row-major-aref pixels i)))
>>   (#/ 
>> initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:bitsPerPixel 
>> :
>>    (#/alloc ns:ns-bitmap-image-rep)
>>    ptr
>>    x y 8 3 0 0 #@"NSCalibratedRGBColorSpace" (* x 3) 24)))
>>
>> It seems to work:
>>
>> ? (stuff-pixels #3A(((0 0 0) (0 0 0) (0 0 0) (0 0 0))
>> ((0 0 0) (0 0 0) (0 0 0) (0 0 0))
>> ((0 0 0) (0 0 0) (0 0 0) (0 0 0))((0 0 0) (0 0 0) (0 0 0) (0 0 0)))
>> )
>> #<NS-BITMAP-IMAGE-REP NSBitmapImageRep 0xa992900 Size={4, 4}  
>> ColorSpace=NSCalibratedRGBColorSpace BPS=8 BPP=24 Pixels=4x4  
>> Alpha=NO Planar=NO Format=0 (#xA992900)>
>> ?
>>
>> But the resulting bitmapRep is corrupt:
>>
>> ? (#/bitmapData *)
>> Unhandled exception 11 at 0x7fff82855d80, context->regs at #xb0c3e350
>> Exception occurred while executing foreign code
>> ? for help
>> [58183] OpenMCL kernel debugger:
>
> I think I ran into this same thing myself a while ago.
>
> The first arg passed to #/initWithBitmapDataPlanes:... actually  
> needs to be a pointer to a pointer (a char ** in this case).
>

Aha!  (Makes sense when you think about it.  And actually read the  
documentation :-)

Thanks!

rg




More information about the Openmcl-devel mailing list