THGraphics External

Here is where the magnanimous folks that create externals post them (.zip archives only please).

Re: THGraphics External

Postby gonetriadrr » Fri Mar 11, 2011 2:32 pm

sctell wrote:colorWithDeviceCyan:magenta:yellow:black:alpha:


That's the one!
But i thought deviceCMYK was to be phased out in favor of device independent genericCMYK.

Python's defunct quartz bridge allowed the bitmap context to be defined in rgb, cmyk, or grayscale and color to be defined in any of the three.
Cmyk and grayscale are much more suitable for print when output file format tiff or other format that supports cmyk & grayscale.
Illustrator files are most commonly defined in cmyk. I have nearly completed an importer supporting most of the last published Illustrator specification and rely on Python's quartz bridge for cmyk to rgb conversion. A shame to resort to lousy cmyk to rgb color math to support systems > 10.4.

Had a chance to test the external a little.
10.5 must automatically convert quickdraw to cartesian coordinates since image clip flips image upside down in Tiger. Ability to apply an affine transform matrix to image would be handy.
Does clip follow winding number rule. Both winding number and even-odd clip would also be handy.

For what it's worth, i'll briefly describe an aspect of my ideal. No criticism intended. I'm amazed at the progress you've made. My brain turns to mush every time i start reading up on cocoa.

Allow commands to be passed as multi-line space delimited attributes which mimic postscript code.
last coordinate of each line = the on-curve coordinate.
for instance...
0,0 moveto
100,100 lineto
120,100 150,150 300,300 curveto
0,0 lineto
closepath

IMHO, one can't help but get ankle deep in the tedium of geometric calculations when working with bezier curves. Easy to read formatting would make everything a little easier to debug & edit.
Of course, I'll just write a script function to reformat a 'program' similar to that above to use the external as it is.

I'll post a script to spit out coordinates for true stars as soon as i get a chance.

Thanks!
DCS
gonetriadrr
 
Posts: 170
Joined: Fri Jan 08, 2010 6:50 pm

Re: THGraphics External

Postby gonetriadrr » Fri Mar 11, 2011 2:36 pm

Dan_Kelleher wrote:yellow & blue make green,
tested w Crayola,
-Dan


Yep :) .

DCS
gonetriadrr
 
Posts: 170
Joined: Fri Jan 08, 2010 6:50 pm

Re: THGraphics External

Postby sctell » Sat Mar 12, 2011 12:26 am

gonetriadrr wrote:10.5 must automatically convert quickdraw to cartesian coordinates since image clip flips image upside down in Tiger


I wrote the external with the coordinates as per SC. The ability to flip coordinates/images exists in Cocoa so I thought this would be more useful to SC users.

There may be something wrong here, I will have a look although it works fine in 10.6.

gonetriadrr wrote:But i thought deviceCMYK was to be phased out in favor of device independent genericCMYK.


There's no reference to this being deprecated in the documentation.

gonetriadrr wrote:I'll post a script to spit out coordinates for true stars as soon as i get a chance.


Please explain.

gonetriadrr wrote:Allow commands to be passed as multi-line space delimited attributes which mimic postscript code.
last coordinate of each line = the on-curve coordinate.


I will have to think about this one.
sctell
 
Posts: 1143
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby sctell » Sat Mar 12, 2011 12:39 am

sctell wrote:gonetriadrr wrote:
10.5 must automatically convert quickdraw to cartesian coordinates since image clip flips image upside down in Tiger


I wrote the external with the coordinates as per SC. The ability to flip coordinates/images exists in Cocoa so I thought this would be more useful to SC users.

There may be something wrong here, I will have a look although it works fine in 10.6.


I have had a quick look and everything seems fine.

Are you seeing this in the test programme or in some other circumstance where you are using the external.

If in another situation can you post your SC script please as something else may be interacting with the clipImage routine.
sctell
 
Posts: 1143
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby sctell » Sat Mar 12, 2011 1:03 am

Hi,

With regard to "clipImage" you can achieve the same result by the use of "fillPathWithPattern".

if you use

export {card | [the] picture[Data] of graphicDescriptor} [from topLeft to bottomRight] {to {[fileType] [file] FilePath} | into variableIdentifier [as format]} [with qualitySpec [quality]]

and place it into tImageData (see below) then fillPathWithPattern will clip the image.

Code: Select all

put "50,100,300,200" into tRect -- x,y,w,h
get THGraphics("appendPathWithOvalInRect",tRect)

export the pictureData of cd grc "scImage" into tImageData as "tiff"
get THGraphics("fillPathWithPattern",tImageData)



I will add an example to the fillPathWithPattern card.


EDIT TEXT

