Re: [Pyobjc-dev] initWithBitmapDataPlanes?
Brought to you by:
ronaldoussoren
From: Francesco P. <fpi...@no...> - 2003-12-06 07:21:26
|
Hi, Thanks for the quick reply! I actually saw the test scripts but when I tried using the function, I got a sgefault :-( (that is why I thought that the function had not really been wrapped) What I do is the following: img_size = str (len (self.img_data)) + 'B' temp_data = struct.unpack (img_size, self.img_data) data = array.array ('B') for c in temp_data: data.append (c) del (temp_data) my_bitmap = NSBitmapImageRep.alloc().initWithBitmapDataPlanes_pixelsWide_pixelsHigh_ bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bytesPerR ow_bitsPerPixel_ ( (data, None, None, None, None), width, height, 8, 1, NO, YES, NSCalibratedWhiteColorSpace, width, 8) my_image = NSImage.alloc ().init () my_image.addRepresentation_ (my_bitmap) # display the image in the GUI self.server.controller.imgView.setImage_ (my_image) Am I trashing the memory somewhere? I guess so, but have no idea where... Cheers fra On Dec 6, 2003, at 12:03 AM, b.bum wrote: > On Dec 5, 2003, at 10:40 PM, Francesco Pierfederici wrote: >> The reason I am asking is that I am writing an application that >> receives a raster through a socket connection. The raster is a >> (potentially large) array of bytes that I would like to display as a >> grey-scale bitmap. Hence the need for NSBitmapImageRep and its >> initWithBitmapDataPlanes:...., unless, of course, there is a better >> way of doing displaying that data, other than using a >> NSBitmapImageRep! > > It is already partially mapped, but the assumption is that you have -- > effectively -- five data planes worth of color information passed in > as a tuple. > > I believe that this means it will just work in your case -- you would > need to pass a tuple like (greyScaleBytes, None, None, None, None) in > as the first argument. > > See Modules/Appkit/_AppKitMapping_NSBitmap.m for the mapping code. It > is incomplete. > > Better yet, see -- Lib/AppKit/test/test_nsbitmapimagerep.py -- as it > contains a set of unit tests that are passing and do pass bitmap data > across the bridge. > > So -- maybe -- Guido's time machine has been effective once again for > your particular use case. ;-) > > b.bum --- Francesco Pierfederici <fpi...@no...> NOAO/AURA Inc. http://www.noao.edu/staff/fpierfed/ 950 N. Cherry Ave. Phone: +1 520 318 8402 Tucson, AZ 85719 USA FAX: +1 520 318 8360 |