malloc()

is it possible to call a malloc() function
im trying to create a CGContextRef

thanks

Hi,

you can create a CGContextRef with the function

CGBitmapContextCreate()

or retrieve the current context with

current application's NSGraphicsContext's currentContext()'s graphicsPort()

hi stefan thanks for your reply

i was able to make a CGContext using graphicsPort() but not CGBitmapContextCreate because i wasnt certain about how to include the malloc() into its parameters

following the graphicsPort method i got stuck again on CGLayer

eg code
— my createCGContextRef function
on createCGContextRef(pixelswide, pixelsHigh)
set theBitMapToBeSaved to current application’s NSBitmapImageRep’s alloc()'s initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bitmapFormat_bytesPerRow_bitsPerPixel_(missing value, pixelswide, pixelsHigh, 8, 4, true, false, “NSCalibratedRGBColorSpace”, 0, 0, 0)
set nsContext to current application’s NSGraphicsContext’s graphicsContextWithBitmapImageRep_(theBitMapToBeSaved)
current application’s NSGraphicsContext’s setCurrentContext_(nsContext)
set myCGContent to current application’s NSGraphicsContext’s currentContext()'s graphicsPort()
end createCGContextRef

set myCGContents to createCGContextRef(7000, 7000)
log myCGContents
set myCGRect to current application’s NSRectToCGRect(current application’s NSMakeRect(0, 0, 7000, 7000))
log myCGRect
–current application’s CGLayerCreateWithContext(myCGContents, myCGRect, (missing value))
log {myCGContents, myCGRect, (missing value)}

could you give a little example on asobjc CGBitmapContextCreate with parameters also
if not to much trouble what am i doing wrong with CGLayer

many thanks

Although ASObjC has supported calling functions since 10.7, in practice it’s very limited because of the parameters required, the inability to cast, the inability to deal with primitive types, and the inability to pass pointers to pointers. It also seems just generally hit-and-miss.

Your use of NSRectToCGRect is a good example: AS can’t deal with structs, so the result is converted into an AS record – NSRectToCGRect is thus effectively useless.

Depending on what you’re trying to achieve, you might do better to look at Cocoa Drawing rather than Quartz.

Hello Shane thank you for your reply

To give you a bigger picture with what I’m doing is my composing templates with various images on the templates. Some templates of the same image various times. some templates have text on, some images on the templates have various colour filters such as sepia black-and-white etc.
some of the work entails batching processing templates and other making data base instructions for processing images with xml’s

  i am doing this now with no problems by driving photoshop with applescript and 
  thought it would be good if i could do the image processing through Xcode and dropping photoshop

I started with cocoa drawing up to as far as placing images on the template at locations and writing out to file the template as a jpeg, ok this was good i thought, but on doing a loop of this i found it had a massive memory leak. the memory seems to come back but only after the loop and slowly. i tried putting the processing action in a function and calling it from the loop but didn’t help either. so with this problem at hand i decided to give coreGraphics a try to see if i could control the memory leak better… but apparently not…

so back to cocoa drawing board again and worry about the memory madness later
my next hurdles are Text on the templates, colour filters, and clipping masks

but my biggest worry is the colour filters, i understand that this has to be done through core image and applying a filter. i have been able to obtain a ciimage during my fooling around but not tried to add a filter,
do you know if adding cifilter is possible with asobjc?

many thanks

I looked at Core Image briefly a while ago, but didn’t get beyond the basics (I got distracted). However, it looks promising, especially being an Objective-C API.

The memory thing is part of life with garbage collection – there’s nothing you can do about it.