I WAS TO HASTY, THIS DOES NOT SEEM TO WORK.
sctell
 
Posts: 1143
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby sctell » Sun Mar 13, 2011 11:15 am

Hi all,

I have now added a number of additional functions. What they do is probably self explanatory from their names.

Here is the latest additions:

fillPathWithPattern
strokePathWithPattern

imageToVarTIFF
imageToVarPNG

saveToFileTIFF
saveToFilePNG

drawText
drawStrokedText
drawFilledStrokedText
drawPatternedStrokedText
setFontNameSize
setTextForegroundColor
setTextStrokeWidth
setTextStrokeColor
setTextPattern

The latest download is at the top of the thread.
sctell
 
Posts: 1143
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby gonetriadrr » Mon Mar 14, 2011 2:43 pm

sctell wrote:
gonetriadrr wrote:I'll post a script to spit out coordinates for true stars as soon as i get a chance.


Please explain.


IIRC, your example script draws a pentagram for instance. In my mind, a pentagram and a 5 pointed star are not the same. Did i miss something obvious?

As for the rest, my observations were based on a brief run through the examples provided in your demo project.
Os 10.4.1, SC 4.6.
Since beggars can't be choosers, and I will have little time to devote to scripting anything until the fall, i wouldn't deviate from your path ;)

DCS
gonetriadrr
 
Posts: 170
Joined: Fri Jan 08, 2010 6:50 pm

Re: THGraphics External

Postby gonetriadrr » Tue Mar 15, 2011 7:20 am

sctell wrote:
gonetriadrr wrote:10.5 must automatically convert quickdraw to cartesian coordinates since image clip flips image upside down in Tiger


I wrote the external with the coordinates as per SC. The ability to flip coordinates/images exists in Cocoa so I thought this would be more useful to SC users.

There may be something wrong here, I will have a look although it works fine in 10.6.



Hmmm... unexpected flip of clipped image example righted itself on subsequent launch of demo project where star and image clip examples were only examples tested.
May have no bearing, but did notice that roundrect example doesn't seem to function here under os 10.4.11 but does not crash SC. Is it possible that commands from one or more previous examples might remain active to cause the unexpected flip i reported?

BTW: Played around with clip image long enough to use 2 paths to knock a hole in the image.
Since, my projects only require moveto, lineto and curveto path constructors, failure of roundrect routine doesn't effect me.

Downloading the latest version and will try to test a little each night and hopefully post a project before too long.

Thanks!
DCS
gonetriadrr
 
Posts: 170
Joined: Fri Jan 08, 2010 6:50 pm

Re: THGraphics External

Postby gonetriadrr » Tue Mar 15, 2011 7:56 am

gonetriadrr wrote:
sctell wrote:colorWithDeviceCyan:magenta:yellow:black:alpha:

That's the one!


Upon further consideration, a separate external to convert cmyk to rgb would be more suitable for my purposes and general use.
Unlike additive color space specification (RGB,HSV, and the like), subtractive CMYK defies a scriptable conversion that yields the slightest degree of color fidelity. I've gone as far as parsing ICC CMYK profiles to extract the requisite muti-dimensional lookup tables and curves... i simply don't have the math skills to make sense of it.

Just sayin' ;)

DCS
gonetriadrr
 
Posts: 170
Joined: Fri Jan 08, 2010 6:50 pm

Re: THGraphics External

Postby sctell » Tue Mar 15, 2011 11:42 am

Hi,

I have been concentrating on text at the moment.

I have just added a further 4 functions allowing easy rotation of text to the available text routines.

The full list of text routines is:

drawText
drawStrokedText
drawFilledStrokedText
drawPatternedStrokedText
setFontNameSize
setTextForegroundColor
setTextStrokeWidth
setTextStrokeColor
setTextPattern
textBoxSize
setEnableTextRotation
setTextRotationAngle
setTextRotationPoint

Please look at the sample scripts on how to use these functions, very easy.

Please download the update from the top of the thread.
sctell
 
Posts: 1143
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby gonetriadrr » Wed Mar 16, 2011 8:11 am

So far, testing is going quite well.
Just a few observations...
OS 10.4.11, SC 4.6

Are all command names case sensitive?

Had to change bundle file extension to .pkg to convince resource manager utility to import bundle external.

Dimensions of first instance of createCanvas persists, requiring project to be closed and reopened to reset.

One instance where coordinates flipped after an error dialog due to typo in an external call.

Thanks for all the effort.

DCS
gonetriadrr
 
Posts: 170
Joined: Fri Jan 08, 2010 6:50 pm

Re: THGraphics External

Postby sctell » Wed Mar 16, 2011 10:40 am

