[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] strange compile error with cocoa



Ok, good news, with the current version of the camera module, I am able to grab a frame from the camera, copy it to the SDL_Surface and display this image in the display.

The image is not displayed 'naturally' on the display, probably because of a difference between the rgb mapping on the gWorld and the SDL_Surface.

I will fix that tomorrow, and clean up the code (the current one is a mess), and write a blog post about it. I think it would be useful if someone would test it to see if it works on other computers...

Grtz

On 13-jul-09, at 06:45, René Dudfield wrote:

Hi,

you should be able to put a pointer in the structure in the .h file. Then in your .m file define another structure with all your objc/cocoa specific parts.

Then you might need to typedef yourstuff to void *. Then just cast to and from the void * to your mac specific structure. That way the C code doesn't need to know about the objc structures.


eg. in the camera.h

typedef struct {
    PyObject_HEAD
    char* device_name;              // unieke name of the device
long size; // size of the image in our buffer to draw


    void * apple_junk;

    SDL_Surface* surf;
    unsigned char *pbuffer;
    unsigned char *buffer;
} PyCameraObject;



Then have your struct defined in your camera_mac.m something like this:

typedef struct {
    TimeScale timeScale;
    TimeValue lastTime;
    NSTimeInterval startTime;
    NSTimer *frameTimer;
SeqGrabComponent component; // A type used by the Sequence Grabber API
    SGChannel channel;              // Channel of the Sequence Grabber
GWorldPtr gWorld; // Pointer to the struct that holds the data of the captured image
    Rect boundsRect;                // bounds of the image frame
    ImageSequence decompressionSequence;

} AppleJunk;


Then you'll need to allocate some room for that, and also dealloc it. Probably with some functions defined in your .m too that get called from the camera_dealloc, and Camera (...) functions in the _camera.c.


AppleJunk myapplejunk = (AppleJunk)(cameraobj->apple_junk);
cameraobj.apple_junk = (void *) malloc(sizeof(AppleJunk));
free(cameraobj.apple_junk);

etc.

Hope that helps.


cu,