Saturday, November 1, 2014

#1 2012-12-18 11:58:11 pm

johndavidlewis
Member
Registered: 2012-12-05
Posts: 8

malloc()

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

thanks

Offline

 

#2 2012-12-19 12:11:36 am

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 10624
Website

Re: malloc()

Hi,

you can create a CGContextRef with the function

Applescript:

CGBitmapContextCreate()

or retrieve the current context with 

Applescript:

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


regards

Stefan

Online

 

#3 2012-12-19 06:03:10 am

johndavidlewis
Member
Registered: 2012-12-05
Posts: 8

Re: malloc()

StefanK wrote:

Hi,

you can create a CGContextRef with the function

Applescript:

CGBitmapContextCreate()

or retrieve the current context with 

Applescript:

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

Offline

 

#4 2012-12-19 04:21:48 pm

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 3731

Re: malloc()

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Online

 

#5 2012-12-20 04:04:20 am

johndavidlewis
Member
Registered: 2012-12-05
Posts: 8

Re: malloc()

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

Offline

 

#6 2012-12-20 05:41:23 am

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 3731

Re: malloc()

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Online

 

Board footer

Powered by FluxBB

[ Generated in 0.021 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)