gonetriadrr wrote:Are all command names case sensitive?


Yes, if you mistype a command name nothing will happen.

gonetriadrr wrote:Had to change bundle file extension to .pkg to convince resource manager utility to import bundle external.


This must be an issue with 4.6 and Tiger.

No problems with 4.6.3 and Snow Leopard.

gonetriadrr wrote:Dimensions of first instance of createCanvas persists, requiring project to be closed and reopened to reset.


I will change the arrangement so that you can change the canvas from within SC.

Probably a "releaseCanvas" call that will then allow you to "createCanvas" again.

gonetriadrr wrote:One instance where coordinates flipped after an error dialog due to typo in an external call.


Anymore information on what you were doing when it happened.
I will add some better error trapping.


Thanks for the feedback.
sctell
 
Posts: 1143
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby gonetriadrr » Wed Mar 16, 2011 12:01 pm

sctell wrote:
gonetriadrr wrote:Had to change bundle file extension to .pkg to convince resource manager utility to import bundle external.


This must be an issue with 4.6 and Tiger.

No problems with 4.6.3 and Snow Leopard.

gonetriadrr wrote:One instance where coordinates flipped after an error dialog due to typo in an external call.


Anymore information on what you were doing when it happened.
I will add some better error trapping.


Thanks for the feedback.


The bundle folder wasn't recognized as a package by tiger's finder. Thought is might frustrate other tiger users if not mentioned.

I wish i could remember the details when coordinates flipped.
If it happens again, i'll take notes.

Thanks,
DCS
gonetriadrr
 
Posts: 170
Joined: Fri Jan 08, 2010 6:50 pm

Re: THGraphics External

Postby sctell » Wed Mar 16, 2011 12:02 pm

Hi,

gonetriadrr wrote:Dimensions of first instance of createCanvas persists, requiring project to be closed and reopened to reset


One little update to address this issue.

A function which now allows you to change the size of the canvas.

get THGraphics("setCanvasSize","width,height")

This function does not destroy the existing image although depending how you size the canvas you may lose some of the image.

Update at the top of the thread.
sctell
 
Posts: 1143
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby gonetriadrr » Thu Mar 17, 2011 8:03 am

Example of a Illustrator eps file imported into BezierPenTool. (Actually an Adobe Dimensions eps file.)
A card export of native supercard polygons first and same rendered using your THGraphics external.
This example required only 50 lines or so of additional script to implement the external.
Unfortunately, it will be a while before is BezerPenTool project is ready to repost.

bezierPenPolygons.png
bezierPenTool project polygon preview
bezierPenPolygons.png (14.37 KiB) Viewed 10877 times
bezierPenTHGraphicsTest.png
rendered bezierPenTool project polygons
bezierPenTHGraphicsTest.png (43.97 KiB) Viewed 10877 times


DCS
gonetriadrr
 
Posts: 170
Joined: Fri Jan 08, 2010 6:50 pm

Re: THGraphics External

Postby gonetriadrr » Thu Mar 17, 2011 8:49 am

There appears to be an issue when filling 'compound paths'.

For instance, given 2 intersecting subpaths defined between 'bezierPath' and 'releasePath' calls.
(Each subpath begins with a moveToPoint operator.)
If both subpaths are drawn in same direction (both clockwise or both counter clockwise) all is well.
However, if subpath direction does not match, i expected the intersecting area to be erased to transparent. Get black instead.

DCS
gonetriadrr
 
Posts: 170
Joined: Fri Jan 08, 2010 6:50 pm

Re: THGraphics External

Postby Dan_Kelleher » Thu Mar 17, 2011 10:43 am

Without seeing a screenShot, I'm not sure what your paths look like.

But if the fillColor is black and the winding rule is the default "NonZero" winding rule then you may be getting the expected behavior BASED ON THE EXAMPLE GRAPHIC in the "CocoaDrawingGuide.pdf".

However, as I see it, this BEHAVIOR THEY SHOW is NOT what I'd EXPECT FROM THEIR WRITTEN DESCRIPTION: (see the attached screenShot for the wriiten description at the top and the graphic example below)

Seems to be a Special Case for when only 2 paths are involved, Which they forgot to mention !! ??
1 L->R + 1 R->L = 0
therefore the points are outside and are not filled with the fillColor.... BUT THEY SHOW THEM FILLED

-Dan
CocoaWindingRules_ Note 1L+1R SpecCase.jpg
CocoaWindingRules_ Note 1L+1R SpecCase.jpg (61.66 KiB) Viewed 10873 times
Daniel.Kelleher@umassmed.edu
SC4.7.3 OSX 10.7.2 Mac Pro
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: THGraphics External

Postby gonetriadrr » Thu Mar 17, 2011 12:20 pm

Dan_Kelleher wrote:Without seeing a screenShot, I'm not sure what your paths look like.

But if the fillColor is black and the winding rule is the default "NonZero" winding rule then you may be getting the expected behavior BASED ON THE EXAMPLE GRAPHIC in the "CocoaDrawingGuide.pdf".


Since i'm only implementing, not coding the xternal i can't comment on drawingGuide details.
Haven't tested to see if more that two subpaths makes a difference.

DCS
gonetriadrr
 
Posts: 170
Joined: Fri Jan 08, 2010 6:50 pm

Re: THGraphics External

Postby gonetriadrr » Thu Mar 17, 2011 12:24 pm

Terry,
Following up on a post in another thread.
You seem to be asking about extracting the argb byte stream from pictdata.
If so, by script it can be done like this.

export pictdata of objdesc into pd
put char 215 to 214+(pixWidth*pixHeight*4) of pd into rawargb

DCS
gonetriadrr
 
Posts: 170
Joined: Fri Jan 08, 2010 6:50 pm

Re: THGraphics External

Postby sctell » Thu Mar 17, 2011 1:02 pm

I have a book Programming with Quartz 2d and have just read the nonzero winding number rule (easier than Apple's explanation) and have concluded when applying it to the Apple Diagrams above (diagram c) the following.

The ray crosses right to left +1
The ray crosses left to right -1

Total = 0

Rule

If the outcome is nonzero the point is in the interior of the path.

In this case the outcome is zero therefore the Apple diagram c is correct.

Please disagree if you wish.


gonetriadrr wrote:For instance, given 2 intersecting subpaths defined between 'bezierPath' and 'releasePath' calls.
(Each subpath begins with a moveToPoint operator.)
If both subpaths are drawn in same direction (both clockwise or both counter clockwise) all is well.
However, if subpath direction does not match, i expected the intersecting area to be erased to transparent. Get black instead.


We do need to see your script to agree or disagree.
sctell
 
Posts: 1143
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby sctell » Thu Mar 17, 2011 1:05 pm

gonetriadrr wrote:export pictdata of objdesc into pd
put char 215 to 214+(pixWidth*pixHeight*4) of pd into rawargb


Thanks for that.

I'm sure we had this conversation a while ago on the Yahoo Group?
sctell
 
Posts: 1143
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby sctell » Thu Mar 17, 2011 1:09 pm

I will add the winding rule functions to the external.

Probably tomorrow.

Time for bed soon and getting tired.
sctell
 
Posts: 1143
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby Dan_Kelleher » Thu Mar 17, 2011 2:02 pm

Well, 1:1 we have a tie.
It will all come out in the wash,
sleep well
-Dan
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: THGraphics External

Postby sctell » Fri Mar 18, 2011 12:19 am

Here is an example from the book:

Works as expected.

Code: Select all
on mouseUp
get THGraphics("bezierPath") -- creates the NSBezierPath
get THGraphics("setLineWidth",10)
get THGraphics("moveToPoint","5,395")
get THGraphics("lineToPoint","395,395")
get THGraphics("lineToPoint","395,200")
get THGraphics("lineToPoint","100,200")
get THGraphics("lineToPoint","100,250")
get THGraphics("lineToPoint","350,250")
get THGraphics("lineToPoint","350,300")
get THGraphics("lineToPoint","200,300")
get THGraphics("lineToPoint","200,100")
get THGraphics("lineToPoint","5,100")
get THGraphics("lineToPoint","5,395")
get THGraphics("setLineColor","0,0.5,0.5,1") -- r,g,b,a
get THGraphics("setFillColor","0.5,0,0.5,1") -- r,g,b,a
get THGraphics("fill")
get THGraphics("stroke")
get THGraphics("releasePath") -- releases/disposes of the NSBezierPath
put "" into tImageVar
get THGraphics("imageToVar",@tImageVar)
set the pictureData of cd grc "scCanvas" to display tImageVar as tiff
end mouseUp
sctell
 
Posts: 1143
Joined: Sun Jul 06, 2008 10:41 am

Re: THGraphics External

Postby sctell » Fri Mar 18, 2011 6:59 am

Hi,


setWindingRule is now implemented.

NSNonZeroWindingRule = 0
NSEvenOddWindingRule = 1

Have a look at the script of button "setWindingRule" on the card "Drawing Lines"
sctell
 
Posts: 1143
Joined: Sun Jul 06, 2008 10:41 am

PreviousNext

Return to XCmds, XFcns, and XRtns

Who is online

Users browsing this forum: No registered users and 1 guest